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"
63 static double my_zoom_table[] =
76 static int total_zooms = sizeof(my_zoom_table) / sizeof(double);
79 CWindowGUI::CWindowGUI(MWindow *mwindow, CWindow *cwindow)
80 : BC_Window(_(PROGRAM_NAME ": Compositor"),
81 mwindow->session->cwindow_x,
82 mwindow->session->cwindow_y,
83 mwindow->session->cwindow_w,
84 mwindow->session->cwindow_h,
85 xS(100), yS(100), 1, 1, 1,
86 BC_WindowBase::get_resources()->bg_color,
87 mwindow->get_cwindow_display())
89 this->mwindow = mwindow;
90 this->cwindow = cwindow;
92 affected_x = affected_y = affected_z = 0;
94 orig_mask_keyframe = new MaskAuto(0, 0);
96 x_offset = y_offset = 0;
97 x_origin = y_origin = 0;
98 current_operation = CWINDOW_NONE;
102 crop_handle = -1; crop_translate = 0;
103 crop_origin_x = crop_origin_y = 0;
104 crop_origin_x1 = crop_origin_y1 = 0;
105 crop_origin_x2 = crop_origin_y2 = 0;
107 eyedrop_x = eyedrop_y = 0;
108 ruler_origin_x = ruler_origin_y = 0;
109 ruler_handle = -1; ruler_translate = 0;
110 center_x = center_y = center_z = 0;
111 control_in_x = control_in_y = 0;
112 control_out_x = control_out_y = 0;
113 translating_zoom = 0;
117 CWindowGUI::~CWindowGUI()
119 cwindow->stop_playback(1);
120 if( tool_panel ) delete tool_panel;
122 delete composite_panel;
130 delete orig_mask_keyframe;
133 void CWindowGUI::create_objects()
135 lock_window("CWindowGUI::create_objects");
136 set_icon(mwindow->theme->get_image("cwindow_icon"));
138 active = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_active"));
139 inactive = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_inactive"));
140 focus_frame = new VFramePng(mwindow->theme->get_image_data("cwindow_focus.png"));
142 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
143 mwindow->theme->draw_cwindow_bg(this);
146 // Meters required by composite panel
147 meters = new CWindowMeters(mwindow,
149 mwindow->theme->cmeter_x,
150 mwindow->theme->cmeter_y,
151 mwindow->theme->cmeter_h);
152 meters->create_objects();
155 composite_panel = new CPanel(mwindow,
157 mwindow->theme->ccomposite_x,
158 mwindow->theme->ccomposite_y,
159 mwindow->theme->ccomposite_w,
160 mwindow->theme->ccomposite_h);
161 composite_panel->create_objects();
163 canvas = new CWindowCanvas(mwindow, this);
165 canvas->create_objects(mwindow->edl);
167 add_subwindow(timebar = new CTimeBar(mwindow,
169 mwindow->theme->ctimebar_x,
170 mwindow->theme->ctimebar_y,
171 mwindow->theme->ctimebar_w,
172 mwindow->theme->ctimebar_h));
173 timebar->create_objects();
176 add_subwindow(slider = new CWindowSlider(mwindow,
178 mwindow->theme->cslider_x,
179 mwindow->theme->cslider_y,
180 mwindow->theme->cslider_w));
183 transport = new CWindowTransport(mwindow,
185 mwindow->theme->ctransport_x,
186 mwindow->theme->ctransport_y);
187 transport->create_objects();
189 transport->set_slider(slider);
192 edit_panel = new CWindowEditing(mwindow, cwindow);
193 edit_panel->set_meters(meters);
194 edit_panel->create_objects();
196 // add_subwindow(clock = new MainClock(mwindow,
197 // mwindow->theme->ctime_x,
198 // mwindow->theme->ctime_y));
200 zoom_panel = new CWindowZoom(mwindow,
202 mwindow->theme->czoom_x,
203 mwindow->theme->czoom_y,
204 mwindow->theme->czoom_w);
205 zoom_panel->create_objects();
206 zoom_panel->zoom_text->add_item(new BC_MenuItem(auto_zoom = _(AUTO_ZOOM)));
207 if( !mwindow->edl->session->cwindow_scrollbars )
208 zoom_panel->set_text(auto_zoom);
210 // Must create after meter panel
211 tool_panel = new CWindowTool(mwindow, this);
212 tool_panel->Thread::start();
214 set_operation(mwindow->edl->session->cwindow_operation);
219 int CWindowGUI::translation_event()
221 mwindow->session->cwindow_x = get_x();
222 mwindow->session->cwindow_y = get_y();
226 int CWindowGUI::resize_event(int w, int h)
228 mwindow->session->cwindow_x = get_x();
229 mwindow->session->cwindow_y = get_y();
230 mwindow->session->cwindow_w = w;
231 mwindow->session->cwindow_h = h;
233 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
234 mwindow->theme->draw_cwindow_bg(this);
237 composite_panel->reposition_buttons(mwindow->theme->ccomposite_x,
238 mwindow->theme->ccomposite_y, mwindow->theme->ccomposite_h);
240 canvas->set_zoom(mwindow->edl, canvas->get_zoom());
243 timebar->resize_event();
246 slider->reposition_window(mwindow->theme->cslider_x,
247 mwindow->theme->cslider_y,
248 mwindow->theme->cslider_w);
249 // Recalibrate pointer motion range
250 slider->set_position();
253 transport->reposition_buttons(mwindow->theme->ctransport_x,
254 mwindow->theme->ctransport_y);
256 edit_panel->reposition_buttons(mwindow->theme->cedit_x,
257 mwindow->theme->cedit_y);
259 // clock->reposition_window(mwindow->theme->ctime_x,
260 // mwindow->theme->ctime_y);
262 zoom_panel->reposition_window(mwindow->theme->czoom_x,
263 mwindow->theme->czoom_y);
265 // destination->reposition_window(mwindow->theme->cdest_x,
266 // mwindow->theme->cdest_y);
268 meters->reposition_window(mwindow->theme->cmeter_x,
269 mwindow->theme->cmeter_y,
271 mwindow->theme->cmeter_h);
275 BC_WindowBase::resize_event(w, h);
279 int CWindowGUI::button_press_event()
281 if( current_operation == CWINDOW_NONE &&
282 mwindow->edl != 0 && canvas->get_canvas() &&
283 mwindow->edl->session->cwindow_click2play &&
284 canvas->get_canvas()->get_cursor_over_window() ) {
285 switch( get_buttonpress() ) {
287 if( !cwindow->playback_engine->is_playing_back ) {
288 double length = mwindow->edl->tracks->total_playable_length();
289 double position = cwindow->playback_engine->get_tracking_position();
290 if( position >= length ) transport->goto_start();
292 return transport->forward_play->handle_event();
294 if( !cwindow->playback_engine->is_playing_back ) {
295 double position = cwindow->playback_engine->get_tracking_position();
296 if( position <= 0 ) transport->goto_end();
298 return transport->reverse_play->handle_event();
299 case RIGHT_BUTTON: // activates popup
302 return transport->frame_forward_play->handle_event();
304 return transport->frame_reverse_play->handle_event();
307 if( canvas->get_canvas() )
308 return canvas->button_press_event_base(canvas->get_canvas());
312 int CWindowGUI::cursor_leave_event()
314 if( canvas->get_canvas() )
315 return canvas->cursor_leave_event_base(canvas->get_canvas());
319 int CWindowGUI::cursor_enter_event()
321 if( canvas->get_canvas() )
322 return canvas->cursor_enter_event_base(canvas->get_canvas());
326 int CWindowGUI::button_release_event()
328 if( canvas->get_canvas() )
329 return canvas->button_release_event();
333 int CWindowGUI::cursor_motion_event()
335 if( canvas->get_canvas() ) {
336 canvas->get_canvas()->unhide_cursor();
337 return canvas->cursor_motion_event();
348 void CWindowGUI::draw_status(int flush)
350 if( (canvas->get_canvas() && canvas->get_canvas()->get_video_on()) ||
351 canvas->is_processing ) {
353 mwindow->theme->cstatus_x,
354 mwindow->theme->cstatus_y);
357 draw_pixmap(inactive,
358 mwindow->theme->cstatus_x,
359 mwindow->theme->cstatus_y);
363 // printf("CWindowGUI::draw_status %d %d %d\n", __LINE__, mwindow->theme->cstatus_x,
364 // mwindow->theme->cstatus_y);
365 flash(mwindow->theme->cstatus_x,
366 mwindow->theme->cstatus_y,
372 void CWindowGUI::update_canvas(int redraw)
374 float zoom = canvas->get_zoom();
375 zoom_panel->update(zoom);
376 if( mwindow->edl->session->cwindow_operation == CWINDOW_ZOOM ) {
377 if( !zoom ) zoom = canvas->get_auto_zoom(mwindow->edl);
378 composite_panel->cpanel_zoom->update(zoom);
380 canvas->update_scrollbars(mwindow->edl, 0);
381 canvas->reposition_window(mwindow->edl,
382 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
383 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
388 void CWindowGUI::set_operation(int value)
391 case CWINDOW_TOOL_WINDOW:
392 mwindow->edl->session->tool_window = !mwindow->edl->session->tool_window;
393 composite_panel->operation[CWINDOW_TOOL_WINDOW]->update(mwindow->edl->session->tool_window);
394 tool_panel->update_show_window();
396 case CWINDOW_TITLESAFE:
397 mwindow->edl->session->safe_regions = !mwindow->edl->session->safe_regions;
398 composite_panel->operation[CWINDOW_TITLESAFE]->update(mwindow->edl->session->safe_regions);
399 value = mwindow->edl->session->cwindow_operation;
402 mwindow->edl->session->cwindow_operation = value;
403 composite_panel->set_operation(value);
407 edit_panel->update();
408 tool_panel->start_tool(value);
412 void CWindowGUI::update_tool()
414 tool_panel->update_values();
417 int CWindowGUI::close_event()
419 cwindow->hide_window();
424 int CWindowGUI::keypress_event()
427 int cwindow_operation = CWINDOW_NONE;
429 switch( get_keypress() ) {
445 int on = canvas->get_fullscreen() ? 0 : 1;
446 canvas->set_fullscreen(on, 1);
450 canvas->set_fullscreen(0, 1);
454 if( ctrl_down() || shift_down() || alt_down() ) break;
456 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
458 mwindow->gui->unlock_window();
459 lock_window("CWindowGUI::keypress_event 2");
464 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
465 mwindow->clear_entry();
466 mwindow->gui->unlock_window();
467 lock_window("CWindowGUI::keypress_event 3");
472 int alt_down = this->alt_down();
473 int shift_down = this->shift_down();
476 mwindow->gui->lock_window("CWindowGUI::keypress_event 5");
478 mwindow->prev_edit_handle(shift_down);
480 mwindow->move_left();
481 mwindow->gui->unlock_window();
482 lock_window("CWindowGUI::keypress_event 6");
488 if( !ctrl_down() && !alt_down() ) {
491 mwindow->gui->lock_window("CWindowGUI::keypress_event 7");
492 mwindow->move_left();
493 mwindow->gui->unlock_window();
494 lock_window("CWindowGUI::keypress_event 8");
501 int alt_down = this->alt_down();
502 int shift_down = this->shift_down();
505 mwindow->gui->lock_window("CWindowGUI::keypress_event 8");
507 mwindow->next_edit_handle(shift_down);
509 mwindow->move_right();
510 mwindow->gui->unlock_window();
511 lock_window("CWindowGUI::keypress_event 9");
517 if( !ctrl_down() && !alt_down() ) {
520 mwindow->gui->lock_window("CWindowGUI::keypress_event 10");
521 mwindow->move_right();
522 mwindow->gui->unlock_window();
523 lock_window("CWindowGUI::keypress_event 11");
529 if( !result && cwindow_operation < 0 && ctrl_down() && shift_down() ) {
530 switch( get_keypress() ) {
531 case KEY_F1 ... KEY_F4: // mainmenu, load layout
532 resend_event(mwindow->gui);
537 if( !result && !ctrl_down() ) {
538 switch( get_keypress() ) {
541 mwindow->toggle_camera_xyz(); result = 1;
544 cwindow_operation = CWINDOW_PROTECT;
548 mwindow->toggle_projector_xyz(); result = 1;
551 cwindow_operation = CWINDOW_ZOOM;
555 if( !result && cwindow_operation < 0 && !ctrl_down() && !shift_down() ) {
556 switch( get_keypress() ) {
557 case KEY_F3: cwindow_operation = CWINDOW_MASK; break;
558 case KEY_F4: cwindow_operation = CWINDOW_RULER; break;
559 case KEY_F5: cwindow_operation = CWINDOW_CAMERA; break;
560 case KEY_F6: cwindow_operation = CWINDOW_PROJECTOR; break;
561 case KEY_F7: cwindow_operation = CWINDOW_CROP; break;
562 case KEY_F8: cwindow_operation = CWINDOW_EYEDROP; break;
563 case KEY_F9: cwindow_operation = CWINDOW_TOOL_WINDOW; break;
564 case KEY_F10: cwindow_operation = CWINDOW_TITLESAFE; break;
567 if( !result && cwindow_operation < 0 && !ctrl_down() ) {
568 switch( get_keypress() ) {
571 canvas->reset_camera();
573 canvas->camera_keyframe();
578 canvas->reset_projector();
580 canvas->projector_keyframe();
586 if( cwindow_operation >= 0 ) {
587 set_operation(cwindow_operation);
592 result = transport->keypress_event();
598 void CWindowGUI::reset_affected()
605 void CWindowGUI::keyboard_zoomin()
607 zoom_panel->zoom_tumbler->handle_up_event();
610 void CWindowGUI::keyboard_zoomout()
612 zoom_panel->zoom_tumbler->handle_down_event();
615 void CWindowGUI::sync_parameters(int change_type, int redraw, int overlay)
621 if( change_type < 0 && !overlay ) return;
623 if( change_type >= 0 ) {
624 mwindow->restart_brender();
625 mwindow->sync_parameters(change_type);
628 mwindow->gui->lock_window("CWindowGUI::sync_parameters");
629 mwindow->gui->draw_overlays(1);
630 mwindow->gui->unlock_window();
632 lock_window("CWindowGUI::sync_parameters");
635 void CWindowGUI::drag_motion()
637 if( get_hidden() ) return;
639 if( mwindow->session->current_operation != DRAG_ASSET &&
640 mwindow->session->current_operation != DRAG_VTRANSITION &&
641 mwindow->session->current_operation != DRAG_VEFFECT ) return;
642 int need_highlight = cursor_above() && get_cursor_over_window();
643 if( highlighted == need_highlight ) return;
644 highlighted = need_highlight;
648 int CWindowGUI::drag_stop()
651 if( get_hidden() ) return 0;
652 if( !highlighted ) return 0;
653 if( mwindow->session->current_operation != DRAG_ASSET &&
654 mwindow->session->current_operation != DRAG_VTRANSITION &&
655 mwindow->session->current_operation != DRAG_VEFFECT) return 0;
660 if( mwindow->session->current_operation == DRAG_ASSET ) {
661 if( mwindow->session->drag_assets->total ||
662 mwindow->session->drag_clips->total ) {
663 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
664 mwindow->undo->update_undo_before(_("insert assets"), 0);
667 if( mwindow->session->drag_assets->total ) {
669 mwindow->load_assets(mwindow->session->drag_assets,
670 mwindow->edl->local_session->get_selectionstart(),
672 mwindow->session->track_highlighted,
674 mwindow->edl->session->labels_follow_edits,
675 mwindow->edl->session->plugins_follow_edits,
676 mwindow->edl->session->autos_follow_edits,
680 if( mwindow->session->drag_clips->total ) {
682 mwindow->paste_edls(mwindow->session->drag_clips,
684 mwindow->session->track_highlighted,
685 mwindow->edl->local_session->get_selectionstart(),
686 mwindow->edl->session->labels_follow_edits,
687 mwindow->edl->session->plugins_follow_edits,
688 mwindow->edl->session->autos_follow_edits,
692 if( mwindow->session->drag_assets->total ||
693 mwindow->session->drag_clips->total ) {
694 mwindow->save_backup();
695 mwindow->restart_brender();
696 mwindow->gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
697 mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
698 mwindow->gui->unlock_window();
699 sync_parameters(CHANGE_ALL);
703 if( mwindow->session->current_operation == DRAG_VEFFECT ) {
704 //printf("CWindowGUI::drag_stop 1\n");
705 Track *affected_track = cwindow->calculate_affected_track();
706 //printf("CWindowGUI::drag_stop 2\n");
708 mwindow->gui->lock_window("CWindowGUI::drag_stop 3");
709 mwindow->insert_effects_cwindow(affected_track);
710 mwindow->session->current_operation = NO_OPERATION;
711 mwindow->gui->unlock_window();
714 if( mwindow->session->current_operation == DRAG_VTRANSITION ) {
715 Track *affected_track = cwindow->calculate_affected_track();
716 mwindow->gui->lock_window("CWindowGUI::drag_stop 4");
717 mwindow->paste_transition_cwindow(affected_track);
718 mwindow->session->current_operation = NO_OPERATION;
719 mwindow->gui->unlock_window();
725 void CWindowGUI::update_meters()
727 if( mwindow->edl->session->cwindow_meter != meters->visible ) {
728 meters->set_meters(meters->meter_count, mwindow->edl->session->cwindow_meter);
729 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
730 resize_event(get_w(), get_h());
734 void CWindowGUI::stop_transport(const char *lock_msg)
736 if( lock_msg ) unlock_window();
737 mwindow->stop_transport();
738 if( lock_msg ) lock_window(lock_msg);
742 CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
743 : EditPanel(mwindow, cwindow->gui, CWINDOW_ID,
744 mwindow->theme->cedit_x, mwindow->theme->cedit_y,
745 mwindow->edl->session->editing_mode,
746 0, // use_editing_mode
764 this->mwindow = mwindow;
765 this->cwindow = cwindow;
768 #define relock_cm(s) \
769 cwindow->gui->unlock_window(); \
770 mwindow->gui->lock_window("CWindowEditing::" s)
771 #define relock_mc(s) \
772 mwindow->gui->unlock_window(); \
773 cwindow->gui->lock_window("CWindowEditing::" s)
774 #define panel_fn(fn, args, s) \
775 CWindowEditing::fn args { relock_cm(#fn); s; relock_mc(#fn); }
777 // transmit lock to mwindow, and run mbutton->edit_panel->s
778 #define panel_btn(fn, args, s) \
779 panel_fn(panel_##fn, args, mwindow->gui->mbuttons->edit_panel->panel_##s)
782 double CWindowEditing::get_position()
784 relock_cm("get_position");
785 double ret = mwindow->edl->local_session->get_selectionstart(1);
786 relock_mc("get_position");
790 void CWindowEditing::set_position(double position)
792 relock_cm("set_position");
793 mwindow->gui->mbuttons->edit_panel->set_position(position);
794 relock_mc("set_position");
797 void CWindowEditing::set_click_to_play(int v)
799 relock_cm("set_position");
800 mwindow->edl->session->cwindow_click2play = v;
801 relock_mc("set_position");
802 click2play->update(v);
806 void panel_btn(stop_transport,(), stop_transport())
807 void panel_btn(toggle_label,(), toggle_label())
808 void panel_btn(next_label,(int cut), next_label(cut))
809 void panel_btn(prev_label,(int cut), prev_label(cut))
810 void panel_btn(next_edit,(int cut), next_edit(cut))
811 void panel_btn(prev_edit,(int cut), prev_edit(cut))
812 void panel_fn(panel_copy_selection,(), mwindow->copy())
813 void CWindowEditing::panel_overwrite_selection() {} // not used
814 void CWindowEditing::panel_splice_selection() {} // not used
815 void panel_btn(set_inpoint,(), set_inpoint())
816 void panel_btn(set_outpoint,(), set_outpoint())
817 void panel_btn(unset_inoutpoint,(), unset_inoutpoint())
818 void panel_fn(panel_to_clip,(), mwindow->to_clip(mwindow->edl, _("main window: "), 0))
819 void panel_btn(cut,(), cut())
820 void panel_btn(paste,(), paste())
821 void panel_btn(fit_selection,(), fit_selection())
822 void panel_btn(fit_autos,(int all), fit_autos(all))
823 void panel_btn(set_editing_mode,(int mode), set_editing_mode(mode))
824 void panel_btn(set_auto_keyframes,(int v), set_auto_keyframes(v))
825 void panel_btn(set_span_keyframes,(int v), set_span_keyframes(v))
826 void panel_btn(set_labels_follow_edits,(int v), set_labels_follow_edits(v))
829 CWindowMeters::CWindowMeters(MWindow *mwindow,
830 CWindowGUI *gui, int x, int y, int h)
831 : MeterPanel(mwindow, gui, x, y, -1, h,
832 mwindow->edl->session->audio_channels,
833 mwindow->edl->session->cwindow_meter,
836 this->mwindow = mwindow;
840 CWindowMeters::~CWindowMeters()
844 int CWindowMeters::change_status_event(int new_status)
846 mwindow->edl->session->cwindow_meter = new_status;
847 gui->update_meters();
854 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
855 : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
856 x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
858 this->mwindow = mwindow;
862 CWindowZoom::~CWindowZoom()
866 void CWindowZoom::update(double value)
868 char string[BCSTRLEN];
869 const char *cp = string;
872 int frac = value >= 1.0f ? 1 :
874 value >= .01f ? 3 : 4;
875 sprintf(string, "x %.*f", frac, value);
879 ZoomPanel::update(cp);
882 int CWindowZoom::handle_event()
884 double value = !strcasecmp(gui->auto_zoom, get_text()) ? 0 : get_value();
885 gui->canvas->set_zoom(mwindow->edl, value);
886 gui->update_canvas();
893 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
894 : BC_PercentageSlider(x, y, 0, pixels, pixels, 0, 1, 0)
896 this->mwindow = mwindow;
897 this->cwindow = cwindow;
898 set_precision(0.00001);
901 CWindowSlider::~CWindowSlider()
905 int CWindowSlider::handle_event()
907 cwindow->update_position((double)get_value());
911 void CWindowSlider::set_position()
913 double new_length = mwindow->edl->tracks->total_length();
914 update(mwindow->theme->cslider_w,
915 mwindow->edl->local_session->get_selectionstart(1),
920 int CWindowSlider::increase_value()
923 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
924 lock_window("CWindowSlider::increase_value");
928 int CWindowSlider::decrease_value()
931 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
932 lock_window("CWindowSlider::decrease_value");
938 CWindowTransport::CWindowTransport(MWindow *mwindow,
939 CWindowGUI *gui, int x, int y)
940 : PlayTransport(mwindow, gui, x, y)
945 EDL* CWindowTransport::get_edl()
950 void CWindowTransport::goto_start()
952 gui->unlock_window();
953 handle_transport(REWIND, 1);
955 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
956 mwindow->goto_start();
957 mwindow->gui->unlock_window();
959 gui->lock_window("CWindowTransport::goto_start 2");
962 void CWindowTransport::goto_end()
964 gui->unlock_window();
965 handle_transport(GOTO_END, 1);
967 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
969 mwindow->gui->unlock_window();
971 gui->lock_window("CWindowTransport::goto_end 2");
974 CWindowCanvasToggleControls::CWindowCanvasToggleControls(CWindowCanvas *canvas)
975 : BC_MenuItem(calculate_text(canvas->get_controls()))
977 this->canvas = canvas;
979 int CWindowCanvasToggleControls::handle_event()
981 canvas->toggle_controls();
982 set_text(calculate_text(canvas->get_controls()));
986 const char *CWindowCanvasToggleControls::calculate_text(int controls)
988 return !controls ? _("Show controls") : _("Hide controls");
992 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
993 : Canvas(mwindow, gui,
994 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
995 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h,
996 0, 0, mwindow->edl->session->cwindow_scrollbars)
998 this->mwindow = mwindow;
1006 void CWindowCanvas::create_objects(EDL *edl)
1008 Canvas::create_objects(edl);
1009 canvas_menu->add_item(new CanvasPopupAuto(this));
1010 canvas_menu->add_item(new CanvasPopupResetCamera(this));
1011 canvas_menu->add_item(new CanvasPopupResetProjector(this));
1012 canvas_menu->add_item(new CanvasPopupCameraKeyframe(this));
1013 canvas_menu->add_item(new CanvasPopupProjectorKeyframe(this));
1014 canvas_menu->add_item(controls = new CWindowCanvasToggleControls(this));
1015 fullscreen_menu->add_item(new CanvasPopupAuto(this));
1018 void CWindowCanvas::status_event()
1020 gui->draw_status(1);
1023 void CWindowCanvas::update_zoom(int x, int y, float zoom)
1025 mwindow->edl->session->cwindow_xscroll = x;
1026 mwindow->edl->session->cwindow_yscroll = y;
1027 mwindow->edl->session->cwindow_zoom = zoom;
1028 use_scrollbars = !zoom ? 0 : 1;
1029 mwindow->edl->session->cwindow_scrollbars = use_scrollbars;
1032 int CWindowCanvas::set_fullscreen(int on, int unlock)
1035 if( on && !get_fullscreen() ) {
1036 last_xscroll = get_xscroll();
1037 last_yscroll = get_yscroll();
1038 last_zoom = get_zoom();
1039 Canvas::set_fullscreen(1, unlock);
1043 if( !on && get_fullscreen() ) {
1044 Canvas::set_fullscreen(0, unlock);
1045 gui->zoom_panel->update(get_zoom());
1046 update_zoom(last_xscroll, last_yscroll, last_zoom);
1047 gui->update_canvas();
1053 int CWindowCanvas::get_xscroll()
1055 return mwindow->edl->session->cwindow_xscroll;
1058 int CWindowCanvas::get_yscroll()
1060 return mwindow->edl->session->cwindow_yscroll;
1064 float CWindowCanvas::get_zoom()
1066 return mwindow->edl->session->cwindow_zoom;
1069 void CWindowCanvas::zoom_auto()
1072 set_zoom(mwindow->edl, 0);
1073 gui->update_canvas();
1076 int CWindowCanvas::do_scroll(EDL *edl, float cursor_x, float cursor_y)
1078 float zoom = get_zoom();
1079 float zoom_x, zoom_y, conformed_w, conformed_h;
1080 get_zooms(edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
1082 x = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
1083 y = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
1084 zoom = get_auto_zoom(mwindow->edl);
1087 x = gui->x_origin - cursor_x / zoom_x;
1088 y = gui->y_origin - cursor_y / zoom_y;
1090 update_zoom(x, y, zoom);
1091 gui->update_canvas();
1095 int CWindowCanvas::scope_on()
1097 return !gui->edit_panel->scope_dialog ? 0 :
1098 gui->edit_panel->scope_dialog->running();
1101 void CWindowCanvas::draw_scope(VFrame *output)
1103 if( gui->edit_panel->scope_dialog && output )
1104 gui->edit_panel->scope_dialog->process(output);
1107 void CWindowCanvas::draw_refresh(int flush)
1109 BC_WindowBase *window = get_canvas();
1110 if( window && !window->get_video_on() ) {
1112 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
1113 float in_x1, in_y1, in_x2, in_y2;
1114 float out_x1, out_y1, out_x2, out_y2;
1115 get_transfers(mwindow->edl,
1116 in_x1, in_y1, in_x2, in_y2,
1117 out_x1, out_y1, out_x2, out_y2);
1120 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1121 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1124 if( out_x2 > out_x1 && out_y2 > out_y1 &&
1125 in_x2 > in_x1 && in_y2 > in_y1 ) {
1126 // input scaled from session to refresh frame coordinates
1127 int ow = get_output_w(mwindow->edl);
1128 int oh = get_output_h(mwindow->edl);
1129 int rw = refresh_frame->get_w();
1130 int rh = refresh_frame->get_h();
1131 float xs = (float)rw / ow;
1132 float ys = (float)rh / oh;
1133 in_x1 *= xs; in_x2 *= xs;
1134 in_y1 *= ys; in_y2 *= ys;
1135 // Can't use OpenGL here because it is called asynchronously of the
1136 // playback operation.
1137 window->draw_vframe(refresh_frame,
1138 (int)out_x1, (int)out_y1,
1139 (int)(out_x2 - out_x1),
1140 (int)(out_y2 - out_y1),
1141 (int)in_x1, (int)in_y1,
1142 (int)(in_x2 - in_x1),
1143 (int)(in_y2 - in_y1),
1149 window->flash(flush);
1151 //printf("CWindowCanvas::draw_refresh 10\n");
1154 #define CROPHANDLE_W xS(10)
1155 #define CROPHANDLE_H yS(10)
1157 void CWindowCanvas::draw_crophandle(int x, int y)
1159 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1163 #define CONTROL_W xS(10)
1164 #define CONTROL_H yS(10)
1165 #define FIRST_CONTROL_W xS(20)
1166 #define FIRST_CONTROL_H yS(20)
1168 #define BC_INFINITY 65536
1170 #define RULERHANDLE_W xS(16)
1171 #define RULERHANDLE_H yS(16)
1173 int CWindowCanvas::do_ruler(int draw, int motion,
1174 int button_press, int button_release)
1177 EDLSession *session = mwindow->edl->session;
1178 float x1 = session->ruler_x1;
1179 float y1 = session->ruler_y1;
1180 float x2 = session->ruler_x2;
1181 float y2 = session->ruler_y2;
1182 float canvas_x1 = x1;
1183 float canvas_y1 = y1;
1184 float canvas_x2 = x2;
1185 float canvas_y2 = y2;
1186 float output_x = get_cursor_x();
1187 float output_y = get_cursor_y();
1188 float canvas_cursor_x = output_x;
1189 float canvas_cursor_y = output_y;
1191 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1192 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1193 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1194 mwindow->session->cwindow_output_x = roundf(output_x);
1195 mwindow->session->cwindow_output_y = roundf(output_y);
1197 if( button_press && get_buttonpress() == 1 ) {
1198 gui->ruler_handle = -1;
1199 gui->ruler_translate = 0;
1200 if( gui->alt_down() ) {
1201 gui->ruler_translate = 1;
1202 gui->ruler_origin_x = x1;
1203 gui->ruler_origin_y = y1;
1206 if( canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1207 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1208 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1209 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2 ) {
1210 gui->ruler_handle = 0;
1211 gui->ruler_origin_x = x1;
1212 gui->ruler_origin_y = y1;
1215 if( canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1216 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1217 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1218 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2 ) {
1219 gui->ruler_handle = 1;
1220 gui->ruler_origin_x = x2;
1221 gui->ruler_origin_y = y2;
1225 // Start new selection
1226 if( !gui->ruler_translate &&
1227 (gui->ruler_handle < 0 ||
1231 do_ruler(1, 0, 0, 0);
1232 get_canvas()->flash();
1233 gui->ruler_handle = 1;
1234 session->ruler_x1 = output_x;
1235 session->ruler_y1 = output_y;
1236 session->ruler_x2 = output_x;
1237 session->ruler_y2 = output_y;
1238 gui->ruler_origin_x = session->ruler_x2;
1239 gui->ruler_origin_y = session->ruler_y2;
1242 gui->x_origin = output_x;
1243 gui->y_origin = output_y;
1244 gui->current_operation = CWINDOW_RULER;
1245 gui->tool_panel->raise_window();
1250 if( gui->current_operation == CWINDOW_RULER ) {
1251 if( gui->ruler_translate ) {
1253 do_ruler(1, 0, 0, 0);
1254 float x_difference = session->ruler_x1;
1255 float y_difference = session->ruler_y1;
1256 session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1257 session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1258 x_difference -= session->ruler_x1;
1259 y_difference -= session->ruler_y1;
1260 session->ruler_x2 -= x_difference;
1261 session->ruler_y2 -= y_difference;
1263 do_ruler(1, 0, 0, 0);
1264 get_canvas()->flash();
1268 switch( gui->ruler_handle ) {
1270 do_ruler(1, 0, 0, 0);
1271 session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1272 session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1273 if( gui->alt_down() || gui->ctrl_down() ) {
1274 double angle_value = fabs(atan((session->ruler_y2 - session->ruler_y1) /
1275 (session->ruler_x2 - session->ruler_x1)) *
1277 double distance_value =
1278 sqrt(SQR(session->ruler_x2 - session->ruler_x1) +
1279 SQR(session->ruler_y2 - session->ruler_y1));
1280 if( angle_value < 22 )
1281 session->ruler_y1 = session->ruler_y2;
1283 if( angle_value > 67 )
1284 session->ruler_x1 = session->ruler_x2;
1286 if( session->ruler_x1 < session->ruler_x2 &&
1287 session->ruler_y1 < session->ruler_y2 ) {
1288 session->ruler_x1 = session->ruler_x2 - distance_value / 1.414214;
1289 session->ruler_y1 = session->ruler_y2 - distance_value / 1.414214;
1292 if( session->ruler_x1 < session->ruler_x2 && session->ruler_y1 > session->ruler_y2 ) {
1293 session->ruler_x1 = session->ruler_x2 - distance_value / 1.414214;
1294 session->ruler_y1 = session->ruler_y2 + distance_value / 1.414214;
1297 if( session->ruler_x1 > session->ruler_x2 &&
1298 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 session->ruler_x1 = session->ruler_x2 + distance_value / 1.414214;
1304 session->ruler_y1 = session->ruler_y2 + distance_value / 1.414214;
1307 do_ruler(1, 0, 0, 0);
1308 get_canvas()->flash();
1313 do_ruler(1, 0, 0, 0);
1314 session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1315 session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1316 if( gui->alt_down() || gui->ctrl_down() ) {
1317 double angle_value = fabs(atan((session->ruler_y2 - session->ruler_y1) /
1318 (session->ruler_x2 - session->ruler_x1)) *
1320 double distance_value =
1321 sqrt(SQR(session->ruler_x2 - session->ruler_x1) +
1322 SQR(session->ruler_y2 - session->ruler_y1));
1323 if( angle_value < 22 )
1324 session->ruler_y2 = session->ruler_y1;
1326 if( angle_value > 67 )
1327 session->ruler_x2 = session->ruler_x1;
1329 if( session->ruler_x2 < session->ruler_x1 &&
1330 session->ruler_y2 < session->ruler_y1 ) {
1331 session->ruler_x2 = session->ruler_x1 - distance_value / 1.414214;
1332 session->ruler_y2 = session->ruler_y1 - distance_value / 1.414214;
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 && session->ruler_y2 < session->ruler_y1 ) {
1342 session->ruler_x2 = session->ruler_x1 + distance_value / 1.414214;
1343 session->ruler_y2 = session->ruler_y1 - distance_value / 1.414214;
1346 session->ruler_x2 = session->ruler_x1 + distance_value / 1.414214;
1347 session->ruler_y2 = session->ruler_y1 + distance_value / 1.414214;
1350 do_ruler(1, 0, 0, 0);
1351 get_canvas()->flash();
1356 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1359 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1364 if( canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1365 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1366 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1367 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2 ) {
1368 set_cursor(UPRIGHT_ARROW_CURSOR);
1371 if( canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1372 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1373 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1374 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2 ) {
1375 set_cursor(UPRIGHT_ARROW_CURSOR);
1378 set_cursor(CROSS_CURSOR);
1380 // Update current position
1385 // Assume no ruler measurement if 0 length
1386 if( draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)) ) {
1387 get_canvas()->set_inverse();
1388 get_canvas()->set_color(WHITE);
1389 get_canvas()->draw_line((int)canvas_x1,
1393 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1395 roundf(canvas_x1) + RULERHANDLE_W / 2,
1397 get_canvas()->draw_line(roundf(canvas_x1),
1398 roundf(canvas_y1) - RULERHANDLE_H / 2,
1400 roundf(canvas_y1) + RULERHANDLE_H / 2);
1401 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1403 roundf(canvas_x2) + RULERHANDLE_W / 2,
1405 get_canvas()->draw_line(roundf(canvas_x2),
1406 roundf(canvas_y2) - RULERHANDLE_H / 2,
1408 roundf(canvas_y2) + RULERHANDLE_H / 2);
1409 get_canvas()->set_opaque();
1416 static inline double line_dist(float cx,float cy, float tx,float ty)
1418 double dx = tx-cx, dy = ty-cy;
1419 return sqrt(dx*dx + dy*dy);
1422 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1424 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1425 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1429 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1430 int button_press, int cursor_motion, int draw)
1432 // Retrieve points from top recordable track
1433 //printf("CWindowCanvas::do_mask 1\n");
1434 Track *track = gui->cwindow->calculate_mask_track();
1435 //printf("CWindowCanvas::do_mask 2\n");
1437 if( !track ) return 0;
1438 //printf("CWindowCanvas::do_mask 3\n");
1439 CWindowMaskGUI *mask_gui = (CWindowMaskGUI *)
1440 (gui->tool_panel ? gui->tool_panel->tool_gui : 0);
1441 int draw_markers = mask_gui ? mask_gui->markers : 0;
1442 int draw_boundary = mask_gui ? mask_gui->boundary : 0;
1443 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1444 int64_t position = track->to_units(
1445 mwindow->edl->local_session->get_selectionstart(1),
1447 Auto *prev_auto = 0;
1448 mask_autos->get_prev_auto(position, PLAY_FORWARD, (Auto *&)prev_auto, 1);
1449 MaskAuto *prev_mask = (MaskAuto *)prev_auto;
1451 int update_points = 1;
1452 // Determine the points based on whether
1453 // new keyframes will be generated or drawing is performed.
1454 // If keyframe generation occurs, use the interpolated mask.
1455 // If no keyframe generation occurs, use the previous mask.
1456 int use_interpolated = 0;
1457 if( button_press || cursor_motion ) {
1458 #ifdef USE_KEYFRAME_SPANNING
1459 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1460 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1461 int64_t start_pos = track->to_units(selection_start, 0);
1462 int64_t end_pos = track->to_units(selection_end, 0);
1463 Auto *first = 0, *last = 0;
1464 mask_autos->get_prev_auto(start_pos, PLAY_FORWARD, first, 1);
1465 mask_autos->get_prev_auto(end_pos, PLAY_FORWARD, last, 1);
1466 if( last == first && (!mwindow->edl->session->auto_keyframes) )
1467 use_interpolated = 0;
1469 // If keyframe spanning occurs, use the interpolated points.
1470 // If new keyframe is generated, use the interpolated points.
1471 use_interpolated = 1;
1474 if( mwindow->edl->session->auto_keyframes )
1475 use_interpolated = 1;
1479 use_interpolated = 1;
1481 if( use_interpolated ) {
1482 // Interpolate the points to get exactly what is being rendered at this position.
1483 mask_autos->get_points(&points,
1484 mwindow->edl->session->cwindow_mask,
1485 position, PLAY_FORWARD);
1488 // Use the prev mask
1489 prev_mask->get_points(&points,
1490 mwindow->edl->session->cwindow_mask);
1493 // Projector zooms relative to the center of the track output.
1494 float half_track_w = (float)track->track_w / 2;
1495 float half_track_h = (float)track->track_h / 2;
1496 // Translate mask to projection
1497 float projector_x, projector_y, projector_z;
1498 track->automation->get_projector(
1499 &projector_x, &projector_y, &projector_z,
1500 position, PLAY_FORWARD);
1503 // Get position of cursor relative to mask
1504 float cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
1505 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1506 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1508 projector_x += mwindow->edl->session->output_w / 2;
1509 projector_y += mwindow->edl->session->output_h / 2;
1510 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1511 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1513 // Fix cursor origin
1514 if( button_press ) {
1515 gui->x_origin = mask_cursor_x;
1516 gui->y_origin = mask_cursor_y;
1520 // Points of closest line
1521 int shortest_point1 = -1;
1522 int shortest_point2 = -1;
1524 int shortest_point = -1;
1525 // Distance to closest line
1526 float shortest_line_distance = BC_INFINITY;
1527 // Distance to closest point
1528 float shortest_point_distance = BC_INFINITY;
1529 int selected_point = -1;
1530 int selected_control_point = -1;
1531 float selected_control_point_distance = BC_INFINITY;
1532 ArrayList<int> x_points;
1533 ArrayList<int> y_points;
1535 if( !cursor_motion ) {
1537 get_canvas()->set_color(WHITE);
1538 get_canvas()->set_inverse();
1540 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1542 // Never draw closed polygon and a closed
1543 // polygon is harder to add points to.
1544 for( int i = 0; i < points.size() && !result; i++ ) {
1545 MaskPoint *point1 = points.get(i);
1546 MaskPoint *point2 = (i >= points.size() - 1) ?
1547 points.get(0) : points.get(i + 1);
1548 if( button_press ) {
1549 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1550 if( point_distance1 < shortest_point_distance || shortest_point < 0 ) {
1551 shortest_point_distance = point_distance1;
1555 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1556 if( point_distance2 < shortest_point_distance || shortest_point < 0 ) {
1557 shortest_point_distance = point_distance2;
1558 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1562 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1564 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1565 //point1->x, point1->y, point2->x, point2->y, projector_z);
1566 for( int j = 0; j <= segments && !result; j++ ) {
1567 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1568 float x0 = point1->x, y0 = point1->y;
1569 float x1 = point1->x + point1->control_x2;
1570 float y1 = point1->y + point1->control_y2;
1571 float x2 = point2->x + point2->control_x1;
1572 float y2 = point2->y + point2->control_y1;
1573 float x3 = point2->x, y3 = point2->y;
1574 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1575 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1576 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1577 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1578 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1579 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1580 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1581 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1583 float t = (float)j / segments;
1584 float tpow2 = t * t;
1585 float tpow3 = t * t * t;
1587 float invtpow2 = invt * invt;
1588 float invtpow3 = invt * invt * invt;
1590 float x = ( invtpow3 * x0
1591 + 3 * t * invtpow2 * x1
1592 + 3 * tpow2 * invt * x2
1594 float y = ( invtpow3 * y0
1595 + 3 * t * invtpow2 * y1
1596 + 3 * tpow2 * invt * y2
1598 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1599 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1600 // Test new point addition
1601 if( button_press ) {
1602 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1604 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1605 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1606 if( line_distance < shortest_line_distance ||
1607 shortest_point1 < 0 ) {
1608 shortest_line_distance = line_distance;
1609 shortest_point1 = i;
1610 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1611 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1612 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1615 // Test existing point selection
1617 if( gui->ctrl_down() ) {
1618 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1620 if( distance < selected_control_point_distance ) {
1622 selected_control_point = 1;
1623 selected_control_point_distance = distance;
1627 if( !gui->shift_down() ) {
1628 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1629 if( test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0) ) {
1634 selected_point = shortest_point;
1637 // Test second point
1638 if( gui->ctrl_down() ) {
1639 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1641 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1642 if( distance < selected_control_point_distance ) {
1643 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1644 selected_control_point = 0;
1645 selected_control_point_distance = distance;
1648 else if( i < points.size() - 1 ) {
1649 if( !gui->shift_down() ) {
1650 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1651 if( test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3) ) {
1652 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1656 selected_point = shortest_point;
1661 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1665 if( draw ) { // Draw joining line
1666 x_points.append((int)canvas_x);
1667 y_points.append((int)canvas_y);
1670 if( j == segments ) {
1671 if( draw && draw_markers ) { // Draw second anchor
1672 if( i < points.size() - 1 ) {
1673 if( i == gui->affected_point - 1 )
1674 get_canvas()->draw_disc(
1675 (int)canvas_x - CONTROL_W / 2,
1676 (int)canvas_y - CONTROL_W / 2,
1677 CONTROL_W, CONTROL_H);
1679 get_canvas()->draw_circle(
1680 (int)canvas_x - CONTROL_W / 2,
1681 (int)canvas_y - CONTROL_W / 2,
1682 CONTROL_W, CONTROL_H);
1683 // char string[BCTEXTLEN];
1684 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1685 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1687 // Draw second control point.
1688 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1689 get_canvas()->draw_line(
1690 (int)canvas_x, (int)canvas_y,
1691 (int)canvas_x2, (int)canvas_y2);
1692 get_canvas()->draw_rectangle(
1693 (int)canvas_x2 - CONTROL_W / 2,
1694 (int)canvas_y2 - CONTROL_H / 2,
1695 CONTROL_W, CONTROL_H);
1700 // Draw first anchor
1701 if( i == 0 && draw ) {
1702 if( draw_boundary ) {
1703 char mask_label[BCSTRLEN];
1704 int k = mwindow->edl->session->cwindow_mask;
1705 if( !prev_mask || k < 0 || k >= prev_mask->masks.size() )
1706 sprintf(mask_label, "%d", k);
1708 sprintf(mask_label, "%s", prev_mask->masks[k]->name);
1709 get_canvas()->draw_text(
1710 (int)canvas_x - FIRST_CONTROL_W,
1711 (int)canvas_y - FIRST_CONTROL_H,
1714 if( draw_markers ) {
1715 get_canvas()->draw_disc(
1716 (int)canvas_x - FIRST_CONTROL_W / 2,
1717 (int)canvas_y - FIRST_CONTROL_H / 2,
1718 FIRST_CONTROL_W, FIRST_CONTROL_H);
1722 // Draw first control point.
1723 if( draw && draw_markers ) {
1724 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1725 get_canvas()->draw_line(
1726 (int)canvas_x, (int)canvas_y,
1727 (int)canvas_x1, (int)canvas_y1);
1728 get_canvas()->draw_rectangle(
1729 (int)canvas_x1 - CONTROL_W / 2,
1730 (int)canvas_y1 - CONTROL_H / 2,
1731 CONTROL_W, CONTROL_H);
1733 x_points.append((int)canvas_x);
1734 y_points.append((int)canvas_y);
1737 //printf("CWindowCanvas::do_mask 1\n");
1741 //printf("CWindowCanvas::do_mask 1\n");
1743 BC_WindowBase *cvs_win = get_canvas();
1744 if( draw && draw_boundary ) {
1745 cvs_win->draw_polygon(&x_points, &y_points);
1746 cvs_win->set_opaque();
1748 if( draw && mask_gui && mask_gui->focused ) {
1749 float fx = atof(mask_gui->focus_x->get_text());
1750 float fy = atof(mask_gui->focus_y->get_text());
1751 fx = (fx - half_track_w) * projector_z + projector_x;
1752 fy = (fy - half_track_h) * projector_z + projector_y;
1753 output_to_canvas(mwindow->edl, 0, fx, fy);
1754 float r = bmax(cvs_win->get_w(), cvs_win->get_h());
1757 int fw = 2*d+3, fh = fw;
1758 VFrame focus(fw,fh, BC_RGBA8888);
1759 focus.transfer_from(gui->focus_frame);
1760 fx -= fw/2.f; fy -= fh/2.f;
1761 BC_Pixmap focus_pixmap(cvs_win, &focus, PIXMAP_ALPHA);
1762 cvs_win->draw_pixmap(&focus_pixmap,fx,fy);
1764 cvs_win->set_line_width((int)(0.0025*r) + 1);
1765 cvs_win->set_color(BLUE);
1766 cvs_win->draw_line(fx-d,fy-d, fx+d, fy+d);
1767 cvs_win->draw_line(fx-d,fy+d, fx+d, fy-d);
1768 cvs_win->set_line_width(0);
1769 cvs_win->set_color(WHITE);
1772 if( draw && mask_gui && draw_markers && points.size() ) {
1773 float cx = 0, cy = 0;
1774 int n = points.size();
1775 for( int i=0; i<n; ++i ) {
1776 MaskPoint *point = points.get(i);
1777 cx += point->x; cy += point->y;
1780 if( !mask_gui->focused )
1781 mask_gui->set_focused(0, cx, cy);
1782 cx = (cx - half_track_w) * projector_z + projector_x;
1783 cy = (cy - half_track_h) * projector_z + projector_y;
1784 output_to_canvas(mwindow->edl, 0, cx, cy);
1785 float r = bmax(cvs_win->get_w(), cvs_win->get_h());
1787 cvs_win->set_line_width((int)(0.002*r) + 1);
1788 cvs_win->set_color(ORANGE);
1789 cvs_win->draw_line(cx-d,cy, cx+d, cy);
1790 cvs_win->draw_line(cx,cy-d, cx, cy+d);
1791 cvs_win->set_line_width(0);
1792 cvs_win->set_color(WHITE);
1794 //printf("CWindowCanvas::do_mask 1\n");
1797 if( button_press && !result ) {
1798 gui->affected_track = gui->cwindow->calculate_mask_track();
1800 // Get keyframe outside the EDL to edit. This must be rendered
1801 // instead of the EDL keyframes when it exists. Then it must be
1802 // applied to the EDL keyframes on buttonrelease.
1803 if( gui->affected_track ) {
1804 #ifdef USE_KEYFRAME_SPANNING
1805 // Make copy of current parameters in local keyframe
1806 gui->mask_keyframe =
1807 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1809 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1812 gui->mask_keyframe =
1813 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1817 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1819 if( get_buttonpress() == WHEEL_UP || get_buttonpress() == WHEEL_DOWN ) {
1820 if( !gui->shift_down() ) {
1821 mwindow->undo->update_undo_before(_("mask rotate"), this);
1822 gui->current_operation = CWINDOW_MASK_ROTATE;
1825 mwindow->undo->update_undo_before(_("mask scale"), this);
1826 gui->current_operation = CWINDOW_MASK_SCALE;
1828 gui->affected_point = 0;
1831 // Translate entire keyframe
1832 if( gui->alt_down() && mask->points.size() ) {
1833 mwindow->undo->update_undo_before(_("mask translate"), 0);
1834 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1835 gui->affected_point = 0;
1838 // Existing point or control point was selected
1839 if( selected_point >= 0 ) {
1840 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1841 gui->affected_point = selected_point;
1843 if( selected_control_point == 0 )
1844 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1846 if( selected_control_point == 1 )
1847 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1849 gui->current_operation = mwindow->edl->session->cwindow_operation;
1851 else // No existing point or control point was selected so create a new one
1852 if( !gui->ctrl_down() && !gui->alt_down() ) {
1853 mwindow->undo->update_undo_before(_("mask point"), 0);
1854 // Create the template
1855 MaskPoint *point = new MaskPoint;
1856 point->x = mask_cursor_x;
1857 point->y = mask_cursor_y;
1858 point->control_x1 = 0;
1859 point->control_y1 = 0;
1860 point->control_x2 = 0;
1861 point->control_y2 = 0;
1864 if( shortest_point2 < shortest_point1 ) {
1865 shortest_point2 ^= shortest_point1;
1866 shortest_point1 ^= shortest_point2;
1867 shortest_point2 ^= shortest_point1;
1872 // printf("CWindowGUI::do_mask 40\n");
1873 // mwindow->edl->dump();
1874 // printf("CWindowGUI::do_mask 50\n");
1878 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1879 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1880 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1882 // Append to end of list
1883 if( shortest_point1 == shortest_point2 ||
1884 labs(shortest_point1 - shortest_point2) > 1) {
1885 #ifdef USE_KEYFRAME_SPANNING
1887 MaskPoint *new_point = new MaskPoint;
1888 points.append(new_point);
1889 *new_point = *point;
1890 gui->affected_point = points.size() - 1;
1894 // Need to apply the new point to every keyframe
1895 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1896 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1897 MaskPoint *new_point = new MaskPoint;
1898 submask->points.append(new_point);
1899 *new_point = *point;
1900 if( current == (MaskAuto*)mask_autos->default_auto )
1901 current = (MaskAuto*)mask_autos->first;
1903 current = (MaskAuto*)NEXT;
1905 gui->affected_point = mask->points.size() - 1;
1911 // Insert between 2 points, shifting back point 2
1912 if( shortest_point1 >= 0 && shortest_point2 >= 0 ) {
1914 #ifdef USE_KEYFRAME_SPANNING
1915 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1917 if( points.size() >= shortest_point2 ) {
1918 MaskPoint *new_point = new MaskPoint;
1920 for( int i = points.size() - 1;
1921 i > shortest_point2;
1923 points.values[i] = points.values[i - 1];
1924 points.values[shortest_point2] = new_point;
1926 *new_point = *point;
1931 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1932 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1933 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1935 if( submask->points.size() >= shortest_point2 ) {
1936 MaskPoint *new_point = new MaskPoint;
1937 submask->points.append(0);
1938 for( int i = submask->points.size() - 1;
1939 i > shortest_point2;
1941 submask->points.values[i] = submask->points.values[i - 1];
1942 submask->points.values[shortest_point2] = new_point;
1944 *new_point = *point;
1947 if( current == (MaskAuto*)mask_autos->default_auto )
1948 current = (MaskAuto*)mask_autos->first;
1950 current = (MaskAuto*)NEXT;
1954 gui->affected_point = shortest_point2;
1959 // printf("CWindowGUI::do_mask 20\n");
1960 // mwindow->edl->dump();
1961 // printf("CWindowGUI::do_mask 30\n");
1964 //printf("CWindowCanvas::do_mask 1\n");
1965 // Create the first point.
1966 #ifdef USE_KEYFRAME_SPANNING
1967 MaskPoint *new_point = new MaskPoint;
1968 points.append(new_point);
1969 *new_point = *point;
1970 gui->affected_point = points.size() - 1;
1972 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1973 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1974 MaskPoint *new_point = new MaskPoint;
1975 submask->points.append(new_point);
1976 *new_point = *point;
1977 if( current == (MaskAuto*)mask_autos->default_auto )
1978 current = (MaskAuto*)mask_autos->first;
1980 current = (MaskAuto*)NEXT;
1982 gui->affected_point = points.size() - 1;
1985 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
1988 gui->current_operation = mwindow->edl->session->cwindow_operation;
1989 // Delete the template
1998 if( button_press && result ) {
1999 #ifdef USE_KEYFRAME_SPANNING
2000 MaskPoints &mask_points = points;
2002 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
2003 MaskPoints &mask_points = mask->points;
2005 int k = gui->affected_point;
2006 if( k >= 0 && k < mask_points.size() ) {
2007 MaskPoint *point = mask_points.values[k];
2008 gui->center_x = point->x;
2009 gui->center_y = point->y;
2010 gui->control_in_x = point->control_x1;
2011 gui->control_in_y = point->control_y1;
2012 gui->control_out_x = point->control_x2;
2013 gui->control_out_y = point->control_y2;
2016 gui->center_x = gui->center_y = 0;
2017 gui->control_in_x = gui->control_in_y = 0;
2018 gui->control_out_x = gui->control_out_y = 0;
2020 gui->tool_panel->raise_window();
2023 //printf("CWindowCanvas::do_mask 8\n");
2024 if( cursor_motion ) {
2026 #ifdef USE_KEYFRAME_SPANNING
2027 // Must update the reference keyframes for every cursor motion
2028 gui->mask_keyframe = (MaskAuto*)gui->cwindow->
2029 calculate_affected_auto(mask_autos, 0);
2030 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
2033 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2035 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
2036 if( mask && gui->affected_point >= 0 &&
2037 gui->affected_point < mask->points.size() &&
2038 gui->current_operation != CWINDOW_NONE ) {
2039 // mwindow->undo->update_undo_before(_("mask point"), this);
2040 #ifdef USE_KEYFRAME_SPANNING
2041 MaskPoints &mask_points = points;
2043 MaskPoints &mask_points = mask->points;
2045 MaskPoint *point = mask_points.get(gui->affected_point);
2046 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2047 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask_points.size(), gui->affected_point);
2049 float last_x = point->x;
2050 float last_y = point->y;
2051 float last_control_x1 = point->control_x1;
2052 float last_control_y1 = point->control_y1;
2053 float last_control_x2 = point->control_x2;
2054 float last_control_y2 = point->control_y2;
2057 switch( gui->current_operation ) {
2059 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2060 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
2061 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
2064 case CWINDOW_MASK_CONTROL_IN:
2065 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
2066 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
2069 case CWINDOW_MASK_CONTROL_OUT:
2070 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
2071 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
2074 case CWINDOW_MASK_TRANSLATE: {
2075 if( !mask_gui ) break;
2076 int mode = mask_gui->scale_mode;
2077 MaskAuto *keyframe = gui->mask_keyframe;
2078 int gang = mask_gui->gang_focus->get_value();
2079 float dx = mask_cursor_x - gui->x_origin;
2080 float dy = mask_cursor_y - gui->y_origin;
2081 if( !dx && !dy ) break;
2082 int k = mwindow->edl->session->cwindow_mask;
2083 int n = gang ? keyframe->masks.size() : k+1;
2084 for( int j=gang? 0 : k; j<n; ++j ) {
2085 if( !mask_gui->mask_enables[j]->get_value() ) continue;
2086 SubMask *sub_mask = keyframe->get_submask(j);
2087 if( !sub_mask ) continue;
2088 MaskPoints &points = sub_mask->points;
2089 for( int i=0; i<points.size(); ++i ) {
2090 MaskPoint *point = points[i];
2091 if( mode == MASK_SCALE_X || mode == MASK_SCALE_XY ) point->x += dx;
2092 if( mode == MASK_SCALE_Y || mode == MASK_SCALE_XY ) point->y += dy;
2095 gui->x_origin = mask_cursor_x;
2096 gui->y_origin = mask_cursor_y;
2101 case CWINDOW_MASK_ROTATE:
2103 case CWINDOW_MASK_SCALE: {
2104 if( !mask_gui || !mask_points.size() ) break;
2105 float cx = gui->x_origin, cy = gui->y_origin;
2106 if( mask_gui->focused ) {
2107 cx = atof(mask_gui->focus_x->get_text());
2108 cy = atof(mask_gui->focus_y->get_text());
2110 else if( !gui->ctrl_down() ) {
2112 int n = mask_points.size();
2113 for( int i=0; i<n; ++i ) {
2114 MaskPoint *point = mask_points.values[i];
2115 cx += point->x; cy += point->y;
2118 mask_gui->set_focused(0, cx, cy);
2123 gui->get_triple_click() ? 8. :
2124 gui->get_double_click() ? 4. :
2126 int button_no = get_buttonpress();
2127 double ds = accel/64., dt = accel*M_PI/360.;
2128 double scale = button_no == WHEEL_UP ? 1.+ds : 1.-ds;
2129 int mode = mask_gui->scale_mode;
2130 double xscale = !rotate && (mode == MASK_SCALE_X ||
2131 mode == MASK_SCALE_XY ) ? scale : 1.;
2132 double yscale = !rotate && (mode == MASK_SCALE_Y ||
2133 mode == MASK_SCALE_XY ) ? scale : 1.;
2134 double theta = button_no == WHEEL_UP ? dt : -dt;
2135 if( rotate ? theta==0 : scale==1 ) break;
2136 float st = sin(theta), ct = cos(theta);
2137 MaskAuto *keyframe = gui->mask_keyframe;
2138 int gang = mask_gui->gang_focus->get_value();
2139 int k = mwindow->edl->session->cwindow_mask;
2140 int n = gang ? keyframe->masks.size() : k+1;
2141 for( int j=gang? 0 : k; j<n; ++j ) {
2142 if( !mask_gui->mask_enables[j]->get_value() ) continue;
2143 SubMask *sub_mask = keyframe->get_submask(j);
2144 if( !sub_mask ) continue;
2145 MaskPoints &points = sub_mask->points;
2146 for( int i=0; i<points.size(); ++i ) {
2147 MaskPoint *point = points[i];
2148 float px = point->x - gui->x_origin;
2149 float py = point->y - gui->y_origin;
2150 float nx = !rotate ? px*xscale : px*ct + py*st;
2151 float ny = !rotate ? py*yscale : py*ct - px*st;
2152 point->x = nx + gui->x_origin;
2153 point->y = ny + gui->y_origin;
2154 px = point->control_x1; py = point->control_y1;
2155 point->control_x1 = !rotate ? px*xscale : px*ct + py*st;
2156 point->control_y1 = !rotate ? py*yscale : py*ct - px*st;
2157 px = point->control_x2; py = point->control_y2;
2158 point->control_x2 = !rotate ? px*xscale : px*ct + py*st;
2159 point->control_y2 = !rotate ? py*yscale : py*ct - px*st;
2168 if( !(rerender && redraw) && (!EQUIV(last_x, point->x) ||
2169 !EQUIV(last_y, point->y) ||
2170 !EQUIV(last_control_x1, point->control_x1) ||
2171 !EQUIV(last_control_y1, point->control_y1) ||
2172 !EQUIV(last_control_x2, point->control_x2) ||
2173 !EQUIV(last_control_y2, point->control_y2)) ) {
2179 if( gui->current_operation == CWINDOW_NONE ) {
2180 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
2182 for( int i = 0; i < points.size() && !over_point; i++ ) {
2183 MaskPoint *point = points.get(i);
2184 float x0 = point->x;
2185 float y0 = point->y;
2186 float x1 = point->x + point->control_x1;
2187 float y1 = point->y + point->control_y1;
2188 float x2 = point->x + point->control_x2;
2189 float y2 = point->y + point->control_y2;
2190 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
2191 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
2193 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
2194 if( test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0) ) {
2198 if( !over_point && gui->ctrl_down() ) {
2199 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
2200 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
2201 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2202 if( test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1) ) {
2206 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2207 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2208 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2209 if( test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2) ) {
2216 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2221 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2224 #ifdef USE_KEYFRAME_SPANNING
2225 // Must commit change after operation.
2226 if( rerender && track ) {
2227 // Swap EDL keyframe with original.
2228 // Apply new values to keyframe span
2229 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2230 temp_keyframe.copy_data(gui->mask_keyframe);
2231 // Apply interpolated points back to keyframe
2233 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2234 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2235 mask_autos->update_parameter(&temp_keyframe);
2238 //printf("CWindowCanvas::do_mask 20\n");
2240 if( draw && draw_boundary && !draw_markers ) {
2241 BC_WindowBase *cvs_win = get_canvas();
2242 cvs_win->set_inverse();
2243 cvs_win->set_color(RED+GREEN);
2244 for( int k=0; k<SUBMASKS; ++k ) {
2245 if( k == mwindow->edl->session->cwindow_mask ) continue;
2246 points.remove_all_objects();
2247 if( use_interpolated )
2248 mask_autos->get_points(&points, k, position, PLAY_FORWARD);
2250 prev_mask->get_points(&points, k);
2252 edge.load(points, 0);
2253 for( int i=0; i<edge.size(); ++i ) {
2254 MaskCoord a = edge[i];
2255 MaskCoord b = i<edge.size()-1 ? edge[i+1] : edge[0];
2256 float ax = a.x, ay = a.y;
2257 float bx = b.x, by = b.y;
2258 output_to_canvas(mwindow->edl, 0, ax, ay);
2259 output_to_canvas(mwindow->edl, 0, bx, by);
2260 cvs_win->draw_line(ax,ay, bx,by);
2268 int CWindowCanvas::do_mask_focus()
2270 Track *track = gui->cwindow->calculate_affected_track();
2271 int64_t position = track->to_units(
2272 mwindow->edl->local_session->get_selectionstart(1),
2274 float projector_x, projector_y, projector_z;
2275 track->automation->get_projector(
2276 &projector_x, &projector_y, &projector_z,
2277 position, PLAY_FORWARD);
2278 float cx = get_cursor_x(), cy = get_cursor_y();
2279 canvas_to_output(mwindow->edl, 0, cx, cy);
2280 projector_x += mwindow->edl->session->output_w / 2;
2281 projector_y += mwindow->edl->session->output_h / 2;
2282 float half_track_w = (float)track->track_w / 2;
2283 float half_track_h = (float)track->track_h / 2;
2284 cx = (cx - projector_x) / projector_z + half_track_w;
2285 cy = (cy - projector_y) / projector_z + half_track_h;
2286 CWindowMaskGUI *mask_gui = (CWindowMaskGUI*) gui->tool_panel->tool_gui;
2287 mask_gui->set_focused(1, cx, cy);
2291 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2294 int radius = mwindow->edl->session->eyedrop_radius;
2302 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
2305 row1 = gui->eyedrop_y - radius;
2306 row2 = gui->eyedrop_y + radius;
2307 column1 = gui->eyedrop_x - radius;
2308 column2 = gui->eyedrop_x + radius;
2310 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2311 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2312 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2313 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2315 if( row2 <= row1 ) row2 = row1 + 1;
2316 if( column2 <= column1 ) column2 = column1 + 1;
2323 output_to_canvas(mwindow->edl, 0, x1, y1);
2324 output_to_canvas(mwindow->edl, 0, x2, y2);
2325 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2327 if( x2 - x1 >= 1 && y2 - y1 >= 1 ) {
2328 get_canvas()->set_inverse();
2329 get_canvas()->set_color(WHITE);
2331 get_canvas()->draw_rectangle((int)x1,
2336 get_canvas()->set_opaque();
2337 get_canvas()->flash();
2343 if( button_press ) {
2344 gui->current_operation = CWINDOW_EYEDROP;
2345 gui->tool_panel->raise_window();
2348 if( gui->current_operation == CWINDOW_EYEDROP ) {
2349 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2351 // Get color out of frame.
2352 // Doesn't work during playback because that bypasses the refresh frame.
2353 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
2354 float cursor_x = get_cursor_x();
2355 float cursor_y = get_cursor_y();
2356 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2357 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2358 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2360 row1 = cursor_y - radius;
2361 row2 = cursor_y + radius;
2362 column1 = cursor_x - radius;
2363 column2 = cursor_x + radius;
2364 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2365 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2366 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2367 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2368 if( row2 <= row1 ) row2 = row1 + 1;
2369 if( column2 <= column1 ) column2 = column1 + 1;
2373 if( gui->eyedrop_visible ) {
2375 do_eyedrop(temp, 0, 1);
2376 gui->eyedrop_visible = 0;
2379 gui->eyedrop_x = cursor_x;
2380 gui->eyedrop_y = cursor_y;
2385 do_eyedrop(temp, 0, 1);
2386 gui->eyedrop_visible = 1;
2389 #define GET_COLOR(type, components, max, do_yuv) { \
2390 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2392 float red = (float)*row++ / max; \
2393 float green = (float)*row++ / max; \
2394 float blue = (float)*row++ / max; \
2396 YUV::yuv.yuv_to_rgb_f(red, green, blue, red, green-0.5, blue-0.5); \
2397 mwindow->edl->local_session->red += red; \
2398 mwindow->edl->local_session->green += green; \
2399 mwindow->edl->local_session->blue += blue; \
2400 if( red > mwindow->edl->local_session->red_max ) mwindow->edl->local_session->red_max = red; \
2401 if( green > mwindow->edl->local_session->green_max ) mwindow->edl->local_session->green_max = green; \
2402 if( blue > mwindow->edl->local_session->blue_max ) mwindow->edl->local_session->blue_max = blue; \
2405 mwindow->edl->local_session->red = 0;
2406 mwindow->edl->local_session->green = 0;
2407 mwindow->edl->local_session->blue = 0;
2408 mwindow->edl->local_session->red_max = 0;
2409 mwindow->edl->local_session->green_max = 0;
2410 mwindow->edl->local_session->blue_max = 0;
2411 for( int i = row1; i < row2; i++ ) {
2412 for( int j = column1; j < column2; j++ ) {
2413 switch( refresh_frame->get_color_model() )
2416 GET_COLOR(unsigned char, 3, 0xff, 1);
2419 GET_COLOR(unsigned char, 4, 0xff, 1);
2422 GET_COLOR(uint16_t, 3, 0xffff, 1);
2424 case BC_YUVA16161616:
2425 GET_COLOR(uint16_t, 4, 0xffff, 1);
2428 GET_COLOR(unsigned char, 3, 0xff, 0);
2431 GET_COLOR(unsigned char, 4, 0xff, 0);
2434 GET_COLOR(float, 3, 1.0, 0);
2437 GET_COLOR(float, 4, 1.0, 0);
2443 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2444 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2445 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2449 mwindow->edl->local_session->red = 0;
2450 mwindow->edl->local_session->green = 0;
2451 mwindow->edl->local_session->blue = 0;
2452 gui->eyedrop_visible = 0;
2461 // Can't rerender since the color value is from the output of any effect it
2464 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2470 int CWindowCanvas::need_overlays()
2472 if( mwindow->edl->session->safe_regions ) return 1;
2473 if( mwindow->edl->session->cwindow_scrollbars ) return 1;
2474 if( gui->highlighted ) return 1;
2475 switch( mwindow->edl->session->cwindow_operation ) {
2476 case CWINDOW_EYEDROP:
2477 if( ! gui->eyedrop_visible ) break;
2478 case CWINDOW_CAMERA:
2479 case CWINDOW_PROJECTOR:
2488 void CWindowCanvas::draw_overlays()
2490 if( mwindow->edl->session->safe_regions ) {
2491 draw_safe_regions();
2494 if( mwindow->edl->session->cwindow_scrollbars ) {
2495 // Always draw output rectangle
2496 float x1, y1, x2, y2;
2498 x2 = mwindow->edl->session->output_w;
2500 y2 = mwindow->edl->session->output_h;
2501 output_to_canvas(mwindow->edl, 0, x1, y1);
2502 output_to_canvas(mwindow->edl, 0, x2, y2);
2504 get_canvas()->set_inverse();
2505 get_canvas()->set_color(WHITE);
2506 int ix1 = x1-1, iy1 = y1-1, ix2 = x2+1, iy2 = y2+1;
2507 get_canvas()->draw_rectangle(ix1, iy1, ix2-ix1, iy2-iy1);
2508 get_canvas()->set_opaque();
2511 if( gui->highlighted ) {
2512 get_canvas()->set_color(WHITE);
2513 get_canvas()->set_inverse();
2514 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2515 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2516 get_canvas()->set_opaque();
2519 int temp1 = 0, temp2 = 0;
2520 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2521 switch( mwindow->edl->session->cwindow_operation )
2523 case CWINDOW_CAMERA:
2527 case CWINDOW_PROJECTOR:
2536 do_mask(temp1, temp2, 0, 0, 1);
2540 do_ruler(1, 0, 0, 0);
2543 case CWINDOW_EYEDROP:
2544 if( gui->eyedrop_visible ) {
2546 do_eyedrop(rerender, 0, 1);
2547 gui->eyedrop_visible = 1;
2553 void CWindowCanvas::draw_safe_regions()
2555 float action_x1, action_x2, action_y1, action_y2;
2556 float title_x1, title_x2, title_y1, title_y2;
2558 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2559 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2560 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2561 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2562 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2563 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2564 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2565 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2567 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2568 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2569 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2570 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2572 get_canvas()->set_inverse();
2573 get_canvas()->set_color(WHITE);
2575 get_canvas()->draw_rectangle((int)action_x1,
2577 (int)(action_x2 - action_x1),
2578 (int)(action_y2 - action_y1));
2579 get_canvas()->draw_rectangle((int)title_x1,
2581 (int)(title_x2 - title_x1),
2582 (int)(title_y2 - title_y1));
2584 get_canvas()->set_opaque();
2588 void CWindowCanvas::create_keyframe(int do_camera)
2590 Track *affected_track = gui->cwindow->calculate_affected_track();
2591 if( affected_track ) {
2592 double pos = mwindow->edl->local_session->get_selectionstart(1);
2593 int64_t position = affected_track->to_units(pos, 0);
2594 int ix = do_camera ? AUTOMATION_CAMERA_X : AUTOMATION_PROJECTOR_X;
2595 int iy = do_camera ? AUTOMATION_CAMERA_Y : AUTOMATION_PROJECTOR_Y;
2596 int iz = do_camera ? AUTOMATION_CAMERA_Z : AUTOMATION_PROJECTOR_Z;
2597 FloatAuto *prev, *next;
2598 FloatAutos **autos = (FloatAutos**)affected_track->automation->autos;
2599 FloatAutos *x_autos = autos[ix]; prev = 0; next = 0;
2600 float x_value = x_autos->get_value(position, PLAY_FORWARD, prev, next);
2601 FloatAutos *y_autos = autos[iy]; prev = 0; next = 0;
2602 float y_value = y_autos->get_value(position, PLAY_FORWARD, prev, next);
2603 FloatAutos *z_autos = autos[iz]; prev = 0; next = 0;
2604 float z_value = z_autos->get_value(position, PLAY_FORWARD, prev, next);
2605 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2607 gui->cwindow->calculate_affected_autos(affected_track,
2608 &x_keyframe, &y_keyframe, &z_keyframe,
2609 do_camera, -1, -1, -1, 0);
2610 x_keyframe->set_value(x_value);
2611 y_keyframe->set_value(y_value);
2612 z_keyframe->set_value(z_value);
2614 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2618 void CWindowCanvas::camera_keyframe() { create_keyframe(1); }
2619 void CWindowCanvas::projector_keyframe() { create_keyframe(0); }
2621 void CWindowCanvas::reset_keyframe(int do_camera)
2623 Track *affected_track = gui->cwindow->calculate_affected_track();
2624 if( affected_track ) {
2625 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2626 gui->cwindow->calculate_affected_autos(affected_track,
2627 &x_keyframe, &y_keyframe, &z_keyframe,
2628 do_camera, 1, 1, 1);
2630 x_keyframe->set_value(0);
2631 y_keyframe->set_value(0);
2632 z_keyframe->set_value(1);
2634 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2638 void CWindowCanvas::reset_camera() { reset_keyframe(1); }
2639 void CWindowCanvas::reset_projector() { reset_keyframe(0); }
2642 int CWindowCanvas::test_crop(int button_press, int &redraw)
2645 int handle_selected = -1;
2646 float x1 = mwindow->edl->session->crop_x1;
2647 float y1 = mwindow->edl->session->crop_y1;
2648 float x2 = mwindow->edl->session->crop_x2;
2649 float y2 = mwindow->edl->session->crop_y2;
2650 float cursor_x = get_cursor_x();
2651 float cursor_y = get_cursor_y();
2652 float canvas_x1 = x1;
2653 float canvas_y1 = y1;
2654 float canvas_x2 = x2;
2655 float canvas_y2 = y2;
2656 float canvas_cursor_x = cursor_x;
2657 float canvas_cursor_y = cursor_y;
2659 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2660 // Use screen normalized coordinates for hot spot tests.
2661 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2662 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2665 if( gui->current_operation == CWINDOW_CROP ) {
2666 handle_selected = gui->crop_handle;
2669 if( canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2670 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H ) {
2671 handle_selected = 0;
2672 gui->crop_origin_x = x1;
2673 gui->crop_origin_y = y1;
2676 if( canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2677 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H ) {
2678 handle_selected = 1;
2679 gui->crop_origin_x = x2;
2680 gui->crop_origin_y = y1;
2683 if( canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2684 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2 ) {
2685 handle_selected = 2;
2686 gui->crop_origin_x = x1;
2687 gui->crop_origin_y = y2;
2690 if( canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2691 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2 ) {
2692 handle_selected = 3;
2693 gui->crop_origin_x = x2;
2694 gui->crop_origin_y = y2;
2699 gui->crop_origin_x = cursor_x;
2700 gui->crop_origin_y = cursor_y;
2703 // printf("test crop %d %d\n",
2704 // gui->current_operation,
2705 // handle_selected);
2708 if( button_press ) {
2709 if( gui->alt_down() ) {
2710 gui->crop_translate = 1;
2711 gui->crop_origin_x1 = x1;
2712 gui->crop_origin_y1 = y1;
2713 gui->crop_origin_x2 = x2;
2714 gui->crop_origin_y2 = y2;
2717 gui->crop_translate = 0;
2719 gui->current_operation = CWINDOW_CROP;
2720 gui->crop_handle = handle_selected;
2721 gui->x_origin = cursor_x;
2722 gui->y_origin = cursor_y;
2723 gui->tool_panel->raise_window();
2726 if( handle_selected < 0 && !gui->crop_translate ) {
2729 mwindow->edl->session->crop_x1 = (int)x1;
2730 mwindow->edl->session->crop_y1 = (int)y1;
2731 mwindow->edl->session->crop_x2 = (int)x2;
2732 mwindow->edl->session->crop_y2 = (int)y2;
2737 // Translate all 4 points
2738 if( gui->current_operation == CWINDOW_CROP && gui->crop_translate ) {
2739 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2740 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2741 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2742 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2744 mwindow->edl->session->crop_x1 = (int)x1;
2745 mwindow->edl->session->crop_y1 = (int)y1;
2746 mwindow->edl->session->crop_x2 = (int)x2;
2747 mwindow->edl->session->crop_y2 = (int)y2;
2753 if( gui->current_operation == CWINDOW_CROP ) {
2754 switch( gui->crop_handle ) {
2756 x1 = gui->crop_origin_x;
2757 y1 = gui->crop_origin_y;
2758 x2 = gui->crop_origin_x;
2759 y2 = gui->crop_origin_y;
2760 if( cursor_x < gui->x_origin ) {
2761 if( cursor_y < gui->y_origin ) {
2766 if( cursor_y >= gui->y_origin ) {
2772 if( cursor_x >= gui->x_origin ) {
2773 if( cursor_y < gui->y_origin ) {
2778 if( cursor_y >= gui->y_origin ) {
2784 // printf("test crop %d %d %d %d\n",
2785 // mwindow->edl->session->crop_x1,
2786 // mwindow->edl->session->crop_y1,
2787 // mwindow->edl->session->crop_x2,
2788 // mwindow->edl->session->crop_y2);
2791 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2792 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2795 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2796 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2799 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2800 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2803 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2804 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2808 if( !EQUIV(mwindow->edl->session->crop_x1, x1) ||
2809 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2810 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2811 !EQUIV(mwindow->edl->session->crop_y2, y2) ) {
2816 switch( gui->crop_handle ) {
2817 case 0: gui->crop_handle = 1; break;
2818 case 1: gui->crop_handle = 0; break;
2819 case 2: gui->crop_handle = 3; break;
2820 case 3: gui->crop_handle = 2; break;
2829 switch( gui->crop_handle ) {
2830 case 0: gui->crop_handle = 2; break;
2831 case 1: gui->crop_handle = 3; break;
2832 case 2: gui->crop_handle = 0; break;
2833 case 3: gui->crop_handle = 1; break;
2838 mwindow->edl->session->crop_x1 = (int)x1;
2839 mwindow->edl->session->crop_y1 = (int)y1;
2840 mwindow->edl->session->crop_x2 = (int)x2;
2841 mwindow->edl->session->crop_y2 = (int)y2;
2847 // Update cursor font
2848 if( handle_selected >= 0 ) {
2849 switch( handle_selected ) {
2850 case 0: set_cursor(UPLEFT_RESIZE); break;
2851 case 1: set_cursor(UPRIGHT_RESIZE); break;
2852 case 2: set_cursor(DOWNLEFT_RESIZE); break;
2853 case 3: set_cursor(DOWNRIGHT_RESIZE); break;
2858 set_cursor(ARROW_CURSOR);
2860 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2863 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2864 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2865 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2866 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2867 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2868 // mwindow->edl->session->crop_x2,
2869 // mwindow->edl->session->crop_y2,
2870 // mwindow->edl->calculate_output_w(0),
2871 // mwindow->edl->calculate_output_h(0));
2877 void CWindowCanvas::draw_crop()
2879 get_canvas()->set_inverse();
2880 get_canvas()->set_color(WHITE);
2882 float x1 = mwindow->edl->session->crop_x1;
2883 float y1 = mwindow->edl->session->crop_y1;
2884 float x2 = mwindow->edl->session->crop_x2;
2885 float y2 = mwindow->edl->session->crop_y2;
2887 output_to_canvas(mwindow->edl, 0, x1, y1);
2888 output_to_canvas(mwindow->edl, 0, x2, y2);
2890 if( x2 - x1 && y2 - y1 )
2891 get_canvas()->draw_rectangle((int)x1,
2896 draw_crophandle((int)x1, (int)y1);
2897 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2898 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2899 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2900 get_canvas()->set_opaque();
2904 void CWindowCanvas::draw_outlines(int do_camera)
2906 Track *track = gui->cwindow->calculate_affected_track();
2908 if( !track ) return;
2910 float proj_x, proj_y, proj_z;
2911 int64_t position = track->to_units(
2912 mwindow->edl->local_session->get_selectionstart(1),
2914 track->automation->get_projector(&proj_x, &proj_y, &proj_z,
2915 position, PLAY_FORWARD);
2917 proj_x += mwindow->edl->session->output_w/2.;
2918 proj_y += mwindow->edl->session->output_h/2.;
2919 float proj_x1 = proj_x - track->track_w/2. * proj_z;
2920 float proj_y1 = proj_y - track->track_h/2. * proj_z;
2921 float proj_x2 = proj_x + track->track_w/2. * proj_z;
2922 float proj_y2 = proj_y + track->track_h/2. * proj_z;
2923 float x1 = proj_x1, x2 = proj_x2;
2924 float y1 = proj_y1, y2 = proj_y2;
2925 output_to_canvas(mwindow->edl, 0, x1, y1);
2926 output_to_canvas(mwindow->edl, 0, x2, y2);
2928 #define DRAW_PROJECTION(offset) \
2929 get_canvas()->draw_rectangle(x1+offset, y1+offset, (x2-x1), (y2-y1)); \
2930 get_canvas()->draw_line(x1+offset, y1+offset, x2+offset, y2+offset); \
2931 get_canvas()->draw_line(x2+offset, y1+offset, x1+offset, y2+offset); \
2934 get_canvas()->set_color(BLACK);
2936 get_canvas()->set_color(do_camera ? GREEN : RED);
2940 float cam_x, cam_y, cam_z;
2941 track->automation->get_camera(&cam_x, &cam_y, &cam_z,
2942 position, PLAY_FORWARD);
2943 cam_x += track->track_w / 2.;
2944 cam_y += track->track_h / 2.;
2945 // follow image, not camera
2946 cam_x = -cam_x; cam_y = -cam_y; cam_z *= proj_z;
2947 float cam_x1 = cam_x * cam_z + proj_x;
2948 float cam_y1 = cam_y * cam_z + proj_y;
2949 float cam_x2 = (cam_x + track->track_w) * cam_z + proj_x;
2950 float cam_y2 = (cam_y + track->track_h) * cam_z + proj_y;
2951 output_to_canvas(mwindow->edl, 0, cam_x1, cam_y1);
2952 output_to_canvas(mwindow->edl, 0, cam_x2, cam_y2);
2953 get_canvas()->set_color(YELLOW);
2954 get_canvas()->draw_rectangle(cam_x1, cam_y1, cam_x2-cam_x1, cam_y2-cam_y1);
2958 int CWindowCanvas::test_bezier(int button_press,
2966 // Processing drag operation.
2967 // Create keyframe during first cursor motion.
2968 if( !button_press ) {
2970 float cursor_x = get_cursor_x();
2971 float cursor_y = get_cursor_y();
2972 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2974 if( gui->current_operation == CWINDOW_CAMERA ||
2975 gui->current_operation == CWINDOW_PROJECTOR ) {
2976 if( !gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom ) {
2977 gui->translating_zoom = 1;
2978 gui->reset_affected();
2980 else if( !gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom ) {
2981 gui->translating_zoom = 0;
2982 gui->reset_affected();
2985 // Get target keyframe
2986 if( !gui->affected_x && !gui->affected_y && !gui->affected_z ) {
2987 if( !gui->affected_track ) return 0;
2988 FloatAutos *affected_x_autos, *affected_y_autos, *affected_z_autos;
2989 FloatAutos** autos = (FloatAutos**) gui->affected_track->automation->autos;
2990 if( mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA ) {
2991 affected_x_autos = autos[AUTOMATION_CAMERA_X];
2992 affected_y_autos = autos[AUTOMATION_CAMERA_Y];
2993 affected_z_autos = autos[AUTOMATION_CAMERA_Z];
2996 affected_x_autos = autos[AUTOMATION_PROJECTOR_X];
2997 affected_y_autos = autos[AUTOMATION_PROJECTOR_Y];
2998 affected_z_autos = autos[AUTOMATION_PROJECTOR_Z];
3000 double position = mwindow->edl->local_session->get_selectionstart(1);
3001 int64_t track_position = gui->affected_track->to_units(position, 0);
3002 FloatAuto *prev_x = 0, *next_x = 0;
3003 float new_x = affected_x_autos->get_value(track_position, PLAY_FORWARD, prev_x, next_x);
3004 FloatAuto *prev_y = 0, *next_y = 0;
3005 float new_y = affected_y_autos->get_value(track_position, PLAY_FORWARD, prev_y, next_y);
3006 FloatAuto *prev_z = 0, *next_z = 0;
3007 float new_z = affected_z_autos->get_value(track_position, PLAY_FORWARD, prev_z, next_z);
3008 int zooming = gui->translating_zoom, created;
3009 gui->affected_x = (FloatAuto*)gui->cwindow->calculate_affected_auto(
3010 affected_x_autos, !zooming, &created, 0);
3012 gui->affected_x->set_value(new_x);
3015 gui->affected_y = (FloatAuto*)gui->cwindow->calculate_affected_auto(
3016 affected_y_autos, !zooming, &created, 0);
3018 gui->affected_y->set_value(new_y);
3021 gui->affected_z = (FloatAuto*)gui->cwindow->calculate_affected_auto(
3022 affected_z_autos, zooming, &created, 0);
3024 gui->affected_z->set_value(new_z);
3029 if( gui->translating_zoom ) {
3030 gui->center_z = gui->affected_z->get_value();
3033 gui->center_x = gui->affected_x->get_value();
3034 gui->center_y = gui->affected_y->get_value();
3041 float x_val = gui->affected_x->get_value();
3042 float y_val = gui->affected_y->get_value();
3043 float z_val = gui->affected_z->get_value();
3045 if( gui->translating_zoom ) {
3046 float z = gui->center_z + (cursor_y - gui->y_origin) / yS(128);
3048 if( !EQUIV(z_val, z) ) {
3053 gui->affected_z->set_value(z);
3056 float dx = cursor_x - gui->x_origin;
3057 float dy = cursor_y - gui->y_origin;
3058 // follow image, not camera
3059 if( gui->current_operation == CWINDOW_CAMERA ) {
3060 dx = -dx / z_val; dy = -dy / z_val;
3062 float x = gui->center_x + dx;
3063 float y = gui->center_y + dy;
3064 gui->affected_x->set_value(x);
3065 gui->affected_y->set_value(y);
3066 if( !EQUIV(x_val, x) || !EQUIV(y_val, y) ) {
3077 // Begin drag operation. Don't create keyframe here.
3079 // Get affected track off of the first recordable video track.
3080 // Calculating based on the alpha channel would require recording what layer
3081 // each output pixel belongs to as they're rendered and stacked. Forget it.
3082 gui->affected_track = gui->cwindow->calculate_affected_track();
3083 gui->reset_affected();
3085 if( gui->affected_track ) {
3087 mwindow->undo->update_undo_before(_("camera"), this);
3089 mwindow->undo->update_undo_before(_("projector"), this);
3091 gui->current_operation =
3092 mwindow->edl->session->cwindow_operation;
3093 gui->tool_panel->raise_window();
3101 int CWindowCanvas::test_zoom(int &redraw)
3104 int button = get_buttonpress();
3105 if( button == LEFT_BUTTON )
3106 button = gui->shift_down() ? WHEEL_DOWN : WHEEL_UP;
3107 if( !(zoom = get_zoom()) )
3108 zoom = get_auto_zoom(mwindow->edl);
3112 for( ; idx < total_zooms; ++idx ) {
3113 if( EQUIV(zoom, my_zoom_table[idx]) ) continue;
3114 if( zoom < my_zoom_table[idx] ) break;
3116 float zoom11 = 1.1f * zoom;
3117 zoom = idx < total_zooms ? my_zoom_table[idx] : zoom11;
3118 if( zoom > zoom11 ) zoom = zoom11;
3121 int idx = total_zooms;
3122 for( ; --idx >= 0; ) {
3123 if( EQUIV(my_zoom_table[idx], zoom) ) continue;
3124 if( my_zoom_table[idx] < zoom ) break;
3126 float zoom09 = 0.9f * zoom;
3127 zoom = idx >= 0 ? my_zoom_table[idx] : zoom09;
3128 if( zoom < zoom09 ) zoom = zoom09;
3131 if( gui->shift_down() ) {
3135 default: // fall thru
3138 float cx = get_cursor_x(), cy = get_cursor_y();
3139 set_zoom(mwindow->edl, zoom, cx, cy);
3140 gui->zoom_panel->update(zoom);
3141 gui->update_canvas();
3147 void CWindowCanvas::calculate_origin()
3149 float zoom_x, zoom_y, conformed_w, conformed_h;
3150 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3151 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3152 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3153 gui->x_origin = (float)get_cursor_x() / zoom_x + gui->x_offset;
3154 gui->y_origin = (float)get_cursor_y() / zoom_y + gui->y_offset;
3158 int CWindowCanvas::cursor_leave_event()
3160 set_cursor(ARROW_CURSOR);
3164 int CWindowCanvas::cursor_enter_event()
3167 switch( mwindow->edl->session->cwindow_operation ) {
3168 case CWINDOW_CAMERA:
3169 case CWINDOW_PROJECTOR:
3170 set_cursor(MOVE_CURSOR);
3173 set_cursor(MOVE_CURSOR);
3176 test_crop(0, redraw);
3178 case CWINDOW_PROTECT:
3179 set_cursor(ARROW_CURSOR);
3183 set_cursor(CROSS_CURSOR);
3185 case CWINDOW_EYEDROP:
3186 set_cursor(CROSS_CURSOR);
3192 int CWindowCanvas::cursor_motion_event()
3194 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3197 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3198 switch( gui->current_operation ) {
3199 case CWINDOW_SCROLL: {
3200 result = do_scroll(mwindow->edl, get_cursor_x(), get_cursor_y());
3204 result = do_ruler(0, 1, 0, 0);
3207 case CWINDOW_CAMERA:
3208 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3211 case CWINDOW_PROJECTOR:
3212 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3216 result = test_crop(0, redraw);
3217 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3218 // __LINE__, result, redraw);
3222 case CWINDOW_MASK_CONTROL_IN:
3223 case CWINDOW_MASK_CONTROL_OUT:
3224 case CWINDOW_MASK_TRANSLATE:
3225 result = do_mask(redraw, rerender, 0, 1, 0);
3228 case CWINDOW_EYEDROP:
3229 result = do_eyedrop(rerender, 0, 0);
3237 // cursor font changes
3239 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3240 // __LINE__, mwindow->edl->session->cwindow_operation);
3241 switch( mwindow->edl->session->cwindow_operation ) {
3243 result = test_crop(0, redraw);
3246 result = do_ruler(0, 1, 0, 0);
3249 result = do_mask(redraw, rerender, 0, 1, 0);
3254 int change_type = rerender ? CHANGE_PARAMS : -1;
3255 gui->sync_parameters(change_type, redraw, redraw_canvas);
3260 int CWindowCanvas::button_press_event()
3264 int redraw_canvas = 0;
3267 if( Canvas::button_press_event() ) return 1;
3269 gui->translating_zoom = gui->shift_down();
3273 if( mwindow->edl->session->cwindow_operation != CWINDOW_PROTECT &&
3274 get_buttonpress() == MIDDLE_BUTTON && !get_canvas()->shift_down() ) {
3275 gui->current_operation = CWINDOW_SCROLL;
3280 switch( mwindow->edl->session->cwindow_operation ) {
3282 result = do_ruler(0, 0, 1, 0);
3285 case CWINDOW_CAMERA:
3286 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3289 case CWINDOW_PROJECTOR:
3290 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3294 result = test_zoom(redraw);
3298 result = test_crop(1, redraw);
3302 switch( get_buttonpress() ) {
3304 result = do_mask(redraw, rerender, 1, 0, 0);
3306 case MIDDLE_BUTTON: { // && shift_down()
3307 result = do_mask_focus();
3308 redraw = redraw_canvas = 1;
3312 result = do_mask(redraw, rerender, 1, 1, 0);
3315 if( result ) redraw_canvas = 1;
3318 case CWINDOW_EYEDROP:
3319 result = do_eyedrop(rerender, 1, 0);
3324 int change_type = rerender ? CHANGE_PARAMS : -1;
3325 gui->sync_parameters(change_type, redraw, redraw_canvas);
3330 int CWindowCanvas::button_release_event()
3333 const char *undo_label = 0;
3335 switch( gui->current_operation ) {
3336 case CWINDOW_SCROLL:
3341 do_ruler(0, 0, 0, 1);
3344 case CWINDOW_CAMERA:
3345 undo_label = _("camera");
3348 case CWINDOW_PROJECTOR:
3349 undo_label = _("projector");
3353 case CWINDOW_MASK_CONTROL_IN:
3354 case CWINDOW_MASK_CONTROL_OUT:
3355 case CWINDOW_MASK_TRANSLATE:
3356 // Finish mask operation
3357 gui->mask_keyframe = 0;
3358 undo_label = _("mask");
3360 case CWINDOW_MASK_ROTATE:
3361 gui->mask_keyframe = 0;
3362 undo_label = _("mask rotate");
3364 case CWINDOW_MASK_SCALE:
3365 gui->mask_keyframe = 0;
3366 undo_label = _("mask scale");
3369 result = Canvas::button_release_event();
3374 mwindow->undo->update_undo_after(undo_label, LOAD_AUTOMATION);
3375 gui->current_operation = CWINDOW_NONE;
3379 void CWindowCanvas::zoom_resize_window(float percentage)
3381 int canvas_w, canvas_h;
3384 // Get required canvas size
3385 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3386 mwindow->edl->session->output_w,
3387 mwindow->edl->session->output_h,
3388 percentage, canvas_w, canvas_h);
3390 // Estimate window size from current borders
3391 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3392 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3394 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3395 mwindow->session->cwindow_w = new_w;
3396 mwindow->session->cwindow_h = new_h;
3398 mwindow->theme->get_cwindow_sizes(gui,
3399 mwindow->session->cwindow_controls);
3401 // Estimate again from new borders
3402 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3403 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3404 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3406 gui->resize_window(new_w, new_h);
3407 gui->resize_event(new_w, new_h);
3410 void CWindowCanvas::toggle_controls()
3412 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3413 gui->resize_event(gui->get_w(), gui->get_h());
3416 int CWindowCanvas::get_controls()
3418 return mwindow->session->cwindow_controls;
3421 int CWindowCanvas::get_clear_color()
3423 int color = mwindow->edl->session->cwindow_clear_color;
3424 if( color < 0 ) color = Canvas::get_clear_color();