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);
166 canvas->use_cwindow();
169 add_subwindow(timebar = new CTimeBar(mwindow,
171 mwindow->theme->ctimebar_x,
172 mwindow->theme->ctimebar_y,
173 mwindow->theme->ctimebar_w,
174 mwindow->theme->ctimebar_h));
175 timebar->create_objects();
178 add_subwindow(slider = new CWindowSlider(mwindow,
180 mwindow->theme->cslider_x,
181 mwindow->theme->cslider_y,
182 mwindow->theme->cslider_w));
185 transport = new CWindowTransport(mwindow,
187 mwindow->theme->ctransport_x,
188 mwindow->theme->ctransport_y);
189 transport->create_objects();
191 transport->set_slider(slider);
194 edit_panel = new CWindowEditing(mwindow, cwindow);
195 edit_panel->set_meters(meters);
196 edit_panel->create_objects();
198 // add_subwindow(clock = new MainClock(mwindow,
199 // mwindow->theme->ctime_x,
200 // mwindow->theme->ctime_y));
202 zoom_panel = new CWindowZoom(mwindow,
204 mwindow->theme->czoom_x,
205 mwindow->theme->czoom_y,
206 mwindow->theme->czoom_w);
207 zoom_panel->create_objects();
208 zoom_panel->zoom_text->add_item(new BC_MenuItem(auto_zoom = _(AUTO_ZOOM)));
209 if( !mwindow->edl->session->cwindow_scrollbars )
210 zoom_panel->set_text(auto_zoom);
212 // Must create after meter panel
213 tool_panel = new CWindowTool(mwindow, this);
214 tool_panel->Thread::start();
216 set_operation(mwindow->edl->session->cwindow_operation);
221 int CWindowGUI::translation_event()
223 mwindow->session->cwindow_x = get_x();
224 mwindow->session->cwindow_y = get_y();
228 int CWindowGUI::resize_event(int w, int h)
230 mwindow->session->cwindow_x = get_x();
231 mwindow->session->cwindow_y = get_y();
232 mwindow->session->cwindow_w = w;
233 mwindow->session->cwindow_h = h;
235 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
236 mwindow->theme->draw_cwindow_bg(this);
239 composite_panel->reposition_buttons(mwindow->theme->ccomposite_x,
240 mwindow->theme->ccomposite_y, mwindow->theme->ccomposite_h);
242 canvas->set_zoom(mwindow->edl, canvas->get_zoom());
245 timebar->resize_event();
248 slider->reposition_window(mwindow->theme->cslider_x,
249 mwindow->theme->cslider_y,
250 mwindow->theme->cslider_w);
251 // Recalibrate pointer motion range
252 slider->set_position();
255 transport->reposition_buttons(mwindow->theme->ctransport_x,
256 mwindow->theme->ctransport_y);
258 edit_panel->reposition_buttons(mwindow->theme->cedit_x,
259 mwindow->theme->cedit_y);
261 // clock->reposition_window(mwindow->theme->ctime_x,
262 // mwindow->theme->ctime_y);
264 zoom_panel->reposition_window(mwindow->theme->czoom_x,
265 mwindow->theme->czoom_y);
267 // destination->reposition_window(mwindow->theme->cdest_x,
268 // mwindow->theme->cdest_y);
270 meters->reposition_window(mwindow->theme->cmeter_x,
271 mwindow->theme->cmeter_y,
273 mwindow->theme->cmeter_h);
277 BC_WindowBase::resize_event(w, h);
281 int CWindowGUI::button_press_event()
283 if( current_operation == CWINDOW_NONE &&
284 mwindow->edl != 0 && canvas->get_canvas() &&
285 mwindow->edl->session->cwindow_click2play &&
286 canvas->get_canvas()->get_cursor_over_window() ) {
287 switch( get_buttonpress() ) {
289 if( !cwindow->playback_engine->is_playing_back ) {
290 double length = mwindow->edl->tracks->total_playable_length();
291 double position = cwindow->playback_engine->get_tracking_position();
292 if( position >= length ) transport->goto_start();
294 return transport->forward_play->handle_event();
296 if( !cwindow->playback_engine->is_playing_back ) {
297 double position = cwindow->playback_engine->get_tracking_position();
298 if( position <= 0 ) transport->goto_end();
300 return transport->reverse_play->handle_event();
301 case RIGHT_BUTTON: // activates popup
304 return transport->frame_forward_play->handle_event();
306 return transport->frame_reverse_play->handle_event();
309 if( canvas->get_canvas() )
310 return canvas->button_press_event_base(canvas->get_canvas());
314 int CWindowGUI::cursor_leave_event()
316 if( canvas->get_canvas() )
317 return canvas->cursor_leave_event_base(canvas->get_canvas());
321 int CWindowGUI::cursor_enter_event()
323 if( canvas->get_canvas() )
324 return canvas->cursor_enter_event_base(canvas->get_canvas());
328 int CWindowGUI::button_release_event()
330 if( canvas->get_canvas() )
331 return canvas->button_release_event();
335 int CWindowGUI::cursor_motion_event()
337 if( canvas->get_canvas() ) {
338 canvas->get_canvas()->unhide_cursor();
339 return canvas->cursor_motion_event();
350 void CWindowGUI::draw_status(int flush)
352 if( (canvas->get_canvas() && canvas->get_canvas()->get_video_on()) ||
353 canvas->is_processing ) {
355 mwindow->theme->cstatus_x,
356 mwindow->theme->cstatus_y);
359 draw_pixmap(inactive,
360 mwindow->theme->cstatus_x,
361 mwindow->theme->cstatus_y);
365 // printf("CWindowGUI::draw_status %d %d %d\n", __LINE__, mwindow->theme->cstatus_x,
366 // mwindow->theme->cstatus_y);
367 flash(mwindow->theme->cstatus_x,
368 mwindow->theme->cstatus_y,
374 void CWindowGUI::update_canvas(int redraw)
376 float zoom = canvas->get_zoom();
377 zoom_panel->update(zoom);
378 if( mwindow->edl->session->cwindow_operation == CWINDOW_ZOOM ) {
379 if( !zoom ) zoom = canvas->get_auto_zoom(mwindow->edl);
380 composite_panel->cpanel_zoom->update(zoom);
382 canvas->update_scrollbars(mwindow->edl, 0);
383 canvas->reposition_window(mwindow->edl,
384 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
385 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
390 void CWindowGUI::set_operation(int value)
393 case CWINDOW_TOOL_WINDOW:
394 mwindow->edl->session->tool_window = !mwindow->edl->session->tool_window;
395 composite_panel->operation[CWINDOW_TOOL_WINDOW]->update(mwindow->edl->session->tool_window);
396 tool_panel->update_show_window();
398 case CWINDOW_TITLESAFE:
399 mwindow->edl->session->safe_regions = !mwindow->edl->session->safe_regions;
400 composite_panel->operation[CWINDOW_TITLESAFE]->update(mwindow->edl->session->safe_regions);
401 value = mwindow->edl->session->cwindow_operation;
404 mwindow->edl->session->cwindow_operation = value;
405 composite_panel->set_operation(value);
409 edit_panel->update();
410 tool_panel->start_tool(value);
414 void CWindowGUI::update_tool()
416 tool_panel->update_values();
419 int CWindowGUI::close_event()
421 cwindow->hide_window();
426 int CWindowGUI::keypress_event()
429 int cwindow_operation = CWINDOW_NONE;
431 switch( get_keypress() ) {
447 int on = canvas->get_fullscreen() ? 0 : 1;
448 canvas->set_fullscreen(on, 1);
452 canvas->set_fullscreen(0, 1);
456 if( ctrl_down() || shift_down() || alt_down() ) break;
458 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
460 mwindow->gui->unlock_window();
461 lock_window("CWindowGUI::keypress_event 2");
466 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
467 mwindow->clear_entry();
468 mwindow->gui->unlock_window();
469 lock_window("CWindowGUI::keypress_event 3");
474 int alt_down = this->alt_down();
475 int shift_down = this->shift_down();
478 mwindow->gui->lock_window("CWindowGUI::keypress_event 5");
480 mwindow->prev_edit_handle(shift_down);
482 mwindow->move_left();
483 mwindow->gui->unlock_window();
484 lock_window("CWindowGUI::keypress_event 6");
490 if( !ctrl_down() && !alt_down() ) {
493 mwindow->gui->lock_window("CWindowGUI::keypress_event 7");
494 mwindow->move_left();
495 mwindow->gui->unlock_window();
496 lock_window("CWindowGUI::keypress_event 8");
503 int alt_down = this->alt_down();
504 int shift_down = this->shift_down();
507 mwindow->gui->lock_window("CWindowGUI::keypress_event 8");
509 mwindow->next_edit_handle(shift_down);
511 mwindow->move_right();
512 mwindow->gui->unlock_window();
513 lock_window("CWindowGUI::keypress_event 9");
519 if( !ctrl_down() && !alt_down() ) {
522 mwindow->gui->lock_window("CWindowGUI::keypress_event 10");
523 mwindow->move_right();
524 mwindow->gui->unlock_window();
525 lock_window("CWindowGUI::keypress_event 11");
531 if( !result && cwindow_operation < 0 && ctrl_down() && shift_down() ) {
532 switch( get_keypress() ) {
533 case KEY_F1 ... KEY_F4: // mainmenu, load layout
534 resend_event(mwindow->gui);
539 if( !result && !ctrl_down() ) {
540 switch( get_keypress() ) {
543 mwindow->toggle_camera_xyz(); result = 1;
546 cwindow_operation = CWINDOW_PROTECT;
550 mwindow->toggle_projector_xyz(); result = 1;
553 cwindow_operation = CWINDOW_ZOOM;
557 if( !result && cwindow_operation < 0 && !ctrl_down() && !shift_down() ) {
558 switch( get_keypress() ) {
559 case KEY_F3: cwindow_operation = CWINDOW_MASK; break;
560 case KEY_F4: cwindow_operation = CWINDOW_RULER; break;
561 case KEY_F5: cwindow_operation = CWINDOW_CAMERA; break;
562 case KEY_F6: cwindow_operation = CWINDOW_PROJECTOR; break;
563 case KEY_F7: cwindow_operation = CWINDOW_CROP; break;
564 case KEY_F8: cwindow_operation = CWINDOW_EYEDROP; break;
565 case KEY_F9: cwindow_operation = CWINDOW_TOOL_WINDOW; break;
566 case KEY_F10: cwindow_operation = CWINDOW_TITLESAFE; break;
569 if( !result && cwindow_operation < 0 && !ctrl_down() ) {
570 switch( get_keypress() ) {
573 canvas->reset_camera();
575 canvas->camera_keyframe();
580 canvas->reset_projector();
582 canvas->projector_keyframe();
588 if( cwindow_operation >= 0 ) {
589 set_operation(cwindow_operation);
594 result = transport->keypress_event();
600 void CWindowGUI::reset_affected()
607 void CWindowGUI::keyboard_zoomin()
609 zoom_panel->zoom_tumbler->handle_up_event();
612 void CWindowGUI::keyboard_zoomout()
614 zoom_panel->zoom_tumbler->handle_down_event();
617 void CWindowGUI::sync_parameters(int change_type, int redraw, int overlay)
623 if( change_type < 0 && !overlay ) return;
625 if( change_type >= 0 ) {
626 mwindow->restart_brender();
627 mwindow->sync_parameters(change_type);
630 mwindow->gui->lock_window("CWindowGUI::sync_parameters");
631 mwindow->gui->draw_overlays(1);
632 mwindow->gui->unlock_window();
634 lock_window("CWindowGUI::sync_parameters");
637 void CWindowGUI::drag_motion()
639 if( get_hidden() ) return;
641 if( mwindow->session->current_operation != DRAG_ASSET &&
642 mwindow->session->current_operation != DRAG_VTRANSITION &&
643 mwindow->session->current_operation != DRAG_VEFFECT ) return;
644 int need_highlight = cursor_above() && get_cursor_over_window();
645 if( highlighted == need_highlight ) return;
646 highlighted = need_highlight;
650 int CWindowGUI::drag_stop()
653 if( get_hidden() ) return 0;
654 if( !highlighted ) return 0;
655 if( mwindow->session->current_operation != DRAG_ASSET &&
656 mwindow->session->current_operation != DRAG_VTRANSITION &&
657 mwindow->session->current_operation != DRAG_VEFFECT) return 0;
662 if( mwindow->session->current_operation == DRAG_ASSET ) {
663 if( mwindow->session->drag_assets->total ||
664 mwindow->session->drag_clips->total ) {
665 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
666 mwindow->undo->update_undo_before(_("insert assets"), 0);
669 if( mwindow->session->drag_assets->total ) {
671 mwindow->load_assets(mwindow->session->drag_assets,
672 mwindow->edl->local_session->get_selectionstart(),
674 mwindow->session->track_highlighted,
676 mwindow->edl->session->labels_follow_edits,
677 mwindow->edl->session->plugins_follow_edits,
678 mwindow->edl->session->autos_follow_edits,
682 if( mwindow->session->drag_clips->total ) {
684 mwindow->paste_edls(mwindow->session->drag_clips,
686 mwindow->session->track_highlighted,
687 mwindow->edl->local_session->get_selectionstart(),
688 mwindow->edl->session->labels_follow_edits,
689 mwindow->edl->session->plugins_follow_edits,
690 mwindow->edl->session->autos_follow_edits,
694 if( mwindow->session->drag_assets->total ||
695 mwindow->session->drag_clips->total ) {
696 mwindow->save_backup();
697 mwindow->restart_brender();
698 mwindow->gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
699 mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
700 mwindow->gui->unlock_window();
701 sync_parameters(CHANGE_ALL);
705 if( mwindow->session->current_operation == DRAG_VEFFECT ) {
706 //printf("CWindowGUI::drag_stop 1\n");
707 Track *affected_track = cwindow->calculate_affected_track();
708 //printf("CWindowGUI::drag_stop 2\n");
710 mwindow->gui->lock_window("CWindowGUI::drag_stop 3");
711 mwindow->insert_effects_cwindow(affected_track);
712 mwindow->session->current_operation = NO_OPERATION;
713 mwindow->gui->unlock_window();
716 if( mwindow->session->current_operation == DRAG_VTRANSITION ) {
717 Track *affected_track = cwindow->calculate_affected_track();
718 mwindow->gui->lock_window("CWindowGUI::drag_stop 4");
719 mwindow->paste_transition_cwindow(affected_track);
720 mwindow->session->current_operation = NO_OPERATION;
721 mwindow->gui->unlock_window();
727 void CWindowGUI::update_meters()
729 if( mwindow->edl->session->cwindow_meter != meters->visible ) {
730 meters->set_meters(meters->meter_count, mwindow->edl->session->cwindow_meter);
731 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
732 resize_event(get_w(), get_h());
736 void CWindowGUI::stop_transport(const char *lock_msg)
738 if( lock_msg ) unlock_window();
739 mwindow->stop_transport();
740 if( lock_msg ) lock_window(lock_msg);
744 CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
745 : EditPanel(mwindow, cwindow->gui, CWINDOW_ID,
746 mwindow->theme->cedit_x, mwindow->theme->cedit_y,
747 mwindow->edl->session->editing_mode,
748 0, // use_editing_mode
765 this->mwindow = mwindow;
766 this->cwindow = cwindow;
769 #define relock_cm(s) \
770 cwindow->gui->unlock_window(); \
771 mwindow->gui->lock_window("CWindowEditing::" s)
772 #define relock_mc(s) \
773 mwindow->gui->unlock_window(); \
774 cwindow->gui->lock_window("CWindowEditing::" s)
775 #define panel_fn(fn, args, s) \
776 CWindowEditing::fn args { relock_cm(#fn); s; relock_mc(#fn); }
778 // transmit lock to mwindow, and run mbutton->edit_panel->s
779 #define panel_btn(fn, args, s) \
780 panel_fn(panel_##fn, args, mwindow->gui->mbuttons->edit_panel->panel_##s)
783 double CWindowEditing::get_position()
785 relock_cm("get_position");
786 double ret = mwindow->edl->local_session->get_selectionstart(1);
787 relock_mc("get_position");
791 void CWindowEditing::set_position(double position)
793 relock_cm("set_position");
794 mwindow->gui->mbuttons->edit_panel->set_position(position);
795 relock_mc("set_position");
798 void CWindowEditing::set_click_to_play(int v)
800 relock_cm("set_position");
801 mwindow->edl->session->cwindow_click2play = v;
802 relock_mc("set_position");
803 click2play->update(v);
807 void panel_btn(stop_transport,(), stop_transport())
808 void panel_btn(toggle_label,(), toggle_label())
809 void panel_btn(next_label,(int cut), next_label(cut))
810 void panel_btn(prev_label,(int cut), prev_label(cut))
811 void panel_btn(next_edit,(int cut), next_edit(cut))
812 void panel_btn(prev_edit,(int cut), prev_edit(cut))
813 void panel_fn(panel_copy_selection,(), mwindow->copy())
814 void CWindowEditing::panel_overwrite_selection() {} // not used
815 void CWindowEditing::panel_splice_selection() {} // not used
816 void panel_btn(set_inpoint,(), set_inpoint())
817 void panel_btn(set_outpoint,(), set_outpoint())
818 void panel_btn(unset_inoutpoint,(), unset_inoutpoint())
819 void panel_fn(panel_to_clip,(), mwindow->to_clip(mwindow->edl, _("main window: "), 0))
820 void panel_btn(cut,(), cut())
821 void panel_btn(paste,(), paste())
822 void panel_btn(fit_selection,(), fit_selection())
823 void panel_btn(fit_autos,(int all), fit_autos(all))
824 void panel_btn(set_editing_mode,(int mode), set_editing_mode(mode))
825 void panel_btn(set_auto_keyframes,(int v), set_auto_keyframes(v))
826 void panel_btn(set_span_keyframes,(int v), set_span_keyframes(v))
827 void panel_btn(set_labels_follow_edits,(int v), set_labels_follow_edits(v))
830 CWindowMeters::CWindowMeters(MWindow *mwindow,
831 CWindowGUI *gui, int x, int y, int h)
832 : MeterPanel(mwindow, gui, x, y, -1, h,
833 mwindow->edl->session->audio_channels,
834 mwindow->edl->session->cwindow_meter,
837 this->mwindow = mwindow;
841 CWindowMeters::~CWindowMeters()
845 int CWindowMeters::change_status_event(int new_status)
847 mwindow->edl->session->cwindow_meter = new_status;
848 gui->update_meters();
855 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
856 : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
857 x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
859 this->mwindow = mwindow;
863 CWindowZoom::~CWindowZoom()
867 void CWindowZoom::update(double value)
869 char string[BCSTRLEN];
870 const char *cp = string;
873 int frac = value >= 1.0f ? 1 :
875 value >= .01f ? 3 : 4;
876 sprintf(string, "x %.*f", frac, value);
880 ZoomPanel::update(cp);
883 int CWindowZoom::handle_event()
885 double value = !strcasecmp(gui->auto_zoom, get_text()) ? 0 : get_value();
886 gui->canvas->set_zoom(mwindow->edl, value);
887 gui->update_canvas();
894 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
895 : BC_PercentageSlider(x, y, 0, pixels, pixels, 0, 1, 0)
897 this->mwindow = mwindow;
898 this->cwindow = cwindow;
899 set_precision(0.00001);
902 CWindowSlider::~CWindowSlider()
906 int CWindowSlider::handle_event()
908 cwindow->update_position((double)get_value());
912 void CWindowSlider::set_position()
914 double new_length = mwindow->edl->tracks->total_length();
915 update(mwindow->theme->cslider_w,
916 mwindow->edl->local_session->get_selectionstart(1),
921 int CWindowSlider::increase_value()
924 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
925 lock_window("CWindowSlider::increase_value");
929 int CWindowSlider::decrease_value()
932 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
933 lock_window("CWindowSlider::decrease_value");
939 CWindowTransport::CWindowTransport(MWindow *mwindow,
940 CWindowGUI *gui, int x, int y)
941 : PlayTransport(mwindow, gui, x, y)
946 EDL* CWindowTransport::get_edl()
951 void CWindowTransport::goto_start()
953 gui->unlock_window();
954 handle_transport(REWIND, 1);
956 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
957 mwindow->goto_start();
958 mwindow->gui->unlock_window();
960 gui->lock_window("CWindowTransport::goto_start 2");
963 void CWindowTransport::goto_end()
965 gui->unlock_window();
966 handle_transport(GOTO_END, 1);
968 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
970 mwindow->gui->unlock_window();
972 gui->lock_window("CWindowTransport::goto_end 2");
977 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
978 : Canvas(mwindow, gui,
979 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
980 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h,
981 0, 0, mwindow->edl->session->cwindow_scrollbars)
983 this->mwindow = mwindow;
990 void CWindowCanvas::status_event()
995 void CWindowCanvas::update_zoom(int x, int y, float zoom)
997 mwindow->edl->session->cwindow_xscroll = x;
998 mwindow->edl->session->cwindow_yscroll = y;
999 mwindow->edl->session->cwindow_zoom = zoom;
1000 use_scrollbars = !zoom ? 0 : 1;
1001 mwindow->edl->session->cwindow_scrollbars = use_scrollbars;
1004 int CWindowCanvas::set_fullscreen(int on, int unlock)
1007 if( on && !get_fullscreen() ) {
1008 last_xscroll = get_xscroll();
1009 last_yscroll = get_yscroll();
1010 last_zoom = get_zoom();
1011 Canvas::set_fullscreen(1, unlock);
1015 if( !on && get_fullscreen() ) {
1016 Canvas::set_fullscreen(0, unlock);
1017 gui->zoom_panel->update(get_zoom());
1018 update_zoom(last_xscroll, last_yscroll, last_zoom);
1019 gui->update_canvas();
1025 int CWindowCanvas::get_xscroll()
1027 return mwindow->edl->session->cwindow_xscroll;
1030 int CWindowCanvas::get_yscroll()
1032 return mwindow->edl->session->cwindow_yscroll;
1036 float CWindowCanvas::get_zoom()
1038 return mwindow->edl->session->cwindow_zoom;
1041 void CWindowCanvas::zoom_auto()
1044 set_zoom(mwindow->edl, 0);
1045 gui->update_canvas();
1048 int CWindowCanvas::do_scroll(EDL *edl, float cursor_x, float cursor_y)
1050 float zoom = get_zoom();
1051 float zoom_x, zoom_y, conformed_w, conformed_h;
1052 get_zooms(edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
1054 x = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
1055 y = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
1056 zoom = get_auto_zoom(mwindow->edl);
1059 x = gui->x_origin - cursor_x / zoom_x;
1060 y = gui->y_origin - cursor_y / zoom_y;
1062 update_zoom(x, y, zoom);
1063 gui->update_canvas();
1067 void CWindowCanvas::draw_refresh(int flush)
1069 BC_WindowBase *window = get_canvas();
1070 if( window && !window->get_video_on() ) {
1072 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
1073 float in_x1, in_y1, in_x2, in_y2;
1074 float out_x1, out_y1, out_x2, out_y2;
1075 get_transfers(mwindow->edl,
1076 in_x1, in_y1, in_x2, in_y2,
1077 out_x1, out_y1, out_x2, out_y2);
1080 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1081 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1084 if( out_x2 > out_x1 && out_y2 > out_y1 &&
1085 in_x2 > in_x1 && in_y2 > in_y1 ) {
1086 // input scaled from session to refresh frame coordinates
1087 int ow = get_output_w(mwindow->edl);
1088 int oh = get_output_h(mwindow->edl);
1089 int rw = refresh_frame->get_w();
1090 int rh = refresh_frame->get_h();
1091 float xs = (float)rw / ow;
1092 float ys = (float)rh / oh;
1093 in_x1 *= xs; in_x2 *= xs;
1094 in_y1 *= ys; in_y2 *= ys;
1095 // Can't use OpenGL here because it is called asynchronously of the
1096 // playback operation.
1097 window->draw_vframe(refresh_frame,
1098 (int)out_x1, (int)out_y1,
1099 (int)(out_x2 - out_x1),
1100 (int)(out_y2 - out_y1),
1101 (int)in_x1, (int)in_y1,
1102 (int)(in_x2 - in_x1),
1103 (int)(in_y2 - in_y1),
1109 window->flash(flush);
1111 //printf("CWindowCanvas::draw_refresh 10\n");
1114 #define CROPHANDLE_W xS(10)
1115 #define CROPHANDLE_H yS(10)
1117 void CWindowCanvas::draw_crophandle(int x, int y)
1119 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1123 #define CONTROL_W xS(10)
1124 #define CONTROL_H yS(10)
1125 #define FIRST_CONTROL_W xS(20)
1126 #define FIRST_CONTROL_H yS(20)
1128 #define BC_INFINITY 65536
1130 #define RULERHANDLE_W xS(16)
1131 #define RULERHANDLE_H yS(16)
1133 int CWindowCanvas::do_ruler(int draw, int motion,
1134 int button_press, int button_release)
1137 EDLSession *session = mwindow->edl->session;
1138 float x1 = session->ruler_x1;
1139 float y1 = session->ruler_y1;
1140 float x2 = session->ruler_x2;
1141 float y2 = session->ruler_y2;
1142 float canvas_x1 = x1;
1143 float canvas_y1 = y1;
1144 float canvas_x2 = x2;
1145 float canvas_y2 = y2;
1146 float output_x = get_cursor_x();
1147 float output_y = get_cursor_y();
1148 float canvas_cursor_x = output_x;
1149 float canvas_cursor_y = output_y;
1151 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1152 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1153 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1154 mwindow->session->cwindow_output_x = roundf(output_x);
1155 mwindow->session->cwindow_output_y = roundf(output_y);
1157 if( button_press && get_buttonpress() == 1 ) {
1158 gui->ruler_handle = -1;
1159 gui->ruler_translate = 0;
1160 if( gui->alt_down() ) {
1161 gui->ruler_translate = 1;
1162 gui->ruler_origin_x = x1;
1163 gui->ruler_origin_y = y1;
1166 if( canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1167 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1168 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1169 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2 ) {
1170 gui->ruler_handle = 0;
1171 gui->ruler_origin_x = x1;
1172 gui->ruler_origin_y = y1;
1175 if( canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1176 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1177 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1178 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2 ) {
1179 gui->ruler_handle = 1;
1180 gui->ruler_origin_x = x2;
1181 gui->ruler_origin_y = y2;
1185 // Start new selection
1186 if( !gui->ruler_translate &&
1187 (gui->ruler_handle < 0 ||
1191 do_ruler(1, 0, 0, 0);
1192 get_canvas()->flash();
1193 gui->ruler_handle = 1;
1194 session->ruler_x1 = output_x;
1195 session->ruler_y1 = output_y;
1196 session->ruler_x2 = output_x;
1197 session->ruler_y2 = output_y;
1198 gui->ruler_origin_x = session->ruler_x2;
1199 gui->ruler_origin_y = session->ruler_y2;
1202 gui->x_origin = output_x;
1203 gui->y_origin = output_y;
1204 gui->current_operation = CWINDOW_RULER;
1205 gui->tool_panel->raise_window();
1210 if( gui->current_operation == CWINDOW_RULER ) {
1211 if( gui->ruler_translate ) {
1213 do_ruler(1, 0, 0, 0);
1214 float x_difference = session->ruler_x1;
1215 float y_difference = session->ruler_y1;
1216 session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1217 session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1218 x_difference -= session->ruler_x1;
1219 y_difference -= session->ruler_y1;
1220 session->ruler_x2 -= x_difference;
1221 session->ruler_y2 -= y_difference;
1223 do_ruler(1, 0, 0, 0);
1224 get_canvas()->flash();
1228 switch( gui->ruler_handle ) {
1230 do_ruler(1, 0, 0, 0);
1231 session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1232 session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1233 if( gui->alt_down() || gui->ctrl_down() ) {
1234 double angle_value = fabs(atan((session->ruler_y2 - session->ruler_y1) /
1235 (session->ruler_x2 - session->ruler_x1)) *
1237 double distance_value =
1238 sqrt(SQR(session->ruler_x2 - session->ruler_x1) +
1239 SQR(session->ruler_y2 - session->ruler_y1));
1240 if( angle_value < 22 )
1241 session->ruler_y1 = session->ruler_y2;
1243 if( angle_value > 67 )
1244 session->ruler_x1 = session->ruler_x2;
1246 if( session->ruler_x1 < session->ruler_x2 &&
1247 session->ruler_y1 < session->ruler_y2 ) {
1248 session->ruler_x1 = session->ruler_x2 - distance_value / 1.414214;
1249 session->ruler_y1 = session->ruler_y2 - distance_value / 1.414214;
1252 if( session->ruler_x1 < session->ruler_x2 && session->ruler_y1 > session->ruler_y2 ) {
1253 session->ruler_x1 = session->ruler_x2 - distance_value / 1.414214;
1254 session->ruler_y1 = session->ruler_y2 + distance_value / 1.414214;
1257 if( session->ruler_x1 > session->ruler_x2 &&
1258 session->ruler_y1 < session->ruler_y2 ) {
1259 session->ruler_x1 = session->ruler_x2 + distance_value / 1.414214;
1260 session->ruler_y1 = session->ruler_y2 - distance_value / 1.414214;
1263 session->ruler_x1 = session->ruler_x2 + distance_value / 1.414214;
1264 session->ruler_y1 = session->ruler_y2 + distance_value / 1.414214;
1267 do_ruler(1, 0, 0, 0);
1268 get_canvas()->flash();
1273 do_ruler(1, 0, 0, 0);
1274 session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1275 session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1276 if( gui->alt_down() || gui->ctrl_down() ) {
1277 double angle_value = fabs(atan((session->ruler_y2 - session->ruler_y1) /
1278 (session->ruler_x2 - session->ruler_x1)) *
1280 double distance_value =
1281 sqrt(SQR(session->ruler_x2 - session->ruler_x1) +
1282 SQR(session->ruler_y2 - session->ruler_y1));
1283 if( angle_value < 22 )
1284 session->ruler_y2 = session->ruler_y1;
1286 if( angle_value > 67 )
1287 session->ruler_x2 = session->ruler_x1;
1289 if( session->ruler_x2 < session->ruler_x1 &&
1290 session->ruler_y2 < session->ruler_y1 ) {
1291 session->ruler_x2 = session->ruler_x1 - distance_value / 1.414214;
1292 session->ruler_y2 = session->ruler_y1 - distance_value / 1.414214;
1295 if( session->ruler_x2 < session->ruler_x1 &&
1296 session->ruler_y2 > session->ruler_y1 ) {
1297 session->ruler_x2 = session->ruler_x1 - distance_value / 1.414214;
1298 session->ruler_y2 = session->ruler_y1 + distance_value / 1.414214;
1301 if( session->ruler_x2 > session->ruler_x1 && session->ruler_y2 < session->ruler_y1 ) {
1302 session->ruler_x2 = session->ruler_x1 + distance_value / 1.414214;
1303 session->ruler_y2 = session->ruler_y1 - distance_value / 1.414214;
1306 session->ruler_x2 = session->ruler_x1 + distance_value / 1.414214;
1307 session->ruler_y2 = session->ruler_y1 + distance_value / 1.414214;
1310 do_ruler(1, 0, 0, 0);
1311 get_canvas()->flash();
1316 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1319 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1324 if( canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1325 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1326 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1327 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2 ) {
1328 set_cursor(UPRIGHT_ARROW_CURSOR);
1331 if( canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1332 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1333 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1334 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2 ) {
1335 set_cursor(UPRIGHT_ARROW_CURSOR);
1338 set_cursor(CROSS_CURSOR);
1340 // Update current position
1345 // Assume no ruler measurement if 0 length
1346 if( draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)) ) {
1347 get_canvas()->set_inverse();
1348 get_canvas()->set_color(WHITE);
1349 get_canvas()->draw_line((int)canvas_x1,
1353 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1355 roundf(canvas_x1) + RULERHANDLE_W / 2,
1357 get_canvas()->draw_line(roundf(canvas_x1),
1358 roundf(canvas_y1) - RULERHANDLE_H / 2,
1360 roundf(canvas_y1) + RULERHANDLE_H / 2);
1361 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1363 roundf(canvas_x2) + RULERHANDLE_W / 2,
1365 get_canvas()->draw_line(roundf(canvas_x2),
1366 roundf(canvas_y2) - RULERHANDLE_H / 2,
1368 roundf(canvas_y2) + RULERHANDLE_H / 2);
1369 get_canvas()->set_opaque();
1376 static inline double line_dist(float cx,float cy, float tx,float ty)
1378 double dx = tx-cx, dy = ty-cy;
1379 return sqrt(dx*dx + dy*dy);
1382 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1384 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1385 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1389 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1390 int button_press, int cursor_motion, int draw)
1392 // Retrieve points from top recordable track
1393 //printf("CWindowCanvas::do_mask 1\n");
1394 Track *track = gui->cwindow->calculate_mask_track();
1395 //printf("CWindowCanvas::do_mask 2\n");
1397 if( !track ) return 0;
1398 //printf("CWindowCanvas::do_mask 3\n");
1399 CWindowMaskGUI *mask_gui = (CWindowMaskGUI *)
1400 (gui->tool_panel ? gui->tool_panel->tool_gui : 0);
1401 int draw_markers = mask_gui ? mask_gui->markers : 0;
1402 int draw_boundary = mask_gui ? mask_gui->boundary : 0;
1403 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1404 int64_t position = track->to_units(
1405 mwindow->edl->local_session->get_selectionstart(1),
1407 Auto *prev_auto = 0;
1408 mask_autos->get_prev_auto(position, PLAY_FORWARD, (Auto *&)prev_auto, 1);
1409 MaskAuto *prev_mask = (MaskAuto *)prev_auto;
1411 int update_points = 1;
1412 // Determine the points based on whether
1413 // new keyframes will be generated or drawing is performed.
1414 // If keyframe generation occurs, use the interpolated mask.
1415 // If no keyframe generation occurs, use the previous mask.
1416 int use_interpolated = 0;
1417 if( button_press || cursor_motion ) {
1418 #ifdef USE_KEYFRAME_SPANNING
1419 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1420 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1421 int64_t start_pos = track->to_units(selection_start, 0);
1422 int64_t end_pos = track->to_units(selection_end, 0);
1423 Auto *first = 0, *last = 0;
1424 mask_autos->get_prev_auto(start_pos, PLAY_FORWARD, first, 1);
1425 mask_autos->get_prev_auto(end_pos, PLAY_FORWARD, last, 1);
1426 if( last == first && (!mwindow->edl->session->auto_keyframes) )
1427 use_interpolated = 0;
1429 // If keyframe spanning occurs, use the interpolated points.
1430 // If new keyframe is generated, use the interpolated points.
1431 use_interpolated = 1;
1434 if( mwindow->edl->session->auto_keyframes )
1435 use_interpolated = 1;
1439 use_interpolated = 1;
1441 if( use_interpolated ) {
1442 // Interpolate the points to get exactly what is being rendered at this position.
1443 mask_autos->get_points(&points,
1444 mwindow->edl->session->cwindow_mask,
1445 position, PLAY_FORWARD);
1448 // Use the prev mask
1449 prev_mask->get_points(&points,
1450 mwindow->edl->session->cwindow_mask);
1453 // Projector zooms relative to the center of the track output.
1454 float half_track_w = (float)track->track_w / 2;
1455 float half_track_h = (float)track->track_h / 2;
1456 // Translate mask to projection
1457 float projector_x, projector_y, projector_z;
1458 track->automation->get_projector(
1459 &projector_x, &projector_y, &projector_z,
1460 position, PLAY_FORWARD);
1463 // Get position of cursor relative to mask
1464 float cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
1465 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1466 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1468 projector_x += mwindow->edl->session->output_w / 2;
1469 projector_y += mwindow->edl->session->output_h / 2;
1470 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1471 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1473 // Fix cursor origin
1474 if( button_press ) {
1475 gui->x_origin = mask_cursor_x;
1476 gui->y_origin = mask_cursor_y;
1480 // Points of closest line
1481 int shortest_point1 = -1;
1482 int shortest_point2 = -1;
1484 int shortest_point = -1;
1485 // Distance to closest line
1486 float shortest_line_distance = BC_INFINITY;
1487 // Distance to closest point
1488 float shortest_point_distance = BC_INFINITY;
1489 int selected_point = -1;
1490 int selected_control_point = -1;
1491 float selected_control_point_distance = BC_INFINITY;
1492 ArrayList<int> x_points;
1493 ArrayList<int> y_points;
1495 if( !cursor_motion ) {
1497 get_canvas()->set_color(WHITE);
1498 get_canvas()->set_inverse();
1500 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1502 // Never draw closed polygon and a closed
1503 // polygon is harder to add points to.
1504 for( int i = 0; i < points.size() && !result; i++ ) {
1505 MaskPoint *point1 = points.get(i);
1506 MaskPoint *point2 = (i >= points.size() - 1) ?
1507 points.get(0) : points.get(i + 1);
1508 if( button_press ) {
1509 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1510 if( point_distance1 < shortest_point_distance || shortest_point < 0 ) {
1511 shortest_point_distance = point_distance1;
1515 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1516 if( point_distance2 < shortest_point_distance || shortest_point < 0 ) {
1517 shortest_point_distance = point_distance2;
1518 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1522 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1524 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1525 //point1->x, point1->y, point2->x, point2->y, projector_z);
1526 for( int j = 0; j <= segments && !result; j++ ) {
1527 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1528 float x0 = point1->x, y0 = point1->y;
1529 float x1 = point1->x + point1->control_x2;
1530 float y1 = point1->y + point1->control_y2;
1531 float x2 = point2->x + point2->control_x1;
1532 float y2 = point2->y + point2->control_y1;
1533 float x3 = point2->x, y3 = point2->y;
1534 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1535 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1536 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1537 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1538 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1539 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1540 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1541 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1543 float t = (float)j / segments;
1544 float tpow2 = t * t;
1545 float tpow3 = t * t * t;
1547 float invtpow2 = invt * invt;
1548 float invtpow3 = invt * invt * invt;
1550 float x = ( invtpow3 * x0
1551 + 3 * t * invtpow2 * x1
1552 + 3 * tpow2 * invt * x2
1554 float y = ( invtpow3 * y0
1555 + 3 * t * invtpow2 * y1
1556 + 3 * tpow2 * invt * y2
1558 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1559 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1560 // Test new point addition
1561 if( button_press ) {
1562 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1564 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1565 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1566 if( line_distance < shortest_line_distance ||
1567 shortest_point1 < 0 ) {
1568 shortest_line_distance = line_distance;
1569 shortest_point1 = i;
1570 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1571 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1572 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1575 // Test existing point selection
1577 if( gui->ctrl_down() ) {
1578 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1580 if( distance < selected_control_point_distance ) {
1582 selected_control_point = 1;
1583 selected_control_point_distance = distance;
1587 if( !gui->shift_down() ) {
1588 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1589 if( test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0) ) {
1594 selected_point = shortest_point;
1597 // Test second point
1598 if( gui->ctrl_down() ) {
1599 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1601 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1602 if( distance < selected_control_point_distance ) {
1603 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1604 selected_control_point = 0;
1605 selected_control_point_distance = distance;
1608 else if( i < points.size() - 1 ) {
1609 if( !gui->shift_down() ) {
1610 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1611 if( test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3) ) {
1612 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1616 selected_point = shortest_point;
1621 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1625 if( draw ) { // Draw joining line
1626 x_points.append((int)canvas_x);
1627 y_points.append((int)canvas_y);
1630 if( j == segments ) {
1631 if( draw && draw_markers ) { // Draw second anchor
1632 if( i < points.size() - 1 ) {
1633 if( i == gui->affected_point - 1 )
1634 get_canvas()->draw_disc(
1635 (int)canvas_x - CONTROL_W / 2,
1636 (int)canvas_y - CONTROL_W / 2,
1637 CONTROL_W, CONTROL_H);
1639 get_canvas()->draw_circle(
1640 (int)canvas_x - CONTROL_W / 2,
1641 (int)canvas_y - CONTROL_W / 2,
1642 CONTROL_W, CONTROL_H);
1643 // char string[BCTEXTLEN];
1644 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1645 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1647 // Draw second control point.
1648 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1649 get_canvas()->draw_line(
1650 (int)canvas_x, (int)canvas_y,
1651 (int)canvas_x2, (int)canvas_y2);
1652 get_canvas()->draw_rectangle(
1653 (int)canvas_x2 - CONTROL_W / 2,
1654 (int)canvas_y2 - CONTROL_H / 2,
1655 CONTROL_W, CONTROL_H);
1660 // Draw first anchor
1661 if( i == 0 && draw ) {
1662 if( draw_boundary ) {
1663 char mask_label[BCSTRLEN];
1664 int k = mwindow->edl->session->cwindow_mask;
1665 if( !prev_mask || k < 0 || k >= prev_mask->masks.size() )
1666 sprintf(mask_label, "%d", k);
1668 sprintf(mask_label, "%s", prev_mask->masks[k]->name);
1669 get_canvas()->draw_text(
1670 (int)canvas_x - FIRST_CONTROL_W,
1671 (int)canvas_y - FIRST_CONTROL_H,
1674 if( draw_markers ) {
1675 get_canvas()->draw_disc(
1676 (int)canvas_x - FIRST_CONTROL_W / 2,
1677 (int)canvas_y - FIRST_CONTROL_H / 2,
1678 FIRST_CONTROL_W, FIRST_CONTROL_H);
1682 // Draw first control point.
1683 if( draw && draw_markers ) {
1684 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1685 get_canvas()->draw_line(
1686 (int)canvas_x, (int)canvas_y,
1687 (int)canvas_x1, (int)canvas_y1);
1688 get_canvas()->draw_rectangle(
1689 (int)canvas_x1 - CONTROL_W / 2,
1690 (int)canvas_y1 - CONTROL_H / 2,
1691 CONTROL_W, CONTROL_H);
1693 x_points.append((int)canvas_x);
1694 y_points.append((int)canvas_y);
1697 //printf("CWindowCanvas::do_mask 1\n");
1701 //printf("CWindowCanvas::do_mask 1\n");
1703 BC_WindowBase *cvs_win = get_canvas();
1704 if( draw && draw_boundary ) {
1705 cvs_win->draw_polygon(&x_points, &y_points);
1706 cvs_win->set_opaque();
1708 if( draw && mask_gui && mask_gui->focused ) {
1709 float fx = atof(mask_gui->focus_x->get_text());
1710 float fy = atof(mask_gui->focus_y->get_text());
1711 fx = (fx - half_track_w) * projector_z + projector_x;
1712 fy = (fy - half_track_h) * projector_z + projector_y;
1713 output_to_canvas(mwindow->edl, 0, fx, fy);
1714 float r = bmax(cvs_win->get_w(), cvs_win->get_h());
1717 int fw = 2*d+3, fh = fw;
1718 VFrame focus(fw,fh, BC_RGBA8888);
1719 focus.transfer_from(gui->focus_frame);
1720 fx -= fw/2.f; fy -= fh/2.f;
1721 BC_Pixmap focus_pixmap(cvs_win, &focus, PIXMAP_ALPHA);
1722 cvs_win->draw_pixmap(&focus_pixmap,fx,fy);
1724 cvs_win->set_line_width((int)(0.0025*r) + 1);
1725 cvs_win->set_color(BLUE);
1726 cvs_win->draw_line(fx-d,fy-d, fx+d, fy+d);
1727 cvs_win->draw_line(fx-d,fy+d, fx+d, fy-d);
1728 cvs_win->set_line_width(0);
1729 cvs_win->set_color(WHITE);
1732 if( draw && mask_gui && draw_markers && points.size() ) {
1733 float cx = 0, cy = 0;
1734 int n = points.size();
1735 for( int i=0; i<n; ++i ) {
1736 MaskPoint *point = points.get(i);
1737 cx += point->x; cy += point->y;
1740 if( !mask_gui->focused )
1741 mask_gui->set_focused(0, cx, cy);
1742 cx = (cx - half_track_w) * projector_z + projector_x;
1743 cy = (cy - half_track_h) * projector_z + projector_y;
1744 output_to_canvas(mwindow->edl, 0, cx, cy);
1745 float r = bmax(cvs_win->get_w(), cvs_win->get_h());
1747 cvs_win->set_line_width((int)(0.002*r) + 1);
1748 cvs_win->set_color(ORANGE);
1749 cvs_win->draw_line(cx-d,cy, cx+d, cy);
1750 cvs_win->draw_line(cx,cy-d, cx, cy+d);
1751 cvs_win->set_line_width(0);
1752 cvs_win->set_color(WHITE);
1754 //printf("CWindowCanvas::do_mask 1\n");
1757 if( button_press && !result ) {
1758 gui->affected_track = gui->cwindow->calculate_mask_track();
1760 // Get keyframe outside the EDL to edit. This must be rendered
1761 // instead of the EDL keyframes when it exists. Then it must be
1762 // applied to the EDL keyframes on buttonrelease.
1763 if( gui->affected_track ) {
1764 #ifdef USE_KEYFRAME_SPANNING
1765 // Make copy of current parameters in local keyframe
1766 gui->mask_keyframe =
1767 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1769 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1772 gui->mask_keyframe =
1773 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1777 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1779 if( get_buttonpress() == WHEEL_UP || get_buttonpress() == WHEEL_DOWN ) {
1780 if( !gui->shift_down() ) {
1781 mwindow->undo->update_undo_before(_("mask rotate"), this);
1782 gui->current_operation = CWINDOW_MASK_ROTATE;
1785 mwindow->undo->update_undo_before(_("mask scale"), this);
1786 gui->current_operation = CWINDOW_MASK_SCALE;
1788 gui->affected_point = 0;
1791 // Translate entire keyframe
1792 if( gui->alt_down() && mask->points.size() ) {
1793 mwindow->undo->update_undo_before(_("mask translate"), 0);
1794 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1795 gui->affected_point = 0;
1798 // Existing point or control point was selected
1799 if( selected_point >= 0 ) {
1800 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1801 gui->affected_point = selected_point;
1803 if( selected_control_point == 0 )
1804 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1806 if( selected_control_point == 1 )
1807 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1809 gui->current_operation = mwindow->edl->session->cwindow_operation;
1811 else // No existing point or control point was selected so create a new one
1812 if( !gui->ctrl_down() && !gui->alt_down() ) {
1813 mwindow->undo->update_undo_before(_("mask point"), 0);
1814 // Create the template
1815 MaskPoint *point = new MaskPoint;
1816 point->x = mask_cursor_x;
1817 point->y = mask_cursor_y;
1818 point->control_x1 = 0;
1819 point->control_y1 = 0;
1820 point->control_x2 = 0;
1821 point->control_y2 = 0;
1824 if( shortest_point2 < shortest_point1 ) {
1825 shortest_point2 ^= shortest_point1;
1826 shortest_point1 ^= shortest_point2;
1827 shortest_point2 ^= shortest_point1;
1832 // printf("CWindowGUI::do_mask 40\n");
1833 // mwindow->edl->dump();
1834 // printf("CWindowGUI::do_mask 50\n");
1838 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1839 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1840 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1842 // Append to end of list
1843 if( shortest_point1 == shortest_point2 ||
1844 labs(shortest_point1 - shortest_point2) > 1) {
1845 #ifdef USE_KEYFRAME_SPANNING
1847 MaskPoint *new_point = new MaskPoint;
1848 points.append(new_point);
1849 *new_point = *point;
1850 gui->affected_point = points.size() - 1;
1854 // Need to apply the new point to every keyframe
1855 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1856 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1857 MaskPoint *new_point = new MaskPoint;
1858 submask->points.append(new_point);
1859 *new_point = *point;
1860 if( current == (MaskAuto*)mask_autos->default_auto )
1861 current = (MaskAuto*)mask_autos->first;
1863 current = (MaskAuto*)NEXT;
1865 gui->affected_point = mask->points.size() - 1;
1871 // Insert between 2 points, shifting back point 2
1872 if( shortest_point1 >= 0 && shortest_point2 >= 0 ) {
1874 #ifdef USE_KEYFRAME_SPANNING
1875 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1877 if( points.size() >= shortest_point2 ) {
1878 MaskPoint *new_point = new MaskPoint;
1880 for( int i = points.size() - 1;
1881 i > shortest_point2;
1883 points.values[i] = points.values[i - 1];
1884 points.values[shortest_point2] = new_point;
1886 *new_point = *point;
1891 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1892 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1893 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1895 if( submask->points.size() >= shortest_point2 ) {
1896 MaskPoint *new_point = new MaskPoint;
1897 submask->points.append(0);
1898 for( int i = submask->points.size() - 1;
1899 i > shortest_point2;
1901 submask->points.values[i] = submask->points.values[i - 1];
1902 submask->points.values[shortest_point2] = new_point;
1904 *new_point = *point;
1907 if( current == (MaskAuto*)mask_autos->default_auto )
1908 current = (MaskAuto*)mask_autos->first;
1910 current = (MaskAuto*)NEXT;
1914 gui->affected_point = shortest_point2;
1919 // printf("CWindowGUI::do_mask 20\n");
1920 // mwindow->edl->dump();
1921 // printf("CWindowGUI::do_mask 30\n");
1924 //printf("CWindowCanvas::do_mask 1\n");
1925 // Create the first point.
1926 #ifdef USE_KEYFRAME_SPANNING
1927 MaskPoint *new_point = new MaskPoint;
1928 points.append(new_point);
1929 *new_point = *point;
1930 gui->affected_point = points.size() - 1;
1932 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1933 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1934 MaskPoint *new_point = new MaskPoint;
1935 submask->points.append(new_point);
1936 *new_point = *point;
1937 if( current == (MaskAuto*)mask_autos->default_auto )
1938 current = (MaskAuto*)mask_autos->first;
1940 current = (MaskAuto*)NEXT;
1942 gui->affected_point = points.size() - 1;
1945 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
1948 gui->current_operation = mwindow->edl->session->cwindow_operation;
1949 // Delete the template
1958 if( button_press && result ) {
1959 #ifdef USE_KEYFRAME_SPANNING
1960 MaskPoints &mask_points = points;
1962 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1963 MaskPoints &mask_points = mask->points;
1965 int k = gui->affected_point;
1966 if( k >= 0 && k < mask_points.size() ) {
1967 MaskPoint *point = mask_points.values[k];
1968 gui->center_x = point->x;
1969 gui->center_y = point->y;
1970 gui->control_in_x = point->control_x1;
1971 gui->control_in_y = point->control_y1;
1972 gui->control_out_x = point->control_x2;
1973 gui->control_out_y = point->control_y2;
1976 gui->center_x = gui->center_y = 0;
1977 gui->control_in_x = gui->control_in_y = 0;
1978 gui->control_out_x = gui->control_out_y = 0;
1980 gui->tool_panel->raise_window();
1983 //printf("CWindowCanvas::do_mask 8\n");
1984 if( cursor_motion ) {
1986 #ifdef USE_KEYFRAME_SPANNING
1987 // Must update the reference keyframes for every cursor motion
1988 gui->mask_keyframe = (MaskAuto*)gui->cwindow->
1989 calculate_affected_auto(mask_autos, 0);
1990 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1993 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1995 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1996 if( mask && gui->affected_point >= 0 &&
1997 gui->affected_point < mask->points.size() &&
1998 gui->current_operation != CWINDOW_NONE ) {
1999 // mwindow->undo->update_undo_before(_("mask point"), this);
2000 #ifdef USE_KEYFRAME_SPANNING
2001 MaskPoints &mask_points = points;
2003 MaskPoints &mask_points = mask->points;
2005 MaskPoint *point = mask_points.get(gui->affected_point);
2006 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2007 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask_points.size(), gui->affected_point);
2009 float last_x = point->x;
2010 float last_y = point->y;
2011 float last_control_x1 = point->control_x1;
2012 float last_control_y1 = point->control_y1;
2013 float last_control_x2 = point->control_x2;
2014 float last_control_y2 = point->control_y2;
2017 switch( gui->current_operation ) {
2019 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2020 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
2021 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
2024 case CWINDOW_MASK_CONTROL_IN:
2025 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
2026 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
2029 case CWINDOW_MASK_CONTROL_OUT:
2030 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
2031 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
2034 case CWINDOW_MASK_TRANSLATE: {
2035 if( !mask_gui ) break;
2036 int mode = mask_gui->scale_mode;
2037 MaskAuto *keyframe = gui->mask_keyframe;
2038 int gang = mask_gui->gang_focus->get_value();
2039 float dx = mask_cursor_x - gui->x_origin;
2040 float dy = mask_cursor_y - gui->y_origin;
2041 if( !dx && !dy ) break;
2042 int k = mwindow->edl->session->cwindow_mask;
2043 int n = gang ? keyframe->masks.size() : k+1;
2044 for( int j=gang? 0 : k; j<n; ++j ) {
2045 if( !mask_gui->mask_enables[j]->get_value() ) continue;
2046 SubMask *sub_mask = keyframe->get_submask(j);
2047 if( !sub_mask ) continue;
2048 MaskPoints &points = sub_mask->points;
2049 for( int i=0; i<points.size(); ++i ) {
2050 MaskPoint *point = points[i];
2051 if( mode == MASK_SCALE_X || mode == MASK_SCALE_XY ) point->x += dx;
2052 if( mode == MASK_SCALE_Y || mode == MASK_SCALE_XY ) point->y += dy;
2055 gui->x_origin = mask_cursor_x;
2056 gui->y_origin = mask_cursor_y;
2061 case CWINDOW_MASK_ROTATE:
2063 case CWINDOW_MASK_SCALE: {
2064 if( !mask_gui || !mask_points.size() ) break;
2065 float cx = gui->x_origin, cy = gui->y_origin;
2066 if( mask_gui->focused ) {
2067 cx = atof(mask_gui->focus_x->get_text());
2068 cy = atof(mask_gui->focus_y->get_text());
2070 else if( !gui->ctrl_down() ) {
2072 int n = mask_points.size();
2073 for( int i=0; i<n; ++i ) {
2074 MaskPoint *point = mask_points.values[i];
2075 cx += point->x; cy += point->y;
2078 mask_gui->set_focused(0, cx, cy);
2083 gui->get_triple_click() ? 8. :
2084 gui->get_double_click() ? 4. :
2086 int button_no = get_buttonpress();
2087 double ds = accel/64., dt = accel*M_PI/360.;
2088 double scale = button_no == WHEEL_UP ? 1.+ds : 1.-ds;
2089 int mode = mask_gui->scale_mode;
2090 double xscale = !rotate && (mode == MASK_SCALE_X ||
2091 mode == MASK_SCALE_XY ) ? scale : 1.;
2092 double yscale = !rotate && (mode == MASK_SCALE_Y ||
2093 mode == MASK_SCALE_XY ) ? scale : 1.;
2094 double theta = button_no == WHEEL_UP ? dt : -dt;
2095 if( rotate ? theta==0 : scale==1 ) break;
2096 float st = sin(theta), ct = cos(theta);
2097 MaskAuto *keyframe = gui->mask_keyframe;
2098 int gang = mask_gui->gang_focus->get_value();
2099 int k = mwindow->edl->session->cwindow_mask;
2100 int n = gang ? keyframe->masks.size() : k+1;
2101 for( int j=gang? 0 : k; j<n; ++j ) {
2102 if( !mask_gui->mask_enables[j]->get_value() ) continue;
2103 SubMask *sub_mask = keyframe->get_submask(j);
2104 if( !sub_mask ) continue;
2105 MaskPoints &points = sub_mask->points;
2106 for( int i=0; i<points.size(); ++i ) {
2107 MaskPoint *point = points[i];
2108 float px = point->x - gui->x_origin;
2109 float py = point->y - gui->y_origin;
2110 float nx = !rotate ? px*xscale : px*ct + py*st;
2111 float ny = !rotate ? py*yscale : py*ct - px*st;
2112 point->x = nx + gui->x_origin;
2113 point->y = ny + gui->y_origin;
2114 px = point->control_x1; py = point->control_y1;
2115 point->control_x1 = !rotate ? px*xscale : px*ct + py*st;
2116 point->control_y1 = !rotate ? py*yscale : py*ct - px*st;
2117 px = point->control_x2; py = point->control_y2;
2118 point->control_x2 = !rotate ? px*xscale : px*ct + py*st;
2119 point->control_y2 = !rotate ? py*yscale : py*ct - px*st;
2128 if( !(rerender && redraw) && (!EQUIV(last_x, point->x) ||
2129 !EQUIV(last_y, point->y) ||
2130 !EQUIV(last_control_x1, point->control_x1) ||
2131 !EQUIV(last_control_y1, point->control_y1) ||
2132 !EQUIV(last_control_x2, point->control_x2) ||
2133 !EQUIV(last_control_y2, point->control_y2)) ) {
2139 if( gui->current_operation == CWINDOW_NONE ) {
2140 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
2142 for( int i = 0; i < points.size() && !over_point; i++ ) {
2143 MaskPoint *point = points.get(i);
2144 float x0 = point->x;
2145 float y0 = point->y;
2146 float x1 = point->x + point->control_x1;
2147 float y1 = point->y + point->control_y1;
2148 float x2 = point->x + point->control_x2;
2149 float y2 = point->y + point->control_y2;
2150 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
2151 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
2153 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
2154 if( test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0) ) {
2158 if( !over_point && gui->ctrl_down() ) {
2159 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
2160 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
2161 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2162 if( test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1) ) {
2166 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2167 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2168 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2169 if( test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2) ) {
2176 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2181 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2184 #ifdef USE_KEYFRAME_SPANNING
2185 // Must commit change after operation.
2186 if( rerender && track ) {
2187 // Swap EDL keyframe with original.
2188 // Apply new values to keyframe span
2189 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2190 temp_keyframe.copy_data(gui->mask_keyframe);
2191 // Apply interpolated points back to keyframe
2193 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2194 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2195 mask_autos->update_parameter(&temp_keyframe);
2198 //printf("CWindowCanvas::do_mask 20\n");
2200 if( draw && draw_boundary && !draw_markers ) {
2201 BC_WindowBase *cvs_win = get_canvas();
2202 cvs_win->set_inverse();
2203 cvs_win->set_color(RED+GREEN);
2204 for( int k=0; k<SUBMASKS; ++k ) {
2205 if( k == mwindow->edl->session->cwindow_mask ) continue;
2206 points.remove_all_objects();
2207 if( use_interpolated )
2208 mask_autos->get_points(&points, k, position, PLAY_FORWARD);
2210 prev_mask->get_points(&points, k);
2212 edge.load(points, 0);
2213 for( int i=0; i<edge.size(); ++i ) {
2214 MaskCoord a = edge[i];
2215 MaskCoord b = i<edge.size()-1 ? edge[i+1] : edge[0];
2216 float ax = a.x, ay = a.y;
2217 float bx = b.x, by = b.y;
2218 output_to_canvas(mwindow->edl, 0, ax, ay);
2219 output_to_canvas(mwindow->edl, 0, bx, by);
2220 cvs_win->draw_line(ax,ay, bx,by);
2228 int CWindowCanvas::do_mask_focus()
2230 Track *track = gui->cwindow->calculate_affected_track();
2231 int64_t position = track->to_units(
2232 mwindow->edl->local_session->get_selectionstart(1),
2234 float projector_x, projector_y, projector_z;
2235 track->automation->get_projector(
2236 &projector_x, &projector_y, &projector_z,
2237 position, PLAY_FORWARD);
2238 float cx = get_cursor_x(), cy = get_cursor_y();
2239 canvas_to_output(mwindow->edl, 0, cx, cy);
2240 projector_x += mwindow->edl->session->output_w / 2;
2241 projector_y += mwindow->edl->session->output_h / 2;
2242 float half_track_w = (float)track->track_w / 2;
2243 float half_track_h = (float)track->track_h / 2;
2244 cx = (cx - projector_x) / projector_z + half_track_w;
2245 cy = (cy - projector_y) / projector_z + half_track_h;
2246 CWindowMaskGUI *mask_gui = (CWindowMaskGUI*) gui->tool_panel->tool_gui;
2247 mask_gui->set_focused(1, cx, cy);
2251 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2254 int radius = mwindow->edl->session->eyedrop_radius;
2262 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
2265 row1 = gui->eyedrop_y - radius;
2266 row2 = gui->eyedrop_y + radius;
2267 column1 = gui->eyedrop_x - radius;
2268 column2 = gui->eyedrop_x + radius;
2270 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2271 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2272 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2273 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2275 if( row2 <= row1 ) row2 = row1 + 1;
2276 if( column2 <= column1 ) column2 = column1 + 1;
2283 output_to_canvas(mwindow->edl, 0, x1, y1);
2284 output_to_canvas(mwindow->edl, 0, x2, y2);
2285 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2287 if( x2 - x1 >= 1 && y2 - y1 >= 1 ) {
2288 get_canvas()->set_inverse();
2289 get_canvas()->set_color(WHITE);
2291 get_canvas()->draw_rectangle((int)x1,
2296 get_canvas()->set_opaque();
2297 get_canvas()->flash();
2303 if( button_press ) {
2304 gui->current_operation = CWINDOW_EYEDROP;
2305 gui->tool_panel->raise_window();
2308 if( gui->current_operation == CWINDOW_EYEDROP ) {
2309 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2311 // Get color out of frame.
2312 // Doesn't work during playback because that bypasses the refresh frame.
2313 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
2314 float cursor_x = get_cursor_x();
2315 float cursor_y = get_cursor_y();
2316 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2317 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2318 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2320 row1 = cursor_y - radius;
2321 row2 = cursor_y + radius;
2322 column1 = cursor_x - radius;
2323 column2 = cursor_x + radius;
2324 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2325 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2326 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2327 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2328 if( row2 <= row1 ) row2 = row1 + 1;
2329 if( column2 <= column1 ) column2 = column1 + 1;
2333 if( gui->eyedrop_visible ) {
2335 do_eyedrop(temp, 0, 1);
2336 gui->eyedrop_visible = 0;
2339 gui->eyedrop_x = cursor_x;
2340 gui->eyedrop_y = cursor_y;
2345 do_eyedrop(temp, 0, 1);
2346 gui->eyedrop_visible = 1;
2349 #define GET_COLOR(type, components, max, do_yuv) { \
2350 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2352 float red = (float)*row++ / max; \
2353 float green = (float)*row++ / max; \
2354 float blue = (float)*row++ / max; \
2356 YUV::yuv.yuv_to_rgb_f(red, green, blue, red, green-0.5, blue-0.5); \
2357 mwindow->edl->local_session->red += red; \
2358 mwindow->edl->local_session->green += green; \
2359 mwindow->edl->local_session->blue += blue; \
2360 if( red > mwindow->edl->local_session->red_max ) mwindow->edl->local_session->red_max = red; \
2361 if( green > mwindow->edl->local_session->green_max ) mwindow->edl->local_session->green_max = green; \
2362 if( blue > mwindow->edl->local_session->blue_max ) mwindow->edl->local_session->blue_max = blue; \
2365 mwindow->edl->local_session->red = 0;
2366 mwindow->edl->local_session->green = 0;
2367 mwindow->edl->local_session->blue = 0;
2368 mwindow->edl->local_session->red_max = 0;
2369 mwindow->edl->local_session->green_max = 0;
2370 mwindow->edl->local_session->blue_max = 0;
2371 for( int i = row1; i < row2; i++ ) {
2372 for( int j = column1; j < column2; j++ ) {
2373 switch( refresh_frame->get_color_model() )
2376 GET_COLOR(unsigned char, 3, 0xff, 1);
2379 GET_COLOR(unsigned char, 4, 0xff, 1);
2382 GET_COLOR(uint16_t, 3, 0xffff, 1);
2384 case BC_YUVA16161616:
2385 GET_COLOR(uint16_t, 4, 0xffff, 1);
2388 GET_COLOR(unsigned char, 3, 0xff, 0);
2391 GET_COLOR(unsigned char, 4, 0xff, 0);
2394 GET_COLOR(float, 3, 1.0, 0);
2397 GET_COLOR(float, 4, 1.0, 0);
2403 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2404 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2405 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2409 mwindow->edl->local_session->red = 0;
2410 mwindow->edl->local_session->green = 0;
2411 mwindow->edl->local_session->blue = 0;
2412 gui->eyedrop_visible = 0;
2421 // Can't rerender since the color value is from the output of any effect it
2424 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2430 int CWindowCanvas::need_overlays()
2432 if( mwindow->edl->session->safe_regions ) return 1;
2433 if( mwindow->edl->session->cwindow_scrollbars ) return 1;
2434 if( gui->highlighted ) return 1;
2435 switch( mwindow->edl->session->cwindow_operation ) {
2436 case CWINDOW_EYEDROP:
2437 if( ! gui->eyedrop_visible ) break;
2438 case CWINDOW_CAMERA:
2439 case CWINDOW_PROJECTOR:
2448 void CWindowCanvas::draw_overlays()
2450 if( mwindow->edl->session->safe_regions ) {
2451 draw_safe_regions();
2454 if( mwindow->edl->session->cwindow_scrollbars ) {
2455 // Always draw output rectangle
2456 float x1, y1, x2, y2;
2458 x2 = mwindow->edl->session->output_w;
2460 y2 = mwindow->edl->session->output_h;
2461 output_to_canvas(mwindow->edl, 0, x1, y1);
2462 output_to_canvas(mwindow->edl, 0, x2, y2);
2464 get_canvas()->set_inverse();
2465 get_canvas()->set_color(WHITE);
2466 int ix1 = x1-1, iy1 = y1-1, ix2 = x2+1, iy2 = y2+1;
2467 get_canvas()->draw_rectangle(ix1, iy1, ix2-ix1, iy2-iy1);
2468 get_canvas()->set_opaque();
2471 if( gui->highlighted ) {
2472 get_canvas()->set_color(WHITE);
2473 get_canvas()->set_inverse();
2474 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2475 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2476 get_canvas()->set_opaque();
2479 int temp1 = 0, temp2 = 0;
2480 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2481 switch( mwindow->edl->session->cwindow_operation )
2483 case CWINDOW_CAMERA:
2487 case CWINDOW_PROJECTOR:
2496 do_mask(temp1, temp2, 0, 0, 1);
2500 do_ruler(1, 0, 0, 0);
2503 case CWINDOW_EYEDROP:
2504 if( gui->eyedrop_visible ) {
2506 do_eyedrop(rerender, 0, 1);
2507 gui->eyedrop_visible = 1;
2513 void CWindowCanvas::draw_safe_regions()
2515 float action_x1, action_x2, action_y1, action_y2;
2516 float title_x1, title_x2, title_y1, title_y2;
2518 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2519 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2520 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2521 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2522 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2523 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2524 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2525 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2527 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2528 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2529 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2530 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2532 get_canvas()->set_inverse();
2533 get_canvas()->set_color(WHITE);
2535 get_canvas()->draw_rectangle((int)action_x1,
2537 (int)(action_x2 - action_x1),
2538 (int)(action_y2 - action_y1));
2539 get_canvas()->draw_rectangle((int)title_x1,
2541 (int)(title_x2 - title_x1),
2542 (int)(title_y2 - title_y1));
2544 get_canvas()->set_opaque();
2548 void CWindowCanvas::create_keyframe(int do_camera)
2550 Track *affected_track = gui->cwindow->calculate_affected_track();
2551 if( affected_track ) {
2552 double pos = mwindow->edl->local_session->get_selectionstart(1);
2553 int64_t position = affected_track->to_units(pos, 0);
2554 int ix = do_camera ? AUTOMATION_CAMERA_X : AUTOMATION_PROJECTOR_X;
2555 int iy = do_camera ? AUTOMATION_CAMERA_Y : AUTOMATION_PROJECTOR_Y;
2556 int iz = do_camera ? AUTOMATION_CAMERA_Z : AUTOMATION_PROJECTOR_Z;
2557 FloatAuto *prev, *next;
2558 FloatAutos **autos = (FloatAutos**)affected_track->automation->autos;
2559 FloatAutos *x_autos = autos[ix]; prev = 0; next = 0;
2560 float x_value = x_autos->get_value(position, PLAY_FORWARD, prev, next);
2561 FloatAutos *y_autos = autos[iy]; prev = 0; next = 0;
2562 float y_value = y_autos->get_value(position, PLAY_FORWARD, prev, next);
2563 FloatAutos *z_autos = autos[iz]; prev = 0; next = 0;
2564 float z_value = z_autos->get_value(position, PLAY_FORWARD, prev, next);
2565 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2567 gui->cwindow->calculate_affected_autos(affected_track,
2568 &x_keyframe, &y_keyframe, &z_keyframe,
2569 do_camera, -1, -1, -1, 0);
2570 x_keyframe->set_value(x_value);
2571 y_keyframe->set_value(y_value);
2572 z_keyframe->set_value(z_value);
2574 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2578 void CWindowCanvas::camera_keyframe() { create_keyframe(1); }
2579 void CWindowCanvas::projector_keyframe() { create_keyframe(0); }
2581 void CWindowCanvas::reset_keyframe(int do_camera)
2583 Track *affected_track = gui->cwindow->calculate_affected_track();
2584 if( affected_track ) {
2585 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2586 gui->cwindow->calculate_affected_autos(affected_track,
2587 &x_keyframe, &y_keyframe, &z_keyframe,
2588 do_camera, 1, 1, 1);
2590 x_keyframe->set_value(0);
2591 y_keyframe->set_value(0);
2592 z_keyframe->set_value(1);
2594 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2598 void CWindowCanvas::reset_camera() { reset_keyframe(1); }
2599 void CWindowCanvas::reset_projector() { reset_keyframe(0); }
2602 int CWindowCanvas::test_crop(int button_press, int &redraw)
2605 int handle_selected = -1;
2606 float x1 = mwindow->edl->session->crop_x1;
2607 float y1 = mwindow->edl->session->crop_y1;
2608 float x2 = mwindow->edl->session->crop_x2;
2609 float y2 = mwindow->edl->session->crop_y2;
2610 float cursor_x = get_cursor_x();
2611 float cursor_y = get_cursor_y();
2612 float canvas_x1 = x1;
2613 float canvas_y1 = y1;
2614 float canvas_x2 = x2;
2615 float canvas_y2 = y2;
2616 float canvas_cursor_x = cursor_x;
2617 float canvas_cursor_y = cursor_y;
2619 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2620 // Use screen normalized coordinates for hot spot tests.
2621 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2622 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2625 if( gui->current_operation == CWINDOW_CROP ) {
2626 handle_selected = gui->crop_handle;
2629 if( canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2630 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H ) {
2631 handle_selected = 0;
2632 gui->crop_origin_x = x1;
2633 gui->crop_origin_y = y1;
2636 if( canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2637 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H ) {
2638 handle_selected = 1;
2639 gui->crop_origin_x = x2;
2640 gui->crop_origin_y = y1;
2643 if( canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2644 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2 ) {
2645 handle_selected = 2;
2646 gui->crop_origin_x = x1;
2647 gui->crop_origin_y = y2;
2650 if( canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2651 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2 ) {
2652 handle_selected = 3;
2653 gui->crop_origin_x = x2;
2654 gui->crop_origin_y = y2;
2659 gui->crop_origin_x = cursor_x;
2660 gui->crop_origin_y = cursor_y;
2663 // printf("test crop %d %d\n",
2664 // gui->current_operation,
2665 // handle_selected);
2668 if( button_press ) {
2669 if( gui->alt_down() ) {
2670 gui->crop_translate = 1;
2671 gui->crop_origin_x1 = x1;
2672 gui->crop_origin_y1 = y1;
2673 gui->crop_origin_x2 = x2;
2674 gui->crop_origin_y2 = y2;
2677 gui->crop_translate = 0;
2679 gui->current_operation = CWINDOW_CROP;
2680 gui->crop_handle = handle_selected;
2681 gui->x_origin = cursor_x;
2682 gui->y_origin = cursor_y;
2683 gui->tool_panel->raise_window();
2686 if( handle_selected < 0 && !gui->crop_translate ) {
2689 mwindow->edl->session->crop_x1 = (int)x1;
2690 mwindow->edl->session->crop_y1 = (int)y1;
2691 mwindow->edl->session->crop_x2 = (int)x2;
2692 mwindow->edl->session->crop_y2 = (int)y2;
2697 // Translate all 4 points
2698 if( gui->current_operation == CWINDOW_CROP && gui->crop_translate ) {
2699 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2700 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2701 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2702 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2704 mwindow->edl->session->crop_x1 = (int)x1;
2705 mwindow->edl->session->crop_y1 = (int)y1;
2706 mwindow->edl->session->crop_x2 = (int)x2;
2707 mwindow->edl->session->crop_y2 = (int)y2;
2713 if( gui->current_operation == CWINDOW_CROP ) {
2714 switch( gui->crop_handle ) {
2716 x1 = gui->crop_origin_x;
2717 y1 = gui->crop_origin_y;
2718 x2 = gui->crop_origin_x;
2719 y2 = gui->crop_origin_y;
2720 if( cursor_x < gui->x_origin ) {
2721 if( cursor_y < gui->y_origin ) {
2726 if( cursor_y >= gui->y_origin ) {
2732 if( cursor_x >= gui->x_origin ) {
2733 if( cursor_y < gui->y_origin ) {
2738 if( cursor_y >= gui->y_origin ) {
2744 // printf("test crop %d %d %d %d\n",
2745 // mwindow->edl->session->crop_x1,
2746 // mwindow->edl->session->crop_y1,
2747 // mwindow->edl->session->crop_x2,
2748 // mwindow->edl->session->crop_y2);
2751 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2752 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2755 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2756 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2759 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2760 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2763 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2764 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2768 if( !EQUIV(mwindow->edl->session->crop_x1, x1) ||
2769 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2770 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2771 !EQUIV(mwindow->edl->session->crop_y2, y2) ) {
2776 switch( gui->crop_handle ) {
2777 case 0: gui->crop_handle = 1; break;
2778 case 1: gui->crop_handle = 0; break;
2779 case 2: gui->crop_handle = 3; break;
2780 case 3: gui->crop_handle = 2; break;
2789 switch( gui->crop_handle ) {
2790 case 0: gui->crop_handle = 2; break;
2791 case 1: gui->crop_handle = 3; break;
2792 case 2: gui->crop_handle = 0; break;
2793 case 3: gui->crop_handle = 1; break;
2798 mwindow->edl->session->crop_x1 = (int)x1;
2799 mwindow->edl->session->crop_y1 = (int)y1;
2800 mwindow->edl->session->crop_x2 = (int)x2;
2801 mwindow->edl->session->crop_y2 = (int)y2;
2807 // Update cursor font
2808 if( handle_selected >= 0 ) {
2809 switch( handle_selected ) {
2810 case 0: set_cursor(UPLEFT_RESIZE); break;
2811 case 1: set_cursor(UPRIGHT_RESIZE); break;
2812 case 2: set_cursor(DOWNLEFT_RESIZE); break;
2813 case 3: set_cursor(DOWNRIGHT_RESIZE); break;
2818 set_cursor(ARROW_CURSOR);
2820 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2823 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2824 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2825 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2826 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2827 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2828 // mwindow->edl->session->crop_x2,
2829 // mwindow->edl->session->crop_y2,
2830 // mwindow->edl->calculate_output_w(0),
2831 // mwindow->edl->calculate_output_h(0));
2837 void CWindowCanvas::draw_crop()
2839 get_canvas()->set_inverse();
2840 get_canvas()->set_color(WHITE);
2842 float x1 = mwindow->edl->session->crop_x1;
2843 float y1 = mwindow->edl->session->crop_y1;
2844 float x2 = mwindow->edl->session->crop_x2;
2845 float y2 = mwindow->edl->session->crop_y2;
2847 output_to_canvas(mwindow->edl, 0, x1, y1);
2848 output_to_canvas(mwindow->edl, 0, x2, y2);
2850 if( x2 - x1 && y2 - y1 )
2851 get_canvas()->draw_rectangle((int)x1,
2856 draw_crophandle((int)x1, (int)y1);
2857 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2858 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2859 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2860 get_canvas()->set_opaque();
2864 void CWindowCanvas::draw_outlines(int do_camera)
2866 Track *track = gui->cwindow->calculate_affected_track();
2868 if( !track ) return;
2870 float proj_x, proj_y, proj_z;
2871 int64_t position = track->to_units(
2872 mwindow->edl->local_session->get_selectionstart(1),
2874 track->automation->get_projector(&proj_x, &proj_y, &proj_z,
2875 position, PLAY_FORWARD);
2877 proj_x += mwindow->edl->session->output_w/2.;
2878 proj_y += mwindow->edl->session->output_h/2.;
2879 float proj_x1 = proj_x - track->track_w/2. * proj_z;
2880 float proj_y1 = proj_y - track->track_h/2. * proj_z;
2881 float proj_x2 = proj_x + track->track_w/2. * proj_z;
2882 float proj_y2 = proj_y + track->track_h/2. * proj_z;
2883 float x1 = proj_x1, x2 = proj_x2;
2884 float y1 = proj_y1, y2 = proj_y2;
2885 output_to_canvas(mwindow->edl, 0, x1, y1);
2886 output_to_canvas(mwindow->edl, 0, x2, y2);
2888 #define DRAW_PROJECTION(offset) \
2889 get_canvas()->draw_rectangle(x1+offset, y1+offset, (x2-x1), (y2-y1)); \
2890 get_canvas()->draw_line(x1+offset, y1+offset, x2+offset, y2+offset); \
2891 get_canvas()->draw_line(x2+offset, y1+offset, x1+offset, y2+offset); \
2894 get_canvas()->set_color(BLACK);
2896 get_canvas()->set_color(do_camera ? GREEN : RED);
2900 float cam_x, cam_y, cam_z;
2901 track->automation->get_camera(&cam_x, &cam_y, &cam_z,
2902 position, PLAY_FORWARD);
2903 cam_x += track->track_w / 2.;
2904 cam_y += track->track_h / 2.;
2905 // follow image, not camera
2906 cam_x = -cam_x; cam_y = -cam_y; cam_z *= proj_z;
2907 float cam_x1 = cam_x * cam_z + proj_x;
2908 float cam_y1 = cam_y * cam_z + proj_y;
2909 float cam_x2 = (cam_x + track->track_w) * cam_z + proj_x;
2910 float cam_y2 = (cam_y + track->track_h) * cam_z + proj_y;
2911 output_to_canvas(mwindow->edl, 0, cam_x1, cam_y1);
2912 output_to_canvas(mwindow->edl, 0, cam_x2, cam_y2);
2913 get_canvas()->set_color(YELLOW);
2914 get_canvas()->draw_rectangle(cam_x1, cam_y1, cam_x2-cam_x1, cam_y2-cam_y1);
2918 int CWindowCanvas::test_bezier(int button_press,
2926 // Processing drag operation.
2927 // Create keyframe during first cursor motion.
2928 if( !button_press ) {
2930 float cursor_x = get_cursor_x();
2931 float cursor_y = get_cursor_y();
2932 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2934 if( gui->current_operation == CWINDOW_CAMERA ||
2935 gui->current_operation == CWINDOW_PROJECTOR ) {
2936 if( !gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom ) {
2937 gui->translating_zoom = 1;
2938 gui->reset_affected();
2940 else if( !gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom ) {
2941 gui->translating_zoom = 0;
2942 gui->reset_affected();
2945 // Get target keyframe
2946 if( !gui->affected_x && !gui->affected_y && !gui->affected_z ) {
2947 if( !gui->affected_track ) return 0;
2948 FloatAutos *affected_x_autos, *affected_y_autos, *affected_z_autos;
2949 FloatAutos** autos = (FloatAutos**) gui->affected_track->automation->autos;
2950 if( mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA ) {
2951 affected_x_autos = autos[AUTOMATION_CAMERA_X];
2952 affected_y_autos = autos[AUTOMATION_CAMERA_Y];
2953 affected_z_autos = autos[AUTOMATION_CAMERA_Z];
2956 affected_x_autos = autos[AUTOMATION_PROJECTOR_X];
2957 affected_y_autos = autos[AUTOMATION_PROJECTOR_Y];
2958 affected_z_autos = autos[AUTOMATION_PROJECTOR_Z];
2960 double position = mwindow->edl->local_session->get_selectionstart(1);
2961 int64_t track_position = gui->affected_track->to_units(position, 0);
2962 FloatAuto *prev_x = 0, *next_x = 0;
2963 float new_x = affected_x_autos->get_value(track_position, PLAY_FORWARD, prev_x, next_x);
2964 FloatAuto *prev_y = 0, *next_y = 0;
2965 float new_y = affected_y_autos->get_value(track_position, PLAY_FORWARD, prev_y, next_y);
2966 FloatAuto *prev_z = 0, *next_z = 0;
2967 float new_z = affected_z_autos->get_value(track_position, PLAY_FORWARD, prev_z, next_z);
2968 int zooming = gui->translating_zoom, created;
2969 gui->affected_x = (FloatAuto*)gui->cwindow->calculate_affected_auto(
2970 affected_x_autos, !zooming, &created, 0);
2972 gui->affected_x->set_value(new_x);
2975 gui->affected_y = (FloatAuto*)gui->cwindow->calculate_affected_auto(
2976 affected_y_autos, !zooming, &created, 0);
2978 gui->affected_y->set_value(new_y);
2981 gui->affected_z = (FloatAuto*)gui->cwindow->calculate_affected_auto(
2982 affected_z_autos, zooming, &created, 0);
2984 gui->affected_z->set_value(new_z);
2989 if( gui->translating_zoom ) {
2990 gui->center_z = gui->affected_z->get_value();
2993 gui->center_x = gui->affected_x->get_value();
2994 gui->center_y = gui->affected_y->get_value();
3001 float x_val = gui->affected_x->get_value();
3002 float y_val = gui->affected_y->get_value();
3003 float z_val = gui->affected_z->get_value();
3005 if( gui->translating_zoom ) {
3006 float z = gui->center_z + (cursor_y - gui->y_origin) / yS(128);
3008 if( !EQUIV(z_val, z) ) {
3013 gui->affected_z->set_value(z);
3016 float dx = cursor_x - gui->x_origin;
3017 float dy = cursor_y - gui->y_origin;
3018 // follow image, not camera
3019 if( gui->current_operation == CWINDOW_CAMERA ) {
3020 dx = -dx / z_val; dy = -dy / z_val;
3022 float x = gui->center_x + dx;
3023 float y = gui->center_y + dy;
3024 gui->affected_x->set_value(x);
3025 gui->affected_y->set_value(y);
3026 if( !EQUIV(x_val, x) || !EQUIV(y_val, y) ) {
3037 // Begin drag operation. Don't create keyframe here.
3039 // Get affected track off of the first recordable video track.
3040 // Calculating based on the alpha channel would require recording what layer
3041 // each output pixel belongs to as they're rendered and stacked. Forget it.
3042 gui->affected_track = gui->cwindow->calculate_affected_track();
3043 gui->reset_affected();
3045 if( gui->affected_track ) {
3047 mwindow->undo->update_undo_before(_("camera"), this);
3049 mwindow->undo->update_undo_before(_("projector"), this);
3051 gui->current_operation =
3052 mwindow->edl->session->cwindow_operation;
3053 gui->tool_panel->raise_window();
3061 int CWindowCanvas::test_zoom(int &redraw)
3064 int button = get_buttonpress();
3065 if( button == LEFT_BUTTON )
3066 button = gui->shift_down() ? WHEEL_DOWN : WHEEL_UP;
3067 if( !(zoom = get_zoom()) )
3068 zoom = get_auto_zoom(mwindow->edl);
3072 for( ; idx < total_zooms; ++idx ) {
3073 if( EQUIV(zoom, my_zoom_table[idx]) ) continue;
3074 if( zoom < my_zoom_table[idx] ) break;
3076 float zoom11 = 1.1f * zoom;
3077 zoom = idx < total_zooms ? my_zoom_table[idx] : zoom11;
3078 if( zoom > zoom11 ) zoom = zoom11;
3081 int idx = total_zooms;
3082 for( ; --idx >= 0; ) {
3083 if( EQUIV(my_zoom_table[idx], zoom) ) continue;
3084 if( my_zoom_table[idx] < zoom ) break;
3086 float zoom09 = 0.9f * zoom;
3087 zoom = idx >= 0 ? my_zoom_table[idx] : zoom09;
3088 if( zoom < zoom09 ) zoom = zoom09;
3091 if( gui->shift_down() ) {
3095 default: // fall thru
3098 float cx = get_cursor_x(), cy = get_cursor_y();
3099 set_zoom(mwindow->edl, zoom, cx, cy);
3100 gui->zoom_panel->update(zoom);
3101 gui->update_canvas();
3107 void CWindowCanvas::calculate_origin()
3109 float zoom_x, zoom_y, conformed_w, conformed_h;
3110 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3111 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3112 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3113 gui->x_origin = (float)get_cursor_x() / zoom_x + gui->x_offset;
3114 gui->y_origin = (float)get_cursor_y() / zoom_y + gui->y_offset;
3118 int CWindowCanvas::cursor_leave_event()
3120 set_cursor(ARROW_CURSOR);
3124 int CWindowCanvas::cursor_enter_event()
3127 switch( mwindow->edl->session->cwindow_operation ) {
3128 case CWINDOW_CAMERA:
3129 case CWINDOW_PROJECTOR:
3130 set_cursor(MOVE_CURSOR);
3133 set_cursor(MOVE_CURSOR);
3136 test_crop(0, redraw);
3138 case CWINDOW_PROTECT:
3139 set_cursor(ARROW_CURSOR);
3143 set_cursor(CROSS_CURSOR);
3145 case CWINDOW_EYEDROP:
3146 set_cursor(CROSS_CURSOR);
3152 int CWindowCanvas::cursor_motion_event()
3154 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3157 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3158 switch( gui->current_operation ) {
3159 case CWINDOW_SCROLL: {
3160 result = do_scroll(mwindow->edl, get_cursor_x(), get_cursor_y());
3164 result = do_ruler(0, 1, 0, 0);
3167 case CWINDOW_CAMERA:
3168 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3171 case CWINDOW_PROJECTOR:
3172 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3176 result = test_crop(0, redraw);
3177 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3178 // __LINE__, result, redraw);
3182 case CWINDOW_MASK_CONTROL_IN:
3183 case CWINDOW_MASK_CONTROL_OUT:
3184 case CWINDOW_MASK_TRANSLATE:
3185 result = do_mask(redraw, rerender, 0, 1, 0);
3188 case CWINDOW_EYEDROP:
3189 result = do_eyedrop(rerender, 0, 0);
3197 // cursor font changes
3199 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3200 // __LINE__, mwindow->edl->session->cwindow_operation);
3201 switch( mwindow->edl->session->cwindow_operation ) {
3203 result = test_crop(0, redraw);
3206 result = do_ruler(0, 1, 0, 0);
3209 result = do_mask(redraw, rerender, 0, 1, 0);
3214 int change_type = rerender ? CHANGE_PARAMS : -1;
3215 gui->sync_parameters(change_type, redraw, redraw_canvas);
3220 int CWindowCanvas::button_press_event()
3224 int redraw_canvas = 0;
3227 if( Canvas::button_press_event() ) return 1;
3229 gui->translating_zoom = gui->shift_down();
3233 if( mwindow->edl->session->cwindow_operation != CWINDOW_PROTECT &&
3234 get_buttonpress() == MIDDLE_BUTTON && !get_canvas()->shift_down() ) {
3235 gui->current_operation = CWINDOW_SCROLL;
3240 switch( mwindow->edl->session->cwindow_operation ) {
3242 result = do_ruler(0, 0, 1, 0);
3245 case CWINDOW_CAMERA:
3246 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3249 case CWINDOW_PROJECTOR:
3250 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3254 result = test_zoom(redraw);
3258 result = test_crop(1, redraw);
3262 switch( get_buttonpress() ) {
3264 result = do_mask(redraw, rerender, 1, 0, 0);
3266 case MIDDLE_BUTTON: { // && shift_down()
3267 result = do_mask_focus();
3268 redraw = redraw_canvas = 1;
3272 result = do_mask(redraw, rerender, 1, 1, 0);
3275 if( result ) redraw_canvas = 1;
3278 case CWINDOW_EYEDROP:
3279 result = do_eyedrop(rerender, 1, 0);
3284 int change_type = rerender ? CHANGE_PARAMS : -1;
3285 gui->sync_parameters(change_type, redraw, redraw_canvas);
3290 int CWindowCanvas::button_release_event()
3293 const char *undo_label = 0;
3295 switch( gui->current_operation ) {
3296 case CWINDOW_SCROLL:
3301 do_ruler(0, 0, 0, 1);
3304 case CWINDOW_CAMERA:
3305 undo_label = _("camera");
3308 case CWINDOW_PROJECTOR:
3309 undo_label = _("projector");
3313 case CWINDOW_MASK_CONTROL_IN:
3314 case CWINDOW_MASK_CONTROL_OUT:
3315 case CWINDOW_MASK_TRANSLATE:
3316 // Finish mask operation
3317 gui->mask_keyframe = 0;
3318 undo_label = _("mask");
3320 case CWINDOW_MASK_ROTATE:
3321 gui->mask_keyframe = 0;
3322 undo_label = _("mask rotate");
3324 case CWINDOW_MASK_SCALE:
3325 gui->mask_keyframe = 0;
3326 undo_label = _("mask scale");
3329 result = Canvas::button_release_event();
3334 mwindow->undo->update_undo_after(undo_label, LOAD_AUTOMATION);
3335 gui->current_operation = CWINDOW_NONE;
3339 void CWindowCanvas::zoom_resize_window(float percentage)
3341 int canvas_w, canvas_h;
3344 // Get required canvas size
3345 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3346 mwindow->edl->session->output_w,
3347 mwindow->edl->session->output_h,
3348 percentage, canvas_w, canvas_h);
3350 // Estimate window size from current borders
3351 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3352 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3354 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3355 mwindow->session->cwindow_w = new_w;
3356 mwindow->session->cwindow_h = new_h;
3358 mwindow->theme->get_cwindow_sizes(gui,
3359 mwindow->session->cwindow_controls);
3361 // Estimate again from new borders
3362 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3363 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3364 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3366 gui->resize_window(new_w, new_h);
3367 gui->resize_event(new_w, new_h);
3370 void CWindowCanvas::toggle_controls()
3372 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3373 gui->resize_event(gui->get_w(), gui->get_h());
3376 int CWindowCanvas::get_cwindow_controls()
3378 return mwindow->session->cwindow_controls;
3381 int CWindowCanvas::get_clear_color()
3383 int color = mwindow->edl->session->cwindow_clear_color;
3384 if( color < 0 ) color = Canvas::get_clear_color();