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() ) {
447 canvas->use_fullscreen(canvas->get_fullscreen() ? 0 : 1);
448 lock_window("CWindowGUI::keypress_event 1");
452 if( ctrl_down() || shift_down() || alt_down() ) break;
454 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
456 mwindow->gui->unlock_window();
457 lock_window("CWindowGUI::keypress_event 2");
462 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
463 mwindow->clear_entry();
464 mwindow->gui->unlock_window();
465 lock_window("CWindowGUI::keypress_event 3");
470 canvas->use_fullscreen(0);
471 lock_window("CWindowGUI::keypress_event 4");
476 int alt_down = this->alt_down();
477 int shift_down = this->shift_down();
480 mwindow->gui->lock_window("CWindowGUI::keypress_event 5");
482 mwindow->prev_edit_handle(shift_down);
484 mwindow->move_left();
485 mwindow->gui->unlock_window();
486 lock_window("CWindowGUI::keypress_event 6");
492 if( !ctrl_down() && !alt_down() ) {
495 mwindow->gui->lock_window("CWindowGUI::keypress_event 7");
496 mwindow->move_left();
497 mwindow->gui->unlock_window();
498 lock_window("CWindowGUI::keypress_event 8");
505 int alt_down = this->alt_down();
506 int shift_down = this->shift_down();
509 mwindow->gui->lock_window("CWindowGUI::keypress_event 8");
511 mwindow->next_edit_handle(shift_down);
513 mwindow->move_right();
514 mwindow->gui->unlock_window();
515 lock_window("CWindowGUI::keypress_event 9");
521 if( !ctrl_down() && !alt_down() ) {
524 mwindow->gui->lock_window("CWindowGUI::keypress_event 10");
525 mwindow->move_right();
526 mwindow->gui->unlock_window();
527 lock_window("CWindowGUI::keypress_event 11");
533 if( !result && cwindow_operation < 0 && ctrl_down() && shift_down() ) {
534 switch( get_keypress() ) {
535 case KEY_F1 ... KEY_F4: // mainmenu, load layout
536 resend_event(mwindow->gui);
541 if( !result && !ctrl_down() ) {
542 switch( get_keypress() ) {
545 mwindow->toggle_camera_xyz(); result = 1;
548 cwindow_operation = CWINDOW_PROTECT;
552 mwindow->toggle_projector_xyz(); result = 1;
555 cwindow_operation = CWINDOW_ZOOM;
559 if( !result && cwindow_operation < 0 && !ctrl_down() && !shift_down() ) {
560 switch( get_keypress() ) {
561 case KEY_F3: cwindow_operation = CWINDOW_MASK; break;
562 case KEY_F4: cwindow_operation = CWINDOW_RULER; break;
563 case KEY_F5: cwindow_operation = CWINDOW_CAMERA; break;
564 case KEY_F6: cwindow_operation = CWINDOW_PROJECTOR; break;
565 case KEY_F7: cwindow_operation = CWINDOW_CROP; break;
566 case KEY_F8: cwindow_operation = CWINDOW_EYEDROP; break;
567 case KEY_F9: cwindow_operation = CWINDOW_TOOL_WINDOW; break;
568 case KEY_F10: cwindow_operation = CWINDOW_TITLESAFE; break;
571 if( !result && cwindow_operation < 0 && !ctrl_down() ) {
572 switch( get_keypress() ) {
575 canvas->reset_camera();
577 canvas->camera_keyframe();
582 canvas->reset_projector();
584 canvas->projector_keyframe();
590 if( cwindow_operation >= 0 ) {
591 set_operation(cwindow_operation);
596 result = transport->keypress_event();
602 void CWindowGUI::reset_affected()
609 void CWindowGUI::keyboard_zoomin()
611 zoom_panel->zoom_tumbler->handle_up_event();
614 void CWindowGUI::keyboard_zoomout()
616 zoom_panel->zoom_tumbler->handle_down_event();
619 void CWindowGUI::sync_parameters(int change_type, int redraw, int overlay)
625 if( change_type < 0 && !overlay ) return;
627 if( change_type >= 0 ) {
628 mwindow->restart_brender();
629 mwindow->sync_parameters(change_type);
632 mwindow->gui->lock_window("CWindowGUI::sync_parameters");
633 mwindow->gui->draw_overlays(1);
634 mwindow->gui->unlock_window();
636 lock_window("CWindowGUI::sync_parameters");
639 void CWindowGUI::drag_motion()
641 if( get_hidden() ) return;
643 if( mwindow->session->current_operation != DRAG_ASSET &&
644 mwindow->session->current_operation != DRAG_VTRANSITION &&
645 mwindow->session->current_operation != DRAG_VEFFECT ) return;
646 int need_highlight = cursor_above() && get_cursor_over_window();
647 if( highlighted == need_highlight ) return;
648 highlighted = need_highlight;
652 int CWindowGUI::drag_stop()
655 if( get_hidden() ) return 0;
656 if( !highlighted ) return 0;
657 if( mwindow->session->current_operation != DRAG_ASSET &&
658 mwindow->session->current_operation != DRAG_VTRANSITION &&
659 mwindow->session->current_operation != DRAG_VEFFECT) return 0;
664 if( mwindow->session->current_operation == DRAG_ASSET ) {
665 if( mwindow->session->drag_assets->total ||
666 mwindow->session->drag_clips->total ) {
667 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
668 mwindow->undo->update_undo_before(_("insert assets"), 0);
671 if( mwindow->session->drag_assets->total ) {
673 mwindow->load_assets(mwindow->session->drag_assets,
674 mwindow->edl->local_session->get_selectionstart(),
676 mwindow->session->track_highlighted,
678 mwindow->edl->session->labels_follow_edits,
679 mwindow->edl->session->plugins_follow_edits,
680 mwindow->edl->session->autos_follow_edits,
684 if( mwindow->session->drag_clips->total ) {
686 mwindow->paste_edls(mwindow->session->drag_clips,
688 mwindow->session->track_highlighted,
689 mwindow->edl->local_session->get_selectionstart(),
690 mwindow->edl->session->labels_follow_edits,
691 mwindow->edl->session->plugins_follow_edits,
692 mwindow->edl->session->autos_follow_edits,
696 if( mwindow->session->drag_assets->total ||
697 mwindow->session->drag_clips->total ) {
698 mwindow->save_backup();
699 mwindow->restart_brender();
700 mwindow->gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
701 mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
702 mwindow->gui->unlock_window();
703 sync_parameters(CHANGE_ALL);
707 if( mwindow->session->current_operation == DRAG_VEFFECT ) {
708 //printf("CWindowGUI::drag_stop 1\n");
709 Track *affected_track = cwindow->calculate_affected_track();
710 //printf("CWindowGUI::drag_stop 2\n");
712 mwindow->gui->lock_window("CWindowGUI::drag_stop 3");
713 mwindow->insert_effects_cwindow(affected_track);
714 mwindow->session->current_operation = NO_OPERATION;
715 mwindow->gui->unlock_window();
718 if( mwindow->session->current_operation == DRAG_VTRANSITION ) {
719 Track *affected_track = cwindow->calculate_affected_track();
720 mwindow->gui->lock_window("CWindowGUI::drag_stop 4");
721 mwindow->paste_transition_cwindow(affected_track);
722 mwindow->session->current_operation = NO_OPERATION;
723 mwindow->gui->unlock_window();
729 void CWindowGUI::update_meters()
731 if( mwindow->edl->session->cwindow_meter != meters->visible ) {
732 meters->set_meters(meters->meter_count, mwindow->edl->session->cwindow_meter);
733 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
734 resize_event(get_w(), get_h());
738 void CWindowGUI::stop_transport(const char *lock_msg)
740 if( lock_msg ) unlock_window();
741 mwindow->stop_transport();
742 if( lock_msg ) lock_window(lock_msg);
746 CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
747 : EditPanel(mwindow, cwindow->gui, CWINDOW_ID,
748 mwindow->theme->cedit_x, mwindow->theme->cedit_y,
749 mwindow->edl->session->editing_mode,
750 0, // use_editing_mode
767 this->mwindow = mwindow;
768 this->cwindow = cwindow;
771 #define relock_cm(s) \
772 cwindow->gui->unlock_window(); \
773 mwindow->gui->lock_window("CWindowEditing::" s)
774 #define relock_mc(s) \
775 mwindow->gui->unlock_window(); \
776 cwindow->gui->lock_window("CWindowEditing::" s)
777 #define panel_fn(fn, args, s) \
778 CWindowEditing::fn args { relock_cm(#fn); s; relock_mc(#fn); }
780 // transmit lock to mwindow, and run mbutton->edit_panel->s
781 #define panel_btn(fn, args, s) \
782 panel_fn(panel_##fn, args, mwindow->gui->mbuttons->edit_panel->panel_##s)
785 double CWindowEditing::get_position()
787 relock_cm("get_position");
788 double ret = mwindow->edl->local_session->get_selectionstart(1);
789 relock_mc("get_position");
793 void CWindowEditing::set_position(double position)
795 relock_cm("set_position");
796 mwindow->gui->mbuttons->edit_panel->set_position(position);
797 relock_mc("set_position");
800 void CWindowEditing::set_click_to_play(int v)
802 relock_cm("set_position");
803 mwindow->edl->session->cwindow_click2play = v;
804 relock_mc("set_position");
805 click2play->update(v);
809 void panel_btn(stop_transport,(), stop_transport())
810 void panel_btn(toggle_label,(), toggle_label())
811 void panel_btn(next_label,(int cut), next_label(cut))
812 void panel_btn(prev_label,(int cut), prev_label(cut))
813 void panel_btn(next_edit,(int cut), next_edit(cut))
814 void panel_btn(prev_edit,(int cut), prev_edit(cut))
815 void panel_fn(panel_copy_selection,(), mwindow->copy())
816 void CWindowEditing::panel_overwrite_selection() {} // not used
817 void CWindowEditing::panel_splice_selection() {} // not used
818 void panel_btn(set_inpoint,(), set_inpoint())
819 void panel_btn(set_outpoint,(), set_outpoint())
820 void panel_btn(unset_inoutpoint,(), unset_inoutpoint())
821 void panel_fn(panel_to_clip,(), mwindow->to_clip(mwindow->edl, _("main window: "), 0))
822 void panel_btn(cut,(), cut())
823 void panel_btn(paste,(), paste())
824 void panel_btn(fit_selection,(), fit_selection())
825 void panel_btn(fit_autos,(int all), fit_autos(all))
826 void panel_btn(set_editing_mode,(int mode), set_editing_mode(mode))
827 void panel_btn(set_auto_keyframes,(int v), set_auto_keyframes(v))
828 void panel_btn(set_span_keyframes,(int v), set_span_keyframes(v))
829 void panel_btn(set_labels_follow_edits,(int v), set_labels_follow_edits(v))
832 CWindowMeters::CWindowMeters(MWindow *mwindow,
833 CWindowGUI *gui, int x, int y, int h)
834 : MeterPanel(mwindow, gui, x, y, -1, h,
835 mwindow->edl->session->audio_channels,
836 mwindow->edl->session->cwindow_meter,
839 this->mwindow = mwindow;
843 CWindowMeters::~CWindowMeters()
847 int CWindowMeters::change_status_event(int new_status)
849 mwindow->edl->session->cwindow_meter = new_status;
850 gui->update_meters();
857 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
858 : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
859 x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
861 this->mwindow = mwindow;
865 CWindowZoom::~CWindowZoom()
869 void CWindowZoom::update(double value)
871 char string[BCSTRLEN];
872 const char *cp = string;
875 int frac = value >= 1.0f ? 1 :
877 value >= .01f ? 3 : 4;
878 sprintf(string, "x %.*f", frac, value);
882 ZoomPanel::update(cp);
885 int CWindowZoom::handle_event()
887 double value = !strcasecmp(gui->auto_zoom, get_text()) ? 0 : get_value();
888 gui->canvas->set_zoom(mwindow->edl, value);
889 gui->update_canvas();
896 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
897 : BC_PercentageSlider(x, y, 0, pixels, pixels, 0, 1, 0)
899 this->mwindow = mwindow;
900 this->cwindow = cwindow;
901 set_precision(0.00001);
904 CWindowSlider::~CWindowSlider()
908 int CWindowSlider::handle_event()
910 cwindow->update_position((double)get_value());
914 void CWindowSlider::set_position()
916 double new_length = mwindow->edl->tracks->total_length();
917 update(mwindow->theme->cslider_w,
918 mwindow->edl->local_session->get_selectionstart(1),
923 int CWindowSlider::increase_value()
926 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
927 lock_window("CWindowSlider::increase_value");
931 int CWindowSlider::decrease_value()
934 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
935 lock_window("CWindowSlider::decrease_value");
941 CWindowTransport::CWindowTransport(MWindow *mwindow,
942 CWindowGUI *gui, int x, int y)
943 : PlayTransport(mwindow, gui, x, y)
948 EDL* CWindowTransport::get_edl()
953 void CWindowTransport::goto_start()
955 gui->unlock_window();
956 handle_transport(REWIND, 1);
958 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
959 mwindow->goto_start();
960 mwindow->gui->unlock_window();
962 gui->lock_window("CWindowTransport::goto_start 2");
965 void CWindowTransport::goto_end()
967 gui->unlock_window();
968 handle_transport(GOTO_END, 1);
970 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
972 mwindow->gui->unlock_window();
974 gui->lock_window("CWindowTransport::goto_end 2");
979 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
980 : Canvas(mwindow, gui,
981 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
982 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h,
983 0, 0, mwindow->edl->session->cwindow_scrollbars)
985 this->mwindow = mwindow;
989 void CWindowCanvas::status_event()
994 void CWindowCanvas::update_zoom(int x, int y, float zoom)
996 mwindow->edl->session->cwindow_xscroll = x;
997 mwindow->edl->session->cwindow_yscroll = y;
998 mwindow->edl->session->cwindow_zoom = zoom;
999 use_scrollbars = !zoom ? 0 : 1;
1000 mwindow->edl->session->cwindow_scrollbars = use_scrollbars;
1003 int CWindowCanvas::use_fullscreen(int on)
1005 if( Canvas::use_fullscreen(on) ) {
1006 gui->lock_window("CWindowCanvas::use_fullscreen");
1008 if( !on ) gui->zoom_panel->update(0);
1009 gui->unlock_window();
1014 int CWindowCanvas::get_xscroll()
1016 return mwindow->edl->session->cwindow_xscroll;
1019 int CWindowCanvas::get_yscroll()
1021 return mwindow->edl->session->cwindow_yscroll;
1025 float CWindowCanvas::get_zoom()
1027 return mwindow->edl->session->cwindow_zoom;
1030 void CWindowCanvas::zoom_auto()
1033 set_zoom(mwindow->edl, 0);
1034 gui->update_canvas();
1037 int CWindowCanvas::do_scroll(EDL *edl, float cursor_x, float cursor_y)
1039 float zoom = get_zoom();
1040 float zoom_x, zoom_y, conformed_w, conformed_h;
1041 get_zooms(edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
1043 x = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
1044 y = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
1045 zoom = get_auto_zoom(mwindow->edl);
1048 x = gui->x_origin - cursor_x / zoom_x;
1049 y = gui->y_origin - cursor_y / zoom_y;
1051 update_zoom(x, y, zoom);
1052 gui->update_canvas();
1056 void CWindowCanvas::draw_refresh(int flush)
1058 BC_WindowBase *window = get_canvas();
1059 if( window && !window->get_video_on() ) {
1061 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
1062 float in_x1, in_y1, in_x2, in_y2;
1063 float out_x1, out_y1, out_x2, out_y2;
1064 get_transfers(mwindow->edl,
1065 in_x1, in_y1, in_x2, in_y2,
1066 out_x1, out_y1, out_x2, out_y2);
1069 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1070 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1073 if( out_x2 > out_x1 && out_y2 > out_y1 &&
1074 in_x2 > in_x1 && in_y2 > in_y1 ) {
1075 // input scaled from session to refresh frame coordinates
1076 int ow = get_output_w(mwindow->edl);
1077 int oh = get_output_h(mwindow->edl);
1078 int rw = refresh_frame->get_w();
1079 int rh = refresh_frame->get_h();
1080 float xs = (float)rw / ow;
1081 float ys = (float)rh / oh;
1082 in_x1 *= xs; in_x2 *= xs;
1083 in_y1 *= ys; in_y2 *= ys;
1084 // Can't use OpenGL here because it is called asynchronously of the
1085 // playback operation.
1086 window->draw_vframe(refresh_frame,
1087 (int)out_x1, (int)out_y1,
1088 (int)(out_x2 - out_x1),
1089 (int)(out_y2 - out_y1),
1090 (int)in_x1, (int)in_y1,
1091 (int)(in_x2 - in_x1),
1092 (int)(in_y2 - in_y1),
1098 window->flash(flush);
1100 //printf("CWindowCanvas::draw_refresh 10\n");
1103 #define CROPHANDLE_W xS(10)
1104 #define CROPHANDLE_H yS(10)
1106 void CWindowCanvas::draw_crophandle(int x, int y)
1108 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1112 #define CONTROL_W xS(10)
1113 #define CONTROL_H yS(10)
1114 #define FIRST_CONTROL_W xS(20)
1115 #define FIRST_CONTROL_H yS(20)
1117 #define BC_INFINITY 65536
1119 #define RULERHANDLE_W xS(16)
1120 #define RULERHANDLE_H yS(16)
1122 int CWindowCanvas::do_ruler(int draw, int motion,
1123 int button_press, int button_release)
1126 EDLSession *session = mwindow->edl->session;
1127 float x1 = session->ruler_x1;
1128 float y1 = session->ruler_y1;
1129 float x2 = session->ruler_x2;
1130 float y2 = session->ruler_y2;
1131 float canvas_x1 = x1;
1132 float canvas_y1 = y1;
1133 float canvas_x2 = x2;
1134 float canvas_y2 = y2;
1135 float output_x = get_cursor_x();
1136 float output_y = get_cursor_y();
1137 float canvas_cursor_x = output_x;
1138 float canvas_cursor_y = output_y;
1140 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1141 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1142 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1143 mwindow->session->cwindow_output_x = roundf(output_x);
1144 mwindow->session->cwindow_output_y = roundf(output_y);
1146 if( button_press && get_buttonpress() == 1 ) {
1147 gui->ruler_handle = -1;
1148 gui->ruler_translate = 0;
1149 if( gui->alt_down() ) {
1150 gui->ruler_translate = 1;
1151 gui->ruler_origin_x = x1;
1152 gui->ruler_origin_y = y1;
1155 if( canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1156 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1157 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1158 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2 ) {
1159 gui->ruler_handle = 0;
1160 gui->ruler_origin_x = x1;
1161 gui->ruler_origin_y = y1;
1164 if( canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1165 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1166 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1167 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2 ) {
1168 gui->ruler_handle = 1;
1169 gui->ruler_origin_x = x2;
1170 gui->ruler_origin_y = y2;
1174 // Start new selection
1175 if( !gui->ruler_translate &&
1176 (gui->ruler_handle < 0 ||
1180 do_ruler(1, 0, 0, 0);
1181 get_canvas()->flash();
1182 gui->ruler_handle = 1;
1183 session->ruler_x1 = output_x;
1184 session->ruler_y1 = output_y;
1185 session->ruler_x2 = output_x;
1186 session->ruler_y2 = output_y;
1187 gui->ruler_origin_x = session->ruler_x2;
1188 gui->ruler_origin_y = session->ruler_y2;
1191 gui->x_origin = output_x;
1192 gui->y_origin = output_y;
1193 gui->current_operation = CWINDOW_RULER;
1194 gui->tool_panel->raise_window();
1199 if( gui->current_operation == CWINDOW_RULER ) {
1200 if( gui->ruler_translate ) {
1202 do_ruler(1, 0, 0, 0);
1203 float x_difference = session->ruler_x1;
1204 float y_difference = session->ruler_y1;
1205 session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1206 session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1207 x_difference -= session->ruler_x1;
1208 y_difference -= session->ruler_y1;
1209 session->ruler_x2 -= x_difference;
1210 session->ruler_y2 -= y_difference;
1212 do_ruler(1, 0, 0, 0);
1213 get_canvas()->flash();
1217 switch( gui->ruler_handle ) {
1219 do_ruler(1, 0, 0, 0);
1220 session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1221 session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1222 if( gui->alt_down() || gui->ctrl_down() ) {
1223 double angle_value = fabs(atan((session->ruler_y2 - session->ruler_y1) /
1224 (session->ruler_x2 - session->ruler_x1)) *
1226 double distance_value =
1227 sqrt(SQR(session->ruler_x2 - session->ruler_x1) +
1228 SQR(session->ruler_y2 - session->ruler_y1));
1229 if( angle_value < 22 )
1230 session->ruler_y1 = session->ruler_y2;
1232 if( angle_value > 67 )
1233 session->ruler_x1 = session->ruler_x2;
1235 if( session->ruler_x1 < session->ruler_x2 &&
1236 session->ruler_y1 < session->ruler_y2 ) {
1237 session->ruler_x1 = session->ruler_x2 - distance_value / 1.414214;
1238 session->ruler_y1 = session->ruler_y2 - distance_value / 1.414214;
1241 if( session->ruler_x1 < session->ruler_x2 && session->ruler_y1 > session->ruler_y2 ) {
1242 session->ruler_x1 = session->ruler_x2 - distance_value / 1.414214;
1243 session->ruler_y1 = session->ruler_y2 + distance_value / 1.414214;
1246 if( session->ruler_x1 > session->ruler_x2 &&
1247 session->ruler_y1 < session->ruler_y2 ) {
1248 session->ruler_x1 = session->ruler_x2 + distance_value / 1.414214;
1249 session->ruler_y1 = session->ruler_y2 - distance_value / 1.414214;
1252 session->ruler_x1 = session->ruler_x2 + distance_value / 1.414214;
1253 session->ruler_y1 = session->ruler_y2 + distance_value / 1.414214;
1256 do_ruler(1, 0, 0, 0);
1257 get_canvas()->flash();
1262 do_ruler(1, 0, 0, 0);
1263 session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1264 session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1265 if( gui->alt_down() || gui->ctrl_down() ) {
1266 double angle_value = fabs(atan((session->ruler_y2 - session->ruler_y1) /
1267 (session->ruler_x2 - session->ruler_x1)) *
1269 double distance_value =
1270 sqrt(SQR(session->ruler_x2 - session->ruler_x1) +
1271 SQR(session->ruler_y2 - session->ruler_y1));
1272 if( angle_value < 22 )
1273 session->ruler_y2 = session->ruler_y1;
1275 if( angle_value > 67 )
1276 session->ruler_x2 = session->ruler_x1;
1278 if( session->ruler_x2 < session->ruler_x1 &&
1279 session->ruler_y2 < session->ruler_y1 ) {
1280 session->ruler_x2 = session->ruler_x1 - distance_value / 1.414214;
1281 session->ruler_y2 = session->ruler_y1 - distance_value / 1.414214;
1284 if( session->ruler_x2 < session->ruler_x1 &&
1285 session->ruler_y2 > session->ruler_y1 ) {
1286 session->ruler_x2 = session->ruler_x1 - distance_value / 1.414214;
1287 session->ruler_y2 = session->ruler_y1 + distance_value / 1.414214;
1290 if( session->ruler_x2 > session->ruler_x1 && session->ruler_y2 < session->ruler_y1 ) {
1291 session->ruler_x2 = session->ruler_x1 + distance_value / 1.414214;
1292 session->ruler_y2 = session->ruler_y1 - distance_value / 1.414214;
1295 session->ruler_x2 = session->ruler_x1 + distance_value / 1.414214;
1296 session->ruler_y2 = session->ruler_y1 + distance_value / 1.414214;
1299 do_ruler(1, 0, 0, 0);
1300 get_canvas()->flash();
1305 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1308 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1313 if( canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1314 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1315 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1316 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2 ) {
1317 set_cursor(UPRIGHT_ARROW_CURSOR);
1320 if( canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1321 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1322 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1323 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2 ) {
1324 set_cursor(UPRIGHT_ARROW_CURSOR);
1327 set_cursor(CROSS_CURSOR);
1329 // Update current position
1334 // Assume no ruler measurement if 0 length
1335 if( draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)) ) {
1336 get_canvas()->set_inverse();
1337 get_canvas()->set_color(WHITE);
1338 get_canvas()->draw_line((int)canvas_x1,
1342 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1344 roundf(canvas_x1) + RULERHANDLE_W / 2,
1346 get_canvas()->draw_line(roundf(canvas_x1),
1347 roundf(canvas_y1) - RULERHANDLE_H / 2,
1349 roundf(canvas_y1) + RULERHANDLE_H / 2);
1350 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1352 roundf(canvas_x2) + RULERHANDLE_W / 2,
1354 get_canvas()->draw_line(roundf(canvas_x2),
1355 roundf(canvas_y2) - RULERHANDLE_H / 2,
1357 roundf(canvas_y2) + RULERHANDLE_H / 2);
1358 get_canvas()->set_opaque();
1365 static inline double line_dist(float cx,float cy, float tx,float ty)
1367 double dx = tx-cx, dy = ty-cy;
1368 return sqrt(dx*dx + dy*dy);
1371 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1373 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1374 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1378 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1379 int button_press, int cursor_motion, int draw)
1381 // Retrieve points from top recordable track
1382 //printf("CWindowCanvas::do_mask 1\n");
1383 Track *track = gui->cwindow->calculate_mask_track();
1384 //printf("CWindowCanvas::do_mask 2\n");
1386 if( !track ) return 0;
1387 //printf("CWindowCanvas::do_mask 3\n");
1388 CWindowMaskGUI *mask_gui = (CWindowMaskGUI *)
1389 (gui->tool_panel ? gui->tool_panel->tool_gui : 0);
1390 int draw_markers = mask_gui ? mask_gui->markers : 0;
1391 int draw_boundary = mask_gui ? mask_gui->boundary : 0;
1392 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1393 int64_t position = track->to_units(
1394 mwindow->edl->local_session->get_selectionstart(1),
1396 Auto *prev_auto = 0;
1397 mask_autos->get_prev_auto(position, PLAY_FORWARD, (Auto *&)prev_auto, 1);
1398 MaskAuto *prev_mask = (MaskAuto *)prev_auto;
1400 int update_points = 1;
1401 // Determine the points based on whether
1402 // new keyframes will be generated or drawing is performed.
1403 // If keyframe generation occurs, use the interpolated mask.
1404 // If no keyframe generation occurs, use the previous mask.
1405 int use_interpolated = 0;
1406 if( button_press || cursor_motion ) {
1407 #ifdef USE_KEYFRAME_SPANNING
1408 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1409 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1410 int64_t start_pos = track->to_units(selection_start, 0);
1411 int64_t end_pos = track->to_units(selection_end, 0);
1412 Auto *first = 0, *last = 0;
1413 mask_autos->get_prev_auto(start_pos, PLAY_FORWARD, first, 1);
1414 mask_autos->get_prev_auto(end_pos, PLAY_FORWARD, last, 1);
1415 if( last == first && (!mwindow->edl->session->auto_keyframes) )
1416 use_interpolated = 0;
1418 // If keyframe spanning occurs, use the interpolated points.
1419 // If new keyframe is generated, use the interpolated points.
1420 use_interpolated = 1;
1423 if( mwindow->edl->session->auto_keyframes )
1424 use_interpolated = 1;
1428 use_interpolated = 1;
1430 if( use_interpolated ) {
1431 // Interpolate the points to get exactly what is being rendered at this position.
1432 mask_autos->get_points(&points,
1433 mwindow->edl->session->cwindow_mask,
1434 position, PLAY_FORWARD);
1437 // Use the prev mask
1438 prev_mask->get_points(&points,
1439 mwindow->edl->session->cwindow_mask);
1442 // Projector zooms relative to the center of the track output.
1443 float half_track_w = (float)track->track_w / 2;
1444 float half_track_h = (float)track->track_h / 2;
1445 // Translate mask to projection
1446 float projector_x, projector_y, projector_z;
1447 track->automation->get_projector(
1448 &projector_x, &projector_y, &projector_z,
1449 position, PLAY_FORWARD);
1452 // Get position of cursor relative to mask
1453 float cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
1454 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1455 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1457 projector_x += mwindow->edl->session->output_w / 2;
1458 projector_y += mwindow->edl->session->output_h / 2;
1459 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1460 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1462 // Fix cursor origin
1463 if( button_press ) {
1464 gui->x_origin = mask_cursor_x;
1465 gui->y_origin = mask_cursor_y;
1469 // Points of closest line
1470 int shortest_point1 = -1;
1471 int shortest_point2 = -1;
1473 int shortest_point = -1;
1474 // Distance to closest line
1475 float shortest_line_distance = BC_INFINITY;
1476 // Distance to closest point
1477 float shortest_point_distance = BC_INFINITY;
1478 int selected_point = -1;
1479 int selected_control_point = -1;
1480 float selected_control_point_distance = BC_INFINITY;
1481 ArrayList<int> x_points;
1482 ArrayList<int> y_points;
1484 if( !cursor_motion ) {
1486 get_canvas()->set_color(WHITE);
1487 get_canvas()->set_inverse();
1489 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1491 // Never draw closed polygon and a closed
1492 // polygon is harder to add points to.
1493 for( int i = 0; i < points.size() && !result; i++ ) {
1494 MaskPoint *point1 = points.get(i);
1495 MaskPoint *point2 = (i >= points.size() - 1) ?
1496 points.get(0) : points.get(i + 1);
1497 if( button_press ) {
1498 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1499 if( point_distance1 < shortest_point_distance || shortest_point < 0 ) {
1500 shortest_point_distance = point_distance1;
1504 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1505 if( point_distance2 < shortest_point_distance || shortest_point < 0 ) {
1506 shortest_point_distance = point_distance2;
1507 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1511 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1513 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1514 //point1->x, point1->y, point2->x, point2->y, projector_z);
1515 for( int j = 0; j <= segments && !result; j++ ) {
1516 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1517 float x0 = point1->x, y0 = point1->y;
1518 float x1 = point1->x + point1->control_x2;
1519 float y1 = point1->y + point1->control_y2;
1520 float x2 = point2->x + point2->control_x1;
1521 float y2 = point2->y + point2->control_y1;
1522 float x3 = point2->x, y3 = point2->y;
1523 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1524 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1525 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1526 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1527 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1528 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1529 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1530 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1532 float t = (float)j / segments;
1533 float tpow2 = t * t;
1534 float tpow3 = t * t * t;
1536 float invtpow2 = invt * invt;
1537 float invtpow3 = invt * invt * invt;
1539 float x = ( invtpow3 * x0
1540 + 3 * t * invtpow2 * x1
1541 + 3 * tpow2 * invt * x2
1543 float y = ( invtpow3 * y0
1544 + 3 * t * invtpow2 * y1
1545 + 3 * tpow2 * invt * y2
1547 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1548 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1549 // Test new point addition
1550 if( button_press ) {
1551 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1553 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1554 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1555 if( line_distance < shortest_line_distance ||
1556 shortest_point1 < 0 ) {
1557 shortest_line_distance = line_distance;
1558 shortest_point1 = i;
1559 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1560 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1561 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1564 // Test existing point selection
1566 if( gui->ctrl_down() ) {
1567 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1569 if( distance < selected_control_point_distance ) {
1571 selected_control_point = 1;
1572 selected_control_point_distance = distance;
1576 if( !gui->shift_down() ) {
1577 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1578 if( test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0) ) {
1583 selected_point = shortest_point;
1586 // Test second point
1587 if( gui->ctrl_down() ) {
1588 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1590 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1591 if( distance < selected_control_point_distance ) {
1592 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1593 selected_control_point = 0;
1594 selected_control_point_distance = distance;
1597 else if( i < points.size() - 1 ) {
1598 if( !gui->shift_down() ) {
1599 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1600 if( test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3) ) {
1601 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1605 selected_point = shortest_point;
1610 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1614 if( draw ) { // Draw joining line
1615 x_points.append((int)canvas_x);
1616 y_points.append((int)canvas_y);
1619 if( j == segments ) {
1620 if( draw && draw_markers ) { // Draw second anchor
1621 if( i < points.size() - 1 ) {
1622 if( i == gui->affected_point - 1 )
1623 get_canvas()->draw_disc(
1624 (int)canvas_x - CONTROL_W / 2,
1625 (int)canvas_y - CONTROL_W / 2,
1626 CONTROL_W, CONTROL_H);
1628 get_canvas()->draw_circle(
1629 (int)canvas_x - CONTROL_W / 2,
1630 (int)canvas_y - CONTROL_W / 2,
1631 CONTROL_W, CONTROL_H);
1632 // char string[BCTEXTLEN];
1633 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1634 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1636 // Draw second control point.
1637 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1638 get_canvas()->draw_line(
1639 (int)canvas_x, (int)canvas_y,
1640 (int)canvas_x2, (int)canvas_y2);
1641 get_canvas()->draw_rectangle(
1642 (int)canvas_x2 - CONTROL_W / 2,
1643 (int)canvas_y2 - CONTROL_H / 2,
1644 CONTROL_W, CONTROL_H);
1649 // Draw first anchor
1650 if( i == 0 && draw ) {
1651 if( draw_boundary ) {
1652 char mask_label[BCSTRLEN];
1653 int k = mwindow->edl->session->cwindow_mask;
1654 if( !prev_mask || k < 0 || k >= prev_mask->masks.size() )
1655 sprintf(mask_label, "%d", k);
1657 sprintf(mask_label, "%s", prev_mask->masks[k]->name);
1658 get_canvas()->draw_text(
1659 (int)canvas_x - FIRST_CONTROL_W,
1660 (int)canvas_y - FIRST_CONTROL_H,
1663 if( draw_markers ) {
1664 get_canvas()->draw_disc(
1665 (int)canvas_x - FIRST_CONTROL_W / 2,
1666 (int)canvas_y - FIRST_CONTROL_H / 2,
1667 FIRST_CONTROL_W, FIRST_CONTROL_H);
1671 // Draw first control point.
1672 if( draw && draw_markers ) {
1673 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1674 get_canvas()->draw_line(
1675 (int)canvas_x, (int)canvas_y,
1676 (int)canvas_x1, (int)canvas_y1);
1677 get_canvas()->draw_rectangle(
1678 (int)canvas_x1 - CONTROL_W / 2,
1679 (int)canvas_y1 - CONTROL_H / 2,
1680 CONTROL_W, CONTROL_H);
1682 x_points.append((int)canvas_x);
1683 y_points.append((int)canvas_y);
1686 //printf("CWindowCanvas::do_mask 1\n");
1690 //printf("CWindowCanvas::do_mask 1\n");
1692 BC_WindowBase *cvs_win = get_canvas();
1693 if( draw && draw_boundary ) {
1694 cvs_win->draw_polygon(&x_points, &y_points);
1695 cvs_win->set_opaque();
1697 if( draw && mask_gui && mask_gui->focused ) {
1698 float fx = atof(mask_gui->focus_x->get_text());
1699 float fy = atof(mask_gui->focus_y->get_text());
1700 fx = (fx - half_track_w) * projector_z + projector_x;
1701 fy = (fy - half_track_h) * projector_z + projector_y;
1702 output_to_canvas(mwindow->edl, 0, fx, fy);
1703 float r = bmax(cvs_win->get_w(), cvs_win->get_h());
1706 int fw = 2*d+3, fh = fw;
1707 VFrame focus(fw,fh, BC_RGBA8888);
1708 focus.transfer_from(gui->focus_frame);
1709 fx -= fw/2.f; fy -= fh/2.f;
1710 BC_Pixmap focus_pixmap(cvs_win, &focus, PIXMAP_ALPHA);
1711 cvs_win->draw_pixmap(&focus_pixmap,fx,fy);
1713 cvs_win->set_line_width((int)(0.0025*r) + 1);
1714 cvs_win->set_color(BLUE);
1715 cvs_win->draw_line(fx-d,fy-d, fx+d, fy+d);
1716 cvs_win->draw_line(fx-d,fy+d, fx+d, fy-d);
1717 cvs_win->set_line_width(0);
1718 cvs_win->set_color(WHITE);
1721 if( draw && mask_gui && draw_markers && points.size() ) {
1722 float cx = 0, cy = 0;
1723 int n = points.size();
1724 for( int i=0; i<n; ++i ) {
1725 MaskPoint *point = points.get(i);
1726 cx += point->x; cy += point->y;
1729 if( !mask_gui->focused )
1730 mask_gui->set_focused(0, cx, cy);
1731 cx = (cx - half_track_w) * projector_z + projector_x;
1732 cy = (cy - half_track_h) * projector_z + projector_y;
1733 output_to_canvas(mwindow->edl, 0, cx, cy);
1734 float r = bmax(cvs_win->get_w(), cvs_win->get_h());
1736 cvs_win->set_line_width((int)(0.002*r) + 1);
1737 cvs_win->set_color(ORANGE);
1738 cvs_win->draw_line(cx-d,cy, cx+d, cy);
1739 cvs_win->draw_line(cx,cy-d, cx, cy+d);
1740 cvs_win->set_line_width(0);
1741 cvs_win->set_color(WHITE);
1743 //printf("CWindowCanvas::do_mask 1\n");
1746 if( button_press && !result ) {
1747 gui->affected_track = gui->cwindow->calculate_mask_track();
1749 // Get keyframe outside the EDL to edit. This must be rendered
1750 // instead of the EDL keyframes when it exists. Then it must be
1751 // applied to the EDL keyframes on buttonrelease.
1752 if( gui->affected_track ) {
1753 #ifdef USE_KEYFRAME_SPANNING
1754 // Make copy of current parameters in local keyframe
1755 gui->mask_keyframe =
1756 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1758 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1761 gui->mask_keyframe =
1762 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1766 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1768 if( get_buttonpress() == WHEEL_UP || get_buttonpress() == WHEEL_DOWN ) {
1769 if( !gui->shift_down() ) {
1770 mwindow->undo->update_undo_before(_("mask rotate"), this);
1771 gui->current_operation = CWINDOW_MASK_ROTATE;
1774 mwindow->undo->update_undo_before(_("mask scale"), this);
1775 gui->current_operation = CWINDOW_MASK_SCALE;
1777 gui->affected_point = 0;
1780 // Translate entire keyframe
1781 if( gui->alt_down() && mask->points.size() ) {
1782 mwindow->undo->update_undo_before(_("mask translate"), 0);
1783 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1784 gui->affected_point = 0;
1787 // Existing point or control point was selected
1788 if( selected_point >= 0 ) {
1789 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1790 gui->affected_point = selected_point;
1792 if( selected_control_point == 0 )
1793 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1795 if( selected_control_point == 1 )
1796 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1798 gui->current_operation = mwindow->edl->session->cwindow_operation;
1800 else // No existing point or control point was selected so create a new one
1801 if( !gui->ctrl_down() && !gui->alt_down() ) {
1802 mwindow->undo->update_undo_before(_("mask point"), 0);
1803 // Create the template
1804 MaskPoint *point = new MaskPoint;
1805 point->x = mask_cursor_x;
1806 point->y = mask_cursor_y;
1807 point->control_x1 = 0;
1808 point->control_y1 = 0;
1809 point->control_x2 = 0;
1810 point->control_y2 = 0;
1813 if( shortest_point2 < shortest_point1 ) {
1814 shortest_point2 ^= shortest_point1;
1815 shortest_point1 ^= shortest_point2;
1816 shortest_point2 ^= shortest_point1;
1821 // printf("CWindowGUI::do_mask 40\n");
1822 // mwindow->edl->dump();
1823 // printf("CWindowGUI::do_mask 50\n");
1827 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1828 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1829 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1831 // Append to end of list
1832 if( shortest_point1 == shortest_point2 ||
1833 labs(shortest_point1 - shortest_point2) > 1) {
1834 #ifdef USE_KEYFRAME_SPANNING
1836 MaskPoint *new_point = new MaskPoint;
1837 points.append(new_point);
1838 *new_point = *point;
1839 gui->affected_point = points.size() - 1;
1843 // Need to apply the new point to every keyframe
1844 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1845 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1846 MaskPoint *new_point = new MaskPoint;
1847 submask->points.append(new_point);
1848 *new_point = *point;
1849 if( current == (MaskAuto*)mask_autos->default_auto )
1850 current = (MaskAuto*)mask_autos->first;
1852 current = (MaskAuto*)NEXT;
1854 gui->affected_point = mask->points.size() - 1;
1860 // Insert between 2 points, shifting back point 2
1861 if( shortest_point1 >= 0 && shortest_point2 >= 0 ) {
1863 #ifdef USE_KEYFRAME_SPANNING
1864 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1866 if( points.size() >= shortest_point2 ) {
1867 MaskPoint *new_point = new MaskPoint;
1869 for( int i = points.size() - 1;
1870 i > shortest_point2;
1872 points.values[i] = points.values[i - 1];
1873 points.values[shortest_point2] = new_point;
1875 *new_point = *point;
1880 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1881 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1882 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1884 if( submask->points.size() >= shortest_point2 ) {
1885 MaskPoint *new_point = new MaskPoint;
1886 submask->points.append(0);
1887 for( int i = submask->points.size() - 1;
1888 i > shortest_point2;
1890 submask->points.values[i] = submask->points.values[i - 1];
1891 submask->points.values[shortest_point2] = new_point;
1893 *new_point = *point;
1896 if( current == (MaskAuto*)mask_autos->default_auto )
1897 current = (MaskAuto*)mask_autos->first;
1899 current = (MaskAuto*)NEXT;
1903 gui->affected_point = shortest_point2;
1908 // printf("CWindowGUI::do_mask 20\n");
1909 // mwindow->edl->dump();
1910 // printf("CWindowGUI::do_mask 30\n");
1913 //printf("CWindowCanvas::do_mask 1\n");
1914 // Create the first point.
1915 #ifdef USE_KEYFRAME_SPANNING
1916 MaskPoint *new_point = new MaskPoint;
1917 points.append(new_point);
1918 *new_point = *point;
1919 gui->affected_point = points.size() - 1;
1921 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1922 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1923 MaskPoint *new_point = new MaskPoint;
1924 submask->points.append(new_point);
1925 *new_point = *point;
1926 if( current == (MaskAuto*)mask_autos->default_auto )
1927 current = (MaskAuto*)mask_autos->first;
1929 current = (MaskAuto*)NEXT;
1931 gui->affected_point = points.size() - 1;
1934 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
1937 gui->current_operation = mwindow->edl->session->cwindow_operation;
1938 // Delete the template
1947 if( button_press && result ) {
1948 #ifdef USE_KEYFRAME_SPANNING
1949 MaskPoints &mask_points = points;
1951 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1952 MaskPoints &mask_points = mask->points;
1954 int k = gui->affected_point;
1955 if( k >= 0 && k < mask_points.size() ) {
1956 MaskPoint *point = mask_points.values[k];
1957 gui->center_x = point->x;
1958 gui->center_y = point->y;
1959 gui->control_in_x = point->control_x1;
1960 gui->control_in_y = point->control_y1;
1961 gui->control_out_x = point->control_x2;
1962 gui->control_out_y = point->control_y2;
1965 gui->center_x = gui->center_y = 0;
1966 gui->control_in_x = gui->control_in_y = 0;
1967 gui->control_out_x = gui->control_out_y = 0;
1969 gui->tool_panel->raise_window();
1972 //printf("CWindowCanvas::do_mask 8\n");
1973 if( cursor_motion ) {
1975 #ifdef USE_KEYFRAME_SPANNING
1976 // Must update the reference keyframes for every cursor motion
1977 gui->mask_keyframe = (MaskAuto*)gui->cwindow->
1978 calculate_affected_auto(mask_autos, 0);
1979 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1982 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1984 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1985 if( mask && gui->affected_point >= 0 &&
1986 gui->affected_point < mask->points.size() &&
1987 gui->current_operation != CWINDOW_NONE ) {
1988 // mwindow->undo->update_undo_before(_("mask point"), this);
1989 #ifdef USE_KEYFRAME_SPANNING
1990 MaskPoints &mask_points = points;
1992 MaskPoints &mask_points = mask->points;
1994 MaskPoint *point = mask_points.get(gui->affected_point);
1995 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
1996 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask_points.size(), gui->affected_point);
1998 float last_x = point->x;
1999 float last_y = point->y;
2000 float last_control_x1 = point->control_x1;
2001 float last_control_y1 = point->control_y1;
2002 float last_control_x2 = point->control_x2;
2003 float last_control_y2 = point->control_y2;
2006 switch( gui->current_operation ) {
2008 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2009 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
2010 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
2013 case CWINDOW_MASK_CONTROL_IN:
2014 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
2015 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
2018 case CWINDOW_MASK_CONTROL_OUT:
2019 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
2020 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
2023 case CWINDOW_MASK_TRANSLATE: {
2024 if( !mask_gui ) break;
2025 int mode = mask_gui->scale_mode;
2026 MaskAuto *keyframe = gui->mask_keyframe;
2027 int gang = mask_gui->gang_focus->get_value();
2028 float dx = mask_cursor_x - gui->x_origin;
2029 float dy = mask_cursor_y - gui->y_origin;
2030 if( !dx && !dy ) break;
2031 int k = mwindow->edl->session->cwindow_mask;
2032 int n = gang ? keyframe->masks.size() : k+1;
2033 for( int j=gang? 0 : k; j<n; ++j ) {
2034 if( !mask_gui->mask_enables[j]->get_value() ) continue;
2035 SubMask *sub_mask = keyframe->get_submask(j);
2036 if( !sub_mask ) continue;
2037 MaskPoints &points = sub_mask->points;
2038 for( int i=0; i<points.size(); ++i ) {
2039 MaskPoint *point = points[i];
2040 if( mode == MASK_SCALE_X || mode == MASK_SCALE_XY ) point->x += dx;
2041 if( mode == MASK_SCALE_Y || mode == MASK_SCALE_XY ) point->y += dy;
2044 gui->x_origin = mask_cursor_x;
2045 gui->y_origin = mask_cursor_y;
2050 case CWINDOW_MASK_ROTATE:
2052 case CWINDOW_MASK_SCALE: {
2053 if( !mask_gui || !mask_points.size() ) break;
2054 float cx = gui->x_origin, cy = gui->y_origin;
2055 if( mask_gui->focused ) {
2056 cx = atof(mask_gui->focus_x->get_text());
2057 cy = atof(mask_gui->focus_y->get_text());
2059 else if( !gui->ctrl_down() ) {
2061 int n = mask_points.size();
2062 for( int i=0; i<n; ++i ) {
2063 MaskPoint *point = mask_points.values[i];
2064 cx += point->x; cy += point->y;
2067 mask_gui->set_focused(0, cx, cy);
2072 gui->get_triple_click() ? 8. :
2073 gui->get_double_click() ? 4. :
2075 int button_no = get_buttonpress();
2076 double ds = accel/64., dt = accel*M_PI/360.;
2077 double scale = button_no == WHEEL_UP ? 1.+ds : 1.-ds;
2078 int mode = mask_gui->scale_mode;
2079 double xscale = !rotate && (mode == MASK_SCALE_X ||
2080 mode == MASK_SCALE_XY ) ? scale : 1.;
2081 double yscale = !rotate && (mode == MASK_SCALE_Y ||
2082 mode == MASK_SCALE_XY ) ? scale : 1.;
2083 double theta = button_no == WHEEL_UP ? dt : -dt;
2084 if( rotate ? theta==0 : scale==1 ) break;
2085 float st = sin(theta), ct = cos(theta);
2086 MaskAuto *keyframe = gui->mask_keyframe;
2087 int gang = mask_gui->gang_focus->get_value();
2088 int k = mwindow->edl->session->cwindow_mask;
2089 int n = gang ? keyframe->masks.size() : k+1;
2090 for( int j=gang? 0 : k; j<n; ++j ) {
2091 if( !mask_gui->mask_enables[j]->get_value() ) continue;
2092 SubMask *sub_mask = keyframe->get_submask(j);
2093 if( !sub_mask ) continue;
2094 MaskPoints &points = sub_mask->points;
2095 for( int i=0; i<points.size(); ++i ) {
2096 MaskPoint *point = points[i];
2097 float px = point->x - gui->x_origin;
2098 float py = point->y - gui->y_origin;
2099 float nx = !rotate ? px*xscale : px*ct + py*st;
2100 float ny = !rotate ? py*yscale : py*ct - px*st;
2101 point->x = nx + gui->x_origin;
2102 point->y = ny + gui->y_origin;
2103 px = point->control_x1; py = point->control_y1;
2104 point->control_x1 = !rotate ? px*xscale : px*ct + py*st;
2105 point->control_y1 = !rotate ? py*yscale : py*ct - px*st;
2106 px = point->control_x2; py = point->control_y2;
2107 point->control_x2 = !rotate ? px*xscale : px*ct + py*st;
2108 point->control_y2 = !rotate ? py*yscale : py*ct - px*st;
2117 if( !(rerender && redraw) && (!EQUIV(last_x, point->x) ||
2118 !EQUIV(last_y, point->y) ||
2119 !EQUIV(last_control_x1, point->control_x1) ||
2120 !EQUIV(last_control_y1, point->control_y1) ||
2121 !EQUIV(last_control_x2, point->control_x2) ||
2122 !EQUIV(last_control_y2, point->control_y2)) ) {
2128 if( gui->current_operation == CWINDOW_NONE ) {
2129 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
2131 for( int i = 0; i < points.size() && !over_point; i++ ) {
2132 MaskPoint *point = points.get(i);
2133 float x0 = point->x;
2134 float y0 = point->y;
2135 float x1 = point->x + point->control_x1;
2136 float y1 = point->y + point->control_y1;
2137 float x2 = point->x + point->control_x2;
2138 float y2 = point->y + point->control_y2;
2139 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
2140 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
2142 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
2143 if( test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0) ) {
2147 if( !over_point && gui->ctrl_down() ) {
2148 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
2149 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
2150 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2151 if( test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1) ) {
2155 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2156 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2157 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2158 if( test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2) ) {
2165 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2170 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2173 #ifdef USE_KEYFRAME_SPANNING
2174 // Must commit change after operation.
2175 if( rerender && track ) {
2176 // Swap EDL keyframe with original.
2177 // Apply new values to keyframe span
2178 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2179 temp_keyframe.copy_data(gui->mask_keyframe);
2180 // Apply interpolated points back to keyframe
2182 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2183 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2184 mask_autos->update_parameter(&temp_keyframe);
2187 //printf("CWindowCanvas::do_mask 20\n");
2189 if( draw && draw_boundary && !draw_markers ) {
2190 BC_WindowBase *cvs_win = get_canvas();
2191 cvs_win->set_inverse();
2192 cvs_win->set_color(RED+GREEN);
2193 for( int k=0; k<SUBMASKS; ++k ) {
2194 if( k == mwindow->edl->session->cwindow_mask ) continue;
2195 points.remove_all_objects();
2196 if( use_interpolated )
2197 mask_autos->get_points(&points, k, position, PLAY_FORWARD);
2199 prev_mask->get_points(&points, k);
2201 edge.load(points, 0);
2202 for( int i=0; i<edge.size(); ++i ) {
2203 MaskCoord a = edge[i];
2204 MaskCoord b = i<edge.size()-1 ? edge[i+1] : edge[0];
2205 float ax = a.x, ay = a.y;
2206 float bx = b.x, by = b.y;
2207 output_to_canvas(mwindow->edl, 0, ax, ay);
2208 output_to_canvas(mwindow->edl, 0, bx, by);
2209 cvs_win->draw_line(ax,ay, bx,by);
2217 int CWindowCanvas::do_mask_focus()
2219 Track *track = gui->cwindow->calculate_affected_track();
2220 int64_t position = track->to_units(
2221 mwindow->edl->local_session->get_selectionstart(1),
2223 float projector_x, projector_y, projector_z;
2224 track->automation->get_projector(
2225 &projector_x, &projector_y, &projector_z,
2226 position, PLAY_FORWARD);
2227 float cx = get_cursor_x(), cy = get_cursor_y();
2228 canvas_to_output(mwindow->edl, 0, cx, cy);
2229 projector_x += mwindow->edl->session->output_w / 2;
2230 projector_y += mwindow->edl->session->output_h / 2;
2231 float half_track_w = (float)track->track_w / 2;
2232 float half_track_h = (float)track->track_h / 2;
2233 cx = (cx - projector_x) / projector_z + half_track_w;
2234 cy = (cy - projector_y) / projector_z + half_track_h;
2235 CWindowMaskGUI *mask_gui = (CWindowMaskGUI*) gui->tool_panel->tool_gui;
2236 mask_gui->set_focused(1, cx, cy);
2240 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2243 int radius = mwindow->edl->session->eyedrop_radius;
2251 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
2254 row1 = gui->eyedrop_y - radius;
2255 row2 = gui->eyedrop_y + radius;
2256 column1 = gui->eyedrop_x - radius;
2257 column2 = gui->eyedrop_x + radius;
2259 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2260 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2261 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2262 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2264 if( row2 <= row1 ) row2 = row1 + 1;
2265 if( column2 <= column1 ) column2 = column1 + 1;
2272 output_to_canvas(mwindow->edl, 0, x1, y1);
2273 output_to_canvas(mwindow->edl, 0, x2, y2);
2274 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2276 if( x2 - x1 >= 1 && y2 - y1 >= 1 ) {
2277 get_canvas()->set_inverse();
2278 get_canvas()->set_color(WHITE);
2280 get_canvas()->draw_rectangle((int)x1,
2285 get_canvas()->set_opaque();
2286 get_canvas()->flash();
2292 if( button_press ) {
2293 gui->current_operation = CWINDOW_EYEDROP;
2294 gui->tool_panel->raise_window();
2297 if( gui->current_operation == CWINDOW_EYEDROP ) {
2298 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2300 // Get color out of frame.
2301 // Doesn't work during playback because that bypasses the refresh frame.
2302 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
2303 float cursor_x = get_cursor_x();
2304 float cursor_y = get_cursor_y();
2305 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2306 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2307 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2309 row1 = cursor_y - radius;
2310 row2 = cursor_y + radius;
2311 column1 = cursor_x - radius;
2312 column2 = cursor_x + radius;
2313 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2314 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2315 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2316 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2317 if( row2 <= row1 ) row2 = row1 + 1;
2318 if( column2 <= column1 ) column2 = column1 + 1;
2322 if( gui->eyedrop_visible ) {
2324 do_eyedrop(temp, 0, 1);
2325 gui->eyedrop_visible = 0;
2328 gui->eyedrop_x = cursor_x;
2329 gui->eyedrop_y = cursor_y;
2334 do_eyedrop(temp, 0, 1);
2335 gui->eyedrop_visible = 1;
2338 // Decompression coefficients straight out of jpeglib
2339 #define V_TO_R 1.40200
2340 #define V_TO_G -0.71414
2342 #define U_TO_G -0.34414
2343 #define U_TO_B 1.77200
2345 #define GET_COLOR(type, components, max, do_yuv) \
2347 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2349 float red = (float)*row++ / max; \
2350 float green = (float)*row++ / max; \
2351 float blue = (float)*row++ / max; \
2354 float r = red + V_TO_R * (blue - 0.5); \
2355 float g = red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
2356 float b = red + U_TO_B * (green - 0.5); \
2357 mwindow->edl->local_session->red += r; \
2358 mwindow->edl->local_session->green += g; \
2359 mwindow->edl->local_session->blue += b; \
2360 if( r > mwindow->edl->local_session->red_max ) mwindow->edl->local_session->red_max = r; \
2361 if( g > mwindow->edl->local_session->green_max ) mwindow->edl->local_session->green_max = g; \
2362 if( b > mwindow->edl->local_session->blue_max ) mwindow->edl->local_session->blue_max = b; \
2366 mwindow->edl->local_session->red += red; \
2367 mwindow->edl->local_session->green += green; \
2368 mwindow->edl->local_session->blue += blue; \
2369 if( red > mwindow->edl->local_session->red_max ) mwindow->edl->local_session->red_max = red; \
2370 if( green > mwindow->edl->local_session->green_max ) mwindow->edl->local_session->green_max = green; \
2371 if( blue > mwindow->edl->local_session->blue_max ) mwindow->edl->local_session->blue_max = blue; \
2377 mwindow->edl->local_session->red = 0;
2378 mwindow->edl->local_session->green = 0;
2379 mwindow->edl->local_session->blue = 0;
2380 mwindow->edl->local_session->red_max = 0;
2381 mwindow->edl->local_session->green_max = 0;
2382 mwindow->edl->local_session->blue_max = 0;
2383 for( int i = row1; i < row2; i++ ) {
2384 for( int j = column1; j < column2; j++ ) {
2385 switch( refresh_frame->get_color_model() )
2388 GET_COLOR(unsigned char, 3, 0xff, 1);
2391 GET_COLOR(unsigned char, 4, 0xff, 1);
2394 GET_COLOR(uint16_t, 3, 0xffff, 1);
2396 case BC_YUVA16161616:
2397 GET_COLOR(uint16_t, 4, 0xffff, 1);
2400 GET_COLOR(unsigned char, 3, 0xff, 0);
2403 GET_COLOR(unsigned char, 4, 0xff, 0);
2406 GET_COLOR(float, 3, 1.0, 0);
2409 GET_COLOR(float, 4, 1.0, 0);
2415 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2416 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2417 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2421 mwindow->edl->local_session->red = 0;
2422 mwindow->edl->local_session->green = 0;
2423 mwindow->edl->local_session->blue = 0;
2424 gui->eyedrop_visible = 0;
2433 // Can't rerender since the color value is from the output of any effect it
2436 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2442 int CWindowCanvas::need_overlays()
2444 if( mwindow->edl->session->safe_regions ) return 1;
2445 if( mwindow->edl->session->cwindow_scrollbars ) return 1;
2446 if( gui->highlighted ) return 1;
2447 switch( mwindow->edl->session->cwindow_operation ) {
2448 case CWINDOW_EYEDROP:
2449 if( ! gui->eyedrop_visible ) break;
2450 case CWINDOW_CAMERA:
2451 case CWINDOW_PROJECTOR:
2460 void CWindowCanvas::draw_overlays()
2462 if( mwindow->edl->session->safe_regions ) {
2463 draw_safe_regions();
2466 if( mwindow->edl->session->cwindow_scrollbars ) {
2467 // Always draw output rectangle
2468 float x1, y1, x2, y2;
2470 x2 = mwindow->edl->session->output_w;
2472 y2 = mwindow->edl->session->output_h;
2473 output_to_canvas(mwindow->edl, 0, x1, y1);
2474 output_to_canvas(mwindow->edl, 0, x2, y2);
2476 get_canvas()->set_inverse();
2477 get_canvas()->set_color(WHITE);
2478 int ix1 = x1-1, iy1 = y1-1, ix2 = x2+1, iy2 = y2+1;
2479 get_canvas()->draw_rectangle(ix1, iy1, ix2-ix1, iy2-iy1);
2480 get_canvas()->set_opaque();
2483 if( gui->highlighted ) {
2484 get_canvas()->set_color(WHITE);
2485 get_canvas()->set_inverse();
2486 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2487 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2488 get_canvas()->set_opaque();
2491 int temp1 = 0, temp2 = 0;
2492 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2493 switch( mwindow->edl->session->cwindow_operation )
2495 case CWINDOW_CAMERA:
2499 case CWINDOW_PROJECTOR:
2508 do_mask(temp1, temp2, 0, 0, 1);
2512 do_ruler(1, 0, 0, 0);
2515 case CWINDOW_EYEDROP:
2516 if( gui->eyedrop_visible ) {
2518 do_eyedrop(rerender, 0, 1);
2519 gui->eyedrop_visible = 1;
2525 void CWindowCanvas::draw_safe_regions()
2527 float action_x1, action_x2, action_y1, action_y2;
2528 float title_x1, title_x2, title_y1, title_y2;
2530 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2531 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2532 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2533 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2534 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2535 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2536 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2537 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2539 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2540 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2541 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2542 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2544 get_canvas()->set_inverse();
2545 get_canvas()->set_color(WHITE);
2547 get_canvas()->draw_rectangle((int)action_x1,
2549 (int)(action_x2 - action_x1),
2550 (int)(action_y2 - action_y1));
2551 get_canvas()->draw_rectangle((int)title_x1,
2553 (int)(title_x2 - title_x1),
2554 (int)(title_y2 - title_y1));
2556 get_canvas()->set_opaque();
2560 void CWindowCanvas::create_keyframe(int do_camera)
2562 Track *affected_track = gui->cwindow->calculate_affected_track();
2563 if( affected_track ) {
2564 double pos = mwindow->edl->local_session->get_selectionstart(1);
2565 int64_t position = affected_track->to_units(pos, 0);
2566 int ix = do_camera ? AUTOMATION_CAMERA_X : AUTOMATION_PROJECTOR_X;
2567 int iy = do_camera ? AUTOMATION_CAMERA_Y : AUTOMATION_PROJECTOR_Y;
2568 int iz = do_camera ? AUTOMATION_CAMERA_Z : AUTOMATION_PROJECTOR_Z;
2569 FloatAuto *prev, *next;
2570 FloatAutos **autos = (FloatAutos**)affected_track->automation->autos;
2571 FloatAutos *x_autos = autos[ix]; prev = 0; next = 0;
2572 float x_value = x_autos->get_value(position, PLAY_FORWARD, prev, next);
2573 FloatAutos *y_autos = autos[iy]; prev = 0; next = 0;
2574 float y_value = y_autos->get_value(position, PLAY_FORWARD, prev, next);
2575 FloatAutos *z_autos = autos[iz]; prev = 0; next = 0;
2576 float z_value = z_autos->get_value(position, PLAY_FORWARD, prev, next);
2577 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2579 gui->cwindow->calculate_affected_autos(affected_track,
2580 &x_keyframe, &y_keyframe, &z_keyframe,
2581 do_camera, -1, -1, -1, 0);
2582 x_keyframe->set_value(x_value);
2583 y_keyframe->set_value(y_value);
2584 z_keyframe->set_value(z_value);
2586 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2590 void CWindowCanvas::camera_keyframe() { create_keyframe(1); }
2591 void CWindowCanvas::projector_keyframe() { create_keyframe(0); }
2593 void CWindowCanvas::reset_keyframe(int do_camera)
2595 Track *affected_track = gui->cwindow->calculate_affected_track();
2596 if( affected_track ) {
2597 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2598 gui->cwindow->calculate_affected_autos(affected_track,
2599 &x_keyframe, &y_keyframe, &z_keyframe,
2600 do_camera, 1, 1, 1);
2602 x_keyframe->set_value(0);
2603 y_keyframe->set_value(0);
2604 z_keyframe->set_value(1);
2606 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2610 void CWindowCanvas::reset_camera() { reset_keyframe(1); }
2611 void CWindowCanvas::reset_projector() { reset_keyframe(0); }
2614 int CWindowCanvas::test_crop(int button_press, int &redraw)
2617 int handle_selected = -1;
2618 float x1 = mwindow->edl->session->crop_x1;
2619 float y1 = mwindow->edl->session->crop_y1;
2620 float x2 = mwindow->edl->session->crop_x2;
2621 float y2 = mwindow->edl->session->crop_y2;
2622 float cursor_x = get_cursor_x();
2623 float cursor_y = get_cursor_y();
2624 float canvas_x1 = x1;
2625 float canvas_y1 = y1;
2626 float canvas_x2 = x2;
2627 float canvas_y2 = y2;
2628 float canvas_cursor_x = cursor_x;
2629 float canvas_cursor_y = cursor_y;
2631 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2632 // Use screen normalized coordinates for hot spot tests.
2633 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2634 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2637 if( gui->current_operation == CWINDOW_CROP ) {
2638 handle_selected = gui->crop_handle;
2641 if( canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2642 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H ) {
2643 handle_selected = 0;
2644 gui->crop_origin_x = x1;
2645 gui->crop_origin_y = y1;
2648 if( canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2649 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H ) {
2650 handle_selected = 1;
2651 gui->crop_origin_x = x2;
2652 gui->crop_origin_y = y1;
2655 if( canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2656 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2 ) {
2657 handle_selected = 2;
2658 gui->crop_origin_x = x1;
2659 gui->crop_origin_y = y2;
2662 if( canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2663 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2 ) {
2664 handle_selected = 3;
2665 gui->crop_origin_x = x2;
2666 gui->crop_origin_y = y2;
2671 gui->crop_origin_x = cursor_x;
2672 gui->crop_origin_y = cursor_y;
2675 // printf("test crop %d %d\n",
2676 // gui->current_operation,
2677 // handle_selected);
2680 if( button_press ) {
2681 if( gui->alt_down() ) {
2682 gui->crop_translate = 1;
2683 gui->crop_origin_x1 = x1;
2684 gui->crop_origin_y1 = y1;
2685 gui->crop_origin_x2 = x2;
2686 gui->crop_origin_y2 = y2;
2689 gui->crop_translate = 0;
2691 gui->current_operation = CWINDOW_CROP;
2692 gui->crop_handle = handle_selected;
2693 gui->x_origin = cursor_x;
2694 gui->y_origin = cursor_y;
2695 gui->tool_panel->raise_window();
2698 if( handle_selected < 0 && !gui->crop_translate ) {
2701 mwindow->edl->session->crop_x1 = (int)x1;
2702 mwindow->edl->session->crop_y1 = (int)y1;
2703 mwindow->edl->session->crop_x2 = (int)x2;
2704 mwindow->edl->session->crop_y2 = (int)y2;
2709 // Translate all 4 points
2710 if( gui->current_operation == CWINDOW_CROP && gui->crop_translate ) {
2711 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2712 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2713 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2714 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2716 mwindow->edl->session->crop_x1 = (int)x1;
2717 mwindow->edl->session->crop_y1 = (int)y1;
2718 mwindow->edl->session->crop_x2 = (int)x2;
2719 mwindow->edl->session->crop_y2 = (int)y2;
2725 if( gui->current_operation == CWINDOW_CROP ) {
2726 switch( gui->crop_handle ) {
2728 x1 = gui->crop_origin_x;
2729 y1 = gui->crop_origin_y;
2730 x2 = gui->crop_origin_x;
2731 y2 = gui->crop_origin_y;
2732 if( cursor_x < gui->x_origin ) {
2733 if( cursor_y < gui->y_origin ) {
2738 if( cursor_y >= gui->y_origin ) {
2744 if( cursor_x >= gui->x_origin ) {
2745 if( cursor_y < gui->y_origin ) {
2750 if( cursor_y >= gui->y_origin ) {
2756 // printf("test crop %d %d %d %d\n",
2757 // mwindow->edl->session->crop_x1,
2758 // mwindow->edl->session->crop_y1,
2759 // mwindow->edl->session->crop_x2,
2760 // mwindow->edl->session->crop_y2);
2763 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2764 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2767 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2768 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2771 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2772 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2775 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2776 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2780 if( !EQUIV(mwindow->edl->session->crop_x1, x1) ||
2781 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2782 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2783 !EQUIV(mwindow->edl->session->crop_y2, y2) ) {
2788 switch( gui->crop_handle ) {
2789 case 0: gui->crop_handle = 1; break;
2790 case 1: gui->crop_handle = 0; break;
2791 case 2: gui->crop_handle = 3; break;
2792 case 3: gui->crop_handle = 2; break;
2801 switch( gui->crop_handle ) {
2802 case 0: gui->crop_handle = 2; break;
2803 case 1: gui->crop_handle = 3; break;
2804 case 2: gui->crop_handle = 0; break;
2805 case 3: gui->crop_handle = 1; break;
2810 mwindow->edl->session->crop_x1 = (int)x1;
2811 mwindow->edl->session->crop_y1 = (int)y1;
2812 mwindow->edl->session->crop_x2 = (int)x2;
2813 mwindow->edl->session->crop_y2 = (int)y2;
2819 // Update cursor font
2820 if( handle_selected >= 0 ) {
2821 switch( handle_selected ) {
2822 case 0: set_cursor(UPLEFT_RESIZE); break;
2823 case 1: set_cursor(UPRIGHT_RESIZE); break;
2824 case 2: set_cursor(DOWNLEFT_RESIZE); break;
2825 case 3: set_cursor(DOWNRIGHT_RESIZE); break;
2830 set_cursor(ARROW_CURSOR);
2832 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2835 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2836 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2837 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2838 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2839 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2840 // mwindow->edl->session->crop_x2,
2841 // mwindow->edl->session->crop_y2,
2842 // mwindow->edl->calculate_output_w(0),
2843 // mwindow->edl->calculate_output_h(0));
2849 void CWindowCanvas::draw_crop()
2851 get_canvas()->set_inverse();
2852 get_canvas()->set_color(WHITE);
2854 float x1 = mwindow->edl->session->crop_x1;
2855 float y1 = mwindow->edl->session->crop_y1;
2856 float x2 = mwindow->edl->session->crop_x2;
2857 float y2 = mwindow->edl->session->crop_y2;
2859 output_to_canvas(mwindow->edl, 0, x1, y1);
2860 output_to_canvas(mwindow->edl, 0, x2, y2);
2862 if( x2 - x1 && y2 - y1 )
2863 get_canvas()->draw_rectangle((int)x1,
2868 draw_crophandle((int)x1, (int)y1);
2869 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2870 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2871 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2872 get_canvas()->set_opaque();
2876 void CWindowCanvas::draw_outlines(int do_camera)
2878 Track *track = gui->cwindow->calculate_affected_track();
2880 if( !track ) return;
2882 float proj_x, proj_y, proj_z;
2883 int64_t position = track->to_units(
2884 mwindow->edl->local_session->get_selectionstart(1),
2886 track->automation->get_projector(&proj_x, &proj_y, &proj_z,
2887 position, PLAY_FORWARD);
2889 proj_x += mwindow->edl->session->output_w/2.;
2890 proj_y += mwindow->edl->session->output_h/2.;
2891 float proj_x1 = proj_x - track->track_w/2. * proj_z;
2892 float proj_y1 = proj_y - track->track_h/2. * proj_z;
2893 float proj_x2 = proj_x + track->track_w/2. * proj_z;
2894 float proj_y2 = proj_y + track->track_h/2. * proj_z;
2895 float x1 = proj_x1, x2 = proj_x2;
2896 float y1 = proj_y1, y2 = proj_y2;
2897 output_to_canvas(mwindow->edl, 0, x1, y1);
2898 output_to_canvas(mwindow->edl, 0, x2, y2);
2900 #define DRAW_PROJECTION(offset) \
2901 get_canvas()->draw_rectangle(x1+offset, y1+offset, (x2-x1), (y2-y1)); \
2902 get_canvas()->draw_line(x1+offset, y1+offset, x2+offset, y2+offset); \
2903 get_canvas()->draw_line(x2+offset, y1+offset, x1+offset, y2+offset); \
2906 get_canvas()->set_color(BLACK);
2908 get_canvas()->set_color(do_camera ? GREEN : RED);
2912 float cam_x, cam_y, cam_z;
2913 track->automation->get_camera(&cam_x, &cam_y, &cam_z,
2914 position, PLAY_FORWARD);
2915 cam_x += track->track_w / 2.;
2916 cam_y += track->track_h / 2.;
2917 // follow image, not camera
2918 cam_x = -cam_x; cam_y = -cam_y; cam_z *= proj_z;
2919 float cam_x1 = cam_x * cam_z + proj_x;
2920 float cam_y1 = cam_y * cam_z + proj_y;
2921 float cam_x2 = (cam_x + track->track_w) * cam_z + proj_x;
2922 float cam_y2 = (cam_y + track->track_h) * cam_z + proj_y;
2923 output_to_canvas(mwindow->edl, 0, cam_x1, cam_y1);
2924 output_to_canvas(mwindow->edl, 0, cam_x2, cam_y2);
2925 get_canvas()->set_color(YELLOW);
2926 get_canvas()->draw_rectangle(cam_x1, cam_y1, cam_x2-cam_x1, cam_y2-cam_y1);
2930 int CWindowCanvas::test_bezier(int button_press,
2938 // Processing drag operation.
2939 // Create keyframe during first cursor motion.
2940 if( !button_press ) {
2942 float cursor_x = get_cursor_x();
2943 float cursor_y = get_cursor_y();
2944 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2946 if( gui->current_operation == CWINDOW_CAMERA ||
2947 gui->current_operation == CWINDOW_PROJECTOR ) {
2948 if( !gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom ) {
2949 gui->translating_zoom = 1;
2950 gui->reset_affected();
2952 else if( !gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom ) {
2953 gui->translating_zoom = 0;
2954 gui->reset_affected();
2957 // Get target keyframe
2958 if( !gui->affected_x && !gui->affected_y && !gui->affected_z ) {
2959 if( !gui->affected_track ) return 0;
2960 FloatAutos *affected_x_autos, *affected_y_autos, *affected_z_autos;
2961 FloatAutos** autos = (FloatAutos**) gui->affected_track->automation->autos;
2962 if( mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA ) {
2963 affected_x_autos = autos[AUTOMATION_CAMERA_X];
2964 affected_y_autos = autos[AUTOMATION_CAMERA_Y];
2965 affected_z_autos = autos[AUTOMATION_CAMERA_Z];
2968 affected_x_autos = autos[AUTOMATION_PROJECTOR_X];
2969 affected_y_autos = autos[AUTOMATION_PROJECTOR_Y];
2970 affected_z_autos = autos[AUTOMATION_PROJECTOR_Z];
2972 double position = mwindow->edl->local_session->get_selectionstart(1);
2973 int64_t track_position = gui->affected_track->to_units(position, 0);
2974 FloatAuto *prev_x = 0, *next_x = 0;
2975 float new_x = affected_x_autos->get_value(track_position, PLAY_FORWARD, prev_x, next_x);
2976 FloatAuto *prev_y = 0, *next_y = 0;
2977 float new_y = affected_y_autos->get_value(track_position, PLAY_FORWARD, prev_y, next_y);
2978 FloatAuto *prev_z = 0, *next_z = 0;
2979 float new_z = affected_z_autos->get_value(track_position, PLAY_FORWARD, prev_z, next_z);
2980 int zooming = gui->translating_zoom, created;
2981 gui->affected_x = (FloatAuto*)gui->cwindow->calculate_affected_auto(
2982 affected_x_autos, !zooming, &created, 0);
2984 gui->affected_x->set_value(new_x);
2987 gui->affected_y = (FloatAuto*)gui->cwindow->calculate_affected_auto(
2988 affected_y_autos, !zooming, &created, 0);
2990 gui->affected_y->set_value(new_y);
2993 gui->affected_z = (FloatAuto*)gui->cwindow->calculate_affected_auto(
2994 affected_z_autos, zooming, &created, 0);
2996 gui->affected_z->set_value(new_z);
3001 if( gui->translating_zoom ) {
3002 gui->center_z = gui->affected_z->get_value();
3005 gui->center_x = gui->affected_x->get_value();
3006 gui->center_y = gui->affected_y->get_value();
3013 float x_val = gui->affected_x->get_value();
3014 float y_val = gui->affected_y->get_value();
3015 float z_val = gui->affected_z->get_value();
3017 if( gui->translating_zoom ) {
3018 float z = gui->center_z + (cursor_y - gui->y_origin) / yS(128);
3020 if( !EQUIV(z_val, z) ) {
3025 gui->affected_z->set_value(z);
3028 float dx = cursor_x - gui->x_origin;
3029 float dy = cursor_y - gui->y_origin;
3030 // follow image, not camera
3031 if( gui->current_operation == CWINDOW_CAMERA ) {
3032 dx = -dx / z_val; dy = -dy / z_val;
3034 float x = gui->center_x + dx;
3035 float y = gui->center_y + dy;
3036 gui->affected_x->set_value(x);
3037 gui->affected_y->set_value(y);
3038 if( !EQUIV(x_val, x) || !EQUIV(y_val, y) ) {
3049 // Begin drag operation. Don't create keyframe here.
3051 // Get affected track off of the first recordable video track.
3052 // Calculating based on the alpha channel would require recording what layer
3053 // each output pixel belongs to as they're rendered and stacked. Forget it.
3054 gui->affected_track = gui->cwindow->calculate_affected_track();
3055 gui->reset_affected();
3057 if( gui->affected_track ) {
3059 mwindow->undo->update_undo_before(_("camera"), this);
3061 mwindow->undo->update_undo_before(_("projector"), this);
3063 gui->current_operation =
3064 mwindow->edl->session->cwindow_operation;
3065 gui->tool_panel->raise_window();
3073 int CWindowCanvas::test_zoom(int &redraw)
3076 int button = get_buttonpress();
3077 if( button == LEFT_BUTTON )
3078 button = gui->shift_down() ? WHEEL_DOWN : WHEEL_UP;
3079 if( !(zoom = get_zoom()) )
3080 zoom = get_auto_zoom(mwindow->edl);
3084 for( ; idx < total_zooms; ++idx ) {
3085 if( EQUIV(zoom, my_zoom_table[idx]) ) continue;
3086 if( zoom < my_zoom_table[idx] ) break;
3088 float zoom11 = 1.1f * zoom;
3089 zoom = idx < total_zooms ? my_zoom_table[idx] : zoom11;
3090 if( zoom > zoom11 ) zoom = zoom11;
3093 int idx = total_zooms;
3094 for( ; --idx >= 0; ) {
3095 if( EQUIV(my_zoom_table[idx], zoom) ) continue;
3096 if( my_zoom_table[idx] < zoom ) break;
3098 float zoom09 = 0.9f * zoom;
3099 zoom = idx >= 0 ? my_zoom_table[idx] : zoom09;
3100 if( zoom < zoom09 ) zoom = zoom09;
3103 if( gui->shift_down() ) {
3107 default: // fall thru
3110 float cx = get_cursor_x(), cy = get_cursor_y();
3111 set_zoom(mwindow->edl, zoom, cx, cy);
3112 gui->zoom_panel->update(zoom);
3113 gui->update_canvas();
3119 void CWindowCanvas::calculate_origin()
3121 float zoom_x, zoom_y, conformed_w, conformed_h;
3122 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3123 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3124 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3125 gui->x_origin = (float)get_cursor_x() / zoom_x + gui->x_offset;
3126 gui->y_origin = (float)get_cursor_y() / zoom_y + gui->y_offset;
3130 int CWindowCanvas::cursor_leave_event()
3132 set_cursor(ARROW_CURSOR);
3136 int CWindowCanvas::cursor_enter_event()
3139 switch( mwindow->edl->session->cwindow_operation ) {
3140 case CWINDOW_CAMERA:
3141 case CWINDOW_PROJECTOR:
3142 set_cursor(MOVE_CURSOR);
3145 set_cursor(MOVE_CURSOR);
3148 test_crop(0, redraw);
3150 case CWINDOW_PROTECT:
3151 set_cursor(ARROW_CURSOR);
3155 set_cursor(CROSS_CURSOR);
3157 case CWINDOW_EYEDROP:
3158 set_cursor(CROSS_CURSOR);
3164 int CWindowCanvas::cursor_motion_event()
3166 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3169 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3170 switch( gui->current_operation ) {
3171 case CWINDOW_SCROLL: {
3172 result = do_scroll(mwindow->edl, get_cursor_x(), get_cursor_y());
3176 result = do_ruler(0, 1, 0, 0);
3179 case CWINDOW_CAMERA:
3180 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3183 case CWINDOW_PROJECTOR:
3184 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3188 result = test_crop(0, redraw);
3189 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3190 // __LINE__, result, redraw);
3194 case CWINDOW_MASK_CONTROL_IN:
3195 case CWINDOW_MASK_CONTROL_OUT:
3196 case CWINDOW_MASK_TRANSLATE:
3197 result = do_mask(redraw, rerender, 0, 1, 0);
3200 case CWINDOW_EYEDROP:
3201 result = do_eyedrop(rerender, 0, 0);
3209 // cursor font changes
3211 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3212 // __LINE__, mwindow->edl->session->cwindow_operation);
3213 switch( mwindow->edl->session->cwindow_operation ) {
3215 result = test_crop(0, redraw);
3218 result = do_ruler(0, 1, 0, 0);
3221 result = do_mask(redraw, rerender, 0, 1, 0);
3226 int change_type = rerender ? CHANGE_PARAMS : -1;
3227 gui->sync_parameters(change_type, redraw, redraw_canvas);
3232 int CWindowCanvas::button_press_event()
3236 int redraw_canvas = 0;
3239 if( Canvas::button_press_event() ) return 1;
3241 gui->translating_zoom = gui->shift_down();
3245 if( mwindow->edl->session->cwindow_operation != CWINDOW_PROTECT &&
3246 get_buttonpress() == MIDDLE_BUTTON && !get_canvas()->shift_down() ) {
3247 gui->current_operation = CWINDOW_SCROLL;
3252 switch( mwindow->edl->session->cwindow_operation ) {
3254 result = do_ruler(0, 0, 1, 0);
3257 case CWINDOW_CAMERA:
3258 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3261 case CWINDOW_PROJECTOR:
3262 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3266 result = test_zoom(redraw);
3270 result = test_crop(1, redraw);
3274 switch( get_buttonpress() ) {
3276 result = do_mask(redraw, rerender, 1, 0, 0);
3278 case MIDDLE_BUTTON: { // && shift_down()
3279 result = do_mask_focus();
3280 redraw = redraw_canvas = 1;
3284 result = do_mask(redraw, rerender, 1, 1, 0);
3287 if( result ) redraw_canvas = 1;
3290 case CWINDOW_EYEDROP:
3291 result = do_eyedrop(rerender, 1, 0);
3296 int change_type = rerender ? CHANGE_PARAMS : -1;
3297 gui->sync_parameters(change_type, redraw, redraw_canvas);
3302 int CWindowCanvas::button_release_event()
3305 const char *undo_label = 0;
3307 switch( gui->current_operation ) {
3308 case CWINDOW_SCROLL:
3313 do_ruler(0, 0, 0, 1);
3316 case CWINDOW_CAMERA:
3317 undo_label = _("camera");
3320 case CWINDOW_PROJECTOR:
3321 undo_label = _("projector");
3325 case CWINDOW_MASK_CONTROL_IN:
3326 case CWINDOW_MASK_CONTROL_OUT:
3327 case CWINDOW_MASK_TRANSLATE:
3328 // Finish mask operation
3329 gui->mask_keyframe = 0;
3330 undo_label = _("mask");
3332 case CWINDOW_MASK_ROTATE:
3333 gui->mask_keyframe = 0;
3334 undo_label = _("mask rotate");
3336 case CWINDOW_MASK_SCALE:
3337 gui->mask_keyframe = 0;
3338 undo_label = _("mask scale");
3341 result = Canvas::button_release_event();
3346 mwindow->undo->update_undo_after(undo_label, LOAD_AUTOMATION);
3347 gui->current_operation = CWINDOW_NONE;
3351 void CWindowCanvas::zoom_resize_window(float percentage)
3353 int canvas_w, canvas_h;
3356 // Get required canvas size
3357 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3358 mwindow->edl->session->output_w,
3359 mwindow->edl->session->output_h,
3360 percentage, canvas_w, canvas_h);
3362 // Estimate window size from current borders
3363 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3364 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3366 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3367 mwindow->session->cwindow_w = new_w;
3368 mwindow->session->cwindow_h = new_h;
3370 mwindow->theme->get_cwindow_sizes(gui,
3371 mwindow->session->cwindow_controls);
3373 // Estimate again from new borders
3374 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3375 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3376 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3378 gui->resize_window(new_w, new_h);
3379 gui->resize_event(new_w, new_h);
3382 void CWindowCanvas::toggle_controls()
3384 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3385 gui->resize_event(gui->get_w(), gui->get_h());
3388 int CWindowCanvas::get_cwindow_controls()
3390 return mwindow->session->cwindow_controls;
3393 int CWindowCanvas::get_clear_color()
3395 int color = mwindow->edl->session->cwindow_clear_color;
3396 if( color < 0 ) color = Canvas::get_clear_color();