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
763 this->mwindow = mwindow;
764 this->cwindow = cwindow;
767 #define relock_cm(s) \
768 cwindow->gui->unlock_window(); \
769 mwindow->gui->lock_window("CWindowEditing::" s)
770 #define relock_mc(s) \
771 mwindow->gui->unlock_window(); \
772 cwindow->gui->lock_window("CWindowEditing::" s)
773 #define panel_fn(fn, args, s) \
774 CWindowEditing::fn args { relock_cm(#fn); s; relock_mc(#fn); }
776 // transmit lock to mwindow, and run mbutton->edit_panel->s
777 #define panel_btn(fn, args, s) \
778 panel_fn(panel_##fn, args, mwindow->gui->mbuttons->edit_panel->panel_##s)
781 double CWindowEditing::get_position()
783 relock_cm("get_position");
784 double ret = mwindow->edl->local_session->get_selectionstart(1);
785 relock_mc("get_position");
789 void CWindowEditing::set_position(double position)
791 relock_cm("set_position");
792 mwindow->gui->mbuttons->edit_panel->set_position(position);
793 relock_mc("set_position");
796 void CWindowEditing::set_click_to_play(int v)
798 relock_cm("set_position");
799 mwindow->edl->session->cwindow_click2play = v;
800 relock_mc("set_position");
801 click2play->update(v);
805 void panel_btn(stop_transport,(), stop_transport())
806 void panel_btn(toggle_label,(), toggle_label())
807 void panel_btn(next_label,(int cut), next_label(cut))
808 void panel_btn(prev_label,(int cut), prev_label(cut))
809 void panel_btn(next_edit,(int cut), next_edit(cut))
810 void panel_btn(prev_edit,(int cut), prev_edit(cut))
811 void panel_fn(panel_copy_selection,(), mwindow->copy())
812 void CWindowEditing::panel_overwrite_selection() {} // not used
813 void CWindowEditing::panel_splice_selection() {} // not used
814 void panel_btn(set_inpoint,(), set_inpoint())
815 void panel_btn(set_outpoint,(), set_outpoint())
816 void panel_btn(unset_inoutpoint,(), unset_inoutpoint())
817 void panel_fn(panel_to_clip,(), mwindow->to_clip(mwindow->edl, _("main window: "), 0))
818 void panel_btn(cut,(), cut())
819 void panel_btn(paste,(), paste())
820 void panel_btn(fit_selection,(), fit_selection())
821 void panel_btn(fit_autos,(int all), fit_autos(all))
822 void panel_btn(set_editing_mode,(int mode), set_editing_mode(mode))
823 void panel_btn(set_auto_keyframes,(int v), set_auto_keyframes(v))
824 void panel_btn(set_span_keyframes,(int v), set_span_keyframes(v))
825 void panel_btn(set_labels_follow_edits,(int v), set_labels_follow_edits(v))
828 CWindowMeters::CWindowMeters(MWindow *mwindow,
829 CWindowGUI *gui, int x, int y, int h)
830 : MeterPanel(mwindow, gui, x, y, -1, h,
831 mwindow->edl->session->audio_channels,
832 mwindow->edl->session->cwindow_meter,
835 this->mwindow = mwindow;
839 CWindowMeters::~CWindowMeters()
843 int CWindowMeters::change_status_event(int new_status)
845 mwindow->edl->session->cwindow_meter = new_status;
846 gui->update_meters();
853 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
854 : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
855 x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
857 this->mwindow = mwindow;
861 CWindowZoom::~CWindowZoom()
865 void CWindowZoom::update(double value)
867 char string[BCSTRLEN];
868 const char *cp = string;
871 int frac = value >= 1.0f ? 1 :
873 value >= .01f ? 3 : 4;
874 sprintf(string, "x %.*f", frac, value);
878 ZoomPanel::update(cp);
881 int CWindowZoom::handle_event()
883 double value = !strcasecmp(gui->auto_zoom, get_text()) ? 0 : get_value();
884 gui->canvas->set_zoom(mwindow->edl, value);
885 gui->update_canvas();
892 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
893 : BC_PercentageSlider(x, y, 0, pixels, pixels, 0, 1, 0)
895 this->mwindow = mwindow;
896 this->cwindow = cwindow;
897 set_precision(0.00001);
900 CWindowSlider::~CWindowSlider()
904 int CWindowSlider::handle_event()
906 cwindow->update_position((double)get_value());
910 void CWindowSlider::set_position()
912 double new_length = mwindow->edl->tracks->total_length();
913 update(mwindow->theme->cslider_w,
914 mwindow->edl->local_session->get_selectionstart(1),
919 int CWindowSlider::increase_value()
922 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
923 lock_window("CWindowSlider::increase_value");
927 int CWindowSlider::decrease_value()
930 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
931 lock_window("CWindowSlider::decrease_value");
937 CWindowTransport::CWindowTransport(MWindow *mwindow,
938 CWindowGUI *gui, int x, int y)
939 : PlayTransport(mwindow, gui, x, y)
944 EDL* CWindowTransport::get_edl()
949 void CWindowTransport::goto_start()
951 gui->unlock_window();
952 handle_transport(REWIND, 1);
954 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
955 mwindow->goto_start();
956 mwindow->gui->unlock_window();
958 gui->lock_window("CWindowTransport::goto_start 2");
961 void CWindowTransport::goto_end()
963 gui->unlock_window();
964 handle_transport(GOTO_END, 1);
966 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
968 mwindow->gui->unlock_window();
970 gui->lock_window("CWindowTransport::goto_end 2");
973 CWindowCanvasToggleControls::CWindowCanvasToggleControls(CWindowCanvas *canvas)
974 : BC_MenuItem(calculate_text(canvas->get_controls()))
976 this->canvas = canvas;
978 int CWindowCanvasToggleControls::handle_event()
980 canvas->toggle_controls();
981 set_text(calculate_text(canvas->get_controls()));
985 const char *CWindowCanvasToggleControls::calculate_text(int controls)
987 return !controls ? _("Show controls") : _("Hide controls");
991 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
992 : Canvas(mwindow, gui,
993 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
994 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h,
995 0, 0, mwindow->edl->session->cwindow_scrollbars)
997 this->mwindow = mwindow;
1005 void CWindowCanvas::create_objects(EDL *edl)
1007 Canvas::create_objects(edl);
1008 canvas_menu->add_item(new CanvasPopupAuto(this));
1009 canvas_menu->add_item(new CanvasPopupResetCamera(this));
1010 canvas_menu->add_item(new CanvasPopupResetProjector(this));
1011 canvas_menu->add_item(new CanvasPopupCameraKeyframe(this));
1012 canvas_menu->add_item(new CanvasPopupProjectorKeyframe(this));
1013 canvas_menu->add_item(controls = new CWindowCanvasToggleControls(this));
1014 fullscreen_menu->add_item(new CanvasPopupAuto(this));
1017 void CWindowCanvas::status_event()
1019 gui->draw_status(1);
1022 void CWindowCanvas::update_zoom(int x, int y, float zoom)
1024 mwindow->edl->session->cwindow_xscroll = x;
1025 mwindow->edl->session->cwindow_yscroll = y;
1026 mwindow->edl->session->cwindow_zoom = zoom;
1027 use_scrollbars = !zoom ? 0 : 1;
1028 mwindow->edl->session->cwindow_scrollbars = use_scrollbars;
1031 int CWindowCanvas::set_fullscreen(int on, int unlock)
1034 if( on && !get_fullscreen() ) {
1035 last_xscroll = get_xscroll();
1036 last_yscroll = get_yscroll();
1037 last_zoom = get_zoom();
1038 Canvas::set_fullscreen(1, unlock);
1042 if( !on && get_fullscreen() ) {
1043 Canvas::set_fullscreen(0, unlock);
1044 gui->zoom_panel->update(get_zoom());
1045 update_zoom(last_xscroll, last_yscroll, last_zoom);
1046 gui->update_canvas();
1052 int CWindowCanvas::get_xscroll()
1054 return mwindow->edl->session->cwindow_xscroll;
1057 int CWindowCanvas::get_yscroll()
1059 return mwindow->edl->session->cwindow_yscroll;
1063 float CWindowCanvas::get_zoom()
1065 return mwindow->edl->session->cwindow_zoom;
1068 void CWindowCanvas::zoom_auto()
1071 set_zoom(mwindow->edl, 0);
1072 gui->update_canvas();
1075 int CWindowCanvas::do_scroll(EDL *edl, float cursor_x, float cursor_y)
1077 float zoom = get_zoom();
1078 float zoom_x, zoom_y, conformed_w, conformed_h;
1079 get_zooms(edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
1081 x = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
1082 y = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
1083 zoom = get_auto_zoom(mwindow->edl);
1086 x = gui->x_origin - cursor_x / zoom_x;
1087 y = gui->y_origin - cursor_y / zoom_y;
1089 update_zoom(x, y, zoom);
1090 gui->update_canvas();
1094 void CWindowCanvas::draw_refresh(int flush)
1096 BC_WindowBase *window = get_canvas();
1097 if( window && !window->get_video_on() ) {
1099 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
1100 float in_x1, in_y1, in_x2, in_y2;
1101 float out_x1, out_y1, out_x2, out_y2;
1102 get_transfers(mwindow->edl,
1103 in_x1, in_y1, in_x2, in_y2,
1104 out_x1, out_y1, out_x2, out_y2);
1107 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1108 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1111 if( out_x2 > out_x1 && out_y2 > out_y1 &&
1112 in_x2 > in_x1 && in_y2 > in_y1 ) {
1113 // input scaled from session to refresh frame coordinates
1114 int ow = get_output_w(mwindow->edl);
1115 int oh = get_output_h(mwindow->edl);
1116 int rw = refresh_frame->get_w();
1117 int rh = refresh_frame->get_h();
1118 float xs = (float)rw / ow;
1119 float ys = (float)rh / oh;
1120 in_x1 *= xs; in_x2 *= xs;
1121 in_y1 *= ys; in_y2 *= ys;
1122 // Can't use OpenGL here because it is called asynchronously of the
1123 // playback operation.
1124 window->draw_vframe(refresh_frame,
1125 (int)out_x1, (int)out_y1,
1126 (int)(out_x2 - out_x1),
1127 (int)(out_y2 - out_y1),
1128 (int)in_x1, (int)in_y1,
1129 (int)(in_x2 - in_x1),
1130 (int)(in_y2 - in_y1),
1136 window->flash(flush);
1138 //printf("CWindowCanvas::draw_refresh 10\n");
1141 #define CROPHANDLE_W xS(10)
1142 #define CROPHANDLE_H yS(10)
1144 void CWindowCanvas::draw_crophandle(int x, int y)
1146 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1150 #define CONTROL_W xS(10)
1151 #define CONTROL_H yS(10)
1152 #define FIRST_CONTROL_W xS(20)
1153 #define FIRST_CONTROL_H yS(20)
1155 #define BC_INFINITY 65536
1157 #define RULERHANDLE_W xS(16)
1158 #define RULERHANDLE_H yS(16)
1160 int CWindowCanvas::do_ruler(int draw, int motion,
1161 int button_press, int button_release)
1164 EDLSession *session = mwindow->edl->session;
1165 float x1 = session->ruler_x1;
1166 float y1 = session->ruler_y1;
1167 float x2 = session->ruler_x2;
1168 float y2 = session->ruler_y2;
1169 float canvas_x1 = x1;
1170 float canvas_y1 = y1;
1171 float canvas_x2 = x2;
1172 float canvas_y2 = y2;
1173 float output_x = get_cursor_x();
1174 float output_y = get_cursor_y();
1175 float canvas_cursor_x = output_x;
1176 float canvas_cursor_y = output_y;
1178 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1179 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1180 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1181 mwindow->session->cwindow_output_x = roundf(output_x);
1182 mwindow->session->cwindow_output_y = roundf(output_y);
1184 if( button_press && get_buttonpress() == 1 ) {
1185 gui->ruler_handle = -1;
1186 gui->ruler_translate = 0;
1187 if( gui->alt_down() ) {
1188 gui->ruler_translate = 1;
1189 gui->ruler_origin_x = x1;
1190 gui->ruler_origin_y = y1;
1193 if( canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1194 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1195 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1196 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2 ) {
1197 gui->ruler_handle = 0;
1198 gui->ruler_origin_x = x1;
1199 gui->ruler_origin_y = y1;
1202 if( canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1203 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1204 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1205 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2 ) {
1206 gui->ruler_handle = 1;
1207 gui->ruler_origin_x = x2;
1208 gui->ruler_origin_y = y2;
1212 // Start new selection
1213 if( !gui->ruler_translate &&
1214 (gui->ruler_handle < 0 ||
1218 do_ruler(1, 0, 0, 0);
1219 get_canvas()->flash();
1220 gui->ruler_handle = 1;
1221 session->ruler_x1 = output_x;
1222 session->ruler_y1 = output_y;
1223 session->ruler_x2 = output_x;
1224 session->ruler_y2 = output_y;
1225 gui->ruler_origin_x = session->ruler_x2;
1226 gui->ruler_origin_y = session->ruler_y2;
1229 gui->x_origin = output_x;
1230 gui->y_origin = output_y;
1231 gui->current_operation = CWINDOW_RULER;
1232 gui->tool_panel->raise_window();
1237 if( gui->current_operation == CWINDOW_RULER ) {
1238 if( gui->ruler_translate ) {
1240 do_ruler(1, 0, 0, 0);
1241 float x_difference = session->ruler_x1;
1242 float y_difference = session->ruler_y1;
1243 session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1244 session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1245 x_difference -= session->ruler_x1;
1246 y_difference -= session->ruler_y1;
1247 session->ruler_x2 -= x_difference;
1248 session->ruler_y2 -= y_difference;
1250 do_ruler(1, 0, 0, 0);
1251 get_canvas()->flash();
1255 switch( gui->ruler_handle ) {
1257 do_ruler(1, 0, 0, 0);
1258 session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1259 session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1260 if( gui->alt_down() || gui->ctrl_down() ) {
1261 double angle_value = fabs(atan((session->ruler_y2 - session->ruler_y1) /
1262 (session->ruler_x2 - session->ruler_x1)) *
1264 double distance_value =
1265 sqrt(SQR(session->ruler_x2 - session->ruler_x1) +
1266 SQR(session->ruler_y2 - session->ruler_y1));
1267 if( angle_value < 22 )
1268 session->ruler_y1 = session->ruler_y2;
1270 if( angle_value > 67 )
1271 session->ruler_x1 = session->ruler_x2;
1273 if( session->ruler_x1 < session->ruler_x2 &&
1274 session->ruler_y1 < session->ruler_y2 ) {
1275 session->ruler_x1 = session->ruler_x2 - distance_value / 1.414214;
1276 session->ruler_y1 = session->ruler_y2 - distance_value / 1.414214;
1279 if( session->ruler_x1 < session->ruler_x2 && session->ruler_y1 > session->ruler_y2 ) {
1280 session->ruler_x1 = session->ruler_x2 - distance_value / 1.414214;
1281 session->ruler_y1 = session->ruler_y2 + distance_value / 1.414214;
1284 if( session->ruler_x1 > session->ruler_x2 &&
1285 session->ruler_y1 < session->ruler_y2 ) {
1286 session->ruler_x1 = session->ruler_x2 + distance_value / 1.414214;
1287 session->ruler_y1 = session->ruler_y2 - distance_value / 1.414214;
1290 session->ruler_x1 = session->ruler_x2 + distance_value / 1.414214;
1291 session->ruler_y1 = session->ruler_y2 + distance_value / 1.414214;
1294 do_ruler(1, 0, 0, 0);
1295 get_canvas()->flash();
1300 do_ruler(1, 0, 0, 0);
1301 session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1302 session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1303 if( gui->alt_down() || gui->ctrl_down() ) {
1304 double angle_value = fabs(atan((session->ruler_y2 - session->ruler_y1) /
1305 (session->ruler_x2 - session->ruler_x1)) *
1307 double distance_value =
1308 sqrt(SQR(session->ruler_x2 - session->ruler_x1) +
1309 SQR(session->ruler_y2 - session->ruler_y1));
1310 if( angle_value < 22 )
1311 session->ruler_y2 = session->ruler_y1;
1313 if( angle_value > 67 )
1314 session->ruler_x2 = session->ruler_x1;
1316 if( session->ruler_x2 < session->ruler_x1 &&
1317 session->ruler_y2 < session->ruler_y1 ) {
1318 session->ruler_x2 = session->ruler_x1 - distance_value / 1.414214;
1319 session->ruler_y2 = session->ruler_y1 - distance_value / 1.414214;
1322 if( session->ruler_x2 < session->ruler_x1 &&
1323 session->ruler_y2 > session->ruler_y1 ) {
1324 session->ruler_x2 = session->ruler_x1 - distance_value / 1.414214;
1325 session->ruler_y2 = session->ruler_y1 + distance_value / 1.414214;
1328 if( session->ruler_x2 > session->ruler_x1 && session->ruler_y2 < session->ruler_y1 ) {
1329 session->ruler_x2 = session->ruler_x1 + distance_value / 1.414214;
1330 session->ruler_y2 = session->ruler_y1 - distance_value / 1.414214;
1333 session->ruler_x2 = session->ruler_x1 + distance_value / 1.414214;
1334 session->ruler_y2 = session->ruler_y1 + distance_value / 1.414214;
1337 do_ruler(1, 0, 0, 0);
1338 get_canvas()->flash();
1343 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1346 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1351 if( canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1352 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1353 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1354 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2 ) {
1355 set_cursor(UPRIGHT_ARROW_CURSOR);
1358 if( canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1359 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1360 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1361 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2 ) {
1362 set_cursor(UPRIGHT_ARROW_CURSOR);
1365 set_cursor(CROSS_CURSOR);
1367 // Update current position
1372 // Assume no ruler measurement if 0 length
1373 if( draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)) ) {
1374 get_canvas()->set_inverse();
1375 get_canvas()->set_color(WHITE);
1376 get_canvas()->draw_line((int)canvas_x1,
1380 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1382 roundf(canvas_x1) + RULERHANDLE_W / 2,
1384 get_canvas()->draw_line(roundf(canvas_x1),
1385 roundf(canvas_y1) - RULERHANDLE_H / 2,
1387 roundf(canvas_y1) + RULERHANDLE_H / 2);
1388 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1390 roundf(canvas_x2) + RULERHANDLE_W / 2,
1392 get_canvas()->draw_line(roundf(canvas_x2),
1393 roundf(canvas_y2) - RULERHANDLE_H / 2,
1395 roundf(canvas_y2) + RULERHANDLE_H / 2);
1396 get_canvas()->set_opaque();
1403 static inline double line_dist(float cx,float cy, float tx,float ty)
1405 double dx = tx-cx, dy = ty-cy;
1406 return sqrt(dx*dx + dy*dy);
1409 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1411 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1412 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1416 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1417 int button_press, int cursor_motion, int draw)
1419 // Retrieve points from top recordable track
1420 //printf("CWindowCanvas::do_mask 1\n");
1421 Track *track = gui->cwindow->calculate_mask_track();
1422 //printf("CWindowCanvas::do_mask 2\n");
1424 if( !track ) return 0;
1425 //printf("CWindowCanvas::do_mask 3\n");
1426 CWindowMaskGUI *mask_gui = (CWindowMaskGUI *)
1427 (gui->tool_panel ? gui->tool_panel->tool_gui : 0);
1428 int draw_markers = mask_gui ? mask_gui->markers : 0;
1429 int draw_boundary = mask_gui ? mask_gui->boundary : 0;
1430 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1431 int64_t position = track->to_units(
1432 mwindow->edl->local_session->get_selectionstart(1),
1434 Auto *prev_auto = 0;
1435 mask_autos->get_prev_auto(position, PLAY_FORWARD, (Auto *&)prev_auto, 1);
1436 MaskAuto *prev_mask = (MaskAuto *)prev_auto;
1438 int update_points = 1;
1439 // Determine the points based on whether
1440 // new keyframes will be generated or drawing is performed.
1441 // If keyframe generation occurs, use the interpolated mask.
1442 // If no keyframe generation occurs, use the previous mask.
1443 int use_interpolated = 0;
1444 if( button_press || cursor_motion ) {
1445 #ifdef USE_KEYFRAME_SPANNING
1446 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1447 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1448 int64_t start_pos = track->to_units(selection_start, 0);
1449 int64_t end_pos = track->to_units(selection_end, 0);
1450 Auto *first = 0, *last = 0;
1451 mask_autos->get_prev_auto(start_pos, PLAY_FORWARD, first, 1);
1452 mask_autos->get_prev_auto(end_pos, PLAY_FORWARD, last, 1);
1453 if( last == first && (!mwindow->edl->session->auto_keyframes) )
1454 use_interpolated = 0;
1456 // If keyframe spanning occurs, use the interpolated points.
1457 // If new keyframe is generated, use the interpolated points.
1458 use_interpolated = 1;
1461 if( mwindow->edl->session->auto_keyframes )
1462 use_interpolated = 1;
1466 use_interpolated = 1;
1468 if( use_interpolated ) {
1469 // Interpolate the points to get exactly what is being rendered at this position.
1470 mask_autos->get_points(&points,
1471 mwindow->edl->session->cwindow_mask,
1472 position, PLAY_FORWARD);
1475 // Use the prev mask
1476 prev_mask->get_points(&points,
1477 mwindow->edl->session->cwindow_mask);
1480 // Projector zooms relative to the center of the track output.
1481 float half_track_w = (float)track->track_w / 2;
1482 float half_track_h = (float)track->track_h / 2;
1483 // Translate mask to projection
1484 float projector_x, projector_y, projector_z;
1485 track->automation->get_projector(
1486 &projector_x, &projector_y, &projector_z,
1487 position, PLAY_FORWARD);
1490 // Get position of cursor relative to mask
1491 float cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
1492 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1493 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1495 projector_x += mwindow->edl->session->output_w / 2;
1496 projector_y += mwindow->edl->session->output_h / 2;
1497 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1498 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1500 // Fix cursor origin
1501 if( button_press ) {
1502 gui->x_origin = mask_cursor_x;
1503 gui->y_origin = mask_cursor_y;
1507 // Points of closest line
1508 int shortest_point1 = -1;
1509 int shortest_point2 = -1;
1511 int shortest_point = -1;
1512 // Distance to closest line
1513 float shortest_line_distance = BC_INFINITY;
1514 // Distance to closest point
1515 float shortest_point_distance = BC_INFINITY;
1516 int selected_point = -1;
1517 int selected_control_point = -1;
1518 float selected_control_point_distance = BC_INFINITY;
1519 ArrayList<int> x_points;
1520 ArrayList<int> y_points;
1522 if( !cursor_motion ) {
1524 get_canvas()->set_color(WHITE);
1525 get_canvas()->set_inverse();
1527 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1529 // Never draw closed polygon and a closed
1530 // polygon is harder to add points to.
1531 for( int i = 0; i < points.size() && !result; i++ ) {
1532 MaskPoint *point1 = points.get(i);
1533 MaskPoint *point2 = (i >= points.size() - 1) ?
1534 points.get(0) : points.get(i + 1);
1535 if( button_press ) {
1536 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1537 if( point_distance1 < shortest_point_distance || shortest_point < 0 ) {
1538 shortest_point_distance = point_distance1;
1542 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1543 if( point_distance2 < shortest_point_distance || shortest_point < 0 ) {
1544 shortest_point_distance = point_distance2;
1545 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1549 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1551 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1552 //point1->x, point1->y, point2->x, point2->y, projector_z);
1553 for( int j = 0; j <= segments && !result; j++ ) {
1554 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1555 float x0 = point1->x, y0 = point1->y;
1556 float x1 = point1->x + point1->control_x2;
1557 float y1 = point1->y + point1->control_y2;
1558 float x2 = point2->x + point2->control_x1;
1559 float y2 = point2->y + point2->control_y1;
1560 float x3 = point2->x, y3 = point2->y;
1561 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1562 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1563 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1564 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1565 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1566 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1567 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1568 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1570 float t = (float)j / segments;
1571 float tpow2 = t * t;
1572 float tpow3 = t * t * t;
1574 float invtpow2 = invt * invt;
1575 float invtpow3 = invt * invt * invt;
1577 float x = ( invtpow3 * x0
1578 + 3 * t * invtpow2 * x1
1579 + 3 * tpow2 * invt * x2
1581 float y = ( invtpow3 * y0
1582 + 3 * t * invtpow2 * y1
1583 + 3 * tpow2 * invt * y2
1585 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1586 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1587 // Test new point addition
1588 if( button_press ) {
1589 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1591 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1592 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1593 if( line_distance < shortest_line_distance ||
1594 shortest_point1 < 0 ) {
1595 shortest_line_distance = line_distance;
1596 shortest_point1 = i;
1597 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1598 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1599 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1602 // Test existing point selection
1604 if( gui->ctrl_down() ) {
1605 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1607 if( distance < selected_control_point_distance ) {
1609 selected_control_point = 1;
1610 selected_control_point_distance = distance;
1614 if( !gui->shift_down() ) {
1615 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1616 if( test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0) ) {
1621 selected_point = shortest_point;
1624 // Test second point
1625 if( gui->ctrl_down() ) {
1626 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1628 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1629 if( distance < selected_control_point_distance ) {
1630 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1631 selected_control_point = 0;
1632 selected_control_point_distance = distance;
1635 else if( i < points.size() - 1 ) {
1636 if( !gui->shift_down() ) {
1637 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1638 if( test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3) ) {
1639 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1643 selected_point = shortest_point;
1648 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1652 if( draw ) { // Draw joining line
1653 x_points.append((int)canvas_x);
1654 y_points.append((int)canvas_y);
1657 if( j == segments ) {
1658 if( draw && draw_markers ) { // Draw second anchor
1659 if( i < points.size() - 1 ) {
1660 if( i == gui->affected_point - 1 )
1661 get_canvas()->draw_disc(
1662 (int)canvas_x - CONTROL_W / 2,
1663 (int)canvas_y - CONTROL_W / 2,
1664 CONTROL_W, CONTROL_H);
1666 get_canvas()->draw_circle(
1667 (int)canvas_x - CONTROL_W / 2,
1668 (int)canvas_y - CONTROL_W / 2,
1669 CONTROL_W, CONTROL_H);
1670 // char string[BCTEXTLEN];
1671 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1672 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1674 // Draw second control point.
1675 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1676 get_canvas()->draw_line(
1677 (int)canvas_x, (int)canvas_y,
1678 (int)canvas_x2, (int)canvas_y2);
1679 get_canvas()->draw_rectangle(
1680 (int)canvas_x2 - CONTROL_W / 2,
1681 (int)canvas_y2 - CONTROL_H / 2,
1682 CONTROL_W, CONTROL_H);
1687 // Draw first anchor
1688 if( i == 0 && draw ) {
1689 if( draw_boundary ) {
1690 char mask_label[BCSTRLEN];
1691 int k = mwindow->edl->session->cwindow_mask;
1692 if( !prev_mask || k < 0 || k >= prev_mask->masks.size() )
1693 sprintf(mask_label, "%d", k);
1695 sprintf(mask_label, "%s", prev_mask->masks[k]->name);
1696 get_canvas()->draw_text(
1697 (int)canvas_x - FIRST_CONTROL_W,
1698 (int)canvas_y - FIRST_CONTROL_H,
1701 if( draw_markers ) {
1702 get_canvas()->draw_disc(
1703 (int)canvas_x - FIRST_CONTROL_W / 2,
1704 (int)canvas_y - FIRST_CONTROL_H / 2,
1705 FIRST_CONTROL_W, FIRST_CONTROL_H);
1709 // Draw first control point.
1710 if( draw && draw_markers ) {
1711 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1712 get_canvas()->draw_line(
1713 (int)canvas_x, (int)canvas_y,
1714 (int)canvas_x1, (int)canvas_y1);
1715 get_canvas()->draw_rectangle(
1716 (int)canvas_x1 - CONTROL_W / 2,
1717 (int)canvas_y1 - CONTROL_H / 2,
1718 CONTROL_W, CONTROL_H);
1720 x_points.append((int)canvas_x);
1721 y_points.append((int)canvas_y);
1724 //printf("CWindowCanvas::do_mask 1\n");
1728 //printf("CWindowCanvas::do_mask 1\n");
1730 BC_WindowBase *cvs_win = get_canvas();
1731 if( draw && draw_boundary ) {
1732 cvs_win->draw_polygon(&x_points, &y_points);
1733 cvs_win->set_opaque();
1735 if( draw && mask_gui && mask_gui->focused ) {
1736 float fx = atof(mask_gui->focus_x->get_text());
1737 float fy = atof(mask_gui->focus_y->get_text());
1738 fx = (fx - half_track_w) * projector_z + projector_x;
1739 fy = (fy - half_track_h) * projector_z + projector_y;
1740 output_to_canvas(mwindow->edl, 0, fx, fy);
1741 float r = bmax(cvs_win->get_w(), cvs_win->get_h());
1744 int fw = 2*d+3, fh = fw;
1745 VFrame focus(fw,fh, BC_RGBA8888);
1746 focus.transfer_from(gui->focus_frame);
1747 fx -= fw/2.f; fy -= fh/2.f;
1748 BC_Pixmap focus_pixmap(cvs_win, &focus, PIXMAP_ALPHA);
1749 cvs_win->draw_pixmap(&focus_pixmap,fx,fy);
1751 cvs_win->set_line_width((int)(0.0025*r) + 1);
1752 cvs_win->set_color(BLUE);
1753 cvs_win->draw_line(fx-d,fy-d, fx+d, fy+d);
1754 cvs_win->draw_line(fx-d,fy+d, fx+d, fy-d);
1755 cvs_win->set_line_width(0);
1756 cvs_win->set_color(WHITE);
1759 if( draw && mask_gui && draw_markers && points.size() ) {
1760 float cx = 0, cy = 0;
1761 int n = points.size();
1762 for( int i=0; i<n; ++i ) {
1763 MaskPoint *point = points.get(i);
1764 cx += point->x; cy += point->y;
1767 if( !mask_gui->focused )
1768 mask_gui->set_focused(0, cx, cy);
1769 cx = (cx - half_track_w) * projector_z + projector_x;
1770 cy = (cy - half_track_h) * projector_z + projector_y;
1771 output_to_canvas(mwindow->edl, 0, cx, cy);
1772 float r = bmax(cvs_win->get_w(), cvs_win->get_h());
1774 cvs_win->set_line_width((int)(0.002*r) + 1);
1775 cvs_win->set_color(ORANGE);
1776 cvs_win->draw_line(cx-d,cy, cx+d, cy);
1777 cvs_win->draw_line(cx,cy-d, cx, cy+d);
1778 cvs_win->set_line_width(0);
1779 cvs_win->set_color(WHITE);
1781 //printf("CWindowCanvas::do_mask 1\n");
1784 if( button_press && !result ) {
1785 gui->affected_track = gui->cwindow->calculate_mask_track();
1787 // Get keyframe outside the EDL to edit. This must be rendered
1788 // instead of the EDL keyframes when it exists. Then it must be
1789 // applied to the EDL keyframes on buttonrelease.
1790 if( gui->affected_track ) {
1791 #ifdef USE_KEYFRAME_SPANNING
1792 // Make copy of current parameters in local keyframe
1793 gui->mask_keyframe =
1794 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1796 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1799 gui->mask_keyframe =
1800 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1804 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1806 if( get_buttonpress() == WHEEL_UP || get_buttonpress() == WHEEL_DOWN ) {
1807 if( !gui->shift_down() ) {
1808 mwindow->undo->update_undo_before(_("mask rotate"), this);
1809 gui->current_operation = CWINDOW_MASK_ROTATE;
1812 mwindow->undo->update_undo_before(_("mask scale"), this);
1813 gui->current_operation = CWINDOW_MASK_SCALE;
1815 gui->affected_point = 0;
1818 // Translate entire keyframe
1819 if( gui->alt_down() && mask->points.size() ) {
1820 mwindow->undo->update_undo_before(_("mask translate"), 0);
1821 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1822 gui->affected_point = 0;
1825 // Existing point or control point was selected
1826 if( selected_point >= 0 ) {
1827 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1828 gui->affected_point = selected_point;
1830 if( selected_control_point == 0 )
1831 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1833 if( selected_control_point == 1 )
1834 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1836 gui->current_operation = mwindow->edl->session->cwindow_operation;
1838 else // No existing point or control point was selected so create a new one
1839 if( !gui->ctrl_down() && !gui->alt_down() ) {
1840 mwindow->undo->update_undo_before(_("mask point"), 0);
1841 // Create the template
1842 MaskPoint *point = new MaskPoint;
1843 point->x = mask_cursor_x;
1844 point->y = mask_cursor_y;
1845 point->control_x1 = 0;
1846 point->control_y1 = 0;
1847 point->control_x2 = 0;
1848 point->control_y2 = 0;
1851 if( shortest_point2 < shortest_point1 ) {
1852 shortest_point2 ^= shortest_point1;
1853 shortest_point1 ^= shortest_point2;
1854 shortest_point2 ^= shortest_point1;
1859 // printf("CWindowGUI::do_mask 40\n");
1860 // mwindow->edl->dump();
1861 // printf("CWindowGUI::do_mask 50\n");
1865 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1866 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1867 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1869 // Append to end of list
1870 if( shortest_point1 == shortest_point2 ||
1871 labs(shortest_point1 - shortest_point2) > 1) {
1872 #ifdef USE_KEYFRAME_SPANNING
1874 MaskPoint *new_point = new MaskPoint;
1875 points.append(new_point);
1876 *new_point = *point;
1877 gui->affected_point = points.size() - 1;
1881 // Need to apply the new point to every keyframe
1882 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1883 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1884 MaskPoint *new_point = new MaskPoint;
1885 submask->points.append(new_point);
1886 *new_point = *point;
1887 if( current == (MaskAuto*)mask_autos->default_auto )
1888 current = (MaskAuto*)mask_autos->first;
1890 current = (MaskAuto*)NEXT;
1892 gui->affected_point = mask->points.size() - 1;
1898 // Insert between 2 points, shifting back point 2
1899 if( shortest_point1 >= 0 && shortest_point2 >= 0 ) {
1901 #ifdef USE_KEYFRAME_SPANNING
1902 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1904 if( points.size() >= shortest_point2 ) {
1905 MaskPoint *new_point = new MaskPoint;
1907 for( int i = points.size() - 1;
1908 i > shortest_point2;
1910 points.values[i] = points.values[i - 1];
1911 points.values[shortest_point2] = new_point;
1913 *new_point = *point;
1918 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1919 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1920 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1922 if( submask->points.size() >= shortest_point2 ) {
1923 MaskPoint *new_point = new MaskPoint;
1924 submask->points.append(0);
1925 for( int i = submask->points.size() - 1;
1926 i > shortest_point2;
1928 submask->points.values[i] = submask->points.values[i - 1];
1929 submask->points.values[shortest_point2] = new_point;
1931 *new_point = *point;
1934 if( current == (MaskAuto*)mask_autos->default_auto )
1935 current = (MaskAuto*)mask_autos->first;
1937 current = (MaskAuto*)NEXT;
1941 gui->affected_point = shortest_point2;
1946 // printf("CWindowGUI::do_mask 20\n");
1947 // mwindow->edl->dump();
1948 // printf("CWindowGUI::do_mask 30\n");
1951 //printf("CWindowCanvas::do_mask 1\n");
1952 // Create the first point.
1953 #ifdef USE_KEYFRAME_SPANNING
1954 MaskPoint *new_point = new MaskPoint;
1955 points.append(new_point);
1956 *new_point = *point;
1957 gui->affected_point = points.size() - 1;
1959 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1960 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1961 MaskPoint *new_point = new MaskPoint;
1962 submask->points.append(new_point);
1963 *new_point = *point;
1964 if( current == (MaskAuto*)mask_autos->default_auto )
1965 current = (MaskAuto*)mask_autos->first;
1967 current = (MaskAuto*)NEXT;
1969 gui->affected_point = points.size() - 1;
1972 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
1975 gui->current_operation = mwindow->edl->session->cwindow_operation;
1976 // Delete the template
1985 if( button_press && result ) {
1986 #ifdef USE_KEYFRAME_SPANNING
1987 MaskPoints &mask_points = points;
1989 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1990 MaskPoints &mask_points = mask->points;
1992 int k = gui->affected_point;
1993 if( k >= 0 && k < mask_points.size() ) {
1994 MaskPoint *point = mask_points.values[k];
1995 gui->center_x = point->x;
1996 gui->center_y = point->y;
1997 gui->control_in_x = point->control_x1;
1998 gui->control_in_y = point->control_y1;
1999 gui->control_out_x = point->control_x2;
2000 gui->control_out_y = point->control_y2;
2003 gui->center_x = gui->center_y = 0;
2004 gui->control_in_x = gui->control_in_y = 0;
2005 gui->control_out_x = gui->control_out_y = 0;
2007 gui->tool_panel->raise_window();
2010 //printf("CWindowCanvas::do_mask 8\n");
2011 if( cursor_motion ) {
2013 #ifdef USE_KEYFRAME_SPANNING
2014 // Must update the reference keyframes for every cursor motion
2015 gui->mask_keyframe = (MaskAuto*)gui->cwindow->
2016 calculate_affected_auto(mask_autos, 0);
2017 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
2020 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2022 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
2023 if( mask && gui->affected_point >= 0 &&
2024 gui->affected_point < mask->points.size() &&
2025 gui->current_operation != CWINDOW_NONE ) {
2026 // mwindow->undo->update_undo_before(_("mask point"), this);
2027 #ifdef USE_KEYFRAME_SPANNING
2028 MaskPoints &mask_points = points;
2030 MaskPoints &mask_points = mask->points;
2032 MaskPoint *point = mask_points.get(gui->affected_point);
2033 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2034 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask_points.size(), gui->affected_point);
2036 float last_x = point->x;
2037 float last_y = point->y;
2038 float last_control_x1 = point->control_x1;
2039 float last_control_y1 = point->control_y1;
2040 float last_control_x2 = point->control_x2;
2041 float last_control_y2 = point->control_y2;
2044 switch( gui->current_operation ) {
2046 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2047 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
2048 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
2051 case CWINDOW_MASK_CONTROL_IN:
2052 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
2053 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
2056 case CWINDOW_MASK_CONTROL_OUT:
2057 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
2058 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
2061 case CWINDOW_MASK_TRANSLATE: {
2062 if( !mask_gui ) break;
2063 int mode = mask_gui->scale_mode;
2064 MaskAuto *keyframe = gui->mask_keyframe;
2065 int gang = mask_gui->gang_focus->get_value();
2066 float dx = mask_cursor_x - gui->x_origin;
2067 float dy = mask_cursor_y - gui->y_origin;
2068 if( !dx && !dy ) break;
2069 int k = mwindow->edl->session->cwindow_mask;
2070 int n = gang ? keyframe->masks.size() : k+1;
2071 for( int j=gang? 0 : k; j<n; ++j ) {
2072 if( !mask_gui->mask_enables[j]->get_value() ) continue;
2073 SubMask *sub_mask = keyframe->get_submask(j);
2074 if( !sub_mask ) continue;
2075 MaskPoints &points = sub_mask->points;
2076 for( int i=0; i<points.size(); ++i ) {
2077 MaskPoint *point = points[i];
2078 if( mode == MASK_SCALE_X || mode == MASK_SCALE_XY ) point->x += dx;
2079 if( mode == MASK_SCALE_Y || mode == MASK_SCALE_XY ) point->y += dy;
2082 gui->x_origin = mask_cursor_x;
2083 gui->y_origin = mask_cursor_y;
2088 case CWINDOW_MASK_ROTATE:
2090 case CWINDOW_MASK_SCALE: {
2091 if( !mask_gui || !mask_points.size() ) break;
2092 float cx = gui->x_origin, cy = gui->y_origin;
2093 if( mask_gui->focused ) {
2094 cx = atof(mask_gui->focus_x->get_text());
2095 cy = atof(mask_gui->focus_y->get_text());
2097 else if( !gui->ctrl_down() ) {
2099 int n = mask_points.size();
2100 for( int i=0; i<n; ++i ) {
2101 MaskPoint *point = mask_points.values[i];
2102 cx += point->x; cy += point->y;
2105 mask_gui->set_focused(0, cx, cy);
2110 gui->get_triple_click() ? 8. :
2111 gui->get_double_click() ? 4. :
2113 int button_no = get_buttonpress();
2114 double ds = accel/64., dt = accel*M_PI/360.;
2115 double scale = button_no == WHEEL_UP ? 1.+ds : 1.-ds;
2116 int mode = mask_gui->scale_mode;
2117 double xscale = !rotate && (mode == MASK_SCALE_X ||
2118 mode == MASK_SCALE_XY ) ? scale : 1.;
2119 double yscale = !rotate && (mode == MASK_SCALE_Y ||
2120 mode == MASK_SCALE_XY ) ? scale : 1.;
2121 double theta = button_no == WHEEL_UP ? dt : -dt;
2122 if( rotate ? theta==0 : scale==1 ) break;
2123 float st = sin(theta), ct = cos(theta);
2124 MaskAuto *keyframe = gui->mask_keyframe;
2125 int gang = mask_gui->gang_focus->get_value();
2126 int k = mwindow->edl->session->cwindow_mask;
2127 int n = gang ? keyframe->masks.size() : k+1;
2128 for( int j=gang? 0 : k; j<n; ++j ) {
2129 if( !mask_gui->mask_enables[j]->get_value() ) continue;
2130 SubMask *sub_mask = keyframe->get_submask(j);
2131 if( !sub_mask ) continue;
2132 MaskPoints &points = sub_mask->points;
2133 for( int i=0; i<points.size(); ++i ) {
2134 MaskPoint *point = points[i];
2135 float px = point->x - gui->x_origin;
2136 float py = point->y - gui->y_origin;
2137 float nx = !rotate ? px*xscale : px*ct + py*st;
2138 float ny = !rotate ? py*yscale : py*ct - px*st;
2139 point->x = nx + gui->x_origin;
2140 point->y = ny + gui->y_origin;
2141 px = point->control_x1; py = point->control_y1;
2142 point->control_x1 = !rotate ? px*xscale : px*ct + py*st;
2143 point->control_y1 = !rotate ? py*yscale : py*ct - px*st;
2144 px = point->control_x2; py = point->control_y2;
2145 point->control_x2 = !rotate ? px*xscale : px*ct + py*st;
2146 point->control_y2 = !rotate ? py*yscale : py*ct - px*st;
2155 if( !(rerender && redraw) && (!EQUIV(last_x, point->x) ||
2156 !EQUIV(last_y, point->y) ||
2157 !EQUIV(last_control_x1, point->control_x1) ||
2158 !EQUIV(last_control_y1, point->control_y1) ||
2159 !EQUIV(last_control_x2, point->control_x2) ||
2160 !EQUIV(last_control_y2, point->control_y2)) ) {
2166 if( gui->current_operation == CWINDOW_NONE ) {
2167 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
2169 for( int i = 0; i < points.size() && !over_point; i++ ) {
2170 MaskPoint *point = points.get(i);
2171 float x0 = point->x;
2172 float y0 = point->y;
2173 float x1 = point->x + point->control_x1;
2174 float y1 = point->y + point->control_y1;
2175 float x2 = point->x + point->control_x2;
2176 float y2 = point->y + point->control_y2;
2177 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
2178 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
2180 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
2181 if( test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0) ) {
2185 if( !over_point && gui->ctrl_down() ) {
2186 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
2187 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
2188 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2189 if( test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1) ) {
2193 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2194 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2195 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2196 if( test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2) ) {
2203 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2208 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2211 #ifdef USE_KEYFRAME_SPANNING
2212 // Must commit change after operation.
2213 if( rerender && track ) {
2214 // Swap EDL keyframe with original.
2215 // Apply new values to keyframe span
2216 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2217 temp_keyframe.copy_data(gui->mask_keyframe);
2218 // Apply interpolated points back to keyframe
2220 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2221 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2222 mask_autos->update_parameter(&temp_keyframe);
2225 //printf("CWindowCanvas::do_mask 20\n");
2227 if( draw && draw_boundary && !draw_markers ) {
2228 BC_WindowBase *cvs_win = get_canvas();
2229 cvs_win->set_inverse();
2230 cvs_win->set_color(RED+GREEN);
2231 for( int k=0; k<SUBMASKS; ++k ) {
2232 if( k == mwindow->edl->session->cwindow_mask ) continue;
2233 points.remove_all_objects();
2234 if( use_interpolated )
2235 mask_autos->get_points(&points, k, position, PLAY_FORWARD);
2237 prev_mask->get_points(&points, k);
2239 edge.load(points, 0);
2240 for( int i=0; i<edge.size(); ++i ) {
2241 MaskCoord a = edge[i];
2242 MaskCoord b = i<edge.size()-1 ? edge[i+1] : edge[0];
2243 float ax = a.x, ay = a.y;
2244 float bx = b.x, by = b.y;
2245 output_to_canvas(mwindow->edl, 0, ax, ay);
2246 output_to_canvas(mwindow->edl, 0, bx, by);
2247 cvs_win->draw_line(ax,ay, bx,by);
2255 int CWindowCanvas::do_mask_focus()
2257 Track *track = gui->cwindow->calculate_affected_track();
2258 int64_t position = track->to_units(
2259 mwindow->edl->local_session->get_selectionstart(1),
2261 float projector_x, projector_y, projector_z;
2262 track->automation->get_projector(
2263 &projector_x, &projector_y, &projector_z,
2264 position, PLAY_FORWARD);
2265 float cx = get_cursor_x(), cy = get_cursor_y();
2266 canvas_to_output(mwindow->edl, 0, cx, cy);
2267 projector_x += mwindow->edl->session->output_w / 2;
2268 projector_y += mwindow->edl->session->output_h / 2;
2269 float half_track_w = (float)track->track_w / 2;
2270 float half_track_h = (float)track->track_h / 2;
2271 cx = (cx - projector_x) / projector_z + half_track_w;
2272 cy = (cy - projector_y) / projector_z + half_track_h;
2273 CWindowMaskGUI *mask_gui = (CWindowMaskGUI*) gui->tool_panel->tool_gui;
2274 mask_gui->set_focused(1, cx, cy);
2278 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2281 int radius = mwindow->edl->session->eyedrop_radius;
2289 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
2292 row1 = gui->eyedrop_y - radius;
2293 row2 = gui->eyedrop_y + radius;
2294 column1 = gui->eyedrop_x - radius;
2295 column2 = gui->eyedrop_x + radius;
2297 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2298 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2299 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2300 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2302 if( row2 <= row1 ) row2 = row1 + 1;
2303 if( column2 <= column1 ) column2 = column1 + 1;
2310 output_to_canvas(mwindow->edl, 0, x1, y1);
2311 output_to_canvas(mwindow->edl, 0, x2, y2);
2312 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2314 if( x2 - x1 >= 1 && y2 - y1 >= 1 ) {
2315 get_canvas()->set_inverse();
2316 get_canvas()->set_color(WHITE);
2318 get_canvas()->draw_rectangle((int)x1,
2323 get_canvas()->set_opaque();
2324 get_canvas()->flash();
2330 if( button_press ) {
2331 gui->current_operation = CWINDOW_EYEDROP;
2332 gui->tool_panel->raise_window();
2335 if( gui->current_operation == CWINDOW_EYEDROP ) {
2336 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2338 // Get color out of frame.
2339 // Doesn't work during playback because that bypasses the refresh frame.
2340 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
2341 float cursor_x = get_cursor_x();
2342 float cursor_y = get_cursor_y();
2343 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2344 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2345 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2347 row1 = cursor_y - radius;
2348 row2 = cursor_y + radius;
2349 column1 = cursor_x - radius;
2350 column2 = cursor_x + radius;
2351 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2352 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2353 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2354 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2355 if( row2 <= row1 ) row2 = row1 + 1;
2356 if( column2 <= column1 ) column2 = column1 + 1;
2360 if( gui->eyedrop_visible ) {
2362 do_eyedrop(temp, 0, 1);
2363 gui->eyedrop_visible = 0;
2366 gui->eyedrop_x = cursor_x;
2367 gui->eyedrop_y = cursor_y;
2372 do_eyedrop(temp, 0, 1);
2373 gui->eyedrop_visible = 1;
2376 #define GET_COLOR(type, components, max, do_yuv) { \
2377 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2379 float red = (float)*row++ / max; \
2380 float green = (float)*row++ / max; \
2381 float blue = (float)*row++ / max; \
2383 YUV::yuv.yuv_to_rgb_f(red, green, blue, red, green-0.5, blue-0.5); \
2384 mwindow->edl->local_session->red += red; \
2385 mwindow->edl->local_session->green += green; \
2386 mwindow->edl->local_session->blue += blue; \
2387 if( red > mwindow->edl->local_session->red_max ) mwindow->edl->local_session->red_max = red; \
2388 if( green > mwindow->edl->local_session->green_max ) mwindow->edl->local_session->green_max = green; \
2389 if( blue > mwindow->edl->local_session->blue_max ) mwindow->edl->local_session->blue_max = blue; \
2392 mwindow->edl->local_session->red = 0;
2393 mwindow->edl->local_session->green = 0;
2394 mwindow->edl->local_session->blue = 0;
2395 mwindow->edl->local_session->red_max = 0;
2396 mwindow->edl->local_session->green_max = 0;
2397 mwindow->edl->local_session->blue_max = 0;
2398 for( int i = row1; i < row2; i++ ) {
2399 for( int j = column1; j < column2; j++ ) {
2400 switch( refresh_frame->get_color_model() )
2403 GET_COLOR(unsigned char, 3, 0xff, 1);
2406 GET_COLOR(unsigned char, 4, 0xff, 1);
2409 GET_COLOR(uint16_t, 3, 0xffff, 1);
2411 case BC_YUVA16161616:
2412 GET_COLOR(uint16_t, 4, 0xffff, 1);
2415 GET_COLOR(unsigned char, 3, 0xff, 0);
2418 GET_COLOR(unsigned char, 4, 0xff, 0);
2421 GET_COLOR(float, 3, 1.0, 0);
2424 GET_COLOR(float, 4, 1.0, 0);
2430 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2431 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2432 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2436 mwindow->edl->local_session->red = 0;
2437 mwindow->edl->local_session->green = 0;
2438 mwindow->edl->local_session->blue = 0;
2439 gui->eyedrop_visible = 0;
2448 // Can't rerender since the color value is from the output of any effect it
2451 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2457 int CWindowCanvas::need_overlays()
2459 if( mwindow->edl->session->safe_regions ) return 1;
2460 if( mwindow->edl->session->cwindow_scrollbars ) return 1;
2461 if( gui->highlighted ) return 1;
2462 switch( mwindow->edl->session->cwindow_operation ) {
2463 case CWINDOW_EYEDROP:
2464 if( ! gui->eyedrop_visible ) break;
2465 case CWINDOW_CAMERA:
2466 case CWINDOW_PROJECTOR:
2475 void CWindowCanvas::draw_overlays()
2477 if( mwindow->edl->session->safe_regions ) {
2478 draw_safe_regions();
2481 if( mwindow->edl->session->cwindow_scrollbars ) {
2482 // Always draw output rectangle
2483 float x1, y1, x2, y2;
2485 x2 = mwindow->edl->session->output_w;
2487 y2 = mwindow->edl->session->output_h;
2488 output_to_canvas(mwindow->edl, 0, x1, y1);
2489 output_to_canvas(mwindow->edl, 0, x2, y2);
2491 get_canvas()->set_inverse();
2492 get_canvas()->set_color(WHITE);
2493 int ix1 = x1-1, iy1 = y1-1, ix2 = x2+1, iy2 = y2+1;
2494 get_canvas()->draw_rectangle(ix1, iy1, ix2-ix1, iy2-iy1);
2495 get_canvas()->set_opaque();
2498 if( gui->highlighted ) {
2499 get_canvas()->set_color(WHITE);
2500 get_canvas()->set_inverse();
2501 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2502 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2503 get_canvas()->set_opaque();
2506 int temp1 = 0, temp2 = 0;
2507 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2508 switch( mwindow->edl->session->cwindow_operation )
2510 case CWINDOW_CAMERA:
2514 case CWINDOW_PROJECTOR:
2523 do_mask(temp1, temp2, 0, 0, 1);
2527 do_ruler(1, 0, 0, 0);
2530 case CWINDOW_EYEDROP:
2531 if( gui->eyedrop_visible ) {
2533 do_eyedrop(rerender, 0, 1);
2534 gui->eyedrop_visible = 1;
2540 void CWindowCanvas::draw_safe_regions()
2542 float action_x1, action_x2, action_y1, action_y2;
2543 float title_x1, title_x2, title_y1, title_y2;
2545 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2546 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2547 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2548 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2549 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2550 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2551 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2552 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2554 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2555 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2556 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2557 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2559 get_canvas()->set_inverse();
2560 get_canvas()->set_color(WHITE);
2562 get_canvas()->draw_rectangle((int)action_x1,
2564 (int)(action_x2 - action_x1),
2565 (int)(action_y2 - action_y1));
2566 get_canvas()->draw_rectangle((int)title_x1,
2568 (int)(title_x2 - title_x1),
2569 (int)(title_y2 - title_y1));
2571 get_canvas()->set_opaque();
2575 void CWindowCanvas::create_keyframe(int do_camera)
2577 Track *affected_track = gui->cwindow->calculate_affected_track();
2578 if( affected_track ) {
2579 double pos = mwindow->edl->local_session->get_selectionstart(1);
2580 int64_t position = affected_track->to_units(pos, 0);
2581 int ix = do_camera ? AUTOMATION_CAMERA_X : AUTOMATION_PROJECTOR_X;
2582 int iy = do_camera ? AUTOMATION_CAMERA_Y : AUTOMATION_PROJECTOR_Y;
2583 int iz = do_camera ? AUTOMATION_CAMERA_Z : AUTOMATION_PROJECTOR_Z;
2584 FloatAuto *prev, *next;
2585 FloatAutos **autos = (FloatAutos**)affected_track->automation->autos;
2586 FloatAutos *x_autos = autos[ix]; prev = 0; next = 0;
2587 float x_value = x_autos->get_value(position, PLAY_FORWARD, prev, next);
2588 FloatAutos *y_autos = autos[iy]; prev = 0; next = 0;
2589 float y_value = y_autos->get_value(position, PLAY_FORWARD, prev, next);
2590 FloatAutos *z_autos = autos[iz]; prev = 0; next = 0;
2591 float z_value = z_autos->get_value(position, PLAY_FORWARD, prev, next);
2592 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2594 gui->cwindow->calculate_affected_autos(affected_track,
2595 &x_keyframe, &y_keyframe, &z_keyframe,
2596 do_camera, -1, -1, -1, 0);
2597 x_keyframe->set_value(x_value);
2598 y_keyframe->set_value(y_value);
2599 z_keyframe->set_value(z_value);
2601 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2605 void CWindowCanvas::camera_keyframe() { create_keyframe(1); }
2606 void CWindowCanvas::projector_keyframe() { create_keyframe(0); }
2608 void CWindowCanvas::reset_keyframe(int do_camera)
2610 Track *affected_track = gui->cwindow->calculate_affected_track();
2611 if( affected_track ) {
2612 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2613 gui->cwindow->calculate_affected_autos(affected_track,
2614 &x_keyframe, &y_keyframe, &z_keyframe,
2615 do_camera, 1, 1, 1);
2617 x_keyframe->set_value(0);
2618 y_keyframe->set_value(0);
2619 z_keyframe->set_value(1);
2621 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2625 void CWindowCanvas::reset_camera() { reset_keyframe(1); }
2626 void CWindowCanvas::reset_projector() { reset_keyframe(0); }
2629 int CWindowCanvas::test_crop(int button_press, int &redraw)
2632 int handle_selected = -1;
2633 float x1 = mwindow->edl->session->crop_x1;
2634 float y1 = mwindow->edl->session->crop_y1;
2635 float x2 = mwindow->edl->session->crop_x2;
2636 float y2 = mwindow->edl->session->crop_y2;
2637 float cursor_x = get_cursor_x();
2638 float cursor_y = get_cursor_y();
2639 float canvas_x1 = x1;
2640 float canvas_y1 = y1;
2641 float canvas_x2 = x2;
2642 float canvas_y2 = y2;
2643 float canvas_cursor_x = cursor_x;
2644 float canvas_cursor_y = cursor_y;
2646 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2647 // Use screen normalized coordinates for hot spot tests.
2648 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2649 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2652 if( gui->current_operation == CWINDOW_CROP ) {
2653 handle_selected = gui->crop_handle;
2656 if( canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2657 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H ) {
2658 handle_selected = 0;
2659 gui->crop_origin_x = x1;
2660 gui->crop_origin_y = y1;
2663 if( canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2664 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H ) {
2665 handle_selected = 1;
2666 gui->crop_origin_x = x2;
2667 gui->crop_origin_y = y1;
2670 if( canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2671 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2 ) {
2672 handle_selected = 2;
2673 gui->crop_origin_x = x1;
2674 gui->crop_origin_y = y2;
2677 if( canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2678 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2 ) {
2679 handle_selected = 3;
2680 gui->crop_origin_x = x2;
2681 gui->crop_origin_y = y2;
2686 gui->crop_origin_x = cursor_x;
2687 gui->crop_origin_y = cursor_y;
2690 // printf("test crop %d %d\n",
2691 // gui->current_operation,
2692 // handle_selected);
2695 if( button_press ) {
2696 if( gui->alt_down() ) {
2697 gui->crop_translate = 1;
2698 gui->crop_origin_x1 = x1;
2699 gui->crop_origin_y1 = y1;
2700 gui->crop_origin_x2 = x2;
2701 gui->crop_origin_y2 = y2;
2704 gui->crop_translate = 0;
2706 gui->current_operation = CWINDOW_CROP;
2707 gui->crop_handle = handle_selected;
2708 gui->x_origin = cursor_x;
2709 gui->y_origin = cursor_y;
2710 gui->tool_panel->raise_window();
2713 if( handle_selected < 0 && !gui->crop_translate ) {
2716 mwindow->edl->session->crop_x1 = (int)x1;
2717 mwindow->edl->session->crop_y1 = (int)y1;
2718 mwindow->edl->session->crop_x2 = (int)x2;
2719 mwindow->edl->session->crop_y2 = (int)y2;
2724 // Translate all 4 points
2725 if( gui->current_operation == CWINDOW_CROP && gui->crop_translate ) {
2726 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2727 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2728 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2729 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2731 mwindow->edl->session->crop_x1 = (int)x1;
2732 mwindow->edl->session->crop_y1 = (int)y1;
2733 mwindow->edl->session->crop_x2 = (int)x2;
2734 mwindow->edl->session->crop_y2 = (int)y2;
2740 if( gui->current_operation == CWINDOW_CROP ) {
2741 switch( gui->crop_handle ) {
2743 x1 = gui->crop_origin_x;
2744 y1 = gui->crop_origin_y;
2745 x2 = gui->crop_origin_x;
2746 y2 = gui->crop_origin_y;
2747 if( cursor_x < gui->x_origin ) {
2748 if( cursor_y < gui->y_origin ) {
2753 if( cursor_y >= gui->y_origin ) {
2759 if( cursor_x >= gui->x_origin ) {
2760 if( cursor_y < gui->y_origin ) {
2765 if( cursor_y >= gui->y_origin ) {
2771 // printf("test crop %d %d %d %d\n",
2772 // mwindow->edl->session->crop_x1,
2773 // mwindow->edl->session->crop_y1,
2774 // mwindow->edl->session->crop_x2,
2775 // mwindow->edl->session->crop_y2);
2778 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2779 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2782 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2783 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2786 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2787 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2790 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2791 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2795 if( !EQUIV(mwindow->edl->session->crop_x1, x1) ||
2796 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2797 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2798 !EQUIV(mwindow->edl->session->crop_y2, y2) ) {
2803 switch( gui->crop_handle ) {
2804 case 0: gui->crop_handle = 1; break;
2805 case 1: gui->crop_handle = 0; break;
2806 case 2: gui->crop_handle = 3; break;
2807 case 3: gui->crop_handle = 2; break;
2816 switch( gui->crop_handle ) {
2817 case 0: gui->crop_handle = 2; break;
2818 case 1: gui->crop_handle = 3; break;
2819 case 2: gui->crop_handle = 0; break;
2820 case 3: gui->crop_handle = 1; break;
2825 mwindow->edl->session->crop_x1 = (int)x1;
2826 mwindow->edl->session->crop_y1 = (int)y1;
2827 mwindow->edl->session->crop_x2 = (int)x2;
2828 mwindow->edl->session->crop_y2 = (int)y2;
2834 // Update cursor font
2835 if( handle_selected >= 0 ) {
2836 switch( handle_selected ) {
2837 case 0: set_cursor(UPLEFT_RESIZE); break;
2838 case 1: set_cursor(UPRIGHT_RESIZE); break;
2839 case 2: set_cursor(DOWNLEFT_RESIZE); break;
2840 case 3: set_cursor(DOWNRIGHT_RESIZE); break;
2845 set_cursor(ARROW_CURSOR);
2847 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2850 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2851 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2852 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2853 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2854 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2855 // mwindow->edl->session->crop_x2,
2856 // mwindow->edl->session->crop_y2,
2857 // mwindow->edl->calculate_output_w(0),
2858 // mwindow->edl->calculate_output_h(0));
2864 void CWindowCanvas::draw_crop()
2866 get_canvas()->set_inverse();
2867 get_canvas()->set_color(WHITE);
2869 float x1 = mwindow->edl->session->crop_x1;
2870 float y1 = mwindow->edl->session->crop_y1;
2871 float x2 = mwindow->edl->session->crop_x2;
2872 float y2 = mwindow->edl->session->crop_y2;
2874 output_to_canvas(mwindow->edl, 0, x1, y1);
2875 output_to_canvas(mwindow->edl, 0, x2, y2);
2877 if( x2 - x1 && y2 - y1 )
2878 get_canvas()->draw_rectangle((int)x1,
2883 draw_crophandle((int)x1, (int)y1);
2884 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2885 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2886 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2887 get_canvas()->set_opaque();
2891 void CWindowCanvas::draw_outlines(int do_camera)
2893 Track *track = gui->cwindow->calculate_affected_track();
2895 if( !track ) return;
2897 float proj_x, proj_y, proj_z;
2898 int64_t position = track->to_units(
2899 mwindow->edl->local_session->get_selectionstart(1),
2901 track->automation->get_projector(&proj_x, &proj_y, &proj_z,
2902 position, PLAY_FORWARD);
2904 proj_x += mwindow->edl->session->output_w/2.;
2905 proj_y += mwindow->edl->session->output_h/2.;
2906 float proj_x1 = proj_x - track->track_w/2. * proj_z;
2907 float proj_y1 = proj_y - track->track_h/2. * proj_z;
2908 float proj_x2 = proj_x + track->track_w/2. * proj_z;
2909 float proj_y2 = proj_y + track->track_h/2. * proj_z;
2910 float x1 = proj_x1, x2 = proj_x2;
2911 float y1 = proj_y1, y2 = proj_y2;
2912 output_to_canvas(mwindow->edl, 0, x1, y1);
2913 output_to_canvas(mwindow->edl, 0, x2, y2);
2915 #define DRAW_PROJECTION(offset) \
2916 get_canvas()->draw_rectangle(x1+offset, y1+offset, (x2-x1), (y2-y1)); \
2917 get_canvas()->draw_line(x1+offset, y1+offset, x2+offset, y2+offset); \
2918 get_canvas()->draw_line(x2+offset, y1+offset, x1+offset, y2+offset); \
2921 get_canvas()->set_color(BLACK);
2923 get_canvas()->set_color(do_camera ? GREEN : RED);
2927 float cam_x, cam_y, cam_z;
2928 track->automation->get_camera(&cam_x, &cam_y, &cam_z,
2929 position, PLAY_FORWARD);
2930 cam_x += track->track_w / 2.;
2931 cam_y += track->track_h / 2.;
2932 // follow image, not camera
2933 cam_x = -cam_x; cam_y = -cam_y; cam_z *= proj_z;
2934 float cam_x1 = cam_x * cam_z + proj_x;
2935 float cam_y1 = cam_y * cam_z + proj_y;
2936 float cam_x2 = (cam_x + track->track_w) * cam_z + proj_x;
2937 float cam_y2 = (cam_y + track->track_h) * cam_z + proj_y;
2938 output_to_canvas(mwindow->edl, 0, cam_x1, cam_y1);
2939 output_to_canvas(mwindow->edl, 0, cam_x2, cam_y2);
2940 get_canvas()->set_color(YELLOW);
2941 get_canvas()->draw_rectangle(cam_x1, cam_y1, cam_x2-cam_x1, cam_y2-cam_y1);
2945 int CWindowCanvas::test_bezier(int button_press,
2953 // Processing drag operation.
2954 // Create keyframe during first cursor motion.
2955 if( !button_press ) {
2957 float cursor_x = get_cursor_x();
2958 float cursor_y = get_cursor_y();
2959 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2961 if( gui->current_operation == CWINDOW_CAMERA ||
2962 gui->current_operation == CWINDOW_PROJECTOR ) {
2963 if( !gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom ) {
2964 gui->translating_zoom = 1;
2965 gui->reset_affected();
2967 else if( !gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom ) {
2968 gui->translating_zoom = 0;
2969 gui->reset_affected();
2972 // Get target keyframe
2973 if( !gui->affected_x && !gui->affected_y && !gui->affected_z ) {
2974 if( !gui->affected_track ) return 0;
2975 FloatAutos *affected_x_autos, *affected_y_autos, *affected_z_autos;
2976 FloatAutos** autos = (FloatAutos**) gui->affected_track->automation->autos;
2977 if( mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA ) {
2978 affected_x_autos = autos[AUTOMATION_CAMERA_X];
2979 affected_y_autos = autos[AUTOMATION_CAMERA_Y];
2980 affected_z_autos = autos[AUTOMATION_CAMERA_Z];
2983 affected_x_autos = autos[AUTOMATION_PROJECTOR_X];
2984 affected_y_autos = autos[AUTOMATION_PROJECTOR_Y];
2985 affected_z_autos = autos[AUTOMATION_PROJECTOR_Z];
2987 double position = mwindow->edl->local_session->get_selectionstart(1);
2988 int64_t track_position = gui->affected_track->to_units(position, 0);
2989 FloatAuto *prev_x = 0, *next_x = 0;
2990 float new_x = affected_x_autos->get_value(track_position, PLAY_FORWARD, prev_x, next_x);
2991 FloatAuto *prev_y = 0, *next_y = 0;
2992 float new_y = affected_y_autos->get_value(track_position, PLAY_FORWARD, prev_y, next_y);
2993 FloatAuto *prev_z = 0, *next_z = 0;
2994 float new_z = affected_z_autos->get_value(track_position, PLAY_FORWARD, prev_z, next_z);
2995 int zooming = gui->translating_zoom, created;
2996 gui->affected_x = (FloatAuto*)gui->cwindow->calculate_affected_auto(
2997 affected_x_autos, !zooming, &created, 0);
2999 gui->affected_x->set_value(new_x);
3002 gui->affected_y = (FloatAuto*)gui->cwindow->calculate_affected_auto(
3003 affected_y_autos, !zooming, &created, 0);
3005 gui->affected_y->set_value(new_y);
3008 gui->affected_z = (FloatAuto*)gui->cwindow->calculate_affected_auto(
3009 affected_z_autos, zooming, &created, 0);
3011 gui->affected_z->set_value(new_z);
3016 if( gui->translating_zoom ) {
3017 gui->center_z = gui->affected_z->get_value();
3020 gui->center_x = gui->affected_x->get_value();
3021 gui->center_y = gui->affected_y->get_value();
3028 float x_val = gui->affected_x->get_value();
3029 float y_val = gui->affected_y->get_value();
3030 float z_val = gui->affected_z->get_value();
3032 if( gui->translating_zoom ) {
3033 float z = gui->center_z + (cursor_y - gui->y_origin) / yS(128);
3035 if( !EQUIV(z_val, z) ) {
3040 gui->affected_z->set_value(z);
3043 float dx = cursor_x - gui->x_origin;
3044 float dy = cursor_y - gui->y_origin;
3045 // follow image, not camera
3046 if( gui->current_operation == CWINDOW_CAMERA ) {
3047 dx = -dx / z_val; dy = -dy / z_val;
3049 float x = gui->center_x + dx;
3050 float y = gui->center_y + dy;
3051 gui->affected_x->set_value(x);
3052 gui->affected_y->set_value(y);
3053 if( !EQUIV(x_val, x) || !EQUIV(y_val, y) ) {
3064 // Begin drag operation. Don't create keyframe here.
3066 // Get affected track off of the first recordable video track.
3067 // Calculating based on the alpha channel would require recording what layer
3068 // each output pixel belongs to as they're rendered and stacked. Forget it.
3069 gui->affected_track = gui->cwindow->calculate_affected_track();
3070 gui->reset_affected();
3072 if( gui->affected_track ) {
3074 mwindow->undo->update_undo_before(_("camera"), this);
3076 mwindow->undo->update_undo_before(_("projector"), this);
3078 gui->current_operation =
3079 mwindow->edl->session->cwindow_operation;
3080 gui->tool_panel->raise_window();
3088 int CWindowCanvas::test_zoom(int &redraw)
3091 int button = get_buttonpress();
3092 if( button == LEFT_BUTTON )
3093 button = gui->shift_down() ? WHEEL_DOWN : WHEEL_UP;
3094 if( !(zoom = get_zoom()) )
3095 zoom = get_auto_zoom(mwindow->edl);
3099 for( ; idx < total_zooms; ++idx ) {
3100 if( EQUIV(zoom, my_zoom_table[idx]) ) continue;
3101 if( zoom < my_zoom_table[idx] ) break;
3103 float zoom11 = 1.1f * zoom;
3104 zoom = idx < total_zooms ? my_zoom_table[idx] : zoom11;
3105 if( zoom > zoom11 ) zoom = zoom11;
3108 int idx = total_zooms;
3109 for( ; --idx >= 0; ) {
3110 if( EQUIV(my_zoom_table[idx], zoom) ) continue;
3111 if( my_zoom_table[idx] < zoom ) break;
3113 float zoom09 = 0.9f * zoom;
3114 zoom = idx >= 0 ? my_zoom_table[idx] : zoom09;
3115 if( zoom < zoom09 ) zoom = zoom09;
3118 if( gui->shift_down() ) {
3122 default: // fall thru
3125 float cx = get_cursor_x(), cy = get_cursor_y();
3126 set_zoom(mwindow->edl, zoom, cx, cy);
3127 gui->zoom_panel->update(zoom);
3128 gui->update_canvas();
3134 void CWindowCanvas::calculate_origin()
3136 float zoom_x, zoom_y, conformed_w, conformed_h;
3137 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3138 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3139 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3140 gui->x_origin = (float)get_cursor_x() / zoom_x + gui->x_offset;
3141 gui->y_origin = (float)get_cursor_y() / zoom_y + gui->y_offset;
3145 int CWindowCanvas::cursor_leave_event()
3147 set_cursor(ARROW_CURSOR);
3151 int CWindowCanvas::cursor_enter_event()
3154 switch( mwindow->edl->session->cwindow_operation ) {
3155 case CWINDOW_CAMERA:
3156 case CWINDOW_PROJECTOR:
3157 set_cursor(MOVE_CURSOR);
3160 set_cursor(MOVE_CURSOR);
3163 test_crop(0, redraw);
3165 case CWINDOW_PROTECT:
3166 set_cursor(ARROW_CURSOR);
3170 set_cursor(CROSS_CURSOR);
3172 case CWINDOW_EYEDROP:
3173 set_cursor(CROSS_CURSOR);
3179 int CWindowCanvas::cursor_motion_event()
3181 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3184 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3185 switch( gui->current_operation ) {
3186 case CWINDOW_SCROLL: {
3187 result = do_scroll(mwindow->edl, get_cursor_x(), get_cursor_y());
3191 result = do_ruler(0, 1, 0, 0);
3194 case CWINDOW_CAMERA:
3195 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3198 case CWINDOW_PROJECTOR:
3199 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3203 result = test_crop(0, redraw);
3204 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3205 // __LINE__, result, redraw);
3209 case CWINDOW_MASK_CONTROL_IN:
3210 case CWINDOW_MASK_CONTROL_OUT:
3211 case CWINDOW_MASK_TRANSLATE:
3212 result = do_mask(redraw, rerender, 0, 1, 0);
3215 case CWINDOW_EYEDROP:
3216 result = do_eyedrop(rerender, 0, 0);
3224 // cursor font changes
3226 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3227 // __LINE__, mwindow->edl->session->cwindow_operation);
3228 switch( mwindow->edl->session->cwindow_operation ) {
3230 result = test_crop(0, redraw);
3233 result = do_ruler(0, 1, 0, 0);
3236 result = do_mask(redraw, rerender, 0, 1, 0);
3241 int change_type = rerender ? CHANGE_PARAMS : -1;
3242 gui->sync_parameters(change_type, redraw, redraw_canvas);
3247 int CWindowCanvas::button_press_event()
3251 int redraw_canvas = 0;
3254 if( Canvas::button_press_event() ) return 1;
3256 gui->translating_zoom = gui->shift_down();
3260 if( mwindow->edl->session->cwindow_operation != CWINDOW_PROTECT &&
3261 get_buttonpress() == MIDDLE_BUTTON && !get_canvas()->shift_down() ) {
3262 gui->current_operation = CWINDOW_SCROLL;
3267 switch( mwindow->edl->session->cwindow_operation ) {
3269 result = do_ruler(0, 0, 1, 0);
3272 case CWINDOW_CAMERA:
3273 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3276 case CWINDOW_PROJECTOR:
3277 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3281 result = test_zoom(redraw);
3285 result = test_crop(1, redraw);
3289 switch( get_buttonpress() ) {
3291 result = do_mask(redraw, rerender, 1, 0, 0);
3293 case MIDDLE_BUTTON: { // && shift_down()
3294 result = do_mask_focus();
3295 redraw = redraw_canvas = 1;
3299 result = do_mask(redraw, rerender, 1, 1, 0);
3302 if( result ) redraw_canvas = 1;
3305 case CWINDOW_EYEDROP:
3306 result = do_eyedrop(rerender, 1, 0);
3311 int change_type = rerender ? CHANGE_PARAMS : -1;
3312 gui->sync_parameters(change_type, redraw, redraw_canvas);
3317 int CWindowCanvas::button_release_event()
3320 const char *undo_label = 0;
3322 switch( gui->current_operation ) {
3323 case CWINDOW_SCROLL:
3328 do_ruler(0, 0, 0, 1);
3331 case CWINDOW_CAMERA:
3332 undo_label = _("camera");
3335 case CWINDOW_PROJECTOR:
3336 undo_label = _("projector");
3340 case CWINDOW_MASK_CONTROL_IN:
3341 case CWINDOW_MASK_CONTROL_OUT:
3342 case CWINDOW_MASK_TRANSLATE:
3343 // Finish mask operation
3344 gui->mask_keyframe = 0;
3345 undo_label = _("mask");
3347 case CWINDOW_MASK_ROTATE:
3348 gui->mask_keyframe = 0;
3349 undo_label = _("mask rotate");
3351 case CWINDOW_MASK_SCALE:
3352 gui->mask_keyframe = 0;
3353 undo_label = _("mask scale");
3356 result = Canvas::button_release_event();
3361 mwindow->undo->update_undo_after(undo_label, LOAD_AUTOMATION);
3362 gui->current_operation = CWINDOW_NONE;
3366 void CWindowCanvas::zoom_resize_window(float percentage)
3368 int canvas_w, canvas_h;
3371 // Get required canvas size
3372 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3373 mwindow->edl->session->output_w,
3374 mwindow->edl->session->output_h,
3375 percentage, canvas_w, canvas_h);
3377 // Estimate window size from current borders
3378 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3379 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3381 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3382 mwindow->session->cwindow_w = new_w;
3383 mwindow->session->cwindow_h = new_h;
3385 mwindow->theme->get_cwindow_sizes(gui,
3386 mwindow->session->cwindow_controls);
3388 // Estimate again from new borders
3389 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3390 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3391 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3393 gui->resize_window(new_w, new_h);
3394 gui->resize_event(new_w, new_h);
3397 void CWindowCanvas::toggle_controls()
3399 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3400 gui->resize_event(gui->get_w(), gui->get_h());
3403 int CWindowCanvas::get_controls()
3405 return mwindow->session->cwindow_controls;
3408 int CWindowCanvas::get_clear_color()
3410 int color = mwindow->edl->session->cwindow_clear_color;
3411 if( color < 0 ) color = Canvas::get_clear_color();