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,
84 xS(100), yS(100), 1, 1, 1,
85 BC_WindowBase::get_resources()->bg_color,
86 mwindow->get_cwindow_display())
88 this->mwindow = mwindow;
89 this->cwindow = cwindow;
91 affected_x = affected_y = affected_z = 0;
93 orig_mask_keyframe = new MaskAuto(0, 0);
95 x_offset = y_offset = 0;
96 x_origin = y_origin = 0;
97 current_operation = CWINDOW_NONE;
101 crop_handle = -1; crop_translate = 0;
102 crop_origin_x = crop_origin_y = 0;
103 crop_origin_x1 = crop_origin_y1 = 0;
104 crop_origin_x2 = crop_origin_y2 = 0;
106 eyedrop_x = eyedrop_y = 0;
107 ruler_origin_x = ruler_origin_y = 0;
108 ruler_handle = -1; ruler_translate = 0;
109 center_x = center_y = center_z = 0;
110 control_in_x = control_in_y = 0;
111 control_out_x = control_out_y = 0;
112 translating_zoom = 0;
116 CWindowGUI::~CWindowGUI()
118 cwindow->stop_playback(1);
119 if( tool_panel ) delete tool_panel;
121 delete composite_panel;
129 delete orig_mask_keyframe;
132 void CWindowGUI::create_objects()
134 lock_window("CWindowGUI::create_objects");
135 set_icon(mwindow->theme->get_image("cwindow_icon"));
137 active = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_active"));
138 inactive = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_inactive"));
139 focus_frame = new VFramePng(mwindow->theme->get_image_data("cwindow_focus.png"));
141 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
142 mwindow->theme->draw_cwindow_bg(this);
145 // Meters required by composite panel
146 meters = new CWindowMeters(mwindow,
148 mwindow->theme->cmeter_x,
149 mwindow->theme->cmeter_y,
150 mwindow->theme->cmeter_h);
151 meters->create_objects();
154 composite_panel = new CPanel(mwindow,
156 mwindow->theme->ccomposite_x,
157 mwindow->theme->ccomposite_y,
158 mwindow->theme->ccomposite_w,
159 mwindow->theme->ccomposite_h);
160 composite_panel->create_objects();
162 canvas = new CWindowCanvas(mwindow, this);
164 canvas->create_objects(mwindow->edl);
165 canvas->use_cwindow();
168 add_subwindow(timebar = new CTimeBar(mwindow,
170 mwindow->theme->ctimebar_x,
171 mwindow->theme->ctimebar_y,
172 mwindow->theme->ctimebar_w,
173 mwindow->theme->ctimebar_h));
174 timebar->create_objects();
177 add_subwindow(slider = new CWindowSlider(mwindow,
179 mwindow->theme->cslider_x,
180 mwindow->theme->cslider_y,
181 mwindow->theme->cslider_w));
184 transport = new CWindowTransport(mwindow,
186 mwindow->theme->ctransport_x,
187 mwindow->theme->ctransport_y);
188 transport->create_objects();
190 transport->set_slider(slider);
193 edit_panel = new CWindowEditing(mwindow, cwindow);
194 edit_panel->set_meters(meters);
195 edit_panel->create_objects();
197 // add_subwindow(clock = new MainClock(mwindow,
198 // mwindow->theme->ctime_x,
199 // mwindow->theme->ctime_y));
201 zoom_panel = new CWindowZoom(mwindow,
203 mwindow->theme->czoom_x,
204 mwindow->theme->czoom_y,
205 mwindow->theme->czoom_w);
206 zoom_panel->create_objects();
207 zoom_panel->zoom_text->add_item(new BC_MenuItem(auto_zoom = _(AUTO_ZOOM)));
208 if( !mwindow->edl->session->cwindow_scrollbars )
209 zoom_panel->set_text(auto_zoom);
211 // Must create after meter panel
212 tool_panel = new CWindowTool(mwindow, this);
213 tool_panel->Thread::start();
215 set_operation(mwindow->edl->session->cwindow_operation);
220 int CWindowGUI::translation_event()
222 mwindow->session->cwindow_x = get_x();
223 mwindow->session->cwindow_y = get_y();
227 int CWindowGUI::resize_event(int w, int h)
229 mwindow->session->cwindow_x = get_x();
230 mwindow->session->cwindow_y = get_y();
231 mwindow->session->cwindow_w = w;
232 mwindow->session->cwindow_h = h;
234 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
235 mwindow->theme->draw_cwindow_bg(this);
238 composite_panel->reposition_buttons(mwindow->theme->ccomposite_x,
239 mwindow->theme->ccomposite_y, mwindow->theme->ccomposite_h);
241 canvas->set_zoom(mwindow->edl, canvas->get_zoom());
244 timebar->resize_event();
247 slider->reposition_window(mwindow->theme->cslider_x,
248 mwindow->theme->cslider_y,
249 mwindow->theme->cslider_w);
250 // Recalibrate pointer motion range
251 slider->set_position();
254 transport->reposition_buttons(mwindow->theme->ctransport_x,
255 mwindow->theme->ctransport_y);
257 edit_panel->reposition_buttons(mwindow->theme->cedit_x,
258 mwindow->theme->cedit_y);
260 // clock->reposition_window(mwindow->theme->ctime_x,
261 // mwindow->theme->ctime_y);
263 zoom_panel->reposition_window(mwindow->theme->czoom_x,
264 mwindow->theme->czoom_y);
266 // destination->reposition_window(mwindow->theme->cdest_x,
267 // mwindow->theme->cdest_y);
269 meters->reposition_window(mwindow->theme->cmeter_x,
270 mwindow->theme->cmeter_y,
272 mwindow->theme->cmeter_h);
276 BC_WindowBase::resize_event(w, h);
280 int CWindowGUI::button_press_event()
282 if( current_operation == CWINDOW_NONE &&
283 mwindow->edl != 0 && canvas->get_canvas() &&
284 mwindow->edl->session->cwindow_click2play &&
285 canvas->get_canvas()->get_cursor_over_window() ) {
286 switch( get_buttonpress() ) {
288 if( !cwindow->playback_engine->is_playing_back ) {
289 double length = mwindow->edl->tracks->total_playable_length();
290 double position = cwindow->playback_engine->get_tracking_position();
291 if( position >= length ) transport->goto_start();
293 return transport->forward_play->handle_event();
295 if( !cwindow->playback_engine->is_playing_back ) {
296 double position = cwindow->playback_engine->get_tracking_position();
297 if( position <= 0 ) transport->goto_end();
299 return transport->reverse_play->handle_event();
300 case RIGHT_BUTTON: // activates popup
303 return transport->frame_forward_play->handle_event();
305 return transport->frame_reverse_play->handle_event();
308 if( canvas->get_canvas() )
309 return canvas->button_press_event_base(canvas->get_canvas());
313 int CWindowGUI::cursor_leave_event()
315 if( canvas->get_canvas() )
316 return canvas->cursor_leave_event_base(canvas->get_canvas());
320 int CWindowGUI::cursor_enter_event()
322 if( canvas->get_canvas() )
323 return canvas->cursor_enter_event_base(canvas->get_canvas());
327 int CWindowGUI::button_release_event()
329 if( canvas->get_canvas() )
330 return canvas->button_release_event();
334 int CWindowGUI::cursor_motion_event()
336 if( canvas->get_canvas() ) {
337 canvas->get_canvas()->unhide_cursor();
338 return canvas->cursor_motion_event();
349 void CWindowGUI::draw_status(int flush)
351 if( (canvas->get_canvas() && canvas->get_canvas()->get_video_on()) ||
352 canvas->is_processing ) {
354 mwindow->theme->cstatus_x,
355 mwindow->theme->cstatus_y);
358 draw_pixmap(inactive,
359 mwindow->theme->cstatus_x,
360 mwindow->theme->cstatus_y);
364 // printf("CWindowGUI::draw_status %d %d %d\n", __LINE__, mwindow->theme->cstatus_x,
365 // mwindow->theme->cstatus_y);
366 flash(mwindow->theme->cstatus_x,
367 mwindow->theme->cstatus_y,
373 void CWindowGUI::update_canvas(int redraw)
375 float zoom = canvas->get_zoom();
376 zoom_panel->update(zoom);
377 if( mwindow->edl->session->cwindow_operation == CWINDOW_ZOOM ) {
378 if( !zoom ) zoom = canvas->get_auto_zoom(mwindow->edl);
379 composite_panel->cpanel_zoom->update(zoom);
381 canvas->update_scrollbars(mwindow->edl, 0);
382 canvas->reposition_window(mwindow->edl,
383 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
384 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
389 void CWindowGUI::set_operation(int value)
392 case CWINDOW_TOOL_WINDOW:
393 mwindow->edl->session->tool_window = !mwindow->edl->session->tool_window;
394 composite_panel->operation[CWINDOW_TOOL_WINDOW]->update(mwindow->edl->session->tool_window);
395 tool_panel->update_show_window();
397 case CWINDOW_TITLESAFE:
398 mwindow->edl->session->safe_regions = !mwindow->edl->session->safe_regions;
399 composite_panel->operation[CWINDOW_TITLESAFE]->update(mwindow->edl->session->safe_regions);
400 value = mwindow->edl->session->cwindow_operation;
403 mwindow->edl->session->cwindow_operation = value;
404 composite_panel->set_operation(value);
408 edit_panel->update();
409 tool_panel->start_tool(value);
413 void CWindowGUI::update_tool()
415 tool_panel->update_values();
418 int CWindowGUI::close_event()
420 cwindow->hide_window();
425 int CWindowGUI::keypress_event()
428 int cwindow_operation = CWINDOW_NONE;
430 switch( get_keypress() ) {
446 canvas->set_fullscreen(canvas->get_fullscreen() ? 0 : 1);
450 canvas->set_fullscreen(0);
454 if( ctrl_down() || shift_down() || alt_down() ) break;
456 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
458 mwindow->gui->unlock_window();
459 lock_window("CWindowGUI::keypress_event 2");
464 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
465 mwindow->clear_entry();
466 mwindow->gui->unlock_window();
467 lock_window("CWindowGUI::keypress_event 3");
472 int alt_down = this->alt_down();
473 int shift_down = this->shift_down();
476 mwindow->gui->lock_window("CWindowGUI::keypress_event 5");
478 mwindow->prev_edit_handle(shift_down);
480 mwindow->move_left();
481 mwindow->gui->unlock_window();
482 lock_window("CWindowGUI::keypress_event 6");
488 if( !ctrl_down() && !alt_down() ) {
491 mwindow->gui->lock_window("CWindowGUI::keypress_event 7");
492 mwindow->move_left();
493 mwindow->gui->unlock_window();
494 lock_window("CWindowGUI::keypress_event 8");
501 int alt_down = this->alt_down();
502 int shift_down = this->shift_down();
505 mwindow->gui->lock_window("CWindowGUI::keypress_event 8");
507 mwindow->next_edit_handle(shift_down);
509 mwindow->move_right();
510 mwindow->gui->unlock_window();
511 lock_window("CWindowGUI::keypress_event 9");
517 if( !ctrl_down() && !alt_down() ) {
520 mwindow->gui->lock_window("CWindowGUI::keypress_event 10");
521 mwindow->move_right();
522 mwindow->gui->unlock_window();
523 lock_window("CWindowGUI::keypress_event 11");
529 if( !result && cwindow_operation < 0 && ctrl_down() && shift_down() ) {
530 switch( get_keypress() ) {
531 case KEY_F1 ... KEY_F4: // mainmenu, load layout
532 resend_event(mwindow->gui);
537 if( !result && !ctrl_down() ) {
538 switch( get_keypress() ) {
541 mwindow->toggle_camera_xyz(); result = 1;
544 cwindow_operation = CWINDOW_PROTECT;
548 mwindow->toggle_projector_xyz(); result = 1;
551 cwindow_operation = CWINDOW_ZOOM;
555 if( !result && cwindow_operation < 0 && !ctrl_down() && !shift_down() ) {
556 switch( get_keypress() ) {
557 case KEY_F3: cwindow_operation = CWINDOW_MASK; break;
558 case KEY_F4: cwindow_operation = CWINDOW_RULER; break;
559 case KEY_F5: cwindow_operation = CWINDOW_CAMERA; break;
560 case KEY_F6: cwindow_operation = CWINDOW_PROJECTOR; break;
561 case KEY_F7: cwindow_operation = CWINDOW_CROP; break;
562 case KEY_F8: cwindow_operation = CWINDOW_EYEDROP; break;
563 case KEY_F9: cwindow_operation = CWINDOW_TOOL_WINDOW; break;
564 case KEY_F10: cwindow_operation = CWINDOW_TITLESAFE; break;
567 if( !result && cwindow_operation < 0 && !ctrl_down() ) {
568 switch( get_keypress() ) {
571 canvas->reset_camera();
573 canvas->camera_keyframe();
578 canvas->reset_projector();
580 canvas->projector_keyframe();
586 if( cwindow_operation >= 0 ) {
587 set_operation(cwindow_operation);
592 result = transport->keypress_event();
598 void CWindowGUI::reset_affected()
605 void CWindowGUI::keyboard_zoomin()
607 zoom_panel->zoom_tumbler->handle_up_event();
610 void CWindowGUI::keyboard_zoomout()
612 zoom_panel->zoom_tumbler->handle_down_event();
615 void CWindowGUI::sync_parameters(int change_type, int redraw, int overlay)
621 if( change_type < 0 && !overlay ) return;
623 if( change_type >= 0 ) {
624 mwindow->restart_brender();
625 mwindow->sync_parameters(change_type);
628 mwindow->gui->lock_window("CWindowGUI::sync_parameters");
629 mwindow->gui->draw_overlays(1);
630 mwindow->gui->unlock_window();
632 lock_window("CWindowGUI::sync_parameters");
635 void CWindowGUI::drag_motion()
637 if( get_hidden() ) return;
639 if( mwindow->session->current_operation != DRAG_ASSET &&
640 mwindow->session->current_operation != DRAG_VTRANSITION &&
641 mwindow->session->current_operation != DRAG_VEFFECT ) return;
642 int need_highlight = cursor_above() && get_cursor_over_window();
643 if( highlighted == need_highlight ) return;
644 highlighted = need_highlight;
648 int CWindowGUI::drag_stop()
651 if( get_hidden() ) return 0;
652 if( !highlighted ) return 0;
653 if( mwindow->session->current_operation != DRAG_ASSET &&
654 mwindow->session->current_operation != DRAG_VTRANSITION &&
655 mwindow->session->current_operation != DRAG_VEFFECT) return 0;
660 if( mwindow->session->current_operation == DRAG_ASSET ) {
661 if( mwindow->session->drag_assets->total ||
662 mwindow->session->drag_clips->total ) {
663 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
664 mwindow->undo->update_undo_before(_("insert assets"), 0);
667 if( mwindow->session->drag_assets->total ) {
669 mwindow->load_assets(mwindow->session->drag_assets,
670 mwindow->edl->local_session->get_selectionstart(),
672 mwindow->session->track_highlighted,
674 mwindow->edl->session->labels_follow_edits,
675 mwindow->edl->session->plugins_follow_edits,
676 mwindow->edl->session->autos_follow_edits,
680 if( mwindow->session->drag_clips->total ) {
682 mwindow->paste_edls(mwindow->session->drag_clips,
684 mwindow->session->track_highlighted,
685 mwindow->edl->local_session->get_selectionstart(),
686 mwindow->edl->session->labels_follow_edits,
687 mwindow->edl->session->plugins_follow_edits,
688 mwindow->edl->session->autos_follow_edits,
692 if( mwindow->session->drag_assets->total ||
693 mwindow->session->drag_clips->total ) {
694 mwindow->save_backup();
695 mwindow->restart_brender();
696 mwindow->gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
697 mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
698 mwindow->gui->unlock_window();
699 sync_parameters(CHANGE_ALL);
703 if( mwindow->session->current_operation == DRAG_VEFFECT ) {
704 //printf("CWindowGUI::drag_stop 1\n");
705 Track *affected_track = cwindow->calculate_affected_track();
706 //printf("CWindowGUI::drag_stop 2\n");
708 mwindow->gui->lock_window("CWindowGUI::drag_stop 3");
709 mwindow->insert_effects_cwindow(affected_track);
710 mwindow->session->current_operation = NO_OPERATION;
711 mwindow->gui->unlock_window();
714 if( mwindow->session->current_operation == DRAG_VTRANSITION ) {
715 Track *affected_track = cwindow->calculate_affected_track();
716 mwindow->gui->lock_window("CWindowGUI::drag_stop 4");
717 mwindow->paste_transition_cwindow(affected_track);
718 mwindow->session->current_operation = NO_OPERATION;
719 mwindow->gui->unlock_window();
725 void CWindowGUI::update_meters()
727 if( mwindow->edl->session->cwindow_meter != meters->visible ) {
728 meters->set_meters(meters->meter_count, mwindow->edl->session->cwindow_meter);
729 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
730 resize_event(get_w(), get_h());
734 void CWindowGUI::stop_transport(const char *lock_msg)
736 if( lock_msg ) unlock_window();
737 mwindow->stop_transport();
738 if( lock_msg ) lock_window(lock_msg);
742 CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
743 : EditPanel(mwindow, cwindow->gui, CWINDOW_ID,
744 mwindow->theme->cedit_x, mwindow->theme->cedit_y,
745 mwindow->edl->session->editing_mode,
746 0, // use_editing_mode
763 this->mwindow = mwindow;
764 this->cwindow = cwindow;
767 #define relock_cm(s) \
768 cwindow->gui->unlock_window(); \
769 mwindow->gui->lock_window("CWindowEditing::" s)
770 #define relock_mc(s) \
771 mwindow->gui->unlock_window(); \
772 cwindow->gui->lock_window("CWindowEditing::" s)
773 #define panel_fn(fn, args, s) \
774 CWindowEditing::fn args { relock_cm(#fn); s; relock_mc(#fn); }
776 // transmit lock to mwindow, and run mbutton->edit_panel->s
777 #define panel_btn(fn, args, s) \
778 panel_fn(panel_##fn, args, mwindow->gui->mbuttons->edit_panel->panel_##s)
781 double CWindowEditing::get_position()
783 relock_cm("get_position");
784 double ret = mwindow->edl->local_session->get_selectionstart(1);
785 relock_mc("get_position");
789 void CWindowEditing::set_position(double position)
791 relock_cm("set_position");
792 mwindow->gui->mbuttons->edit_panel->set_position(position);
793 relock_mc("set_position");
796 void CWindowEditing::set_click_to_play(int v)
798 relock_cm("set_position");
799 mwindow->edl->session->cwindow_click2play = v;
800 relock_mc("set_position");
801 click2play->update(v);
805 void panel_btn(stop_transport,(), stop_transport())
806 void panel_btn(toggle_label,(), toggle_label())
807 void panel_btn(next_label,(int cut), next_label(cut))
808 void panel_btn(prev_label,(int cut), prev_label(cut))
809 void panel_btn(next_edit,(int cut), next_edit(cut))
810 void panel_btn(prev_edit,(int cut), prev_edit(cut))
811 void panel_fn(panel_copy_selection,(), mwindow->copy())
812 void CWindowEditing::panel_overwrite_selection() {} // not used
813 void CWindowEditing::panel_splice_selection() {} // not used
814 void panel_btn(set_inpoint,(), set_inpoint())
815 void panel_btn(set_outpoint,(), set_outpoint())
816 void panel_btn(unset_inoutpoint,(), unset_inoutpoint())
817 void panel_fn(panel_to_clip,(), mwindow->to_clip(mwindow->edl, _("main window: "), 0))
818 void panel_btn(cut,(), cut())
819 void panel_btn(paste,(), paste())
820 void panel_btn(fit_selection,(), fit_selection())
821 void panel_btn(fit_autos,(int all), fit_autos(all))
822 void panel_btn(set_editing_mode,(int mode), set_editing_mode(mode))
823 void panel_btn(set_auto_keyframes,(int v), set_auto_keyframes(v))
824 void panel_btn(set_span_keyframes,(int v), set_span_keyframes(v))
825 void panel_btn(set_labels_follow_edits,(int v), set_labels_follow_edits(v))
828 CWindowMeters::CWindowMeters(MWindow *mwindow,
829 CWindowGUI *gui, int x, int y, int h)
830 : MeterPanel(mwindow, gui, x, y, -1, h,
831 mwindow->edl->session->audio_channels,
832 mwindow->edl->session->cwindow_meter,
835 this->mwindow = mwindow;
839 CWindowMeters::~CWindowMeters()
843 int CWindowMeters::change_status_event(int new_status)
845 mwindow->edl->session->cwindow_meter = new_status;
846 gui->update_meters();
853 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
854 : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
855 x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
857 this->mwindow = mwindow;
861 CWindowZoom::~CWindowZoom()
865 void CWindowZoom::update(double value)
867 char string[BCSTRLEN];
868 const char *cp = string;
871 int frac = value >= 1.0f ? 1 :
873 value >= .01f ? 3 : 4;
874 sprintf(string, "x %.*f", frac, value);
878 ZoomPanel::update(cp);
881 int CWindowZoom::handle_event()
883 double value = !strcasecmp(gui->auto_zoom, get_text()) ? 0 : get_value();
884 gui->canvas->set_zoom(mwindow->edl, value);
885 gui->update_canvas();
892 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
893 : BC_PercentageSlider(x, y, 0, pixels, pixels, 0, 1, 0)
895 this->mwindow = mwindow;
896 this->cwindow = cwindow;
897 set_precision(0.00001);
900 CWindowSlider::~CWindowSlider()
904 int CWindowSlider::handle_event()
906 cwindow->update_position((double)get_value());
910 void CWindowSlider::set_position()
912 double new_length = mwindow->edl->tracks->total_length();
913 update(mwindow->theme->cslider_w,
914 mwindow->edl->local_session->get_selectionstart(1),
919 int CWindowSlider::increase_value()
922 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
923 lock_window("CWindowSlider::increase_value");
927 int CWindowSlider::decrease_value()
930 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
931 lock_window("CWindowSlider::decrease_value");
937 CWindowTransport::CWindowTransport(MWindow *mwindow,
938 CWindowGUI *gui, int x, int y)
939 : PlayTransport(mwindow, gui, x, y)
944 EDL* CWindowTransport::get_edl()
949 void CWindowTransport::goto_start()
951 gui->unlock_window();
952 handle_transport(REWIND, 1);
954 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
955 mwindow->goto_start();
956 mwindow->gui->unlock_window();
958 gui->lock_window("CWindowTransport::goto_start 2");
961 void CWindowTransport::goto_end()
963 gui->unlock_window();
964 handle_transport(GOTO_END, 1);
966 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
968 mwindow->gui->unlock_window();
970 gui->lock_window("CWindowTransport::goto_end 2");
975 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
976 : Canvas(mwindow, gui,
977 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
978 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h,
979 0, 0, mwindow->edl->session->cwindow_scrollbars)
981 this->mwindow = mwindow;
988 void CWindowCanvas::status_event()
993 void CWindowCanvas::update_zoom(int x, int y, float zoom)
995 mwindow->edl->session->cwindow_xscroll = x;
996 mwindow->edl->session->cwindow_yscroll = y;
997 mwindow->edl->session->cwindow_zoom = zoom;
998 use_scrollbars = !zoom ? 0 : 1;
999 mwindow->edl->session->cwindow_scrollbars = use_scrollbars;
1002 int CWindowCanvas::set_fullscreen(int on)
1005 if( on && !get_fullscreen() ) {
1006 last_xscroll = get_xscroll();
1007 last_yscroll = get_yscroll();
1008 last_zoom = get_zoom();
1009 Canvas::set_fullscreen(1);
1013 if( !on && get_fullscreen() ) {
1014 Canvas::set_fullscreen(0);
1015 gui->zoom_panel->update(get_zoom());
1016 update_zoom(last_xscroll, last_yscroll, last_zoom);
1017 gui->update_canvas();
1023 int CWindowCanvas::get_xscroll()
1025 return mwindow->edl->session->cwindow_xscroll;
1028 int CWindowCanvas::get_yscroll()
1030 return mwindow->edl->session->cwindow_yscroll;
1034 float CWindowCanvas::get_zoom()
1036 return mwindow->edl->session->cwindow_zoom;
1039 void CWindowCanvas::zoom_auto()
1042 set_zoom(mwindow->edl, 0);
1043 gui->update_canvas();
1046 int CWindowCanvas::do_scroll(EDL *edl, float cursor_x, float cursor_y)
1048 float zoom = get_zoom();
1049 float zoom_x, zoom_y, conformed_w, conformed_h;
1050 get_zooms(edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
1052 x = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
1053 y = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
1054 zoom = get_auto_zoom(mwindow->edl);
1057 x = gui->x_origin - cursor_x / zoom_x;
1058 y = gui->y_origin - cursor_y / zoom_y;
1060 update_zoom(x, y, zoom);
1061 gui->update_canvas();
1065 void CWindowCanvas::draw_refresh(int flush)
1067 BC_WindowBase *window = get_canvas();
1068 if( window && !window->get_video_on() ) {
1070 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
1071 float in_x1, in_y1, in_x2, in_y2;
1072 float out_x1, out_y1, out_x2, out_y2;
1073 get_transfers(mwindow->edl,
1074 in_x1, in_y1, in_x2, in_y2,
1075 out_x1, out_y1, out_x2, out_y2);
1078 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1079 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1082 if( out_x2 > out_x1 && out_y2 > out_y1 &&
1083 in_x2 > in_x1 && in_y2 > in_y1 ) {
1084 // input scaled from session to refresh frame coordinates
1085 int ow = get_output_w(mwindow->edl);
1086 int oh = get_output_h(mwindow->edl);
1087 int rw = refresh_frame->get_w();
1088 int rh = refresh_frame->get_h();
1089 float xs = (float)rw / ow;
1090 float ys = (float)rh / oh;
1091 in_x1 *= xs; in_x2 *= xs;
1092 in_y1 *= ys; in_y2 *= ys;
1093 // Can't use OpenGL here because it is called asynchronously of the
1094 // playback operation.
1095 window->draw_vframe(refresh_frame,
1096 (int)out_x1, (int)out_y1,
1097 (int)(out_x2 - out_x1),
1098 (int)(out_y2 - out_y1),
1099 (int)in_x1, (int)in_y1,
1100 (int)(in_x2 - in_x1),
1101 (int)(in_y2 - in_y1),
1107 window->flash(flush);
1109 //printf("CWindowCanvas::draw_refresh 10\n");
1112 #define CROPHANDLE_W xS(10)
1113 #define CROPHANDLE_H yS(10)
1115 void CWindowCanvas::draw_crophandle(int x, int y)
1117 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1121 #define CONTROL_W xS(10)
1122 #define CONTROL_H yS(10)
1123 #define FIRST_CONTROL_W xS(20)
1124 #define FIRST_CONTROL_H yS(20)
1126 #define BC_INFINITY 65536
1128 #define RULERHANDLE_W xS(16)
1129 #define RULERHANDLE_H yS(16)
1131 int CWindowCanvas::do_ruler(int draw, int motion,
1132 int button_press, int button_release)
1135 EDLSession *session = mwindow->edl->session;
1136 float x1 = session->ruler_x1;
1137 float y1 = session->ruler_y1;
1138 float x2 = session->ruler_x2;
1139 float y2 = session->ruler_y2;
1140 float canvas_x1 = x1;
1141 float canvas_y1 = y1;
1142 float canvas_x2 = x2;
1143 float canvas_y2 = y2;
1144 float output_x = get_cursor_x();
1145 float output_y = get_cursor_y();
1146 float canvas_cursor_x = output_x;
1147 float canvas_cursor_y = output_y;
1149 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1150 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1151 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1152 mwindow->session->cwindow_output_x = roundf(output_x);
1153 mwindow->session->cwindow_output_y = roundf(output_y);
1155 if( button_press && get_buttonpress() == 1 ) {
1156 gui->ruler_handle = -1;
1157 gui->ruler_translate = 0;
1158 if( gui->alt_down() ) {
1159 gui->ruler_translate = 1;
1160 gui->ruler_origin_x = x1;
1161 gui->ruler_origin_y = y1;
1164 if( canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1165 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1166 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1167 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2 ) {
1168 gui->ruler_handle = 0;
1169 gui->ruler_origin_x = x1;
1170 gui->ruler_origin_y = y1;
1173 if( canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1174 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1175 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1176 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2 ) {
1177 gui->ruler_handle = 1;
1178 gui->ruler_origin_x = x2;
1179 gui->ruler_origin_y = y2;
1183 // Start new selection
1184 if( !gui->ruler_translate &&
1185 (gui->ruler_handle < 0 ||
1189 do_ruler(1, 0, 0, 0);
1190 get_canvas()->flash();
1191 gui->ruler_handle = 1;
1192 session->ruler_x1 = output_x;
1193 session->ruler_y1 = output_y;
1194 session->ruler_x2 = output_x;
1195 session->ruler_y2 = output_y;
1196 gui->ruler_origin_x = session->ruler_x2;
1197 gui->ruler_origin_y = session->ruler_y2;
1200 gui->x_origin = output_x;
1201 gui->y_origin = output_y;
1202 gui->current_operation = CWINDOW_RULER;
1203 gui->tool_panel->raise_window();
1208 if( gui->current_operation == CWINDOW_RULER ) {
1209 if( gui->ruler_translate ) {
1211 do_ruler(1, 0, 0, 0);
1212 float x_difference = session->ruler_x1;
1213 float y_difference = session->ruler_y1;
1214 session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1215 session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1216 x_difference -= session->ruler_x1;
1217 y_difference -= session->ruler_y1;
1218 session->ruler_x2 -= x_difference;
1219 session->ruler_y2 -= y_difference;
1221 do_ruler(1, 0, 0, 0);
1222 get_canvas()->flash();
1226 switch( gui->ruler_handle ) {
1228 do_ruler(1, 0, 0, 0);
1229 session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1230 session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1231 if( gui->alt_down() || gui->ctrl_down() ) {
1232 double angle_value = fabs(atan((session->ruler_y2 - session->ruler_y1) /
1233 (session->ruler_x2 - session->ruler_x1)) *
1235 double distance_value =
1236 sqrt(SQR(session->ruler_x2 - session->ruler_x1) +
1237 SQR(session->ruler_y2 - session->ruler_y1));
1238 if( angle_value < 22 )
1239 session->ruler_y1 = session->ruler_y2;
1241 if( angle_value > 67 )
1242 session->ruler_x1 = session->ruler_x2;
1244 if( session->ruler_x1 < session->ruler_x2 &&
1245 session->ruler_y1 < session->ruler_y2 ) {
1246 session->ruler_x1 = session->ruler_x2 - distance_value / 1.414214;
1247 session->ruler_y1 = session->ruler_y2 - distance_value / 1.414214;
1250 if( session->ruler_x1 < session->ruler_x2 && session->ruler_y1 > session->ruler_y2 ) {
1251 session->ruler_x1 = session->ruler_x2 - distance_value / 1.414214;
1252 session->ruler_y1 = session->ruler_y2 + distance_value / 1.414214;
1255 if( session->ruler_x1 > session->ruler_x2 &&
1256 session->ruler_y1 < session->ruler_y2 ) {
1257 session->ruler_x1 = session->ruler_x2 + distance_value / 1.414214;
1258 session->ruler_y1 = session->ruler_y2 - distance_value / 1.414214;
1261 session->ruler_x1 = session->ruler_x2 + distance_value / 1.414214;
1262 session->ruler_y1 = session->ruler_y2 + distance_value / 1.414214;
1265 do_ruler(1, 0, 0, 0);
1266 get_canvas()->flash();
1271 do_ruler(1, 0, 0, 0);
1272 session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1273 session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1274 if( gui->alt_down() || gui->ctrl_down() ) {
1275 double angle_value = fabs(atan((session->ruler_y2 - session->ruler_y1) /
1276 (session->ruler_x2 - session->ruler_x1)) *
1278 double distance_value =
1279 sqrt(SQR(session->ruler_x2 - session->ruler_x1) +
1280 SQR(session->ruler_y2 - session->ruler_y1));
1281 if( angle_value < 22 )
1282 session->ruler_y2 = session->ruler_y1;
1284 if( angle_value > 67 )
1285 session->ruler_x2 = session->ruler_x1;
1287 if( session->ruler_x2 < session->ruler_x1 &&
1288 session->ruler_y2 < session->ruler_y1 ) {
1289 session->ruler_x2 = session->ruler_x1 - distance_value / 1.414214;
1290 session->ruler_y2 = session->ruler_y1 - distance_value / 1.414214;
1293 if( session->ruler_x2 < session->ruler_x1 &&
1294 session->ruler_y2 > session->ruler_y1 ) {
1295 session->ruler_x2 = session->ruler_x1 - distance_value / 1.414214;
1296 session->ruler_y2 = session->ruler_y1 + distance_value / 1.414214;
1299 if( session->ruler_x2 > session->ruler_x1 && session->ruler_y2 < session->ruler_y1 ) {
1300 session->ruler_x2 = session->ruler_x1 + distance_value / 1.414214;
1301 session->ruler_y2 = session->ruler_y1 - distance_value / 1.414214;
1304 session->ruler_x2 = session->ruler_x1 + distance_value / 1.414214;
1305 session->ruler_y2 = session->ruler_y1 + distance_value / 1.414214;
1308 do_ruler(1, 0, 0, 0);
1309 get_canvas()->flash();
1314 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1317 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1322 if( canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1323 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1324 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1325 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2 ) {
1326 set_cursor(UPRIGHT_ARROW_CURSOR);
1329 if( canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1330 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1331 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1332 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2 ) {
1333 set_cursor(UPRIGHT_ARROW_CURSOR);
1336 set_cursor(CROSS_CURSOR);
1338 // Update current position
1343 // Assume no ruler measurement if 0 length
1344 if( draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)) ) {
1345 get_canvas()->set_inverse();
1346 get_canvas()->set_color(WHITE);
1347 get_canvas()->draw_line((int)canvas_x1,
1351 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1353 roundf(canvas_x1) + RULERHANDLE_W / 2,
1355 get_canvas()->draw_line(roundf(canvas_x1),
1356 roundf(canvas_y1) - RULERHANDLE_H / 2,
1358 roundf(canvas_y1) + RULERHANDLE_H / 2);
1359 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1361 roundf(canvas_x2) + RULERHANDLE_W / 2,
1363 get_canvas()->draw_line(roundf(canvas_x2),
1364 roundf(canvas_y2) - RULERHANDLE_H / 2,
1366 roundf(canvas_y2) + RULERHANDLE_H / 2);
1367 get_canvas()->set_opaque();
1374 static inline double line_dist(float cx,float cy, float tx,float ty)
1376 double dx = tx-cx, dy = ty-cy;
1377 return sqrt(dx*dx + dy*dy);
1380 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1382 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1383 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1387 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1388 int button_press, int cursor_motion, int draw)
1390 // Retrieve points from top recordable track
1391 //printf("CWindowCanvas::do_mask 1\n");
1392 Track *track = gui->cwindow->calculate_mask_track();
1393 //printf("CWindowCanvas::do_mask 2\n");
1395 if( !track ) return 0;
1396 //printf("CWindowCanvas::do_mask 3\n");
1397 CWindowMaskGUI *mask_gui = (CWindowMaskGUI *)
1398 (gui->tool_panel ? gui->tool_panel->tool_gui : 0);
1399 int draw_markers = mask_gui ? mask_gui->markers : 0;
1400 int draw_boundary = mask_gui ? mask_gui->boundary : 0;
1401 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1402 int64_t position = track->to_units(
1403 mwindow->edl->local_session->get_selectionstart(1),
1405 Auto *prev_auto = 0;
1406 mask_autos->get_prev_auto(position, PLAY_FORWARD, (Auto *&)prev_auto, 1);
1407 MaskAuto *prev_mask = (MaskAuto *)prev_auto;
1409 int update_points = 1;
1410 // Determine the points based on whether
1411 // new keyframes will be generated or drawing is performed.
1412 // If keyframe generation occurs, use the interpolated mask.
1413 // If no keyframe generation occurs, use the previous mask.
1414 int use_interpolated = 0;
1415 if( button_press || cursor_motion ) {
1416 #ifdef USE_KEYFRAME_SPANNING
1417 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1418 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1419 int64_t start_pos = track->to_units(selection_start, 0);
1420 int64_t end_pos = track->to_units(selection_end, 0);
1421 Auto *first = 0, *last = 0;
1422 mask_autos->get_prev_auto(start_pos, PLAY_FORWARD, first, 1);
1423 mask_autos->get_prev_auto(end_pos, PLAY_FORWARD, last, 1);
1424 if( last == first && (!mwindow->edl->session->auto_keyframes) )
1425 use_interpolated = 0;
1427 // If keyframe spanning occurs, use the interpolated points.
1428 // If new keyframe is generated, use the interpolated points.
1429 use_interpolated = 1;
1432 if( mwindow->edl->session->auto_keyframes )
1433 use_interpolated = 1;
1437 use_interpolated = 1;
1439 if( use_interpolated ) {
1440 // Interpolate the points to get exactly what is being rendered at this position.
1441 mask_autos->get_points(&points,
1442 mwindow->edl->session->cwindow_mask,
1443 position, PLAY_FORWARD);
1446 // Use the prev mask
1447 prev_mask->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(), cursor_y = get_cursor_y();
1463 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1464 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1466 projector_x += mwindow->edl->session->output_w / 2;
1467 projector_y += mwindow->edl->session->output_h / 2;
1468 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1469 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1471 // Fix cursor origin
1472 if( button_press ) {
1473 gui->x_origin = mask_cursor_x;
1474 gui->y_origin = mask_cursor_y;
1478 // Points of closest line
1479 int shortest_point1 = -1;
1480 int shortest_point2 = -1;
1482 int shortest_point = -1;
1483 // Distance to closest line
1484 float shortest_line_distance = BC_INFINITY;
1485 // Distance to closest point
1486 float shortest_point_distance = BC_INFINITY;
1487 int selected_point = -1;
1488 int selected_control_point = -1;
1489 float selected_control_point_distance = BC_INFINITY;
1490 ArrayList<int> x_points;
1491 ArrayList<int> y_points;
1493 if( !cursor_motion ) {
1495 get_canvas()->set_color(WHITE);
1496 get_canvas()->set_inverse();
1498 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1500 // Never draw closed polygon and a closed
1501 // polygon is harder to add points to.
1502 for( int i = 0; i < points.size() && !result; i++ ) {
1503 MaskPoint *point1 = points.get(i);
1504 MaskPoint *point2 = (i >= points.size() - 1) ?
1505 points.get(0) : points.get(i + 1);
1506 if( button_press ) {
1507 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1508 if( point_distance1 < shortest_point_distance || shortest_point < 0 ) {
1509 shortest_point_distance = point_distance1;
1513 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1514 if( point_distance2 < shortest_point_distance || shortest_point < 0 ) {
1515 shortest_point_distance = point_distance2;
1516 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1520 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1522 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1523 //point1->x, point1->y, point2->x, point2->y, projector_z);
1524 for( int j = 0; j <= segments && !result; j++ ) {
1525 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1526 float x0 = point1->x, y0 = point1->y;
1527 float x1 = point1->x + point1->control_x2;
1528 float y1 = point1->y + point1->control_y2;
1529 float x2 = point2->x + point2->control_x1;
1530 float y2 = point2->y + point2->control_y1;
1531 float x3 = point2->x, y3 = point2->y;
1532 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1533 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1534 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1535 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1536 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1537 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1538 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1539 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1541 float t = (float)j / segments;
1542 float tpow2 = t * t;
1543 float tpow3 = t * t * t;
1545 float invtpow2 = invt * invt;
1546 float invtpow3 = invt * invt * invt;
1548 float x = ( invtpow3 * x0
1549 + 3 * t * invtpow2 * x1
1550 + 3 * tpow2 * invt * x2
1552 float y = ( invtpow3 * y0
1553 + 3 * t * invtpow2 * y1
1554 + 3 * tpow2 * invt * y2
1556 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1557 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1558 // Test new point addition
1559 if( button_press ) {
1560 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1562 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1563 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1564 if( line_distance < shortest_line_distance ||
1565 shortest_point1 < 0 ) {
1566 shortest_line_distance = line_distance;
1567 shortest_point1 = i;
1568 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1569 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1570 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1573 // Test existing point selection
1575 if( gui->ctrl_down() ) {
1576 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1578 if( distance < selected_control_point_distance ) {
1580 selected_control_point = 1;
1581 selected_control_point_distance = distance;
1585 if( !gui->shift_down() ) {
1586 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1587 if( test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0) ) {
1592 selected_point = shortest_point;
1595 // Test second point
1596 if( gui->ctrl_down() ) {
1597 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1599 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1600 if( distance < selected_control_point_distance ) {
1601 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1602 selected_control_point = 0;
1603 selected_control_point_distance = distance;
1606 else if( i < points.size() - 1 ) {
1607 if( !gui->shift_down() ) {
1608 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1609 if( test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3) ) {
1610 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1614 selected_point = shortest_point;
1619 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1623 if( draw ) { // Draw joining line
1624 x_points.append((int)canvas_x);
1625 y_points.append((int)canvas_y);
1628 if( j == segments ) {
1629 if( draw && draw_markers ) { // Draw second anchor
1630 if( i < points.size() - 1 ) {
1631 if( i == gui->affected_point - 1 )
1632 get_canvas()->draw_disc(
1633 (int)canvas_x - CONTROL_W / 2,
1634 (int)canvas_y - CONTROL_W / 2,
1635 CONTROL_W, CONTROL_H);
1637 get_canvas()->draw_circle(
1638 (int)canvas_x - CONTROL_W / 2,
1639 (int)canvas_y - CONTROL_W / 2,
1640 CONTROL_W, CONTROL_H);
1641 // char string[BCTEXTLEN];
1642 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1643 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1645 // Draw second control point.
1646 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1647 get_canvas()->draw_line(
1648 (int)canvas_x, (int)canvas_y,
1649 (int)canvas_x2, (int)canvas_y2);
1650 get_canvas()->draw_rectangle(
1651 (int)canvas_x2 - CONTROL_W / 2,
1652 (int)canvas_y2 - CONTROL_H / 2,
1653 CONTROL_W, CONTROL_H);
1658 // Draw first anchor
1659 if( i == 0 && draw ) {
1660 if( draw_boundary ) {
1661 char mask_label[BCSTRLEN];
1662 int k = mwindow->edl->session->cwindow_mask;
1663 if( !prev_mask || k < 0 || k >= prev_mask->masks.size() )
1664 sprintf(mask_label, "%d", k);
1666 sprintf(mask_label, "%s", prev_mask->masks[k]->name);
1667 get_canvas()->draw_text(
1668 (int)canvas_x - FIRST_CONTROL_W,
1669 (int)canvas_y - FIRST_CONTROL_H,
1672 if( draw_markers ) {
1673 get_canvas()->draw_disc(
1674 (int)canvas_x - FIRST_CONTROL_W / 2,
1675 (int)canvas_y - FIRST_CONTROL_H / 2,
1676 FIRST_CONTROL_W, FIRST_CONTROL_H);
1680 // Draw first control point.
1681 if( draw && draw_markers ) {
1682 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1683 get_canvas()->draw_line(
1684 (int)canvas_x, (int)canvas_y,
1685 (int)canvas_x1, (int)canvas_y1);
1686 get_canvas()->draw_rectangle(
1687 (int)canvas_x1 - CONTROL_W / 2,
1688 (int)canvas_y1 - CONTROL_H / 2,
1689 CONTROL_W, CONTROL_H);
1691 x_points.append((int)canvas_x);
1692 y_points.append((int)canvas_y);
1695 //printf("CWindowCanvas::do_mask 1\n");
1699 //printf("CWindowCanvas::do_mask 1\n");
1701 BC_WindowBase *cvs_win = get_canvas();
1702 if( draw && draw_boundary ) {
1703 cvs_win->draw_polygon(&x_points, &y_points);
1704 cvs_win->set_opaque();
1706 if( draw && mask_gui && mask_gui->focused ) {
1707 float fx = atof(mask_gui->focus_x->get_text());
1708 float fy = atof(mask_gui->focus_y->get_text());
1709 fx = (fx - half_track_w) * projector_z + projector_x;
1710 fy = (fy - half_track_h) * projector_z + projector_y;
1711 output_to_canvas(mwindow->edl, 0, fx, fy);
1712 float r = bmax(cvs_win->get_w(), cvs_win->get_h());
1715 int fw = 2*d+3, fh = fw;
1716 VFrame focus(fw,fh, BC_RGBA8888);
1717 focus.transfer_from(gui->focus_frame);
1718 fx -= fw/2.f; fy -= fh/2.f;
1719 BC_Pixmap focus_pixmap(cvs_win, &focus, PIXMAP_ALPHA);
1720 cvs_win->draw_pixmap(&focus_pixmap,fx,fy);
1722 cvs_win->set_line_width((int)(0.0025*r) + 1);
1723 cvs_win->set_color(BLUE);
1724 cvs_win->draw_line(fx-d,fy-d, fx+d, fy+d);
1725 cvs_win->draw_line(fx-d,fy+d, fx+d, fy-d);
1726 cvs_win->set_line_width(0);
1727 cvs_win->set_color(WHITE);
1730 if( draw && mask_gui && draw_markers && points.size() ) {
1731 float cx = 0, cy = 0;
1732 int n = points.size();
1733 for( int i=0; i<n; ++i ) {
1734 MaskPoint *point = points.get(i);
1735 cx += point->x; cy += point->y;
1738 if( !mask_gui->focused )
1739 mask_gui->set_focused(0, cx, cy);
1740 cx = (cx - half_track_w) * projector_z + projector_x;
1741 cy = (cy - half_track_h) * projector_z + projector_y;
1742 output_to_canvas(mwindow->edl, 0, cx, cy);
1743 float r = bmax(cvs_win->get_w(), cvs_win->get_h());
1745 cvs_win->set_line_width((int)(0.002*r) + 1);
1746 cvs_win->set_color(ORANGE);
1747 cvs_win->draw_line(cx-d,cy, cx+d, cy);
1748 cvs_win->draw_line(cx,cy-d, cx, cy+d);
1749 cvs_win->set_line_width(0);
1750 cvs_win->set_color(WHITE);
1752 //printf("CWindowCanvas::do_mask 1\n");
1755 if( button_press && !result ) {
1756 gui->affected_track = gui->cwindow->calculate_mask_track();
1758 // Get keyframe outside the EDL to edit. This must be rendered
1759 // instead of the EDL keyframes when it exists. Then it must be
1760 // applied to the EDL keyframes on buttonrelease.
1761 if( gui->affected_track ) {
1762 #ifdef USE_KEYFRAME_SPANNING
1763 // Make copy of current parameters in local keyframe
1764 gui->mask_keyframe =
1765 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1767 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1770 gui->mask_keyframe =
1771 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1775 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1777 if( get_buttonpress() == WHEEL_UP || get_buttonpress() == WHEEL_DOWN ) {
1778 if( !gui->shift_down() ) {
1779 mwindow->undo->update_undo_before(_("mask rotate"), this);
1780 gui->current_operation = CWINDOW_MASK_ROTATE;
1783 mwindow->undo->update_undo_before(_("mask scale"), this);
1784 gui->current_operation = CWINDOW_MASK_SCALE;
1786 gui->affected_point = 0;
1789 // Translate entire keyframe
1790 if( gui->alt_down() && mask->points.size() ) {
1791 mwindow->undo->update_undo_before(_("mask translate"), 0);
1792 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1793 gui->affected_point = 0;
1796 // Existing point or control point was selected
1797 if( selected_point >= 0 ) {
1798 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1799 gui->affected_point = selected_point;
1801 if( selected_control_point == 0 )
1802 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1804 if( selected_control_point == 1 )
1805 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1807 gui->current_operation = mwindow->edl->session->cwindow_operation;
1809 else // No existing point or control point was selected so create a new one
1810 if( !gui->ctrl_down() && !gui->alt_down() ) {
1811 mwindow->undo->update_undo_before(_("mask point"), 0);
1812 // Create the template
1813 MaskPoint *point = new MaskPoint;
1814 point->x = mask_cursor_x;
1815 point->y = mask_cursor_y;
1816 point->control_x1 = 0;
1817 point->control_y1 = 0;
1818 point->control_x2 = 0;
1819 point->control_y2 = 0;
1822 if( shortest_point2 < shortest_point1 ) {
1823 shortest_point2 ^= shortest_point1;
1824 shortest_point1 ^= shortest_point2;
1825 shortest_point2 ^= shortest_point1;
1830 // printf("CWindowGUI::do_mask 40\n");
1831 // mwindow->edl->dump();
1832 // printf("CWindowGUI::do_mask 50\n");
1836 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1837 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1838 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1840 // Append to end of list
1841 if( shortest_point1 == shortest_point2 ||
1842 labs(shortest_point1 - shortest_point2) > 1) {
1843 #ifdef USE_KEYFRAME_SPANNING
1845 MaskPoint *new_point = new MaskPoint;
1846 points.append(new_point);
1847 *new_point = *point;
1848 gui->affected_point = points.size() - 1;
1852 // Need to apply the new point to every keyframe
1853 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1854 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1855 MaskPoint *new_point = new MaskPoint;
1856 submask->points.append(new_point);
1857 *new_point = *point;
1858 if( current == (MaskAuto*)mask_autos->default_auto )
1859 current = (MaskAuto*)mask_autos->first;
1861 current = (MaskAuto*)NEXT;
1863 gui->affected_point = mask->points.size() - 1;
1869 // Insert between 2 points, shifting back point 2
1870 if( shortest_point1 >= 0 && shortest_point2 >= 0 ) {
1872 #ifdef USE_KEYFRAME_SPANNING
1873 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1875 if( points.size() >= shortest_point2 ) {
1876 MaskPoint *new_point = new MaskPoint;
1878 for( int i = points.size() - 1;
1879 i > shortest_point2;
1881 points.values[i] = points.values[i - 1];
1882 points.values[shortest_point2] = new_point;
1884 *new_point = *point;
1889 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1890 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1891 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1893 if( submask->points.size() >= shortest_point2 ) {
1894 MaskPoint *new_point = new MaskPoint;
1895 submask->points.append(0);
1896 for( int i = submask->points.size() - 1;
1897 i > shortest_point2;
1899 submask->points.values[i] = submask->points.values[i - 1];
1900 submask->points.values[shortest_point2] = new_point;
1902 *new_point = *point;
1905 if( current == (MaskAuto*)mask_autos->default_auto )
1906 current = (MaskAuto*)mask_autos->first;
1908 current = (MaskAuto*)NEXT;
1912 gui->affected_point = shortest_point2;
1917 // printf("CWindowGUI::do_mask 20\n");
1918 // mwindow->edl->dump();
1919 // printf("CWindowGUI::do_mask 30\n");
1922 //printf("CWindowCanvas::do_mask 1\n");
1923 // Create the first point.
1924 #ifdef USE_KEYFRAME_SPANNING
1925 MaskPoint *new_point = new MaskPoint;
1926 points.append(new_point);
1927 *new_point = *point;
1928 gui->affected_point = points.size() - 1;
1930 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1931 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1932 MaskPoint *new_point = new MaskPoint;
1933 submask->points.append(new_point);
1934 *new_point = *point;
1935 if( current == (MaskAuto*)mask_autos->default_auto )
1936 current = (MaskAuto*)mask_autos->first;
1938 current = (MaskAuto*)NEXT;
1940 gui->affected_point = points.size() - 1;
1943 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
1946 gui->current_operation = mwindow->edl->session->cwindow_operation;
1947 // Delete the template
1956 if( button_press && result ) {
1957 #ifdef USE_KEYFRAME_SPANNING
1958 MaskPoints &mask_points = points;
1960 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1961 MaskPoints &mask_points = mask->points;
1963 int k = gui->affected_point;
1964 if( k >= 0 && k < mask_points.size() ) {
1965 MaskPoint *point = mask_points.values[k];
1966 gui->center_x = point->x;
1967 gui->center_y = point->y;
1968 gui->control_in_x = point->control_x1;
1969 gui->control_in_y = point->control_y1;
1970 gui->control_out_x = point->control_x2;
1971 gui->control_out_y = point->control_y2;
1974 gui->center_x = gui->center_y = 0;
1975 gui->control_in_x = gui->control_in_y = 0;
1976 gui->control_out_x = gui->control_out_y = 0;
1978 gui->tool_panel->raise_window();
1981 //printf("CWindowCanvas::do_mask 8\n");
1982 if( cursor_motion ) {
1984 #ifdef USE_KEYFRAME_SPANNING
1985 // Must update the reference keyframes for every cursor motion
1986 gui->mask_keyframe = (MaskAuto*)gui->cwindow->
1987 calculate_affected_auto(mask_autos, 0);
1988 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1991 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1993 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1994 if( mask && gui->affected_point >= 0 &&
1995 gui->affected_point < mask->points.size() &&
1996 gui->current_operation != CWINDOW_NONE ) {
1997 // mwindow->undo->update_undo_before(_("mask point"), this);
1998 #ifdef USE_KEYFRAME_SPANNING
1999 MaskPoints &mask_points = points;
2001 MaskPoints &mask_points = mask->points;
2003 MaskPoint *point = mask_points.get(gui->affected_point);
2004 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2005 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask_points.size(), gui->affected_point);
2007 float last_x = point->x;
2008 float last_y = point->y;
2009 float last_control_x1 = point->control_x1;
2010 float last_control_y1 = point->control_y1;
2011 float last_control_x2 = point->control_x2;
2012 float last_control_y2 = point->control_y2;
2015 switch( gui->current_operation ) {
2017 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2018 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
2019 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
2022 case CWINDOW_MASK_CONTROL_IN:
2023 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
2024 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
2027 case CWINDOW_MASK_CONTROL_OUT:
2028 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
2029 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
2032 case CWINDOW_MASK_TRANSLATE: {
2033 if( !mask_gui ) break;
2034 int mode = mask_gui->scale_mode;
2035 MaskAuto *keyframe = gui->mask_keyframe;
2036 int gang = mask_gui->gang_focus->get_value();
2037 float dx = mask_cursor_x - gui->x_origin;
2038 float dy = mask_cursor_y - gui->y_origin;
2039 if( !dx && !dy ) break;
2040 int k = mwindow->edl->session->cwindow_mask;
2041 int n = gang ? keyframe->masks.size() : k+1;
2042 for( int j=gang? 0 : k; j<n; ++j ) {
2043 if( !mask_gui->mask_enables[j]->get_value() ) continue;
2044 SubMask *sub_mask = keyframe->get_submask(j);
2045 if( !sub_mask ) continue;
2046 MaskPoints &points = sub_mask->points;
2047 for( int i=0; i<points.size(); ++i ) {
2048 MaskPoint *point = points[i];
2049 if( mode == MASK_SCALE_X || mode == MASK_SCALE_XY ) point->x += dx;
2050 if( mode == MASK_SCALE_Y || mode == MASK_SCALE_XY ) point->y += dy;
2053 gui->x_origin = mask_cursor_x;
2054 gui->y_origin = mask_cursor_y;
2059 case CWINDOW_MASK_ROTATE:
2061 case CWINDOW_MASK_SCALE: {
2062 if( !mask_gui || !mask_points.size() ) break;
2063 float cx = gui->x_origin, cy = gui->y_origin;
2064 if( mask_gui->focused ) {
2065 cx = atof(mask_gui->focus_x->get_text());
2066 cy = atof(mask_gui->focus_y->get_text());
2068 else if( !gui->ctrl_down() ) {
2070 int n = mask_points.size();
2071 for( int i=0; i<n; ++i ) {
2072 MaskPoint *point = mask_points.values[i];
2073 cx += point->x; cy += point->y;
2076 mask_gui->set_focused(0, cx, cy);
2081 gui->get_triple_click() ? 8. :
2082 gui->get_double_click() ? 4. :
2084 int button_no = get_buttonpress();
2085 double ds = accel/64., dt = accel*M_PI/360.;
2086 double scale = button_no == WHEEL_UP ? 1.+ds : 1.-ds;
2087 int mode = mask_gui->scale_mode;
2088 double xscale = !rotate && (mode == MASK_SCALE_X ||
2089 mode == MASK_SCALE_XY ) ? scale : 1.;
2090 double yscale = !rotate && (mode == MASK_SCALE_Y ||
2091 mode == MASK_SCALE_XY ) ? scale : 1.;
2092 double theta = button_no == WHEEL_UP ? dt : -dt;
2093 if( rotate ? theta==0 : scale==1 ) break;
2094 float st = sin(theta), ct = cos(theta);
2095 MaskAuto *keyframe = gui->mask_keyframe;
2096 int gang = mask_gui->gang_focus->get_value();
2097 int k = mwindow->edl->session->cwindow_mask;
2098 int n = gang ? keyframe->masks.size() : k+1;
2099 for( int j=gang? 0 : k; j<n; ++j ) {
2100 if( !mask_gui->mask_enables[j]->get_value() ) continue;
2101 SubMask *sub_mask = keyframe->get_submask(j);
2102 if( !sub_mask ) continue;
2103 MaskPoints &points = sub_mask->points;
2104 for( int i=0; i<points.size(); ++i ) {
2105 MaskPoint *point = points[i];
2106 float px = point->x - gui->x_origin;
2107 float py = point->y - gui->y_origin;
2108 float nx = !rotate ? px*xscale : px*ct + py*st;
2109 float ny = !rotate ? py*yscale : py*ct - px*st;
2110 point->x = nx + gui->x_origin;
2111 point->y = ny + gui->y_origin;
2112 px = point->control_x1; py = point->control_y1;
2113 point->control_x1 = !rotate ? px*xscale : px*ct + py*st;
2114 point->control_y1 = !rotate ? py*yscale : py*ct - px*st;
2115 px = point->control_x2; py = point->control_y2;
2116 point->control_x2 = !rotate ? px*xscale : px*ct + py*st;
2117 point->control_y2 = !rotate ? py*yscale : py*ct - px*st;
2126 if( !(rerender && redraw) && (!EQUIV(last_x, point->x) ||
2127 !EQUIV(last_y, point->y) ||
2128 !EQUIV(last_control_x1, point->control_x1) ||
2129 !EQUIV(last_control_y1, point->control_y1) ||
2130 !EQUIV(last_control_x2, point->control_x2) ||
2131 !EQUIV(last_control_y2, point->control_y2)) ) {
2137 if( gui->current_operation == CWINDOW_NONE ) {
2138 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
2140 for( int i = 0; i < points.size() && !over_point; i++ ) {
2141 MaskPoint *point = points.get(i);
2142 float x0 = point->x;
2143 float y0 = point->y;
2144 float x1 = point->x + point->control_x1;
2145 float y1 = point->y + point->control_y1;
2146 float x2 = point->x + point->control_x2;
2147 float y2 = point->y + point->control_y2;
2148 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
2149 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
2151 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
2152 if( test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0) ) {
2156 if( !over_point && gui->ctrl_down() ) {
2157 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
2158 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
2159 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2160 if( test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1) ) {
2164 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2165 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2166 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2167 if( test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2) ) {
2174 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2179 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2182 #ifdef USE_KEYFRAME_SPANNING
2183 // Must commit change after operation.
2184 if( rerender && track ) {
2185 // Swap EDL keyframe with original.
2186 // Apply new values to keyframe span
2187 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2188 temp_keyframe.copy_data(gui->mask_keyframe);
2189 // Apply interpolated points back to keyframe
2191 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2192 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2193 mask_autos->update_parameter(&temp_keyframe);
2196 //printf("CWindowCanvas::do_mask 20\n");
2198 if( draw && draw_boundary && !draw_markers ) {
2199 BC_WindowBase *cvs_win = get_canvas();
2200 cvs_win->set_inverse();
2201 cvs_win->set_color(RED+GREEN);
2202 for( int k=0; k<SUBMASKS; ++k ) {
2203 if( k == mwindow->edl->session->cwindow_mask ) continue;
2204 points.remove_all_objects();
2205 if( use_interpolated )
2206 mask_autos->get_points(&points, k, position, PLAY_FORWARD);
2208 prev_mask->get_points(&points, k);
2210 edge.load(points, 0);
2211 for( int i=0; i<edge.size(); ++i ) {
2212 MaskCoord a = edge[i];
2213 MaskCoord b = i<edge.size()-1 ? edge[i+1] : edge[0];
2214 float ax = a.x, ay = a.y;
2215 float bx = b.x, by = b.y;
2216 output_to_canvas(mwindow->edl, 0, ax, ay);
2217 output_to_canvas(mwindow->edl, 0, bx, by);
2218 cvs_win->draw_line(ax,ay, bx,by);
2226 int CWindowCanvas::do_mask_focus()
2228 Track *track = gui->cwindow->calculate_affected_track();
2229 int64_t position = track->to_units(
2230 mwindow->edl->local_session->get_selectionstart(1),
2232 float projector_x, projector_y, projector_z;
2233 track->automation->get_projector(
2234 &projector_x, &projector_y, &projector_z,
2235 position, PLAY_FORWARD);
2236 float cx = get_cursor_x(), cy = get_cursor_y();
2237 canvas_to_output(mwindow->edl, 0, cx, cy);
2238 projector_x += mwindow->edl->session->output_w / 2;
2239 projector_y += mwindow->edl->session->output_h / 2;
2240 float half_track_w = (float)track->track_w / 2;
2241 float half_track_h = (float)track->track_h / 2;
2242 cx = (cx - projector_x) / projector_z + half_track_w;
2243 cy = (cy - projector_y) / projector_z + half_track_h;
2244 CWindowMaskGUI *mask_gui = (CWindowMaskGUI*) gui->tool_panel->tool_gui;
2245 mask_gui->set_focused(1, cx, cy);
2249 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2252 int radius = mwindow->edl->session->eyedrop_radius;
2260 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
2263 row1 = gui->eyedrop_y - radius;
2264 row2 = gui->eyedrop_y + radius;
2265 column1 = gui->eyedrop_x - radius;
2266 column2 = gui->eyedrop_x + radius;
2268 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2269 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2270 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2271 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2273 if( row2 <= row1 ) row2 = row1 + 1;
2274 if( column2 <= column1 ) column2 = column1 + 1;
2281 output_to_canvas(mwindow->edl, 0, x1, y1);
2282 output_to_canvas(mwindow->edl, 0, x2, y2);
2283 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2285 if( x2 - x1 >= 1 && y2 - y1 >= 1 ) {
2286 get_canvas()->set_inverse();
2287 get_canvas()->set_color(WHITE);
2289 get_canvas()->draw_rectangle((int)x1,
2294 get_canvas()->set_opaque();
2295 get_canvas()->flash();
2301 if( button_press ) {
2302 gui->current_operation = CWINDOW_EYEDROP;
2303 gui->tool_panel->raise_window();
2306 if( gui->current_operation == CWINDOW_EYEDROP ) {
2307 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2309 // Get color out of frame.
2310 // Doesn't work during playback because that bypasses the refresh frame.
2311 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
2312 float cursor_x = get_cursor_x();
2313 float cursor_y = get_cursor_y();
2314 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2315 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2316 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2318 row1 = cursor_y - radius;
2319 row2 = cursor_y + radius;
2320 column1 = cursor_x - radius;
2321 column2 = cursor_x + radius;
2322 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2323 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2324 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2325 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2326 if( row2 <= row1 ) row2 = row1 + 1;
2327 if( column2 <= column1 ) column2 = column1 + 1;
2331 if( gui->eyedrop_visible ) {
2333 do_eyedrop(temp, 0, 1);
2334 gui->eyedrop_visible = 0;
2337 gui->eyedrop_x = cursor_x;
2338 gui->eyedrop_y = cursor_y;
2343 do_eyedrop(temp, 0, 1);
2344 gui->eyedrop_visible = 1;
2347 // Decompression coefficients straight out of jpeglib
2348 #define V_TO_R 1.40200
2349 #define V_TO_G -0.71414
2351 #define U_TO_G -0.34414
2352 #define U_TO_B 1.77200
2354 #define GET_COLOR(type, components, max, do_yuv) \
2356 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2358 float red = (float)*row++ / max; \
2359 float green = (float)*row++ / max; \
2360 float blue = (float)*row++ / max; \
2363 float r = red + V_TO_R * (blue - 0.5); \
2364 float g = red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
2365 float b = red + U_TO_B * (green - 0.5); \
2366 mwindow->edl->local_session->red += r; \
2367 mwindow->edl->local_session->green += g; \
2368 mwindow->edl->local_session->blue += b; \
2369 if( r > mwindow->edl->local_session->red_max ) mwindow->edl->local_session->red_max = r; \
2370 if( g > mwindow->edl->local_session->green_max ) mwindow->edl->local_session->green_max = g; \
2371 if( b > mwindow->edl->local_session->blue_max ) mwindow->edl->local_session->blue_max = b; \
2375 mwindow->edl->local_session->red += red; \
2376 mwindow->edl->local_session->green += green; \
2377 mwindow->edl->local_session->blue += blue; \
2378 if( red > mwindow->edl->local_session->red_max ) mwindow->edl->local_session->red_max = red; \
2379 if( green > mwindow->edl->local_session->green_max ) mwindow->edl->local_session->green_max = green; \
2380 if( blue > mwindow->edl->local_session->blue_max ) mwindow->edl->local_session->blue_max = blue; \
2386 mwindow->edl->local_session->red = 0;
2387 mwindow->edl->local_session->green = 0;
2388 mwindow->edl->local_session->blue = 0;
2389 mwindow->edl->local_session->red_max = 0;
2390 mwindow->edl->local_session->green_max = 0;
2391 mwindow->edl->local_session->blue_max = 0;
2392 for( int i = row1; i < row2; i++ ) {
2393 for( int j = column1; j < column2; j++ ) {
2394 switch( refresh_frame->get_color_model() )
2397 GET_COLOR(unsigned char, 3, 0xff, 1);
2400 GET_COLOR(unsigned char, 4, 0xff, 1);
2403 GET_COLOR(uint16_t, 3, 0xffff, 1);
2405 case BC_YUVA16161616:
2406 GET_COLOR(uint16_t, 4, 0xffff, 1);
2409 GET_COLOR(unsigned char, 3, 0xff, 0);
2412 GET_COLOR(unsigned char, 4, 0xff, 0);
2415 GET_COLOR(float, 3, 1.0, 0);
2418 GET_COLOR(float, 4, 1.0, 0);
2424 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2425 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2426 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2430 mwindow->edl->local_session->red = 0;
2431 mwindow->edl->local_session->green = 0;
2432 mwindow->edl->local_session->blue = 0;
2433 gui->eyedrop_visible = 0;
2442 // Can't rerender since the color value is from the output of any effect it
2445 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2451 int CWindowCanvas::need_overlays()
2453 if( mwindow->edl->session->safe_regions ) return 1;
2454 if( mwindow->edl->session->cwindow_scrollbars ) return 1;
2455 if( gui->highlighted ) return 1;
2456 switch( mwindow->edl->session->cwindow_operation ) {
2457 case CWINDOW_EYEDROP:
2458 if( ! gui->eyedrop_visible ) break;
2459 case CWINDOW_CAMERA:
2460 case CWINDOW_PROJECTOR:
2469 void CWindowCanvas::draw_overlays()
2471 if( mwindow->edl->session->safe_regions ) {
2472 draw_safe_regions();
2475 if( mwindow->edl->session->cwindow_scrollbars ) {
2476 // Always draw output rectangle
2477 float x1, y1, x2, y2;
2479 x2 = mwindow->edl->session->output_w;
2481 y2 = mwindow->edl->session->output_h;
2482 output_to_canvas(mwindow->edl, 0, x1, y1);
2483 output_to_canvas(mwindow->edl, 0, x2, y2);
2485 get_canvas()->set_inverse();
2486 get_canvas()->set_color(WHITE);
2487 int ix1 = x1-1, iy1 = y1-1, ix2 = x2+1, iy2 = y2+1;
2488 get_canvas()->draw_rectangle(ix1, iy1, ix2-ix1, iy2-iy1);
2489 get_canvas()->set_opaque();
2492 if( gui->highlighted ) {
2493 get_canvas()->set_color(WHITE);
2494 get_canvas()->set_inverse();
2495 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2496 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2497 get_canvas()->set_opaque();
2500 int temp1 = 0, temp2 = 0;
2501 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2502 switch( mwindow->edl->session->cwindow_operation )
2504 case CWINDOW_CAMERA:
2508 case CWINDOW_PROJECTOR:
2517 do_mask(temp1, temp2, 0, 0, 1);
2521 do_ruler(1, 0, 0, 0);
2524 case CWINDOW_EYEDROP:
2525 if( gui->eyedrop_visible ) {
2527 do_eyedrop(rerender, 0, 1);
2528 gui->eyedrop_visible = 1;
2534 void CWindowCanvas::draw_safe_regions()
2536 float action_x1, action_x2, action_y1, action_y2;
2537 float title_x1, title_x2, title_y1, title_y2;
2539 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2540 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2541 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2542 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2543 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2544 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2545 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2546 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2548 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2549 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2550 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2551 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2553 get_canvas()->set_inverse();
2554 get_canvas()->set_color(WHITE);
2556 get_canvas()->draw_rectangle((int)action_x1,
2558 (int)(action_x2 - action_x1),
2559 (int)(action_y2 - action_y1));
2560 get_canvas()->draw_rectangle((int)title_x1,
2562 (int)(title_x2 - title_x1),
2563 (int)(title_y2 - title_y1));
2565 get_canvas()->set_opaque();
2569 void CWindowCanvas::create_keyframe(int do_camera)
2571 Track *affected_track = gui->cwindow->calculate_affected_track();
2572 if( affected_track ) {
2573 double pos = mwindow->edl->local_session->get_selectionstart(1);
2574 int64_t position = affected_track->to_units(pos, 0);
2575 int ix = do_camera ? AUTOMATION_CAMERA_X : AUTOMATION_PROJECTOR_X;
2576 int iy = do_camera ? AUTOMATION_CAMERA_Y : AUTOMATION_PROJECTOR_Y;
2577 int iz = do_camera ? AUTOMATION_CAMERA_Z : AUTOMATION_PROJECTOR_Z;
2578 FloatAuto *prev, *next;
2579 FloatAutos **autos = (FloatAutos**)affected_track->automation->autos;
2580 FloatAutos *x_autos = autos[ix]; prev = 0; next = 0;
2581 float x_value = x_autos->get_value(position, PLAY_FORWARD, prev, next);
2582 FloatAutos *y_autos = autos[iy]; prev = 0; next = 0;
2583 float y_value = y_autos->get_value(position, PLAY_FORWARD, prev, next);
2584 FloatAutos *z_autos = autos[iz]; prev = 0; next = 0;
2585 float z_value = z_autos->get_value(position, PLAY_FORWARD, prev, next);
2586 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2588 gui->cwindow->calculate_affected_autos(affected_track,
2589 &x_keyframe, &y_keyframe, &z_keyframe,
2590 do_camera, -1, -1, -1, 0);
2591 x_keyframe->set_value(x_value);
2592 y_keyframe->set_value(y_value);
2593 z_keyframe->set_value(z_value);
2595 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2599 void CWindowCanvas::camera_keyframe() { create_keyframe(1); }
2600 void CWindowCanvas::projector_keyframe() { create_keyframe(0); }
2602 void CWindowCanvas::reset_keyframe(int do_camera)
2604 Track *affected_track = gui->cwindow->calculate_affected_track();
2605 if( affected_track ) {
2606 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2607 gui->cwindow->calculate_affected_autos(affected_track,
2608 &x_keyframe, &y_keyframe, &z_keyframe,
2609 do_camera, 1, 1, 1);
2611 x_keyframe->set_value(0);
2612 y_keyframe->set_value(0);
2613 z_keyframe->set_value(1);
2615 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2619 void CWindowCanvas::reset_camera() { reset_keyframe(1); }
2620 void CWindowCanvas::reset_projector() { reset_keyframe(0); }
2623 int CWindowCanvas::test_crop(int button_press, int &redraw)
2626 int handle_selected = -1;
2627 float x1 = mwindow->edl->session->crop_x1;
2628 float y1 = mwindow->edl->session->crop_y1;
2629 float x2 = mwindow->edl->session->crop_x2;
2630 float y2 = mwindow->edl->session->crop_y2;
2631 float cursor_x = get_cursor_x();
2632 float cursor_y = get_cursor_y();
2633 float canvas_x1 = x1;
2634 float canvas_y1 = y1;
2635 float canvas_x2 = x2;
2636 float canvas_y2 = y2;
2637 float canvas_cursor_x = cursor_x;
2638 float canvas_cursor_y = cursor_y;
2640 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2641 // Use screen normalized coordinates for hot spot tests.
2642 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2643 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2646 if( gui->current_operation == CWINDOW_CROP ) {
2647 handle_selected = gui->crop_handle;
2650 if( canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2651 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H ) {
2652 handle_selected = 0;
2653 gui->crop_origin_x = x1;
2654 gui->crop_origin_y = y1;
2657 if( canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2658 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H ) {
2659 handle_selected = 1;
2660 gui->crop_origin_x = x2;
2661 gui->crop_origin_y = y1;
2664 if( canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2665 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2 ) {
2666 handle_selected = 2;
2667 gui->crop_origin_x = x1;
2668 gui->crop_origin_y = y2;
2671 if( canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2672 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2 ) {
2673 handle_selected = 3;
2674 gui->crop_origin_x = x2;
2675 gui->crop_origin_y = y2;
2680 gui->crop_origin_x = cursor_x;
2681 gui->crop_origin_y = cursor_y;
2684 // printf("test crop %d %d\n",
2685 // gui->current_operation,
2686 // handle_selected);
2689 if( button_press ) {
2690 if( gui->alt_down() ) {
2691 gui->crop_translate = 1;
2692 gui->crop_origin_x1 = x1;
2693 gui->crop_origin_y1 = y1;
2694 gui->crop_origin_x2 = x2;
2695 gui->crop_origin_y2 = y2;
2698 gui->crop_translate = 0;
2700 gui->current_operation = CWINDOW_CROP;
2701 gui->crop_handle = handle_selected;
2702 gui->x_origin = cursor_x;
2703 gui->y_origin = cursor_y;
2704 gui->tool_panel->raise_window();
2707 if( handle_selected < 0 && !gui->crop_translate ) {
2710 mwindow->edl->session->crop_x1 = (int)x1;
2711 mwindow->edl->session->crop_y1 = (int)y1;
2712 mwindow->edl->session->crop_x2 = (int)x2;
2713 mwindow->edl->session->crop_y2 = (int)y2;
2718 // Translate all 4 points
2719 if( gui->current_operation == CWINDOW_CROP && gui->crop_translate ) {
2720 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2721 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2722 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2723 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2725 mwindow->edl->session->crop_x1 = (int)x1;
2726 mwindow->edl->session->crop_y1 = (int)y1;
2727 mwindow->edl->session->crop_x2 = (int)x2;
2728 mwindow->edl->session->crop_y2 = (int)y2;
2734 if( gui->current_operation == CWINDOW_CROP ) {
2735 switch( gui->crop_handle ) {
2737 x1 = gui->crop_origin_x;
2738 y1 = gui->crop_origin_y;
2739 x2 = gui->crop_origin_x;
2740 y2 = gui->crop_origin_y;
2741 if( cursor_x < gui->x_origin ) {
2742 if( cursor_y < gui->y_origin ) {
2747 if( cursor_y >= gui->y_origin ) {
2753 if( cursor_x >= gui->x_origin ) {
2754 if( cursor_y < gui->y_origin ) {
2759 if( cursor_y >= gui->y_origin ) {
2765 // printf("test crop %d %d %d %d\n",
2766 // mwindow->edl->session->crop_x1,
2767 // mwindow->edl->session->crop_y1,
2768 // mwindow->edl->session->crop_x2,
2769 // mwindow->edl->session->crop_y2);
2772 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2773 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2776 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2777 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2780 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2781 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2784 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2785 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2789 if( !EQUIV(mwindow->edl->session->crop_x1, x1) ||
2790 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2791 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2792 !EQUIV(mwindow->edl->session->crop_y2, y2) ) {
2797 switch( gui->crop_handle ) {
2798 case 0: gui->crop_handle = 1; break;
2799 case 1: gui->crop_handle = 0; break;
2800 case 2: gui->crop_handle = 3; break;
2801 case 3: gui->crop_handle = 2; break;
2810 switch( gui->crop_handle ) {
2811 case 0: gui->crop_handle = 2; break;
2812 case 1: gui->crop_handle = 3; break;
2813 case 2: gui->crop_handle = 0; break;
2814 case 3: gui->crop_handle = 1; break;
2819 mwindow->edl->session->crop_x1 = (int)x1;
2820 mwindow->edl->session->crop_y1 = (int)y1;
2821 mwindow->edl->session->crop_x2 = (int)x2;
2822 mwindow->edl->session->crop_y2 = (int)y2;
2828 // Update cursor font
2829 if( handle_selected >= 0 ) {
2830 switch( handle_selected ) {
2831 case 0: set_cursor(UPLEFT_RESIZE); break;
2832 case 1: set_cursor(UPRIGHT_RESIZE); break;
2833 case 2: set_cursor(DOWNLEFT_RESIZE); break;
2834 case 3: set_cursor(DOWNRIGHT_RESIZE); break;
2839 set_cursor(ARROW_CURSOR);
2841 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2844 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2845 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2846 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2847 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2848 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2849 // mwindow->edl->session->crop_x2,
2850 // mwindow->edl->session->crop_y2,
2851 // mwindow->edl->calculate_output_w(0),
2852 // mwindow->edl->calculate_output_h(0));
2858 void CWindowCanvas::draw_crop()
2860 get_canvas()->set_inverse();
2861 get_canvas()->set_color(WHITE);
2863 float x1 = mwindow->edl->session->crop_x1;
2864 float y1 = mwindow->edl->session->crop_y1;
2865 float x2 = mwindow->edl->session->crop_x2;
2866 float y2 = mwindow->edl->session->crop_y2;
2868 output_to_canvas(mwindow->edl, 0, x1, y1);
2869 output_to_canvas(mwindow->edl, 0, x2, y2);
2871 if( x2 - x1 && y2 - y1 )
2872 get_canvas()->draw_rectangle((int)x1,
2877 draw_crophandle((int)x1, (int)y1);
2878 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2879 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2880 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2881 get_canvas()->set_opaque();
2885 void CWindowCanvas::draw_outlines(int do_camera)
2887 Track *track = gui->cwindow->calculate_affected_track();
2889 if( !track ) return;
2891 float proj_x, proj_y, proj_z;
2892 int64_t position = track->to_units(
2893 mwindow->edl->local_session->get_selectionstart(1),
2895 track->automation->get_projector(&proj_x, &proj_y, &proj_z,
2896 position, PLAY_FORWARD);
2898 proj_x += mwindow->edl->session->output_w/2.;
2899 proj_y += mwindow->edl->session->output_h/2.;
2900 float proj_x1 = proj_x - track->track_w/2. * proj_z;
2901 float proj_y1 = proj_y - track->track_h/2. * proj_z;
2902 float proj_x2 = proj_x + track->track_w/2. * proj_z;
2903 float proj_y2 = proj_y + track->track_h/2. * proj_z;
2904 float x1 = proj_x1, x2 = proj_x2;
2905 float y1 = proj_y1, y2 = proj_y2;
2906 output_to_canvas(mwindow->edl, 0, x1, y1);
2907 output_to_canvas(mwindow->edl, 0, x2, y2);
2909 #define DRAW_PROJECTION(offset) \
2910 get_canvas()->draw_rectangle(x1+offset, y1+offset, (x2-x1), (y2-y1)); \
2911 get_canvas()->draw_line(x1+offset, y1+offset, x2+offset, y2+offset); \
2912 get_canvas()->draw_line(x2+offset, y1+offset, x1+offset, y2+offset); \
2915 get_canvas()->set_color(BLACK);
2917 get_canvas()->set_color(do_camera ? GREEN : RED);
2921 float cam_x, cam_y, cam_z;
2922 track->automation->get_camera(&cam_x, &cam_y, &cam_z,
2923 position, PLAY_FORWARD);
2924 cam_x += track->track_w / 2.;
2925 cam_y += track->track_h / 2.;
2926 // follow image, not camera
2927 cam_x = -cam_x; cam_y = -cam_y; cam_z *= proj_z;
2928 float cam_x1 = cam_x * cam_z + proj_x;
2929 float cam_y1 = cam_y * cam_z + proj_y;
2930 float cam_x2 = (cam_x + track->track_w) * cam_z + proj_x;
2931 float cam_y2 = (cam_y + track->track_h) * cam_z + proj_y;
2932 output_to_canvas(mwindow->edl, 0, cam_x1, cam_y1);
2933 output_to_canvas(mwindow->edl, 0, cam_x2, cam_y2);
2934 get_canvas()->set_color(YELLOW);
2935 get_canvas()->draw_rectangle(cam_x1, cam_y1, cam_x2-cam_x1, cam_y2-cam_y1);
2939 int CWindowCanvas::test_bezier(int button_press,
2947 // Processing drag operation.
2948 // Create keyframe during first cursor motion.
2949 if( !button_press ) {
2951 float cursor_x = get_cursor_x();
2952 float cursor_y = get_cursor_y();
2953 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2955 if( gui->current_operation == CWINDOW_CAMERA ||
2956 gui->current_operation == CWINDOW_PROJECTOR ) {
2957 if( !gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom ) {
2958 gui->translating_zoom = 1;
2959 gui->reset_affected();
2961 else if( !gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom ) {
2962 gui->translating_zoom = 0;
2963 gui->reset_affected();
2966 // Get target keyframe
2967 if( !gui->affected_x && !gui->affected_y && !gui->affected_z ) {
2968 if( !gui->affected_track ) return 0;
2969 FloatAutos *affected_x_autos, *affected_y_autos, *affected_z_autos;
2970 FloatAutos** autos = (FloatAutos**) gui->affected_track->automation->autos;
2971 if( mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA ) {
2972 affected_x_autos = autos[AUTOMATION_CAMERA_X];
2973 affected_y_autos = autos[AUTOMATION_CAMERA_Y];
2974 affected_z_autos = autos[AUTOMATION_CAMERA_Z];
2977 affected_x_autos = autos[AUTOMATION_PROJECTOR_X];
2978 affected_y_autos = autos[AUTOMATION_PROJECTOR_Y];
2979 affected_z_autos = autos[AUTOMATION_PROJECTOR_Z];
2981 double position = mwindow->edl->local_session->get_selectionstart(1);
2982 int64_t track_position = gui->affected_track->to_units(position, 0);
2983 FloatAuto *prev_x = 0, *next_x = 0;
2984 float new_x = affected_x_autos->get_value(track_position, PLAY_FORWARD, prev_x, next_x);
2985 FloatAuto *prev_y = 0, *next_y = 0;
2986 float new_y = affected_y_autos->get_value(track_position, PLAY_FORWARD, prev_y, next_y);
2987 FloatAuto *prev_z = 0, *next_z = 0;
2988 float new_z = affected_z_autos->get_value(track_position, PLAY_FORWARD, prev_z, next_z);
2989 int zooming = gui->translating_zoom, created;
2990 gui->affected_x = (FloatAuto*)gui->cwindow->calculate_affected_auto(
2991 affected_x_autos, !zooming, &created, 0);
2993 gui->affected_x->set_value(new_x);
2996 gui->affected_y = (FloatAuto*)gui->cwindow->calculate_affected_auto(
2997 affected_y_autos, !zooming, &created, 0);
2999 gui->affected_y->set_value(new_y);
3002 gui->affected_z = (FloatAuto*)gui->cwindow->calculate_affected_auto(
3003 affected_z_autos, zooming, &created, 0);
3005 gui->affected_z->set_value(new_z);
3010 if( gui->translating_zoom ) {
3011 gui->center_z = gui->affected_z->get_value();
3014 gui->center_x = gui->affected_x->get_value();
3015 gui->center_y = gui->affected_y->get_value();
3022 float x_val = gui->affected_x->get_value();
3023 float y_val = gui->affected_y->get_value();
3024 float z_val = gui->affected_z->get_value();
3026 if( gui->translating_zoom ) {
3027 float z = gui->center_z + (cursor_y - gui->y_origin) / yS(128);
3029 if( !EQUIV(z_val, z) ) {
3034 gui->affected_z->set_value(z);
3037 float dx = cursor_x - gui->x_origin;
3038 float dy = cursor_y - gui->y_origin;
3039 // follow image, not camera
3040 if( gui->current_operation == CWINDOW_CAMERA ) {
3041 dx = -dx / z_val; dy = -dy / z_val;
3043 float x = gui->center_x + dx;
3044 float y = gui->center_y + dy;
3045 gui->affected_x->set_value(x);
3046 gui->affected_y->set_value(y);
3047 if( !EQUIV(x_val, x) || !EQUIV(y_val, y) ) {
3058 // Begin drag operation. Don't create keyframe here.
3060 // Get affected track off of the first recordable video track.
3061 // Calculating based on the alpha channel would require recording what layer
3062 // each output pixel belongs to as they're rendered and stacked. Forget it.
3063 gui->affected_track = gui->cwindow->calculate_affected_track();
3064 gui->reset_affected();
3066 if( gui->affected_track ) {
3068 mwindow->undo->update_undo_before(_("camera"), this);
3070 mwindow->undo->update_undo_before(_("projector"), this);
3072 gui->current_operation =
3073 mwindow->edl->session->cwindow_operation;
3074 gui->tool_panel->raise_window();
3082 int CWindowCanvas::test_zoom(int &redraw)
3085 int button = get_buttonpress();
3086 if( button == LEFT_BUTTON )
3087 button = gui->shift_down() ? WHEEL_DOWN : WHEEL_UP;
3088 if( !(zoom = get_zoom()) )
3089 zoom = get_auto_zoom(mwindow->edl);
3093 for( ; idx < total_zooms; ++idx ) {
3094 if( EQUIV(zoom, my_zoom_table[idx]) ) continue;
3095 if( zoom < my_zoom_table[idx] ) break;
3097 float zoom11 = 1.1f * zoom;
3098 zoom = idx < total_zooms ? my_zoom_table[idx] : zoom11;
3099 if( zoom > zoom11 ) zoom = zoom11;
3102 int idx = total_zooms;
3103 for( ; --idx >= 0; ) {
3104 if( EQUIV(my_zoom_table[idx], zoom) ) continue;
3105 if( my_zoom_table[idx] < zoom ) break;
3107 float zoom09 = 0.9f * zoom;
3108 zoom = idx >= 0 ? my_zoom_table[idx] : zoom09;
3109 if( zoom < zoom09 ) zoom = zoom09;
3112 if( gui->shift_down() ) {
3116 default: // fall thru
3119 float cx = get_cursor_x(), cy = get_cursor_y();
3120 set_zoom(mwindow->edl, zoom, cx, cy);
3121 gui->zoom_panel->update(zoom);
3122 gui->update_canvas();
3128 void CWindowCanvas::calculate_origin()
3130 float zoom_x, zoom_y, conformed_w, conformed_h;
3131 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3132 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3133 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3134 gui->x_origin = (float)get_cursor_x() / zoom_x + gui->x_offset;
3135 gui->y_origin = (float)get_cursor_y() / zoom_y + gui->y_offset;
3139 int CWindowCanvas::cursor_leave_event()
3141 set_cursor(ARROW_CURSOR);
3145 int CWindowCanvas::cursor_enter_event()
3148 switch( mwindow->edl->session->cwindow_operation ) {
3149 case CWINDOW_CAMERA:
3150 case CWINDOW_PROJECTOR:
3151 set_cursor(MOVE_CURSOR);
3154 set_cursor(MOVE_CURSOR);
3157 test_crop(0, redraw);
3159 case CWINDOW_PROTECT:
3160 set_cursor(ARROW_CURSOR);
3164 set_cursor(CROSS_CURSOR);
3166 case CWINDOW_EYEDROP:
3167 set_cursor(CROSS_CURSOR);
3173 int CWindowCanvas::cursor_motion_event()
3175 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3178 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3179 switch( gui->current_operation ) {
3180 case CWINDOW_SCROLL: {
3181 result = do_scroll(mwindow->edl, get_cursor_x(), get_cursor_y());
3185 result = do_ruler(0, 1, 0, 0);
3188 case CWINDOW_CAMERA:
3189 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3192 case CWINDOW_PROJECTOR:
3193 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3197 result = test_crop(0, redraw);
3198 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3199 // __LINE__, result, redraw);
3203 case CWINDOW_MASK_CONTROL_IN:
3204 case CWINDOW_MASK_CONTROL_OUT:
3205 case CWINDOW_MASK_TRANSLATE:
3206 result = do_mask(redraw, rerender, 0, 1, 0);
3209 case CWINDOW_EYEDROP:
3210 result = do_eyedrop(rerender, 0, 0);
3218 // cursor font changes
3220 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3221 // __LINE__, mwindow->edl->session->cwindow_operation);
3222 switch( mwindow->edl->session->cwindow_operation ) {
3224 result = test_crop(0, redraw);
3227 result = do_ruler(0, 1, 0, 0);
3230 result = do_mask(redraw, rerender, 0, 1, 0);
3235 int change_type = rerender ? CHANGE_PARAMS : -1;
3236 gui->sync_parameters(change_type, redraw, redraw_canvas);
3241 int CWindowCanvas::button_press_event()
3245 int redraw_canvas = 0;
3248 if( Canvas::button_press_event() ) return 1;
3250 gui->translating_zoom = gui->shift_down();
3254 if( mwindow->edl->session->cwindow_operation != CWINDOW_PROTECT &&
3255 get_buttonpress() == MIDDLE_BUTTON && !get_canvas()->shift_down() ) {
3256 gui->current_operation = CWINDOW_SCROLL;
3261 switch( mwindow->edl->session->cwindow_operation ) {
3263 result = do_ruler(0, 0, 1, 0);
3266 case CWINDOW_CAMERA:
3267 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3270 case CWINDOW_PROJECTOR:
3271 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3275 result = test_zoom(redraw);
3279 result = test_crop(1, redraw);
3283 switch( get_buttonpress() ) {
3285 result = do_mask(redraw, rerender, 1, 0, 0);
3287 case MIDDLE_BUTTON: { // && shift_down()
3288 result = do_mask_focus();
3289 redraw = redraw_canvas = 1;
3293 result = do_mask(redraw, rerender, 1, 1, 0);
3296 if( result ) redraw_canvas = 1;
3299 case CWINDOW_EYEDROP:
3300 result = do_eyedrop(rerender, 1, 0);
3305 int change_type = rerender ? CHANGE_PARAMS : -1;
3306 gui->sync_parameters(change_type, redraw, redraw_canvas);
3311 int CWindowCanvas::button_release_event()
3314 const char *undo_label = 0;
3316 switch( gui->current_operation ) {
3317 case CWINDOW_SCROLL:
3322 do_ruler(0, 0, 0, 1);
3325 case CWINDOW_CAMERA:
3326 undo_label = _("camera");
3329 case CWINDOW_PROJECTOR:
3330 undo_label = _("projector");
3334 case CWINDOW_MASK_CONTROL_IN:
3335 case CWINDOW_MASK_CONTROL_OUT:
3336 case CWINDOW_MASK_TRANSLATE:
3337 // Finish mask operation
3338 gui->mask_keyframe = 0;
3339 undo_label = _("mask");
3341 case CWINDOW_MASK_ROTATE:
3342 gui->mask_keyframe = 0;
3343 undo_label = _("mask rotate");
3345 case CWINDOW_MASK_SCALE:
3346 gui->mask_keyframe = 0;
3347 undo_label = _("mask scale");
3350 result = Canvas::button_release_event();
3355 mwindow->undo->update_undo_after(undo_label, LOAD_AUTOMATION);
3356 gui->current_operation = CWINDOW_NONE;
3360 void CWindowCanvas::zoom_resize_window(float percentage)
3362 int canvas_w, canvas_h;
3365 // Get required canvas size
3366 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3367 mwindow->edl->session->output_w,
3368 mwindow->edl->session->output_h,
3369 percentage, canvas_w, canvas_h);
3371 // Estimate window size from current borders
3372 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3373 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3375 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3376 mwindow->session->cwindow_w = new_w;
3377 mwindow->session->cwindow_h = new_h;
3379 mwindow->theme->get_cwindow_sizes(gui,
3380 mwindow->session->cwindow_controls);
3382 // Estimate again from new borders
3383 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3384 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3385 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3387 gui->resize_window(new_w, new_h);
3388 gui->resize_event(new_w, new_h);
3391 void CWindowCanvas::toggle_controls()
3393 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3394 gui->resize_event(gui->get_w(), gui->get_h());
3397 int CWindowCanvas::get_cwindow_controls()
3399 return mwindow->session->cwindow_controls;
3402 int CWindowCanvas::get_clear_color()
3404 int color = mwindow->edl->session->cwindow_clear_color;
3405 if( color < 0 ) color = Canvas::get_clear_color();