4 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "automation.h"
24 #include "bcsignals.h"
28 #include "cplayback.h"
31 #include "cwindowgui.h"
33 #include "cwindowtool.h"
34 #include "editpanel.h"
36 #include "edlsession.h"
37 #include "floatauto.h"
38 #include "floatautos.h"
41 #include "localsession.h"
42 #include "mainclock.h"
45 #include "mainsession.h"
47 #include "maskautos.h"
49 #include "meterpanel.h"
50 #include "mwindowgui.h"
53 #include "playback3d.h"
54 #include "playtransport.h"
56 #include "trackcanvas.h"
58 #include "transportque.h"
62 static double my_zoom_table[] =
75 static int total_zooms = sizeof(my_zoom_table) / sizeof(double);
78 CWindowGUI::CWindowGUI(MWindow *mwindow, CWindow *cwindow)
79 : BC_Window(_(PROGRAM_NAME ": Compositor"),
80 mwindow->session->cwindow_x,
81 mwindow->session->cwindow_y,
82 mwindow->session->cwindow_w,
83 mwindow->session->cwindow_h,
84 xS(100), yS(100), 1, 1, 1,
85 BC_WindowBase::get_resources()->bg_color,
86 mwindow->get_cwindow_display())
88 this->mwindow = mwindow;
89 this->cwindow = cwindow;
91 affected_x = affected_y = affected_z = 0;
93 orig_mask_keyframe = new MaskAuto(0, 0);
95 x_offset = y_offset = 0;
96 x_origin = y_origin = 0;
97 current_operation = CWINDOW_NONE;
101 crop_handle = -1; crop_translate = 0;
102 crop_origin_x = crop_origin_y = 0;
103 crop_origin_x1 = crop_origin_y1 = 0;
104 crop_origin_x2 = crop_origin_y2 = 0;
106 eyedrop_x = eyedrop_y = 0;
107 ruler_origin_x = ruler_origin_y = 0;
108 ruler_handle = -1; ruler_translate = 0;
109 center_x = center_y = center_z = 0;
110 control_in_x = control_in_y = 0;
111 control_out_x = control_out_y = 0;
112 translating_zoom = 0;
116 CWindowGUI::~CWindowGUI()
118 cwindow->stop_playback(1);
119 if( tool_panel ) delete tool_panel;
121 delete composite_panel;
129 delete orig_mask_keyframe;
132 void CWindowGUI::create_objects()
134 lock_window("CWindowGUI::create_objects");
135 set_icon(mwindow->theme->get_image("cwindow_icon"));
137 active = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_active"));
138 inactive = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_inactive"));
139 focus_frame = new VFramePng(mwindow->theme->get_image_data("cwindow_focus.png"));
141 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
142 mwindow->theme->draw_cwindow_bg(this);
145 // Meters required by composite panel
146 meters = new CWindowMeters(mwindow,
148 mwindow->theme->cmeter_x,
149 mwindow->theme->cmeter_y,
150 mwindow->theme->cmeter_h);
151 meters->create_objects();
154 composite_panel = new CPanel(mwindow,
156 mwindow->theme->ccomposite_x,
157 mwindow->theme->ccomposite_y,
158 mwindow->theme->ccomposite_w,
159 mwindow->theme->ccomposite_h);
160 composite_panel->create_objects();
162 canvas = new CWindowCanvas(mwindow, this);
164 canvas->create_objects(mwindow->edl);
165 canvas->use_cwindow();
168 add_subwindow(timebar = new CTimeBar(mwindow,
170 mwindow->theme->ctimebar_x,
171 mwindow->theme->ctimebar_y,
172 mwindow->theme->ctimebar_w,
173 mwindow->theme->ctimebar_h));
174 timebar->create_objects();
177 add_subwindow(slider = new CWindowSlider(mwindow,
179 mwindow->theme->cslider_x,
180 mwindow->theme->cslider_y,
181 mwindow->theme->cslider_w));
184 transport = new CWindowTransport(mwindow,
186 mwindow->theme->ctransport_x,
187 mwindow->theme->ctransport_y);
188 transport->create_objects();
190 transport->set_slider(slider);
193 edit_panel = new CWindowEditing(mwindow, cwindow);
194 edit_panel->set_meters(meters);
195 edit_panel->create_objects();
197 // add_subwindow(clock = new MainClock(mwindow,
198 // mwindow->theme->ctime_x,
199 // mwindow->theme->ctime_y));
201 zoom_panel = new CWindowZoom(mwindow,
203 mwindow->theme->czoom_x,
204 mwindow->theme->czoom_y,
205 mwindow->theme->czoom_w);
206 zoom_panel->create_objects();
207 zoom_panel->zoom_text->add_item(new BC_MenuItem(auto_zoom = _(AUTO_ZOOM)));
208 if( !mwindow->edl->session->cwindow_scrollbars )
209 zoom_panel->set_text(auto_zoom);
211 // Must create after meter panel
212 tool_panel = new CWindowTool(mwindow, this);
213 tool_panel->Thread::start();
215 set_operation(mwindow->edl->session->cwindow_operation);
220 int CWindowGUI::translation_event()
222 mwindow->session->cwindow_x = get_x();
223 mwindow->session->cwindow_y = get_y();
227 int CWindowGUI::resize_event(int w, int h)
229 mwindow->session->cwindow_x = get_x();
230 mwindow->session->cwindow_y = get_y();
231 mwindow->session->cwindow_w = w;
232 mwindow->session->cwindow_h = h;
234 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
235 mwindow->theme->draw_cwindow_bg(this);
238 composite_panel->reposition_buttons(mwindow->theme->ccomposite_x,
239 mwindow->theme->ccomposite_y, mwindow->theme->ccomposite_h);
241 canvas->set_zoom(mwindow->edl, canvas->get_zoom());
244 timebar->resize_event();
247 slider->reposition_window(mwindow->theme->cslider_x,
248 mwindow->theme->cslider_y,
249 mwindow->theme->cslider_w);
250 // Recalibrate pointer motion range
251 slider->set_position();
254 transport->reposition_buttons(mwindow->theme->ctransport_x,
255 mwindow->theme->ctransport_y);
257 edit_panel->reposition_buttons(mwindow->theme->cedit_x,
258 mwindow->theme->cedit_y);
260 // clock->reposition_window(mwindow->theme->ctime_x,
261 // mwindow->theme->ctime_y);
263 zoom_panel->reposition_window(mwindow->theme->czoom_x,
264 mwindow->theme->czoom_y);
266 // destination->reposition_window(mwindow->theme->cdest_x,
267 // mwindow->theme->cdest_y);
269 meters->reposition_window(mwindow->theme->cmeter_x,
270 mwindow->theme->cmeter_y,
272 mwindow->theme->cmeter_h);
276 BC_WindowBase::resize_event(w, h);
280 int CWindowGUI::button_press_event()
282 if( current_operation == CWINDOW_NONE &&
283 mwindow->edl != 0 && canvas->get_canvas() &&
284 mwindow->edl->session->cwindow_click2play &&
285 canvas->get_canvas()->get_cursor_over_window() ) {
286 switch( get_buttonpress() ) {
288 if( !cwindow->playback_engine->is_playing_back ) {
289 double length = mwindow->edl->tracks->total_playable_length();
290 double position = cwindow->playback_engine->get_tracking_position();
291 if( position >= length ) transport->goto_start();
293 return transport->forward_play->handle_event();
295 if( !cwindow->playback_engine->is_playing_back ) {
296 double position = cwindow->playback_engine->get_tracking_position();
297 if( position <= 0 ) transport->goto_end();
299 return transport->reverse_play->handle_event();
300 case RIGHT_BUTTON: // activates popup
303 return transport->frame_forward_play->handle_event();
305 return transport->frame_reverse_play->handle_event();
308 if( canvas->get_canvas() )
309 return canvas->button_press_event_base(canvas->get_canvas());
313 int CWindowGUI::cursor_leave_event()
315 if( canvas->get_canvas() )
316 return canvas->cursor_leave_event_base(canvas->get_canvas());
320 int CWindowGUI::cursor_enter_event()
322 if( canvas->get_canvas() )
323 return canvas->cursor_enter_event_base(canvas->get_canvas());
327 int CWindowGUI::button_release_event()
329 if( canvas->get_canvas() )
330 return canvas->button_release_event();
334 int CWindowGUI::cursor_motion_event()
336 if( canvas->get_canvas() ) {
337 canvas->get_canvas()->unhide_cursor();
338 return canvas->cursor_motion_event();
349 void CWindowGUI::draw_status(int flush)
351 if( (canvas->get_canvas() && canvas->get_canvas()->get_video_on()) ||
352 canvas->is_processing ) {
354 mwindow->theme->cstatus_x,
355 mwindow->theme->cstatus_y);
358 draw_pixmap(inactive,
359 mwindow->theme->cstatus_x,
360 mwindow->theme->cstatus_y);
364 // printf("CWindowGUI::draw_status %d %d %d\n", __LINE__, mwindow->theme->cstatus_x,
365 // mwindow->theme->cstatus_y);
366 flash(mwindow->theme->cstatus_x,
367 mwindow->theme->cstatus_y,
373 void CWindowGUI::update_canvas(int redraw)
375 float zoom = canvas->get_zoom();
376 zoom_panel->update(zoom);
377 if( mwindow->edl->session->cwindow_operation == CWINDOW_ZOOM ) {
378 if( !zoom ) zoom = canvas->get_auto_zoom(mwindow->edl);
379 composite_panel->cpanel_zoom->update(zoom);
381 canvas->update_scrollbars(mwindow->edl, 0);
382 canvas->reposition_window(mwindow->edl,
383 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
384 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
389 void CWindowGUI::set_operation(int value)
392 case CWINDOW_TOOL_WINDOW:
393 mwindow->edl->session->tool_window = !mwindow->edl->session->tool_window;
394 composite_panel->operation[CWINDOW_TOOL_WINDOW]->update(mwindow->edl->session->tool_window);
395 tool_panel->update_show_window();
397 case CWINDOW_TITLESAFE:
398 mwindow->edl->session->safe_regions = !mwindow->edl->session->safe_regions;
399 composite_panel->operation[CWINDOW_TITLESAFE]->update(mwindow->edl->session->safe_regions);
400 value = mwindow->edl->session->cwindow_operation;
403 mwindow->edl->session->cwindow_operation = value;
404 composite_panel->set_operation(value);
408 edit_panel->update();
409 tool_panel->start_tool(value);
413 void CWindowGUI::update_tool()
415 tool_panel->update_values();
418 int CWindowGUI::close_event()
420 cwindow->hide_window();
425 int CWindowGUI::keypress_event()
428 int cwindow_operation = CWINDOW_NONE;
430 switch( get_keypress() ) {
446 int on = canvas->get_fullscreen() ? 0 : 1;
447 canvas->set_fullscreen(on, 1);
451 canvas->set_fullscreen(0, 1);
455 if( ctrl_down() || shift_down() || alt_down() ) break;
457 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
459 mwindow->gui->unlock_window();
460 lock_window("CWindowGUI::keypress_event 2");
465 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
466 mwindow->clear_entry();
467 mwindow->gui->unlock_window();
468 lock_window("CWindowGUI::keypress_event 3");
473 int alt_down = this->alt_down();
474 int shift_down = this->shift_down();
477 mwindow->gui->lock_window("CWindowGUI::keypress_event 5");
479 mwindow->prev_edit_handle(shift_down);
481 mwindow->move_left();
482 mwindow->gui->unlock_window();
483 lock_window("CWindowGUI::keypress_event 6");
489 if( !ctrl_down() && !alt_down() ) {
492 mwindow->gui->lock_window("CWindowGUI::keypress_event 7");
493 mwindow->move_left();
494 mwindow->gui->unlock_window();
495 lock_window("CWindowGUI::keypress_event 8");
502 int alt_down = this->alt_down();
503 int shift_down = this->shift_down();
506 mwindow->gui->lock_window("CWindowGUI::keypress_event 8");
508 mwindow->next_edit_handle(shift_down);
510 mwindow->move_right();
511 mwindow->gui->unlock_window();
512 lock_window("CWindowGUI::keypress_event 9");
518 if( !ctrl_down() && !alt_down() ) {
521 mwindow->gui->lock_window("CWindowGUI::keypress_event 10");
522 mwindow->move_right();
523 mwindow->gui->unlock_window();
524 lock_window("CWindowGUI::keypress_event 11");
530 if( !result && cwindow_operation < 0 && ctrl_down() && shift_down() ) {
531 switch( get_keypress() ) {
532 case KEY_F1 ... KEY_F4: // mainmenu, load layout
533 resend_event(mwindow->gui);
538 if( !result && !ctrl_down() ) {
539 switch( get_keypress() ) {
542 mwindow->toggle_camera_xyz(); result = 1;
545 cwindow_operation = CWINDOW_PROTECT;
549 mwindow->toggle_projector_xyz(); result = 1;
552 cwindow_operation = CWINDOW_ZOOM;
556 if( !result && cwindow_operation < 0 && !ctrl_down() && !shift_down() ) {
557 switch( get_keypress() ) {
558 case KEY_F3: cwindow_operation = CWINDOW_MASK; break;
559 case KEY_F4: cwindow_operation = CWINDOW_RULER; break;
560 case KEY_F5: cwindow_operation = CWINDOW_CAMERA; break;
561 case KEY_F6: cwindow_operation = CWINDOW_PROJECTOR; break;
562 case KEY_F7: cwindow_operation = CWINDOW_CROP; break;
563 case KEY_F8: cwindow_operation = CWINDOW_EYEDROP; break;
564 case KEY_F9: cwindow_operation = CWINDOW_TOOL_WINDOW; break;
565 case KEY_F10: cwindow_operation = CWINDOW_TITLESAFE; break;
568 if( !result && cwindow_operation < 0 && !ctrl_down() ) {
569 switch( get_keypress() ) {
572 canvas->reset_camera();
574 canvas->camera_keyframe();
579 canvas->reset_projector();
581 canvas->projector_keyframe();
587 if( cwindow_operation >= 0 ) {
588 set_operation(cwindow_operation);
593 result = transport->keypress_event();
599 void CWindowGUI::reset_affected()
606 void CWindowGUI::keyboard_zoomin()
608 zoom_panel->zoom_tumbler->handle_up_event();
611 void CWindowGUI::keyboard_zoomout()
613 zoom_panel->zoom_tumbler->handle_down_event();
616 void CWindowGUI::sync_parameters(int change_type, int redraw, int overlay)
622 if( change_type < 0 && !overlay ) return;
624 if( change_type >= 0 ) {
625 mwindow->restart_brender();
626 mwindow->sync_parameters(change_type);
629 mwindow->gui->lock_window("CWindowGUI::sync_parameters");
630 mwindow->gui->draw_overlays(1);
631 mwindow->gui->unlock_window();
633 lock_window("CWindowGUI::sync_parameters");
636 void CWindowGUI::drag_motion()
638 if( get_hidden() ) return;
640 if( mwindow->session->current_operation != DRAG_ASSET &&
641 mwindow->session->current_operation != DRAG_VTRANSITION &&
642 mwindow->session->current_operation != DRAG_VEFFECT ) return;
643 int need_highlight = cursor_above() && get_cursor_over_window();
644 if( highlighted == need_highlight ) return;
645 highlighted = need_highlight;
649 int CWindowGUI::drag_stop()
652 if( get_hidden() ) return 0;
653 if( !highlighted ) return 0;
654 if( mwindow->session->current_operation != DRAG_ASSET &&
655 mwindow->session->current_operation != DRAG_VTRANSITION &&
656 mwindow->session->current_operation != DRAG_VEFFECT) return 0;
661 if( mwindow->session->current_operation == DRAG_ASSET ) {
662 if( mwindow->session->drag_assets->total ||
663 mwindow->session->drag_clips->total ) {
664 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
665 mwindow->undo->update_undo_before(_("insert assets"), 0);
668 if( mwindow->session->drag_assets->total ) {
670 mwindow->load_assets(mwindow->session->drag_assets,
671 mwindow->edl->local_session->get_selectionstart(),
673 mwindow->session->track_highlighted,
675 mwindow->edl->session->labels_follow_edits,
676 mwindow->edl->session->plugins_follow_edits,
677 mwindow->edl->session->autos_follow_edits,
681 if( mwindow->session->drag_clips->total ) {
683 mwindow->paste_edls(mwindow->session->drag_clips,
685 mwindow->session->track_highlighted,
686 mwindow->edl->local_session->get_selectionstart(),
687 mwindow->edl->session->labels_follow_edits,
688 mwindow->edl->session->plugins_follow_edits,
689 mwindow->edl->session->autos_follow_edits,
693 if( mwindow->session->drag_assets->total ||
694 mwindow->session->drag_clips->total ) {
695 mwindow->save_backup();
696 mwindow->restart_brender();
697 mwindow->gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
698 mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
699 mwindow->gui->unlock_window();
700 sync_parameters(CHANGE_ALL);
704 if( mwindow->session->current_operation == DRAG_VEFFECT ) {
705 //printf("CWindowGUI::drag_stop 1\n");
706 Track *affected_track = cwindow->calculate_affected_track();
707 //printf("CWindowGUI::drag_stop 2\n");
709 mwindow->gui->lock_window("CWindowGUI::drag_stop 3");
710 mwindow->insert_effects_cwindow(affected_track);
711 mwindow->session->current_operation = NO_OPERATION;
712 mwindow->gui->unlock_window();
715 if( mwindow->session->current_operation == DRAG_VTRANSITION ) {
716 Track *affected_track = cwindow->calculate_affected_track();
717 mwindow->gui->lock_window("CWindowGUI::drag_stop 4");
718 mwindow->paste_transition_cwindow(affected_track);
719 mwindow->session->current_operation = NO_OPERATION;
720 mwindow->gui->unlock_window();
726 void CWindowGUI::update_meters()
728 if( mwindow->edl->session->cwindow_meter != meters->visible ) {
729 meters->set_meters(meters->meter_count, mwindow->edl->session->cwindow_meter);
730 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
731 resize_event(get_w(), get_h());
735 void CWindowGUI::stop_transport(const char *lock_msg)
737 if( lock_msg ) unlock_window();
738 mwindow->stop_transport();
739 if( lock_msg ) lock_window(lock_msg);
743 CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
744 : EditPanel(mwindow, cwindow->gui, CWINDOW_ID,
745 mwindow->theme->cedit_x, mwindow->theme->cedit_y,
746 mwindow->edl->session->editing_mode,
747 0, // use_editing_mode
764 this->mwindow = mwindow;
765 this->cwindow = cwindow;
768 #define relock_cm(s) \
769 cwindow->gui->unlock_window(); \
770 mwindow->gui->lock_window("CWindowEditing::" s)
771 #define relock_mc(s) \
772 mwindow->gui->unlock_window(); \
773 cwindow->gui->lock_window("CWindowEditing::" s)
774 #define panel_fn(fn, args, s) \
775 CWindowEditing::fn args { relock_cm(#fn); s; relock_mc(#fn); }
777 // transmit lock to mwindow, and run mbutton->edit_panel->s
778 #define panel_btn(fn, args, s) \
779 panel_fn(panel_##fn, args, mwindow->gui->mbuttons->edit_panel->panel_##s)
782 double CWindowEditing::get_position()
784 relock_cm("get_position");
785 double ret = mwindow->edl->local_session->get_selectionstart(1);
786 relock_mc("get_position");
790 void CWindowEditing::set_position(double position)
792 relock_cm("set_position");
793 mwindow->gui->mbuttons->edit_panel->set_position(position);
794 relock_mc("set_position");
797 void CWindowEditing::set_click_to_play(int v)
799 relock_cm("set_position");
800 mwindow->edl->session->cwindow_click2play = v;
801 relock_mc("set_position");
802 click2play->update(v);
806 void panel_btn(stop_transport,(), stop_transport())
807 void panel_btn(toggle_label,(), toggle_label())
808 void panel_btn(next_label,(int cut), next_label(cut))
809 void panel_btn(prev_label,(int cut), prev_label(cut))
810 void panel_btn(next_edit,(int cut), next_edit(cut))
811 void panel_btn(prev_edit,(int cut), prev_edit(cut))
812 void panel_fn(panel_copy_selection,(), mwindow->copy())
813 void CWindowEditing::panel_overwrite_selection() {} // not used
814 void CWindowEditing::panel_splice_selection() {} // not used
815 void panel_btn(set_inpoint,(), set_inpoint())
816 void panel_btn(set_outpoint,(), set_outpoint())
817 void panel_btn(unset_inoutpoint,(), unset_inoutpoint())
818 void panel_fn(panel_to_clip,(), mwindow->to_clip(mwindow->edl, _("main window: "), 0))
819 void panel_btn(cut,(), cut())
820 void panel_btn(paste,(), paste())
821 void panel_btn(fit_selection,(), fit_selection())
822 void panel_btn(fit_autos,(int all), fit_autos(all))
823 void panel_btn(set_editing_mode,(int mode), set_editing_mode(mode))
824 void panel_btn(set_auto_keyframes,(int v), set_auto_keyframes(v))
825 void panel_btn(set_span_keyframes,(int v), set_span_keyframes(v))
826 void panel_btn(set_labels_follow_edits,(int v), set_labels_follow_edits(v))
829 CWindowMeters::CWindowMeters(MWindow *mwindow,
830 CWindowGUI *gui, int x, int y, int h)
831 : MeterPanel(mwindow, gui, x, y, -1, h,
832 mwindow->edl->session->audio_channels,
833 mwindow->edl->session->cwindow_meter,
836 this->mwindow = mwindow;
840 CWindowMeters::~CWindowMeters()
844 int CWindowMeters::change_status_event(int new_status)
846 mwindow->edl->session->cwindow_meter = new_status;
847 gui->update_meters();
854 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
855 : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
856 x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
858 this->mwindow = mwindow;
862 CWindowZoom::~CWindowZoom()
866 void CWindowZoom::update(double value)
868 char string[BCSTRLEN];
869 const char *cp = string;
872 int frac = value >= 1.0f ? 1 :
874 value >= .01f ? 3 : 4;
875 sprintf(string, "x %.*f", frac, value);
879 ZoomPanel::update(cp);
882 int CWindowZoom::handle_event()
884 double value = !strcasecmp(gui->auto_zoom, get_text()) ? 0 : get_value();
885 gui->canvas->set_zoom(mwindow->edl, value);
886 gui->update_canvas();
893 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
894 : BC_PercentageSlider(x, y, 0, pixels, pixels, 0, 1, 0)
896 this->mwindow = mwindow;
897 this->cwindow = cwindow;
898 set_precision(0.00001);
901 CWindowSlider::~CWindowSlider()
905 int CWindowSlider::handle_event()
907 cwindow->update_position((double)get_value());
911 void CWindowSlider::set_position()
913 double new_length = mwindow->edl->tracks->total_length();
914 update(mwindow->theme->cslider_w,
915 mwindow->edl->local_session->get_selectionstart(1),
920 int CWindowSlider::increase_value()
923 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
924 lock_window("CWindowSlider::increase_value");
928 int CWindowSlider::decrease_value()
931 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
932 lock_window("CWindowSlider::decrease_value");
938 CWindowTransport::CWindowTransport(MWindow *mwindow,
939 CWindowGUI *gui, int x, int y)
940 : PlayTransport(mwindow, gui, x, y)
945 EDL* CWindowTransport::get_edl()
950 void CWindowTransport::goto_start()
952 gui->unlock_window();
953 handle_transport(REWIND, 1);
955 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
956 mwindow->goto_start();
957 mwindow->gui->unlock_window();
959 gui->lock_window("CWindowTransport::goto_start 2");
962 void CWindowTransport::goto_end()
964 gui->unlock_window();
965 handle_transport(GOTO_END, 1);
967 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
969 mwindow->gui->unlock_window();
971 gui->lock_window("CWindowTransport::goto_end 2");
976 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
977 : Canvas(mwindow, gui,
978 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
979 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h,
980 0, 0, mwindow->edl->session->cwindow_scrollbars)
982 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::set_fullscreen(int on, int unlock)
1006 if( on && !get_fullscreen() ) {
1007 last_xscroll = get_xscroll();
1008 last_yscroll = get_yscroll();
1009 last_zoom = get_zoom();
1010 Canvas::set_fullscreen(1, unlock);
1014 if( !on && get_fullscreen() ) {
1015 Canvas::set_fullscreen(0, unlock);
1016 gui->zoom_panel->update(get_zoom());
1017 update_zoom(last_xscroll, last_yscroll, last_zoom);
1018 gui->update_canvas();
1024 int CWindowCanvas::get_xscroll()
1026 return mwindow->edl->session->cwindow_xscroll;
1029 int CWindowCanvas::get_yscroll()
1031 return mwindow->edl->session->cwindow_yscroll;
1035 float CWindowCanvas::get_zoom()
1037 return mwindow->edl->session->cwindow_zoom;
1040 void CWindowCanvas::zoom_auto()
1043 set_zoom(mwindow->edl, 0);
1044 gui->update_canvas();
1047 int CWindowCanvas::do_scroll(EDL *edl, float cursor_x, float cursor_y)
1049 float zoom = get_zoom();
1050 float zoom_x, zoom_y, conformed_w, conformed_h;
1051 get_zooms(edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
1053 x = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
1054 y = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
1055 zoom = get_auto_zoom(mwindow->edl);
1058 x = gui->x_origin - cursor_x / zoom_x;
1059 y = gui->y_origin - cursor_y / zoom_y;
1061 update_zoom(x, y, zoom);
1062 gui->update_canvas();
1066 void CWindowCanvas::draw_refresh(int flush)
1068 BC_WindowBase *window = get_canvas();
1069 if( window && !window->get_video_on() ) {
1071 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
1072 float in_x1, in_y1, in_x2, in_y2;
1073 float out_x1, out_y1, out_x2, out_y2;
1074 get_transfers(mwindow->edl,
1075 in_x1, in_y1, in_x2, in_y2,
1076 out_x1, out_y1, out_x2, out_y2);
1079 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1080 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1083 if( out_x2 > out_x1 && out_y2 > out_y1 &&
1084 in_x2 > in_x1 && in_y2 > in_y1 ) {
1085 // input scaled from session to refresh frame coordinates
1086 int ow = get_output_w(mwindow->edl);
1087 int oh = get_output_h(mwindow->edl);
1088 int rw = refresh_frame->get_w();
1089 int rh = refresh_frame->get_h();
1090 float xs = (float)rw / ow;
1091 float ys = (float)rh / oh;
1092 in_x1 *= xs; in_x2 *= xs;
1093 in_y1 *= ys; in_y2 *= ys;
1094 // Can't use OpenGL here because it is called asynchronously of the
1095 // playback operation.
1096 window->draw_vframe(refresh_frame,
1097 (int)out_x1, (int)out_y1,
1098 (int)(out_x2 - out_x1),
1099 (int)(out_y2 - out_y1),
1100 (int)in_x1, (int)in_y1,
1101 (int)(in_x2 - in_x1),
1102 (int)(in_y2 - in_y1),
1108 window->flash(flush);
1110 //printf("CWindowCanvas::draw_refresh 10\n");
1113 #define CROPHANDLE_W xS(10)
1114 #define CROPHANDLE_H yS(10)
1116 void CWindowCanvas::draw_crophandle(int x, int y)
1118 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1122 #define CONTROL_W xS(10)
1123 #define CONTROL_H yS(10)
1124 #define FIRST_CONTROL_W xS(20)
1125 #define FIRST_CONTROL_H yS(20)
1127 #define BC_INFINITY 65536
1129 #define RULERHANDLE_W xS(16)
1130 #define RULERHANDLE_H yS(16)
1132 int CWindowCanvas::do_ruler(int draw, int motion,
1133 int button_press, int button_release)
1136 EDLSession *session = mwindow->edl->session;
1137 float x1 = session->ruler_x1;
1138 float y1 = session->ruler_y1;
1139 float x2 = session->ruler_x2;
1140 float y2 = session->ruler_y2;
1141 float canvas_x1 = x1;
1142 float canvas_y1 = y1;
1143 float canvas_x2 = x2;
1144 float canvas_y2 = y2;
1145 float output_x = get_cursor_x();
1146 float output_y = get_cursor_y();
1147 float canvas_cursor_x = output_x;
1148 float canvas_cursor_y = output_y;
1150 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1151 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1152 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1153 mwindow->session->cwindow_output_x = roundf(output_x);
1154 mwindow->session->cwindow_output_y = roundf(output_y);
1156 if( button_press && get_buttonpress() == 1 ) {
1157 gui->ruler_handle = -1;
1158 gui->ruler_translate = 0;
1159 if( gui->alt_down() ) {
1160 gui->ruler_translate = 1;
1161 gui->ruler_origin_x = x1;
1162 gui->ruler_origin_y = y1;
1165 if( canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1166 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1167 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1168 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2 ) {
1169 gui->ruler_handle = 0;
1170 gui->ruler_origin_x = x1;
1171 gui->ruler_origin_y = y1;
1174 if( canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1175 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1176 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1177 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2 ) {
1178 gui->ruler_handle = 1;
1179 gui->ruler_origin_x = x2;
1180 gui->ruler_origin_y = y2;
1184 // Start new selection
1185 if( !gui->ruler_translate &&
1186 (gui->ruler_handle < 0 ||
1190 do_ruler(1, 0, 0, 0);
1191 get_canvas()->flash();
1192 gui->ruler_handle = 1;
1193 session->ruler_x1 = output_x;
1194 session->ruler_y1 = output_y;
1195 session->ruler_x2 = output_x;
1196 session->ruler_y2 = output_y;
1197 gui->ruler_origin_x = session->ruler_x2;
1198 gui->ruler_origin_y = session->ruler_y2;
1201 gui->x_origin = output_x;
1202 gui->y_origin = output_y;
1203 gui->current_operation = CWINDOW_RULER;
1204 gui->tool_panel->raise_window();
1209 if( gui->current_operation == CWINDOW_RULER ) {
1210 if( gui->ruler_translate ) {
1212 do_ruler(1, 0, 0, 0);
1213 float x_difference = session->ruler_x1;
1214 float y_difference = session->ruler_y1;
1215 session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1216 session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1217 x_difference -= session->ruler_x1;
1218 y_difference -= session->ruler_y1;
1219 session->ruler_x2 -= x_difference;
1220 session->ruler_y2 -= y_difference;
1222 do_ruler(1, 0, 0, 0);
1223 get_canvas()->flash();
1227 switch( gui->ruler_handle ) {
1229 do_ruler(1, 0, 0, 0);
1230 session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1231 session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1232 if( gui->alt_down() || gui->ctrl_down() ) {
1233 double angle_value = fabs(atan((session->ruler_y2 - session->ruler_y1) /
1234 (session->ruler_x2 - session->ruler_x1)) *
1236 double distance_value =
1237 sqrt(SQR(session->ruler_x2 - session->ruler_x1) +
1238 SQR(session->ruler_y2 - session->ruler_y1));
1239 if( angle_value < 22 )
1240 session->ruler_y1 = session->ruler_y2;
1242 if( angle_value > 67 )
1243 session->ruler_x1 = session->ruler_x2;
1245 if( session->ruler_x1 < session->ruler_x2 &&
1246 session->ruler_y1 < session->ruler_y2 ) {
1247 session->ruler_x1 = session->ruler_x2 - distance_value / 1.414214;
1248 session->ruler_y1 = session->ruler_y2 - distance_value / 1.414214;
1251 if( session->ruler_x1 < session->ruler_x2 && session->ruler_y1 > session->ruler_y2 ) {
1252 session->ruler_x1 = session->ruler_x2 - distance_value / 1.414214;
1253 session->ruler_y1 = session->ruler_y2 + distance_value / 1.414214;
1256 if( session->ruler_x1 > session->ruler_x2 &&
1257 session->ruler_y1 < session->ruler_y2 ) {
1258 session->ruler_x1 = session->ruler_x2 + distance_value / 1.414214;
1259 session->ruler_y1 = session->ruler_y2 - distance_value / 1.414214;
1262 session->ruler_x1 = session->ruler_x2 + distance_value / 1.414214;
1263 session->ruler_y1 = session->ruler_y2 + distance_value / 1.414214;
1266 do_ruler(1, 0, 0, 0);
1267 get_canvas()->flash();
1272 do_ruler(1, 0, 0, 0);
1273 session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1274 session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1275 if( gui->alt_down() || gui->ctrl_down() ) {
1276 double angle_value = fabs(atan((session->ruler_y2 - session->ruler_y1) /
1277 (session->ruler_x2 - session->ruler_x1)) *
1279 double distance_value =
1280 sqrt(SQR(session->ruler_x2 - session->ruler_x1) +
1281 SQR(session->ruler_y2 - session->ruler_y1));
1282 if( angle_value < 22 )
1283 session->ruler_y2 = session->ruler_y1;
1285 if( angle_value > 67 )
1286 session->ruler_x2 = session->ruler_x1;
1288 if( session->ruler_x2 < session->ruler_x1 &&
1289 session->ruler_y2 < session->ruler_y1 ) {
1290 session->ruler_x2 = session->ruler_x1 - distance_value / 1.414214;
1291 session->ruler_y2 = session->ruler_y1 - distance_value / 1.414214;
1294 if( session->ruler_x2 < session->ruler_x1 &&
1295 session->ruler_y2 > session->ruler_y1 ) {
1296 session->ruler_x2 = session->ruler_x1 - distance_value / 1.414214;
1297 session->ruler_y2 = session->ruler_y1 + distance_value / 1.414214;
1300 if( session->ruler_x2 > session->ruler_x1 && session->ruler_y2 < session->ruler_y1 ) {
1301 session->ruler_x2 = session->ruler_x1 + distance_value / 1.414214;
1302 session->ruler_y2 = session->ruler_y1 - distance_value / 1.414214;
1305 session->ruler_x2 = session->ruler_x1 + distance_value / 1.414214;
1306 session->ruler_y2 = session->ruler_y1 + distance_value / 1.414214;
1309 do_ruler(1, 0, 0, 0);
1310 get_canvas()->flash();
1315 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1318 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1323 if( canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1324 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1325 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1326 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2 ) {
1327 set_cursor(UPRIGHT_ARROW_CURSOR);
1330 if( canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1331 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1332 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1333 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2 ) {
1334 set_cursor(UPRIGHT_ARROW_CURSOR);
1337 set_cursor(CROSS_CURSOR);
1339 // Update current position
1344 // Assume no ruler measurement if 0 length
1345 if( draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)) ) {
1346 get_canvas()->set_inverse();
1347 get_canvas()->set_color(WHITE);
1348 get_canvas()->draw_line((int)canvas_x1,
1352 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1354 roundf(canvas_x1) + RULERHANDLE_W / 2,
1356 get_canvas()->draw_line(roundf(canvas_x1),
1357 roundf(canvas_y1) - RULERHANDLE_H / 2,
1359 roundf(canvas_y1) + RULERHANDLE_H / 2);
1360 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1362 roundf(canvas_x2) + RULERHANDLE_W / 2,
1364 get_canvas()->draw_line(roundf(canvas_x2),
1365 roundf(canvas_y2) - RULERHANDLE_H / 2,
1367 roundf(canvas_y2) + RULERHANDLE_H / 2);
1368 get_canvas()->set_opaque();
1375 static inline double line_dist(float cx,float cy, float tx,float ty)
1377 double dx = tx-cx, dy = ty-cy;
1378 return sqrt(dx*dx + dy*dy);
1381 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1383 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1384 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1388 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1389 int button_press, int cursor_motion, int draw)
1391 // Retrieve points from top recordable track
1392 //printf("CWindowCanvas::do_mask 1\n");
1393 Track *track = gui->cwindow->calculate_mask_track();
1394 //printf("CWindowCanvas::do_mask 2\n");
1396 if( !track ) return 0;
1397 //printf("CWindowCanvas::do_mask 3\n");
1398 CWindowMaskGUI *mask_gui = (CWindowMaskGUI *)
1399 (gui->tool_panel ? gui->tool_panel->tool_gui : 0);
1400 int draw_markers = mask_gui ? mask_gui->markers : 0;
1401 int draw_boundary = mask_gui ? mask_gui->boundary : 0;
1402 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1403 int64_t position = track->to_units(
1404 mwindow->edl->local_session->get_selectionstart(1),
1406 Auto *prev_auto = 0;
1407 mask_autos->get_prev_auto(position, PLAY_FORWARD, (Auto *&)prev_auto, 1);
1408 MaskAuto *prev_mask = (MaskAuto *)prev_auto;
1410 int update_points = 1;
1411 // Determine the points based on whether
1412 // new keyframes will be generated or drawing is performed.
1413 // If keyframe generation occurs, use the interpolated mask.
1414 // If no keyframe generation occurs, use the previous mask.
1415 int use_interpolated = 0;
1416 if( button_press || cursor_motion ) {
1417 #ifdef USE_KEYFRAME_SPANNING
1418 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1419 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1420 int64_t start_pos = track->to_units(selection_start, 0);
1421 int64_t end_pos = track->to_units(selection_end, 0);
1422 Auto *first = 0, *last = 0;
1423 mask_autos->get_prev_auto(start_pos, PLAY_FORWARD, first, 1);
1424 mask_autos->get_prev_auto(end_pos, PLAY_FORWARD, last, 1);
1425 if( last == first && (!mwindow->edl->session->auto_keyframes) )
1426 use_interpolated = 0;
1428 // If keyframe spanning occurs, use the interpolated points.
1429 // If new keyframe is generated, use the interpolated points.
1430 use_interpolated = 1;
1433 if( mwindow->edl->session->auto_keyframes )
1434 use_interpolated = 1;
1438 use_interpolated = 1;
1440 if( use_interpolated ) {
1441 // Interpolate the points to get exactly what is being rendered at this position.
1442 mask_autos->get_points(&points,
1443 mwindow->edl->session->cwindow_mask,
1444 position, PLAY_FORWARD);
1447 // Use the prev mask
1448 prev_mask->get_points(&points,
1449 mwindow->edl->session->cwindow_mask);
1452 // Projector zooms relative to the center of the track output.
1453 float half_track_w = (float)track->track_w / 2;
1454 float half_track_h = (float)track->track_h / 2;
1455 // Translate mask to projection
1456 float projector_x, projector_y, projector_z;
1457 track->automation->get_projector(
1458 &projector_x, &projector_y, &projector_z,
1459 position, PLAY_FORWARD);
1462 // Get position of cursor relative to mask
1463 float cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
1464 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1465 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1467 projector_x += mwindow->edl->session->output_w / 2;
1468 projector_y += mwindow->edl->session->output_h / 2;
1469 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1470 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1472 // Fix cursor origin
1473 if( button_press ) {
1474 gui->x_origin = mask_cursor_x;
1475 gui->y_origin = mask_cursor_y;
1479 // Points of closest line
1480 int shortest_point1 = -1;
1481 int shortest_point2 = -1;
1483 int shortest_point = -1;
1484 // Distance to closest line
1485 float shortest_line_distance = BC_INFINITY;
1486 // Distance to closest point
1487 float shortest_point_distance = BC_INFINITY;
1488 int selected_point = -1;
1489 int selected_control_point = -1;
1490 float selected_control_point_distance = BC_INFINITY;
1491 ArrayList<int> x_points;
1492 ArrayList<int> y_points;
1494 if( !cursor_motion ) {
1496 get_canvas()->set_color(WHITE);
1497 get_canvas()->set_inverse();
1499 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1501 // Never draw closed polygon and a closed
1502 // polygon is harder to add points to.
1503 for( int i = 0; i < points.size() && !result; i++ ) {
1504 MaskPoint *point1 = points.get(i);
1505 MaskPoint *point2 = (i >= points.size() - 1) ?
1506 points.get(0) : points.get(i + 1);
1507 if( button_press ) {
1508 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1509 if( point_distance1 < shortest_point_distance || shortest_point < 0 ) {
1510 shortest_point_distance = point_distance1;
1514 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1515 if( point_distance2 < shortest_point_distance || shortest_point < 0 ) {
1516 shortest_point_distance = point_distance2;
1517 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1521 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1523 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1524 //point1->x, point1->y, point2->x, point2->y, projector_z);
1525 for( int j = 0; j <= segments && !result; j++ ) {
1526 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1527 float x0 = point1->x, y0 = point1->y;
1528 float x1 = point1->x + point1->control_x2;
1529 float y1 = point1->y + point1->control_y2;
1530 float x2 = point2->x + point2->control_x1;
1531 float y2 = point2->y + point2->control_y1;
1532 float x3 = point2->x, y3 = point2->y;
1533 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1534 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1535 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1536 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1537 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1538 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1539 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1540 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1542 float t = (float)j / segments;
1543 float tpow2 = t * t;
1544 float tpow3 = t * t * t;
1546 float invtpow2 = invt * invt;
1547 float invtpow3 = invt * invt * invt;
1549 float x = ( invtpow3 * x0
1550 + 3 * t * invtpow2 * x1
1551 + 3 * tpow2 * invt * x2
1553 float y = ( invtpow3 * y0
1554 + 3 * t * invtpow2 * y1
1555 + 3 * tpow2 * invt * y2
1557 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1558 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1559 // Test new point addition
1560 if( button_press ) {
1561 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1563 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1564 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1565 if( line_distance < shortest_line_distance ||
1566 shortest_point1 < 0 ) {
1567 shortest_line_distance = line_distance;
1568 shortest_point1 = i;
1569 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1570 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1571 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1574 // Test existing point selection
1576 if( gui->ctrl_down() ) {
1577 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1579 if( distance < selected_control_point_distance ) {
1581 selected_control_point = 1;
1582 selected_control_point_distance = distance;
1586 if( !gui->shift_down() ) {
1587 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1588 if( test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0) ) {
1593 selected_point = shortest_point;
1596 // Test second point
1597 if( gui->ctrl_down() ) {
1598 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1600 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1601 if( distance < selected_control_point_distance ) {
1602 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1603 selected_control_point = 0;
1604 selected_control_point_distance = distance;
1607 else if( i < points.size() - 1 ) {
1608 if( !gui->shift_down() ) {
1609 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1610 if( test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3) ) {
1611 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1615 selected_point = shortest_point;
1620 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1624 if( draw ) { // Draw joining line
1625 x_points.append((int)canvas_x);
1626 y_points.append((int)canvas_y);
1629 if( j == segments ) {
1630 if( draw && draw_markers ) { // Draw second anchor
1631 if( i < points.size() - 1 ) {
1632 if( i == gui->affected_point - 1 )
1633 get_canvas()->draw_disc(
1634 (int)canvas_x - CONTROL_W / 2,
1635 (int)canvas_y - CONTROL_W / 2,
1636 CONTROL_W, CONTROL_H);
1638 get_canvas()->draw_circle(
1639 (int)canvas_x - CONTROL_W / 2,
1640 (int)canvas_y - CONTROL_W / 2,
1641 CONTROL_W, CONTROL_H);
1642 // char string[BCTEXTLEN];
1643 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1644 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1646 // Draw second control point.
1647 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1648 get_canvas()->draw_line(
1649 (int)canvas_x, (int)canvas_y,
1650 (int)canvas_x2, (int)canvas_y2);
1651 get_canvas()->draw_rectangle(
1652 (int)canvas_x2 - CONTROL_W / 2,
1653 (int)canvas_y2 - CONTROL_H / 2,
1654 CONTROL_W, CONTROL_H);
1659 // Draw first anchor
1660 if( i == 0 && draw ) {
1661 if( draw_boundary ) {
1662 char mask_label[BCSTRLEN];
1663 int k = mwindow->edl->session->cwindow_mask;
1664 if( !prev_mask || k < 0 || k >= prev_mask->masks.size() )
1665 sprintf(mask_label, "%d", k);
1667 sprintf(mask_label, "%s", prev_mask->masks[k]->name);
1668 get_canvas()->draw_text(
1669 (int)canvas_x - FIRST_CONTROL_W,
1670 (int)canvas_y - FIRST_CONTROL_H,
1673 if( draw_markers ) {
1674 get_canvas()->draw_disc(
1675 (int)canvas_x - FIRST_CONTROL_W / 2,
1676 (int)canvas_y - FIRST_CONTROL_H / 2,
1677 FIRST_CONTROL_W, FIRST_CONTROL_H);
1681 // Draw first control point.
1682 if( draw && draw_markers ) {
1683 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1684 get_canvas()->draw_line(
1685 (int)canvas_x, (int)canvas_y,
1686 (int)canvas_x1, (int)canvas_y1);
1687 get_canvas()->draw_rectangle(
1688 (int)canvas_x1 - CONTROL_W / 2,
1689 (int)canvas_y1 - CONTROL_H / 2,
1690 CONTROL_W, CONTROL_H);
1692 x_points.append((int)canvas_x);
1693 y_points.append((int)canvas_y);
1696 //printf("CWindowCanvas::do_mask 1\n");
1700 //printf("CWindowCanvas::do_mask 1\n");
1702 BC_WindowBase *cvs_win = get_canvas();
1703 if( draw && draw_boundary ) {
1704 cvs_win->draw_polygon(&x_points, &y_points);
1705 cvs_win->set_opaque();
1707 if( draw && mask_gui && mask_gui->focused ) {
1708 float fx = atof(mask_gui->focus_x->get_text());
1709 float fy = atof(mask_gui->focus_y->get_text());
1710 fx = (fx - half_track_w) * projector_z + projector_x;
1711 fy = (fy - half_track_h) * projector_z + projector_y;
1712 output_to_canvas(mwindow->edl, 0, fx, fy);
1713 float r = bmax(cvs_win->get_w(), cvs_win->get_h());
1716 int fw = 2*d+3, fh = fw;
1717 VFrame focus(fw,fh, BC_RGBA8888);
1718 focus.transfer_from(gui->focus_frame);
1719 fx -= fw/2.f; fy -= fh/2.f;
1720 BC_Pixmap focus_pixmap(cvs_win, &focus, PIXMAP_ALPHA);
1721 cvs_win->draw_pixmap(&focus_pixmap,fx,fy);
1723 cvs_win->set_line_width((int)(0.0025*r) + 1);
1724 cvs_win->set_color(BLUE);
1725 cvs_win->draw_line(fx-d,fy-d, fx+d, fy+d);
1726 cvs_win->draw_line(fx-d,fy+d, fx+d, fy-d);
1727 cvs_win->set_line_width(0);
1728 cvs_win->set_color(WHITE);
1731 if( draw && mask_gui && draw_markers && points.size() ) {
1732 float cx = 0, cy = 0;
1733 int n = points.size();
1734 for( int i=0; i<n; ++i ) {
1735 MaskPoint *point = points.get(i);
1736 cx += point->x; cy += point->y;
1739 if( !mask_gui->focused )
1740 mask_gui->set_focused(0, cx, cy);
1741 cx = (cx - half_track_w) * projector_z + projector_x;
1742 cy = (cy - half_track_h) * projector_z + projector_y;
1743 output_to_canvas(mwindow->edl, 0, cx, cy);
1744 float r = bmax(cvs_win->get_w(), cvs_win->get_h());
1746 cvs_win->set_line_width((int)(0.002*r) + 1);
1747 cvs_win->set_color(ORANGE);
1748 cvs_win->draw_line(cx-d,cy, cx+d, cy);
1749 cvs_win->draw_line(cx,cy-d, cx, cy+d);
1750 cvs_win->set_line_width(0);
1751 cvs_win->set_color(WHITE);
1753 //printf("CWindowCanvas::do_mask 1\n");
1756 if( button_press && !result ) {
1757 gui->affected_track = gui->cwindow->calculate_mask_track();
1759 // Get keyframe outside the EDL to edit. This must be rendered
1760 // instead of the EDL keyframes when it exists. Then it must be
1761 // applied to the EDL keyframes on buttonrelease.
1762 if( gui->affected_track ) {
1763 #ifdef USE_KEYFRAME_SPANNING
1764 // Make copy of current parameters in local keyframe
1765 gui->mask_keyframe =
1766 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1768 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1771 gui->mask_keyframe =
1772 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1776 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1778 if( get_buttonpress() == WHEEL_UP || get_buttonpress() == WHEEL_DOWN ) {
1779 if( !gui->shift_down() ) {
1780 mwindow->undo->update_undo_before(_("mask rotate"), this);
1781 gui->current_operation = CWINDOW_MASK_ROTATE;
1784 mwindow->undo->update_undo_before(_("mask scale"), this);
1785 gui->current_operation = CWINDOW_MASK_SCALE;
1787 gui->affected_point = 0;
1790 // Translate entire keyframe
1791 if( gui->alt_down() && mask->points.size() ) {
1792 mwindow->undo->update_undo_before(_("mask translate"), 0);
1793 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1794 gui->affected_point = 0;
1797 // Existing point or control point was selected
1798 if( selected_point >= 0 ) {
1799 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1800 gui->affected_point = selected_point;
1802 if( selected_control_point == 0 )
1803 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1805 if( selected_control_point == 1 )
1806 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1808 gui->current_operation = mwindow->edl->session->cwindow_operation;
1810 else // No existing point or control point was selected so create a new one
1811 if( !gui->ctrl_down() && !gui->alt_down() ) {
1812 mwindow->undo->update_undo_before(_("mask point"), 0);
1813 // Create the template
1814 MaskPoint *point = new MaskPoint;
1815 point->x = mask_cursor_x;
1816 point->y = mask_cursor_y;
1817 point->control_x1 = 0;
1818 point->control_y1 = 0;
1819 point->control_x2 = 0;
1820 point->control_y2 = 0;
1823 if( shortest_point2 < shortest_point1 ) {
1824 shortest_point2 ^= shortest_point1;
1825 shortest_point1 ^= shortest_point2;
1826 shortest_point2 ^= shortest_point1;
1831 // printf("CWindowGUI::do_mask 40\n");
1832 // mwindow->edl->dump();
1833 // printf("CWindowGUI::do_mask 50\n");
1837 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1838 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1839 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1841 // Append to end of list
1842 if( shortest_point1 == shortest_point2 ||
1843 labs(shortest_point1 - shortest_point2) > 1) {
1844 #ifdef USE_KEYFRAME_SPANNING
1846 MaskPoint *new_point = new MaskPoint;
1847 points.append(new_point);
1848 *new_point = *point;
1849 gui->affected_point = points.size() - 1;
1853 // Need to apply the new point to every keyframe
1854 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1855 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1856 MaskPoint *new_point = new MaskPoint;
1857 submask->points.append(new_point);
1858 *new_point = *point;
1859 if( current == (MaskAuto*)mask_autos->default_auto )
1860 current = (MaskAuto*)mask_autos->first;
1862 current = (MaskAuto*)NEXT;
1864 gui->affected_point = mask->points.size() - 1;
1870 // Insert between 2 points, shifting back point 2
1871 if( shortest_point1 >= 0 && shortest_point2 >= 0 ) {
1873 #ifdef USE_KEYFRAME_SPANNING
1874 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1876 if( points.size() >= shortest_point2 ) {
1877 MaskPoint *new_point = new MaskPoint;
1879 for( int i = points.size() - 1;
1880 i > shortest_point2;
1882 points.values[i] = points.values[i - 1];
1883 points.values[shortest_point2] = new_point;
1885 *new_point = *point;
1890 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1891 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1892 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1894 if( submask->points.size() >= shortest_point2 ) {
1895 MaskPoint *new_point = new MaskPoint;
1896 submask->points.append(0);
1897 for( int i = submask->points.size() - 1;
1898 i > shortest_point2;
1900 submask->points.values[i] = submask->points.values[i - 1];
1901 submask->points.values[shortest_point2] = new_point;
1903 *new_point = *point;
1906 if( current == (MaskAuto*)mask_autos->default_auto )
1907 current = (MaskAuto*)mask_autos->first;
1909 current = (MaskAuto*)NEXT;
1913 gui->affected_point = shortest_point2;
1918 // printf("CWindowGUI::do_mask 20\n");
1919 // mwindow->edl->dump();
1920 // printf("CWindowGUI::do_mask 30\n");
1923 //printf("CWindowCanvas::do_mask 1\n");
1924 // Create the first point.
1925 #ifdef USE_KEYFRAME_SPANNING
1926 MaskPoint *new_point = new MaskPoint;
1927 points.append(new_point);
1928 *new_point = *point;
1929 gui->affected_point = points.size() - 1;
1931 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1932 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1933 MaskPoint *new_point = new MaskPoint;
1934 submask->points.append(new_point);
1935 *new_point = *point;
1936 if( current == (MaskAuto*)mask_autos->default_auto )
1937 current = (MaskAuto*)mask_autos->first;
1939 current = (MaskAuto*)NEXT;
1941 gui->affected_point = points.size() - 1;
1944 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
1947 gui->current_operation = mwindow->edl->session->cwindow_operation;
1948 // Delete the template
1957 if( button_press && result ) {
1958 #ifdef USE_KEYFRAME_SPANNING
1959 MaskPoints &mask_points = points;
1961 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1962 MaskPoints &mask_points = mask->points;
1964 int k = gui->affected_point;
1965 if( k >= 0 && k < mask_points.size() ) {
1966 MaskPoint *point = mask_points.values[k];
1967 gui->center_x = point->x;
1968 gui->center_y = point->y;
1969 gui->control_in_x = point->control_x1;
1970 gui->control_in_y = point->control_y1;
1971 gui->control_out_x = point->control_x2;
1972 gui->control_out_y = point->control_y2;
1975 gui->center_x = gui->center_y = 0;
1976 gui->control_in_x = gui->control_in_y = 0;
1977 gui->control_out_x = gui->control_out_y = 0;
1979 gui->tool_panel->raise_window();
1982 //printf("CWindowCanvas::do_mask 8\n");
1983 if( cursor_motion ) {
1985 #ifdef USE_KEYFRAME_SPANNING
1986 // Must update the reference keyframes for every cursor motion
1987 gui->mask_keyframe = (MaskAuto*)gui->cwindow->
1988 calculate_affected_auto(mask_autos, 0);
1989 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1992 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1994 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1995 if( mask && gui->affected_point >= 0 &&
1996 gui->affected_point < mask->points.size() &&
1997 gui->current_operation != CWINDOW_NONE ) {
1998 // mwindow->undo->update_undo_before(_("mask point"), this);
1999 #ifdef USE_KEYFRAME_SPANNING
2000 MaskPoints &mask_points = points;
2002 MaskPoints &mask_points = mask->points;
2004 MaskPoint *point = mask_points.get(gui->affected_point);
2005 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2006 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask_points.size(), gui->affected_point);
2008 float last_x = point->x;
2009 float last_y = point->y;
2010 float last_control_x1 = point->control_x1;
2011 float last_control_y1 = point->control_y1;
2012 float last_control_x2 = point->control_x2;
2013 float last_control_y2 = point->control_y2;
2016 switch( gui->current_operation ) {
2018 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2019 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
2020 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
2023 case CWINDOW_MASK_CONTROL_IN:
2024 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
2025 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
2028 case CWINDOW_MASK_CONTROL_OUT:
2029 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
2030 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
2033 case CWINDOW_MASK_TRANSLATE: {
2034 if( !mask_gui ) break;
2035 int mode = mask_gui->scale_mode;
2036 MaskAuto *keyframe = gui->mask_keyframe;
2037 int gang = mask_gui->gang_focus->get_value();
2038 float dx = mask_cursor_x - gui->x_origin;
2039 float dy = mask_cursor_y - gui->y_origin;
2040 if( !dx && !dy ) break;
2041 int k = mwindow->edl->session->cwindow_mask;
2042 int n = gang ? keyframe->masks.size() : k+1;
2043 for( int j=gang? 0 : k; j<n; ++j ) {
2044 if( !mask_gui->mask_enables[j]->get_value() ) continue;
2045 SubMask *sub_mask = keyframe->get_submask(j);
2046 if( !sub_mask ) continue;
2047 MaskPoints &points = sub_mask->points;
2048 for( int i=0; i<points.size(); ++i ) {
2049 MaskPoint *point = points[i];
2050 if( mode == MASK_SCALE_X || mode == MASK_SCALE_XY ) point->x += dx;
2051 if( mode == MASK_SCALE_Y || mode == MASK_SCALE_XY ) point->y += dy;
2054 gui->x_origin = mask_cursor_x;
2055 gui->y_origin = mask_cursor_y;
2060 case CWINDOW_MASK_ROTATE:
2062 case CWINDOW_MASK_SCALE: {
2063 if( !mask_gui || !mask_points.size() ) break;
2064 float cx = gui->x_origin, cy = gui->y_origin;
2065 if( mask_gui->focused ) {
2066 cx = atof(mask_gui->focus_x->get_text());
2067 cy = atof(mask_gui->focus_y->get_text());
2069 else if( !gui->ctrl_down() ) {
2071 int n = mask_points.size();
2072 for( int i=0; i<n; ++i ) {
2073 MaskPoint *point = mask_points.values[i];
2074 cx += point->x; cy += point->y;
2077 mask_gui->set_focused(0, cx, cy);
2082 gui->get_triple_click() ? 8. :
2083 gui->get_double_click() ? 4. :
2085 int button_no = get_buttonpress();
2086 double ds = accel/64., dt = accel*M_PI/360.;
2087 double scale = button_no == WHEEL_UP ? 1.+ds : 1.-ds;
2088 int mode = mask_gui->scale_mode;
2089 double xscale = !rotate && (mode == MASK_SCALE_X ||
2090 mode == MASK_SCALE_XY ) ? scale : 1.;
2091 double yscale = !rotate && (mode == MASK_SCALE_Y ||
2092 mode == MASK_SCALE_XY ) ? scale : 1.;
2093 double theta = button_no == WHEEL_UP ? dt : -dt;
2094 if( rotate ? theta==0 : scale==1 ) break;
2095 float st = sin(theta), ct = cos(theta);
2096 MaskAuto *keyframe = gui->mask_keyframe;
2097 int gang = mask_gui->gang_focus->get_value();
2098 int k = mwindow->edl->session->cwindow_mask;
2099 int n = gang ? keyframe->masks.size() : k+1;
2100 for( int j=gang? 0 : k; j<n; ++j ) {
2101 if( !mask_gui->mask_enables[j]->get_value() ) continue;
2102 SubMask *sub_mask = keyframe->get_submask(j);
2103 if( !sub_mask ) continue;
2104 MaskPoints &points = sub_mask->points;
2105 for( int i=0; i<points.size(); ++i ) {
2106 MaskPoint *point = points[i];
2107 float px = point->x - gui->x_origin;
2108 float py = point->y - gui->y_origin;
2109 float nx = !rotate ? px*xscale : px*ct + py*st;
2110 float ny = !rotate ? py*yscale : py*ct - px*st;
2111 point->x = nx + gui->x_origin;
2112 point->y = ny + gui->y_origin;
2113 px = point->control_x1; py = point->control_y1;
2114 point->control_x1 = !rotate ? px*xscale : px*ct + py*st;
2115 point->control_y1 = !rotate ? py*yscale : py*ct - px*st;
2116 px = point->control_x2; py = point->control_y2;
2117 point->control_x2 = !rotate ? px*xscale : px*ct + py*st;
2118 point->control_y2 = !rotate ? py*yscale : py*ct - px*st;
2127 if( !(rerender && redraw) && (!EQUIV(last_x, point->x) ||
2128 !EQUIV(last_y, point->y) ||
2129 !EQUIV(last_control_x1, point->control_x1) ||
2130 !EQUIV(last_control_y1, point->control_y1) ||
2131 !EQUIV(last_control_x2, point->control_x2) ||
2132 !EQUIV(last_control_y2, point->control_y2)) ) {
2138 if( gui->current_operation == CWINDOW_NONE ) {
2139 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
2141 for( int i = 0; i < points.size() && !over_point; i++ ) {
2142 MaskPoint *point = points.get(i);
2143 float x0 = point->x;
2144 float y0 = point->y;
2145 float x1 = point->x + point->control_x1;
2146 float y1 = point->y + point->control_y1;
2147 float x2 = point->x + point->control_x2;
2148 float y2 = point->y + point->control_y2;
2149 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
2150 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
2152 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
2153 if( test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0) ) {
2157 if( !over_point && gui->ctrl_down() ) {
2158 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
2159 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
2160 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2161 if( test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1) ) {
2165 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2166 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2167 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2168 if( test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2) ) {
2175 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2180 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2183 #ifdef USE_KEYFRAME_SPANNING
2184 // Must commit change after operation.
2185 if( rerender && track ) {
2186 // Swap EDL keyframe with original.
2187 // Apply new values to keyframe span
2188 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2189 temp_keyframe.copy_data(gui->mask_keyframe);
2190 // Apply interpolated points back to keyframe
2192 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2193 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2194 mask_autos->update_parameter(&temp_keyframe);
2197 //printf("CWindowCanvas::do_mask 20\n");
2199 if( draw && draw_boundary && !draw_markers ) {
2200 BC_WindowBase *cvs_win = get_canvas();
2201 cvs_win->set_inverse();
2202 cvs_win->set_color(RED+GREEN);
2203 for( int k=0; k<SUBMASKS; ++k ) {
2204 if( k == mwindow->edl->session->cwindow_mask ) continue;
2205 points.remove_all_objects();
2206 if( use_interpolated )
2207 mask_autos->get_points(&points, k, position, PLAY_FORWARD);
2209 prev_mask->get_points(&points, k);
2211 edge.load(points, 0);
2212 for( int i=0; i<edge.size(); ++i ) {
2213 MaskCoord a = edge[i];
2214 MaskCoord b = i<edge.size()-1 ? edge[i+1] : edge[0];
2215 float ax = a.x, ay = a.y;
2216 float bx = b.x, by = b.y;
2217 output_to_canvas(mwindow->edl, 0, ax, ay);
2218 output_to_canvas(mwindow->edl, 0, bx, by);
2219 cvs_win->draw_line(ax,ay, bx,by);
2227 int CWindowCanvas::do_mask_focus()
2229 Track *track = gui->cwindow->calculate_affected_track();
2230 int64_t position = track->to_units(
2231 mwindow->edl->local_session->get_selectionstart(1),
2233 float projector_x, projector_y, projector_z;
2234 track->automation->get_projector(
2235 &projector_x, &projector_y, &projector_z,
2236 position, PLAY_FORWARD);
2237 float cx = get_cursor_x(), cy = get_cursor_y();
2238 canvas_to_output(mwindow->edl, 0, cx, cy);
2239 projector_x += mwindow->edl->session->output_w / 2;
2240 projector_y += mwindow->edl->session->output_h / 2;
2241 float half_track_w = (float)track->track_w / 2;
2242 float half_track_h = (float)track->track_h / 2;
2243 cx = (cx - projector_x) / projector_z + half_track_w;
2244 cy = (cy - projector_y) / projector_z + half_track_h;
2245 CWindowMaskGUI *mask_gui = (CWindowMaskGUI*) gui->tool_panel->tool_gui;
2246 mask_gui->set_focused(1, cx, cy);
2250 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2253 int radius = mwindow->edl->session->eyedrop_radius;
2261 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
2264 row1 = gui->eyedrop_y - radius;
2265 row2 = gui->eyedrop_y + radius;
2266 column1 = gui->eyedrop_x - radius;
2267 column2 = gui->eyedrop_x + radius;
2269 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2270 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2271 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2272 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2274 if( row2 <= row1 ) row2 = row1 + 1;
2275 if( column2 <= column1 ) column2 = column1 + 1;
2282 output_to_canvas(mwindow->edl, 0, x1, y1);
2283 output_to_canvas(mwindow->edl, 0, x2, y2);
2284 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2286 if( x2 - x1 >= 1 && y2 - y1 >= 1 ) {
2287 get_canvas()->set_inverse();
2288 get_canvas()->set_color(WHITE);
2290 get_canvas()->draw_rectangle((int)x1,
2295 get_canvas()->set_opaque();
2296 get_canvas()->flash();
2302 if( button_press ) {
2303 gui->current_operation = CWINDOW_EYEDROP;
2304 gui->tool_panel->raise_window();
2307 if( gui->current_operation == CWINDOW_EYEDROP ) {
2308 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2310 // Get color out of frame.
2311 // Doesn't work during playback because that bypasses the refresh frame.
2312 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
2313 float cursor_x = get_cursor_x();
2314 float cursor_y = get_cursor_y();
2315 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2316 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2317 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2319 row1 = cursor_y - radius;
2320 row2 = cursor_y + radius;
2321 column1 = cursor_x - radius;
2322 column2 = cursor_x + radius;
2323 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2324 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2325 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2326 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2327 if( row2 <= row1 ) row2 = row1 + 1;
2328 if( column2 <= column1 ) column2 = column1 + 1;
2332 if( gui->eyedrop_visible ) {
2334 do_eyedrop(temp, 0, 1);
2335 gui->eyedrop_visible = 0;
2338 gui->eyedrop_x = cursor_x;
2339 gui->eyedrop_y = cursor_y;
2344 do_eyedrop(temp, 0, 1);
2345 gui->eyedrop_visible = 1;
2348 // Decompression coefficients straight out of jpeglib
2349 #define V_TO_R 1.40200
2350 #define V_TO_G -0.71414
2352 #define U_TO_G -0.34414
2353 #define U_TO_B 1.77200
2355 #define GET_COLOR(type, components, max, do_yuv) \
2357 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2359 float red = (float)*row++ / max; \
2360 float green = (float)*row++ / max; \
2361 float blue = (float)*row++ / max; \
2364 float r = red + V_TO_R * (blue - 0.5); \
2365 float g = red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
2366 float b = red + U_TO_B * (green - 0.5); \
2367 mwindow->edl->local_session->red += r; \
2368 mwindow->edl->local_session->green += g; \
2369 mwindow->edl->local_session->blue += b; \
2370 if( r > mwindow->edl->local_session->red_max ) mwindow->edl->local_session->red_max = r; \
2371 if( g > mwindow->edl->local_session->green_max ) mwindow->edl->local_session->green_max = g; \
2372 if( b > mwindow->edl->local_session->blue_max ) mwindow->edl->local_session->blue_max = b; \
2376 mwindow->edl->local_session->red += red; \
2377 mwindow->edl->local_session->green += green; \
2378 mwindow->edl->local_session->blue += blue; \
2379 if( red > mwindow->edl->local_session->red_max ) mwindow->edl->local_session->red_max = red; \
2380 if( green > mwindow->edl->local_session->green_max ) mwindow->edl->local_session->green_max = green; \
2381 if( blue > mwindow->edl->local_session->blue_max ) mwindow->edl->local_session->blue_max = blue; \
2387 mwindow->edl->local_session->red = 0;
2388 mwindow->edl->local_session->green = 0;
2389 mwindow->edl->local_session->blue = 0;
2390 mwindow->edl->local_session->red_max = 0;
2391 mwindow->edl->local_session->green_max = 0;
2392 mwindow->edl->local_session->blue_max = 0;
2393 for( int i = row1; i < row2; i++ ) {
2394 for( int j = column1; j < column2; j++ ) {
2395 switch( refresh_frame->get_color_model() )
2398 GET_COLOR(unsigned char, 3, 0xff, 1);
2401 GET_COLOR(unsigned char, 4, 0xff, 1);
2404 GET_COLOR(uint16_t, 3, 0xffff, 1);
2406 case BC_YUVA16161616:
2407 GET_COLOR(uint16_t, 4, 0xffff, 1);
2410 GET_COLOR(unsigned char, 3, 0xff, 0);
2413 GET_COLOR(unsigned char, 4, 0xff, 0);
2416 GET_COLOR(float, 3, 1.0, 0);
2419 GET_COLOR(float, 4, 1.0, 0);
2425 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2426 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2427 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2431 mwindow->edl->local_session->red = 0;
2432 mwindow->edl->local_session->green = 0;
2433 mwindow->edl->local_session->blue = 0;
2434 gui->eyedrop_visible = 0;
2443 // Can't rerender since the color value is from the output of any effect it
2446 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2452 int CWindowCanvas::need_overlays()
2454 if( mwindow->edl->session->safe_regions ) return 1;
2455 if( mwindow->edl->session->cwindow_scrollbars ) return 1;
2456 if( gui->highlighted ) return 1;
2457 switch( mwindow->edl->session->cwindow_operation ) {
2458 case CWINDOW_EYEDROP:
2459 if( ! gui->eyedrop_visible ) break;
2460 case CWINDOW_CAMERA:
2461 case CWINDOW_PROJECTOR:
2470 void CWindowCanvas::draw_overlays()
2472 if( mwindow->edl->session->safe_regions ) {
2473 draw_safe_regions();
2476 if( mwindow->edl->session->cwindow_scrollbars ) {
2477 // Always draw output rectangle
2478 float x1, y1, x2, y2;
2480 x2 = mwindow->edl->session->output_w;
2482 y2 = mwindow->edl->session->output_h;
2483 output_to_canvas(mwindow->edl, 0, x1, y1);
2484 output_to_canvas(mwindow->edl, 0, x2, y2);
2486 get_canvas()->set_inverse();
2487 get_canvas()->set_color(WHITE);
2488 int ix1 = x1-1, iy1 = y1-1, ix2 = x2+1, iy2 = y2+1;
2489 get_canvas()->draw_rectangle(ix1, iy1, ix2-ix1, iy2-iy1);
2490 get_canvas()->set_opaque();
2493 if( gui->highlighted ) {
2494 get_canvas()->set_color(WHITE);
2495 get_canvas()->set_inverse();
2496 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2497 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2498 get_canvas()->set_opaque();
2501 int temp1 = 0, temp2 = 0;
2502 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2503 switch( mwindow->edl->session->cwindow_operation )
2505 case CWINDOW_CAMERA:
2509 case CWINDOW_PROJECTOR:
2518 do_mask(temp1, temp2, 0, 0, 1);
2522 do_ruler(1, 0, 0, 0);
2525 case CWINDOW_EYEDROP:
2526 if( gui->eyedrop_visible ) {
2528 do_eyedrop(rerender, 0, 1);
2529 gui->eyedrop_visible = 1;
2535 void CWindowCanvas::draw_safe_regions()
2537 float action_x1, action_x2, action_y1, action_y2;
2538 float title_x1, title_x2, title_y1, title_y2;
2540 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2541 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2542 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2543 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2544 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2545 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2546 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2547 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2549 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2550 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2551 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2552 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2554 get_canvas()->set_inverse();
2555 get_canvas()->set_color(WHITE);
2557 get_canvas()->draw_rectangle((int)action_x1,
2559 (int)(action_x2 - action_x1),
2560 (int)(action_y2 - action_y1));
2561 get_canvas()->draw_rectangle((int)title_x1,
2563 (int)(title_x2 - title_x1),
2564 (int)(title_y2 - title_y1));
2566 get_canvas()->set_opaque();
2570 void CWindowCanvas::create_keyframe(int do_camera)
2572 Track *affected_track = gui->cwindow->calculate_affected_track();
2573 if( affected_track ) {
2574 double pos = mwindow->edl->local_session->get_selectionstart(1);
2575 int64_t position = affected_track->to_units(pos, 0);
2576 int ix = do_camera ? AUTOMATION_CAMERA_X : AUTOMATION_PROJECTOR_X;
2577 int iy = do_camera ? AUTOMATION_CAMERA_Y : AUTOMATION_PROJECTOR_Y;
2578 int iz = do_camera ? AUTOMATION_CAMERA_Z : AUTOMATION_PROJECTOR_Z;
2579 FloatAuto *prev, *next;
2580 FloatAutos **autos = (FloatAutos**)affected_track->automation->autos;
2581 FloatAutos *x_autos = autos[ix]; prev = 0; next = 0;
2582 float x_value = x_autos->get_value(position, PLAY_FORWARD, prev, next);
2583 FloatAutos *y_autos = autos[iy]; prev = 0; next = 0;
2584 float y_value = y_autos->get_value(position, PLAY_FORWARD, prev, next);
2585 FloatAutos *z_autos = autos[iz]; prev = 0; next = 0;
2586 float z_value = z_autos->get_value(position, PLAY_FORWARD, prev, next);
2587 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2589 gui->cwindow->calculate_affected_autos(affected_track,
2590 &x_keyframe, &y_keyframe, &z_keyframe,
2591 do_camera, -1, -1, -1, 0);
2592 x_keyframe->set_value(x_value);
2593 y_keyframe->set_value(y_value);
2594 z_keyframe->set_value(z_value);
2596 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2600 void CWindowCanvas::camera_keyframe() { create_keyframe(1); }
2601 void CWindowCanvas::projector_keyframe() { create_keyframe(0); }
2603 void CWindowCanvas::reset_keyframe(int do_camera)
2605 Track *affected_track = gui->cwindow->calculate_affected_track();
2606 if( affected_track ) {
2607 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2608 gui->cwindow->calculate_affected_autos(affected_track,
2609 &x_keyframe, &y_keyframe, &z_keyframe,
2610 do_camera, 1, 1, 1);
2612 x_keyframe->set_value(0);
2613 y_keyframe->set_value(0);
2614 z_keyframe->set_value(1);
2616 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2620 void CWindowCanvas::reset_camera() { reset_keyframe(1); }
2621 void CWindowCanvas::reset_projector() { reset_keyframe(0); }
2624 int CWindowCanvas::test_crop(int button_press, int &redraw)
2627 int handle_selected = -1;
2628 float x1 = mwindow->edl->session->crop_x1;
2629 float y1 = mwindow->edl->session->crop_y1;
2630 float x2 = mwindow->edl->session->crop_x2;
2631 float y2 = mwindow->edl->session->crop_y2;
2632 float cursor_x = get_cursor_x();
2633 float cursor_y = get_cursor_y();
2634 float canvas_x1 = x1;
2635 float canvas_y1 = y1;
2636 float canvas_x2 = x2;
2637 float canvas_y2 = y2;
2638 float canvas_cursor_x = cursor_x;
2639 float canvas_cursor_y = cursor_y;
2641 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2642 // Use screen normalized coordinates for hot spot tests.
2643 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2644 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2647 if( gui->current_operation == CWINDOW_CROP ) {
2648 handle_selected = gui->crop_handle;
2651 if( canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2652 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H ) {
2653 handle_selected = 0;
2654 gui->crop_origin_x = x1;
2655 gui->crop_origin_y = y1;
2658 if( canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2659 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H ) {
2660 handle_selected = 1;
2661 gui->crop_origin_x = x2;
2662 gui->crop_origin_y = y1;
2665 if( canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2666 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2 ) {
2667 handle_selected = 2;
2668 gui->crop_origin_x = x1;
2669 gui->crop_origin_y = y2;
2672 if( canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2673 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2 ) {
2674 handle_selected = 3;
2675 gui->crop_origin_x = x2;
2676 gui->crop_origin_y = y2;
2681 gui->crop_origin_x = cursor_x;
2682 gui->crop_origin_y = cursor_y;
2685 // printf("test crop %d %d\n",
2686 // gui->current_operation,
2687 // handle_selected);
2690 if( button_press ) {
2691 if( gui->alt_down() ) {
2692 gui->crop_translate = 1;
2693 gui->crop_origin_x1 = x1;
2694 gui->crop_origin_y1 = y1;
2695 gui->crop_origin_x2 = x2;
2696 gui->crop_origin_y2 = y2;
2699 gui->crop_translate = 0;
2701 gui->current_operation = CWINDOW_CROP;
2702 gui->crop_handle = handle_selected;
2703 gui->x_origin = cursor_x;
2704 gui->y_origin = cursor_y;
2705 gui->tool_panel->raise_window();
2708 if( handle_selected < 0 && !gui->crop_translate ) {
2711 mwindow->edl->session->crop_x1 = (int)x1;
2712 mwindow->edl->session->crop_y1 = (int)y1;
2713 mwindow->edl->session->crop_x2 = (int)x2;
2714 mwindow->edl->session->crop_y2 = (int)y2;
2719 // Translate all 4 points
2720 if( gui->current_operation == CWINDOW_CROP && gui->crop_translate ) {
2721 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2722 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2723 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2724 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2726 mwindow->edl->session->crop_x1 = (int)x1;
2727 mwindow->edl->session->crop_y1 = (int)y1;
2728 mwindow->edl->session->crop_x2 = (int)x2;
2729 mwindow->edl->session->crop_y2 = (int)y2;
2735 if( gui->current_operation == CWINDOW_CROP ) {
2736 switch( gui->crop_handle ) {
2738 x1 = gui->crop_origin_x;
2739 y1 = gui->crop_origin_y;
2740 x2 = gui->crop_origin_x;
2741 y2 = gui->crop_origin_y;
2742 if( cursor_x < gui->x_origin ) {
2743 if( cursor_y < gui->y_origin ) {
2748 if( cursor_y >= gui->y_origin ) {
2754 if( cursor_x >= gui->x_origin ) {
2755 if( cursor_y < gui->y_origin ) {
2760 if( cursor_y >= gui->y_origin ) {
2766 // printf("test crop %d %d %d %d\n",
2767 // mwindow->edl->session->crop_x1,
2768 // mwindow->edl->session->crop_y1,
2769 // mwindow->edl->session->crop_x2,
2770 // mwindow->edl->session->crop_y2);
2773 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2774 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2777 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2778 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2781 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2782 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2785 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2786 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2790 if( !EQUIV(mwindow->edl->session->crop_x1, x1) ||
2791 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2792 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2793 !EQUIV(mwindow->edl->session->crop_y2, y2) ) {
2798 switch( gui->crop_handle ) {
2799 case 0: gui->crop_handle = 1; break;
2800 case 1: gui->crop_handle = 0; break;
2801 case 2: gui->crop_handle = 3; break;
2802 case 3: gui->crop_handle = 2; break;
2811 switch( gui->crop_handle ) {
2812 case 0: gui->crop_handle = 2; break;
2813 case 1: gui->crop_handle = 3; break;
2814 case 2: gui->crop_handle = 0; break;
2815 case 3: gui->crop_handle = 1; break;
2820 mwindow->edl->session->crop_x1 = (int)x1;
2821 mwindow->edl->session->crop_y1 = (int)y1;
2822 mwindow->edl->session->crop_x2 = (int)x2;
2823 mwindow->edl->session->crop_y2 = (int)y2;
2829 // Update cursor font
2830 if( handle_selected >= 0 ) {
2831 switch( handle_selected ) {
2832 case 0: set_cursor(UPLEFT_RESIZE); break;
2833 case 1: set_cursor(UPRIGHT_RESIZE); break;
2834 case 2: set_cursor(DOWNLEFT_RESIZE); break;
2835 case 3: set_cursor(DOWNRIGHT_RESIZE); break;
2840 set_cursor(ARROW_CURSOR);
2842 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2845 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2846 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2847 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2848 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2849 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2850 // mwindow->edl->session->crop_x2,
2851 // mwindow->edl->session->crop_y2,
2852 // mwindow->edl->calculate_output_w(0),
2853 // mwindow->edl->calculate_output_h(0));
2859 void CWindowCanvas::draw_crop()
2861 get_canvas()->set_inverse();
2862 get_canvas()->set_color(WHITE);
2864 float x1 = mwindow->edl->session->crop_x1;
2865 float y1 = mwindow->edl->session->crop_y1;
2866 float x2 = mwindow->edl->session->crop_x2;
2867 float y2 = mwindow->edl->session->crop_y2;
2869 output_to_canvas(mwindow->edl, 0, x1, y1);
2870 output_to_canvas(mwindow->edl, 0, x2, y2);
2872 if( x2 - x1 && y2 - y1 )
2873 get_canvas()->draw_rectangle((int)x1,
2878 draw_crophandle((int)x1, (int)y1);
2879 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2880 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2881 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2882 get_canvas()->set_opaque();
2886 void CWindowCanvas::draw_outlines(int do_camera)
2888 Track *track = gui->cwindow->calculate_affected_track();
2890 if( !track ) return;
2892 float proj_x, proj_y, proj_z;
2893 int64_t position = track->to_units(
2894 mwindow->edl->local_session->get_selectionstart(1),
2896 track->automation->get_projector(&proj_x, &proj_y, &proj_z,
2897 position, PLAY_FORWARD);
2899 proj_x += mwindow->edl->session->output_w/2.;
2900 proj_y += mwindow->edl->session->output_h/2.;
2901 float proj_x1 = proj_x - track->track_w/2. * proj_z;
2902 float proj_y1 = proj_y - track->track_h/2. * proj_z;
2903 float proj_x2 = proj_x + track->track_w/2. * proj_z;
2904 float proj_y2 = proj_y + track->track_h/2. * proj_z;
2905 float x1 = proj_x1, x2 = proj_x2;
2906 float y1 = proj_y1, y2 = proj_y2;
2907 output_to_canvas(mwindow->edl, 0, x1, y1);
2908 output_to_canvas(mwindow->edl, 0, x2, y2);
2910 #define DRAW_PROJECTION(offset) \
2911 get_canvas()->draw_rectangle(x1+offset, y1+offset, (x2-x1), (y2-y1)); \
2912 get_canvas()->draw_line(x1+offset, y1+offset, x2+offset, y2+offset); \
2913 get_canvas()->draw_line(x2+offset, y1+offset, x1+offset, y2+offset); \
2916 get_canvas()->set_color(BLACK);
2918 get_canvas()->set_color(do_camera ? GREEN : RED);
2922 float cam_x, cam_y, cam_z;
2923 track->automation->get_camera(&cam_x, &cam_y, &cam_z,
2924 position, PLAY_FORWARD);
2925 cam_x += track->track_w / 2.;
2926 cam_y += track->track_h / 2.;
2927 // follow image, not camera
2928 cam_x = -cam_x; cam_y = -cam_y; cam_z *= proj_z;
2929 float cam_x1 = cam_x * cam_z + proj_x;
2930 float cam_y1 = cam_y * cam_z + proj_y;
2931 float cam_x2 = (cam_x + track->track_w) * cam_z + proj_x;
2932 float cam_y2 = (cam_y + track->track_h) * cam_z + proj_y;
2933 output_to_canvas(mwindow->edl, 0, cam_x1, cam_y1);
2934 output_to_canvas(mwindow->edl, 0, cam_x2, cam_y2);
2935 get_canvas()->set_color(YELLOW);
2936 get_canvas()->draw_rectangle(cam_x1, cam_y1, cam_x2-cam_x1, cam_y2-cam_y1);
2940 int CWindowCanvas::test_bezier(int button_press,
2948 // Processing drag operation.
2949 // Create keyframe during first cursor motion.
2950 if( !button_press ) {
2952 float cursor_x = get_cursor_x();
2953 float cursor_y = get_cursor_y();
2954 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2956 if( gui->current_operation == CWINDOW_CAMERA ||
2957 gui->current_operation == CWINDOW_PROJECTOR ) {
2958 if( !gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom ) {
2959 gui->translating_zoom = 1;
2960 gui->reset_affected();
2962 else if( !gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom ) {
2963 gui->translating_zoom = 0;
2964 gui->reset_affected();
2967 // Get target keyframe
2968 if( !gui->affected_x && !gui->affected_y && !gui->affected_z ) {
2969 if( !gui->affected_track ) return 0;
2970 FloatAutos *affected_x_autos, *affected_y_autos, *affected_z_autos;
2971 FloatAutos** autos = (FloatAutos**) gui->affected_track->automation->autos;
2972 if( mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA ) {
2973 affected_x_autos = autos[AUTOMATION_CAMERA_X];
2974 affected_y_autos = autos[AUTOMATION_CAMERA_Y];
2975 affected_z_autos = autos[AUTOMATION_CAMERA_Z];
2978 affected_x_autos = autos[AUTOMATION_PROJECTOR_X];
2979 affected_y_autos = autos[AUTOMATION_PROJECTOR_Y];
2980 affected_z_autos = autos[AUTOMATION_PROJECTOR_Z];
2982 double position = mwindow->edl->local_session->get_selectionstart(1);
2983 int64_t track_position = gui->affected_track->to_units(position, 0);
2984 FloatAuto *prev_x = 0, *next_x = 0;
2985 float new_x = affected_x_autos->get_value(track_position, PLAY_FORWARD, prev_x, next_x);
2986 FloatAuto *prev_y = 0, *next_y = 0;
2987 float new_y = affected_y_autos->get_value(track_position, PLAY_FORWARD, prev_y, next_y);
2988 FloatAuto *prev_z = 0, *next_z = 0;
2989 float new_z = affected_z_autos->get_value(track_position, PLAY_FORWARD, prev_z, next_z);
2990 int zooming = gui->translating_zoom, created;
2991 gui->affected_x = (FloatAuto*)gui->cwindow->calculate_affected_auto(
2992 affected_x_autos, !zooming, &created, 0);
2994 gui->affected_x->set_value(new_x);
2997 gui->affected_y = (FloatAuto*)gui->cwindow->calculate_affected_auto(
2998 affected_y_autos, !zooming, &created, 0);
3000 gui->affected_y->set_value(new_y);
3003 gui->affected_z = (FloatAuto*)gui->cwindow->calculate_affected_auto(
3004 affected_z_autos, zooming, &created, 0);
3006 gui->affected_z->set_value(new_z);
3011 if( gui->translating_zoom ) {
3012 gui->center_z = gui->affected_z->get_value();
3015 gui->center_x = gui->affected_x->get_value();
3016 gui->center_y = gui->affected_y->get_value();
3023 float x_val = gui->affected_x->get_value();
3024 float y_val = gui->affected_y->get_value();
3025 float z_val = gui->affected_z->get_value();
3027 if( gui->translating_zoom ) {
3028 float z = gui->center_z + (cursor_y - gui->y_origin) / yS(128);
3030 if( !EQUIV(z_val, z) ) {
3035 gui->affected_z->set_value(z);
3038 float dx = cursor_x - gui->x_origin;
3039 float dy = cursor_y - gui->y_origin;
3040 // follow image, not camera
3041 if( gui->current_operation == CWINDOW_CAMERA ) {
3042 dx = -dx / z_val; dy = -dy / z_val;
3044 float x = gui->center_x + dx;
3045 float y = gui->center_y + dy;
3046 gui->affected_x->set_value(x);
3047 gui->affected_y->set_value(y);
3048 if( !EQUIV(x_val, x) || !EQUIV(y_val, y) ) {
3059 // Begin drag operation. Don't create keyframe here.
3061 // Get affected track off of the first recordable video track.
3062 // Calculating based on the alpha channel would require recording what layer
3063 // each output pixel belongs to as they're rendered and stacked. Forget it.
3064 gui->affected_track = gui->cwindow->calculate_affected_track();
3065 gui->reset_affected();
3067 if( gui->affected_track ) {
3069 mwindow->undo->update_undo_before(_("camera"), this);
3071 mwindow->undo->update_undo_before(_("projector"), this);
3073 gui->current_operation =
3074 mwindow->edl->session->cwindow_operation;
3075 gui->tool_panel->raise_window();
3083 int CWindowCanvas::test_zoom(int &redraw)
3086 int button = get_buttonpress();
3087 if( button == LEFT_BUTTON )
3088 button = gui->shift_down() ? WHEEL_DOWN : WHEEL_UP;
3089 if( !(zoom = get_zoom()) )
3090 zoom = get_auto_zoom(mwindow->edl);
3094 for( ; idx < total_zooms; ++idx ) {
3095 if( EQUIV(zoom, my_zoom_table[idx]) ) continue;
3096 if( zoom < my_zoom_table[idx] ) break;
3098 float zoom11 = 1.1f * zoom;
3099 zoom = idx < total_zooms ? my_zoom_table[idx] : zoom11;
3100 if( zoom > zoom11 ) zoom = zoom11;
3103 int idx = total_zooms;
3104 for( ; --idx >= 0; ) {
3105 if( EQUIV(my_zoom_table[idx], zoom) ) continue;
3106 if( my_zoom_table[idx] < zoom ) break;
3108 float zoom09 = 0.9f * zoom;
3109 zoom = idx >= 0 ? my_zoom_table[idx] : zoom09;
3110 if( zoom < zoom09 ) zoom = zoom09;
3113 if( gui->shift_down() ) {
3117 default: // fall thru
3120 float cx = get_cursor_x(), cy = get_cursor_y();
3121 set_zoom(mwindow->edl, zoom, cx, cy);
3122 gui->zoom_panel->update(zoom);
3123 gui->update_canvas();
3129 void CWindowCanvas::calculate_origin()
3131 float zoom_x, zoom_y, conformed_w, conformed_h;
3132 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3133 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3134 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3135 gui->x_origin = (float)get_cursor_x() / zoom_x + gui->x_offset;
3136 gui->y_origin = (float)get_cursor_y() / zoom_y + gui->y_offset;
3140 int CWindowCanvas::cursor_leave_event()
3142 set_cursor(ARROW_CURSOR);
3146 int CWindowCanvas::cursor_enter_event()
3149 switch( mwindow->edl->session->cwindow_operation ) {
3150 case CWINDOW_CAMERA:
3151 case CWINDOW_PROJECTOR:
3152 set_cursor(MOVE_CURSOR);
3155 set_cursor(MOVE_CURSOR);
3158 test_crop(0, redraw);
3160 case CWINDOW_PROTECT:
3161 set_cursor(ARROW_CURSOR);
3165 set_cursor(CROSS_CURSOR);
3167 case CWINDOW_EYEDROP:
3168 set_cursor(CROSS_CURSOR);
3174 int CWindowCanvas::cursor_motion_event()
3176 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3179 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3180 switch( gui->current_operation ) {
3181 case CWINDOW_SCROLL: {
3182 result = do_scroll(mwindow->edl, get_cursor_x(), get_cursor_y());
3186 result = do_ruler(0, 1, 0, 0);
3189 case CWINDOW_CAMERA:
3190 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3193 case CWINDOW_PROJECTOR:
3194 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3198 result = test_crop(0, redraw);
3199 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3200 // __LINE__, result, redraw);
3204 case CWINDOW_MASK_CONTROL_IN:
3205 case CWINDOW_MASK_CONTROL_OUT:
3206 case CWINDOW_MASK_TRANSLATE:
3207 result = do_mask(redraw, rerender, 0, 1, 0);
3210 case CWINDOW_EYEDROP:
3211 result = do_eyedrop(rerender, 0, 0);
3219 // cursor font changes
3221 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3222 // __LINE__, mwindow->edl->session->cwindow_operation);
3223 switch( mwindow->edl->session->cwindow_operation ) {
3225 result = test_crop(0, redraw);
3228 result = do_ruler(0, 1, 0, 0);
3231 result = do_mask(redraw, rerender, 0, 1, 0);
3236 int change_type = rerender ? CHANGE_PARAMS : -1;
3237 gui->sync_parameters(change_type, redraw, redraw_canvas);
3242 int CWindowCanvas::button_press_event()
3246 int redraw_canvas = 0;
3249 if( Canvas::button_press_event() ) return 1;
3251 gui->translating_zoom = gui->shift_down();
3255 if( mwindow->edl->session->cwindow_operation != CWINDOW_PROTECT &&
3256 get_buttonpress() == MIDDLE_BUTTON && !get_canvas()->shift_down() ) {
3257 gui->current_operation = CWINDOW_SCROLL;
3262 switch( mwindow->edl->session->cwindow_operation ) {
3264 result = do_ruler(0, 0, 1, 0);
3267 case CWINDOW_CAMERA:
3268 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3271 case CWINDOW_PROJECTOR:
3272 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3276 result = test_zoom(redraw);
3280 result = test_crop(1, redraw);
3284 switch( get_buttonpress() ) {
3286 result = do_mask(redraw, rerender, 1, 0, 0);
3288 case MIDDLE_BUTTON: { // && shift_down()
3289 result = do_mask_focus();
3290 redraw = redraw_canvas = 1;
3294 result = do_mask(redraw, rerender, 1, 1, 0);
3297 if( result ) redraw_canvas = 1;
3300 case CWINDOW_EYEDROP:
3301 result = do_eyedrop(rerender, 1, 0);
3306 int change_type = rerender ? CHANGE_PARAMS : -1;
3307 gui->sync_parameters(change_type, redraw, redraw_canvas);
3312 int CWindowCanvas::button_release_event()
3315 const char *undo_label = 0;
3317 switch( gui->current_operation ) {
3318 case CWINDOW_SCROLL:
3323 do_ruler(0, 0, 0, 1);
3326 case CWINDOW_CAMERA:
3327 undo_label = _("camera");
3330 case CWINDOW_PROJECTOR:
3331 undo_label = _("projector");
3335 case CWINDOW_MASK_CONTROL_IN:
3336 case CWINDOW_MASK_CONTROL_OUT:
3337 case CWINDOW_MASK_TRANSLATE:
3338 // Finish mask operation
3339 gui->mask_keyframe = 0;
3340 undo_label = _("mask");
3342 case CWINDOW_MASK_ROTATE:
3343 gui->mask_keyframe = 0;
3344 undo_label = _("mask rotate");
3346 case CWINDOW_MASK_SCALE:
3347 gui->mask_keyframe = 0;
3348 undo_label = _("mask scale");
3351 result = Canvas::button_release_event();
3356 mwindow->undo->update_undo_after(undo_label, LOAD_AUTOMATION);
3357 gui->current_operation = CWINDOW_NONE;
3361 void CWindowCanvas::zoom_resize_window(float percentage)
3363 int canvas_w, canvas_h;
3366 // Get required canvas size
3367 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3368 mwindow->edl->session->output_w,
3369 mwindow->edl->session->output_h,
3370 percentage, canvas_w, canvas_h);
3372 // Estimate window size from current borders
3373 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3374 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3376 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3377 mwindow->session->cwindow_w = new_w;
3378 mwindow->session->cwindow_h = new_h;
3380 mwindow->theme->get_cwindow_sizes(gui,
3381 mwindow->session->cwindow_controls);
3383 // Estimate again from new borders
3384 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3385 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3386 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3388 gui->resize_window(new_w, new_h);
3389 gui->resize_event(new_w, new_h);
3392 void CWindowCanvas::toggle_controls()
3394 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3395 gui->resize_event(gui->get_w(), gui->get_h());
3398 int CWindowCanvas::get_cwindow_controls()
3400 return mwindow->session->cwindow_controls;
3403 int CWindowCanvas::get_clear_color()
3405 int color = mwindow->edl->session->cwindow_clear_color;
3406 if( color < 0 ) color = Canvas::get_clear_color();