4 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "automation.h"
25 #include "bcsignals.h"
29 #include "cplayback.h"
32 #include "cwindowgui.h"
34 #include "cwindowtool.h"
35 #include "editpanel.h"
37 #include "edlsession.h"
38 #include "floatauto.h"
39 #include "floatautos.h"
42 #include "localsession.h"
43 #include "mainclock.h"
46 #include "mainsession.h"
48 #include "maskautos.h"
50 #include "meterpanel.h"
51 #include "mwindowgui.h"
54 #include "playback3d.h"
55 #include "playtransport.h"
57 #include "trackcanvas.h"
59 #include "transportque.h"
64 static double my_zoom_table[] =
77 static int total_zooms = sizeof(my_zoom_table) / sizeof(double);
80 CWindowGUI::CWindowGUI(MWindow *mwindow, CWindow *cwindow)
81 : BC_Window(_(PROGRAM_NAME ": Compositor"),
82 mwindow->session->cwindow_x,
83 mwindow->session->cwindow_y,
84 mwindow->session->cwindow_w,
85 mwindow->session->cwindow_h,
86 xS(100), yS(100), 1, 1, 1,
87 BC_WindowBase::get_resources()->bg_color,
88 mwindow->get_cwindow_display())
90 this->mwindow = mwindow;
91 this->cwindow = cwindow;
93 affected_x = affected_y = affected_z = 0;
95 orig_mask_keyframe = new MaskAuto(0, 0);
97 x_offset = y_offset = 0;
98 x_origin = y_origin = 0;
99 current_operation = CWINDOW_NONE;
103 crop_handle = -1; crop_translate = 0;
104 crop_origin_x = crop_origin_y = 0;
105 crop_origin_x1 = crop_origin_y1 = 0;
106 crop_origin_x2 = crop_origin_y2 = 0;
108 eyedrop_x = eyedrop_y = 0;
109 ruler_origin_x = ruler_origin_y = 0;
110 ruler_handle = -1; ruler_translate = 0;
111 center_x = center_y = center_z = 0;
112 control_in_x = control_in_y = 0;
113 control_out_x = control_out_y = 0;
114 translating_zoom = 0;
116 // *** CONTEXT_HELP ***
117 context_help_set_keyword("Compositor Window");
120 CWindowGUI::~CWindowGUI()
122 cwindow->stop_playback(1);
123 if( tool_panel ) delete tool_panel;
125 delete composite_panel;
133 delete orig_mask_keyframe;
136 void CWindowGUI::create_objects()
138 lock_window("CWindowGUI::create_objects");
139 set_icon(mwindow->theme->get_image("cwindow_icon"));
141 active = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_active"));
142 inactive = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_inactive"));
143 focus_frame = new VFramePng(mwindow->theme->get_image_data("cwindow_focus.png"));
145 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
146 mwindow->theme->draw_cwindow_bg(this);
149 // Meters required by composite panel
150 meters = new CWindowMeters(mwindow,
152 mwindow->theme->cmeter_x,
153 mwindow->theme->cmeter_y,
154 mwindow->theme->cmeter_h);
155 meters->create_objects();
158 composite_panel = new CPanel(mwindow,
160 mwindow->theme->ccomposite_x,
161 mwindow->theme->ccomposite_y,
162 mwindow->theme->ccomposite_w,
163 mwindow->theme->ccomposite_h);
164 composite_panel->create_objects();
166 canvas = new CWindowCanvas(mwindow, this);
168 canvas->create_objects(mwindow->edl);
170 add_subwindow(timebar = new CTimeBar(mwindow,
172 mwindow->theme->ctimebar_x,
173 mwindow->theme->ctimebar_y,
174 mwindow->theme->ctimebar_w,
175 mwindow->theme->ctimebar_h));
176 timebar->create_objects();
179 add_subwindow(slider = new CWindowSlider(mwindow,
181 mwindow->theme->cslider_x,
182 mwindow->theme->cslider_y,
183 mwindow->theme->cslider_w));
186 transport = new CWindowTransport(mwindow,
188 mwindow->theme->ctransport_x,
189 mwindow->theme->ctransport_y);
190 transport->create_objects();
192 transport->set_slider(slider);
195 edit_panel = new CWindowEditing(mwindow, cwindow);
196 edit_panel->set_meters(meters);
197 edit_panel->create_objects();
199 // add_subwindow(clock = new MainClock(mwindow,
200 // mwindow->theme->ctime_x,
201 // mwindow->theme->ctime_y));
203 zoom_panel = new CWindowZoom(mwindow,
205 mwindow->theme->czoom_x,
206 mwindow->theme->czoom_y,
207 mwindow->theme->czoom_w);
208 zoom_panel->create_objects();
209 zoom_panel->zoom_text->add_item(new BC_MenuItem(auto_zoom = _(AUTO_ZOOM)));
210 if( !mwindow->edl->session->cwindow_scrollbars )
211 zoom_panel->set_text(auto_zoom);
213 // Must create after meter panel
214 tool_panel = new CWindowTool(mwindow, this);
215 tool_panel->Thread::start();
217 set_operation(mwindow->edl->session->cwindow_operation);
222 int CWindowGUI::translation_event()
224 mwindow->session->cwindow_x = get_x();
225 mwindow->session->cwindow_y = get_y();
229 int CWindowGUI::resize_event(int w, int h)
231 mwindow->session->cwindow_x = get_x();
232 mwindow->session->cwindow_y = get_y();
233 mwindow->session->cwindow_w = w;
234 mwindow->session->cwindow_h = h;
236 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
237 mwindow->theme->draw_cwindow_bg(this);
240 composite_panel->reposition_buttons(mwindow->theme->ccomposite_x,
241 mwindow->theme->ccomposite_y, mwindow->theme->ccomposite_h);
243 canvas->set_zoom(mwindow->edl, canvas->get_zoom());
246 timebar->resize_event();
249 slider->reposition_window(mwindow->theme->cslider_x,
250 mwindow->theme->cslider_y,
251 mwindow->theme->cslider_w);
252 // Recalibrate pointer motion range
253 slider->set_position();
256 transport->reposition_buttons(mwindow->theme->ctransport_x,
257 mwindow->theme->ctransport_y);
259 edit_panel->reposition_buttons(mwindow->theme->cedit_x,
260 mwindow->theme->cedit_y);
262 // clock->reposition_window(mwindow->theme->ctime_x,
263 // mwindow->theme->ctime_y);
265 zoom_panel->reposition_window(mwindow->theme->czoom_x,
266 mwindow->theme->czoom_y);
268 // destination->reposition_window(mwindow->theme->cdest_x,
269 // mwindow->theme->cdest_y);
271 meters->reposition_window(mwindow->theme->cmeter_x,
272 mwindow->theme->cmeter_y,
274 mwindow->theme->cmeter_h);
278 BC_WindowBase::resize_event(w, h);
282 int CWindowGUI::button_press_event()
284 if( current_operation == CWINDOW_NONE &&
285 mwindow->edl != 0 && canvas->get_canvas() &&
286 mwindow->edl->session->cwindow_click2play &&
287 canvas->get_canvas()->cursor_above() ) {
288 switch( get_buttonpress() ) {
290 if( !cwindow->playback_engine->is_playing_back ) {
291 double length = mwindow->edl->tracks->total_playable_length();
292 double position = cwindow->playback_engine->get_tracking_position();
293 if( position >= length ) transport->goto_start();
295 return transport->forward_play->handle_event();
297 if( !cwindow->playback_engine->is_playing_back ) {
298 double position = cwindow->playback_engine->get_tracking_position();
299 if( position <= 0 ) transport->goto_end();
301 return transport->reverse_play->handle_event();
302 case RIGHT_BUTTON: // activates popup
305 return transport->frame_forward_play->handle_event();
307 return transport->frame_reverse_play->handle_event();
310 if( canvas->get_canvas() )
311 return canvas->button_press_event_base(canvas->get_canvas());
315 int CWindowGUI::cursor_leave_event()
317 if( canvas->get_canvas() )
318 return canvas->cursor_leave_event_base(canvas->get_canvas());
322 int CWindowGUI::cursor_enter_event()
324 if( canvas->get_canvas() )
325 return canvas->cursor_enter_event_base(canvas->get_canvas());
329 int CWindowGUI::button_release_event()
331 if( canvas->get_canvas() )
332 return canvas->button_release_event();
336 int CWindowGUI::cursor_motion_event()
338 if( canvas->get_canvas() ) {
339 canvas->get_canvas()->unhide_cursor();
340 return canvas->cursor_motion_event();
351 void CWindowGUI::draw_status(int flush)
353 if( (canvas->get_canvas() && canvas->get_canvas()->get_video_on()) ||
354 canvas->is_processing ) {
356 mwindow->theme->cstatus_x,
357 mwindow->theme->cstatus_y);
360 draw_pixmap(inactive,
361 mwindow->theme->cstatus_x,
362 mwindow->theme->cstatus_y);
366 // printf("CWindowGUI::draw_status %d %d %d\n", __LINE__, mwindow->theme->cstatus_x,
367 // mwindow->theme->cstatus_y);
368 flash(mwindow->theme->cstatus_x,
369 mwindow->theme->cstatus_y,
375 void CWindowGUI::update_canvas(int redraw)
377 float zoom = canvas->get_zoom();
378 zoom_panel->update(zoom);
379 if( mwindow->edl->session->cwindow_operation == CWINDOW_ZOOM ) {
380 if( !zoom ) zoom = canvas->get_auto_zoom(mwindow->edl);
381 composite_panel->cpanel_zoom->update(zoom);
383 canvas->update_scrollbars(mwindow->edl, 0);
384 canvas->reposition_window(mwindow->edl,
385 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
386 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
391 void CWindowGUI::set_operation(int value)
394 case CWINDOW_TOOL_WINDOW:
395 mwindow->edl->session->tool_window = !mwindow->edl->session->tool_window;
396 composite_panel->operation[CWINDOW_TOOL_WINDOW]->update(mwindow->edl->session->tool_window);
397 tool_panel->update_show_window();
399 case CWINDOW_TITLESAFE:
400 mwindow->edl->session->safe_regions = !mwindow->edl->session->safe_regions;
401 composite_panel->operation[CWINDOW_TITLESAFE]->update(mwindow->edl->session->safe_regions);
402 value = mwindow->edl->session->cwindow_operation;
405 mwindow->edl->session->cwindow_operation = value;
406 composite_panel->set_operation(value);
410 edit_panel->update();
411 tool_panel->start_tool(value);
415 void CWindowGUI::update_tool()
417 tool_panel->update_values();
420 int CWindowGUI::close_event()
422 cwindow->hide_window();
427 int CWindowGUI::keypress_event()
430 int cwindow_operation = CWINDOW_NONE;
432 switch( get_keypress() ) {
448 int on = canvas->get_fullscreen() ? 0 : 1;
449 canvas->set_fullscreen(on, 1);
453 canvas->set_fullscreen(0, 1);
457 if( ctrl_down() || shift_down() || alt_down() ) break;
459 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
461 mwindow->gui->unlock_window();
462 lock_window("CWindowGUI::keypress_event 2");
467 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
468 mwindow->clear_entry();
469 mwindow->gui->unlock_window();
470 lock_window("CWindowGUI::keypress_event 3");
475 int alt_down = this->alt_down();
476 int shift_down = this->shift_down();
479 mwindow->gui->lock_window("CWindowGUI::keypress_event 5");
481 mwindow->prev_edit_handle(shift_down);
483 mwindow->move_left();
484 mwindow->gui->unlock_window();
485 lock_window("CWindowGUI::keypress_event 6");
491 if( !ctrl_down() && !alt_down() ) {
494 mwindow->gui->lock_window("CWindowGUI::keypress_event 7");
495 mwindow->move_left();
496 mwindow->gui->unlock_window();
497 lock_window("CWindowGUI::keypress_event 8");
504 int alt_down = this->alt_down();
505 int shift_down = this->shift_down();
508 mwindow->gui->lock_window("CWindowGUI::keypress_event 8");
510 mwindow->next_edit_handle(shift_down);
512 mwindow->move_right();
513 mwindow->gui->unlock_window();
514 lock_window("CWindowGUI::keypress_event 9");
520 if( !ctrl_down() && !alt_down() ) {
523 mwindow->gui->lock_window("CWindowGUI::keypress_event 10");
524 mwindow->move_right();
525 mwindow->gui->unlock_window();
526 lock_window("CWindowGUI::keypress_event 11");
532 if( !result && cwindow_operation < 0 && ctrl_down() && shift_down() ) {
533 switch( get_keypress() ) {
534 case KEY_F1 ... KEY_F4: // mainmenu, load layout
535 resend_event(mwindow->gui);
540 if( !result && !ctrl_down() ) {
541 switch( get_keypress() ) {
544 mwindow->toggle_camera_xyz(); result = 1;
547 cwindow_operation = CWINDOW_PROTECT;
551 mwindow->toggle_projector_xyz(); result = 1;
554 cwindow_operation = CWINDOW_ZOOM;
558 if( !result && cwindow_operation < 0 && !ctrl_down() && !shift_down() ) {
559 switch( get_keypress() ) {
560 case KEY_F3: cwindow_operation = CWINDOW_MASK; break;
561 case KEY_F4: cwindow_operation = CWINDOW_RULER; break;
562 case KEY_F5: cwindow_operation = CWINDOW_CAMERA; break;
563 case KEY_F6: cwindow_operation = CWINDOW_PROJECTOR; break;
564 case KEY_F7: cwindow_operation = CWINDOW_CROP; break;
565 case KEY_F8: cwindow_operation = CWINDOW_EYEDROP; break;
566 case KEY_F9: cwindow_operation = CWINDOW_TOOL_WINDOW; break;
567 case KEY_F10: cwindow_operation = CWINDOW_TITLESAFE; break;
570 if( !result && cwindow_operation < 0 && !ctrl_down() ) {
571 switch( get_keypress() ) {
574 canvas->reset_camera();
576 canvas->camera_keyframe();
581 canvas->reset_projector();
583 canvas->projector_keyframe();
589 if( cwindow_operation >= 0 ) {
590 set_operation(cwindow_operation);
595 result = transport->keypress_event();
598 result = context_help_check_and_show();
604 void CWindowGUI::reset_affected()
611 void CWindowGUI::keyboard_zoomin()
613 zoom_panel->zoom_tumbler->handle_up_event();
616 void CWindowGUI::keyboard_zoomout()
618 zoom_panel->zoom_tumbler->handle_down_event();
621 void CWindowGUI::sync_parameters(int change_type, int redraw, int overlay)
627 if( change_type < 0 && !overlay ) return;
629 if( change_type >= 0 ) {
630 mwindow->restart_brender();
631 mwindow->sync_parameters(change_type);
634 mwindow->gui->lock_window("CWindowGUI::sync_parameters");
635 mwindow->gui->draw_overlays(1);
636 mwindow->gui->unlock_window();
638 lock_window("CWindowGUI::sync_parameters");
641 void CWindowGUI::drag_motion()
643 if( get_hidden() ) return;
645 if( mwindow->session->current_operation != DRAG_ASSET &&
646 mwindow->session->current_operation != DRAG_VTRANSITION &&
647 mwindow->session->current_operation != DRAG_VEFFECT ) return;
648 int need_highlight = cursor_above() && get_cursor_over_window();
649 if( highlighted == need_highlight ) return;
650 highlighted = need_highlight;
654 int CWindowGUI::drag_stop()
657 if( get_hidden() ) return 0;
658 if( !highlighted ) return 0;
659 if( mwindow->session->current_operation != DRAG_ASSET &&
660 mwindow->session->current_operation != DRAG_VTRANSITION &&
661 mwindow->session->current_operation != DRAG_VEFFECT) return 0;
666 if( mwindow->session->current_operation == DRAG_ASSET ) {
667 if( mwindow->session->drag_assets->total ||
668 mwindow->session->drag_clips->total ) {
669 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
670 mwindow->undo->update_undo_before(_("insert assets"), 0);
673 if( mwindow->session->drag_assets->total ) {
675 mwindow->load_assets(mwindow->session->drag_assets,
676 mwindow->edl->local_session->get_selectionstart(),
678 mwindow->session->track_highlighted,
680 mwindow->edl->session->labels_follow_edits,
681 mwindow->edl->session->plugins_follow_edits,
682 mwindow->edl->session->autos_follow_edits,
686 if( mwindow->session->drag_clips->total ) {
688 mwindow->paste_edls(mwindow->session->drag_clips,
690 mwindow->session->track_highlighted,
691 mwindow->edl->local_session->get_selectionstart(),
692 mwindow->edl->session->labels_follow_edits,
693 mwindow->edl->session->plugins_follow_edits,
694 mwindow->edl->session->autos_follow_edits,
698 if( mwindow->session->drag_assets->total ||
699 mwindow->session->drag_clips->total ) {
700 mwindow->save_backup();
701 mwindow->restart_brender();
702 mwindow->gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
703 mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
704 mwindow->gui->unlock_window();
705 sync_parameters(CHANGE_ALL);
709 if( mwindow->session->current_operation == DRAG_VEFFECT ) {
710 //printf("CWindowGUI::drag_stop 1\n");
711 Track *affected_track = cwindow->calculate_affected_track();
712 //printf("CWindowGUI::drag_stop 2\n");
714 mwindow->gui->lock_window("CWindowGUI::drag_stop 3");
715 mwindow->insert_effects_cwindow(affected_track);
716 mwindow->session->current_operation = NO_OPERATION;
717 mwindow->gui->unlock_window();
720 if( mwindow->session->current_operation == DRAG_VTRANSITION ) {
721 Track *affected_track = cwindow->calculate_affected_track();
722 mwindow->gui->lock_window("CWindowGUI::drag_stop 4");
723 mwindow->paste_transition_cwindow(affected_track);
724 mwindow->session->current_operation = NO_OPERATION;
725 mwindow->gui->unlock_window();
731 void CWindowGUI::update_meters()
733 if( mwindow->edl->session->cwindow_meter != meters->visible ) {
734 meters->set_meters(meters->meter_count, mwindow->edl->session->cwindow_meter);
735 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
736 resize_event(get_w(), get_h());
740 void CWindowGUI::stop_transport(const char *lock_msg)
742 if( lock_msg ) unlock_window();
743 mwindow->stop_transport();
744 if( lock_msg ) lock_window(lock_msg);
748 CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
749 : EditPanel(mwindow, cwindow->gui, CWINDOW_ID,
750 mwindow->theme->cedit_x, mwindow->theme->cedit_y,
751 mwindow->edl->session->editing_mode,
752 0, // use_editing_mode
769 0, // use_gang_tracks
772 this->mwindow = mwindow;
773 this->cwindow = cwindow;
776 #define relock_cm(s) \
777 cwindow->gui->unlock_window(); \
778 mwindow->gui->lock_window("CWindowEditing::" s)
779 #define relock_mc(s) \
780 mwindow->gui->unlock_window(); \
781 cwindow->gui->lock_window("CWindowEditing::" s)
782 #define panel_fn(fn, args, s) \
783 CWindowEditing::fn args { relock_cm(#fn); s; relock_mc(#fn); }
785 // transmit lock to mwindow, and run mbutton->edit_panel->s
786 #define panel_btn(fn, args, s) \
787 panel_fn(panel_##fn, args, mwindow->gui->mbuttons->edit_panel->panel_##s)
790 double CWindowEditing::get_position()
792 relock_cm("get_position");
793 double ret = mwindow->edl->local_session->get_selectionstart(1);
794 relock_mc("get_position");
798 void CWindowEditing::set_position(double position)
800 relock_cm("set_position");
801 mwindow->gui->mbuttons->edit_panel->set_position(position);
802 relock_mc("set_position");
805 void CWindowEditing::set_click_to_play(int v)
807 relock_cm("set_position");
808 mwindow->edl->session->cwindow_click2play = v;
809 relock_mc("set_position");
810 click2play->update(v);
814 void panel_btn(stop_transport,(), stop_transport())
815 void panel_btn(toggle_label,(), toggle_label())
816 void panel_btn(next_label,(int cut), next_label(cut))
817 void panel_btn(prev_label,(int cut), prev_label(cut))
818 void panel_btn(next_edit,(int cut), next_edit(cut))
819 void panel_btn(prev_edit,(int cut), prev_edit(cut))
820 void panel_fn(panel_copy_selection,(), mwindow->copy())
821 void CWindowEditing::panel_overwrite_selection() {} // not used
822 void CWindowEditing::panel_splice_selection() {} // not used
823 void panel_btn(set_inpoint,(), set_inpoint())
824 void panel_btn(set_outpoint,(), set_outpoint())
825 void panel_btn(unset_inoutpoint,(), unset_inoutpoint())
826 void panel_fn(panel_to_clip,(), mwindow->to_clip(mwindow->edl, _("main window: "), 0))
827 void panel_btn(cut,(), cut())
828 void panel_btn(paste,(), paste())
829 void panel_btn(fit_selection,(), fit_selection())
830 void panel_btn(fit_autos,(int all), fit_autos(all))
831 void panel_btn(set_editing_mode,(int mode), set_editing_mode(mode))
832 void panel_btn(set_auto_keyframes,(int v), set_auto_keyframes(v))
833 void panel_btn(set_span_keyframes,(int v), set_span_keyframes(v))
834 void panel_btn(set_labels_follow_edits,(int v), set_labels_follow_edits(v))
835 void panel_btn(set_gang_tracks,(int v), set_gang_tracks(v))
838 CWindowMeters::CWindowMeters(MWindow *mwindow,
839 CWindowGUI *gui, int x, int y, int h)
840 : MeterPanel(mwindow, gui, x, y, -1, h,
841 mwindow->edl->session->audio_channels,
842 mwindow->edl->session->cwindow_meter,
845 this->mwindow = mwindow;
849 CWindowMeters::~CWindowMeters()
853 int CWindowMeters::change_status_event(int new_status)
855 mwindow->edl->session->cwindow_meter = new_status;
856 gui->update_meters();
863 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
864 : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
865 x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
867 this->mwindow = mwindow;
871 CWindowZoom::~CWindowZoom()
875 void CWindowZoom::update(double value)
877 char string[BCSTRLEN];
878 const char *cp = string;
881 int frac = value >= 1.0f ? 1 :
883 value >= .01f ? 3 : 4;
884 sprintf(string, "x %.*f", frac, value);
888 ZoomPanel::update(cp);
891 int CWindowZoom::handle_event()
893 double value = !strcasecmp(gui->auto_zoom, get_text()) ? 0 : get_value();
894 gui->canvas->set_zoom(mwindow->edl, value);
895 gui->update_canvas();
902 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
903 : BC_PercentageSlider(x, y, 0, pixels, pixels, 0, 1, 0)
905 this->mwindow = mwindow;
906 this->cwindow = cwindow;
907 set_precision(0.00001);
910 CWindowSlider::~CWindowSlider()
914 int CWindowSlider::handle_event()
916 cwindow->update_position((double)get_value());
920 void CWindowSlider::set_position()
922 double new_length = mwindow->edl->tracks->total_length();
923 update(mwindow->theme->cslider_w,
924 mwindow->edl->local_session->get_selectionstart(1),
929 int CWindowSlider::increase_value()
932 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
933 lock_window("CWindowSlider::increase_value");
937 int CWindowSlider::decrease_value()
940 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
941 lock_window("CWindowSlider::decrease_value");
947 CWindowTransport::CWindowTransport(MWindow *mwindow,
948 CWindowGUI *gui, int x, int y)
949 : PlayTransport(mwindow, gui, x, y)
954 EDL* CWindowTransport::get_edl()
959 void CWindowTransport::goto_start()
961 gui->unlock_window();
962 handle_transport(REWIND, 1);
964 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
965 mwindow->goto_start();
966 mwindow->gui->unlock_window();
968 gui->lock_window("CWindowTransport::goto_start 2");
971 void CWindowTransport::goto_end()
973 gui->unlock_window();
974 handle_transport(GOTO_END, 1);
976 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
978 mwindow->gui->unlock_window();
980 gui->lock_window("CWindowTransport::goto_end 2");
983 CWindowCanvasToggleControls::CWindowCanvasToggleControls(CWindowCanvas *canvas)
984 : BC_MenuItem(calculate_text(canvas->get_controls()))
986 this->canvas = canvas;
988 int CWindowCanvasToggleControls::handle_event()
990 canvas->toggle_controls();
991 set_text(calculate_text(canvas->get_controls()));
995 const char *CWindowCanvasToggleControls::calculate_text(int controls)
997 return !controls ? _("Show controls") : _("Hide controls");
1001 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
1002 : Canvas(mwindow, gui,
1003 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
1004 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h,
1005 0, 0, mwindow->edl->session->cwindow_scrollbars)
1007 this->mwindow = mwindow;
1015 void CWindowCanvas::create_objects(EDL *edl)
1017 Canvas::create_objects(edl);
1018 canvas_menu->add_item(new CanvasPopupAuto(this));
1019 canvas_menu->add_item(new CanvasPopupResetCamera(this));
1020 canvas_menu->add_item(new CanvasPopupResetProjector(this));
1021 canvas_menu->add_item(new CanvasPopupCameraKeyframe(this));
1022 canvas_menu->add_item(new CanvasPopupProjectorKeyframe(this));
1023 canvas_menu->add_item(controls = new CWindowCanvasToggleControls(this));
1024 fullscreen_menu->add_item(new CanvasPopupAuto(this));
1027 void CWindowCanvas::status_event()
1029 gui->draw_status(1);
1032 void CWindowCanvas::update_zoom(int x, int y, float zoom)
1034 mwindow->edl->session->cwindow_xscroll = x;
1035 mwindow->edl->session->cwindow_yscroll = y;
1036 mwindow->edl->session->cwindow_zoom = zoom;
1037 use_scrollbars = !zoom ? 0 : 1;
1038 mwindow->edl->session->cwindow_scrollbars = use_scrollbars;
1041 int CWindowCanvas::set_fullscreen(int on, int unlock)
1044 if( on && !get_fullscreen() ) {
1045 last_xscroll = get_xscroll();
1046 last_yscroll = get_yscroll();
1047 last_zoom = get_zoom();
1048 Canvas::set_fullscreen(1, unlock);
1052 if( !on && get_fullscreen() ) {
1053 Canvas::set_fullscreen(0, unlock);
1054 gui->zoom_panel->update(get_zoom());
1055 update_zoom(last_xscroll, last_yscroll, last_zoom);
1056 gui->update_canvas();
1062 int CWindowCanvas::get_xscroll()
1064 return mwindow->edl->session->cwindow_xscroll;
1067 int CWindowCanvas::get_yscroll()
1069 return mwindow->edl->session->cwindow_yscroll;
1073 float CWindowCanvas::get_zoom()
1075 return mwindow->edl->session->cwindow_zoom;
1078 void CWindowCanvas::zoom_auto()
1081 set_zoom(mwindow->edl, 0);
1082 gui->update_canvas();
1085 int CWindowCanvas::do_scroll(EDL *edl, float cursor_x, float cursor_y)
1087 float zoom = get_zoom();
1088 float zoom_x, zoom_y, conformed_w, conformed_h;
1089 get_zooms(edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
1091 x = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
1092 y = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
1093 zoom = get_auto_zoom(mwindow->edl);
1096 x = gui->x_origin - cursor_x / zoom_x;
1097 y = gui->y_origin - cursor_y / zoom_y;
1099 update_zoom(x, y, zoom);
1100 gui->update_canvas();
1104 int CWindowCanvas::scope_on()
1106 EditPanelScopeDialog *scope_dialog = gui->edit_panel->scope_dialog;
1107 if( !scope_dialog || !scope_dialog->scope_gui ) return 0;
1108 if( scope_dialog->scope_gui->use_refresh ) return 0;
1109 if( scope_dialog->scope_gui->use_release ) return 0;
1110 return scope_dialog->running();
1113 void CWindowCanvas::draw_scope(VFrame *output, int refresh)
1115 if( !output ) return;
1116 EditPanelScopeDialog *scope_dialog = gui->edit_panel->scope_dialog;
1117 if( !scope_dialog || !scope_dialog->scope_gui ) return;
1118 if( scope_dialog->scope_gui->use_refresh && !refresh ) return;
1119 if( scope_dialog->scope_gui->use_release && refresh >= 0 ) return;
1120 scope_dialog->process(output);
1123 void CWindowCanvas::draw_refresh(int flush)
1125 BC_WindowBase *window = get_canvas();
1126 if( window && !window->get_video_on() ) {
1128 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
1129 float in_x1, in_y1, in_x2, in_y2;
1130 float out_x1, out_y1, out_x2, out_y2;
1131 get_transfers(mwindow->edl,
1132 in_x1, in_y1, in_x2, in_y2,
1133 out_x1, out_y1, out_x2, out_y2);
1136 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1137 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1140 if( out_x2 > out_x1 && out_y2 > out_y1 &&
1141 in_x2 > in_x1 && in_y2 > in_y1 ) {
1142 // input scaled from session to refresh frame coordinates
1143 int ow = get_output_w(mwindow->edl);
1144 int oh = get_output_h(mwindow->edl);
1145 int rw = refresh_frame->get_w();
1146 int rh = refresh_frame->get_h();
1147 float xs = (float)rw / ow;
1148 float ys = (float)rh / oh;
1149 in_x1 *= xs; in_x2 *= xs;
1150 in_y1 *= ys; in_y2 *= ys;
1151 // Can't use OpenGL here because it is called asynchronously of the
1152 // playback operation.
1153 window->draw_vframe(refresh_frame,
1154 (int)out_x1, (int)out_y1,
1155 (int)(out_x2 - out_x1),
1156 (int)(out_y2 - out_y1),
1157 (int)in_x1, (int)in_y1,
1158 (int)(in_x2 - in_x1),
1159 (int)(in_y2 - in_y1),
1165 window->flash(flush);
1167 //printf("CWindowCanvas::draw_refresh 10\n");
1170 #define CROPHANDLE_W xS(10)
1171 #define CROPHANDLE_H yS(10)
1173 void CWindowCanvas::draw_crophandle(int x, int y)
1175 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1179 #define CONTROL_W xS(10)
1180 #define CONTROL_H yS(10)
1181 #define FIRST_CONTROL_W xS(20)
1182 #define FIRST_CONTROL_H yS(20)
1184 #define BC_INFINITY 65536
1186 #define RULERHANDLE_W xS(16)
1187 #define RULERHANDLE_H yS(16)
1189 int CWindowCanvas::do_ruler(int draw, int motion,
1190 int button_press, int button_release)
1193 EDLSession *session = mwindow->edl->session;
1194 float x1 = session->ruler_x1;
1195 float y1 = session->ruler_y1;
1196 float x2 = session->ruler_x2;
1197 float y2 = session->ruler_y2;
1198 float canvas_x1 = x1;
1199 float canvas_y1 = y1;
1200 float canvas_x2 = x2;
1201 float canvas_y2 = y2;
1202 float output_x = get_cursor_x();
1203 float output_y = get_cursor_y();
1204 float canvas_cursor_x = output_x;
1205 float canvas_cursor_y = output_y;
1207 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1208 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1209 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1210 mwindow->session->cwindow_output_x = roundf(output_x);
1211 mwindow->session->cwindow_output_y = roundf(output_y);
1213 if( button_press && get_buttonpress() == 1 ) {
1214 gui->ruler_handle = -1;
1215 gui->ruler_translate = 0;
1216 if( gui->alt_down() ) {
1217 gui->ruler_translate = 1;
1218 gui->ruler_origin_x = x1;
1219 gui->ruler_origin_y = y1;
1222 if( canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1223 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1224 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1225 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2 ) {
1226 gui->ruler_handle = 0;
1227 gui->ruler_origin_x = x1;
1228 gui->ruler_origin_y = y1;
1231 if( canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1232 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1233 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1234 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2 ) {
1235 gui->ruler_handle = 1;
1236 gui->ruler_origin_x = x2;
1237 gui->ruler_origin_y = y2;
1241 // Start new selection
1242 if( !gui->ruler_translate &&
1243 (gui->ruler_handle < 0 ||
1247 do_ruler(1, 0, 0, 0);
1248 get_canvas()->flash();
1249 gui->ruler_handle = 1;
1250 session->ruler_x1 = output_x;
1251 session->ruler_y1 = output_y;
1252 session->ruler_x2 = output_x;
1253 session->ruler_y2 = output_y;
1254 gui->ruler_origin_x = session->ruler_x2;
1255 gui->ruler_origin_y = session->ruler_y2;
1258 gui->x_origin = output_x;
1259 gui->y_origin = output_y;
1260 gui->current_operation = CWINDOW_RULER;
1261 gui->tool_panel->raise_window();
1266 if( gui->current_operation == CWINDOW_RULER ) {
1267 if( gui->ruler_translate ) {
1269 do_ruler(1, 0, 0, 0);
1270 float x_difference = session->ruler_x1;
1271 float y_difference = session->ruler_y1;
1272 session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1273 session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1274 x_difference -= session->ruler_x1;
1275 y_difference -= session->ruler_y1;
1276 session->ruler_x2 -= x_difference;
1277 session->ruler_y2 -= y_difference;
1279 do_ruler(1, 0, 0, 0);
1280 get_canvas()->flash();
1284 switch( gui->ruler_handle ) {
1286 do_ruler(1, 0, 0, 0);
1287 session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1288 session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1289 if( gui->alt_down() || gui->ctrl_down() ) {
1290 double angle_value = fabs(atan((session->ruler_y2 - session->ruler_y1) /
1291 (session->ruler_x2 - session->ruler_x1)) *
1293 double distance_value =
1294 sqrt(SQR(session->ruler_x2 - session->ruler_x1) +
1295 SQR(session->ruler_y2 - session->ruler_y1));
1296 if( angle_value < 22 )
1297 session->ruler_y1 = session->ruler_y2;
1299 if( angle_value > 67 )
1300 session->ruler_x1 = session->ruler_x2;
1302 if( session->ruler_x1 < session->ruler_x2 &&
1303 session->ruler_y1 < session->ruler_y2 ) {
1304 session->ruler_x1 = session->ruler_x2 - distance_value / 1.414214;
1305 session->ruler_y1 = session->ruler_y2 - distance_value / 1.414214;
1308 if( session->ruler_x1 < session->ruler_x2 && session->ruler_y1 > session->ruler_y2 ) {
1309 session->ruler_x1 = session->ruler_x2 - distance_value / 1.414214;
1310 session->ruler_y1 = session->ruler_y2 + distance_value / 1.414214;
1313 if( session->ruler_x1 > session->ruler_x2 &&
1314 session->ruler_y1 < session->ruler_y2 ) {
1315 session->ruler_x1 = session->ruler_x2 + distance_value / 1.414214;
1316 session->ruler_y1 = session->ruler_y2 - distance_value / 1.414214;
1319 session->ruler_x1 = session->ruler_x2 + distance_value / 1.414214;
1320 session->ruler_y1 = session->ruler_y2 + distance_value / 1.414214;
1323 do_ruler(1, 0, 0, 0);
1324 get_canvas()->flash();
1329 do_ruler(1, 0, 0, 0);
1330 session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1331 session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1332 if( gui->alt_down() || gui->ctrl_down() ) {
1333 double angle_value = fabs(atan((session->ruler_y2 - session->ruler_y1) /
1334 (session->ruler_x2 - session->ruler_x1)) *
1336 double distance_value =
1337 sqrt(SQR(session->ruler_x2 - session->ruler_x1) +
1338 SQR(session->ruler_y2 - session->ruler_y1));
1339 if( angle_value < 22 )
1340 session->ruler_y2 = session->ruler_y1;
1342 if( angle_value > 67 )
1343 session->ruler_x2 = session->ruler_x1;
1345 if( session->ruler_x2 < session->ruler_x1 &&
1346 session->ruler_y2 < session->ruler_y1 ) {
1347 session->ruler_x2 = session->ruler_x1 - distance_value / 1.414214;
1348 session->ruler_y2 = session->ruler_y1 - distance_value / 1.414214;
1351 if( session->ruler_x2 < session->ruler_x1 &&
1352 session->ruler_y2 > session->ruler_y1 ) {
1353 session->ruler_x2 = session->ruler_x1 - distance_value / 1.414214;
1354 session->ruler_y2 = session->ruler_y1 + distance_value / 1.414214;
1357 if( session->ruler_x2 > session->ruler_x1 && session->ruler_y2 < session->ruler_y1 ) {
1358 session->ruler_x2 = session->ruler_x1 + distance_value / 1.414214;
1359 session->ruler_y2 = session->ruler_y1 - distance_value / 1.414214;
1362 session->ruler_x2 = session->ruler_x1 + distance_value / 1.414214;
1363 session->ruler_y2 = session->ruler_y1 + distance_value / 1.414214;
1366 do_ruler(1, 0, 0, 0);
1367 get_canvas()->flash();
1372 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1375 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1380 if( canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1381 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1382 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1383 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2 ) {
1384 set_cursor(UPRIGHT_ARROW_CURSOR);
1387 if( canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1388 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1389 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1390 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2 ) {
1391 set_cursor(UPRIGHT_ARROW_CURSOR);
1394 set_cursor(CROSS_CURSOR);
1396 // Update current position
1401 // Assume no ruler measurement if 0 length
1402 if( draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)) ) {
1403 get_canvas()->set_inverse();
1404 get_canvas()->set_color(WHITE);
1405 get_canvas()->draw_line((int)canvas_x1,
1409 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1411 roundf(canvas_x1) + RULERHANDLE_W / 2,
1413 get_canvas()->draw_line(roundf(canvas_x1),
1414 roundf(canvas_y1) - RULERHANDLE_H / 2,
1416 roundf(canvas_y1) + RULERHANDLE_H / 2);
1417 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1419 roundf(canvas_x2) + RULERHANDLE_W / 2,
1421 get_canvas()->draw_line(roundf(canvas_x2),
1422 roundf(canvas_y2) - RULERHANDLE_H / 2,
1424 roundf(canvas_y2) + RULERHANDLE_H / 2);
1425 get_canvas()->set_opaque();
1432 static inline double line_dist(float cx,float cy, float tx,float ty)
1434 double dx = tx-cx, dy = ty-cy;
1435 return sqrt(dx*dx + dy*dy);
1438 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1440 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1441 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1445 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1446 int button_press, int cursor_motion, int draw)
1448 // Retrieve points from top recordable track
1449 //printf("CWindowCanvas::do_mask 1\n");
1450 Track *track = gui->cwindow->calculate_mask_track();
1451 //printf("CWindowCanvas::do_mask 2\n");
1453 if( !track ) return 0;
1454 //printf("CWindowCanvas::do_mask 3\n");
1455 CWindowMaskGUI *mask_gui = (CWindowMaskGUI *)
1456 (gui->tool_panel ? gui->tool_panel->tool_gui : 0);
1457 int draw_markers = mask_gui ? mask_gui->markers : 0;
1458 int draw_boundary = mask_gui ? mask_gui->boundary : 0;
1459 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1460 int64_t position = track->to_units(
1461 mwindow->edl->local_session->get_selectionstart(1),
1463 Auto *prev_auto = 0;
1464 mask_autos->get_prev_auto(position, PLAY_FORWARD, (Auto *&)prev_auto, 1);
1465 MaskAuto *prev_mask = (MaskAuto *)prev_auto;
1467 int update_points = 1;
1468 // Determine the points based on whether
1469 // new keyframes will be generated or drawing is performed.
1470 // If keyframe generation occurs, use the interpolated mask.
1471 // If no keyframe generation occurs, use the previous mask.
1472 int use_interpolated = 0;
1473 if( button_press || cursor_motion ) {
1474 #ifdef USE_KEYFRAME_SPANNING
1475 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1476 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1477 int64_t start_pos = track->to_units(selection_start, 0);
1478 int64_t end_pos = track->to_units(selection_end, 0);
1479 Auto *first = 0, *last = 0;
1480 mask_autos->get_prev_auto(start_pos, PLAY_FORWARD, first, 1);
1481 mask_autos->get_prev_auto(end_pos, PLAY_FORWARD, last, 1);
1482 if( last == first && (!mwindow->edl->session->auto_keyframes) )
1483 use_interpolated = 0;
1485 // If keyframe spanning occurs, use the interpolated points.
1486 // If new keyframe is generated, use the interpolated points.
1487 use_interpolated = 1;
1490 if( mwindow->edl->session->auto_keyframes )
1491 use_interpolated = 1;
1495 use_interpolated = 1;
1497 if( use_interpolated ) {
1498 // Interpolate the points to get exactly what is being rendered at this position.
1499 mask_autos->get_points(&points,
1500 mwindow->edl->session->cwindow_mask,
1501 position, PLAY_FORWARD);
1504 // Use the prev mask
1505 prev_mask->get_points(&points,
1506 mwindow->edl->session->cwindow_mask);
1509 // Projector zooms relative to the center of the track output.
1510 float half_track_w = (float)track->track_w / 2;
1511 float half_track_h = (float)track->track_h / 2;
1512 // Translate mask to projection
1513 float projector_x, projector_y, projector_z;
1514 track->automation->get_projector(
1515 &projector_x, &projector_y, &projector_z,
1516 position, PLAY_FORWARD);
1519 // Get position of cursor relative to mask
1520 float cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
1521 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1522 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1524 projector_x += mwindow->edl->session->output_w / 2;
1525 projector_y += mwindow->edl->session->output_h / 2;
1526 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1527 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1529 // Fix cursor origin
1530 if( button_press ) {
1531 gui->x_origin = mask_cursor_x;
1532 gui->y_origin = mask_cursor_y;
1536 // Points of closest line
1537 int shortest_point1 = -1;
1538 int shortest_point2 = -1;
1540 int shortest_point = -1;
1541 // Distance to closest line
1542 float shortest_line_distance = BC_INFINITY;
1543 // Distance to closest point
1544 float shortest_point_distance = BC_INFINITY;
1545 int selected_point = -1;
1546 int selected_control_point = -1;
1547 float selected_control_point_distance = BC_INFINITY;
1548 ArrayList<int> x_points;
1549 ArrayList<int> y_points;
1551 if( !cursor_motion ) {
1553 get_canvas()->set_color(WHITE);
1554 get_canvas()->set_inverse();
1556 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1558 // Never draw closed polygon and a closed
1559 // polygon is harder to add points to.
1560 for( int i = 0; i < points.size() && !result; i++ ) {
1561 MaskPoint *point1 = points.get(i);
1562 MaskPoint *point2 = (i >= points.size() - 1) ?
1563 points.get(0) : points.get(i + 1);
1564 if( button_press ) {
1565 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1566 if( point_distance1 < shortest_point_distance || shortest_point < 0 ) {
1567 shortest_point_distance = point_distance1;
1571 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1572 if( point_distance2 < shortest_point_distance || shortest_point < 0 ) {
1573 shortest_point_distance = point_distance2;
1574 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1578 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1580 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1581 //point1->x, point1->y, point2->x, point2->y, projector_z);
1582 for( int j = 0; j <= segments && !result; j++ ) {
1583 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1584 float x0 = point1->x, y0 = point1->y;
1585 float x1 = point1->x + point1->control_x2;
1586 float y1 = point1->y + point1->control_y2;
1587 float x2 = point2->x + point2->control_x1;
1588 float y2 = point2->y + point2->control_y1;
1589 float x3 = point2->x, y3 = point2->y;
1590 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1591 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1592 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1593 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1594 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1595 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1596 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1597 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1599 float t = (float)j / segments;
1600 float tpow2 = t * t;
1601 float tpow3 = t * t * t;
1603 float invtpow2 = invt * invt;
1604 float invtpow3 = invt * invt * invt;
1606 float x = ( invtpow3 * x0
1607 + 3 * t * invtpow2 * x1
1608 + 3 * tpow2 * invt * x2
1610 float y = ( invtpow3 * y0
1611 + 3 * t * invtpow2 * y1
1612 + 3 * tpow2 * invt * y2
1614 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1615 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1616 // Test new point addition
1617 if( button_press ) {
1618 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1620 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1621 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1622 if( line_distance < shortest_line_distance ||
1623 shortest_point1 < 0 ) {
1624 shortest_line_distance = line_distance;
1625 shortest_point1 = i;
1626 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1627 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1628 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1631 // Test existing point selection
1633 if( gui->ctrl_down() ) {
1634 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1636 if( distance < selected_control_point_distance ) {
1638 selected_control_point = 1;
1639 selected_control_point_distance = distance;
1643 if( !gui->shift_down() ) {
1644 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1645 if( test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0) ) {
1650 selected_point = shortest_point;
1653 // Test second point
1654 if( gui->ctrl_down() ) {
1655 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1657 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1658 if( distance < selected_control_point_distance ) {
1659 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1660 selected_control_point = 0;
1661 selected_control_point_distance = distance;
1664 else if( i < points.size() - 1 ) {
1665 if( !gui->shift_down() ) {
1666 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1667 if( test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3) ) {
1668 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1672 selected_point = shortest_point;
1677 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1681 if( draw ) { // Draw joining line
1682 x_points.append((int)canvas_x);
1683 y_points.append((int)canvas_y);
1686 if( j == segments ) {
1687 if( draw && draw_markers ) { // Draw second anchor
1688 if( i < points.size() - 1 ) {
1689 if( i == gui->affected_point - 1 )
1690 get_canvas()->draw_disc(
1691 (int)canvas_x - CONTROL_W / 2,
1692 (int)canvas_y - CONTROL_W / 2,
1693 CONTROL_W, CONTROL_H);
1695 get_canvas()->draw_circle(
1696 (int)canvas_x - CONTROL_W / 2,
1697 (int)canvas_y - CONTROL_W / 2,
1698 CONTROL_W, CONTROL_H);
1699 // char string[BCTEXTLEN];
1700 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1701 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1703 // Draw second control point.
1704 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1705 get_canvas()->draw_line(
1706 (int)canvas_x, (int)canvas_y,
1707 (int)canvas_x2, (int)canvas_y2);
1708 get_canvas()->draw_rectangle(
1709 (int)canvas_x2 - CONTROL_W / 2,
1710 (int)canvas_y2 - CONTROL_H / 2,
1711 CONTROL_W, CONTROL_H);
1716 // Draw first anchor
1717 if( i == 0 && draw ) {
1718 if( draw_boundary ) {
1719 char mask_label[BCSTRLEN];
1720 int k = mwindow->edl->session->cwindow_mask;
1721 if( !prev_mask || k < 0 || k >= prev_mask->masks.size() )
1722 sprintf(mask_label, "%d", k);
1724 sprintf(mask_label, "%s", prev_mask->masks[k]->name);
1725 get_canvas()->draw_text(
1726 (int)canvas_x - FIRST_CONTROL_W,
1727 (int)canvas_y - FIRST_CONTROL_H,
1730 if( draw_markers ) {
1731 get_canvas()->draw_disc(
1732 (int)canvas_x - FIRST_CONTROL_W / 2,
1733 (int)canvas_y - FIRST_CONTROL_H / 2,
1734 FIRST_CONTROL_W, FIRST_CONTROL_H);
1738 // Draw first control point.
1739 if( draw && draw_markers ) {
1740 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1741 get_canvas()->draw_line(
1742 (int)canvas_x, (int)canvas_y,
1743 (int)canvas_x1, (int)canvas_y1);
1744 get_canvas()->draw_rectangle(
1745 (int)canvas_x1 - CONTROL_W / 2,
1746 (int)canvas_y1 - CONTROL_H / 2,
1747 CONTROL_W, CONTROL_H);
1749 x_points.append((int)canvas_x);
1750 y_points.append((int)canvas_y);
1753 //printf("CWindowCanvas::do_mask 1\n");
1757 //printf("CWindowCanvas::do_mask 1\n");
1759 BC_WindowBase *cvs_win = get_canvas();
1760 if( draw && draw_boundary ) {
1761 cvs_win->draw_polygon(&x_points, &y_points);
1762 cvs_win->set_opaque();
1764 if( draw && mask_gui && mask_gui->focused ) {
1765 float fx = atof(mask_gui->focus_x->get_text());
1766 float fy = atof(mask_gui->focus_y->get_text());
1767 fx = (fx - half_track_w) * projector_z + projector_x;
1768 fy = (fy - half_track_h) * projector_z + projector_y;
1769 output_to_canvas(mwindow->edl, 0, fx, fy);
1770 float r = bmax(cvs_win->get_w(), cvs_win->get_h());
1773 int fw = 2*d+3, fh = fw;
1774 VFrame focus(fw,fh, BC_RGBA8888);
1775 focus.transfer_from(gui->focus_frame);
1776 fx -= fw/2.f; fy -= fh/2.f;
1777 BC_Pixmap focus_pixmap(cvs_win, &focus, PIXMAP_ALPHA);
1778 cvs_win->draw_pixmap(&focus_pixmap,fx,fy);
1780 cvs_win->set_line_width((int)(0.0025*r) + 1);
1781 cvs_win->set_color(BLUE);
1782 cvs_win->draw_line(fx-d,fy-d, fx+d, fy+d);
1783 cvs_win->draw_line(fx-d,fy+d, fx+d, fy-d);
1784 cvs_win->set_line_width(0);
1785 cvs_win->set_color(WHITE);
1788 if( draw && mask_gui && draw_markers && points.size() ) {
1789 float cx = 0, cy = 0;
1790 int n = points.size();
1791 for( int i=0; i<n; ++i ) {
1792 MaskPoint *point = points.get(i);
1793 cx += point->x; cy += point->y;
1796 if( !mask_gui->focused )
1797 mask_gui->set_focused(0, cx, cy);
1798 cx = (cx - half_track_w) * projector_z + projector_x;
1799 cy = (cy - half_track_h) * projector_z + projector_y;
1800 output_to_canvas(mwindow->edl, 0, cx, cy);
1801 float r = bmax(cvs_win->get_w(), cvs_win->get_h());
1803 cvs_win->set_line_width((int)(0.002*r) + 1);
1804 cvs_win->set_color(ORANGE);
1805 cvs_win->draw_line(cx-d,cy, cx+d, cy);
1806 cvs_win->draw_line(cx,cy-d, cx, cy+d);
1807 cvs_win->set_line_width(0);
1808 cvs_win->set_color(WHITE);
1810 //printf("CWindowCanvas::do_mask 1\n");
1813 if( button_press && !result ) {
1814 gui->affected_track = gui->cwindow->calculate_mask_track();
1816 // Get keyframe outside the EDL to edit. This must be rendered
1817 // instead of the EDL keyframes when it exists. Then it must be
1818 // applied to the EDL keyframes on buttonrelease.
1819 if( gui->affected_track ) {
1820 #ifdef USE_KEYFRAME_SPANNING
1821 // Make copy of current parameters in local keyframe
1822 gui->mask_keyframe =
1823 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1825 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1828 gui->mask_keyframe =
1829 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1833 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1835 if( get_buttonpress() == WHEEL_UP || get_buttonpress() == WHEEL_DOWN ) {
1836 if( !gui->shift_down() ) {
1837 mwindow->undo->update_undo_before(_("mask rotate"), this);
1838 gui->current_operation = CWINDOW_MASK_ROTATE;
1841 mwindow->undo->update_undo_before(_("mask scale"), this);
1842 gui->current_operation = CWINDOW_MASK_SCALE;
1844 gui->affected_point = 0;
1847 // Translate entire keyframe
1848 if( gui->alt_down() && mask->points.size() ) {
1849 mwindow->undo->update_undo_before(_("mask translate"), 0);
1850 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1851 gui->affected_point = 0;
1854 // Existing point or control point was selected
1855 if( selected_point >= 0 ) {
1856 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1857 gui->affected_point = selected_point;
1859 if( selected_control_point == 0 )
1860 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1862 if( selected_control_point == 1 )
1863 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1865 gui->current_operation = mwindow->edl->session->cwindow_operation;
1867 else // No existing point or control point was selected so create a new one
1868 if( !gui->ctrl_down() && !gui->alt_down() ) {
1869 mwindow->undo->update_undo_before(_("mask point"), 0);
1870 // Create the template
1871 MaskPoint *point = new MaskPoint;
1872 point->x = mask_cursor_x;
1873 point->y = mask_cursor_y;
1874 point->control_x1 = 0;
1875 point->control_y1 = 0;
1876 point->control_x2 = 0;
1877 point->control_y2 = 0;
1880 if( shortest_point2 < shortest_point1 ) {
1881 shortest_point2 ^= shortest_point1;
1882 shortest_point1 ^= shortest_point2;
1883 shortest_point2 ^= shortest_point1;
1888 // printf("CWindowGUI::do_mask 40\n");
1889 // mwindow->edl->dump();
1890 // printf("CWindowGUI::do_mask 50\n");
1894 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1895 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1896 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1898 // Append to end of list
1899 if( shortest_point1 == shortest_point2 ||
1900 labs(shortest_point1 - shortest_point2) > 1) {
1901 #ifdef USE_KEYFRAME_SPANNING
1903 MaskPoint *new_point = new MaskPoint;
1904 points.append(new_point);
1905 *new_point = *point;
1906 gui->affected_point = points.size() - 1;
1910 // Need to apply the new point to every keyframe
1911 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1912 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1913 MaskPoint *new_point = new MaskPoint;
1914 submask->points.append(new_point);
1915 *new_point = *point;
1916 if( current == (MaskAuto*)mask_autos->default_auto )
1917 current = (MaskAuto*)mask_autos->first;
1919 current = (MaskAuto*)NEXT;
1921 gui->affected_point = mask->points.size() - 1;
1927 // Insert between 2 points, shifting back point 2
1928 if( shortest_point1 >= 0 && shortest_point2 >= 0 ) {
1930 #ifdef USE_KEYFRAME_SPANNING
1931 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1933 if( points.size() >= shortest_point2 ) {
1934 MaskPoint *new_point = new MaskPoint;
1936 for( int i = points.size() - 1;
1937 i > shortest_point2;
1939 points.values[i] = points.values[i - 1];
1940 points.values[shortest_point2] = new_point;
1942 *new_point = *point;
1947 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1948 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1949 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1951 if( submask->points.size() >= shortest_point2 ) {
1952 MaskPoint *new_point = new MaskPoint;
1953 submask->points.append(0);
1954 for( int i = submask->points.size() - 1;
1955 i > shortest_point2;
1957 submask->points.values[i] = submask->points.values[i - 1];
1958 submask->points.values[shortest_point2] = new_point;
1960 *new_point = *point;
1963 if( current == (MaskAuto*)mask_autos->default_auto )
1964 current = (MaskAuto*)mask_autos->first;
1966 current = (MaskAuto*)NEXT;
1970 gui->affected_point = shortest_point2;
1975 // printf("CWindowGUI::do_mask 20\n");
1976 // mwindow->edl->dump();
1977 // printf("CWindowGUI::do_mask 30\n");
1980 //printf("CWindowCanvas::do_mask 1\n");
1981 // Create the first point.
1982 #ifdef USE_KEYFRAME_SPANNING
1983 MaskPoint *new_point = new MaskPoint;
1984 points.append(new_point);
1985 *new_point = *point;
1986 gui->affected_point = points.size() - 1;
1988 for( MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1989 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1990 MaskPoint *new_point = new MaskPoint;
1991 submask->points.append(new_point);
1992 *new_point = *point;
1993 if( current == (MaskAuto*)mask_autos->default_auto )
1994 current = (MaskAuto*)mask_autos->first;
1996 current = (MaskAuto*)NEXT;
1998 gui->affected_point = points.size() - 1;
2001 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
2004 gui->current_operation = mwindow->edl->session->cwindow_operation;
2005 // Delete the template
2014 if( button_press && result ) {
2015 #ifdef USE_KEYFRAME_SPANNING
2016 MaskPoints &mask_points = points;
2018 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
2019 MaskPoints &mask_points = mask->points;
2021 int k = gui->affected_point;
2022 if( k >= 0 && k < mask_points.size() ) {
2023 MaskPoint *point = mask_points.values[k];
2024 gui->center_x = point->x;
2025 gui->center_y = point->y;
2026 gui->control_in_x = point->control_x1;
2027 gui->control_in_y = point->control_y1;
2028 gui->control_out_x = point->control_x2;
2029 gui->control_out_y = point->control_y2;
2032 gui->center_x = gui->center_y = 0;
2033 gui->control_in_x = gui->control_in_y = 0;
2034 gui->control_out_x = gui->control_out_y = 0;
2036 gui->tool_panel->raise_window();
2039 //printf("CWindowCanvas::do_mask 8\n");
2040 if( cursor_motion ) {
2042 #ifdef USE_KEYFRAME_SPANNING
2043 // Must update the reference keyframes for every cursor motion
2044 gui->mask_keyframe = (MaskAuto*)gui->cwindow->
2045 calculate_affected_auto(mask_autos, 0);
2046 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
2049 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2051 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
2052 if( mask && gui->affected_point >= 0 &&
2053 gui->affected_point < mask->points.size() &&
2054 gui->current_operation != CWINDOW_NONE ) {
2055 // mwindow->undo->update_undo_before(_("mask point"), this);
2056 #ifdef USE_KEYFRAME_SPANNING
2057 MaskPoints &mask_points = points;
2059 MaskPoints &mask_points = mask->points;
2061 MaskPoint *point = mask_points.get(gui->affected_point);
2062 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2063 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask_points.size(), gui->affected_point);
2065 float last_x = point->x;
2066 float last_y = point->y;
2067 float last_control_x1 = point->control_x1;
2068 float last_control_y1 = point->control_y1;
2069 float last_control_x2 = point->control_x2;
2070 float last_control_y2 = point->control_y2;
2073 switch( gui->current_operation ) {
2075 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2076 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
2077 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
2080 case CWINDOW_MASK_CONTROL_IN:
2081 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
2082 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
2085 case CWINDOW_MASK_CONTROL_OUT:
2086 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
2087 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
2090 case CWINDOW_MASK_TRANSLATE: {
2091 if( !mask_gui ) break;
2092 int mode = mask_gui->scale_mode;
2093 MaskAuto *keyframe = gui->mask_keyframe;
2094 int gang = mask_gui->gang_focus->get_value();
2095 float dx = mask_cursor_x - gui->x_origin;
2096 float dy = mask_cursor_y - gui->y_origin;
2097 if( !dx && !dy ) break;
2098 int k = mwindow->edl->session->cwindow_mask;
2099 int n = gang ? keyframe->masks.size() : k+1;
2100 for( int j=gang? 0 : k; j<n; ++j ) {
2101 if( !mask_gui->mask_enables[j]->get_value() ) continue;
2102 SubMask *sub_mask = keyframe->get_submask(j);
2103 if( !sub_mask ) continue;
2104 MaskPoints &points = sub_mask->points;
2105 for( int i=0; i<points.size(); ++i ) {
2106 MaskPoint *point = points[i];
2107 if( mode == MASK_SCALE_X || mode == MASK_SCALE_XY ) point->x += dx;
2108 if( mode == MASK_SCALE_Y || mode == MASK_SCALE_XY ) point->y += dy;
2111 gui->x_origin = mask_cursor_x;
2112 gui->y_origin = mask_cursor_y;
2117 case CWINDOW_MASK_ROTATE:
2119 case CWINDOW_MASK_SCALE: {
2120 if( !mask_gui || !mask_points.size() ) break;
2121 float cx = gui->x_origin, cy = gui->y_origin;
2122 if( mask_gui->focused ) {
2123 cx = atof(mask_gui->focus_x->get_text());
2124 cy = atof(mask_gui->focus_y->get_text());
2126 else if( !gui->ctrl_down() ) {
2128 int n = mask_points.size();
2129 for( int i=0; i<n; ++i ) {
2130 MaskPoint *point = mask_points.values[i];
2131 cx += point->x; cy += point->y;
2134 mask_gui->set_focused(0, cx, cy);
2139 gui->get_triple_click() ? 8. :
2140 gui->get_double_click() ? 4. :
2142 int button_no = get_buttonpress();
2143 double ds = accel/64., dt = accel*M_PI/360.;
2144 double scale = button_no == WHEEL_UP ? 1.+ds : 1.-ds;
2145 int mode = mask_gui->scale_mode;
2146 double xscale = !rotate && (mode == MASK_SCALE_X ||
2147 mode == MASK_SCALE_XY ) ? scale : 1.;
2148 double yscale = !rotate && (mode == MASK_SCALE_Y ||
2149 mode == MASK_SCALE_XY ) ? scale : 1.;
2150 double theta = button_no == WHEEL_UP ? dt : -dt;
2151 if( rotate ? theta==0 : scale==1 ) break;
2152 float st = sin(theta), ct = cos(theta);
2153 MaskAuto *keyframe = gui->mask_keyframe;
2154 int gang = mask_gui->gang_focus->get_value();
2155 int k = mwindow->edl->session->cwindow_mask;
2156 int n = gang ? keyframe->masks.size() : k+1;
2157 for( int j=gang? 0 : k; j<n; ++j ) {
2158 if( !mask_gui->mask_enables[j]->get_value() ) continue;
2159 SubMask *sub_mask = keyframe->get_submask(j);
2160 if( !sub_mask ) continue;
2161 MaskPoints &points = sub_mask->points;
2162 for( int i=0; i<points.size(); ++i ) {
2163 MaskPoint *point = points[i];
2164 float px = point->x - gui->x_origin;
2165 float py = point->y - gui->y_origin;
2166 float nx = !rotate ? px*xscale : px*ct + py*st;
2167 float ny = !rotate ? py*yscale : py*ct - px*st;
2168 point->x = nx + gui->x_origin;
2169 point->y = ny + gui->y_origin;
2170 px = point->control_x1; py = point->control_y1;
2171 point->control_x1 = !rotate ? px*xscale : px*ct + py*st;
2172 point->control_y1 = !rotate ? py*yscale : py*ct - px*st;
2173 px = point->control_x2; py = point->control_y2;
2174 point->control_x2 = !rotate ? px*xscale : px*ct + py*st;
2175 point->control_y2 = !rotate ? py*yscale : py*ct - px*st;
2184 if( !(rerender && redraw) && (!EQUIV(last_x, point->x) ||
2185 !EQUIV(last_y, point->y) ||
2186 !EQUIV(last_control_x1, point->control_x1) ||
2187 !EQUIV(last_control_y1, point->control_y1) ||
2188 !EQUIV(last_control_x2, point->control_x2) ||
2189 !EQUIV(last_control_y2, point->control_y2)) ) {
2195 if( gui->current_operation == CWINDOW_NONE ) {
2196 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
2198 for( int i = 0; i < points.size() && !over_point; i++ ) {
2199 MaskPoint *point = points.get(i);
2200 float x0 = point->x;
2201 float y0 = point->y;
2202 float x1 = point->x + point->control_x1;
2203 float y1 = point->y + point->control_y1;
2204 float x2 = point->x + point->control_x2;
2205 float y2 = point->y + point->control_y2;
2206 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
2207 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
2209 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
2210 if( test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0) ) {
2214 if( !over_point && gui->ctrl_down() ) {
2215 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
2216 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
2217 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2218 if( test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1) ) {
2222 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2223 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2224 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2225 if( test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2) ) {
2232 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2237 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2240 #ifdef USE_KEYFRAME_SPANNING
2241 // Must commit change after operation.
2242 if( rerender && track ) {
2243 // Swap EDL keyframe with original.
2244 // Apply new values to keyframe span
2245 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2246 temp_keyframe.copy_data(gui->mask_keyframe);
2247 // Apply interpolated points back to keyframe
2249 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2250 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2251 mask_autos->update_parameter(&temp_keyframe);
2254 //printf("CWindowCanvas::do_mask 20\n");
2256 if( draw && draw_boundary && !draw_markers ) {
2257 BC_WindowBase *cvs_win = get_canvas();
2258 cvs_win->set_inverse();
2259 cvs_win->set_color(RED+GREEN);
2260 for( int k=0; k<SUBMASKS; ++k ) {
2261 if( k == mwindow->edl->session->cwindow_mask ) continue;
2262 points.remove_all_objects();
2263 if( use_interpolated )
2264 mask_autos->get_points(&points, k, position, PLAY_FORWARD);
2266 prev_mask->get_points(&points, k);
2268 edge.load(points, 0);
2269 for( int i=0; i<edge.size(); ++i ) {
2270 MaskCoord a = edge[i];
2271 MaskCoord b = i<edge.size()-1 ? edge[i+1] : edge[0];
2272 float ax = a.x, ay = a.y;
2273 float bx = b.x, by = b.y;
2274 output_to_canvas(mwindow->edl, 0, ax, ay);
2275 output_to_canvas(mwindow->edl, 0, bx, by);
2276 cvs_win->draw_line(ax,ay, bx,by);
2284 int CWindowCanvas::do_mask_focus()
2286 Track *track = gui->cwindow->calculate_affected_track();
2287 int64_t position = track->to_units(
2288 mwindow->edl->local_session->get_selectionstart(1),
2290 float projector_x, projector_y, projector_z;
2291 track->automation->get_projector(
2292 &projector_x, &projector_y, &projector_z,
2293 position, PLAY_FORWARD);
2294 float cx = get_cursor_x(), cy = get_cursor_y();
2295 canvas_to_output(mwindow->edl, 0, cx, cy);
2296 projector_x += mwindow->edl->session->output_w / 2;
2297 projector_y += mwindow->edl->session->output_h / 2;
2298 float half_track_w = (float)track->track_w / 2;
2299 float half_track_h = (float)track->track_h / 2;
2300 cx = (cx - projector_x) / projector_z + half_track_w;
2301 cy = (cy - projector_y) / projector_z + half_track_h;
2302 CWindowMaskGUI *mask_gui = (CWindowMaskGUI*) gui->tool_panel->tool_gui;
2303 mask_gui->set_focused(1, cx, cy);
2307 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2310 int radius = mwindow->edl->session->eyedrop_radius;
2318 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
2321 row1 = gui->eyedrop_y - radius;
2322 row2 = gui->eyedrop_y + radius;
2323 column1 = gui->eyedrop_x - radius;
2324 column2 = gui->eyedrop_x + radius;
2326 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2327 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2328 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2329 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2331 if( row2 <= row1 ) row2 = row1 + 1;
2332 if( column2 <= column1 ) column2 = column1 + 1;
2339 output_to_canvas(mwindow->edl, 0, x1, y1);
2340 output_to_canvas(mwindow->edl, 0, x2, y2);
2341 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2343 if( x2 - x1 >= 1 && y2 - y1 >= 1 ) {
2344 get_canvas()->set_inverse();
2345 get_canvas()->set_color(WHITE);
2347 get_canvas()->draw_rectangle((int)x1,
2352 get_canvas()->set_opaque();
2353 get_canvas()->flash();
2359 if( button_press ) {
2360 gui->current_operation = CWINDOW_EYEDROP;
2361 gui->tool_panel->raise_window();
2364 if( gui->current_operation == CWINDOW_EYEDROP ) {
2365 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2367 // Get color out of frame.
2368 // Doesn't work during playback because that bypasses the refresh frame.
2369 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
2370 float cursor_x = get_cursor_x();
2371 float cursor_y = get_cursor_y();
2372 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2373 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2374 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2376 row1 = cursor_y - radius;
2377 row2 = cursor_y + radius;
2378 column1 = cursor_x - radius;
2379 column2 = cursor_x + radius;
2380 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2381 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2382 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2383 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2384 if( row2 <= row1 ) row2 = row1 + 1;
2385 if( column2 <= column1 ) column2 = column1 + 1;
2389 if( gui->eyedrop_visible ) {
2391 do_eyedrop(temp, 0, 1);
2392 gui->eyedrop_visible = 0;
2395 gui->eyedrop_x = cursor_x;
2396 gui->eyedrop_y = cursor_y;
2401 do_eyedrop(temp, 0, 1);
2402 gui->eyedrop_visible = 1;
2405 #define GET_COLOR(type, components, max, do_yuv) { \
2406 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2408 float red = (float)*row++ / max; \
2409 float green = (float)*row++ / max; \
2410 float blue = (float)*row++ / max; \
2412 YUV::yuv.yuv_to_rgb_f(red, green, blue, red, green-0.5, blue-0.5); \
2413 mwindow->edl->local_session->red += red; \
2414 mwindow->edl->local_session->green += green; \
2415 mwindow->edl->local_session->blue += blue; \
2416 if( red > mwindow->edl->local_session->red_max ) mwindow->edl->local_session->red_max = red; \
2417 if( green > mwindow->edl->local_session->green_max ) mwindow->edl->local_session->green_max = green; \
2418 if( blue > mwindow->edl->local_session->blue_max ) mwindow->edl->local_session->blue_max = blue; \
2421 mwindow->edl->local_session->red = 0;
2422 mwindow->edl->local_session->green = 0;
2423 mwindow->edl->local_session->blue = 0;
2424 mwindow->edl->local_session->red_max = 0;
2425 mwindow->edl->local_session->green_max = 0;
2426 mwindow->edl->local_session->blue_max = 0;
2427 for( int i = row1; i < row2; i++ ) {
2428 for( int j = column1; j < column2; j++ ) {
2429 switch( refresh_frame->get_color_model() )
2432 GET_COLOR(unsigned char, 3, 0xff, 1);
2435 GET_COLOR(unsigned char, 4, 0xff, 1);
2438 GET_COLOR(uint16_t, 3, 0xffff, 1);
2440 case BC_YUVA16161616:
2441 GET_COLOR(uint16_t, 4, 0xffff, 1);
2444 GET_COLOR(unsigned char, 3, 0xff, 0);
2447 GET_COLOR(unsigned char, 4, 0xff, 0);
2450 GET_COLOR(float, 3, 1.0, 0);
2453 GET_COLOR(float, 4, 1.0, 0);
2459 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2460 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2461 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2465 mwindow->edl->local_session->red = 0;
2466 mwindow->edl->local_session->green = 0;
2467 mwindow->edl->local_session->blue = 0;
2468 gui->eyedrop_visible = 0;
2477 // Can't rerender since the color value is from the output of any effect it
2480 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2486 int CWindowCanvas::need_overlays()
2488 if( mwindow->edl->session->safe_regions ) return 1;
2489 if( mwindow->edl->session->cwindow_scrollbars ) return 1;
2490 if( gui->highlighted ) return 1;
2491 switch( mwindow->edl->session->cwindow_operation ) {
2492 case CWINDOW_EYEDROP:
2493 if( ! gui->eyedrop_visible ) break;
2494 case CWINDOW_CAMERA:
2495 case CWINDOW_PROJECTOR:
2504 void CWindowCanvas::draw_overlays()
2506 if( mwindow->edl->session->safe_regions ) {
2507 draw_safe_regions();
2510 if( mwindow->edl->session->cwindow_scrollbars ) {
2511 // Always draw output rectangle
2512 float x1, y1, x2, y2;
2514 x2 = mwindow->edl->session->output_w;
2516 y2 = mwindow->edl->session->output_h;
2517 output_to_canvas(mwindow->edl, 0, x1, y1);
2518 output_to_canvas(mwindow->edl, 0, x2, y2);
2520 get_canvas()->set_inverse();
2521 get_canvas()->set_color(WHITE);
2522 int ix1 = x1-1, iy1 = y1-1, ix2 = x2+1, iy2 = y2+1;
2523 get_canvas()->draw_rectangle(ix1, iy1, ix2-ix1, iy2-iy1);
2524 get_canvas()->set_opaque();
2527 if( gui->highlighted ) {
2528 get_canvas()->set_color(WHITE);
2529 get_canvas()->set_inverse();
2530 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2531 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2532 get_canvas()->set_opaque();
2535 int temp1 = 0, temp2 = 0;
2536 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2537 switch( mwindow->edl->session->cwindow_operation )
2539 case CWINDOW_CAMERA:
2543 case CWINDOW_PROJECTOR:
2552 do_mask(temp1, temp2, 0, 0, 1);
2556 do_ruler(1, 0, 0, 0);
2559 case CWINDOW_EYEDROP:
2560 if( gui->eyedrop_visible ) {
2562 do_eyedrop(rerender, 0, 1);
2563 gui->eyedrop_visible = 1;
2569 void CWindowCanvas::draw_safe_regions()
2571 float action_x1, action_x2, action_y1, action_y2;
2572 float title_x1, title_x2, title_y1, title_y2;
2574 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2575 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2576 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2577 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2578 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2579 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2580 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2581 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2583 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2584 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2585 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2586 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2588 get_canvas()->set_inverse();
2589 get_canvas()->set_color(WHITE);
2591 get_canvas()->draw_rectangle((int)action_x1,
2593 (int)(action_x2 - action_x1),
2594 (int)(action_y2 - action_y1));
2595 get_canvas()->draw_rectangle((int)title_x1,
2597 (int)(title_x2 - title_x1),
2598 (int)(title_y2 - title_y1));
2600 get_canvas()->set_opaque();
2604 void CWindowCanvas::create_keyframe(int do_camera)
2606 Track *affected_track = gui->cwindow->calculate_affected_track();
2607 if( affected_track ) {
2608 double pos = mwindow->edl->local_session->get_selectionstart(1);
2609 int64_t position = affected_track->to_units(pos, 0);
2610 int ix = do_camera ? AUTOMATION_CAMERA_X : AUTOMATION_PROJECTOR_X;
2611 int iy = do_camera ? AUTOMATION_CAMERA_Y : AUTOMATION_PROJECTOR_Y;
2612 int iz = do_camera ? AUTOMATION_CAMERA_Z : AUTOMATION_PROJECTOR_Z;
2613 FloatAuto *prev, *next;
2614 FloatAutos **autos = (FloatAutos**)affected_track->automation->autos;
2615 FloatAutos *x_autos = autos[ix]; prev = 0; next = 0;
2616 float x_value = x_autos->get_value(position, PLAY_FORWARD, prev, next);
2617 FloatAutos *y_autos = autos[iy]; prev = 0; next = 0;
2618 float y_value = y_autos->get_value(position, PLAY_FORWARD, prev, next);
2619 FloatAutos *z_autos = autos[iz]; prev = 0; next = 0;
2620 float z_value = z_autos->get_value(position, PLAY_FORWARD, prev, next);
2621 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2623 gui->cwindow->calculate_affected_autos(affected_track,
2624 &x_keyframe, &y_keyframe, &z_keyframe,
2625 do_camera, -1, -1, -1, 0);
2626 x_keyframe->set_value(x_value);
2627 y_keyframe->set_value(y_value);
2628 z_keyframe->set_value(z_value);
2630 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2634 void CWindowCanvas::camera_keyframe() { create_keyframe(1); }
2635 void CWindowCanvas::projector_keyframe() { create_keyframe(0); }
2637 void CWindowCanvas::reset_keyframe(int do_camera)
2639 Track *affected_track = gui->cwindow->calculate_affected_track();
2640 if( affected_track ) {
2641 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2642 gui->cwindow->calculate_affected_autos(affected_track,
2643 &x_keyframe, &y_keyframe, &z_keyframe,
2644 do_camera, 1, 1, 1);
2646 x_keyframe->set_value(0);
2647 y_keyframe->set_value(0);
2648 z_keyframe->set_value(1);
2650 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2651 MWindowGUI *mgui = mwindow->gui;
2652 mgui->lock_window("CWindowCanvas::reset_keyframe");
2653 gui->mwindow->edl->local_session->reset_view_limits();
2654 gui->mwindow->gui->zoombar->update_autozoom();
2655 mgui->unlock_window();
2656 mwindow->save_backup();
2660 void CWindowCanvas::reset_camera() { reset_keyframe(1); }
2661 void CWindowCanvas::reset_projector() { reset_keyframe(0); }
2664 int CWindowCanvas::test_crop(int button_press, int &redraw)
2667 int handle_selected = -1;
2668 float x1 = mwindow->edl->session->crop_x1;
2669 float y1 = mwindow->edl->session->crop_y1;
2670 float x2 = mwindow->edl->session->crop_x2;
2671 float y2 = mwindow->edl->session->crop_y2;
2672 float cursor_x = get_cursor_x();
2673 float cursor_y = get_cursor_y();
2674 float canvas_x1 = x1;
2675 float canvas_y1 = y1;
2676 float canvas_x2 = x2;
2677 float canvas_y2 = y2;
2678 float canvas_cursor_x = cursor_x;
2679 float canvas_cursor_y = cursor_y;
2681 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2682 // Use screen normalized coordinates for hot spot tests.
2683 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2684 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2687 if( gui->current_operation == CWINDOW_CROP ) {
2688 handle_selected = gui->crop_handle;
2691 if( canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2692 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H ) {
2693 handle_selected = 0;
2694 gui->crop_origin_x = x1;
2695 gui->crop_origin_y = y1;
2698 if( canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2699 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H ) {
2700 handle_selected = 1;
2701 gui->crop_origin_x = x2;
2702 gui->crop_origin_y = y1;
2705 if( canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2706 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2 ) {
2707 handle_selected = 2;
2708 gui->crop_origin_x = x1;
2709 gui->crop_origin_y = y2;
2712 if( canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2713 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2 ) {
2714 handle_selected = 3;
2715 gui->crop_origin_x = x2;
2716 gui->crop_origin_y = y2;
2721 gui->crop_origin_x = cursor_x;
2722 gui->crop_origin_y = cursor_y;
2725 // printf("test crop %d %d\n",
2726 // gui->current_operation,
2727 // handle_selected);
2730 if( button_press ) {
2731 if( gui->alt_down() ) {
2732 gui->crop_translate = 1;
2733 gui->crop_origin_x1 = x1;
2734 gui->crop_origin_y1 = y1;
2735 gui->crop_origin_x2 = x2;
2736 gui->crop_origin_y2 = y2;
2739 gui->crop_translate = 0;
2741 gui->current_operation = CWINDOW_CROP;
2742 gui->crop_handle = handle_selected;
2743 gui->x_origin = cursor_x;
2744 gui->y_origin = cursor_y;
2745 gui->tool_panel->raise_window();
2748 if( handle_selected < 0 && !gui->crop_translate ) {
2751 mwindow->edl->session->crop_x1 = (int)x1;
2752 mwindow->edl->session->crop_y1 = (int)y1;
2753 mwindow->edl->session->crop_x2 = (int)x2;
2754 mwindow->edl->session->crop_y2 = (int)y2;
2759 // Translate all 4 points
2760 if( gui->current_operation == CWINDOW_CROP && gui->crop_translate ) {
2761 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2762 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2763 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2764 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2766 mwindow->edl->session->crop_x1 = (int)x1;
2767 mwindow->edl->session->crop_y1 = (int)y1;
2768 mwindow->edl->session->crop_x2 = (int)x2;
2769 mwindow->edl->session->crop_y2 = (int)y2;
2775 if( gui->current_operation == CWINDOW_CROP ) {
2776 switch( gui->crop_handle ) {
2778 x1 = gui->crop_origin_x;
2779 y1 = gui->crop_origin_y;
2780 x2 = gui->crop_origin_x;
2781 y2 = gui->crop_origin_y;
2782 if( cursor_x < gui->x_origin ) {
2783 if( cursor_y < gui->y_origin ) {
2788 if( cursor_y >= gui->y_origin ) {
2794 if( cursor_x >= gui->x_origin ) {
2795 if( cursor_y < gui->y_origin ) {
2800 if( cursor_y >= gui->y_origin ) {
2806 // printf("test crop %d %d %d %d\n",
2807 // mwindow->edl->session->crop_x1,
2808 // mwindow->edl->session->crop_y1,
2809 // mwindow->edl->session->crop_x2,
2810 // mwindow->edl->session->crop_y2);
2813 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2814 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2817 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2818 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2821 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2822 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2825 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2826 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2830 if( !EQUIV(mwindow->edl->session->crop_x1, x1) ||
2831 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2832 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2833 !EQUIV(mwindow->edl->session->crop_y2, y2) ) {
2838 switch( gui->crop_handle ) {
2839 case 0: gui->crop_handle = 1; break;
2840 case 1: gui->crop_handle = 0; break;
2841 case 2: gui->crop_handle = 3; break;
2842 case 3: gui->crop_handle = 2; break;
2851 switch( gui->crop_handle ) {
2852 case 0: gui->crop_handle = 2; break;
2853 case 1: gui->crop_handle = 3; break;
2854 case 2: gui->crop_handle = 0; break;
2855 case 3: gui->crop_handle = 1; break;
2860 mwindow->edl->session->crop_x1 = (int)x1;
2861 mwindow->edl->session->crop_y1 = (int)y1;
2862 mwindow->edl->session->crop_x2 = (int)x2;
2863 mwindow->edl->session->crop_y2 = (int)y2;
2869 // Update cursor font
2870 if( handle_selected >= 0 ) {
2871 switch( handle_selected ) {
2872 case 0: set_cursor(UPLEFT_RESIZE); break;
2873 case 1: set_cursor(UPRIGHT_RESIZE); break;
2874 case 2: set_cursor(DOWNLEFT_RESIZE); break;
2875 case 3: set_cursor(DOWNRIGHT_RESIZE); break;
2880 set_cursor(ARROW_CURSOR);
2882 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2885 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2886 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2887 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2888 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2889 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2890 // mwindow->edl->session->crop_x2,
2891 // mwindow->edl->session->crop_y2,
2892 // mwindow->edl->calculate_output_w(0),
2893 // mwindow->edl->calculate_output_h(0));
2899 void CWindowCanvas::draw_crop()
2901 get_canvas()->set_inverse();
2902 get_canvas()->set_color(WHITE);
2904 float x1 = mwindow->edl->session->crop_x1;
2905 float y1 = mwindow->edl->session->crop_y1;
2906 float x2 = mwindow->edl->session->crop_x2;
2907 float y2 = mwindow->edl->session->crop_y2;
2909 output_to_canvas(mwindow->edl, 0, x1, y1);
2910 output_to_canvas(mwindow->edl, 0, x2, y2);
2912 if( x2 - x1 && y2 - y1 )
2913 get_canvas()->draw_rectangle((int)x1,
2918 draw_crophandle((int)x1, (int)y1);
2919 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2920 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2921 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2922 get_canvas()->set_opaque();
2926 void CWindowCanvas::draw_outlines(int do_camera)
2928 Track *track = gui->cwindow->calculate_affected_track();
2930 if( !track ) return;
2932 float proj_x, proj_y, proj_z;
2933 int64_t position = track->to_units(
2934 mwindow->edl->local_session->get_selectionstart(1),
2936 track->automation->get_projector(&proj_x, &proj_y, &proj_z,
2937 position, PLAY_FORWARD);
2939 proj_x += mwindow->edl->session->output_w/2.;
2940 proj_y += mwindow->edl->session->output_h/2.;
2941 float proj_x1 = proj_x - track->track_w/2. * proj_z;
2942 float proj_y1 = proj_y - track->track_h/2. * proj_z;
2943 float proj_x2 = proj_x + track->track_w/2. * proj_z;
2944 float proj_y2 = proj_y + track->track_h/2. * proj_z;
2945 float x1 = proj_x1, x2 = proj_x2;
2946 float y1 = proj_y1, y2 = proj_y2;
2947 output_to_canvas(mwindow->edl, 0, x1, y1);
2948 output_to_canvas(mwindow->edl, 0, x2, y2);
2950 #define DRAW_PROJECTION(offset) \
2951 get_canvas()->draw_rectangle(x1+offset, y1+offset, (x2-x1), (y2-y1)); \
2952 get_canvas()->draw_line(x1+offset, y1+offset, x2+offset, y2+offset); \
2953 get_canvas()->draw_line(x2+offset, y1+offset, x1+offset, y2+offset); \
2956 get_canvas()->set_color(BLACK);
2958 get_canvas()->set_color(do_camera ? GREEN : RED);
2962 float cam_x, cam_y, cam_z;
2963 track->automation->get_camera(&cam_x, &cam_y, &cam_z,
2964 position, PLAY_FORWARD);
2965 cam_x += track->track_w / 2.;
2966 cam_y += track->track_h / 2.;
2967 // follow image, not camera
2968 cam_x = -cam_x; cam_y = -cam_y; cam_z *= proj_z;
2969 float cam_x1 = cam_x * cam_z + proj_x;
2970 float cam_y1 = cam_y * cam_z + proj_y;
2971 float cam_x2 = (cam_x + track->track_w) * cam_z + proj_x;
2972 float cam_y2 = (cam_y + track->track_h) * cam_z + proj_y;
2973 output_to_canvas(mwindow->edl, 0, cam_x1, cam_y1);
2974 output_to_canvas(mwindow->edl, 0, cam_x2, cam_y2);
2975 get_canvas()->set_color(YELLOW);
2976 get_canvas()->draw_rectangle(cam_x1, cam_y1, cam_x2-cam_x1, cam_y2-cam_y1);
2980 int CWindowCanvas::test_bezier(int button_press,
2988 // Processing drag operation.
2989 // Create keyframe during first cursor motion.
2990 if( !button_press ) {
2992 float cursor_x = get_cursor_x();
2993 float cursor_y = get_cursor_y();
2994 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2996 if( gui->current_operation == CWINDOW_CAMERA ||
2997 gui->current_operation == CWINDOW_PROJECTOR ) {
2998 if( !gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom ) {
2999 gui->translating_zoom = 1;
3000 gui->reset_affected();
3002 else if( !gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom ) {
3003 gui->translating_zoom = 0;
3004 gui->reset_affected();
3007 // Get target keyframe
3008 if( !gui->affected_x && !gui->affected_y && !gui->affected_z ) {
3009 if( !gui->affected_track ) return 0;
3010 FloatAutos *affected_x_autos, *affected_y_autos, *affected_z_autos;
3011 FloatAutos** autos = (FloatAutos**) gui->affected_track->automation->autos;
3012 if( mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA ) {
3013 affected_x_autos = autos[AUTOMATION_CAMERA_X];
3014 affected_y_autos = autos[AUTOMATION_CAMERA_Y];
3015 affected_z_autos = autos[AUTOMATION_CAMERA_Z];
3018 affected_x_autos = autos[AUTOMATION_PROJECTOR_X];
3019 affected_y_autos = autos[AUTOMATION_PROJECTOR_Y];
3020 affected_z_autos = autos[AUTOMATION_PROJECTOR_Z];
3022 double position = mwindow->edl->local_session->get_selectionstart(1);
3023 int64_t track_position = gui->affected_track->to_units(position, 0);
3024 FloatAuto *prev_x = 0, *next_x = 0;
3025 float new_x = affected_x_autos->get_value(track_position, PLAY_FORWARD, prev_x, next_x);
3026 FloatAuto *prev_y = 0, *next_y = 0;
3027 float new_y = affected_y_autos->get_value(track_position, PLAY_FORWARD, prev_y, next_y);
3028 FloatAuto *prev_z = 0, *next_z = 0;
3029 float new_z = affected_z_autos->get_value(track_position, PLAY_FORWARD, prev_z, next_z);
3030 int zooming = gui->translating_zoom, created;
3031 gui->affected_x = (FloatAuto*)gui->cwindow->calculate_affected_auto(
3032 affected_x_autos, !zooming, &created, 0);
3034 gui->affected_x->set_value(new_x);
3037 gui->affected_y = (FloatAuto*)gui->cwindow->calculate_affected_auto(
3038 affected_y_autos, !zooming, &created, 0);
3040 gui->affected_y->set_value(new_y);
3043 gui->affected_z = (FloatAuto*)gui->cwindow->calculate_affected_auto(
3044 affected_z_autos, zooming, &created, 0);
3046 gui->affected_z->set_value(new_z);
3051 if( gui->translating_zoom ) {
3052 gui->center_z = gui->affected_z->get_value();
3055 gui->center_x = gui->affected_x->get_value();
3056 gui->center_y = gui->affected_y->get_value();
3063 CWindowToolGUI *tool_gui = !gui->tool_panel ? 0 : gui->tool_panel->tool_gui;
3064 int edge = tool_gui ? tool_gui->edge : 0;
3065 int span = tool_gui ? tool_gui->span : 0;
3067 float x_val = gui->affected_x->get_value(edge);
3068 float y_val = gui->affected_y->get_value(edge);
3069 float z_val = gui->affected_z->get_value(edge);
3071 if( gui->translating_zoom ) {
3072 float z = gui->center_z + (cursor_y - gui->y_origin) / yS(128);
3074 if( !EQUIV(z_val, z) ) {
3079 gui->affected_z->bump_value(z, edge, span);
3082 float dx = cursor_x - gui->x_origin;
3083 float dy = cursor_y - gui->y_origin;
3084 // follow image, not camera
3085 if( gui->current_operation == CWINDOW_CAMERA ) {
3086 dx = -dx / z_val; dy = -dy / z_val;
3088 float x = gui->center_x + dx;
3089 float y = gui->center_y + dy;
3090 gui->affected_x->bump_value(x, edge, span);
3091 gui->affected_y->bump_value(y, edge, span);
3092 if( !EQUIV(x_val, x) || !EQUIV(y_val, y) ) {
3103 // Begin drag operation. Don't create keyframe here.
3105 // Get affected track off of the first recordable video track.
3106 // Calculating based on the alpha channel would require recording what layer
3107 // each output pixel belongs to as they're rendered and stacked. Forget it.
3108 gui->affected_track = gui->cwindow->calculate_affected_track();
3109 gui->reset_affected();
3111 if( gui->affected_track ) {
3113 mwindow->undo->update_undo_before(_("camera"), this);
3115 mwindow->undo->update_undo_before(_("projector"), this);
3117 gui->current_operation =
3118 mwindow->edl->session->cwindow_operation;
3119 gui->tool_panel->raise_window();
3127 int CWindowCanvas::test_zoom(int &redraw)
3130 int button = get_buttonpress();
3131 if( button == LEFT_BUTTON )
3132 button = gui->shift_down() ? WHEEL_DOWN : WHEEL_UP;
3133 if( !(zoom = get_zoom()) )
3134 zoom = get_auto_zoom(mwindow->edl);
3138 for( ; idx < total_zooms; ++idx ) {
3139 if( EQUIV(zoom, my_zoom_table[idx]) ) continue;
3140 if( zoom < my_zoom_table[idx] ) break;
3142 float zoom11 = 1.1f * zoom;
3143 zoom = idx < total_zooms ? my_zoom_table[idx] : zoom11;
3144 if( zoom > zoom11 ) zoom = zoom11;
3147 int idx = total_zooms;
3148 for( ; --idx >= 0; ) {
3149 if( EQUIV(my_zoom_table[idx], zoom) ) continue;
3150 if( my_zoom_table[idx] < zoom ) break;
3152 float zoom09 = 0.9f * zoom;
3153 zoom = idx >= 0 ? my_zoom_table[idx] : zoom09;
3154 if( zoom < zoom09 ) zoom = zoom09;
3157 if( gui->shift_down() ) {
3161 default: // fall thru
3164 float cx = get_cursor_x(), cy = get_cursor_y();
3165 set_zoom(mwindow->edl, zoom, cx, cy);
3166 gui->zoom_panel->update(zoom);
3167 gui->update_canvas();
3173 void CWindowCanvas::calculate_origin()
3175 float zoom_x, zoom_y, conformed_w, conformed_h;
3176 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3177 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3178 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3179 gui->x_origin = (float)get_cursor_x() / zoom_x + gui->x_offset;
3180 gui->y_origin = (float)get_cursor_y() / zoom_y + gui->y_offset;
3184 int CWindowCanvas::cursor_leave_event()
3186 set_cursor(ARROW_CURSOR);
3190 int CWindowCanvas::cursor_enter_event()
3193 switch( mwindow->edl->session->cwindow_operation ) {
3194 case CWINDOW_CAMERA:
3195 case CWINDOW_PROJECTOR:
3196 set_cursor(MOVE_CURSOR);
3199 set_cursor(MOVE_CURSOR);
3202 test_crop(0, redraw);
3204 case CWINDOW_PROTECT:
3205 set_cursor(ARROW_CURSOR);
3209 set_cursor(CROSS_CURSOR);
3211 case CWINDOW_EYEDROP:
3212 set_cursor(CROSS_CURSOR);
3218 int CWindowCanvas::cursor_motion_event()
3220 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3223 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3224 switch( gui->current_operation ) {
3225 case CWINDOW_SCROLL: {
3226 result = do_scroll(mwindow->edl, get_cursor_x(), get_cursor_y());
3230 result = do_ruler(0, 1, 0, 0);
3233 case CWINDOW_CAMERA:
3234 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3237 case CWINDOW_PROJECTOR:
3238 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3242 result = test_crop(0, redraw);
3243 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3244 // __LINE__, result, redraw);
3248 case CWINDOW_MASK_CONTROL_IN:
3249 case CWINDOW_MASK_CONTROL_OUT:
3250 case CWINDOW_MASK_TRANSLATE:
3251 result = do_mask(redraw, rerender, 0, 1, 0);
3254 case CWINDOW_EYEDROP:
3255 result = do_eyedrop(rerender, 0, 0);
3263 // cursor font changes
3265 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3266 // __LINE__, mwindow->edl->session->cwindow_operation);
3267 switch( mwindow->edl->session->cwindow_operation ) {
3269 result = test_crop(0, redraw);
3272 result = do_ruler(0, 1, 0, 0);
3275 result = do_mask(redraw, rerender, 0, 1, 0);
3280 int change_type = rerender ? CHANGE_PARAMS : -1;
3281 gui->sync_parameters(change_type, redraw, redraw_canvas);
3286 int CWindowCanvas::button_press_event()
3290 int redraw_canvas = 0;
3293 if( Canvas::button_press_event() ) return 1;
3295 gui->translating_zoom = gui->shift_down();
3299 if( mwindow->edl->session->cwindow_operation != CWINDOW_PROTECT &&
3300 get_buttonpress() == MIDDLE_BUTTON && !get_canvas()->shift_down() ) {
3301 gui->current_operation = CWINDOW_SCROLL;
3306 switch( mwindow->edl->session->cwindow_operation ) {
3308 result = do_ruler(0, 0, 1, 0);
3311 case CWINDOW_CAMERA:
3312 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3315 case CWINDOW_PROJECTOR:
3316 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3320 result = test_zoom(redraw);
3324 result = test_crop(1, redraw);
3328 switch( get_buttonpress() ) {
3330 result = do_mask(redraw, rerender, 1, 0, 0);
3332 case MIDDLE_BUTTON: { // && shift_down()
3333 result = do_mask_focus();
3334 redraw = redraw_canvas = 1;
3338 result = do_mask(redraw, rerender, 1, 1, 0);
3341 if( result ) redraw_canvas = 1;
3344 case CWINDOW_EYEDROP:
3345 result = do_eyedrop(rerender, 1, 0);
3350 int change_type = rerender ? CHANGE_PARAMS : -1;
3351 gui->sync_parameters(change_type, redraw, redraw_canvas);
3356 int CWindowCanvas::button_release_event()
3359 const char *undo_label = 0;
3360 BC_WindowBase *window = get_canvas();
3361 if( window && !window->get_video_on() )
3362 draw_scope(refresh_frame, -1);
3364 switch( gui->current_operation ) {
3365 case CWINDOW_SCROLL:
3370 do_ruler(0, 0, 0, 1);
3373 case CWINDOW_CAMERA:
3374 undo_label = _("camera");
3377 case CWINDOW_PROJECTOR:
3378 undo_label = _("projector");
3382 case CWINDOW_MASK_CONTROL_IN:
3383 case CWINDOW_MASK_CONTROL_OUT:
3384 case CWINDOW_MASK_TRANSLATE:
3385 // Finish mask operation
3386 gui->mask_keyframe = 0;
3387 undo_label = _("mask");
3389 case CWINDOW_MASK_ROTATE:
3390 gui->mask_keyframe = 0;
3391 undo_label = _("mask rotate");
3393 case CWINDOW_MASK_SCALE:
3394 gui->mask_keyframe = 0;
3395 undo_label = _("mask scale");
3398 result = Canvas::button_release_event();
3403 mwindow->undo->update_undo_after(undo_label, LOAD_AUTOMATION);
3404 gui->current_operation = CWINDOW_NONE;
3408 void CWindowCanvas::zoom_resize_window(float percentage)
3410 int canvas_w, canvas_h;
3413 // Get required canvas size
3414 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3415 mwindow->edl->session->output_w,
3416 mwindow->edl->session->output_h,
3417 percentage, canvas_w, canvas_h);
3419 // Estimate window size from current borders
3420 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3421 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3423 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3424 mwindow->session->cwindow_w = new_w;
3425 mwindow->session->cwindow_h = new_h;
3427 mwindow->theme->get_cwindow_sizes(gui,
3428 mwindow->session->cwindow_controls);
3430 // Estimate again from new borders
3431 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3432 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3433 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3435 gui->resize_window(new_w, new_h);
3436 gui->resize_event(new_w, new_h);
3439 void CWindowCanvas::toggle_controls()
3441 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3442 gui->resize_event(gui->get_w(), gui->get_h());
3445 int CWindowCanvas::get_controls()
3447 return mwindow->session->cwindow_controls;
3450 int CWindowCanvas::get_clear_color()
3452 int color = mwindow->edl->session->cwindow_clear_color;
3453 if( color < 0 ) color = Canvas::get_clear_color();