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"
25 #include "bcsignals.h"
29 #include "cplayback.h"
32 #include "cwindowgui.h"
34 #include "cwindowtool.h"
35 #include "editpanel.h"
37 #include "edlsession.h"
38 #include "floatauto.h"
39 #include "floatautos.h"
42 #include "localsession.h"
43 #include "mainclock.h"
46 #include "mainsession.h"
48 #include "maskautos.h"
50 #include "meterpanel.h"
51 #include "mwindowgui.h"
54 #include "playback3d.h"
55 #include "playtransport.h"
57 #include "trackcanvas.h"
59 #include "transportque.h"
64 static double my_zoom_table[] =
77 static int total_zooms = sizeof(my_zoom_table) / sizeof(double);
80 CWindowGUI::CWindowGUI(MWindow *mwindow, CWindow *cwindow)
81 : BC_Window(_(PROGRAM_NAME ": Compositor"),
82 mwindow->session->cwindow_x,
83 mwindow->session->cwindow_y,
84 mwindow->session->cwindow_w,
85 mwindow->session->cwindow_h,
86 xS(100), yS(100), 1, 1, 1,
87 BC_WindowBase::get_resources()->bg_color,
88 mwindow->get_cwindow_display())
90 this->mwindow = mwindow;
91 this->cwindow = cwindow;
93 affected_x = affected_y = affected_z = 0;
95 orig_mask_keyframe = new MaskAuto(0, 0);
97 x_offset = y_offset = 0;
98 x_origin = y_origin = 0;
99 current_operation = CWINDOW_NONE;
103 crop_handle = -1; crop_translate = 0;
104 crop_origin_x = crop_origin_y = 0;
105 crop_origin_x1 = crop_origin_y1 = 0;
106 crop_origin_x2 = crop_origin_y2 = 0;
108 eyedrop_x = eyedrop_y = 0;
109 ruler_origin_x = ruler_origin_y = 0;
110 ruler_handle = -1; ruler_translate = 0;
111 center_x = center_y = center_z = 0;
112 control_in_x = control_in_y = 0;
113 control_out_x = control_out_y = 0;
114 translating_zoom = 0;
118 CWindowGUI::~CWindowGUI()
120 cwindow->stop_playback(1);
121 if( tool_panel ) delete tool_panel;
123 delete composite_panel;
131 delete orig_mask_keyframe;
134 void CWindowGUI::create_objects()
136 lock_window("CWindowGUI::create_objects");
137 set_icon(mwindow->theme->get_image("cwindow_icon"));
139 active = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_active"));
140 inactive = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_inactive"));
141 focus_frame = new VFramePng(mwindow->theme->get_image_data("cwindow_focus.png"));
143 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
144 mwindow->theme->draw_cwindow_bg(this);
147 // Meters required by composite panel
148 meters = new CWindowMeters(mwindow,
150 mwindow->theme->cmeter_x,
151 mwindow->theme->cmeter_y,
152 mwindow->theme->cmeter_h);
153 meters->create_objects();
156 composite_panel = new CPanel(mwindow,
158 mwindow->theme->ccomposite_x,
159 mwindow->theme->ccomposite_y,
160 mwindow->theme->ccomposite_w,
161 mwindow->theme->ccomposite_h);
162 composite_panel->create_objects();
164 canvas = new CWindowCanvas(mwindow, this);
166 canvas->create_objects(mwindow->edl);
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()->cursor_above() ) {
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
765 this->mwindow = mwindow;
766 this->cwindow = cwindow;
769 #define relock_cm(s) \
770 cwindow->gui->unlock_window(); \
771 mwindow->gui->lock_window("CWindowEditing::" s)
772 #define relock_mc(s) \
773 mwindow->gui->unlock_window(); \
774 cwindow->gui->lock_window("CWindowEditing::" s)
775 #define panel_fn(fn, args, s) \
776 CWindowEditing::fn args { relock_cm(#fn); s; relock_mc(#fn); }
778 // transmit lock to mwindow, and run mbutton->edit_panel->s
779 #define panel_btn(fn, args, s) \
780 panel_fn(panel_##fn, args, mwindow->gui->mbuttons->edit_panel->panel_##s)
783 double CWindowEditing::get_position()
785 relock_cm("get_position");
786 double ret = mwindow->edl->local_session->get_selectionstart(1);
787 relock_mc("get_position");
791 void CWindowEditing::set_position(double position)
793 relock_cm("set_position");
794 mwindow->gui->mbuttons->edit_panel->set_position(position);
795 relock_mc("set_position");
798 void CWindowEditing::set_click_to_play(int v)
800 relock_cm("set_position");
801 mwindow->edl->session->cwindow_click2play = v;
802 relock_mc("set_position");
803 click2play->update(v);
807 void panel_btn(stop_transport,(), stop_transport())
808 void panel_btn(toggle_label,(), toggle_label())
809 void panel_btn(next_label,(int cut), next_label(cut))
810 void panel_btn(prev_label,(int cut), prev_label(cut))
811 void panel_btn(next_edit,(int cut), next_edit(cut))
812 void panel_btn(prev_edit,(int cut), prev_edit(cut))
813 void panel_fn(panel_copy_selection,(), mwindow->copy())
814 void CWindowEditing::panel_overwrite_selection() {} // not used
815 void CWindowEditing::panel_splice_selection() {} // not used
816 void panel_btn(set_inpoint,(), set_inpoint())
817 void panel_btn(set_outpoint,(), set_outpoint())
818 void panel_btn(unset_inoutpoint,(), unset_inoutpoint())
819 void panel_fn(panel_to_clip,(), mwindow->to_clip(mwindow->edl, _("main window: "), 0))
820 void panel_btn(cut,(), cut())
821 void panel_btn(paste,(), paste())
822 void panel_btn(fit_selection,(), fit_selection())
823 void panel_btn(fit_autos,(int all), fit_autos(all))
824 void panel_btn(set_editing_mode,(int mode), set_editing_mode(mode))
825 void panel_btn(set_auto_keyframes,(int v), set_auto_keyframes(v))
826 void panel_btn(set_span_keyframes,(int v), set_span_keyframes(v))
827 void panel_btn(set_labels_follow_edits,(int v), set_labels_follow_edits(v))
830 CWindowMeters::CWindowMeters(MWindow *mwindow,
831 CWindowGUI *gui, int x, int y, int h)
832 : MeterPanel(mwindow, gui, x, y, -1, h,
833 mwindow->edl->session->audio_channels,
834 mwindow->edl->session->cwindow_meter,
837 this->mwindow = mwindow;
841 CWindowMeters::~CWindowMeters()
845 int CWindowMeters::change_status_event(int new_status)
847 mwindow->edl->session->cwindow_meter = new_status;
848 gui->update_meters();
855 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
856 : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
857 x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
859 this->mwindow = mwindow;
863 CWindowZoom::~CWindowZoom()
867 void CWindowZoom::update(double value)
869 char string[BCSTRLEN];
870 const char *cp = string;
873 int frac = value >= 1.0f ? 1 :
875 value >= .01f ? 3 : 4;
876 sprintf(string, "x %.*f", frac, value);
880 ZoomPanel::update(cp);
883 int CWindowZoom::handle_event()
885 double value = !strcasecmp(gui->auto_zoom, get_text()) ? 0 : get_value();
886 gui->canvas->set_zoom(mwindow->edl, value);
887 gui->update_canvas();
894 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
895 : BC_PercentageSlider(x, y, 0, pixels, pixels, 0, 1, 0)
897 this->mwindow = mwindow;
898 this->cwindow = cwindow;
899 set_precision(0.00001);
902 CWindowSlider::~CWindowSlider()
906 int CWindowSlider::handle_event()
908 cwindow->update_position((double)get_value());
912 void CWindowSlider::set_position()
914 double new_length = mwindow->edl->tracks->total_length();
915 update(mwindow->theme->cslider_w,
916 mwindow->edl->local_session->get_selectionstart(1),
921 int CWindowSlider::increase_value()
924 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
925 lock_window("CWindowSlider::increase_value");
929 int CWindowSlider::decrease_value()
932 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
933 lock_window("CWindowSlider::decrease_value");
939 CWindowTransport::CWindowTransport(MWindow *mwindow,
940 CWindowGUI *gui, int x, int y)
941 : PlayTransport(mwindow, gui, x, y)
946 EDL* CWindowTransport::get_edl()
951 void CWindowTransport::goto_start()
953 gui->unlock_window();
954 handle_transport(REWIND, 1);
956 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
957 mwindow->goto_start();
958 mwindow->gui->unlock_window();
960 gui->lock_window("CWindowTransport::goto_start 2");
963 void CWindowTransport::goto_end()
965 gui->unlock_window();
966 handle_transport(GOTO_END, 1);
968 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
970 mwindow->gui->unlock_window();
972 gui->lock_window("CWindowTransport::goto_end 2");
975 CWindowCanvasToggleControls::CWindowCanvasToggleControls(CWindowCanvas *canvas)
976 : BC_MenuItem(calculate_text(canvas->get_controls()))
978 this->canvas = canvas;
980 int CWindowCanvasToggleControls::handle_event()
982 canvas->toggle_controls();
983 set_text(calculate_text(canvas->get_controls()));
987 const char *CWindowCanvasToggleControls::calculate_text(int controls)
989 return !controls ? _("Show controls") : _("Hide controls");
993 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
994 : Canvas(mwindow, gui,
995 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
996 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h,
997 0, 0, mwindow->edl->session->cwindow_scrollbars)
999 this->mwindow = mwindow;
1007 void CWindowCanvas::create_objects(EDL *edl)
1009 Canvas::create_objects(edl);
1010 canvas_menu->add_item(new CanvasPopupAuto(this));
1011 canvas_menu->add_item(new CanvasPopupResetCamera(this));
1012 canvas_menu->add_item(new CanvasPopupResetProjector(this));
1013 canvas_menu->add_item(new CanvasPopupCameraKeyframe(this));
1014 canvas_menu->add_item(new CanvasPopupProjectorKeyframe(this));
1015 canvas_menu->add_item(controls = new CWindowCanvasToggleControls(this));
1016 fullscreen_menu->add_item(new CanvasPopupAuto(this));
1019 void CWindowCanvas::status_event()
1021 gui->draw_status(1);
1024 void CWindowCanvas::update_zoom(int x, int y, float zoom)
1026 mwindow->edl->session->cwindow_xscroll = x;
1027 mwindow->edl->session->cwindow_yscroll = y;
1028 mwindow->edl->session->cwindow_zoom = zoom;
1029 use_scrollbars = !zoom ? 0 : 1;
1030 mwindow->edl->session->cwindow_scrollbars = use_scrollbars;
1033 int CWindowCanvas::set_fullscreen(int on, int unlock)
1036 if( on && !get_fullscreen() ) {
1037 last_xscroll = get_xscroll();
1038 last_yscroll = get_yscroll();
1039 last_zoom = get_zoom();
1040 Canvas::set_fullscreen(1, unlock);
1044 if( !on && get_fullscreen() ) {
1045 Canvas::set_fullscreen(0, unlock);
1046 gui->zoom_panel->update(get_zoom());
1047 update_zoom(last_xscroll, last_yscroll, last_zoom);
1048 gui->update_canvas();
1054 int CWindowCanvas::get_xscroll()
1056 return mwindow->edl->session->cwindow_xscroll;
1059 int CWindowCanvas::get_yscroll()
1061 return mwindow->edl->session->cwindow_yscroll;
1065 float CWindowCanvas::get_zoom()
1067 return mwindow->edl->session->cwindow_zoom;
1070 void CWindowCanvas::zoom_auto()
1073 set_zoom(mwindow->edl, 0);
1074 gui->update_canvas();
1077 int CWindowCanvas::do_scroll(EDL *edl, float cursor_x, float cursor_y)
1079 float zoom = get_zoom();
1080 float zoom_x, zoom_y, conformed_w, conformed_h;
1081 get_zooms(edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
1083 x = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
1084 y = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
1085 zoom = get_auto_zoom(mwindow->edl);
1088 x = gui->x_origin - cursor_x / zoom_x;
1089 y = gui->y_origin - cursor_y / zoom_y;
1091 update_zoom(x, y, zoom);
1092 gui->update_canvas();
1096 int CWindowCanvas::scope_on()
1098 EditPanelScopeDialog *scope_dialog = gui->edit_panel->scope_dialog;
1099 if( !scope_dialog || !scope_dialog->scope_gui ) return 0;
1100 if( scope_dialog->scope_gui->use_refresh ) return 0;
1101 return scope_dialog->running();
1104 void CWindowCanvas::draw_scope(VFrame *output, int refresh)
1106 if( !output ) return;
1107 EditPanelScopeDialog *scope_dialog = gui->edit_panel->scope_dialog;
1108 if( !scope_dialog || !scope_dialog->scope_gui ) return;
1109 if( scope_dialog->scope_gui->use_refresh && !refresh ) return;
1110 scope_dialog->process(output);
1113 void CWindowCanvas::draw_refresh(int flush)
1115 BC_WindowBase *window = get_canvas();
1116 if( window && !window->get_video_on() ) {
1118 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
1119 float in_x1, in_y1, in_x2, in_y2;
1120 float out_x1, out_y1, out_x2, out_y2;
1121 get_transfers(mwindow->edl,
1122 in_x1, in_y1, in_x2, in_y2,
1123 out_x1, out_y1, out_x2, out_y2);
1126 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1127 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1130 if( out_x2 > out_x1 && out_y2 > out_y1 &&
1131 in_x2 > in_x1 && in_y2 > in_y1 ) {
1132 // input scaled from session to refresh frame coordinates
1133 int ow = get_output_w(mwindow->edl);
1134 int oh = get_output_h(mwindow->edl);
1135 int rw = refresh_frame->get_w();
1136 int rh = refresh_frame->get_h();
1137 float xs = (float)rw / ow;
1138 float ys = (float)rh / oh;
1139 in_x1 *= xs; in_x2 *= xs;
1140 in_y1 *= ys; in_y2 *= ys;
1141 // Can't use OpenGL here because it is called asynchronously of the
1142 // playback operation.
1143 window->draw_vframe(refresh_frame,
1144 (int)out_x1, (int)out_y1,
1145 (int)(out_x2 - out_x1),
1146 (int)(out_y2 - out_y1),
1147 (int)in_x1, (int)in_y1,
1148 (int)(in_x2 - in_x1),
1149 (int)(in_y2 - in_y1),
1155 window->flash(flush);
1157 //printf("CWindowCanvas::draw_refresh 10\n");
1160 #define CROPHANDLE_W xS(10)
1161 #define CROPHANDLE_H yS(10)
1163 void CWindowCanvas::draw_crophandle(int x, int y)
1165 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1169 #define CONTROL_W xS(10)
1170 #define CONTROL_H yS(10)
1171 #define FIRST_CONTROL_W xS(20)
1172 #define FIRST_CONTROL_H yS(20)
1174 #define BC_INFINITY 65536
1176 #define RULERHANDLE_W xS(16)
1177 #define RULERHANDLE_H yS(16)
1179 int CWindowCanvas::do_ruler(int draw, int motion,
1180 int button_press, int button_release)
1183 EDLSession *session = mwindow->edl->session;
1184 float x1 = session->ruler_x1;
1185 float y1 = session->ruler_y1;
1186 float x2 = session->ruler_x2;
1187 float y2 = session->ruler_y2;
1188 float canvas_x1 = x1;
1189 float canvas_y1 = y1;
1190 float canvas_x2 = x2;
1191 float canvas_y2 = y2;
1192 float output_x = get_cursor_x();
1193 float output_y = get_cursor_y();
1194 float canvas_cursor_x = output_x;
1195 float canvas_cursor_y = output_y;
1197 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1198 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1199 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1200 mwindow->session->cwindow_output_x = roundf(output_x);
1201 mwindow->session->cwindow_output_y = roundf(output_y);
1203 if( button_press && get_buttonpress() == 1 ) {
1204 gui->ruler_handle = -1;
1205 gui->ruler_translate = 0;
1206 if( gui->alt_down() ) {
1207 gui->ruler_translate = 1;
1208 gui->ruler_origin_x = x1;
1209 gui->ruler_origin_y = y1;
1212 if( canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1213 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1214 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1215 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2 ) {
1216 gui->ruler_handle = 0;
1217 gui->ruler_origin_x = x1;
1218 gui->ruler_origin_y = y1;
1221 if( canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1222 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1223 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1224 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2 ) {
1225 gui->ruler_handle = 1;
1226 gui->ruler_origin_x = x2;
1227 gui->ruler_origin_y = y2;
1231 // Start new selection
1232 if( !gui->ruler_translate &&
1233 (gui->ruler_handle < 0 ||
1237 do_ruler(1, 0, 0, 0);
1238 get_canvas()->flash();
1239 gui->ruler_handle = 1;
1240 session->ruler_x1 = output_x;
1241 session->ruler_y1 = output_y;
1242 session->ruler_x2 = output_x;
1243 session->ruler_y2 = output_y;
1244 gui->ruler_origin_x = session->ruler_x2;
1245 gui->ruler_origin_y = session->ruler_y2;
1248 gui->x_origin = output_x;
1249 gui->y_origin = output_y;
1250 gui->current_operation = CWINDOW_RULER;
1251 gui->tool_panel->raise_window();
1256 if( gui->current_operation == CWINDOW_RULER ) {
1257 if( gui->ruler_translate ) {
1259 do_ruler(1, 0, 0, 0);
1260 float x_difference = session->ruler_x1;
1261 float y_difference = session->ruler_y1;
1262 session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1263 session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1264 x_difference -= session->ruler_x1;
1265 y_difference -= session->ruler_y1;
1266 session->ruler_x2 -= x_difference;
1267 session->ruler_y2 -= y_difference;
1269 do_ruler(1, 0, 0, 0);
1270 get_canvas()->flash();
1274 switch( gui->ruler_handle ) {
1276 do_ruler(1, 0, 0, 0);
1277 session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1278 session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1279 if( gui->alt_down() || gui->ctrl_down() ) {
1280 double angle_value = fabs(atan((session->ruler_y2 - session->ruler_y1) /
1281 (session->ruler_x2 - session->ruler_x1)) *
1283 double distance_value =
1284 sqrt(SQR(session->ruler_x2 - session->ruler_x1) +
1285 SQR(session->ruler_y2 - session->ruler_y1));
1286 if( angle_value < 22 )
1287 session->ruler_y1 = session->ruler_y2;
1289 if( angle_value > 67 )
1290 session->ruler_x1 = session->ruler_x2;
1292 if( session->ruler_x1 < session->ruler_x2 &&
1293 session->ruler_y1 < session->ruler_y2 ) {
1294 session->ruler_x1 = session->ruler_x2 - distance_value / 1.414214;
1295 session->ruler_y1 = session->ruler_y2 - distance_value / 1.414214;
1298 if( session->ruler_x1 < session->ruler_x2 && session->ruler_y1 > session->ruler_y2 ) {
1299 session->ruler_x1 = session->ruler_x2 - distance_value / 1.414214;
1300 session->ruler_y1 = session->ruler_y2 + distance_value / 1.414214;
1303 if( session->ruler_x1 > session->ruler_x2 &&
1304 session->ruler_y1 < session->ruler_y2 ) {
1305 session->ruler_x1 = session->ruler_x2 + distance_value / 1.414214;
1306 session->ruler_y1 = session->ruler_y2 - distance_value / 1.414214;
1309 session->ruler_x1 = session->ruler_x2 + distance_value / 1.414214;
1310 session->ruler_y1 = session->ruler_y2 + distance_value / 1.414214;
1313 do_ruler(1, 0, 0, 0);
1314 get_canvas()->flash();
1319 do_ruler(1, 0, 0, 0);
1320 session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1321 session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1322 if( gui->alt_down() || gui->ctrl_down() ) {
1323 double angle_value = fabs(atan((session->ruler_y2 - session->ruler_y1) /
1324 (session->ruler_x2 - session->ruler_x1)) *
1326 double distance_value =
1327 sqrt(SQR(session->ruler_x2 - session->ruler_x1) +
1328 SQR(session->ruler_y2 - session->ruler_y1));
1329 if( angle_value < 22 )
1330 session->ruler_y2 = session->ruler_y1;
1332 if( angle_value > 67 )
1333 session->ruler_x2 = session->ruler_x1;
1335 if( session->ruler_x2 < session->ruler_x1 &&
1336 session->ruler_y2 < session->ruler_y1 ) {
1337 session->ruler_x2 = session->ruler_x1 - distance_value / 1.414214;
1338 session->ruler_y2 = session->ruler_y1 - distance_value / 1.414214;
1341 if( session->ruler_x2 < session->ruler_x1 &&
1342 session->ruler_y2 > session->ruler_y1 ) {
1343 session->ruler_x2 = session->ruler_x1 - distance_value / 1.414214;
1344 session->ruler_y2 = session->ruler_y1 + distance_value / 1.414214;
1347 if( session->ruler_x2 > session->ruler_x1 && session->ruler_y2 < session->ruler_y1 ) {
1348 session->ruler_x2 = session->ruler_x1 + distance_value / 1.414214;
1349 session->ruler_y2 = session->ruler_y1 - distance_value / 1.414214;
1352 session->ruler_x2 = session->ruler_x1 + distance_value / 1.414214;
1353 session->ruler_y2 = session->ruler_y1 + distance_value / 1.414214;
1356 do_ruler(1, 0, 0, 0);
1357 get_canvas()->flash();
1362 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1365 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1370 if( canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1371 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1372 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1373 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2 ) {
1374 set_cursor(UPRIGHT_ARROW_CURSOR);
1377 if( canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1378 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1379 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1380 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2 ) {
1381 set_cursor(UPRIGHT_ARROW_CURSOR);
1384 set_cursor(CROSS_CURSOR);
1386 // Update current position
1391 // Assume no ruler measurement if 0 length
1392 if( draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)) ) {
1393 get_canvas()->set_inverse();
1394 get_canvas()->set_color(WHITE);
1395 get_canvas()->draw_line((int)canvas_x1,
1399 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1401 roundf(canvas_x1) + RULERHANDLE_W / 2,
1403 get_canvas()->draw_line(roundf(canvas_x1),
1404 roundf(canvas_y1) - RULERHANDLE_H / 2,
1406 roundf(canvas_y1) + RULERHANDLE_H / 2);
1407 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1409 roundf(canvas_x2) + RULERHANDLE_W / 2,
1411 get_canvas()->draw_line(roundf(canvas_x2),
1412 roundf(canvas_y2) - RULERHANDLE_H / 2,
1414 roundf(canvas_y2) + RULERHANDLE_H / 2);
1415 get_canvas()->set_opaque();
1422 static inline double line_dist(float cx,float cy, float tx,float ty)
1424 double dx = tx-cx, dy = ty-cy;
1425 return sqrt(dx*dx + dy*dy);
1428 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1430 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1431 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1435 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1436 int button_press, int cursor_motion, int draw)
1438 // Retrieve points from top recordable track
1439 //printf("CWindowCanvas::do_mask 1\n");
1440 Track *track = gui->cwindow->calculate_mask_track();
1441 //printf("CWindowCanvas::do_mask 2\n");
1443 if( !track ) return 0;
1444 //printf("CWindowCanvas::do_mask 3\n");
1445 CWindowMaskGUI *mask_gui = (CWindowMaskGUI *)
1446 (gui->tool_panel ? gui->tool_panel->tool_gui : 0);
1447 int draw_markers = mask_gui ? mask_gui->markers : 0;
1448 int draw_boundary = mask_gui ? mask_gui->boundary : 0;
1449 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1450 int64_t position = track->to_units(
1451 mwindow->edl->local_session->get_selectionstart(1),
1453 Auto *prev_auto = 0;
1454 mask_autos->get_prev_auto(position, PLAY_FORWARD, (Auto *&)prev_auto, 1);
1455 MaskAuto *prev_mask = (MaskAuto *)prev_auto;
1457 int update_points = 1;
1458 // Determine the points based on whether
1459 // new keyframes will be generated or drawing is performed.
1460 // If keyframe generation occurs, use the interpolated mask.
1461 // If no keyframe generation occurs, use the previous mask.
1462 int use_interpolated = 0;
1463 if( button_press || cursor_motion ) {
1464 #ifdef USE_KEYFRAME_SPANNING
1465 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1466 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1467 int64_t start_pos = track->to_units(selection_start, 0);
1468 int64_t end_pos = track->to_units(selection_end, 0);
1469 Auto *first = 0, *last = 0;
1470 mask_autos->get_prev_auto(start_pos, PLAY_FORWARD, first, 1);
1471 mask_autos->get_prev_auto(end_pos, PLAY_FORWARD, last, 1);
1472 if( last == first && (!mwindow->edl->session->auto_keyframes) )
1473 use_interpolated = 0;
1475 // If keyframe spanning occurs, use the interpolated points.
1476 // If new keyframe is generated, use the interpolated points.
1477 use_interpolated = 1;
1480 if( mwindow->edl->session->auto_keyframes )
1481 use_interpolated = 1;
1485 use_interpolated = 1;
1487 if( use_interpolated ) {
1488 // Interpolate the points to get exactly what is being rendered at this position.
1489 mask_autos->get_points(&points,
1490 mwindow->edl->session->cwindow_mask,
1491 position, PLAY_FORWARD);
1494 // Use the prev mask
1495 prev_mask->get_points(&points,
1496 mwindow->edl->session->cwindow_mask);
1499 // Projector zooms relative to the center of the track output.
1500 float half_track_w = (float)track->track_w / 2;
1501 float half_track_h = (float)track->track_h / 2;
1502 // Translate mask to projection
1503 float projector_x, projector_y, projector_z;
1504 track->automation->get_projector(
1505 &projector_x, &projector_y, &projector_z,
1506 position, PLAY_FORWARD);
1509 // Get position of cursor relative to mask
1510 float cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
1511 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1512 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1514 projector_x += mwindow->edl->session->output_w / 2;
1515 projector_y += mwindow->edl->session->output_h / 2;
1516 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1517 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1519 // Fix cursor origin
1520 if( button_press ) {
1521 gui->x_origin = mask_cursor_x;
1522 gui->y_origin = mask_cursor_y;
1526 // Points of closest line
1527 int shortest_point1 = -1;
1528 int shortest_point2 = -1;
1530 int shortest_point = -1;
1531 // Distance to closest line
1532 float shortest_line_distance = BC_INFINITY;
1533 // Distance to closest point
1534 float shortest_point_distance = BC_INFINITY;
1535 int selected_point = -1;
1536 int selected_control_point = -1;
1537 float selected_control_point_distance = BC_INFINITY;
1538 ArrayList<int> x_points;
1539 ArrayList<int> y_points;
1541 if( !cursor_motion ) {
1543 get_canvas()->set_color(WHITE);
1544 get_canvas()->set_inverse();
1546 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1548 // Never draw closed polygon and a closed
1549 // polygon is harder to add points to.
1550 for( int i = 0; i < points.size() && !result; i++ ) {
1551 MaskPoint *point1 = points.get(i);
1552 MaskPoint *point2 = (i >= points.size() - 1) ?
1553 points.get(0) : points.get(i + 1);
1554 if( button_press ) {
1555 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1556 if( point_distance1 < shortest_point_distance || shortest_point < 0 ) {
1557 shortest_point_distance = point_distance1;
1561 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1562 if( point_distance2 < shortest_point_distance || shortest_point < 0 ) {
1563 shortest_point_distance = point_distance2;
1564 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1568 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1570 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1571 //point1->x, point1->y, point2->x, point2->y, projector_z);
1572 for( int j = 0; j <= segments && !result; j++ ) {
1573 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1574 float x0 = point1->x, y0 = point1->y;
1575 float x1 = point1->x + point1->control_x2;
1576 float y1 = point1->y + point1->control_y2;
1577 float x2 = point2->x + point2->control_x1;
1578 float y2 = point2->y + point2->control_y1;
1579 float x3 = point2->x, y3 = point2->y;
1580 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1581 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1582 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1583 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1584 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1585 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1586 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1587 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1589 float t = (float)j / segments;
1590 float tpow2 = t * t;
1591 float tpow3 = t * t * t;
1593 float invtpow2 = invt * invt;
1594 float invtpow3 = invt * invt * invt;
1596 float x = ( invtpow3 * x0
1597 + 3 * t * invtpow2 * x1
1598 + 3 * tpow2 * invt * x2
1600 float y = ( invtpow3 * y0
1601 + 3 * t * invtpow2 * y1
1602 + 3 * tpow2 * invt * y2
1604 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1605 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1606 // Test new point addition
1607 if( button_press ) {
1608 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1610 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1611 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1612 if( line_distance < shortest_line_distance ||
1613 shortest_point1 < 0 ) {
1614 shortest_line_distance = line_distance;
1615 shortest_point1 = i;
1616 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1617 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1618 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1621 // Test existing point selection
1623 if( gui->ctrl_down() ) {
1624 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1626 if( distance < selected_control_point_distance ) {
1628 selected_control_point = 1;
1629 selected_control_point_distance = distance;
1633 if( !gui->shift_down() ) {
1634 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1635 if( test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0) ) {
1640 selected_point = shortest_point;
1643 // Test second point
1644 if( gui->ctrl_down() ) {
1645 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1647 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1648 if( distance < selected_control_point_distance ) {
1649 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1650 selected_control_point = 0;
1651 selected_control_point_distance = distance;
1654 else if( i < points.size() - 1 ) {
1655 if( !gui->shift_down() ) {
1656 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1657 if( test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3) ) {
1658 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1662 selected_point = shortest_point;
1667 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1671 if( draw ) { // Draw joining line
1672 x_points.append((int)canvas_x);
1673 y_points.append((int)canvas_y);
1676 if( j == segments ) {
1677 if( draw && draw_markers ) { // Draw second anchor
1678 if( i < points.size() - 1 ) {
1679 if( i == gui->affected_point - 1 )
1680 get_canvas()->draw_disc(
1681 (int)canvas_x - CONTROL_W / 2,
1682 (int)canvas_y - CONTROL_W / 2,
1683 CONTROL_W, CONTROL_H);
1685 get_canvas()->draw_circle(
1686 (int)canvas_x - CONTROL_W / 2,
1687 (int)canvas_y - CONTROL_W / 2,
1688 CONTROL_W, CONTROL_H);
1689 // char string[BCTEXTLEN];
1690 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1691 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1693 // Draw second control point.
1694 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1695 get_canvas()->draw_line(
1696 (int)canvas_x, (int)canvas_y,
1697 (int)canvas_x2, (int)canvas_y2);
1698 get_canvas()->draw_rectangle(
1699 (int)canvas_x2 - CONTROL_W / 2,
1700 (int)canvas_y2 - CONTROL_H / 2,
1701 CONTROL_W, CONTROL_H);
1706 // Draw first anchor
1707 if( i == 0 && draw ) {
1708 if( draw_boundary ) {
1709 char mask_label[BCSTRLEN];
1710 int k = mwindow->edl->session->cwindow_mask;
1711 if( !prev_mask || k < 0 || k >= prev_mask->masks.size() )
1712 sprintf(mask_label, "%d", k);
1714 sprintf(mask_label, "%s", prev_mask->masks[k]->name);
1715 get_canvas()->draw_text(
1716 (int)canvas_x - FIRST_CONTROL_W,
1717 (int)canvas_y - FIRST_CONTROL_H,
1720 if( draw_markers ) {
1721 get_canvas()->draw_disc(
1722 (int)canvas_x - FIRST_CONTROL_W / 2,
1723 (int)canvas_y - FIRST_CONTROL_H / 2,
1724 FIRST_CONTROL_W, FIRST_CONTROL_H);
1728 // Draw first control point.
1729 if( draw && draw_markers ) {
1730 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1731 get_canvas()->draw_line(
1732 (int)canvas_x, (int)canvas_y,
1733 (int)canvas_x1, (int)canvas_y1);
1734 get_canvas()->draw_rectangle(
1735 (int)canvas_x1 - CONTROL_W / 2,
1736 (int)canvas_y1 - CONTROL_H / 2,
1737 CONTROL_W, CONTROL_H);
1739 x_points.append((int)canvas_x);
1740 y_points.append((int)canvas_y);
1743 //printf("CWindowCanvas::do_mask 1\n");
1747 //printf("CWindowCanvas::do_mask 1\n");
1749 BC_WindowBase *cvs_win = get_canvas();
1750 if( draw && draw_boundary ) {
1751 cvs_win->draw_polygon(&x_points, &y_points);
1752 cvs_win->set_opaque();
1754 if( draw && mask_gui && mask_gui->focused ) {
1755 float fx = atof(mask_gui->focus_x->get_text());
1756 float fy = atof(mask_gui->focus_y->get_text());
1757 fx = (fx - half_track_w) * projector_z + projector_x;
1758 fy = (fy - half_track_h) * projector_z + projector_y;
1759 output_to_canvas(mwindow->edl, 0, fx, fy);
1760 float r = bmax(cvs_win->get_w(), cvs_win->get_h());
1763 int fw = 2*d+3, fh = fw;
1764 VFrame focus(fw,fh, BC_RGBA8888);
1765 focus.transfer_from(gui->focus_frame);
1766 fx -= fw/2.f; fy -= fh/2.f;
1767 BC_Pixmap focus_pixmap(cvs_win, &focus, PIXMAP_ALPHA);
1768 cvs_win->draw_pixmap(&focus_pixmap,fx,fy);
1770 cvs_win->set_line_width((int)(0.0025*r) + 1);
1771 cvs_win->set_color(BLUE);
1772 cvs_win->draw_line(fx-d,fy-d, fx+d, fy+d);
1773 cvs_win->draw_line(fx-d,fy+d, fx+d, fy-d);
1774 cvs_win->set_line_width(0);
1775 cvs_win->set_color(WHITE);
1778 if( draw && mask_gui && draw_markers && points.size() ) {
1779 float cx = 0, cy = 0;
1780 int n = points.size();
1781 for( int i=0; i<n; ++i ) {
1782 MaskPoint *point = points.get(i);
1783 cx += point->x; cy += point->y;
1786 if( !mask_gui->focused )
1787 mask_gui->set_focused(0, cx, cy);
1788 cx = (cx - half_track_w) * projector_z + projector_x;
1789 cy = (cy - half_track_h) * projector_z + projector_y;
1790 output_to_canvas(mwindow->edl, 0, cx, cy);
1791 float r = bmax(cvs_win->get_w(), cvs_win->get_h());
1793 cvs_win->set_line_width((int)(0.002*r) + 1);
1794 cvs_win->set_color(ORANGE);
1795 cvs_win->draw_line(cx-d,cy, cx+d, cy);
1796 cvs_win->draw_line(cx,cy-d, cx, cy+d);
1797 cvs_win->set_line_width(0);
1798 cvs_win->set_color(WHITE);
1800 //printf("CWindowCanvas::do_mask 1\n");
1803 if( button_press && !result ) {
1804 gui->affected_track = gui->cwindow->calculate_mask_track();
1806 // Get keyframe outside the EDL to edit. This must be rendered
1807 // instead of the EDL keyframes when it exists. Then it must be
1808 // applied to the EDL keyframes on buttonrelease.
1809 if( gui->affected_track ) {
1810 #ifdef USE_KEYFRAME_SPANNING
1811 // Make copy of current parameters in local keyframe
1812 gui->mask_keyframe =
1813 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1815 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1818 gui->mask_keyframe =
1819 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1823 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1825 if( get_buttonpress() == WHEEL_UP || get_buttonpress() == WHEEL_DOWN ) {
1826 if( !gui->shift_down() ) {
1827 mwindow->undo->update_undo_before(_("mask rotate"), this);
1828 gui->current_operation = CWINDOW_MASK_ROTATE;
1831 mwindow->undo->update_undo_before(_("mask scale"), this);
1832 gui->current_operation = CWINDOW_MASK_SCALE;
1834 gui->affected_point = 0;
1837 // Translate entire keyframe
1838 if( gui->alt_down() && mask->points.size() ) {
1839 mwindow->undo->update_undo_before(_("mask translate"), 0);
1840 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1841 gui->affected_point = 0;
1844 // Existing point or control point was selected
1845 if( selected_point >= 0 ) {
1846 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1847 gui->affected_point = selected_point;
1849 if( selected_control_point == 0 )
1850 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1852 if( selected_control_point == 1 )
1853 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1855 gui->current_operation = mwindow->edl->session->cwindow_operation;
1857 else // No existing point or control point was selected so create a new one
1858 if( !gui->ctrl_down() && !gui->alt_down() ) {
1859 mwindow->undo->update_undo_before(_("mask point"), 0);
1860 // Create the template
1861 MaskPoint *point = new MaskPoint;
1862 point->x = mask_cursor_x;
1863 point->y = mask_cursor_y;
1864 point->control_x1 = 0;
1865 point->control_y1 = 0;
1866 point->control_x2 = 0;
1867 point->control_y2 = 0;
1870 if( shortest_point2 < shortest_point1 ) {
1871 shortest_point2 ^= shortest_point1;
1872 shortest_point1 ^= shortest_point2;
1873 shortest_point2 ^= shortest_point1;
1878 // printf("CWindowGUI::do_mask 40\n");
1879 // mwindow->edl->dump();
1880 // printf("CWindowGUI::do_mask 50\n");
1884 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1885 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1886 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1888 // Append to end of list
1889 if( shortest_point1 == shortest_point2 ||
1890 labs(shortest_point1 - shortest_point2) > 1) {
1891 #ifdef USE_KEYFRAME_SPANNING
1893 MaskPoint *new_point = new MaskPoint;
1894 points.append(new_point);
1895 *new_point = *point;
1896 gui->affected_point = points.size() - 1;
1900 // Need to apply the new point to every keyframe
1901 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1902 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1903 MaskPoint *new_point = new MaskPoint;
1904 submask->points.append(new_point);
1905 *new_point = *point;
1906 if( current == (MaskAuto*)mask_autos->default_auto )
1907 current = (MaskAuto*)mask_autos->first;
1909 current = (MaskAuto*)NEXT;
1911 gui->affected_point = mask->points.size() - 1;
1917 // Insert between 2 points, shifting back point 2
1918 if( shortest_point1 >= 0 && shortest_point2 >= 0 ) {
1920 #ifdef USE_KEYFRAME_SPANNING
1921 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1923 if( points.size() >= shortest_point2 ) {
1924 MaskPoint *new_point = new MaskPoint;
1926 for( int i = points.size() - 1;
1927 i > shortest_point2;
1929 points.values[i] = points.values[i - 1];
1930 points.values[shortest_point2] = new_point;
1932 *new_point = *point;
1937 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1938 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1939 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1941 if( submask->points.size() >= shortest_point2 ) {
1942 MaskPoint *new_point = new MaskPoint;
1943 submask->points.append(0);
1944 for( int i = submask->points.size() - 1;
1945 i > shortest_point2;
1947 submask->points.values[i] = submask->points.values[i - 1];
1948 submask->points.values[shortest_point2] = new_point;
1950 *new_point = *point;
1953 if( current == (MaskAuto*)mask_autos->default_auto )
1954 current = (MaskAuto*)mask_autos->first;
1956 current = (MaskAuto*)NEXT;
1960 gui->affected_point = shortest_point2;
1965 // printf("CWindowGUI::do_mask 20\n");
1966 // mwindow->edl->dump();
1967 // printf("CWindowGUI::do_mask 30\n");
1970 //printf("CWindowCanvas::do_mask 1\n");
1971 // Create the first point.
1972 #ifdef USE_KEYFRAME_SPANNING
1973 MaskPoint *new_point = new MaskPoint;
1974 points.append(new_point);
1975 *new_point = *point;
1976 gui->affected_point = points.size() - 1;
1978 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1979 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1980 MaskPoint *new_point = new MaskPoint;
1981 submask->points.append(new_point);
1982 *new_point = *point;
1983 if( current == (MaskAuto*)mask_autos->default_auto )
1984 current = (MaskAuto*)mask_autos->first;
1986 current = (MaskAuto*)NEXT;
1988 gui->affected_point = points.size() - 1;
1991 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
1994 gui->current_operation = mwindow->edl->session->cwindow_operation;
1995 // Delete the template
2004 if( button_press && result ) {
2005 #ifdef USE_KEYFRAME_SPANNING
2006 MaskPoints &mask_points = points;
2008 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
2009 MaskPoints &mask_points = mask->points;
2011 int k = gui->affected_point;
2012 if( k >= 0 && k < mask_points.size() ) {
2013 MaskPoint *point = mask_points.values[k];
2014 gui->center_x = point->x;
2015 gui->center_y = point->y;
2016 gui->control_in_x = point->control_x1;
2017 gui->control_in_y = point->control_y1;
2018 gui->control_out_x = point->control_x2;
2019 gui->control_out_y = point->control_y2;
2022 gui->center_x = gui->center_y = 0;
2023 gui->control_in_x = gui->control_in_y = 0;
2024 gui->control_out_x = gui->control_out_y = 0;
2026 gui->tool_panel->raise_window();
2029 //printf("CWindowCanvas::do_mask 8\n");
2030 if( cursor_motion ) {
2032 #ifdef USE_KEYFRAME_SPANNING
2033 // Must update the reference keyframes for every cursor motion
2034 gui->mask_keyframe = (MaskAuto*)gui->cwindow->
2035 calculate_affected_auto(mask_autos, 0);
2036 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
2039 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2041 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
2042 if( mask && gui->affected_point >= 0 &&
2043 gui->affected_point < mask->points.size() &&
2044 gui->current_operation != CWINDOW_NONE ) {
2045 // mwindow->undo->update_undo_before(_("mask point"), this);
2046 #ifdef USE_KEYFRAME_SPANNING
2047 MaskPoints &mask_points = points;
2049 MaskPoints &mask_points = mask->points;
2051 MaskPoint *point = mask_points.get(gui->affected_point);
2052 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2053 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask_points.size(), gui->affected_point);
2055 float last_x = point->x;
2056 float last_y = point->y;
2057 float last_control_x1 = point->control_x1;
2058 float last_control_y1 = point->control_y1;
2059 float last_control_x2 = point->control_x2;
2060 float last_control_y2 = point->control_y2;
2063 switch( gui->current_operation ) {
2065 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2066 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
2067 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
2070 case CWINDOW_MASK_CONTROL_IN:
2071 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
2072 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
2075 case CWINDOW_MASK_CONTROL_OUT:
2076 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
2077 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
2080 case CWINDOW_MASK_TRANSLATE: {
2081 if( !mask_gui ) break;
2082 int mode = mask_gui->scale_mode;
2083 MaskAuto *keyframe = gui->mask_keyframe;
2084 int gang = mask_gui->gang_focus->get_value();
2085 float dx = mask_cursor_x - gui->x_origin;
2086 float dy = mask_cursor_y - gui->y_origin;
2087 if( !dx && !dy ) break;
2088 int k = mwindow->edl->session->cwindow_mask;
2089 int n = gang ? keyframe->masks.size() : k+1;
2090 for( int j=gang? 0 : k; j<n; ++j ) {
2091 if( !mask_gui->mask_enables[j]->get_value() ) continue;
2092 SubMask *sub_mask = keyframe->get_submask(j);
2093 if( !sub_mask ) continue;
2094 MaskPoints &points = sub_mask->points;
2095 for( int i=0; i<points.size(); ++i ) {
2096 MaskPoint *point = points[i];
2097 if( mode == MASK_SCALE_X || mode == MASK_SCALE_XY ) point->x += dx;
2098 if( mode == MASK_SCALE_Y || mode == MASK_SCALE_XY ) point->y += dy;
2101 gui->x_origin = mask_cursor_x;
2102 gui->y_origin = mask_cursor_y;
2107 case CWINDOW_MASK_ROTATE:
2109 case CWINDOW_MASK_SCALE: {
2110 if( !mask_gui || !mask_points.size() ) break;
2111 float cx = gui->x_origin, cy = gui->y_origin;
2112 if( mask_gui->focused ) {
2113 cx = atof(mask_gui->focus_x->get_text());
2114 cy = atof(mask_gui->focus_y->get_text());
2116 else if( !gui->ctrl_down() ) {
2118 int n = mask_points.size();
2119 for( int i=0; i<n; ++i ) {
2120 MaskPoint *point = mask_points.values[i];
2121 cx += point->x; cy += point->y;
2124 mask_gui->set_focused(0, cx, cy);
2129 gui->get_triple_click() ? 8. :
2130 gui->get_double_click() ? 4. :
2132 int button_no = get_buttonpress();
2133 double ds = accel/64., dt = accel*M_PI/360.;
2134 double scale = button_no == WHEEL_UP ? 1.+ds : 1.-ds;
2135 int mode = mask_gui->scale_mode;
2136 double xscale = !rotate && (mode == MASK_SCALE_X ||
2137 mode == MASK_SCALE_XY ) ? scale : 1.;
2138 double yscale = !rotate && (mode == MASK_SCALE_Y ||
2139 mode == MASK_SCALE_XY ) ? scale : 1.;
2140 double theta = button_no == WHEEL_UP ? dt : -dt;
2141 if( rotate ? theta==0 : scale==1 ) break;
2142 float st = sin(theta), ct = cos(theta);
2143 MaskAuto *keyframe = gui->mask_keyframe;
2144 int gang = mask_gui->gang_focus->get_value();
2145 int k = mwindow->edl->session->cwindow_mask;
2146 int n = gang ? keyframe->masks.size() : k+1;
2147 for( int j=gang? 0 : k; j<n; ++j ) {
2148 if( !mask_gui->mask_enables[j]->get_value() ) continue;
2149 SubMask *sub_mask = keyframe->get_submask(j);
2150 if( !sub_mask ) continue;
2151 MaskPoints &points = sub_mask->points;
2152 for( int i=0; i<points.size(); ++i ) {
2153 MaskPoint *point = points[i];
2154 float px = point->x - gui->x_origin;
2155 float py = point->y - gui->y_origin;
2156 float nx = !rotate ? px*xscale : px*ct + py*st;
2157 float ny = !rotate ? py*yscale : py*ct - px*st;
2158 point->x = nx + gui->x_origin;
2159 point->y = ny + gui->y_origin;
2160 px = point->control_x1; py = point->control_y1;
2161 point->control_x1 = !rotate ? px*xscale : px*ct + py*st;
2162 point->control_y1 = !rotate ? py*yscale : py*ct - px*st;
2163 px = point->control_x2; py = point->control_y2;
2164 point->control_x2 = !rotate ? px*xscale : px*ct + py*st;
2165 point->control_y2 = !rotate ? py*yscale : py*ct - px*st;
2174 if( !(rerender && redraw) && (!EQUIV(last_x, point->x) ||
2175 !EQUIV(last_y, point->y) ||
2176 !EQUIV(last_control_x1, point->control_x1) ||
2177 !EQUIV(last_control_y1, point->control_y1) ||
2178 !EQUIV(last_control_x2, point->control_x2) ||
2179 !EQUIV(last_control_y2, point->control_y2)) ) {
2185 if( gui->current_operation == CWINDOW_NONE ) {
2186 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
2188 for( int i = 0; i < points.size() && !over_point; i++ ) {
2189 MaskPoint *point = points.get(i);
2190 float x0 = point->x;
2191 float y0 = point->y;
2192 float x1 = point->x + point->control_x1;
2193 float y1 = point->y + point->control_y1;
2194 float x2 = point->x + point->control_x2;
2195 float y2 = point->y + point->control_y2;
2196 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
2197 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
2199 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
2200 if( test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0) ) {
2204 if( !over_point && gui->ctrl_down() ) {
2205 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
2206 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
2207 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2208 if( test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1) ) {
2212 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2213 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2214 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2215 if( test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2) ) {
2222 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2227 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2230 #ifdef USE_KEYFRAME_SPANNING
2231 // Must commit change after operation.
2232 if( rerender && track ) {
2233 // Swap EDL keyframe with original.
2234 // Apply new values to keyframe span
2235 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2236 temp_keyframe.copy_data(gui->mask_keyframe);
2237 // Apply interpolated points back to keyframe
2239 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2240 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2241 mask_autos->update_parameter(&temp_keyframe);
2244 //printf("CWindowCanvas::do_mask 20\n");
2246 if( draw && draw_boundary && !draw_markers ) {
2247 BC_WindowBase *cvs_win = get_canvas();
2248 cvs_win->set_inverse();
2249 cvs_win->set_color(RED+GREEN);
2250 for( int k=0; k<SUBMASKS; ++k ) {
2251 if( k == mwindow->edl->session->cwindow_mask ) continue;
2252 points.remove_all_objects();
2253 if( use_interpolated )
2254 mask_autos->get_points(&points, k, position, PLAY_FORWARD);
2256 prev_mask->get_points(&points, k);
2258 edge.load(points, 0);
2259 for( int i=0; i<edge.size(); ++i ) {
2260 MaskCoord a = edge[i];
2261 MaskCoord b = i<edge.size()-1 ? edge[i+1] : edge[0];
2262 float ax = a.x, ay = a.y;
2263 float bx = b.x, by = b.y;
2264 output_to_canvas(mwindow->edl, 0, ax, ay);
2265 output_to_canvas(mwindow->edl, 0, bx, by);
2266 cvs_win->draw_line(ax,ay, bx,by);
2274 int CWindowCanvas::do_mask_focus()
2276 Track *track = gui->cwindow->calculate_affected_track();
2277 int64_t position = track->to_units(
2278 mwindow->edl->local_session->get_selectionstart(1),
2280 float projector_x, projector_y, projector_z;
2281 track->automation->get_projector(
2282 &projector_x, &projector_y, &projector_z,
2283 position, PLAY_FORWARD);
2284 float cx = get_cursor_x(), cy = get_cursor_y();
2285 canvas_to_output(mwindow->edl, 0, cx, cy);
2286 projector_x += mwindow->edl->session->output_w / 2;
2287 projector_y += mwindow->edl->session->output_h / 2;
2288 float half_track_w = (float)track->track_w / 2;
2289 float half_track_h = (float)track->track_h / 2;
2290 cx = (cx - projector_x) / projector_z + half_track_w;
2291 cy = (cy - projector_y) / projector_z + half_track_h;
2292 CWindowMaskGUI *mask_gui = (CWindowMaskGUI*) gui->tool_panel->tool_gui;
2293 mask_gui->set_focused(1, cx, cy);
2297 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2300 int radius = mwindow->edl->session->eyedrop_radius;
2308 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
2311 row1 = gui->eyedrop_y - radius;
2312 row2 = gui->eyedrop_y + radius;
2313 column1 = gui->eyedrop_x - radius;
2314 column2 = gui->eyedrop_x + radius;
2316 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2317 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2318 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2319 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2321 if( row2 <= row1 ) row2 = row1 + 1;
2322 if( column2 <= column1 ) column2 = column1 + 1;
2329 output_to_canvas(mwindow->edl, 0, x1, y1);
2330 output_to_canvas(mwindow->edl, 0, x2, y2);
2331 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2333 if( x2 - x1 >= 1 && y2 - y1 >= 1 ) {
2334 get_canvas()->set_inverse();
2335 get_canvas()->set_color(WHITE);
2337 get_canvas()->draw_rectangle((int)x1,
2342 get_canvas()->set_opaque();
2343 get_canvas()->flash();
2349 if( button_press ) {
2350 gui->current_operation = CWINDOW_EYEDROP;
2351 gui->tool_panel->raise_window();
2354 if( gui->current_operation == CWINDOW_EYEDROP ) {
2355 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2357 // Get color out of frame.
2358 // Doesn't work during playback because that bypasses the refresh frame.
2359 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
2360 float cursor_x = get_cursor_x();
2361 float cursor_y = get_cursor_y();
2362 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2363 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2364 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2366 row1 = cursor_y - radius;
2367 row2 = cursor_y + radius;
2368 column1 = cursor_x - radius;
2369 column2 = cursor_x + radius;
2370 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2371 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2372 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2373 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2374 if( row2 <= row1 ) row2 = row1 + 1;
2375 if( column2 <= column1 ) column2 = column1 + 1;
2379 if( gui->eyedrop_visible ) {
2381 do_eyedrop(temp, 0, 1);
2382 gui->eyedrop_visible = 0;
2385 gui->eyedrop_x = cursor_x;
2386 gui->eyedrop_y = cursor_y;
2391 do_eyedrop(temp, 0, 1);
2392 gui->eyedrop_visible = 1;
2395 #define GET_COLOR(type, components, max, do_yuv) { \
2396 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2398 float red = (float)*row++ / max; \
2399 float green = (float)*row++ / max; \
2400 float blue = (float)*row++ / max; \
2402 YUV::yuv.yuv_to_rgb_f(red, green, blue, red, green-0.5, blue-0.5); \
2403 mwindow->edl->local_session->red += red; \
2404 mwindow->edl->local_session->green += green; \
2405 mwindow->edl->local_session->blue += blue; \
2406 if( red > mwindow->edl->local_session->red_max ) mwindow->edl->local_session->red_max = red; \
2407 if( green > mwindow->edl->local_session->green_max ) mwindow->edl->local_session->green_max = green; \
2408 if( blue > mwindow->edl->local_session->blue_max ) mwindow->edl->local_session->blue_max = blue; \
2411 mwindow->edl->local_session->red = 0;
2412 mwindow->edl->local_session->green = 0;
2413 mwindow->edl->local_session->blue = 0;
2414 mwindow->edl->local_session->red_max = 0;
2415 mwindow->edl->local_session->green_max = 0;
2416 mwindow->edl->local_session->blue_max = 0;
2417 for( int i = row1; i < row2; i++ ) {
2418 for( int j = column1; j < column2; j++ ) {
2419 switch( refresh_frame->get_color_model() )
2422 GET_COLOR(unsigned char, 3, 0xff, 1);
2425 GET_COLOR(unsigned char, 4, 0xff, 1);
2428 GET_COLOR(uint16_t, 3, 0xffff, 1);
2430 case BC_YUVA16161616:
2431 GET_COLOR(uint16_t, 4, 0xffff, 1);
2434 GET_COLOR(unsigned char, 3, 0xff, 0);
2437 GET_COLOR(unsigned char, 4, 0xff, 0);
2440 GET_COLOR(float, 3, 1.0, 0);
2443 GET_COLOR(float, 4, 1.0, 0);
2449 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2450 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2451 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2455 mwindow->edl->local_session->red = 0;
2456 mwindow->edl->local_session->green = 0;
2457 mwindow->edl->local_session->blue = 0;
2458 gui->eyedrop_visible = 0;
2467 // Can't rerender since the color value is from the output of any effect it
2470 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2476 int CWindowCanvas::need_overlays()
2478 if( mwindow->edl->session->safe_regions ) return 1;
2479 if( mwindow->edl->session->cwindow_scrollbars ) return 1;
2480 if( gui->highlighted ) return 1;
2481 switch( mwindow->edl->session->cwindow_operation ) {
2482 case CWINDOW_EYEDROP:
2483 if( ! gui->eyedrop_visible ) break;
2484 case CWINDOW_CAMERA:
2485 case CWINDOW_PROJECTOR:
2494 void CWindowCanvas::draw_overlays()
2496 if( mwindow->edl->session->safe_regions ) {
2497 draw_safe_regions();
2500 if( mwindow->edl->session->cwindow_scrollbars ) {
2501 // Always draw output rectangle
2502 float x1, y1, x2, y2;
2504 x2 = mwindow->edl->session->output_w;
2506 y2 = mwindow->edl->session->output_h;
2507 output_to_canvas(mwindow->edl, 0, x1, y1);
2508 output_to_canvas(mwindow->edl, 0, x2, y2);
2510 get_canvas()->set_inverse();
2511 get_canvas()->set_color(WHITE);
2512 int ix1 = x1-1, iy1 = y1-1, ix2 = x2+1, iy2 = y2+1;
2513 get_canvas()->draw_rectangle(ix1, iy1, ix2-ix1, iy2-iy1);
2514 get_canvas()->set_opaque();
2517 if( gui->highlighted ) {
2518 get_canvas()->set_color(WHITE);
2519 get_canvas()->set_inverse();
2520 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2521 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2522 get_canvas()->set_opaque();
2525 int temp1 = 0, temp2 = 0;
2526 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2527 switch( mwindow->edl->session->cwindow_operation )
2529 case CWINDOW_CAMERA:
2533 case CWINDOW_PROJECTOR:
2542 do_mask(temp1, temp2, 0, 0, 1);
2546 do_ruler(1, 0, 0, 0);
2549 case CWINDOW_EYEDROP:
2550 if( gui->eyedrop_visible ) {
2552 do_eyedrop(rerender, 0, 1);
2553 gui->eyedrop_visible = 1;
2559 void CWindowCanvas::draw_safe_regions()
2561 float action_x1, action_x2, action_y1, action_y2;
2562 float title_x1, title_x2, title_y1, title_y2;
2564 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2565 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2566 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2567 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2568 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2569 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2570 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2571 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2573 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2574 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2575 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2576 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2578 get_canvas()->set_inverse();
2579 get_canvas()->set_color(WHITE);
2581 get_canvas()->draw_rectangle((int)action_x1,
2583 (int)(action_x2 - action_x1),
2584 (int)(action_y2 - action_y1));
2585 get_canvas()->draw_rectangle((int)title_x1,
2587 (int)(title_x2 - title_x1),
2588 (int)(title_y2 - title_y1));
2590 get_canvas()->set_opaque();
2594 void CWindowCanvas::create_keyframe(int do_camera)
2596 Track *affected_track = gui->cwindow->calculate_affected_track();
2597 if( affected_track ) {
2598 double pos = mwindow->edl->local_session->get_selectionstart(1);
2599 int64_t position = affected_track->to_units(pos, 0);
2600 int ix = do_camera ? AUTOMATION_CAMERA_X : AUTOMATION_PROJECTOR_X;
2601 int iy = do_camera ? AUTOMATION_CAMERA_Y : AUTOMATION_PROJECTOR_Y;
2602 int iz = do_camera ? AUTOMATION_CAMERA_Z : AUTOMATION_PROJECTOR_Z;
2603 FloatAuto *prev, *next;
2604 FloatAutos **autos = (FloatAutos**)affected_track->automation->autos;
2605 FloatAutos *x_autos = autos[ix]; prev = 0; next = 0;
2606 float x_value = x_autos->get_value(position, PLAY_FORWARD, prev, next);
2607 FloatAutos *y_autos = autos[iy]; prev = 0; next = 0;
2608 float y_value = y_autos->get_value(position, PLAY_FORWARD, prev, next);
2609 FloatAutos *z_autos = autos[iz]; prev = 0; next = 0;
2610 float z_value = z_autos->get_value(position, PLAY_FORWARD, prev, next);
2611 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2613 gui->cwindow->calculate_affected_autos(affected_track,
2614 &x_keyframe, &y_keyframe, &z_keyframe,
2615 do_camera, -1, -1, -1, 0);
2616 x_keyframe->set_value(x_value);
2617 y_keyframe->set_value(y_value);
2618 z_keyframe->set_value(z_value);
2620 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2624 void CWindowCanvas::camera_keyframe() { create_keyframe(1); }
2625 void CWindowCanvas::projector_keyframe() { create_keyframe(0); }
2627 void CWindowCanvas::reset_keyframe(int do_camera)
2629 Track *affected_track = gui->cwindow->calculate_affected_track();
2630 if( affected_track ) {
2631 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2632 gui->cwindow->calculate_affected_autos(affected_track,
2633 &x_keyframe, &y_keyframe, &z_keyframe,
2634 do_camera, 1, 1, 1);
2636 x_keyframe->set_value(0);
2637 y_keyframe->set_value(0);
2638 z_keyframe->set_value(1);
2640 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2641 MWindowGUI *mgui = mwindow->gui;
2642 mgui->lock_window("CWindowCanvas::reset_keyframe");
2643 gui->mwindow->edl->local_session->reset_view_limits();
2644 gui->mwindow->gui->zoombar->update_autozoom();
2645 mgui->unlock_window();
2649 void CWindowCanvas::reset_camera() { reset_keyframe(1); }
2650 void CWindowCanvas::reset_projector() { reset_keyframe(0); }
2653 int CWindowCanvas::test_crop(int button_press, int &redraw)
2656 int handle_selected = -1;
2657 float x1 = mwindow->edl->session->crop_x1;
2658 float y1 = mwindow->edl->session->crop_y1;
2659 float x2 = mwindow->edl->session->crop_x2;
2660 float y2 = mwindow->edl->session->crop_y2;
2661 float cursor_x = get_cursor_x();
2662 float cursor_y = get_cursor_y();
2663 float canvas_x1 = x1;
2664 float canvas_y1 = y1;
2665 float canvas_x2 = x2;
2666 float canvas_y2 = y2;
2667 float canvas_cursor_x = cursor_x;
2668 float canvas_cursor_y = cursor_y;
2670 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2671 // Use screen normalized coordinates for hot spot tests.
2672 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2673 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2676 if( gui->current_operation == CWINDOW_CROP ) {
2677 handle_selected = gui->crop_handle;
2680 if( canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2681 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H ) {
2682 handle_selected = 0;
2683 gui->crop_origin_x = x1;
2684 gui->crop_origin_y = y1;
2687 if( canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2688 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H ) {
2689 handle_selected = 1;
2690 gui->crop_origin_x = x2;
2691 gui->crop_origin_y = y1;
2694 if( canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2695 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2 ) {
2696 handle_selected = 2;
2697 gui->crop_origin_x = x1;
2698 gui->crop_origin_y = y2;
2701 if( canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2702 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2 ) {
2703 handle_selected = 3;
2704 gui->crop_origin_x = x2;
2705 gui->crop_origin_y = y2;
2710 gui->crop_origin_x = cursor_x;
2711 gui->crop_origin_y = cursor_y;
2714 // printf("test crop %d %d\n",
2715 // gui->current_operation,
2716 // handle_selected);
2719 if( button_press ) {
2720 if( gui->alt_down() ) {
2721 gui->crop_translate = 1;
2722 gui->crop_origin_x1 = x1;
2723 gui->crop_origin_y1 = y1;
2724 gui->crop_origin_x2 = x2;
2725 gui->crop_origin_y2 = y2;
2728 gui->crop_translate = 0;
2730 gui->current_operation = CWINDOW_CROP;
2731 gui->crop_handle = handle_selected;
2732 gui->x_origin = cursor_x;
2733 gui->y_origin = cursor_y;
2734 gui->tool_panel->raise_window();
2737 if( handle_selected < 0 && !gui->crop_translate ) {
2740 mwindow->edl->session->crop_x1 = (int)x1;
2741 mwindow->edl->session->crop_y1 = (int)y1;
2742 mwindow->edl->session->crop_x2 = (int)x2;
2743 mwindow->edl->session->crop_y2 = (int)y2;
2748 // Translate all 4 points
2749 if( gui->current_operation == CWINDOW_CROP && gui->crop_translate ) {
2750 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2751 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2752 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2753 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2755 mwindow->edl->session->crop_x1 = (int)x1;
2756 mwindow->edl->session->crop_y1 = (int)y1;
2757 mwindow->edl->session->crop_x2 = (int)x2;
2758 mwindow->edl->session->crop_y2 = (int)y2;
2764 if( gui->current_operation == CWINDOW_CROP ) {
2765 switch( gui->crop_handle ) {
2767 x1 = gui->crop_origin_x;
2768 y1 = gui->crop_origin_y;
2769 x2 = gui->crop_origin_x;
2770 y2 = gui->crop_origin_y;
2771 if( cursor_x < gui->x_origin ) {
2772 if( cursor_y < gui->y_origin ) {
2777 if( cursor_y >= gui->y_origin ) {
2783 if( cursor_x >= gui->x_origin ) {
2784 if( cursor_y < gui->y_origin ) {
2789 if( cursor_y >= gui->y_origin ) {
2795 // printf("test crop %d %d %d %d\n",
2796 // mwindow->edl->session->crop_x1,
2797 // mwindow->edl->session->crop_y1,
2798 // mwindow->edl->session->crop_x2,
2799 // mwindow->edl->session->crop_y2);
2802 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2803 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2806 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2807 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2810 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2811 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2814 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2815 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2819 if( !EQUIV(mwindow->edl->session->crop_x1, x1) ||
2820 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2821 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2822 !EQUIV(mwindow->edl->session->crop_y2, y2) ) {
2827 switch( gui->crop_handle ) {
2828 case 0: gui->crop_handle = 1; break;
2829 case 1: gui->crop_handle = 0; break;
2830 case 2: gui->crop_handle = 3; break;
2831 case 3: gui->crop_handle = 2; break;
2840 switch( gui->crop_handle ) {
2841 case 0: gui->crop_handle = 2; break;
2842 case 1: gui->crop_handle = 3; break;
2843 case 2: gui->crop_handle = 0; break;
2844 case 3: gui->crop_handle = 1; break;
2849 mwindow->edl->session->crop_x1 = (int)x1;
2850 mwindow->edl->session->crop_y1 = (int)y1;
2851 mwindow->edl->session->crop_x2 = (int)x2;
2852 mwindow->edl->session->crop_y2 = (int)y2;
2858 // Update cursor font
2859 if( handle_selected >= 0 ) {
2860 switch( handle_selected ) {
2861 case 0: set_cursor(UPLEFT_RESIZE); break;
2862 case 1: set_cursor(UPRIGHT_RESIZE); break;
2863 case 2: set_cursor(DOWNLEFT_RESIZE); break;
2864 case 3: set_cursor(DOWNRIGHT_RESIZE); break;
2869 set_cursor(ARROW_CURSOR);
2871 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2874 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2875 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2876 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2877 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2878 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2879 // mwindow->edl->session->crop_x2,
2880 // mwindow->edl->session->crop_y2,
2881 // mwindow->edl->calculate_output_w(0),
2882 // mwindow->edl->calculate_output_h(0));
2888 void CWindowCanvas::draw_crop()
2890 get_canvas()->set_inverse();
2891 get_canvas()->set_color(WHITE);
2893 float x1 = mwindow->edl->session->crop_x1;
2894 float y1 = mwindow->edl->session->crop_y1;
2895 float x2 = mwindow->edl->session->crop_x2;
2896 float y2 = mwindow->edl->session->crop_y2;
2898 output_to_canvas(mwindow->edl, 0, x1, y1);
2899 output_to_canvas(mwindow->edl, 0, x2, y2);
2901 if( x2 - x1 && y2 - y1 )
2902 get_canvas()->draw_rectangle((int)x1,
2907 draw_crophandle((int)x1, (int)y1);
2908 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2909 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2910 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2911 get_canvas()->set_opaque();
2915 void CWindowCanvas::draw_outlines(int do_camera)
2917 Track *track = gui->cwindow->calculate_affected_track();
2919 if( !track ) return;
2921 float proj_x, proj_y, proj_z;
2922 int64_t position = track->to_units(
2923 mwindow->edl->local_session->get_selectionstart(1),
2925 track->automation->get_projector(&proj_x, &proj_y, &proj_z,
2926 position, PLAY_FORWARD);
2928 proj_x += mwindow->edl->session->output_w/2.;
2929 proj_y += mwindow->edl->session->output_h/2.;
2930 float proj_x1 = proj_x - track->track_w/2. * proj_z;
2931 float proj_y1 = proj_y - track->track_h/2. * proj_z;
2932 float proj_x2 = proj_x + track->track_w/2. * proj_z;
2933 float proj_y2 = proj_y + track->track_h/2. * proj_z;
2934 float x1 = proj_x1, x2 = proj_x2;
2935 float y1 = proj_y1, y2 = proj_y2;
2936 output_to_canvas(mwindow->edl, 0, x1, y1);
2937 output_to_canvas(mwindow->edl, 0, x2, y2);
2939 #define DRAW_PROJECTION(offset) \
2940 get_canvas()->draw_rectangle(x1+offset, y1+offset, (x2-x1), (y2-y1)); \
2941 get_canvas()->draw_line(x1+offset, y1+offset, x2+offset, y2+offset); \
2942 get_canvas()->draw_line(x2+offset, y1+offset, x1+offset, y2+offset); \
2945 get_canvas()->set_color(BLACK);
2947 get_canvas()->set_color(do_camera ? GREEN : RED);
2951 float cam_x, cam_y, cam_z;
2952 track->automation->get_camera(&cam_x, &cam_y, &cam_z,
2953 position, PLAY_FORWARD);
2954 cam_x += track->track_w / 2.;
2955 cam_y += track->track_h / 2.;
2956 // follow image, not camera
2957 cam_x = -cam_x; cam_y = -cam_y; cam_z *= proj_z;
2958 float cam_x1 = cam_x * cam_z + proj_x;
2959 float cam_y1 = cam_y * cam_z + proj_y;
2960 float cam_x2 = (cam_x + track->track_w) * cam_z + proj_x;
2961 float cam_y2 = (cam_y + track->track_h) * cam_z + proj_y;
2962 output_to_canvas(mwindow->edl, 0, cam_x1, cam_y1);
2963 output_to_canvas(mwindow->edl, 0, cam_x2, cam_y2);
2964 get_canvas()->set_color(YELLOW);
2965 get_canvas()->draw_rectangle(cam_x1, cam_y1, cam_x2-cam_x1, cam_y2-cam_y1);
2969 int CWindowCanvas::test_bezier(int button_press,
2977 // Processing drag operation.
2978 // Create keyframe during first cursor motion.
2979 if( !button_press ) {
2981 float cursor_x = get_cursor_x();
2982 float cursor_y = get_cursor_y();
2983 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2985 if( gui->current_operation == CWINDOW_CAMERA ||
2986 gui->current_operation == CWINDOW_PROJECTOR ) {
2987 if( !gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom ) {
2988 gui->translating_zoom = 1;
2989 gui->reset_affected();
2991 else if( !gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom ) {
2992 gui->translating_zoom = 0;
2993 gui->reset_affected();
2996 // Get target keyframe
2997 if( !gui->affected_x && !gui->affected_y && !gui->affected_z ) {
2998 if( !gui->affected_track ) return 0;
2999 FloatAutos *affected_x_autos, *affected_y_autos, *affected_z_autos;
3000 FloatAutos** autos = (FloatAutos**) gui->affected_track->automation->autos;
3001 if( mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA ) {
3002 affected_x_autos = autos[AUTOMATION_CAMERA_X];
3003 affected_y_autos = autos[AUTOMATION_CAMERA_Y];
3004 affected_z_autos = autos[AUTOMATION_CAMERA_Z];
3007 affected_x_autos = autos[AUTOMATION_PROJECTOR_X];
3008 affected_y_autos = autos[AUTOMATION_PROJECTOR_Y];
3009 affected_z_autos = autos[AUTOMATION_PROJECTOR_Z];
3011 double position = mwindow->edl->local_session->get_selectionstart(1);
3012 int64_t track_position = gui->affected_track->to_units(position, 0);
3013 FloatAuto *prev_x = 0, *next_x = 0;
3014 float new_x = affected_x_autos->get_value(track_position, PLAY_FORWARD, prev_x, next_x);
3015 FloatAuto *prev_y = 0, *next_y = 0;
3016 float new_y = affected_y_autos->get_value(track_position, PLAY_FORWARD, prev_y, next_y);
3017 FloatAuto *prev_z = 0, *next_z = 0;
3018 float new_z = affected_z_autos->get_value(track_position, PLAY_FORWARD, prev_z, next_z);
3019 int zooming = gui->translating_zoom, created;
3020 gui->affected_x = (FloatAuto*)gui->cwindow->calculate_affected_auto(
3021 affected_x_autos, !zooming, &created, 0);
3023 gui->affected_x->set_value(new_x);
3026 gui->affected_y = (FloatAuto*)gui->cwindow->calculate_affected_auto(
3027 affected_y_autos, !zooming, &created, 0);
3029 gui->affected_y->set_value(new_y);
3032 gui->affected_z = (FloatAuto*)gui->cwindow->calculate_affected_auto(
3033 affected_z_autos, zooming, &created, 0);
3035 gui->affected_z->set_value(new_z);
3040 if( gui->translating_zoom ) {
3041 gui->center_z = gui->affected_z->get_value();
3044 gui->center_x = gui->affected_x->get_value();
3045 gui->center_y = gui->affected_y->get_value();
3052 float x_val = gui->affected_x->get_value();
3053 float y_val = gui->affected_y->get_value();
3054 float z_val = gui->affected_z->get_value();
3056 if( gui->translating_zoom ) {
3057 float z = gui->center_z + (cursor_y - gui->y_origin) / yS(128);
3059 if( !EQUIV(z_val, z) ) {
3064 gui->affected_z->set_value(z);
3067 float dx = cursor_x - gui->x_origin;
3068 float dy = cursor_y - gui->y_origin;
3069 // follow image, not camera
3070 if( gui->current_operation == CWINDOW_CAMERA ) {
3071 dx = -dx / z_val; dy = -dy / z_val;
3073 float x = gui->center_x + dx;
3074 float y = gui->center_y + dy;
3075 gui->affected_x->set_value(x);
3076 gui->affected_y->set_value(y);
3077 if( !EQUIV(x_val, x) || !EQUIV(y_val, y) ) {
3088 // Begin drag operation. Don't create keyframe here.
3090 // Get affected track off of the first recordable video track.
3091 // Calculating based on the alpha channel would require recording what layer
3092 // each output pixel belongs to as they're rendered and stacked. Forget it.
3093 gui->affected_track = gui->cwindow->calculate_affected_track();
3094 gui->reset_affected();
3096 if( gui->affected_track ) {
3098 mwindow->undo->update_undo_before(_("camera"), this);
3100 mwindow->undo->update_undo_before(_("projector"), this);
3102 gui->current_operation =
3103 mwindow->edl->session->cwindow_operation;
3104 gui->tool_panel->raise_window();
3112 int CWindowCanvas::test_zoom(int &redraw)
3115 int button = get_buttonpress();
3116 if( button == LEFT_BUTTON )
3117 button = gui->shift_down() ? WHEEL_DOWN : WHEEL_UP;
3118 if( !(zoom = get_zoom()) )
3119 zoom = get_auto_zoom(mwindow->edl);
3123 for( ; idx < total_zooms; ++idx ) {
3124 if( EQUIV(zoom, my_zoom_table[idx]) ) continue;
3125 if( zoom < my_zoom_table[idx] ) break;
3127 float zoom11 = 1.1f * zoom;
3128 zoom = idx < total_zooms ? my_zoom_table[idx] : zoom11;
3129 if( zoom > zoom11 ) zoom = zoom11;
3132 int idx = total_zooms;
3133 for( ; --idx >= 0; ) {
3134 if( EQUIV(my_zoom_table[idx], zoom) ) continue;
3135 if( my_zoom_table[idx] < zoom ) break;
3137 float zoom09 = 0.9f * zoom;
3138 zoom = idx >= 0 ? my_zoom_table[idx] : zoom09;
3139 if( zoom < zoom09 ) zoom = zoom09;
3142 if( gui->shift_down() ) {
3146 default: // fall thru
3149 float cx = get_cursor_x(), cy = get_cursor_y();
3150 set_zoom(mwindow->edl, zoom, cx, cy);
3151 gui->zoom_panel->update(zoom);
3152 gui->update_canvas();
3158 void CWindowCanvas::calculate_origin()
3160 float zoom_x, zoom_y, conformed_w, conformed_h;
3161 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3162 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3163 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3164 gui->x_origin = (float)get_cursor_x() / zoom_x + gui->x_offset;
3165 gui->y_origin = (float)get_cursor_y() / zoom_y + gui->y_offset;
3169 int CWindowCanvas::cursor_leave_event()
3171 set_cursor(ARROW_CURSOR);
3175 int CWindowCanvas::cursor_enter_event()
3178 switch( mwindow->edl->session->cwindow_operation ) {
3179 case CWINDOW_CAMERA:
3180 case CWINDOW_PROJECTOR:
3181 set_cursor(MOVE_CURSOR);
3184 set_cursor(MOVE_CURSOR);
3187 test_crop(0, redraw);
3189 case CWINDOW_PROTECT:
3190 set_cursor(ARROW_CURSOR);
3194 set_cursor(CROSS_CURSOR);
3196 case CWINDOW_EYEDROP:
3197 set_cursor(CROSS_CURSOR);
3203 int CWindowCanvas::cursor_motion_event()
3205 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3208 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3209 switch( gui->current_operation ) {
3210 case CWINDOW_SCROLL: {
3211 result = do_scroll(mwindow->edl, get_cursor_x(), get_cursor_y());
3215 result = do_ruler(0, 1, 0, 0);
3218 case CWINDOW_CAMERA:
3219 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3222 case CWINDOW_PROJECTOR:
3223 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3227 result = test_crop(0, redraw);
3228 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3229 // __LINE__, result, redraw);
3233 case CWINDOW_MASK_CONTROL_IN:
3234 case CWINDOW_MASK_CONTROL_OUT:
3235 case CWINDOW_MASK_TRANSLATE:
3236 result = do_mask(redraw, rerender, 0, 1, 0);
3239 case CWINDOW_EYEDROP:
3240 result = do_eyedrop(rerender, 0, 0);
3248 // cursor font changes
3250 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3251 // __LINE__, mwindow->edl->session->cwindow_operation);
3252 switch( mwindow->edl->session->cwindow_operation ) {
3254 result = test_crop(0, redraw);
3257 result = do_ruler(0, 1, 0, 0);
3260 result = do_mask(redraw, rerender, 0, 1, 0);
3265 int change_type = rerender ? CHANGE_PARAMS : -1;
3266 gui->sync_parameters(change_type, redraw, redraw_canvas);
3271 int CWindowCanvas::button_press_event()
3275 int redraw_canvas = 0;
3278 if( Canvas::button_press_event() ) return 1;
3280 gui->translating_zoom = gui->shift_down();
3284 if( mwindow->edl->session->cwindow_operation != CWINDOW_PROTECT &&
3285 get_buttonpress() == MIDDLE_BUTTON && !get_canvas()->shift_down() ) {
3286 gui->current_operation = CWINDOW_SCROLL;
3291 switch( mwindow->edl->session->cwindow_operation ) {
3293 result = do_ruler(0, 0, 1, 0);
3296 case CWINDOW_CAMERA:
3297 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3300 case CWINDOW_PROJECTOR:
3301 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3305 result = test_zoom(redraw);
3309 result = test_crop(1, redraw);
3313 switch( get_buttonpress() ) {
3315 result = do_mask(redraw, rerender, 1, 0, 0);
3317 case MIDDLE_BUTTON: { // && shift_down()
3318 result = do_mask_focus();
3319 redraw = redraw_canvas = 1;
3323 result = do_mask(redraw, rerender, 1, 1, 0);
3326 if( result ) redraw_canvas = 1;
3329 case CWINDOW_EYEDROP:
3330 result = do_eyedrop(rerender, 1, 0);
3335 int change_type = rerender ? CHANGE_PARAMS : -1;
3336 gui->sync_parameters(change_type, redraw, redraw_canvas);
3341 int CWindowCanvas::button_release_event()
3344 const char *undo_label = 0;
3346 switch( gui->current_operation ) {
3347 case CWINDOW_SCROLL:
3352 do_ruler(0, 0, 0, 1);
3355 case CWINDOW_CAMERA:
3356 undo_label = _("camera");
3359 case CWINDOW_PROJECTOR:
3360 undo_label = _("projector");
3364 case CWINDOW_MASK_CONTROL_IN:
3365 case CWINDOW_MASK_CONTROL_OUT:
3366 case CWINDOW_MASK_TRANSLATE:
3367 // Finish mask operation
3368 gui->mask_keyframe = 0;
3369 undo_label = _("mask");
3371 case CWINDOW_MASK_ROTATE:
3372 gui->mask_keyframe = 0;
3373 undo_label = _("mask rotate");
3375 case CWINDOW_MASK_SCALE:
3376 gui->mask_keyframe = 0;
3377 undo_label = _("mask scale");
3380 result = Canvas::button_release_event();
3385 mwindow->undo->update_undo_after(undo_label, LOAD_AUTOMATION);
3386 gui->current_operation = CWINDOW_NONE;
3390 void CWindowCanvas::zoom_resize_window(float percentage)
3392 int canvas_w, canvas_h;
3395 // Get required canvas size
3396 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3397 mwindow->edl->session->output_w,
3398 mwindow->edl->session->output_h,
3399 percentage, canvas_w, canvas_h);
3401 // Estimate window size from current borders
3402 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3403 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3405 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3406 mwindow->session->cwindow_w = new_w;
3407 mwindow->session->cwindow_h = new_h;
3409 mwindow->theme->get_cwindow_sizes(gui,
3410 mwindow->session->cwindow_controls);
3412 // Estimate again from new borders
3413 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3414 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3415 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3417 gui->resize_window(new_w, new_h);
3418 gui->resize_event(new_w, new_h);
3421 void CWindowCanvas::toggle_controls()
3423 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3424 gui->resize_event(gui->get_w(), gui->get_h());
3427 int CWindowCanvas::get_controls()
3429 return mwindow->session->cwindow_controls;
3432 int CWindowCanvas::get_clear_color()
3434 int color = mwindow->edl->session->cwindow_clear_color;
3435 if( color < 0 ) color = Canvas::get_clear_color();