4 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "automation.h"
24 #include "bcsignals.h"
28 #include "cplayback.h"
31 #include "cwindowgui.h"
33 #include "cwindowtool.h"
34 #include "editpanel.h"
36 #include "edlsession.h"
37 #include "floatauto.h"
38 #include "floatautos.h"
41 #include "localsession.h"
42 #include "mainclock.h"
45 #include "mainsession.h"
47 #include "maskautos.h"
49 #include "meterpanel.h"
50 #include "mwindowgui.h"
53 #include "playback3d.h"
54 #include "playtransport.h"
56 #include "trackcanvas.h"
58 #include "transportque.h"
62 static double my_zoom_table[] =
75 static int total_zooms = sizeof(my_zoom_table) / sizeof(double);
78 CWindowGUI::CWindowGUI(MWindow *mwindow, CWindow *cwindow)
79 : BC_Window(_(PROGRAM_NAME ": Compositor"),
80 mwindow->session->cwindow_x,
81 mwindow->session->cwindow_y,
82 mwindow->session->cwindow_w,
83 mwindow->session->cwindow_h,
89 BC_WindowBase::get_resources()->bg_color,
90 mwindow->get_cwindow_display())
92 this->mwindow = mwindow;
93 this->cwindow = cwindow;
99 orig_mask_keyframe = new MaskAuto(0, 0);
105 current_operation = CWINDOW_NONE;
107 translating_zoom = 0;
114 CWindowGUI::~CWindowGUI()
116 if(tool_panel) delete tool_panel;
118 delete composite_panel;
125 delete orig_mask_keyframe;
128 void CWindowGUI::create_objects()
130 lock_window("CWindowGUI::create_objects");
131 set_icon(mwindow->theme->get_image("cwindow_icon"));
133 active = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_active"));
134 inactive = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_inactive"));
136 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
137 mwindow->theme->draw_cwindow_bg(this);
140 // Meters required by composite panel
141 meters = new CWindowMeters(mwindow,
143 mwindow->theme->cmeter_x,
144 mwindow->theme->cmeter_y,
145 mwindow->theme->cmeter_h);
146 meters->create_objects();
149 composite_panel = new CPanel(mwindow,
151 mwindow->theme->ccomposite_x,
152 mwindow->theme->ccomposite_y,
153 mwindow->theme->ccomposite_w,
154 mwindow->theme->ccomposite_h);
155 composite_panel->create_objects();
157 canvas = new CWindowCanvas(mwindow, this);
159 canvas->create_objects(mwindow->edl);
160 canvas->use_cwindow();
163 add_subwindow(timebar = new CTimeBar(mwindow,
165 mwindow->theme->ctimebar_x,
166 mwindow->theme->ctimebar_y,
167 mwindow->theme->ctimebar_w,
168 mwindow->theme->ctimebar_h));
169 timebar->create_objects();
172 add_subwindow(slider = new CWindowSlider(mwindow,
174 mwindow->theme->cslider_x,
175 mwindow->theme->cslider_y,
176 mwindow->theme->cslider_w));
179 transport = new CWindowTransport(mwindow,
181 mwindow->theme->ctransport_x,
182 mwindow->theme->ctransport_y);
183 transport->create_objects();
185 transport->set_slider(slider);
188 edit_panel = new CWindowEditing(mwindow, cwindow);
189 edit_panel->set_meters(meters);
190 edit_panel->create_objects();
192 // add_subwindow(clock = new MainClock(mwindow,
193 // mwindow->theme->ctime_x,
194 // mwindow->theme->ctime_y));
196 zoom_panel = new CWindowZoom(mwindow,
198 mwindow->theme->czoom_x,
199 mwindow->theme->czoom_y,
200 mwindow->theme->czoom_w);
201 zoom_panel->create_objects();
202 zoom_panel->zoom_text->add_item(new BC_MenuItem(AUTO_ZOOM));
203 if(!mwindow->edl->session->cwindow_scrollbars) zoom_panel->set_text(AUTO_ZOOM);
205 // destination = new CWindowDestination(mwindow,
207 // mwindow->theme->cdest_x,
208 // mwindow->theme->cdest_y);
209 // destination->create_objects();
211 // Must create after meter panel
212 tool_panel = new CWindowTool(mwindow, this);
213 tool_panel->Thread::start();
216 set_operation(mwindow->edl->session->cwindow_operation);
220 canvas->draw_refresh(0);
227 int CWindowGUI::translation_event()
229 mwindow->session->cwindow_x = get_x();
230 mwindow->session->cwindow_y = get_y();
234 int CWindowGUI::resize_event(int w, int h)
236 mwindow->session->cwindow_x = get_x();
237 mwindow->session->cwindow_y = get_y();
238 mwindow->session->cwindow_w = w;
239 mwindow->session->cwindow_h = h;
241 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
242 mwindow->theme->draw_cwindow_bg(this);
245 composite_panel->reposition_buttons(mwindow->theme->ccomposite_x,
246 mwindow->theme->ccomposite_y);
248 canvas->reposition_window(mwindow->edl,
249 mwindow->theme->ccanvas_x,
250 mwindow->theme->ccanvas_y,
251 mwindow->theme->ccanvas_w,
252 mwindow->theme->ccanvas_h);
254 timebar->resize_event();
257 slider->reposition_window(mwindow->theme->cslider_x,
258 mwindow->theme->cslider_y,
259 mwindow->theme->cslider_w);
260 // Recalibrate pointer motion range
261 slider->set_position();
264 transport->reposition_buttons(mwindow->theme->ctransport_x,
265 mwindow->theme->ctransport_y);
267 edit_panel->reposition_buttons(mwindow->theme->cedit_x,
268 mwindow->theme->cedit_y);
270 // clock->reposition_window(mwindow->theme->ctime_x,
271 // mwindow->theme->ctime_y);
273 zoom_panel->reposition_window(mwindow->theme->czoom_x,
274 mwindow->theme->czoom_y);
276 // destination->reposition_window(mwindow->theme->cdest_x,
277 // mwindow->theme->cdest_y);
279 meters->reposition_window(mwindow->theme->cmeter_x,
280 mwindow->theme->cmeter_y,
282 mwindow->theme->cmeter_h);
286 BC_WindowBase::resize_event(w, h);
290 int CWindowGUI::button_press_event()
292 if(canvas->get_canvas())
293 return canvas->button_press_event_base(canvas->get_canvas());
297 int CWindowGUI::cursor_leave_event()
299 if(canvas->get_canvas())
300 return canvas->cursor_leave_event_base(canvas->get_canvas());
304 int CWindowGUI::cursor_enter_event()
306 if(canvas->get_canvas())
307 return canvas->cursor_enter_event_base(canvas->get_canvas());
311 int CWindowGUI::button_release_event()
313 if(canvas->get_canvas())
314 return canvas->button_release_event();
318 int CWindowGUI::cursor_motion_event()
320 if(canvas->get_canvas())
322 canvas->get_canvas()->unhide_cursor();
323 return canvas->cursor_motion_event();
334 void CWindowGUI::draw_status(int flush)
336 if( (canvas->get_canvas() && canvas->get_canvas()->get_video_on()) ||
337 canvas->is_processing )
340 mwindow->theme->cstatus_x,
341 mwindow->theme->cstatus_y);
345 draw_pixmap(inactive,
346 mwindow->theme->cstatus_x,
347 mwindow->theme->cstatus_y);
351 // printf("CWindowGUI::draw_status %d %d %d\n", __LINE__, mwindow->theme->cstatus_x,
352 // mwindow->theme->cstatus_y);
353 flash(mwindow->theme->cstatus_x,
354 mwindow->theme->cstatus_y,
361 void CWindowGUI::zoom_canvas(int do_auto, double value, int update_menu)
364 mwindow->edl->session->cwindow_scrollbars = 0;
366 mwindow->edl->session->cwindow_scrollbars = 1;
368 float old_zoom = mwindow->edl->session->cwindow_zoom;
369 float new_zoom = value;
370 float x = canvas->w / 2.0;
371 float y = canvas->h / 2.0;
372 canvas->canvas_to_output(mwindow->edl,
376 x -= canvas->w_visible / 2 * old_zoom / new_zoom;
377 y -= canvas->h_visible / 2 * old_zoom / new_zoom;
382 zoom_panel->update(AUTO_ZOOM);
386 zoom_panel->update(value);
390 canvas->update_zoom((int)x,
393 canvas->reposition_window(mwindow->edl,
394 mwindow->theme->ccanvas_x,
395 mwindow->theme->ccanvas_y,
396 mwindow->theme->ccanvas_w,
397 mwindow->theme->ccanvas_h);
398 canvas->draw_refresh();
403 void CWindowGUI::set_operation(int value)
405 mwindow->edl->session->cwindow_operation = value;
407 composite_panel->set_operation(value);
408 edit_panel->update();
410 tool_panel->start_tool(value);
411 canvas->draw_refresh();
414 void CWindowGUI::update_tool()
416 tool_panel->update_values();
419 int CWindowGUI::close_event()
421 cwindow->hide_window();
426 int CWindowGUI::keypress_event()
430 switch(get_keypress())
448 if(mwindow->session->cwindow_fullscreen)
449 canvas->stop_fullscreen();
451 canvas->start_fullscreen();
452 lock_window("CWindowGUI::keypress_event 1");
456 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
458 mwindow->gui->unlock_window();
459 lock_window("CWindowGUI::keypress_event 2");
463 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
464 mwindow->clear_entry();
465 mwindow->gui->unlock_window();
466 lock_window("CWindowGUI::keypress_event 3");
470 if(mwindow->session->cwindow_fullscreen)
471 canvas->stop_fullscreen();
472 lock_window("CWindowGUI::keypress_event 4");
479 int shift_down = this->shift_down();
481 mwindow->gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
483 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
484 mwindow->prev_edit_handle(shift_down);
485 mwindow->gui->unlock_window();
487 lock_window("CWindowGUI::keypress_event 1");
493 mwindow->gui->lock_window("CWindowGUI::keypress_event 3");
494 mwindow->move_left();
495 mwindow->gui->unlock_window();
497 lock_window("CWindowGUI::keypress_event 2");
507 int shift_down = this->shift_down();
509 mwindow->gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
511 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
512 mwindow->next_edit_handle(shift_down);
513 mwindow->gui->unlock_window();
515 lock_window("CWindowGUI::keypress_event 2");
521 mwindow->gui->lock_window("CWindowGUI::keypress_event 4");
522 mwindow->move_right();
523 mwindow->gui->unlock_window();
525 lock_window("CWindowGUI::keypress_event 3");
532 if(!result) result = transport->keypress_event();
538 void CWindowGUI::reset_affected()
545 void CWindowGUI::keyboard_zoomin()
547 // if(mwindow->edl->session->cwindow_scrollbars)
549 zoom_panel->zoom_tumbler->handle_up_event();
556 void CWindowGUI::keyboard_zoomout()
558 // if(mwindow->edl->session->cwindow_scrollbars)
560 zoom_panel->zoom_tumbler->handle_down_event();
568 void CWindowGUI::drag_motion()
570 if(get_hidden()) return;
572 if(mwindow->session->current_operation == DRAG_ASSET ||
573 mwindow->session->current_operation == DRAG_VTRANSITION ||
574 mwindow->session->current_operation == DRAG_VEFFECT)
576 int old_status = mwindow->session->ccanvas_highlighted;
577 int cursor_x = get_relative_cursor_x();
578 int cursor_y = get_relative_cursor_y();
580 mwindow->session->ccanvas_highlighted = get_cursor_over_window() &&
581 cursor_x >= canvas->x &&
582 cursor_x < canvas->x + canvas->w &&
583 cursor_y >= canvas->y &&
584 cursor_y < canvas->y + canvas->h;
587 if(old_status != mwindow->session->ccanvas_highlighted)
588 canvas->draw_refresh();
592 int CWindowGUI::drag_stop()
595 if(get_hidden()) return 0;
597 if((mwindow->session->current_operation == DRAG_ASSET ||
598 mwindow->session->current_operation == DRAG_VTRANSITION ||
599 mwindow->session->current_operation == DRAG_VEFFECT) &&
600 mwindow->session->ccanvas_highlighted)
603 mwindow->session->ccanvas_highlighted = 0;
604 canvas->draw_refresh();
610 if(mwindow->session->current_operation == DRAG_ASSET)
612 if(mwindow->session->drag_assets->total ||
613 mwindow->session->drag_clips->total)
615 mwindow->gui->lock_window("CWindowGUI::drag_stop 5");
616 mwindow->undo->update_undo_before(_("insert assets"), 0);
617 mwindow->gui->unlock_window();
620 if(mwindow->session->drag_assets->total)
622 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
624 mwindow->load_assets(mwindow->session->drag_assets,
625 mwindow->edl->local_session->get_selectionstart(),
627 mwindow->session->track_highlighted,
629 mwindow->edl->session->labels_follow_edits,
630 mwindow->edl->session->plugins_follow_edits,
631 mwindow->edl->session->autos_follow_edits,
635 if(mwindow->session->drag_clips->total)
637 mwindow->gui->lock_window("CWindowGUI::drag_stop 2");
639 mwindow->paste_edls(mwindow->session->drag_clips,
641 mwindow->session->track_highlighted,
642 mwindow->edl->local_session->get_selectionstart(),
643 mwindow->edl->session->labels_follow_edits,
644 mwindow->edl->session->plugins_follow_edits,
645 mwindow->edl->session->autos_follow_edits,
649 if(mwindow->session->drag_assets->total ||
650 mwindow->session->drag_clips->total)
652 mwindow->save_backup();
653 mwindow->restart_brender();
654 mwindow->gui->update(1, 1, 1, 1, 0, 1, 0);
655 mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
656 mwindow->gui->unlock_window();
657 mwindow->sync_parameters(LOAD_ALL);
661 if(mwindow->session->current_operation == DRAG_VEFFECT)
663 //printf("CWindowGUI::drag_stop 1\n");
664 Track *affected_track = cwindow->calculate_affected_track();
665 //printf("CWindowGUI::drag_stop 2\n");
667 mwindow->gui->lock_window("CWindowGUI::drag_stop 3");
668 mwindow->insert_effects_cwindow(affected_track);
669 mwindow->session->current_operation = NO_OPERATION;
670 mwindow->gui->unlock_window();
673 if(mwindow->session->current_operation == DRAG_VTRANSITION)
675 Track *affected_track = cwindow->calculate_affected_track();
676 mwindow->gui->lock_window("CWindowGUI::drag_stop 4");
677 mwindow->paste_transition_cwindow(affected_track);
678 mwindow->session->current_operation = NO_OPERATION;
679 mwindow->gui->unlock_window();
685 void CWindowGUI::update_meters()
687 if(mwindow->edl->session->cwindow_meter != meters->visible)
689 meters->set_meters(meters->meter_count, mwindow->edl->session->cwindow_meter);
690 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
691 resize_event(get_w(), get_h());
696 CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
699 mwindow->theme->cedit_x,
700 mwindow->theme->cedit_y,
701 mwindow->edl->session->editing_mode,
720 this->mwindow = mwindow;
721 this->cwindow = cwindow;
724 #define CWrapper(fn) void CWindowEditing::fn() { \
725 mwindow->gui->lock_window("CWrapper::" #fn); \
727 mwindow->gui->unlock_window(); \
730 CWrapper(copy_selection)
731 CWrapper(splice_selection)
732 CWrapper(overwrite_selection)
733 CWrapper(set_inpoint)
734 CWrapper(set_outpoint)
735 CWrapper(clear_inpoint)
736 CWrapper(clear_outpoint)
738 CWrapper(toggle_label)
746 CWindowMeters::CWindowMeters(MWindow *mwindow,
751 : MeterPanel(mwindow,
757 mwindow->edl->session->audio_channels,
758 mwindow->edl->session->cwindow_meter,
762 this->mwindow = mwindow;
766 CWindowMeters::~CWindowMeters()
770 int CWindowMeters::change_status_event(int new_status)
772 mwindow->edl->session->cwindow_meter = new_status;
773 gui->update_meters();
780 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
783 (double)mwindow->edl->session->cwindow_zoom,
791 this->mwindow = mwindow;
795 CWindowZoom::~CWindowZoom()
799 int CWindowZoom::handle_event()
801 if(!strcasecmp(AUTO_ZOOM, get_text()))
803 gui->zoom_canvas(1, get_value(), 0);
807 gui->zoom_canvas(0, get_value(), 0);
816 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
817 : BC_PercentageSlider(x,
826 this->mwindow = mwindow;
827 this->cwindow = cwindow;
828 set_precision(0.00001);
831 CWindowSlider::~CWindowSlider()
835 int CWindowSlider::handle_event()
837 cwindow->update_position((double)get_value());
841 void CWindowSlider::set_position()
843 double new_length = mwindow->edl->tracks->total_playable_length();
844 // if(mwindow->edl->local_session->preview_end <= 0 ||
845 // mwindow->edl->local_session->preview_end > new_length)
846 // mwindow->edl->local_session->preview_end = new_length;
847 // if(mwindow->edl->local_session->preview_start >
848 // mwindow->edl->local_session->preview_end)
849 // mwindow->edl->local_session->preview_start = 0;
852 update(mwindow->theme->cslider_w,
853 mwindow->edl->local_session->get_selectionstart(1),
856 // mwindow->edl->local_session->preview_start,
857 // mwindow->edl->local_session->preview_end);
861 int CWindowSlider::increase_value()
864 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
865 lock_window("CWindowSlider::increase_value");
869 int CWindowSlider::decrease_value()
872 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
873 lock_window("CWindowSlider::decrease_value");
878 // CWindowDestination::CWindowDestination(MWindow *mwindow, CWindowGUI *cwindow, int x, int y)
879 // : BC_PopupTextBox(cwindow,
880 // &cwindow->destinations,
881 // cwindow->destinations.values[cwindow->cwindow->destination]->get_text(),
887 // this->mwindow = mwindow;
888 // this->cwindow = cwindow;
891 // CWindowDestination::~CWindowDestination()
895 // int CWindowDestination::handle_event()
906 CWindowTransport::CWindowTransport(MWindow *mwindow,
910 : PlayTransport(mwindow,
918 EDL* CWindowTransport::get_edl()
923 void CWindowTransport::goto_start()
925 gui->unlock_window();
926 handle_transport(REWIND, 1);
928 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
929 mwindow->goto_start();
930 mwindow->gui->unlock_window();
932 gui->lock_window("CWindowTransport::goto_start 2");
935 void CWindowTransport::goto_end()
937 gui->unlock_window();
938 handle_transport(GOTO_END, 1);
940 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
942 mwindow->gui->unlock_window();
944 gui->lock_window("CWindowTransport::goto_end 2");
949 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
952 mwindow->theme->ccanvas_x,
953 mwindow->theme->ccanvas_y,
954 mwindow->theme->ccanvas_w,
955 mwindow->theme->ccanvas_h,
958 mwindow->edl->session->cwindow_scrollbars)
960 this->mwindow = mwindow;
964 void CWindowCanvas::status_event()
969 int CWindowCanvas::get_fullscreen()
971 return mwindow->session->cwindow_fullscreen;
974 void CWindowCanvas::set_fullscreen(int value)
976 mwindow->session->cwindow_fullscreen = value;
980 void CWindowCanvas::update_zoom(int x, int y, float zoom)
982 use_scrollbars = mwindow->edl->session->cwindow_scrollbars;
984 mwindow->edl->session->cwindow_xscroll = x;
985 mwindow->edl->session->cwindow_yscroll = y;
986 mwindow->edl->session->cwindow_zoom = zoom;
989 void CWindowCanvas::zoom_auto()
991 gui->zoom_canvas(1, 1.0, 1);
994 int CWindowCanvas::get_xscroll()
996 return mwindow->edl->session->cwindow_xscroll;
999 int CWindowCanvas::get_yscroll()
1001 return mwindow->edl->session->cwindow_yscroll;
1005 float CWindowCanvas::get_zoom()
1007 return mwindow->edl->session->cwindow_zoom;
1010 void CWindowCanvas::draw_refresh(int flush)
1012 if(get_canvas() && !get_canvas()->get_video_on())
1015 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
1017 float in_x1, in_y1, in_x2, in_y2;
1018 float out_x1, out_y1, out_x2, out_y2;
1019 get_transfers(mwindow->edl,
1029 if(!EQUIV(out_x1, 0) ||
1030 !EQUIV(out_y1, 0) ||
1031 !EQUIV(out_x2, get_canvas()->get_w()) ||
1032 !EQUIV(out_y2, get_canvas()->get_h()))
1034 get_canvas()->clear_box(0,
1036 get_canvas()->get_w(),
1037 get_canvas()->get_h());
1040 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1041 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1044 if(out_x2 > out_x1 &&
1049 // Can't use OpenGL here because it is called asynchronously of the
1050 // playback operation.
1051 get_canvas()->draw_vframe(refresh_frame,
1054 (int)(out_x2 - out_x1),
1055 (int)(out_y2 - out_y1),
1058 (int)(in_x2 - in_x1),
1059 (int)(in_y2 - in_y1),
1065 get_canvas()->clear_box(0,
1067 get_canvas()->get_w(),
1068 get_canvas()->get_h());
1072 get_canvas()->flash(flush);
1074 //printf("CWindowCanvas::draw_refresh 10\n");
1077 #define CROPHANDLE_W 10
1078 #define CROPHANDLE_H 10
1080 void CWindowCanvas::draw_crophandle(int x, int y)
1082 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1090 #define CONTROL_W 10
1091 #define CONTROL_H 10
1092 #define FIRST_CONTROL_W 20
1093 #define FIRST_CONTROL_H 20
1095 #define BC_INFINITY 65536
1097 #define RULERHANDLE_W 16
1098 #define RULERHANDLE_H 16
1102 int CWindowCanvas::do_ruler(int draw,
1108 float x1 = mwindow->edl->session->ruler_x1;
1109 float y1 = mwindow->edl->session->ruler_y1;
1110 float x2 = mwindow->edl->session->ruler_x2;
1111 float y2 = mwindow->edl->session->ruler_y2;
1112 float canvas_x1 = x1;
1113 float canvas_y1 = y1;
1114 float canvas_x2 = x2;
1115 float canvas_y2 = y2;
1116 float output_x = get_cursor_x();
1117 float output_y = get_cursor_y();
1118 float canvas_cursor_x = output_x;
1119 float canvas_cursor_y = output_y;
1121 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1122 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1123 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1124 mwindow->session->cwindow_output_x = roundf(output_x);
1125 mwindow->session->cwindow_output_y = roundf(output_y);
1127 if(button_press && get_buttonpress() == 1)
1129 gui->ruler_handle = -1;
1130 gui->ruler_translate = 0;
1133 gui->ruler_translate = 1;
1134 gui->ruler_origin_x = x1;
1135 gui->ruler_origin_y = y1;
1138 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1139 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1140 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1141 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1143 gui->ruler_handle = 0;
1144 gui->ruler_origin_x = x1;
1145 gui->ruler_origin_y = y1;
1148 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1149 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1150 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1151 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1153 gui->ruler_handle = 1;
1154 gui->ruler_origin_x = x2;
1155 gui->ruler_origin_y = y2;
1159 // Start new selection
1160 if(!gui->ruler_translate &&
1161 (gui->ruler_handle < 0 ||
1166 do_ruler(1, 0, 0, 0);
1167 get_canvas()->flash();
1168 gui->ruler_handle = 1;
1169 mwindow->edl->session->ruler_x1 = output_x;
1170 mwindow->edl->session->ruler_y1 = output_y;
1171 mwindow->edl->session->ruler_x2 = output_x;
1172 mwindow->edl->session->ruler_y2 = output_y;
1173 gui->ruler_origin_x = mwindow->edl->session->ruler_x2;
1174 gui->ruler_origin_y = mwindow->edl->session->ruler_y2;
1177 gui->x_origin = output_x;
1178 gui->y_origin = output_y;
1179 gui->current_operation = CWINDOW_RULER;
1180 gui->tool_panel->raise_window();
1186 if(gui->current_operation == CWINDOW_RULER)
1188 if(gui->ruler_translate)
1191 do_ruler(1, 0, 0, 0);
1192 float x_difference = mwindow->edl->session->ruler_x1;
1193 float y_difference = mwindow->edl->session->ruler_y1;
1194 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1195 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1196 x_difference -= mwindow->edl->session->ruler_x1;
1197 y_difference -= mwindow->edl->session->ruler_y1;
1198 mwindow->edl->session->ruler_x2 -= x_difference;
1199 mwindow->edl->session->ruler_y2 -= y_difference;
1201 do_ruler(1, 0, 0, 0);
1202 get_canvas()->flash();
1206 switch(gui->ruler_handle)
1209 do_ruler(1, 0, 0, 0);
1210 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1211 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1212 if(gui->alt_down() || gui->ctrl_down())
1214 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1215 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1219 double distance_value =
1220 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1221 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1222 if(angle_value < 22)
1223 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2;
1225 if(angle_value > 67)
1226 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2;
1228 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 &&
1229 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1231 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1232 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1235 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 && mwindow->edl->session->ruler_y1 > mwindow->edl->session->ruler_y2)
1237 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1238 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1241 if(mwindow->edl->session->ruler_x1 > mwindow->edl->session->ruler_x2 &&
1242 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1244 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1245 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1249 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1250 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1253 do_ruler(1, 0, 0, 0);
1254 get_canvas()->flash();
1259 do_ruler(1, 0, 0, 0);
1260 mwindow->edl->session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1261 mwindow->edl->session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1262 if(gui->alt_down() || gui->ctrl_down())
1264 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1265 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1269 double distance_value =
1270 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1271 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1272 if(angle_value < 22)
1273 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1;
1275 if(angle_value > 67)
1276 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1;
1278 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1279 mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1281 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1282 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1285 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1286 mwindow->edl->session->ruler_y2 > mwindow->edl->session->ruler_y1)
1288 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1289 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1292 if(mwindow->edl->session->ruler_x2 > mwindow->edl->session->ruler_x1 && mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1294 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1295 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1299 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1300 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1303 do_ruler(1, 0, 0, 0);
1304 get_canvas()->flash();
1308 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1312 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1317 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1318 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1319 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1320 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1322 set_cursor(UPRIGHT_ARROW_CURSOR);
1325 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1326 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1327 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1328 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1330 set_cursor(UPRIGHT_ARROW_CURSOR);
1333 set_cursor(CROSS_CURSOR);
1335 // Update current position
1340 // Assume no ruler measurement if 0 length
1341 if(draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)))
1343 get_canvas()->set_inverse();
1344 get_canvas()->set_color(WHITE);
1345 get_canvas()->draw_line((int)canvas_x1,
1349 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1351 roundf(canvas_x1) + RULERHANDLE_W / 2,
1353 get_canvas()->draw_line(roundf(canvas_x1),
1354 roundf(canvas_y1) - RULERHANDLE_H / 2,
1356 roundf(canvas_y1) + RULERHANDLE_H / 2);
1357 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1359 roundf(canvas_x2) + RULERHANDLE_W / 2,
1361 get_canvas()->draw_line(roundf(canvas_x2),
1362 roundf(canvas_y2) - RULERHANDLE_H / 2,
1364 roundf(canvas_y2) + RULERHANDLE_H / 2);
1365 get_canvas()->set_opaque();
1372 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1374 return (llabs(cx-tx) < (CONTROL_W/2) && llabs(cy-ty) < (CONTROL_H/2));
1377 static inline double line_dist(float cx,float cy, float tx,float ty)
1379 int dx = tx-cx, dy = ty-cy;
1380 return sqrt(dx*dx + dy*dy);
1384 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1385 int button_press, int cursor_motion, int draw)
1387 // Retrieve points from top recordable track
1388 //printf("CWindowCanvas::do_mask 1\n");
1389 Track *track = gui->cwindow->calculate_affected_track();
1390 //printf("CWindowCanvas::do_mask 2\n");
1392 if(!track) return 0;
1393 //printf("CWindowCanvas::do_mask 3\n");
1395 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1396 int64_t position = track->to_units(
1397 mwindow->edl->local_session->get_selectionstart(1),
1399 ArrayList<MaskPoint*> points;
1401 // Determine the points based on whether
1402 // new keyframes will be generated or drawing is performed.
1403 // If keyframe generation occurs, use the interpolated mask.
1404 // If no keyframe generation occurs, use the previous mask.
1405 int use_interpolated = 0;
1406 if(button_press || cursor_motion) {
1407 #ifdef USE_KEYFRAME_SPANNING
1408 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1409 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1412 mask_autos->get_prev_auto(track->to_units(selection_start, 0),
1413 PLAY_FORWARD, first, 1);
1415 mask_autos->get_prev_auto(track->to_units(selection_end, 0),
1416 PLAY_FORWARD, last, 1);
1418 if(last == first && (!mwindow->edl->session->auto_keyframes))
1419 use_interpolated = 0;
1421 // If keyframe spanning occurs, use the interpolated points.
1422 // If new keyframe is generated, use the interpolated points.
1423 use_interpolated = 1;
1426 if(mwindow->edl->session->auto_keyframes)
1427 use_interpolated = 1;
1431 use_interpolated = 1;
1433 if(use_interpolated) {
1434 // Interpolate the points to get exactly what is being rendered at this position.
1435 mask_autos->get_points(&points,
1436 mwindow->edl->session->cwindow_mask,
1441 // Use the prev mask
1443 mask_autos->get_prev_auto(position,
1447 ((MaskAuto*)prev)->get_points(&points,
1448 mwindow->edl->session->cwindow_mask);
1451 // Projector zooms relative to the center of the track output.
1452 float half_track_w = (float)track->track_w / 2;
1453 float half_track_h = (float)track->track_h / 2;
1454 // Translate mask to projection
1455 float projector_x, projector_y, projector_z;
1456 track->automation->get_projector(
1457 &projector_x, &projector_y, &projector_z,
1458 position, PLAY_FORWARD);
1461 // Get position of cursor relative to mask
1462 float cursor_x = get_cursor_x();
1463 float cursor_y = get_cursor_y();
1464 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
1466 projector_x += mwindow->edl->session->output_w / 2;
1467 projector_y += mwindow->edl->session->output_h / 2;
1469 float mask_cursor_x = (cursor_x - projector_x) / projector_z + half_track_w;
1470 float mask_cursor_y = (cursor_y - projector_y) / projector_z + half_track_h;
1472 // Fix cursor origin
1474 gui->x_origin = mask_cursor_x;
1475 gui->y_origin = mask_cursor_y;
1479 // Points of closest line
1480 int shortest_point1 = -1;
1481 int shortest_point2 = -1;
1483 int shortest_point = -1;
1484 // Distance to closest line
1485 float shortest_line_distance = BC_INFINITY;
1486 // Distance to closest point
1487 float shortest_point_distance = BC_INFINITY;
1488 int selected_point = -1;
1489 int selected_control_point = -1;
1490 float selected_control_point_distance = BC_INFINITY;
1491 ArrayList<int> x_points;
1492 ArrayList<int> y_points;
1494 if(!cursor_motion) {
1496 get_canvas()->set_color(WHITE);
1497 get_canvas()->set_inverse();
1499 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1501 // Never draw closed polygon and a closed
1502 // polygon is harder to add points to.
1503 for(int i = 0; i < points.size() && !result; i++) {
1504 MaskPoint *point1 = points.get(i);
1505 MaskPoint *point2 = (i >= points.size() - 1) ?
1506 points.get(0) : points.get(i + 1);
1508 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1509 if(point_distance1 < shortest_point_distance || shortest_point < 0) {
1510 shortest_point_distance = point_distance1;
1514 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1515 if(point_distance2 < shortest_point_distance || shortest_point < 0) {
1516 shortest_point_distance = point_distance2;
1517 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1521 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1523 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1524 //point1->x, point1->y, point2->x, point2->y, projector_z);
1525 for(int j = 0; j <= segments && !result; j++) {
1526 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1527 float x0 = point1->x, y0 = point1->y;
1528 float x1 = point1->x + point1->control_x2;
1529 float y1 = point1->y + point1->control_y2;
1530 float x2 = point2->x + point2->control_x1;
1531 float y2 = point2->y + point2->control_y1;
1532 float x3 = point2->x, y3 = point2->y;
1534 float t = (float)j / segments;
1535 float tpow2 = t * t;
1536 float tpow3 = t * t * t;
1538 float invtpow2 = invt * invt;
1539 float invtpow3 = invt * invt * invt;
1541 float x = ( invtpow3 * x0
1542 + 3 * t * invtpow2 * x1
1543 + 3 * tpow2 * invt * x2
1545 float y = ( invtpow3 * y0
1546 + 3 * t * invtpow2 * y1
1547 + 3 * tpow2 * invt * y2
1550 x = (x - half_track_w) * projector_z + projector_x;
1551 y = (y - half_track_h) * projector_z + projector_y;
1552 // Test new point addition
1554 float line_distance = line_dist(x,y, cursor_x,cursor_y);
1556 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1557 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1558 if(line_distance < shortest_line_distance ||
1559 shortest_point1 < 0) {
1560 shortest_line_distance = line_distance;
1561 shortest_point1 = i;
1562 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1563 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1564 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1567 // Test existing point selection
1568 float canvas_x = (x0 - half_track_w) * projector_z + projector_x;
1569 float canvas_y = (y0 - half_track_h) * projector_z + projector_y;
1571 if(gui->shift_down()) {
1572 float control_x = (x1 - half_track_w) * projector_z + projector_x;
1573 float control_y = (y1 - half_track_h) * projector_z + projector_y;
1574 float distance = line_dist(control_x,control_y, cursor_x,cursor_y);
1576 if(distance < selected_control_point_distance) {
1578 selected_control_point = 1;
1579 selected_control_point_distance = distance;
1583 if(!gui->ctrl_down()) {
1584 if(test_bbox(cursor_x, cursor_y, canvas_x, canvas_y)) {
1589 selected_point = shortest_point;
1592 // Test second point
1593 canvas_x = (x3 - half_track_w) * projector_z + projector_x;
1594 canvas_y = (y3 - half_track_h) * projector_z + projector_y;
1596 if(gui->shift_down()) {
1597 float control_x = (x2 - half_track_w) * projector_z + projector_x;
1598 float control_y = (y2 - half_track_h) * projector_z + projector_y;
1599 float distance = line_dist(control_x,control_y, cursor_x,cursor_y);
1601 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1602 if(distance < selected_control_point_distance) {
1603 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1604 selected_control_point = 0;
1605 selected_control_point_distance = distance;
1608 else if(i < points.size() - 1) {
1609 if(!gui->ctrl_down()) {
1610 if(test_bbox(cursor_x, cursor_y, canvas_x, canvas_y)) {
1611 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1615 selected_point = shortest_point;
1621 output_to_canvas(mwindow->edl, 0, x, y);
1625 if(draw) { // Draw joining line
1626 x_points.append((int)x);
1627 y_points.append((int)y);
1631 if(draw) { // Draw second anchor
1632 if(i < points.size() - 1) {
1633 if(i == gui->affected_point - 1)
1634 get_canvas()->draw_disc(
1635 (int)x - CONTROL_W / 2,
1636 (int)y - CONTROL_W / 2,
1637 CONTROL_W, CONTROL_H);
1639 get_canvas()->draw_circle(
1640 (int)x - CONTROL_W / 2,
1641 (int)y - CONTROL_W / 2,
1642 CONTROL_W, CONTROL_H);
1643 // char string[BCTEXTLEN];
1644 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1645 // canvas->draw_text((int)x + CONTROL_W, (int)y + CONTROL_W, string);
1648 // Draw second control point. Discard x2 and y2 after this.
1649 x2 = (x2 - half_track_w) * projector_z + projector_x;
1650 y2 = (y2 - half_track_h) * projector_z + projector_y;
1651 output_to_canvas(mwindow->edl, 0, x2, y2);
1652 get_canvas()->draw_line((int)x, (int)y, (int)x2, (int)y2);
1653 get_canvas()->draw_rectangle(
1654 (int)x2 - CONTROL_W / 2,
1655 (int)y2 - CONTROL_H / 2,
1656 CONTROL_W, CONTROL_H);
1661 // Draw first anchor
1662 if(i == 0 && draw) {
1663 char mask_label[BCSTRLEN];
1664 sprintf(mask_label, "%d",
1665 mwindow->edl->session->cwindow_mask);
1666 get_canvas()->draw_text(
1667 (int)x - FIRST_CONTROL_W,
1668 (int)y - FIRST_CONTROL_H,
1671 get_canvas()->draw_disc(
1672 (int)x - FIRST_CONTROL_W / 2,
1673 (int)y - FIRST_CONTROL_H / 2,
1674 FIRST_CONTROL_W, FIRST_CONTROL_H);
1677 // Draw first control point. Discard x1 and y1 after this.
1679 x1 = (x1 - half_track_w) * projector_z + projector_x;
1680 y1 = (y1 - half_track_h) * projector_z + projector_y;
1681 output_to_canvas(mwindow->edl, 0, x1, y1);
1682 get_canvas()->draw_line((int)x, (int)y, (int)x1, (int)y1);
1683 get_canvas()->draw_rectangle(
1684 (int)x1 - CONTROL_W / 2,
1685 (int)y1 - CONTROL_H / 2,
1686 CONTROL_W, CONTROL_H);
1688 x_points.append((int)x);
1689 y_points.append((int)y);
1692 //printf("CWindowCanvas::do_mask 1\n");
1696 //printf("CWindowCanvas::do_mask 1\n");
1699 get_canvas()->draw_polygon(&x_points, &y_points);
1700 get_canvas()->set_opaque();
1702 //printf("CWindowCanvas::do_mask 1\n");
1705 if(button_press && !result) {
1706 gui->affected_track = gui->cwindow->calculate_affected_track();
1708 // Get keyframe outside the EDL to edit. This must be rendered
1709 // instead of the EDL keyframes when it exists. Then it must be
1710 // applied to the EDL keyframes on buttonrelease.
1711 if(gui->affected_track) {
1712 #ifdef USE_KEYFRAME_SPANNING
1713 // Make copy of current parameters in local keyframe
1714 gui->mask_keyframe =
1715 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1718 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1721 gui->mask_keyframe =
1722 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1727 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1730 // Translate entire keyframe
1731 if(gui->alt_down() && mask->points.size()) {
1732 mwindow->undo->update_undo_before(_("mask translate"), 0);
1733 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1734 gui->affected_point = 0;
1737 // Existing point or control point was selected
1738 if(selected_point >= 0) {
1739 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1740 gui->affected_point = selected_point;
1742 if(selected_control_point == 0)
1743 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1745 if(selected_control_point == 1)
1746 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1748 gui->current_operation = mwindow->edl->session->cwindow_operation;
1750 else // No existing point or control point was selected so create a new one
1751 if(!gui->shift_down() && !gui->alt_down()) {
1752 mwindow->undo->update_undo_before(_("mask point"), 0);
1753 // Create the template
1754 MaskPoint *point = new MaskPoint;
1755 point->x = mask_cursor_x;
1756 point->y = mask_cursor_y;
1757 point->control_x1 = 0;
1758 point->control_y1 = 0;
1759 point->control_x2 = 0;
1760 point->control_y2 = 0;
1763 if(shortest_point2 < shortest_point1) {
1764 shortest_point2 ^= shortest_point1;
1765 shortest_point1 ^= shortest_point2;
1766 shortest_point2 ^= shortest_point1;
1771 // printf("CWindowGUI::do_mask 40\n");
1772 // mwindow->edl->dump();
1773 // printf("CWindowGUI::do_mask 50\n");
1777 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1778 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1779 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1781 // Append to end of list
1782 if(labs(shortest_point1 - shortest_point2) > 1) {
1783 #ifdef USE_KEYFRAME_SPANNING
1785 MaskPoint *new_point = new MaskPoint;
1786 points.append(new_point);
1787 *new_point = *point;
1788 gui->affected_point = points.size() - 1;
1792 // Need to apply the new point to every keyframe
1793 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1794 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1795 MaskPoint *new_point = new MaskPoint;
1796 submask->points.append(new_point);
1797 *new_point = *point;
1798 if(current == (MaskAuto*)mask_autos->default_auto)
1799 current = (MaskAuto*)mask_autos->first;
1801 current = (MaskAuto*)NEXT;
1803 gui->affected_point = mask->points.size() - 1;
1809 // Insert between 2 points, shifting back point 2
1810 if(shortest_point1 >= 0 && shortest_point2 >= 0) {
1812 #ifdef USE_KEYFRAME_SPANNING
1813 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1815 if(points.size() >= shortest_point2) {
1816 MaskPoint *new_point = new MaskPoint;
1818 for(int i = points.size() - 1;
1819 i > shortest_point2;
1821 points.values[i] = points.values[i - 1];
1822 points.values[shortest_point2] = new_point;
1824 *new_point = *point;
1829 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1830 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1831 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1833 if(submask->points.size() >= shortest_point2) {
1834 MaskPoint *new_point = new MaskPoint;
1835 submask->points.append(0);
1836 for(int i = submask->points.size() - 1;
1837 i > shortest_point2;
1839 submask->points.values[i] = submask->points.values[i - 1];
1840 submask->points.values[shortest_point2] = new_point;
1842 *new_point = *point;
1845 if(current == (MaskAuto*)mask_autos->default_auto)
1846 current = (MaskAuto*)mask_autos->first;
1848 current = (MaskAuto*)NEXT;
1852 gui->affected_point = shortest_point2;
1857 // printf("CWindowGUI::do_mask 20\n");
1858 // mwindow->edl->dump();
1859 // printf("CWindowGUI::do_mask 30\n");
1862 //printf("CWindowCanvas::do_mask 1\n");
1863 // Create the first point.
1864 #ifdef USE_KEYFRAME_SPANNING
1865 MaskPoint *new_point = new MaskPoint;
1866 points.append(new_point);
1867 *new_point = *point;
1869 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1870 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1871 MaskPoint *new_point = new MaskPoint;
1872 submask->points.append(new_point);
1873 *new_point = *point;
1874 if(current == (MaskAuto*)mask_autos->default_auto)
1875 current = (MaskAuto*)mask_autos->first;
1877 current = (MaskAuto*)NEXT;
1881 //printf("CWindowCanvas::do_mask 2\n");
1882 // Create a second point if none existed before
1883 #ifdef USE_KEYFRAME_SPANNING
1884 if(points.size() < 2) {
1886 MaskPoint *new_point = new MaskPoint;
1887 points.append(new_point);
1888 *new_point = *point;
1891 gui->affected_point = points.size() - 1;
1893 if(mask->points.size() < 2) {
1895 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1896 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1897 MaskPoint *new_point = new MaskPoint;
1898 submask->points.append(new_point);
1899 *new_point = *point;
1900 if(current == (MaskAuto*)mask_autos->default_auto)
1901 current = (MaskAuto*)mask_autos->first;
1903 current = (MaskAuto*)NEXT;
1907 gui->affected_point = mask->points.size() - 1;
1910 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
1913 gui->current_operation = mwindow->edl->session->cwindow_operation;
1914 // Delete the template
1923 if(button_press && result) {
1924 #ifdef USE_KEYFRAME_SPANNING
1925 MaskPoint *point = points.values[gui->affected_point];
1926 gui->center_x = point->x;
1927 gui->center_y = point->y;
1928 gui->control_in_x = point->control_x1;
1929 gui->control_in_y = point->control_y1;
1930 gui->control_out_x = point->control_x2;
1931 gui->control_out_y = point->control_y2;
1932 gui->tool_panel->raise_window();
1934 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1935 MaskPoint *point = mask->points.values[gui->affected_point];
1936 gui->center_x = point->x;
1937 gui->center_y = point->y;
1938 gui->control_in_x = point->control_x1;
1939 gui->control_in_y = point->control_y1;
1940 gui->control_out_x = point->control_x2;
1941 gui->control_out_y = point->control_y2;
1942 gui->tool_panel->raise_window();
1946 //printf("CWindowCanvas::do_mask 8\n");
1949 #ifdef USE_KEYFRAME_SPANNING
1950 // Must update the reference keyframes for every cursor motion
1951 gui->mask_keyframe =
1952 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1955 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1958 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1960 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1961 if(gui->affected_point < mask->points.size() &&
1962 gui->current_operation != CWINDOW_NONE) {
1963 // mwindow->undo->update_undo_before(_("mask point"), this);
1964 #ifdef USE_KEYFRAME_SPANNING
1965 MaskPoint *point = points.get(gui->affected_point);
1967 MaskPoint *point = mask->points.get(gui->affected_point);
1969 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
1970 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask->points.size(), gui->affected_point);
1972 float last_x = point->x;
1973 float last_y = point->y;
1974 float last_control_x1 = point->control_x1;
1975 float last_control_y1 = point->control_y1;
1976 float last_control_x2 = point->control_x2;
1977 float last_control_y2 = point->control_y2;
1979 switch(gui->current_operation) {
1981 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1982 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
1983 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
1986 case CWINDOW_MASK_CONTROL_IN:
1987 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
1988 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
1991 case CWINDOW_MASK_CONTROL_OUT:
1992 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
1993 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
1996 case CWINDOW_MASK_TRANSLATE:
1997 #ifdef USE_KEYFRAME_SPANNING
1998 for(int i = 0; i < points.size(); i++) {
1999 points.values[i]->x += mask_cursor_x - gui->x_origin;
2000 points.values[i]->y += mask_cursor_y - gui->y_origin;
2003 for(int i = 0; i < mask->points.size(); i++) {
2004 mask->points.values[i]->x += mask_cursor_x - gui->x_origin;
2005 mask->points.values[i]->y += mask_cursor_y - gui->y_origin;
2008 gui->x_origin = mask_cursor_x;
2009 gui->y_origin = mask_cursor_y;
2013 if( !EQUIV(last_x, point->x) ||
2014 !EQUIV(last_y, point->y) ||
2015 !EQUIV(last_control_x1, point->control_x1) ||
2016 !EQUIV(last_control_y1, point->control_y1) ||
2017 !EQUIV(last_control_x2, point->control_x2) ||
2018 !EQUIV(last_control_y2, point->control_y2)) {
2024 if(gui->current_operation == CWINDOW_NONE) {
2025 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
2027 for(int i = 0; i < points.size() && !over_point; i++) {
2028 MaskPoint *point = points.get(i);
2029 float x0 = point->x;
2030 float y0 = point->y;
2031 float x1 = point->x + point->control_x1;
2032 float y1 = point->y + point->control_y1;
2033 float x2 = point->x + point->control_x2;
2034 float y2 = point->y + point->control_y2;
2035 float canvas_x = (x0 - half_track_w) * projector_z + projector_x;
2036 float canvas_y = (y0 - half_track_h) * projector_z + projector_y;
2038 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
2039 if(test_bbox(cursor_x, cursor_y, canvas_x, canvas_y)) {
2043 if(!over_point && gui->shift_down()) {
2044 canvas_x = (x1 - half_track_w) * projector_z + projector_x;
2045 canvas_y = (y1 - half_track_h) * projector_z + projector_y;
2046 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
2047 if(test_bbox(cursor_x, cursor_y, canvas_x, canvas_y)) {
2051 canvas_x = (x2 - half_track_w) * projector_z + projector_x;
2052 canvas_y = (y2 - half_track_h) * projector_z + projector_y;
2053 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
2054 if(test_bbox(cursor_x, cursor_y, canvas_x, canvas_y)) {
2061 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2066 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2069 #ifdef USE_KEYFRAME_SPANNING
2070 // Must commit change after operation.
2071 if(rerender && track) {
2072 // Swap EDL keyframe with original.
2073 // Apply new values to keyframe span
2074 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2075 temp_keyframe.copy_data(gui->mask_keyframe);
2076 // Apply interpolated points back to keyframe
2077 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2078 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2079 mask_autos->update_parameter(&temp_keyframe);
2083 points.remove_all_objects();
2084 //printf("CWindowCanvas::do_mask 20\n");
2089 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2092 int radius = mwindow->edl->session->eyedrop_radius;
2100 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2105 row1 = gui->eyedrop_y - radius;
2106 row2 = gui->eyedrop_y + radius;
2107 column1 = gui->eyedrop_x - radius;
2108 column2 = gui->eyedrop_x + radius;
2110 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2111 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2112 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2113 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2115 if(row2 <= row1) row2 = row1 + 1;
2116 if(column2 <= column1) column2 = column1 + 1;
2123 output_to_canvas(mwindow->edl, 0, x1, y1);
2124 output_to_canvas(mwindow->edl, 0, x2, y2);
2125 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2127 if(x2 - x1 >= 1 && y2 - y1 >= 1)
2129 get_canvas()->set_inverse();
2130 get_canvas()->set_color(WHITE);
2132 get_canvas()->draw_rectangle((int)x1,
2137 get_canvas()->set_opaque();
2138 get_canvas()->flash();
2146 gui->current_operation = CWINDOW_EYEDROP;
2147 gui->tool_panel->raise_window();
2150 if(gui->current_operation == CWINDOW_EYEDROP)
2152 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2154 // Get color out of frame.
2155 // Doesn't work during playback because that bypasses the refresh frame.
2156 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2158 float cursor_x = get_cursor_x();
2159 float cursor_y = get_cursor_y();
2160 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2161 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2162 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2164 row1 = cursor_y - radius;
2165 row2 = cursor_y + radius;
2166 column1 = cursor_x - radius;
2167 column2 = cursor_x + radius;
2168 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2169 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2170 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2171 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2172 if(row2 <= row1) row2 = row1 + 1;
2173 if(column2 <= column1) column2 = column1 + 1;
2177 if(gui->eyedrop_visible)
2180 do_eyedrop(temp, 0, 1);
2181 gui->eyedrop_visible = 0;
2184 gui->eyedrop_x = cursor_x;
2185 gui->eyedrop_y = cursor_y;
2190 do_eyedrop(temp, 0, 1);
2191 gui->eyedrop_visible = 1;
2194 // Decompression coefficients straight out of jpeglib
2195 #define V_TO_R 1.40200
2196 #define V_TO_G -0.71414
2198 #define U_TO_G -0.34414
2199 #define U_TO_B 1.77200
2201 #define GET_COLOR(type, components, max, do_yuv) \
2203 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2205 float red = (float)*row++ / max; \
2206 float green = (float)*row++ / max; \
2207 float blue = (float)*row++ / max; \
2210 mwindow->edl->local_session->red += red + V_TO_R * (blue - 0.5); \
2211 mwindow->edl->local_session->green += red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
2212 mwindow->edl->local_session->blue += red + U_TO_B * (green - 0.5); \
2216 mwindow->edl->local_session->red += red; \
2217 mwindow->edl->local_session->green += green; \
2218 mwindow->edl->local_session->blue += blue; \
2224 mwindow->edl->local_session->red = 0;
2225 mwindow->edl->local_session->green = 0;
2226 mwindow->edl->local_session->blue = 0;
2227 for(int i = row1; i < row2; i++)
2229 for(int j = column1; j < column2; j++)
2231 switch(refresh_frame->get_color_model())
2234 GET_COLOR(unsigned char, 3, 0xff, 1);
2237 GET_COLOR(unsigned char, 4, 0xff, 1);
2240 GET_COLOR(uint16_t, 3, 0xffff, 1);
2242 case BC_YUVA16161616:
2243 GET_COLOR(uint16_t, 4, 0xffff, 1);
2246 GET_COLOR(unsigned char, 3, 0xff, 0);
2249 GET_COLOR(unsigned char, 4, 0xff, 0);
2252 GET_COLOR(float, 3, 1.0, 0);
2255 GET_COLOR(float, 4, 1.0, 0);
2261 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2262 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2263 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2268 mwindow->edl->local_session->red = 0;
2269 mwindow->edl->local_session->green = 0;
2270 mwindow->edl->local_session->blue = 0;
2271 gui->eyedrop_visible = 0;
2280 // Can't rerender since the color value is from the output of any effect it
2283 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2289 void CWindowCanvas::draw_overlays()
2291 if(mwindow->edl->session->safe_regions)
2293 draw_safe_regions();
2296 if(mwindow->edl->session->cwindow_scrollbars)
2298 // Always draw output rectangle
2299 float x1, y1, x2, y2;
2301 x2 = mwindow->edl->session->output_w;
2303 y2 = mwindow->edl->session->output_h;
2304 output_to_canvas(mwindow->edl, 0, x1, y1);
2305 output_to_canvas(mwindow->edl, 0, x2, y2);
2307 get_canvas()->set_inverse();
2308 get_canvas()->set_color(WHITE);
2310 get_canvas()->draw_rectangle((int)x1,
2315 get_canvas()->set_opaque();
2318 if(mwindow->session->ccanvas_highlighted)
2320 get_canvas()->set_color(WHITE);
2321 get_canvas()->set_inverse();
2322 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2323 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2324 get_canvas()->set_opaque();
2327 int temp1 = 0, temp2 = 0;
2328 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2329 switch(mwindow->edl->session->cwindow_operation)
2331 case CWINDOW_CAMERA:
2335 case CWINDOW_PROJECTOR:
2344 do_mask(temp1, temp2, 0, 0, 1);
2348 do_ruler(1, 0, 0, 0);
2351 case CWINDOW_EYEDROP:
2352 if(gui->eyedrop_visible)
2355 do_eyedrop(rerender, 0, 1);
2356 gui->eyedrop_visible = 1;
2362 void CWindowCanvas::draw_safe_regions()
2364 float action_x1, action_x2, action_y1, action_y2;
2365 float title_x1, title_x2, title_y1, title_y2;
2367 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2368 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2369 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2370 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2371 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2372 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2373 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2374 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2376 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2377 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2378 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2379 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2381 get_canvas()->set_inverse();
2382 get_canvas()->set_color(WHITE);
2384 get_canvas()->draw_rectangle((int)action_x1,
2386 (int)(action_x2 - action_x1),
2387 (int)(action_y2 - action_y1));
2388 get_canvas()->draw_rectangle((int)title_x1,
2390 (int)(title_x2 - title_x1),
2391 (int)(title_y2 - title_y1));
2393 get_canvas()->set_opaque();
2396 void CWindowCanvas::reset_keyframe(int do_camera)
2398 FloatAuto *x_keyframe = 0;
2399 FloatAuto *y_keyframe = 0;
2400 FloatAuto *z_keyframe = 0;
2401 Track *affected_track = 0;
2403 affected_track = gui->cwindow->calculate_affected_track();
2407 gui->cwindow->calculate_affected_autos(&x_keyframe,
2416 x_keyframe->set_value(0);
2417 y_keyframe->set_value(0);
2418 z_keyframe->set_value(1);
2420 mwindow->sync_parameters(CHANGE_PARAMS);
2425 void CWindowCanvas::reset_camera()
2430 void CWindowCanvas::reset_projector()
2435 int CWindowCanvas::test_crop(int button_press, int &redraw)
2438 int handle_selected = -1;
2439 float x1 = mwindow->edl->session->crop_x1;
2440 float y1 = mwindow->edl->session->crop_y1;
2441 float x2 = mwindow->edl->session->crop_x2;
2442 float y2 = mwindow->edl->session->crop_y2;
2443 float cursor_x = get_cursor_x();
2444 float cursor_y = get_cursor_y();
2445 float canvas_x1 = x1;
2446 float canvas_y1 = y1;
2447 float canvas_x2 = x2;
2448 float canvas_y2 = y2;
2449 float canvas_cursor_x = cursor_x;
2450 float canvas_cursor_y = cursor_y;
2452 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2453 // Use screen normalized coordinates for hot spot tests.
2454 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2455 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2458 if(gui->current_operation == CWINDOW_CROP)
2460 handle_selected = gui->crop_handle;
2463 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2464 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2466 handle_selected = 0;
2467 gui->crop_origin_x = x1;
2468 gui->crop_origin_y = y1;
2471 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2472 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2474 handle_selected = 1;
2475 gui->crop_origin_x = x2;
2476 gui->crop_origin_y = y1;
2479 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2480 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2482 handle_selected = 2;
2483 gui->crop_origin_x = x1;
2484 gui->crop_origin_y = y2;
2487 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2488 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2490 handle_selected = 3;
2491 gui->crop_origin_x = x2;
2492 gui->crop_origin_y = y2;
2497 gui->crop_origin_x = cursor_x;
2498 gui->crop_origin_y = cursor_y;
2501 // printf("test crop %d %d\n",
2502 // gui->current_operation,
2503 // handle_selected);
2510 gui->crop_translate = 1;
2511 gui->crop_origin_x1 = x1;
2512 gui->crop_origin_y1 = y1;
2513 gui->crop_origin_x2 = x2;
2514 gui->crop_origin_y2 = y2;
2517 gui->crop_translate = 0;
2519 gui->current_operation = CWINDOW_CROP;
2520 gui->crop_handle = handle_selected;
2521 gui->x_origin = cursor_x;
2522 gui->y_origin = cursor_y;
2523 gui->tool_panel->raise_window();
2526 if(handle_selected < 0 && !gui->crop_translate)
2530 mwindow->edl->session->crop_x1 = (int)x1;
2531 mwindow->edl->session->crop_y1 = (int)y1;
2532 mwindow->edl->session->crop_x2 = (int)x2;
2533 mwindow->edl->session->crop_y2 = (int)y2;
2538 // Translate all 4 points
2539 if(gui->current_operation == CWINDOW_CROP && gui->crop_translate)
2541 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2542 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2543 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2544 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2546 mwindow->edl->session->crop_x1 = (int)x1;
2547 mwindow->edl->session->crop_y1 = (int)y1;
2548 mwindow->edl->session->crop_x2 = (int)x2;
2549 mwindow->edl->session->crop_y2 = (int)y2;
2555 if(gui->current_operation == CWINDOW_CROP)
2557 switch(gui->crop_handle)
2560 x1 = gui->crop_origin_x;
2561 y1 = gui->crop_origin_y;
2562 x2 = gui->crop_origin_x;
2563 y2 = gui->crop_origin_y;
2564 if(cursor_x < gui->x_origin)
2566 if(cursor_y < gui->y_origin)
2572 if(cursor_y >= gui->y_origin)
2579 if(cursor_x >= gui->x_origin)
2581 if(cursor_y < gui->y_origin)
2587 if(cursor_y >= gui->y_origin)
2594 // printf("test crop %d %d %d %d\n",
2595 // mwindow->edl->session->crop_x1,
2596 // mwindow->edl->session->crop_y1,
2597 // mwindow->edl->session->crop_x2,
2598 // mwindow->edl->session->crop_y2);
2601 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2602 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2605 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2606 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2609 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2610 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2613 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2614 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2618 if(!EQUIV(mwindow->edl->session->crop_x1, x1) ||
2619 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2620 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2621 !EQUIV(mwindow->edl->session->crop_y2, y2))
2628 switch (gui->crop_handle)
2630 case 0: gui->crop_handle = 1; break;
2631 case 1: gui->crop_handle = 0; break;
2632 case 2: gui->crop_handle = 3; break;
2633 case 3: gui->crop_handle = 2; break;
2643 switch (gui->crop_handle)
2645 case 0: gui->crop_handle = 2; break;
2646 case 1: gui->crop_handle = 3; break;
2647 case 2: gui->crop_handle = 0; break;
2648 case 3: gui->crop_handle = 1; break;
2653 mwindow->edl->session->crop_x1 = (int)x1;
2654 mwindow->edl->session->crop_y1 = (int)y1;
2655 mwindow->edl->session->crop_x2 = (int)x2;
2656 mwindow->edl->session->crop_y2 = (int)y2;
2662 // Update cursor font
2663 if(handle_selected >= 0)
2665 switch(handle_selected)
2668 set_cursor(UPLEFT_RESIZE);
2671 set_cursor(UPRIGHT_RESIZE);
2674 set_cursor(DOWNLEFT_RESIZE);
2677 set_cursor(DOWNRIGHT_RESIZE);
2684 set_cursor(ARROW_CURSOR);
2686 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2690 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2691 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2692 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2693 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2694 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2695 // mwindow->edl->session->crop_x2,
2696 // mwindow->edl->session->crop_y2,
2697 // mwindow->edl->calculate_output_w(0),
2698 // mwindow->edl->calculate_output_h(0));
2704 void CWindowCanvas::draw_crop()
2706 get_canvas()->set_inverse();
2707 get_canvas()->set_color(WHITE);
2709 float x1 = mwindow->edl->session->crop_x1;
2710 float y1 = mwindow->edl->session->crop_y1;
2711 float x2 = mwindow->edl->session->crop_x2;
2712 float y2 = mwindow->edl->session->crop_y2;
2714 output_to_canvas(mwindow->edl, 0, x1, y1);
2715 output_to_canvas(mwindow->edl, 0, x2, y2);
2717 if(x2 - x1 && y2 - y1)
2718 get_canvas()->draw_rectangle((int)x1,
2723 draw_crophandle((int)x1, (int)y1);
2724 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2725 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2726 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2727 get_canvas()->set_opaque();
2737 void CWindowCanvas::draw_bezier(int do_camera)
2739 Track *track = gui->cwindow->calculate_affected_track();
2746 int64_t position = track->to_units(
2747 mwindow->edl->local_session->get_selectionstart(1),
2750 track->automation->get_projector(¢er_x,
2756 // center_x += track->track_w / 2;
2757 // center_y += track->track_h / 2;
2758 center_x += mwindow->edl->session->output_w / 2;
2759 center_y += mwindow->edl->session->output_h / 2;
2760 float track_x1 = center_x - track->track_w / 2 * center_z;
2761 float track_y1 = center_y - track->track_h / 2 * center_z;
2762 float track_x2 = track_x1 + track->track_w * center_z;
2763 float track_y2 = track_y1 + track->track_h * center_z;
2765 output_to_canvas(mwindow->edl, 0, track_x1, track_y1);
2766 output_to_canvas(mwindow->edl, 0, track_x2, track_y2);
2768 #define DRAW_PROJECTION(offset) \
2769 get_canvas()->draw_rectangle((int)track_x1 + offset, \
2770 (int)track_y1 + offset, \
2771 (int)(track_x2 - track_x1), \
2772 (int)(track_y2 - track_y1)); \
2773 get_canvas()->draw_line((int)track_x1 + offset, \
2774 (int)track_y1 + offset, \
2775 (int)track_x2 + offset, \
2776 (int)track_y2 + offset); \
2777 get_canvas()->draw_line((int)track_x2 + offset, \
2778 (int)track_y1 + offset, \
2779 (int)track_x1 + offset, \
2780 (int)track_y2 + offset); \
2784 get_canvas()->set_color(BLACK);
2787 // canvas->set_inverse();
2789 get_canvas()->set_color(GREEN);
2791 get_canvas()->set_color(RED);
2794 // canvas->set_opaque();
2798 int CWindowCanvas::test_bezier(int button_press,
2806 // Processing drag operation.
2807 // Create keyframe during first cursor motion.
2811 float cursor_x = get_cursor_x();
2812 float cursor_y = get_cursor_y();
2813 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2815 if(gui->current_operation == CWINDOW_CAMERA ||
2816 gui->current_operation == CWINDOW_PROJECTOR)
2818 if(!gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom)
2820 gui->translating_zoom = 1;
2821 gui->reset_affected();
2824 if(!gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom)
2826 gui->translating_zoom = 0;
2827 gui->reset_affected();
2830 // Get target keyframe
2831 float last_center_x;
2832 float last_center_y;
2833 float last_center_z;
2836 if(!gui->affected_x && !gui->affected_y && !gui->affected_z)
2838 FloatAutos *affected_x_autos;
2839 FloatAutos *affected_y_autos;
2840 FloatAutos *affected_z_autos;
2841 if(!gui->affected_track) return 0;
2842 double position = mwindow->edl->local_session->get_selectionstart(1);
2843 int64_t track_position = gui->affected_track->to_units(position, 0);
2845 if(mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA)
2847 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_X];
2848 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Y];
2849 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Z];
2853 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_X];
2854 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Y];
2855 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Z];
2859 if(gui->translating_zoom)
2861 FloatAuto *previous = 0;
2862 FloatAuto *next = 0;
2863 float new_z = affected_z_autos->get_value(
2869 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2870 affected_z_autos, 1, &created, 0);
2872 gui->affected_z->set_value(new_z);
2878 FloatAuto *previous = 0;
2879 FloatAuto *next = 0;
2880 float new_x = affected_x_autos->get_value(
2887 float new_y = affected_y_autos->get_value(
2893 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2894 affected_x_autos, 1, &created, 0);
2896 gui->affected_x->set_value(new_x);
2900 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2901 affected_y_autos, 1, &created, 0);
2903 gui->affected_y->set_value(new_y);
2910 if(gui->translating_zoom)
2912 gui->center_z = gui->affected_z->get_value();
2916 gui->center_x = gui->affected_x->get_value();
2917 gui->center_y = gui->affected_y->get_value();
2924 if(gui->translating_zoom)
2926 last_center_z = gui->affected_z->get_value();
2927 float z = gui->center_z + (cursor_y - gui->y_origin) / 128;
2929 if(!EQUIV(last_center_z, z))
2935 gui->affected_z->set_value(z);
2939 last_center_x = gui->affected_x->get_value();
2940 last_center_y = gui->affected_y->get_value();
2941 float x = gui->center_x + cursor_x - gui->x_origin;
2942 float y = gui->center_y + cursor_y - gui->y_origin;
2943 gui->affected_x->set_value(x);
2944 gui->affected_y->set_value(y);
2945 if( !EQUIV(last_center_x, x) || !EQUIV(last_center_y, y) )
2951 gui->affected_x->set_value(x);
2952 gui->affected_y->set_value(y);
2959 // Begin drag operation. Don't create keyframe here.
2961 // Get affected track off of the first recordable video track.
2962 // Calculating based on the alpha channel would require recording what layer
2963 // each output pixel belongs to as they're rendered and stacked. Forget it.
2964 gui->affected_track = gui->cwindow->calculate_affected_track();
2965 gui->reset_affected();
2967 if(gui->affected_track)
2969 if(gui->current_operation == CWINDOW_CAMERA)
2970 mwindow->undo->update_undo_before(_("camera"), this);
2972 mwindow->undo->update_undo_before(_("projector"), this);
2974 gui->current_operation =
2975 mwindow->edl->session->cwindow_operation;
2976 gui->tool_panel->raise_window();
2985 int CWindowCanvas::test_zoom(int &redraw)
2988 float zoom = get_zoom();
2992 if(!mwindow->edl->session->cwindow_scrollbars)
2994 mwindow->edl->session->cwindow_scrollbars = 1;
2996 x = mwindow->edl->session->output_w / 2;
2997 y = mwindow->edl->session->output_h / 2;
2998 x = x - w / zoom / 2;
2999 y = y - h / zoom / 2;
3003 // Cursor position relative to canvas
3006 // cursor position relative to output
3009 canvas_to_output(mwindow->edl,
3014 //printf("CWindowCanvas::test_zoom 1 %f %f\n", x, y);
3016 // Find current zoom in table
3017 int current_index = 0;
3018 for(current_index = 0 ; current_index < total_zooms; current_index++)
3019 if(EQUIV(my_zoom_table[current_index], zoom)) break;
3023 if(get_buttonpress() == 5 ||
3035 CLAMP(current_index, 0, total_zooms - 1);
3036 zoom = my_zoom_table[current_index];
3038 x = output_x - x / zoom;
3039 y = output_y - y / zoom;
3048 // check_boundaries(mwindow->edl, x_i, y_i, zoom);
3050 //printf("CWindowCanvas::test_zoom 2 %d %d\n", x_i, y_i);
3055 reposition_window(mwindow->edl,
3056 mwindow->theme->ccanvas_x,
3057 mwindow->theme->ccanvas_y,
3058 mwindow->theme->ccanvas_w,
3059 mwindow->theme->ccanvas_h);
3064 gui->zoom_panel->update(zoom);
3070 void CWindowCanvas::calculate_origin()
3072 gui->x_origin = get_cursor_x();
3073 gui->y_origin = get_cursor_y();
3074 //printf("CWindowCanvas::calculate_origin 1 %f %f\n", gui->x_origin, gui->y_origin);
3075 canvas_to_output(mwindow->edl, 0, gui->x_origin, gui->y_origin);
3076 //printf("CWindowCanvas::calculate_origin 2 %f %f\n", gui->x_origin, gui->y_origin);
3080 int CWindowCanvas::cursor_leave_event()
3082 set_cursor(ARROW_CURSOR);
3086 int CWindowCanvas::cursor_enter_event()
3089 switch(mwindow->edl->session->cwindow_operation)
3091 case CWINDOW_CAMERA:
3092 case CWINDOW_PROJECTOR:
3093 set_cursor(MOVE_CURSOR);
3096 set_cursor(MOVE_CURSOR);
3099 test_crop(0, redraw);
3101 case CWINDOW_PROTECT:
3102 set_cursor(ARROW_CURSOR);
3106 set_cursor(CROSS_CURSOR);
3108 case CWINDOW_EYEDROP:
3109 set_cursor(CROSS_CURSOR);
3115 int CWindowCanvas::cursor_motion_event()
3117 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3120 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3121 switch(gui->current_operation)
3123 case CWINDOW_SCROLL:
3125 float zoom = get_zoom();
3126 float cursor_x = get_cursor_x();
3127 float cursor_y = get_cursor_y();
3129 float zoom_x, zoom_y, conformed_w, conformed_h;
3130 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3131 cursor_x = (float)cursor_x / zoom_x + gui->x_offset;
3132 cursor_y = (float)cursor_y / zoom_y + gui->y_offset;
3136 int x = (int)(gui->x_origin - cursor_x + gui->x_offset);
3137 int y = (int)(gui->y_origin - cursor_y + gui->y_offset);
3142 update_scrollbars(0);
3149 result = do_ruler(0, 1, 0, 0);
3152 case CWINDOW_CAMERA:
3153 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3156 case CWINDOW_PROJECTOR:
3157 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3162 result = test_crop(0, redraw);
3163 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3170 case CWINDOW_MASK_CONTROL_IN:
3171 case CWINDOW_MASK_CONTROL_OUT:
3172 case CWINDOW_MASK_TRANSLATE:
3174 result = do_mask(redraw,
3181 case CWINDOW_EYEDROP:
3182 result = do_eyedrop(rerender, 0, 0);
3191 // cursor font changes
3194 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3196 // mwindow->edl->session->cwindow_operation);
3197 switch(mwindow->edl->session->cwindow_operation)
3200 result = test_crop(0, redraw);
3203 result = do_ruler(0, 1, 0, 0);
3206 result = do_mask(redraw,
3216 // If the window is never unlocked before calling send_command the
3217 // display shouldn't get stuck on the old video frame although it will
3218 // flicker between the old video frame and the new video frame.
3228 gui->unlock_window();
3231 mwindow->gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3232 mwindow->gui->draw_overlays(1);
3233 mwindow->gui->unlock_window();
3235 gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3240 gui->unlock_window();
3241 mwindow->restart_brender();
3242 mwindow->sync_parameters(CHANGE_PARAMS);
3243 gui->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
3247 if(!redraw) gui->update_tool();
3248 gui->lock_window("CWindowCanvas::cursor_motion_event 2");
3253 int CWindowCanvas::button_press_event()
3257 int redraw_canvas = 0;
3260 if(Canvas::button_press_event()) return 1;
3262 gui->translating_zoom = gui->shift_down();
3265 //printf("CWindowCanvas::button_press_event 2 %f %f\n", gui->x_origin, gui->y_origin, gui->x_origin, gui->y_origin);
3267 float zoom_x, zoom_y, conformed_w, conformed_h;
3268 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3269 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3270 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3273 if(get_buttonpress() == 2)
3275 gui->current_operation = CWINDOW_SCROLL;
3281 switch(mwindow->edl->session->cwindow_operation)
3284 result = do_ruler(0, 0, 1, 0);
3287 case CWINDOW_CAMERA:
3288 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3291 case CWINDOW_PROJECTOR:
3292 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3296 result = test_zoom(redraw);
3300 result = test_crop(1, redraw);
3304 if(get_buttonpress() == 1)
3305 result = do_mask(redraw, rerender, 1, 0, 0);
3308 case CWINDOW_EYEDROP:
3309 result = do_eyedrop(rerender, 1, 0);
3317 gui->unlock_window();
3320 mwindow->gui->lock_window("CWindowCanvas::button_press_event 1");
3321 mwindow->gui->draw_overlays(1);
3322 mwindow->gui->unlock_window();
3325 gui->lock_window("CWindowCanvas::button_press_event 1");
3328 // rerendering can also be caused by press event
3331 gui->unlock_window();
3333 mwindow->restart_brender();
3334 mwindow->sync_parameters(CHANGE_PARAMS);
3335 gui->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
3339 if(!redraw) gui->update_tool();
3340 gui->lock_window("CWindowCanvas::button_press_event 2");
3345 int CWindowCanvas::button_release_event()
3349 switch(gui->current_operation)
3351 case CWINDOW_SCROLL:
3356 do_ruler(0, 0, 0, 1);
3359 case CWINDOW_CAMERA:
3360 mwindow->undo->update_undo_after(_("camera"), LOAD_AUTOMATION);
3363 case CWINDOW_PROJECTOR:
3364 mwindow->undo->update_undo_after(_("projector"), LOAD_AUTOMATION);
3368 case CWINDOW_MASK_CONTROL_IN:
3369 case CWINDOW_MASK_CONTROL_OUT:
3370 case CWINDOW_MASK_TRANSLATE:
3371 // Finish mask operation
3372 gui->mask_keyframe = 0;
3373 mwindow->undo->update_undo_after(_("mask"), LOAD_AUTOMATION);
3378 gui->current_operation = CWINDOW_NONE;
3382 void CWindowCanvas::zoom_resize_window(float percentage)
3384 int canvas_w, canvas_h;
3388 // Get required canvas size
3389 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3390 mwindow->edl->session->output_w,
3391 mwindow->edl->session->output_h,
3396 // Estimate window size from current borders
3397 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3398 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3400 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3401 mwindow->session->cwindow_w = new_w;
3402 mwindow->session->cwindow_h = new_h;
3404 mwindow->theme->get_cwindow_sizes(gui,
3405 mwindow->session->cwindow_controls);
3407 // Estimate again from new borders
3408 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3409 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3410 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3412 gui->resize_window(new_w, new_h);
3413 gui->resize_event(new_w, new_h);
3416 void CWindowCanvas::toggle_controls()
3418 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3419 gui->resize_event(gui->get_w(), gui->get_h());
3422 int CWindowCanvas::get_cwindow_controls()
3424 return mwindow->session->cwindow_controls;