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"
24 #include "bcsignals.h"
28 #include "cplayback.h"
31 #include "cwindowgui.h"
33 #include "cwindowtool.h"
34 #include "editpanel.h"
36 #include "edlsession.h"
37 #include "floatauto.h"
38 #include "floatautos.h"
41 #include "localsession.h"
42 #include "mainclock.h"
45 #include "mainsession.h"
47 #include "maskautos.h"
49 #include "meterpanel.h"
50 #include "mwindowgui.h"
53 #include "playback3d.h"
54 #include "playtransport.h"
56 #include "trackcanvas.h"
58 #include "transportque.h"
62 static double my_zoom_table[] =
75 static int total_zooms = sizeof(my_zoom_table) / sizeof(double);
78 CWindowGUI::CWindowGUI(MWindow *mwindow, CWindow *cwindow)
79 : BC_Window(_(PROGRAM_NAME ": Compositor"),
80 mwindow->session->cwindow_x,
81 mwindow->session->cwindow_y,
82 mwindow->session->cwindow_w,
83 mwindow->session->cwindow_h,
85 BC_WindowBase::get_resources()->bg_color,
86 mwindow->get_cwindow_display())
88 this->mwindow = mwindow;
89 this->cwindow = cwindow;
91 affected_x = affected_y = affected_z = 0;
93 orig_mask_keyframe = new MaskAuto(0, 0);
95 x_offset = y_offset = 0;
96 x_origin = y_origin = 0;
97 current_operation = CWINDOW_NONE;
101 crop_handle = -1; crop_translate = 0;
102 crop_origin_x = crop_origin_y = 0;
103 crop_origin_x1 = crop_origin_y1 = 0;
104 crop_origin_x2 = crop_origin_y2 = 0;
106 eyedrop_x = eyedrop_y = 0;
107 ruler_origin_x = ruler_origin_y = 0;
108 ruler_handle = -1; ruler_translate = 0;
109 center_x = center_y = center_z = 0;
110 control_in_x = control_in_y = 0;
111 control_out_x = control_out_y = 0;
112 translating_zoom = 0;
116 CWindowGUI::~CWindowGUI()
118 cwindow->stop_playback(1);
119 if(tool_panel) delete tool_panel;
121 delete composite_panel;
129 delete orig_mask_keyframe;
132 void CWindowGUI::create_objects()
134 lock_window("CWindowGUI::create_objects");
135 set_icon(mwindow->theme->get_image("cwindow_icon"));
137 active = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_active"));
138 inactive = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_inactive"));
139 focus_frame = new VFramePng(mwindow->theme->get_image_data("cwindow_focus.png"));
141 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
142 mwindow->theme->draw_cwindow_bg(this);
145 // Meters required by composite panel
146 meters = new CWindowMeters(mwindow,
148 mwindow->theme->cmeter_x,
149 mwindow->theme->cmeter_y,
150 mwindow->theme->cmeter_h);
151 meters->create_objects();
154 composite_panel = new CPanel(mwindow,
156 mwindow->theme->ccomposite_x,
157 mwindow->theme->ccomposite_y,
158 mwindow->theme->ccomposite_w,
159 mwindow->theme->ccomposite_h);
160 composite_panel->create_objects();
162 canvas = new CWindowCanvas(mwindow, this);
164 canvas->create_objects(mwindow->edl);
165 canvas->use_cwindow();
168 add_subwindow(timebar = new CTimeBar(mwindow,
170 mwindow->theme->ctimebar_x,
171 mwindow->theme->ctimebar_y,
172 mwindow->theme->ctimebar_w,
173 mwindow->theme->ctimebar_h));
174 timebar->create_objects();
177 add_subwindow(slider = new CWindowSlider(mwindow,
179 mwindow->theme->cslider_x,
180 mwindow->theme->cslider_y,
181 mwindow->theme->cslider_w));
184 transport = new CWindowTransport(mwindow,
186 mwindow->theme->ctransport_x,
187 mwindow->theme->ctransport_y);
188 transport->create_objects();
190 transport->set_slider(slider);
193 edit_panel = new CWindowEditing(mwindow, cwindow);
194 edit_panel->set_meters(meters);
195 edit_panel->create_objects();
197 // add_subwindow(clock = new MainClock(mwindow,
198 // mwindow->theme->ctime_x,
199 // mwindow->theme->ctime_y));
201 zoom_panel = new CWindowZoom(mwindow,
203 mwindow->theme->czoom_x,
204 mwindow->theme->czoom_y,
205 mwindow->theme->czoom_w);
206 zoom_panel->create_objects();
207 zoom_panel->zoom_text->add_item(new BC_MenuItem(auto_zoom = _(AUTO_ZOOM)));
208 if( !mwindow->edl->session->cwindow_scrollbars )
209 zoom_panel->set_text(auto_zoom);
211 // Must create after meter panel
212 tool_panel = new CWindowTool(mwindow, this);
213 tool_panel->Thread::start();
215 set_operation(mwindow->edl->session->cwindow_operation);
220 int CWindowGUI::translation_event()
222 mwindow->session->cwindow_x = get_x();
223 mwindow->session->cwindow_y = get_y();
227 int CWindowGUI::resize_event(int w, int h)
229 mwindow->session->cwindow_x = get_x();
230 mwindow->session->cwindow_y = get_y();
231 mwindow->session->cwindow_w = w;
232 mwindow->session->cwindow_h = h;
234 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
235 mwindow->theme->draw_cwindow_bg(this);
238 composite_panel->reposition_buttons(mwindow->theme->ccomposite_x,
239 mwindow->theme->ccomposite_y, mwindow->theme->ccomposite_h);
241 canvas->reposition_window(mwindow->edl,
242 mwindow->theme->ccanvas_x,
243 mwindow->theme->ccanvas_y,
244 mwindow->theme->ccanvas_w,
245 mwindow->theme->ccanvas_h);
247 timebar->resize_event();
250 slider->reposition_window(mwindow->theme->cslider_x,
251 mwindow->theme->cslider_y,
252 mwindow->theme->cslider_w);
253 // Recalibrate pointer motion range
254 slider->set_position();
257 transport->reposition_buttons(mwindow->theme->ctransport_x,
258 mwindow->theme->ctransport_y);
260 edit_panel->reposition_buttons(mwindow->theme->cedit_x,
261 mwindow->theme->cedit_y);
263 // clock->reposition_window(mwindow->theme->ctime_x,
264 // mwindow->theme->ctime_y);
266 zoom_panel->reposition_window(mwindow->theme->czoom_x,
267 mwindow->theme->czoom_y);
269 // destination->reposition_window(mwindow->theme->cdest_x,
270 // mwindow->theme->cdest_y);
272 meters->reposition_window(mwindow->theme->cmeter_x,
273 mwindow->theme->cmeter_y,
275 mwindow->theme->cmeter_h);
279 BC_WindowBase::resize_event(w, h);
283 int CWindowGUI::button_press_event()
285 if( current_operation == CWINDOW_NONE &&
286 mwindow->edl != 0 && canvas->get_canvas() &&
287 mwindow->edl->session->cwindow_click2play &&
288 canvas->get_canvas()->get_cursor_over_window() ) {
289 switch( get_buttonpress() ) {
291 if( !cwindow->playback_engine->is_playing_back ) {
292 double length = mwindow->edl->tracks->total_playable_length();
293 double position = cwindow->playback_engine->get_tracking_position();
294 if( position >= length ) transport->goto_start();
296 return transport->forward_play->handle_event();
298 if( !cwindow->playback_engine->is_playing_back ) {
299 double position = cwindow->playback_engine->get_tracking_position();
300 if( position <= 0 ) transport->goto_end();
302 return transport->reverse_play->handle_event();
303 case RIGHT_BUTTON: // activates popup
306 return transport->frame_forward_play->handle_event();
308 return transport->frame_reverse_play->handle_event();
311 if(canvas->get_canvas())
312 return canvas->button_press_event_base(canvas->get_canvas());
316 int CWindowGUI::cursor_leave_event()
318 if(canvas->get_canvas())
319 return canvas->cursor_leave_event_base(canvas->get_canvas());
323 int CWindowGUI::cursor_enter_event()
325 if(canvas->get_canvas())
326 return canvas->cursor_enter_event_base(canvas->get_canvas());
330 int CWindowGUI::button_release_event()
332 if(canvas->get_canvas())
333 return canvas->button_release_event();
337 int CWindowGUI::cursor_motion_event()
339 if(canvas->get_canvas())
341 canvas->get_canvas()->unhide_cursor();
342 return canvas->cursor_motion_event();
353 void CWindowGUI::draw_status(int flush)
355 if( (canvas->get_canvas() && canvas->get_canvas()->get_video_on()) ||
356 canvas->is_processing )
359 mwindow->theme->cstatus_x,
360 mwindow->theme->cstatus_y);
364 draw_pixmap(inactive,
365 mwindow->theme->cstatus_x,
366 mwindow->theme->cstatus_y);
370 // printf("CWindowGUI::draw_status %d %d %d\n", __LINE__, mwindow->theme->cstatus_x,
371 // mwindow->theme->cstatus_y);
372 flash(mwindow->theme->cstatus_x,
373 mwindow->theme->cstatus_y,
379 float CWindowGUI::get_auto_zoom()
381 float conformed_w, conformed_h;
382 mwindow->edl->calculate_conformed_dimensions(0, conformed_w, conformed_h);
383 float zoom_x = canvas->w / conformed_w;
384 float zoom_y = canvas->h / conformed_h;
385 return zoom_x < zoom_y ? zoom_x : zoom_y;
388 void CWindowGUI::zoom_canvas(double value, int update_menu)
391 float zoom = !value ? get_auto_zoom() : value;
392 EDL *edl = mwindow->edl;
393 edl->session->cwindow_scrollbars = !value ? 0 : 1;
395 float cx = 0.5f * canvas->w; x = cx;
396 float cy = 0.5f * canvas->h; y = cy;
397 canvas->canvas_to_output(edl, 0, x, y);
398 canvas->update_zoom(0, 0, zoom);
399 float zoom_x, zoom_y, conformed_w, conformed_h;
400 canvas->get_zooms(edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
405 canvas->update_zoom((int)(x+0.5), (int)(y+0.5), zoom);
408 zoom_panel->update(value);
409 if( mwindow->edl->session->cwindow_operation == CWINDOW_ZOOM )
410 composite_panel->cpanel_zoom->update(zoom);
412 canvas->reposition_window(mwindow->edl,
413 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
414 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
418 void CWindowGUI::set_operation(int value)
421 case CWINDOW_TOOL_WINDOW:
422 mwindow->edl->session->tool_window = !mwindow->edl->session->tool_window;
423 composite_panel->operation[CWINDOW_TOOL_WINDOW]->update(mwindow->edl->session->tool_window);
424 tool_panel->update_show_window();
426 case CWINDOW_TITLESAFE:
427 mwindow->edl->session->safe_regions = !mwindow->edl->session->safe_regions;
428 composite_panel->operation[CWINDOW_TITLESAFE]->update(mwindow->edl->session->safe_regions);
429 value = mwindow->edl->session->cwindow_operation;
432 mwindow->edl->session->cwindow_operation = value;
433 composite_panel->set_operation(value);
437 edit_panel->update();
438 tool_panel->start_tool(value);
442 void CWindowGUI::update_tool()
444 tool_panel->update_values();
447 int CWindowGUI::close_event()
449 cwindow->hide_window();
454 int CWindowGUI::keypress_event()
457 int cwindow_operation = CWINDOW_NONE;
459 switch( get_keypress() ) {
476 if( canvas->get_fullscreen() )
477 canvas->stop_fullscreen();
479 canvas->start_fullscreen();
480 lock_window("CWindowGUI::keypress_event 1");
484 if( ctrl_down() || shift_down() || alt_down() ) break;
486 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
488 mwindow->gui->unlock_window();
489 lock_window("CWindowGUI::keypress_event 2");
494 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
495 mwindow->clear_entry();
496 mwindow->gui->unlock_window();
497 lock_window("CWindowGUI::keypress_event 3");
502 if( canvas->get_fullscreen() )
503 canvas->stop_fullscreen();
504 lock_window("CWindowGUI::keypress_event 4");
509 int alt_down = this->alt_down();
510 int shift_down = this->shift_down();
513 mwindow->gui->lock_window("CWindowGUI::keypress_event 5");
515 mwindow->prev_edit_handle(shift_down);
517 mwindow->move_left();
518 mwindow->gui->unlock_window();
519 lock_window("CWindowGUI::keypress_event 6");
525 if( !ctrl_down() && !alt_down() ) {
528 mwindow->gui->lock_window("CWindowGUI::keypress_event 7");
529 mwindow->move_left();
530 mwindow->gui->unlock_window();
531 lock_window("CWindowGUI::keypress_event 8");
538 int alt_down = this->alt_down();
539 int shift_down = this->shift_down();
542 mwindow->gui->lock_window("CWindowGUI::keypress_event 8");
544 mwindow->next_edit_handle(shift_down);
546 mwindow->move_right();
547 mwindow->gui->unlock_window();
548 lock_window("CWindowGUI::keypress_event 9");
554 if( !ctrl_down() && !alt_down() ) {
557 mwindow->gui->lock_window("CWindowGUI::keypress_event 10");
558 mwindow->move_right();
559 mwindow->gui->unlock_window();
560 lock_window("CWindowGUI::keypress_event 11");
566 if( !result && cwindow_operation < 0 && ctrl_down() && shift_down() ) {
567 switch( get_keypress() ) {
568 case KEY_F1 ... KEY_F4: // mainmenu, load layout
569 resend_event(mwindow->gui);
574 if( !result && !ctrl_down() ) {
575 switch( get_keypress() ) {
578 mwindow->toggle_camera_xyz(); result = 1;
581 cwindow_operation = CWINDOW_PROTECT;
585 mwindow->toggle_projector_xyz(); result = 1;
588 cwindow_operation = CWINDOW_ZOOM;
592 if( !result && cwindow_operation < 0 && !ctrl_down() && !shift_down() ) {
593 switch( get_keypress() ) {
594 case KEY_F3: cwindow_operation = CWINDOW_MASK; break;
595 case KEY_F4: cwindow_operation = CWINDOW_RULER; break;
596 case KEY_F5: cwindow_operation = CWINDOW_CAMERA; break;
597 case KEY_F6: cwindow_operation = CWINDOW_PROJECTOR; break;
598 case KEY_F7: cwindow_operation = CWINDOW_CROP; break;
599 case KEY_F8: cwindow_operation = CWINDOW_EYEDROP; break;
600 case KEY_F9: cwindow_operation = CWINDOW_TOOL_WINDOW; break;
601 case KEY_F10: cwindow_operation = CWINDOW_TITLESAFE; break;
604 if( !result && cwindow_operation < 0 && !ctrl_down() ) {
605 switch( get_keypress() ) {
608 canvas->reset_camera();
610 canvas->camera_keyframe();
615 canvas->reset_projector();
617 canvas->projector_keyframe();
623 if( cwindow_operation >= 0 ) {
624 set_operation(cwindow_operation);
629 result = transport->keypress_event();
635 void CWindowGUI::reset_affected()
642 void CWindowGUI::keyboard_zoomin()
644 // if(mwindow->edl->session->cwindow_scrollbars)
646 zoom_panel->zoom_tumbler->handle_up_event();
653 void CWindowGUI::keyboard_zoomout()
655 // if(mwindow->edl->session->cwindow_scrollbars)
657 zoom_panel->zoom_tumbler->handle_down_event();
664 void CWindowGUI::sync_parameters(int change_type, int redraw, int overlay)
670 if( change_type < 0 && !overlay ) return;
672 if( change_type >= 0 ) {
673 mwindow->restart_brender();
674 mwindow->sync_parameters(change_type);
677 mwindow->gui->lock_window("CWindowGUI::sync_parameters");
678 mwindow->gui->draw_overlays(1);
679 mwindow->gui->unlock_window();
681 lock_window("CWindowGUI::sync_parameters");
684 void CWindowGUI::drag_motion()
686 if(get_hidden()) return;
688 if(mwindow->session->current_operation != DRAG_ASSET &&
689 mwindow->session->current_operation != DRAG_VTRANSITION &&
690 mwindow->session->current_operation != DRAG_VEFFECT) return;
691 int need_highlight = cursor_above() && get_cursor_over_window();
692 if( highlighted == need_highlight ) return;
693 highlighted = need_highlight;
697 int CWindowGUI::drag_stop()
700 if(get_hidden()) return 0;
701 if( !highlighted ) return 0;
702 if( mwindow->session->current_operation != DRAG_ASSET &&
703 mwindow->session->current_operation != DRAG_VTRANSITION &&
704 mwindow->session->current_operation != DRAG_VEFFECT) return 0;
709 if(mwindow->session->current_operation == DRAG_ASSET)
711 if(mwindow->session->drag_assets->total ||
712 mwindow->session->drag_clips->total)
714 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
715 mwindow->undo->update_undo_before(_("insert assets"), 0);
718 if(mwindow->session->drag_assets->total)
721 mwindow->load_assets(mwindow->session->drag_assets,
722 mwindow->edl->local_session->get_selectionstart(),
724 mwindow->session->track_highlighted,
726 mwindow->edl->session->labels_follow_edits,
727 mwindow->edl->session->plugins_follow_edits,
728 mwindow->edl->session->autos_follow_edits,
732 if(mwindow->session->drag_clips->total)
735 mwindow->paste_edls(mwindow->session->drag_clips,
737 mwindow->session->track_highlighted,
738 mwindow->edl->local_session->get_selectionstart(),
739 mwindow->edl->session->labels_follow_edits,
740 mwindow->edl->session->plugins_follow_edits,
741 mwindow->edl->session->autos_follow_edits,
745 if(mwindow->session->drag_assets->total ||
746 mwindow->session->drag_clips->total)
748 mwindow->save_backup();
749 mwindow->restart_brender();
750 mwindow->gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
751 mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
752 mwindow->gui->unlock_window();
753 sync_parameters(CHANGE_ALL);
757 if(mwindow->session->current_operation == DRAG_VEFFECT)
759 //printf("CWindowGUI::drag_stop 1\n");
760 Track *affected_track = cwindow->calculate_affected_track();
761 //printf("CWindowGUI::drag_stop 2\n");
763 mwindow->gui->lock_window("CWindowGUI::drag_stop 3");
764 mwindow->insert_effects_cwindow(affected_track);
765 mwindow->session->current_operation = NO_OPERATION;
766 mwindow->gui->unlock_window();
769 if(mwindow->session->current_operation == DRAG_VTRANSITION)
771 Track *affected_track = cwindow->calculate_affected_track();
772 mwindow->gui->lock_window("CWindowGUI::drag_stop 4");
773 mwindow->paste_transition_cwindow(affected_track);
774 mwindow->session->current_operation = NO_OPERATION;
775 mwindow->gui->unlock_window();
781 void CWindowGUI::update_meters()
783 if(mwindow->edl->session->cwindow_meter != meters->visible)
785 meters->set_meters(meters->meter_count, mwindow->edl->session->cwindow_meter);
786 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
787 resize_event(get_w(), get_h());
791 void CWindowGUI::stop_transport(const char *lock_msg)
793 if( lock_msg ) unlock_window();
794 mwindow->stop_transport();
795 if( lock_msg ) lock_window(lock_msg);
799 CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
800 : EditPanel(mwindow, cwindow->gui, CWINDOW_ID,
801 mwindow->theme->cedit_x, mwindow->theme->cedit_y,
802 mwindow->edl->session->editing_mode,
803 0, // use_editing_mode
820 this->mwindow = mwindow;
821 this->cwindow = cwindow;
824 #define relock_cm(s) \
825 cwindow->gui->unlock_window(); \
826 mwindow->gui->lock_window("CWindowEditing::" s)
827 #define relock_mc(s) \
828 mwindow->gui->unlock_window(); \
829 cwindow->gui->lock_window("CWindowEditing::" s)
830 #define panel_fn(fn, args, s) \
831 CWindowEditing::fn args { relock_cm(#fn); s; relock_mc(#fn); }
833 // transmit lock to mwindow, and run mbutton->edit_panel->s
834 #define panel_btn(fn, args, s) \
835 panel_fn(panel_##fn, args, mwindow->gui->mbuttons->edit_panel->panel_##s)
838 double CWindowEditing::get_position()
840 relock_cm("get_position");
841 double ret = mwindow->edl->local_session->get_selectionstart(1);
842 relock_mc("get_position");
846 void CWindowEditing::set_position(double position)
848 relock_cm("set_position");
849 mwindow->gui->mbuttons->edit_panel->set_position(position);
850 relock_mc("set_position");
853 void CWindowEditing::set_click_to_play(int v)
855 relock_cm("set_position");
856 mwindow->edl->session->cwindow_click2play = v;
857 relock_mc("set_position");
858 click2play->update(v);
862 void panel_btn(stop_transport,(), stop_transport())
863 void panel_btn(toggle_label,(), toggle_label())
864 void panel_btn(next_label,(int cut), next_label(cut))
865 void panel_btn(prev_label,(int cut), prev_label(cut))
866 void panel_btn(next_edit,(int cut), next_edit(cut))
867 void panel_btn(prev_edit,(int cut), prev_edit(cut))
868 void panel_fn(panel_copy_selection,(), mwindow->copy())
869 void CWindowEditing::panel_overwrite_selection() {} // not used
870 void CWindowEditing::panel_splice_selection() {} // not used
871 void panel_btn(set_inpoint,(), set_inpoint())
872 void panel_btn(set_outpoint,(), set_outpoint())
873 void panel_btn(unset_inoutpoint,(), unset_inoutpoint())
874 void panel_fn(panel_to_clip,(), mwindow->to_clip(mwindow->edl, _("main window: "), 0))
875 void panel_btn(cut,(), cut())
876 void panel_btn(paste,(), paste())
877 void panel_btn(fit_selection,(), fit_selection())
878 void panel_btn(fit_autos,(int all), fit_autos(all))
879 void panel_btn(set_editing_mode,(int mode), set_editing_mode(mode))
880 void panel_btn(set_auto_keyframes,(int v), set_auto_keyframes(v))
881 void panel_btn(set_labels_follow_edits,(int v), set_labels_follow_edits(v))
884 CWindowMeters::CWindowMeters(MWindow *mwindow,
885 CWindowGUI *gui, int x, int y, int h)
886 : MeterPanel(mwindow, gui, x, y, -1, h,
887 mwindow->edl->session->audio_channels,
888 mwindow->edl->session->cwindow_meter,
891 this->mwindow = mwindow;
895 CWindowMeters::~CWindowMeters()
899 int CWindowMeters::change_status_event(int new_status)
901 mwindow->edl->session->cwindow_meter = new_status;
902 gui->update_meters();
909 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
910 : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
911 x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
913 this->mwindow = mwindow;
917 CWindowZoom::~CWindowZoom()
921 void CWindowZoom::update(double value)
923 char string[BCSTRLEN];
924 const char *cp = string;
927 int frac = value >= 1.0f ? 1 :
929 value >= .01f ? 3 : 4;
930 sprintf(string, "x %.*f", frac, value);
934 ZoomPanel::update(cp);
937 int CWindowZoom::handle_event()
939 double value = !strcasecmp(gui->auto_zoom, get_text()) ? 0 : get_value();
940 gui->zoom_canvas(value, 0);
947 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
948 : BC_PercentageSlider(x,
957 this->mwindow = mwindow;
958 this->cwindow = cwindow;
959 set_precision(0.00001);
962 CWindowSlider::~CWindowSlider()
966 int CWindowSlider::handle_event()
968 cwindow->update_position((double)get_value());
972 void CWindowSlider::set_position()
974 double new_length = mwindow->edl->tracks->total_length();
975 update(mwindow->theme->cslider_w,
976 mwindow->edl->local_session->get_selectionstart(1),
981 int CWindowSlider::increase_value()
984 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
985 lock_window("CWindowSlider::increase_value");
989 int CWindowSlider::decrease_value()
992 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
993 lock_window("CWindowSlider::decrease_value");
999 CWindowTransport::CWindowTransport(MWindow *mwindow,
1000 CWindowGUI *gui, int x, int y)
1001 : PlayTransport(mwindow, gui, x, y)
1006 EDL* CWindowTransport::get_edl()
1008 return mwindow->edl;
1011 void CWindowTransport::goto_start()
1013 gui->unlock_window();
1014 handle_transport(REWIND, 1);
1016 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
1017 mwindow->goto_start();
1018 mwindow->gui->unlock_window();
1020 gui->lock_window("CWindowTransport::goto_start 2");
1023 void CWindowTransport::goto_end()
1025 gui->unlock_window();
1026 handle_transport(GOTO_END, 1);
1028 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
1029 mwindow->goto_end();
1030 mwindow->gui->unlock_window();
1032 gui->lock_window("CWindowTransport::goto_end 2");
1037 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
1040 mwindow->theme->ccanvas_x,
1041 mwindow->theme->ccanvas_y,
1042 mwindow->theme->ccanvas_w,
1043 mwindow->theme->ccanvas_h,
1046 mwindow->edl->session->cwindow_scrollbars)
1048 this->mwindow = mwindow;
1052 void CWindowCanvas::status_event()
1054 gui->draw_status(1);
1057 void CWindowCanvas::update_zoom(int x, int y, float zoom)
1059 use_scrollbars = mwindow->edl->session->cwindow_scrollbars;
1061 mwindow->edl->session->cwindow_xscroll = x;
1062 mwindow->edl->session->cwindow_yscroll = y;
1063 mwindow->edl->session->cwindow_zoom = zoom;
1066 void CWindowCanvas::zoom_auto()
1068 gui->zoom_canvas(0, 1);
1071 int CWindowCanvas::get_xscroll()
1073 return mwindow->edl->session->cwindow_xscroll;
1076 int CWindowCanvas::get_yscroll()
1078 return mwindow->edl->session->cwindow_yscroll;
1082 float CWindowCanvas::get_zoom()
1084 return mwindow->edl->session->cwindow_zoom;
1087 void CWindowCanvas::draw_refresh(int flush)
1089 BC_WindowBase *window = get_canvas();
1090 if( window && !window->get_video_on() ) {
1092 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
1093 float in_x1, in_y1, in_x2, in_y2;
1094 float out_x1, out_y1, out_x2, out_y2;
1095 get_transfers(mwindow->edl,
1096 in_x1, in_y1, in_x2, in_y2,
1097 out_x1, out_y1, out_x2, out_y2);
1100 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1101 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1104 if( out_x2 > out_x1 && out_y2 > out_y1 &&
1105 in_x2 > in_x1 && in_y2 > in_y1 ) {
1106 // input scaled from session to refresh frame coordinates
1107 int ow = get_output_w(mwindow->edl);
1108 int oh = get_output_h(mwindow->edl);
1109 int rw = refresh_frame->get_w();
1110 int rh = refresh_frame->get_h();
1111 float xs = (float)rw / ow;
1112 float ys = (float)rh / oh;
1113 in_x1 *= xs; in_x2 *= xs;
1114 in_y1 *= ys; in_y2 *= ys;
1115 // Can't use OpenGL here because it is called asynchronously of the
1116 // playback operation.
1117 window->draw_vframe(refresh_frame,
1118 (int)out_x1, (int)out_y1,
1119 (int)(out_x2 - out_x1),
1120 (int)(out_y2 - out_y1),
1121 (int)in_x1, (int)in_y1,
1122 (int)(in_x2 - in_x1),
1123 (int)(in_y2 - in_y1),
1129 window->flash(flush);
1131 //printf("CWindowCanvas::draw_refresh 10\n");
1134 #define CROPHANDLE_W 10
1135 #define CROPHANDLE_H 10
1137 void CWindowCanvas::draw_crophandle(int x, int y)
1139 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1143 #define CONTROL_W 10
1144 #define CONTROL_H 10
1145 #define FIRST_CONTROL_W 20
1146 #define FIRST_CONTROL_H 20
1148 #define BC_INFINITY 65536
1150 #define RULERHANDLE_W 16
1151 #define RULERHANDLE_H 16
1153 int CWindowCanvas::do_ruler(int draw,
1159 float x1 = mwindow->edl->session->ruler_x1;
1160 float y1 = mwindow->edl->session->ruler_y1;
1161 float x2 = mwindow->edl->session->ruler_x2;
1162 float y2 = mwindow->edl->session->ruler_y2;
1163 float canvas_x1 = x1;
1164 float canvas_y1 = y1;
1165 float canvas_x2 = x2;
1166 float canvas_y2 = y2;
1167 float output_x = get_cursor_x();
1168 float output_y = get_cursor_y();
1169 float canvas_cursor_x = output_x;
1170 float canvas_cursor_y = output_y;
1172 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1173 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1174 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1175 mwindow->session->cwindow_output_x = roundf(output_x);
1176 mwindow->session->cwindow_output_y = roundf(output_y);
1178 if(button_press && get_buttonpress() == 1)
1180 gui->ruler_handle = -1;
1181 gui->ruler_translate = 0;
1184 gui->ruler_translate = 1;
1185 gui->ruler_origin_x = x1;
1186 gui->ruler_origin_y = y1;
1189 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1190 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1191 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1192 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1194 gui->ruler_handle = 0;
1195 gui->ruler_origin_x = x1;
1196 gui->ruler_origin_y = y1;
1199 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1200 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1201 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1202 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1204 gui->ruler_handle = 1;
1205 gui->ruler_origin_x = x2;
1206 gui->ruler_origin_y = y2;
1210 // Start new selection
1211 if(!gui->ruler_translate &&
1212 (gui->ruler_handle < 0 ||
1217 do_ruler(1, 0, 0, 0);
1218 get_canvas()->flash();
1219 gui->ruler_handle = 1;
1220 mwindow->edl->session->ruler_x1 = output_x;
1221 mwindow->edl->session->ruler_y1 = output_y;
1222 mwindow->edl->session->ruler_x2 = output_x;
1223 mwindow->edl->session->ruler_y2 = output_y;
1224 gui->ruler_origin_x = mwindow->edl->session->ruler_x2;
1225 gui->ruler_origin_y = mwindow->edl->session->ruler_y2;
1228 gui->x_origin = output_x;
1229 gui->y_origin = output_y;
1230 gui->current_operation = CWINDOW_RULER;
1231 gui->tool_panel->raise_window();
1237 if(gui->current_operation == CWINDOW_RULER)
1239 if(gui->ruler_translate)
1242 do_ruler(1, 0, 0, 0);
1243 float x_difference = mwindow->edl->session->ruler_x1;
1244 float y_difference = mwindow->edl->session->ruler_y1;
1245 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1246 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1247 x_difference -= mwindow->edl->session->ruler_x1;
1248 y_difference -= mwindow->edl->session->ruler_y1;
1249 mwindow->edl->session->ruler_x2 -= x_difference;
1250 mwindow->edl->session->ruler_y2 -= y_difference;
1252 do_ruler(1, 0, 0, 0);
1253 get_canvas()->flash();
1257 switch(gui->ruler_handle)
1260 do_ruler(1, 0, 0, 0);
1261 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1262 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1263 if(gui->alt_down() || gui->ctrl_down())
1265 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1266 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1270 double distance_value =
1271 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1272 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1273 if(angle_value < 22)
1274 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2;
1276 if(angle_value > 67)
1277 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2;
1279 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 &&
1280 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1282 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1283 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1286 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 && mwindow->edl->session->ruler_y1 > mwindow->edl->session->ruler_y2)
1288 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1289 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1292 if(mwindow->edl->session->ruler_x1 > mwindow->edl->session->ruler_x2 &&
1293 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1295 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1296 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1300 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1301 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1304 do_ruler(1, 0, 0, 0);
1305 get_canvas()->flash();
1310 do_ruler(1, 0, 0, 0);
1311 mwindow->edl->session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1312 mwindow->edl->session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1313 if(gui->alt_down() || gui->ctrl_down())
1315 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1316 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1320 double distance_value =
1321 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1322 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1323 if(angle_value < 22)
1324 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1;
1326 if(angle_value > 67)
1327 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1;
1329 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1330 mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1332 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1333 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1336 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1337 mwindow->edl->session->ruler_y2 > mwindow->edl->session->ruler_y1)
1339 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1340 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1343 if(mwindow->edl->session->ruler_x2 > mwindow->edl->session->ruler_x1 && mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1345 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1346 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1350 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1351 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1354 do_ruler(1, 0, 0, 0);
1355 get_canvas()->flash();
1359 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1363 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1368 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1369 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1370 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1371 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1373 set_cursor(UPRIGHT_ARROW_CURSOR);
1376 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1377 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1378 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1379 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1381 set_cursor(UPRIGHT_ARROW_CURSOR);
1384 set_cursor(CROSS_CURSOR);
1386 // Update current position
1391 // Assume no ruler measurement if 0 length
1392 if(draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)))
1394 get_canvas()->set_inverse();
1395 get_canvas()->set_color(WHITE);
1396 get_canvas()->draw_line((int)canvas_x1,
1400 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1402 roundf(canvas_x1) + RULERHANDLE_W / 2,
1404 get_canvas()->draw_line(roundf(canvas_x1),
1405 roundf(canvas_y1) - RULERHANDLE_H / 2,
1407 roundf(canvas_y1) + RULERHANDLE_H / 2);
1408 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1410 roundf(canvas_x2) + RULERHANDLE_W / 2,
1412 get_canvas()->draw_line(roundf(canvas_x2),
1413 roundf(canvas_y2) - RULERHANDLE_H / 2,
1415 roundf(canvas_y2) + RULERHANDLE_H / 2);
1416 get_canvas()->set_opaque();
1423 static inline double line_dist(float cx,float cy, float tx,float ty)
1425 double dx = tx-cx, dy = ty-cy;
1426 return sqrt(dx*dx + dy*dy);
1429 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1431 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1432 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1436 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1437 int button_press, int cursor_motion, int draw)
1439 // Retrieve points from top recordable track
1440 //printf("CWindowCanvas::do_mask 1\n");
1441 Track *track = gui->cwindow->calculate_mask_track();
1442 //printf("CWindowCanvas::do_mask 2\n");
1444 if(!track) return 0;
1445 //printf("CWindowCanvas::do_mask 3\n");
1446 CWindowMaskGUI *mask_gui = (CWindowMaskGUI *)
1447 (gui->tool_panel ? gui->tool_panel->tool_gui : 0);
1448 int draw_markers = mask_gui ? mask_gui->markers : 0;
1449 int draw_boundary = mask_gui ? mask_gui->boundary : 0;
1450 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1451 int64_t position = track->to_units(
1452 mwindow->edl->local_session->get_selectionstart(1),
1454 Auto *prev_auto = 0;
1455 mask_autos->get_prev_auto(position, PLAY_FORWARD, (Auto *&)prev_auto, 1);
1456 MaskAuto *prev_mask = (MaskAuto *)prev_auto;
1457 ArrayList<MaskPoint*> points;
1458 int update_points = 1;
1459 // Determine the points based on whether
1460 // new keyframes will be generated or drawing is performed.
1461 // If keyframe generation occurs, use the interpolated mask.
1462 // If no keyframe generation occurs, use the previous mask.
1463 int use_interpolated = 0;
1464 if( button_press || cursor_motion ) {
1465 #ifdef USE_KEYFRAME_SPANNING
1466 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1467 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1468 int64_t start_pos = track->to_units(selection_start, 0);
1469 int64_t end_pos = track->to_units(selection_end, 0);
1470 Auto *first = 0, *last = 0;
1471 mask_autos->get_prev_auto(start_pos, PLAY_FORWARD, first, 1);
1472 mask_autos->get_prev_auto(end_pos, PLAY_FORWARD, last, 1);
1473 if( last == first && (!mwindow->edl->session->auto_keyframes) )
1474 use_interpolated = 0;
1476 // If keyframe spanning occurs, use the interpolated points.
1477 // If new keyframe is generated, use the interpolated points.
1478 use_interpolated = 1;
1481 if( mwindow->edl->session->auto_keyframes )
1482 use_interpolated = 1;
1486 use_interpolated = 1;
1488 if( use_interpolated ) {
1489 // Interpolate the points to get exactly what is being rendered at this position.
1490 mask_autos->get_points(&points,
1491 mwindow->edl->session->cwindow_mask,
1492 position, PLAY_FORWARD);
1495 // Use the prev mask
1496 prev_mask->get_points(&points,
1497 mwindow->edl->session->cwindow_mask);
1500 // Projector zooms relative to the center of the track output.
1501 float half_track_w = (float)track->track_w / 2;
1502 float half_track_h = (float)track->track_h / 2;
1503 // Translate mask to projection
1504 float projector_x, projector_y, projector_z;
1505 track->automation->get_projector(
1506 &projector_x, &projector_y, &projector_z,
1507 position, PLAY_FORWARD);
1510 // Get position of cursor relative to mask
1511 float cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
1512 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1513 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1515 projector_x += mwindow->edl->session->output_w / 2;
1516 projector_y += mwindow->edl->session->output_h / 2;
1517 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1518 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1520 // Fix cursor origin
1522 gui->x_origin = mask_cursor_x;
1523 gui->y_origin = mask_cursor_y;
1527 // Points of closest line
1528 int shortest_point1 = -1;
1529 int shortest_point2 = -1;
1531 int shortest_point = -1;
1532 // Distance to closest line
1533 float shortest_line_distance = BC_INFINITY;
1534 // Distance to closest point
1535 float shortest_point_distance = BC_INFINITY;
1536 int selected_point = -1;
1537 int selected_control_point = -1;
1538 float selected_control_point_distance = BC_INFINITY;
1539 ArrayList<int> x_points;
1540 ArrayList<int> y_points;
1542 if(!cursor_motion) {
1544 get_canvas()->set_color(WHITE);
1545 get_canvas()->set_inverse();
1547 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1549 // Never draw closed polygon and a closed
1550 // polygon is harder to add points to.
1551 for(int i = 0; i < points.size() && !result; i++) {
1552 MaskPoint *point1 = points.get(i);
1553 MaskPoint *point2 = (i >= points.size() - 1) ?
1554 points.get(0) : points.get(i + 1);
1556 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1557 if(point_distance1 < shortest_point_distance || shortest_point < 0) {
1558 shortest_point_distance = point_distance1;
1562 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1563 if(point_distance2 < shortest_point_distance || shortest_point < 0) {
1564 shortest_point_distance = point_distance2;
1565 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1569 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1571 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1572 //point1->x, point1->y, point2->x, point2->y, projector_z);
1573 for(int j = 0; j <= segments && !result; j++) {
1574 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1575 float x0 = point1->x, y0 = point1->y;
1576 float x1 = point1->x + point1->control_x2;
1577 float y1 = point1->y + point1->control_y2;
1578 float x2 = point2->x + point2->control_x1;
1579 float y2 = point2->y + point2->control_y1;
1580 float x3 = point2->x, y3 = point2->y;
1581 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1582 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1583 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1584 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1585 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1586 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1587 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1588 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1590 float t = (float)j / segments;
1591 float tpow2 = t * t;
1592 float tpow3 = t * t * t;
1594 float invtpow2 = invt * invt;
1595 float invtpow3 = invt * invt * invt;
1597 float x = ( invtpow3 * x0
1598 + 3 * t * invtpow2 * x1
1599 + 3 * tpow2 * invt * x2
1601 float y = ( invtpow3 * y0
1602 + 3 * t * invtpow2 * y1
1603 + 3 * tpow2 * invt * y2
1605 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1606 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1607 // Test new point addition
1609 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1611 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1612 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1613 if(line_distance < shortest_line_distance ||
1614 shortest_point1 < 0) {
1615 shortest_line_distance = line_distance;
1616 shortest_point1 = i;
1617 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1618 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1619 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1622 // Test existing point selection
1624 if(gui->ctrl_down()) {
1625 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1627 if(distance < selected_control_point_distance) {
1629 selected_control_point = 1;
1630 selected_control_point_distance = distance;
1634 if(!gui->shift_down()) {
1635 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1636 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
1641 selected_point = shortest_point;
1644 // Test second point
1645 if(gui->ctrl_down()) {
1646 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1648 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1649 if(distance < selected_control_point_distance) {
1650 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1651 selected_control_point = 0;
1652 selected_control_point_distance = distance;
1655 else if(i < points.size() - 1) {
1656 if(!gui->shift_down()) {
1657 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1658 if(test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3)) {
1659 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1663 selected_point = shortest_point;
1668 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1672 if( draw ) { // Draw joining line
1673 x_points.append((int)canvas_x);
1674 y_points.append((int)canvas_y);
1677 if( j == segments ) {
1678 if( draw && draw_markers ) { // Draw second anchor
1679 if(i < points.size() - 1) {
1680 if(i == gui->affected_point - 1)
1681 get_canvas()->draw_disc(
1682 (int)canvas_x - CONTROL_W / 2,
1683 (int)canvas_y - CONTROL_W / 2,
1684 CONTROL_W, CONTROL_H);
1686 get_canvas()->draw_circle(
1687 (int)canvas_x - CONTROL_W / 2,
1688 (int)canvas_y - CONTROL_W / 2,
1689 CONTROL_W, CONTROL_H);
1690 // char string[BCTEXTLEN];
1691 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1692 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1694 // Draw second control point.
1695 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1696 get_canvas()->draw_line(
1697 (int)canvas_x, (int)canvas_y,
1698 (int)canvas_x2, (int)canvas_y2);
1699 get_canvas()->draw_rectangle(
1700 (int)canvas_x2 - CONTROL_W / 2,
1701 (int)canvas_y2 - CONTROL_H / 2,
1702 CONTROL_W, CONTROL_H);
1707 // Draw first anchor
1708 if( i == 0 && draw ) {
1709 if( draw_boundary ) {
1710 char mask_label[BCSTRLEN];
1711 int k = mwindow->edl->session->cwindow_mask;
1712 if( !prev_mask || k < 0 || k >= prev_mask->masks.size() )
1713 sprintf(mask_label, "%d", k);
1715 sprintf(mask_label, "%s", prev_mask->masks[k]->name);
1716 get_canvas()->draw_text(
1717 (int)canvas_x - FIRST_CONTROL_W,
1718 (int)canvas_y - FIRST_CONTROL_H,
1721 if( draw_markers ) {
1722 get_canvas()->draw_disc(
1723 (int)canvas_x - FIRST_CONTROL_W / 2,
1724 (int)canvas_y - FIRST_CONTROL_H / 2,
1725 FIRST_CONTROL_W, FIRST_CONTROL_H);
1729 // Draw first control point.
1730 if( draw && draw_markers ) {
1731 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1732 get_canvas()->draw_line(
1733 (int)canvas_x, (int)canvas_y,
1734 (int)canvas_x1, (int)canvas_y1);
1735 get_canvas()->draw_rectangle(
1736 (int)canvas_x1 - CONTROL_W / 2,
1737 (int)canvas_y1 - CONTROL_H / 2,
1738 CONTROL_W, CONTROL_H);
1740 x_points.append((int)canvas_x);
1741 y_points.append((int)canvas_y);
1744 //printf("CWindowCanvas::do_mask 1\n");
1748 //printf("CWindowCanvas::do_mask 1\n");
1750 BC_WindowBase *cvs_win = get_canvas();
1751 if( draw && draw_boundary ) {
1752 cvs_win->draw_polygon(&x_points, &y_points);
1753 cvs_win->set_opaque();
1755 if( draw && mask_gui && mask_gui->focused ) {
1756 float fx = atof(mask_gui->focus_x->get_text());
1757 float fy = atof(mask_gui->focus_y->get_text());
1758 output_to_canvas(mwindow->edl, 0, fx, fy);
1759 float r = bmax(cvs_win->get_w(), cvs_win->get_h());
1762 int fw = 2*d+3, fh = fw;
1763 VFrame focus(fw,fh, BC_RGBA8888);
1764 focus.transfer_from(gui->focus_frame);
1765 fx -= fw/2.f; fy -= fh/2.f;
1766 BC_Pixmap focus_pixmap(cvs_win, &focus, PIXMAP_ALPHA);
1767 cvs_win->draw_pixmap(&focus_pixmap,fx,fy);
1769 cvs_win->set_line_width((int)(0.0025*r) + 1);
1770 cvs_win->set_color(BLUE);
1771 cvs_win->draw_line(fx-d,fy-d, fx+d, fy+d);
1772 cvs_win->draw_line(fx-d,fy+d, fx+d, fy-d);
1773 cvs_win->set_line_width(0);
1774 cvs_win->set_color(WHITE);
1777 if( draw && mask_gui && draw_markers && points.size() ) {
1778 float cx = 0, cy = 0;
1779 int n = points.size();
1780 for( int i=0; i<n; ++i ) {
1781 MaskPoint *point = points.get(i);
1782 cx += point->x; cy += point->y;
1785 if( !mask_gui->focused )
1786 mask_gui->set_focused(0, cx, cy);
1787 output_to_canvas(mwindow->edl, 0, cx, cy);
1788 float r = bmax(cvs_win->get_w(), cvs_win->get_h());
1790 cvs_win->set_line_width((int)(0.002*r) + 1);
1791 cvs_win->set_color(ORANGE);
1792 cvs_win->draw_line(cx-d,cy, cx+d, cy);
1793 cvs_win->draw_line(cx,cy-d, cx, cy+d);
1794 cvs_win->set_line_width(0);
1795 cvs_win->set_color(WHITE);
1797 //printf("CWindowCanvas::do_mask 1\n");
1800 if(button_press && !result) {
1801 gui->affected_track = gui->cwindow->calculate_mask_track();
1803 // Get keyframe outside the EDL to edit. This must be rendered
1804 // instead of the EDL keyframes when it exists. Then it must be
1805 // applied to the EDL keyframes on buttonrelease.
1806 if( gui->affected_track ) {
1807 #ifdef USE_KEYFRAME_SPANNING
1808 // Make copy of current parameters in local keyframe
1809 gui->mask_keyframe =
1810 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1813 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1816 gui->mask_keyframe =
1817 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1822 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1824 if( get_buttonpress() == WHEEL_UP || get_buttonpress() == WHEEL_DOWN ) {
1825 if( !gui->shift_down() ) {
1826 mwindow->undo->update_undo_before(_("mask rotate"), this);
1827 gui->current_operation = CWINDOW_MASK_ROTATE;
1830 mwindow->undo->update_undo_before(_("mask scale"), this);
1831 gui->current_operation = CWINDOW_MASK_SCALE;
1833 gui->affected_point = 0;
1836 // Translate entire keyframe
1837 if(gui->alt_down() && mask->points.size()) {
1838 mwindow->undo->update_undo_before(_("mask translate"), 0);
1839 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1840 gui->affected_point = 0;
1843 // Existing point or control point was selected
1844 if(selected_point >= 0) {
1845 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1846 gui->affected_point = selected_point;
1848 if(selected_control_point == 0)
1849 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1851 if(selected_control_point == 1)
1852 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1854 gui->current_operation = mwindow->edl->session->cwindow_operation;
1856 else // No existing point or control point was selected so create a new one
1857 if(!gui->ctrl_down() && !gui->alt_down()) {
1858 mwindow->undo->update_undo_before(_("mask point"), 0);
1859 // Create the template
1860 MaskPoint *point = new MaskPoint;
1861 point->x = mask_cursor_x;
1862 point->y = mask_cursor_y;
1863 point->control_x1 = 0;
1864 point->control_y1 = 0;
1865 point->control_x2 = 0;
1866 point->control_y2 = 0;
1869 if(shortest_point2 < shortest_point1) {
1870 shortest_point2 ^= shortest_point1;
1871 shortest_point1 ^= shortest_point2;
1872 shortest_point2 ^= shortest_point1;
1877 // printf("CWindowGUI::do_mask 40\n");
1878 // mwindow->edl->dump();
1879 // printf("CWindowGUI::do_mask 50\n");
1883 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1884 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1885 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1887 // Append to end of list
1888 if( shortest_point1 == shortest_point2 ||
1889 labs(shortest_point1 - shortest_point2) > 1) {
1890 #ifdef USE_KEYFRAME_SPANNING
1892 MaskPoint *new_point = new MaskPoint;
1893 points.append(new_point);
1894 *new_point = *point;
1895 gui->affected_point = points.size() - 1;
1899 // Need to apply the new point to every keyframe
1900 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1901 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1902 MaskPoint *new_point = new MaskPoint;
1903 submask->points.append(new_point);
1904 *new_point = *point;
1905 if(current == (MaskAuto*)mask_autos->default_auto)
1906 current = (MaskAuto*)mask_autos->first;
1908 current = (MaskAuto*)NEXT;
1910 gui->affected_point = mask->points.size() - 1;
1916 // Insert between 2 points, shifting back point 2
1917 if(shortest_point1 >= 0 && shortest_point2 >= 0) {
1919 #ifdef USE_KEYFRAME_SPANNING
1920 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1922 if(points.size() >= shortest_point2) {
1923 MaskPoint *new_point = new MaskPoint;
1925 for(int i = points.size() - 1;
1926 i > shortest_point2;
1928 points.values[i] = points.values[i - 1];
1929 points.values[shortest_point2] = new_point;
1931 *new_point = *point;
1936 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1937 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1938 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1940 if(submask->points.size() >= shortest_point2) {
1941 MaskPoint *new_point = new MaskPoint;
1942 submask->points.append(0);
1943 for(int i = submask->points.size() - 1;
1944 i > shortest_point2;
1946 submask->points.values[i] = submask->points.values[i - 1];
1947 submask->points.values[shortest_point2] = new_point;
1949 *new_point = *point;
1952 if(current == (MaskAuto*)mask_autos->default_auto)
1953 current = (MaskAuto*)mask_autos->first;
1955 current = (MaskAuto*)NEXT;
1959 gui->affected_point = shortest_point2;
1964 // printf("CWindowGUI::do_mask 20\n");
1965 // mwindow->edl->dump();
1966 // printf("CWindowGUI::do_mask 30\n");
1969 //printf("CWindowCanvas::do_mask 1\n");
1970 // Create the first point.
1971 #ifdef USE_KEYFRAME_SPANNING
1972 MaskPoint *new_point = new MaskPoint;
1973 points.append(new_point);
1974 *new_point = *point;
1975 gui->affected_point = points.size() - 1;
1977 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1978 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1979 MaskPoint *new_point = new MaskPoint;
1980 submask->points.append(new_point);
1981 *new_point = *point;
1982 if(current == (MaskAuto*)mask_autos->default_auto)
1983 current = (MaskAuto*)mask_autos->first;
1985 current = (MaskAuto*)NEXT;
1987 gui->affected_point = points.size() - 1;
1990 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
1993 gui->current_operation = mwindow->edl->session->cwindow_operation;
1994 // Delete the template
2003 if(button_press && result) {
2004 #ifdef USE_KEYFRAME_SPANNING
2005 ArrayList<MaskPoint*> &mask_points = points;
2007 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
2008 ArrayList<MaskPoint*> &mask_points = mask->points;
2010 int k = gui->affected_point;
2011 if( k >= 0 && k < mask_points.size() ) {
2012 MaskPoint *point = mask_points.values[k];
2013 gui->center_x = point->x;
2014 gui->center_y = point->y;
2015 gui->control_in_x = point->control_x1;
2016 gui->control_in_y = point->control_y1;
2017 gui->control_out_x = point->control_x2;
2018 gui->control_out_y = point->control_y2;
2021 gui->center_x = gui->center_y = 0;
2022 gui->control_in_x = gui->control_in_y = 0;
2023 gui->control_out_x = gui->control_out_y = 0;
2025 gui->tool_panel->raise_window();
2028 //printf("CWindowCanvas::do_mask 8\n");
2029 if( cursor_motion ) {
2031 #ifdef USE_KEYFRAME_SPANNING
2032 // Must update the reference keyframes for every cursor motion
2033 gui->mask_keyframe = (MaskAuto*)gui->cwindow->
2034 calculate_affected_auto(mask_autos, 0);
2035 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
2038 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2040 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
2041 if( mask && gui->affected_point >= 0 &&
2042 gui->affected_point < mask->points.size() &&
2043 gui->current_operation != CWINDOW_NONE ) {
2044 // mwindow->undo->update_undo_before(_("mask point"), this);
2045 #ifdef USE_KEYFRAME_SPANNING
2046 ArrayList<MaskPoint*> &mask_points = points;
2048 ArrayList<MaskPoint*> &mask_points = mask->points;
2050 MaskPoint *point = mask_points.get(gui->affected_point);
2051 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2052 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask_points.size(), gui->affected_point);
2054 float last_x = point->x;
2055 float last_y = point->y;
2056 float last_control_x1 = point->control_x1;
2057 float last_control_y1 = point->control_y1;
2058 float last_control_x2 = point->control_x2;
2059 float last_control_y2 = point->control_y2;
2062 switch(gui->current_operation) {
2064 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2065 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
2066 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
2069 case CWINDOW_MASK_CONTROL_IN:
2070 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
2071 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
2074 case CWINDOW_MASK_CONTROL_OUT:
2075 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
2076 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
2079 case CWINDOW_MASK_TRANSLATE: {
2080 if( !mask_gui ) break;
2081 MaskAuto *keyframe = gui->mask_keyframe;
2082 int gang = mask_gui->gang_focus->get_value();
2083 float dx = mask_cursor_x - gui->x_origin;
2084 float dy = mask_cursor_y - gui->y_origin;
2085 if( !dx && !dy ) break;
2086 int k = mwindow->edl->session->cwindow_mask;
2087 int n = gang ? keyframe->masks.size() : k+1;
2088 for( int j=gang? 0 : k; j<n; ++j ) {
2089 SubMask *sub_mask = keyframe->get_submask(j);
2090 if( !sub_mask ) continue;
2091 ArrayList<MaskPoint*> &points = sub_mask->points;
2092 for( int i=0; i<points.size(); ++i ) {
2093 MaskPoint *point = points[i];
2098 gui->x_origin = mask_cursor_x;
2099 gui->y_origin = mask_cursor_y;
2104 case CWINDOW_MASK_ROTATE:
2106 case CWINDOW_MASK_SCALE: {
2107 if( !mask_gui || !mask_points.size() ) break;
2108 float cx = gui->x_origin, cy = gui->y_origin;
2109 if( mask_gui->focused ) {
2110 cx = atof(mask_gui->focus_x->get_text());
2111 cy = atof(mask_gui->focus_y->get_text());
2113 else if( !gui->ctrl_down() ) {
2115 int n = mask_points.size();
2116 for( int i=0; i<n; ++i ) {
2117 MaskPoint *point = mask_points.values[i];
2118 cx += point->x; cy += point->y;
2121 mask_gui->set_focused(0, cx, cy);
2126 gui->get_triple_click() ? 8. :
2127 gui->get_double_click() ? 4. :
2129 int button_no = get_buttonpress();
2130 double ds = accel/64., dt = accel*M_PI/360.;
2131 double scale = button_no == WHEEL_UP ? 1.+ds : 1.-ds;
2132 double theta = button_no == WHEEL_UP ? dt : -dt;
2133 if( rotate ? theta==0 : scale==1 ) break;
2134 float st = sin(theta), ct = cos(theta);
2135 MaskAuto *keyframe = gui->mask_keyframe;
2136 int gang = mask_gui->gang_focus->get_value();
2137 int k = mwindow->edl->session->cwindow_mask;
2138 int n = gang ? keyframe->masks.size() : k+1;
2139 for( int j=gang? 0 : k; j<n; ++j ) {
2140 SubMask *sub_mask = keyframe->get_submask(j);
2141 ArrayList<MaskPoint*> &points = sub_mask->points;
2142 if( !sub_mask ) continue;
2143 for( int i=0; i<points.size(); ++i ) {
2144 MaskPoint *point = points[i];
2145 float px = point->x - gui->x_origin;
2146 float py = point->y - gui->y_origin;
2147 float nx = !rotate ? px*scale : px*ct + py*st;
2148 float ny = !rotate ? py*scale : py*ct - px*st;
2149 point->x = nx + gui->x_origin;
2150 point->y = ny + gui->y_origin;
2151 px = point->control_x1; py = point->control_y1;
2152 point->control_x1 = !rotate ? px*scale : px*ct + py*st;
2153 point->control_y1 = !rotate ? py*scale : py*ct - px*st;
2154 px = point->control_x2; py = point->control_y2;
2155 point->control_x2 = !rotate ? px*scale : px*ct + py*st;
2156 point->control_y2 = !rotate ? py*scale : py*ct - px*st;
2165 if( !(rerender && redraw) && (!EQUIV(last_x, point->x) ||
2166 !EQUIV(last_y, point->y) ||
2167 !EQUIV(last_control_x1, point->control_x1) ||
2168 !EQUIV(last_control_y1, point->control_y1) ||
2169 !EQUIV(last_control_x2, point->control_x2) ||
2170 !EQUIV(last_control_y2, point->control_y2)) ) {
2176 if(gui->current_operation == CWINDOW_NONE) {
2177 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
2179 for(int i = 0; i < points.size() && !over_point; i++) {
2180 MaskPoint *point = points.get(i);
2181 float x0 = point->x;
2182 float y0 = point->y;
2183 float x1 = point->x + point->control_x1;
2184 float y1 = point->y + point->control_y1;
2185 float x2 = point->x + point->control_x2;
2186 float y2 = point->y + point->control_y2;
2187 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
2188 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
2190 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
2191 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
2195 if(!over_point && gui->ctrl_down()) {
2196 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
2197 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
2198 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2199 if(test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1)) {
2203 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2204 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2205 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2206 if(test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2)) {
2213 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2218 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2221 #ifdef USE_KEYFRAME_SPANNING
2222 // Must commit change after operation.
2223 if(rerender && track) {
2224 // Swap EDL keyframe with original.
2225 // Apply new values to keyframe span
2226 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2227 temp_keyframe.copy_data(gui->mask_keyframe);
2228 // Apply interpolated points back to keyframe
2230 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2231 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2232 mask_autos->update_parameter(&temp_keyframe);
2236 points.remove_all_objects();
2237 //printf("CWindowCanvas::do_mask 20\n");
2241 int CWindowCanvas::do_mask_focus()
2243 CWindowMaskGUI *mask_gui = (CWindowMaskGUI*) gui->tool_panel->tool_gui;
2244 float cx = get_cursor_x(), cy = get_cursor_y();
2245 canvas_to_output(mwindow->edl, 0, cx, cy);
2246 mask_gui->set_focused(1, cx, cy);
2250 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2253 int radius = mwindow->edl->session->eyedrop_radius;
2261 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2266 row1 = gui->eyedrop_y - radius;
2267 row2 = gui->eyedrop_y + radius;
2268 column1 = gui->eyedrop_x - radius;
2269 column2 = gui->eyedrop_x + radius;
2271 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2272 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2273 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2274 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2276 if(row2 <= row1) row2 = row1 + 1;
2277 if(column2 <= column1) column2 = column1 + 1;
2284 output_to_canvas(mwindow->edl, 0, x1, y1);
2285 output_to_canvas(mwindow->edl, 0, x2, y2);
2286 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2288 if(x2 - x1 >= 1 && y2 - y1 >= 1)
2290 get_canvas()->set_inverse();
2291 get_canvas()->set_color(WHITE);
2293 get_canvas()->draw_rectangle((int)x1,
2298 get_canvas()->set_opaque();
2299 get_canvas()->flash();
2307 gui->current_operation = CWINDOW_EYEDROP;
2308 gui->tool_panel->raise_window();
2311 if(gui->current_operation == CWINDOW_EYEDROP)
2313 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2315 // Get color out of frame.
2316 // Doesn't work during playback because that bypasses the refresh frame.
2317 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2319 float cursor_x = get_cursor_x();
2320 float cursor_y = get_cursor_y();
2321 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2322 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2323 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2325 row1 = cursor_y - radius;
2326 row2 = cursor_y + radius;
2327 column1 = cursor_x - radius;
2328 column2 = cursor_x + radius;
2329 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2330 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2331 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2332 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2333 if(row2 <= row1) row2 = row1 + 1;
2334 if(column2 <= column1) column2 = column1 + 1;
2338 if(gui->eyedrop_visible)
2341 do_eyedrop(temp, 0, 1);
2342 gui->eyedrop_visible = 0;
2345 gui->eyedrop_x = cursor_x;
2346 gui->eyedrop_y = cursor_y;
2351 do_eyedrop(temp, 0, 1);
2352 gui->eyedrop_visible = 1;
2355 // Decompression coefficients straight out of jpeglib
2356 #define V_TO_R 1.40200
2357 #define V_TO_G -0.71414
2359 #define U_TO_G -0.34414
2360 #define U_TO_B 1.77200
2362 #define GET_COLOR(type, components, max, do_yuv) \
2364 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2366 float red = (float)*row++ / max; \
2367 float green = (float)*row++ / max; \
2368 float blue = (float)*row++ / max; \
2371 float r = red + V_TO_R * (blue - 0.5); \
2372 float g = red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
2373 float b = red + U_TO_B * (green - 0.5); \
2374 mwindow->edl->local_session->red += r; \
2375 mwindow->edl->local_session->green += g; \
2376 mwindow->edl->local_session->blue += b; \
2377 if(r > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = r; \
2378 if(g > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = g; \
2379 if(b > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = b; \
2383 mwindow->edl->local_session->red += red; \
2384 mwindow->edl->local_session->green += green; \
2385 mwindow->edl->local_session->blue += blue; \
2386 if(red > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = red; \
2387 if(green > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = green; \
2388 if(blue > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = blue; \
2394 mwindow->edl->local_session->red = 0;
2395 mwindow->edl->local_session->green = 0;
2396 mwindow->edl->local_session->blue = 0;
2397 mwindow->edl->local_session->red_max = 0;
2398 mwindow->edl->local_session->green_max = 0;
2399 mwindow->edl->local_session->blue_max = 0;
2400 for(int i = row1; i < row2; i++)
2402 for(int j = column1; j < column2; j++)
2404 switch(refresh_frame->get_color_model())
2407 GET_COLOR(unsigned char, 3, 0xff, 1);
2410 GET_COLOR(unsigned char, 4, 0xff, 1);
2413 GET_COLOR(uint16_t, 3, 0xffff, 1);
2415 case BC_YUVA16161616:
2416 GET_COLOR(uint16_t, 4, 0xffff, 1);
2419 GET_COLOR(unsigned char, 3, 0xff, 0);
2422 GET_COLOR(unsigned char, 4, 0xff, 0);
2425 GET_COLOR(float, 3, 1.0, 0);
2428 GET_COLOR(float, 4, 1.0, 0);
2434 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2435 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2436 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2441 mwindow->edl->local_session->red = 0;
2442 mwindow->edl->local_session->green = 0;
2443 mwindow->edl->local_session->blue = 0;
2444 gui->eyedrop_visible = 0;
2453 // Can't rerender since the color value is from the output of any effect it
2456 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2462 int CWindowCanvas::need_overlays()
2464 if( mwindow->edl->session->safe_regions ) return 1;
2465 if( mwindow->edl->session->cwindow_scrollbars ) return 1;
2466 if( gui->highlighted ) return 1;
2467 switch( mwindow->edl->session->cwindow_operation ) {
2468 case CWINDOW_EYEDROP:
2469 if( ! gui->eyedrop_visible ) break;
2470 case CWINDOW_CAMERA:
2471 case CWINDOW_PROJECTOR:
2480 void CWindowCanvas::draw_overlays()
2482 if(mwindow->edl->session->safe_regions)
2484 draw_safe_regions();
2487 if(mwindow->edl->session->cwindow_scrollbars)
2489 // Always draw output rectangle
2490 float x1, y1, x2, y2;
2492 x2 = mwindow->edl->session->output_w;
2494 y2 = mwindow->edl->session->output_h;
2495 output_to_canvas(mwindow->edl, 0, x1, y1);
2496 output_to_canvas(mwindow->edl, 0, x2, y2);
2498 get_canvas()->set_inverse();
2499 get_canvas()->set_color(WHITE);
2501 get_canvas()->draw_rectangle((int)x1,
2506 get_canvas()->set_opaque();
2509 if(gui->highlighted)
2511 get_canvas()->set_color(WHITE);
2512 get_canvas()->set_inverse();
2513 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2514 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2515 get_canvas()->set_opaque();
2518 int temp1 = 0, temp2 = 0;
2519 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2520 switch(mwindow->edl->session->cwindow_operation)
2522 case CWINDOW_CAMERA:
2526 case CWINDOW_PROJECTOR:
2535 do_mask(temp1, temp2, 0, 0, 1);
2539 do_ruler(1, 0, 0, 0);
2542 case CWINDOW_EYEDROP:
2543 if(gui->eyedrop_visible)
2546 do_eyedrop(rerender, 0, 1);
2547 gui->eyedrop_visible = 1;
2553 void CWindowCanvas::draw_safe_regions()
2555 float action_x1, action_x2, action_y1, action_y2;
2556 float title_x1, title_x2, title_y1, title_y2;
2558 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2559 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2560 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2561 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2562 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2563 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2564 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2565 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2567 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2568 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2569 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2570 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2572 get_canvas()->set_inverse();
2573 get_canvas()->set_color(WHITE);
2575 get_canvas()->draw_rectangle((int)action_x1,
2577 (int)(action_x2 - action_x1),
2578 (int)(action_y2 - action_y1));
2579 get_canvas()->draw_rectangle((int)title_x1,
2581 (int)(title_x2 - title_x1),
2582 (int)(title_y2 - title_y1));
2584 get_canvas()->set_opaque();
2588 void CWindowCanvas::create_keyframe(int do_camera)
2590 Track *affected_track = gui->cwindow->calculate_affected_track();
2591 if( affected_track ) {
2592 double pos = mwindow->edl->local_session->get_selectionstart(1);
2593 int64_t position = affected_track->to_units(pos, 0);
2594 int ix = do_camera ? AUTOMATION_CAMERA_X : AUTOMATION_PROJECTOR_X;
2595 int iy = do_camera ? AUTOMATION_CAMERA_Y : AUTOMATION_PROJECTOR_Y;
2596 int iz = do_camera ? AUTOMATION_CAMERA_Z : AUTOMATION_PROJECTOR_Z;
2597 FloatAuto *prev, *next;
2598 FloatAutos **autos = (FloatAutos**)affected_track->automation->autos;
2599 FloatAutos *x_autos = autos[ix]; prev = 0; next = 0;
2600 float x_value = x_autos->get_value(position, PLAY_FORWARD, prev, next);
2601 FloatAutos *y_autos = autos[iy]; prev = 0; next = 0;
2602 float y_value = y_autos->get_value(position, PLAY_FORWARD, prev, next);
2603 FloatAutos *z_autos = autos[iz]; prev = 0; next = 0;
2604 float z_value = z_autos->get_value(position, PLAY_FORWARD, prev, next);
2605 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2607 gui->cwindow->calculate_affected_autos(affected_track,
2608 &x_keyframe, &y_keyframe, &z_keyframe,
2609 do_camera, -1, -1, -1, 0);
2610 x_keyframe->set_value(x_value);
2611 y_keyframe->set_value(y_value);
2612 z_keyframe->set_value(z_value);
2614 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2618 void CWindowCanvas::camera_keyframe() { create_keyframe(1); }
2619 void CWindowCanvas::projector_keyframe() { create_keyframe(0); }
2621 void CWindowCanvas::reset_keyframe(int do_camera)
2623 Track *affected_track = gui->cwindow->calculate_affected_track();
2624 if( affected_track ) {
2625 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2626 gui->cwindow->calculate_affected_autos(affected_track,
2627 &x_keyframe, &y_keyframe, &z_keyframe,
2628 do_camera, 1, 1, 1);
2630 x_keyframe->set_value(0);
2631 y_keyframe->set_value(0);
2632 z_keyframe->set_value(1);
2634 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2638 void CWindowCanvas::reset_camera() { reset_keyframe(1); }
2639 void CWindowCanvas::reset_projector() { reset_keyframe(0); }
2642 int CWindowCanvas::test_crop(int button_press, int &redraw)
2645 int handle_selected = -1;
2646 float x1 = mwindow->edl->session->crop_x1;
2647 float y1 = mwindow->edl->session->crop_y1;
2648 float x2 = mwindow->edl->session->crop_x2;
2649 float y2 = mwindow->edl->session->crop_y2;
2650 float cursor_x = get_cursor_x();
2651 float cursor_y = get_cursor_y();
2652 float canvas_x1 = x1;
2653 float canvas_y1 = y1;
2654 float canvas_x2 = x2;
2655 float canvas_y2 = y2;
2656 float canvas_cursor_x = cursor_x;
2657 float canvas_cursor_y = cursor_y;
2659 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2660 // Use screen normalized coordinates for hot spot tests.
2661 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2662 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2665 if(gui->current_operation == CWINDOW_CROP)
2667 handle_selected = gui->crop_handle;
2670 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2671 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2673 handle_selected = 0;
2674 gui->crop_origin_x = x1;
2675 gui->crop_origin_y = y1;
2678 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2679 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2681 handle_selected = 1;
2682 gui->crop_origin_x = x2;
2683 gui->crop_origin_y = y1;
2686 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2687 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2689 handle_selected = 2;
2690 gui->crop_origin_x = x1;
2691 gui->crop_origin_y = y2;
2694 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2695 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2697 handle_selected = 3;
2698 gui->crop_origin_x = x2;
2699 gui->crop_origin_y = y2;
2704 gui->crop_origin_x = cursor_x;
2705 gui->crop_origin_y = cursor_y;
2708 // printf("test crop %d %d\n",
2709 // gui->current_operation,
2710 // handle_selected);
2717 gui->crop_translate = 1;
2718 gui->crop_origin_x1 = x1;
2719 gui->crop_origin_y1 = y1;
2720 gui->crop_origin_x2 = x2;
2721 gui->crop_origin_y2 = y2;
2724 gui->crop_translate = 0;
2726 gui->current_operation = CWINDOW_CROP;
2727 gui->crop_handle = handle_selected;
2728 gui->x_origin = cursor_x;
2729 gui->y_origin = cursor_y;
2730 gui->tool_panel->raise_window();
2733 if(handle_selected < 0 && !gui->crop_translate)
2737 mwindow->edl->session->crop_x1 = (int)x1;
2738 mwindow->edl->session->crop_y1 = (int)y1;
2739 mwindow->edl->session->crop_x2 = (int)x2;
2740 mwindow->edl->session->crop_y2 = (int)y2;
2745 // Translate all 4 points
2746 if(gui->current_operation == CWINDOW_CROP && gui->crop_translate)
2748 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2749 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2750 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2751 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2753 mwindow->edl->session->crop_x1 = (int)x1;
2754 mwindow->edl->session->crop_y1 = (int)y1;
2755 mwindow->edl->session->crop_x2 = (int)x2;
2756 mwindow->edl->session->crop_y2 = (int)y2;
2762 if(gui->current_operation == CWINDOW_CROP)
2764 switch(gui->crop_handle)
2767 x1 = gui->crop_origin_x;
2768 y1 = gui->crop_origin_y;
2769 x2 = gui->crop_origin_x;
2770 y2 = gui->crop_origin_y;
2771 if(cursor_x < gui->x_origin)
2773 if(cursor_y < gui->y_origin)
2779 if(cursor_y >= gui->y_origin)
2786 if(cursor_x >= gui->x_origin)
2788 if(cursor_y < gui->y_origin)
2794 if(cursor_y >= gui->y_origin)
2801 // printf("test crop %d %d %d %d\n",
2802 // mwindow->edl->session->crop_x1,
2803 // mwindow->edl->session->crop_y1,
2804 // mwindow->edl->session->crop_x2,
2805 // mwindow->edl->session->crop_y2);
2808 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2809 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2812 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2813 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2816 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2817 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2820 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2821 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2825 if(!EQUIV(mwindow->edl->session->crop_x1, x1) ||
2826 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2827 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2828 !EQUIV(mwindow->edl->session->crop_y2, y2))
2835 switch (gui->crop_handle)
2837 case 0: gui->crop_handle = 1; break;
2838 case 1: gui->crop_handle = 0; break;
2839 case 2: gui->crop_handle = 3; break;
2840 case 3: gui->crop_handle = 2; break;
2850 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)
2872 switch(handle_selected)
2875 set_cursor(UPLEFT_RESIZE);
2878 set_cursor(UPRIGHT_RESIZE);
2881 set_cursor(DOWNLEFT_RESIZE);
2884 set_cursor(DOWNRIGHT_RESIZE);
2891 set_cursor(ARROW_CURSOR);
2893 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2897 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2898 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2899 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2900 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2901 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2902 // mwindow->edl->session->crop_x2,
2903 // mwindow->edl->session->crop_y2,
2904 // mwindow->edl->calculate_output_w(0),
2905 // mwindow->edl->calculate_output_h(0));
2911 void CWindowCanvas::draw_crop()
2913 get_canvas()->set_inverse();
2914 get_canvas()->set_color(WHITE);
2916 float x1 = mwindow->edl->session->crop_x1;
2917 float y1 = mwindow->edl->session->crop_y1;
2918 float x2 = mwindow->edl->session->crop_x2;
2919 float y2 = mwindow->edl->session->crop_y2;
2921 output_to_canvas(mwindow->edl, 0, x1, y1);
2922 output_to_canvas(mwindow->edl, 0, x2, y2);
2924 if(x2 - x1 && y2 - y1)
2925 get_canvas()->draw_rectangle((int)x1,
2930 draw_crophandle((int)x1, (int)y1);
2931 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2932 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2933 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2934 get_canvas()->set_opaque();
2938 void CWindowCanvas::draw_outlines(int do_camera)
2940 Track *track = gui->cwindow->calculate_affected_track();
2944 float proj_x, proj_y, proj_z;
2945 int64_t position = track->to_units(
2946 mwindow->edl->local_session->get_selectionstart(1),
2948 track->automation->get_projector(&proj_x, &proj_y, &proj_z,
2949 position, PLAY_FORWARD);
2951 proj_x += mwindow->edl->session->output_w/2.;
2952 proj_y += mwindow->edl->session->output_h/2.;
2953 float proj_x1 = proj_x - track->track_w/2. * proj_z;
2954 float proj_y1 = proj_y - track->track_h/2. * proj_z;
2955 float proj_x2 = proj_x + track->track_w/2. * proj_z;
2956 float proj_y2 = proj_y + track->track_h/2. * proj_z;
2957 float x1 = proj_x1, x2 = proj_x2;
2958 float y1 = proj_y1, y2 = proj_y2;
2959 output_to_canvas(mwindow->edl, 0, x1, y1);
2960 output_to_canvas(mwindow->edl, 0, x2, y2);
2962 #define DRAW_PROJECTION(offset) \
2963 get_canvas()->draw_rectangle(x1+offset, y1+offset, (x2-x1), (y2-y1)); \
2964 get_canvas()->draw_line(x1+offset, y1+offset, x2+offset, y2+offset); \
2965 get_canvas()->draw_line(x2+offset, y1+offset, x1+offset, y2+offset); \
2968 get_canvas()->set_color(BLACK);
2970 get_canvas()->set_color(do_camera ? GREEN : RED);
2974 float cam_x, cam_y, cam_z;
2975 track->automation->get_camera(&cam_x, &cam_y, &cam_z,
2976 position, PLAY_FORWARD);
2977 cam_x += track->track_w / 2.;
2978 cam_y += track->track_h / 2.;
2979 // follow image, not camera
2980 cam_x = -cam_x; cam_y = -cam_y; cam_z *= proj_z;
2981 float cam_x1 = cam_x * cam_z + proj_x;
2982 float cam_y1 = cam_y * cam_z + proj_y;
2983 float cam_x2 = (cam_x + track->track_w) * cam_z + proj_x;
2984 float cam_y2 = (cam_y + track->track_h) * cam_z + proj_y;
2985 output_to_canvas(mwindow->edl, 0, cam_x1, cam_y1);
2986 output_to_canvas(mwindow->edl, 0, cam_x2, cam_y2);
2987 get_canvas()->set_color(YELLOW);
2988 get_canvas()->draw_rectangle(cam_x1, cam_y1, cam_x2-cam_x1, cam_y2-cam_y1);
2992 int CWindowCanvas::test_bezier(int button_press,
3000 // Processing drag operation.
3001 // Create keyframe during first cursor motion.
3002 if( !button_press ) {
3004 float cursor_x = get_cursor_x();
3005 float cursor_y = get_cursor_y();
3006 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
3008 if( gui->current_operation == CWINDOW_CAMERA ||
3009 gui->current_operation == CWINDOW_PROJECTOR ) {
3010 if( !gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom ) {
3011 gui->translating_zoom = 1;
3012 gui->reset_affected();
3014 else if( !gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom ) {
3015 gui->translating_zoom = 0;
3016 gui->reset_affected();
3019 // Get target keyframe
3020 if( !gui->affected_x && !gui->affected_y && !gui->affected_z ) {
3021 if( !gui->affected_track ) return 0;
3022 FloatAutos *affected_x_autos, *affected_y_autos, *affected_z_autos;
3023 FloatAutos** autos = (FloatAutos**) gui->affected_track->automation->autos;
3024 if( mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA ) {
3025 affected_x_autos = autos[AUTOMATION_CAMERA_X];
3026 affected_y_autos = autos[AUTOMATION_CAMERA_Y];
3027 affected_z_autos = autos[AUTOMATION_CAMERA_Z];
3030 affected_x_autos = autos[AUTOMATION_PROJECTOR_X];
3031 affected_y_autos = autos[AUTOMATION_PROJECTOR_Y];
3032 affected_z_autos = autos[AUTOMATION_PROJECTOR_Z];
3034 double position = mwindow->edl->local_session->get_selectionstart(1);
3035 int64_t track_position = gui->affected_track->to_units(position, 0);
3036 FloatAuto *prev_x = 0, *next_x = 0;
3037 float new_x = affected_x_autos->get_value(track_position, PLAY_FORWARD, prev_x, next_x);
3038 FloatAuto *prev_y = 0, *next_y = 0;
3039 float new_y = affected_y_autos->get_value(track_position, PLAY_FORWARD, prev_y, next_y);
3040 FloatAuto *prev_z = 0, *next_z = 0;
3041 float new_z = affected_z_autos->get_value(track_position, PLAY_FORWARD, prev_z, next_z);
3042 int zooming = gui->translating_zoom, created;
3043 gui->affected_x = (FloatAuto*)gui->cwindow->calculate_affected_auto(
3044 affected_x_autos, !zooming, &created, 0);
3046 gui->affected_x->set_value(new_x);
3049 gui->affected_y = (FloatAuto*)gui->cwindow->calculate_affected_auto(
3050 affected_y_autos, !zooming, &created, 0);
3052 gui->affected_y->set_value(new_y);
3055 gui->affected_z = (FloatAuto*)gui->cwindow->calculate_affected_auto(
3056 affected_z_autos, zooming, &created, 0);
3058 gui->affected_z->set_value(new_z);
3063 if( gui->translating_zoom ) {
3064 gui->center_z = gui->affected_z->get_value();
3067 gui->center_x = gui->affected_x->get_value();
3068 gui->center_y = gui->affected_y->get_value();
3075 float x_val = gui->affected_x->get_value();
3076 float y_val = gui->affected_y->get_value();
3077 float z_val = gui->affected_z->get_value();
3079 if( gui->translating_zoom ) {
3080 float z = gui->center_z + (cursor_y - gui->y_origin) / 128;
3082 if( !EQUIV(z_val, z) ) {
3087 gui->affected_z->set_value(z);
3090 float dx = cursor_x - gui->x_origin;
3091 float dy = cursor_y - gui->y_origin;
3092 // follow image, not camera
3093 if( gui->current_operation == CWINDOW_CAMERA ) {
3094 dx = -dx / z_val; dy = -dy / z_val;
3096 float x = gui->center_x + dx;
3097 float y = gui->center_y + dy;
3098 gui->affected_x->set_value(x);
3099 gui->affected_y->set_value(y);
3100 if( !EQUIV(x_val, x) || !EQUIV(y_val, y) ) {
3111 // Begin drag operation. Don't create keyframe here.
3113 // Get affected track off of the first recordable video track.
3114 // Calculating based on the alpha channel would require recording what layer
3115 // each output pixel belongs to as they're rendered and stacked. Forget it.
3116 gui->affected_track = gui->cwindow->calculate_affected_track();
3117 gui->reset_affected();
3119 if( gui->affected_track ) {
3121 mwindow->undo->update_undo_before(_("camera"), this);
3123 mwindow->undo->update_undo_before(_("projector"), this);
3125 gui->current_operation =
3126 mwindow->edl->session->cwindow_operation;
3127 gui->tool_panel->raise_window();
3136 int CWindowCanvas::test_zoom(int &redraw)
3142 if( mwindow->edl->session->cwindow_scrollbars ) {
3143 if( *gui->zoom_panel->get_text() != 'x' ) {
3144 // Find current zoom in table
3145 int idx = total_zooms; float old_zoom = get_zoom();
3146 while( --idx >= 0 && !EQUIV(my_zoom_table[idx], old_zoom) );
3148 idx += get_buttonpress() == 5 ||
3149 gui->ctrl_down() || gui->shift_down() ? -1 : +1 ;
3150 CLAMP(idx, 0, total_zooms-1);
3151 zoom = my_zoom_table[idx];
3154 x = get_cursor_x(); y = get_cursor_y();
3156 mwindow->edl->session->cwindow_scrollbars = 0;
3157 gui->zoom_panel->update(0);
3158 zoom = gui->get_auto_zoom();
3161 gui->zoom_panel->ZoomPanel::update(zoom);
3162 float output_x = x, output_y = y;
3163 canvas_to_output(mwindow->edl, 0, output_x, output_y);
3164 x = output_x - x / zoom;
3165 y = output_y - y / zoom;
3169 mwindow->edl->session->cwindow_scrollbars = 1;
3170 x = (mwindow->edl->session->output_w - w) / 2;
3171 y = (mwindow->edl->session->output_h - h) / 2;
3174 update_zoom((int)x, (int)y, zoom);
3176 gui->composite_panel->cpanel_zoom->update(zoom);
3178 reposition_window(mwindow->edl,
3179 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
3180 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
3181 redraw = 1; result = 1;
3187 void CWindowCanvas::calculate_origin()
3189 gui->x_origin = get_cursor_x();
3190 gui->y_origin = get_cursor_y();
3191 //printf("CWindowCanvas::calculate_origin 1 %f %f\n", gui->x_origin, gui->y_origin);
3192 canvas_to_output(mwindow->edl, 0, gui->x_origin, gui->y_origin);
3193 //printf("CWindowCanvas::calculate_origin 2 %f %f\n", gui->x_origin, gui->y_origin);
3197 int CWindowCanvas::cursor_leave_event()
3199 set_cursor(ARROW_CURSOR);
3203 int CWindowCanvas::cursor_enter_event()
3206 switch(mwindow->edl->session->cwindow_operation)
3208 case CWINDOW_CAMERA:
3209 case CWINDOW_PROJECTOR:
3210 set_cursor(MOVE_CURSOR);
3213 set_cursor(MOVE_CURSOR);
3216 test_crop(0, redraw);
3218 case CWINDOW_PROTECT:
3219 set_cursor(ARROW_CURSOR);
3223 set_cursor(CROSS_CURSOR);
3225 case CWINDOW_EYEDROP:
3226 set_cursor(CROSS_CURSOR);
3232 int CWindowCanvas::cursor_motion_event()
3234 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3237 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3238 switch(gui->current_operation)
3240 case CWINDOW_SCROLL:
3242 float zoom = get_zoom();
3243 float cursor_x = get_cursor_x();
3244 float cursor_y = get_cursor_y();
3246 float zoom_x, zoom_y, conformed_w, conformed_h;
3247 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3248 cursor_x = (float)cursor_x / zoom_x + gui->x_offset;
3249 cursor_y = (float)cursor_y / zoom_y + gui->y_offset;
3253 int x = (int)(gui->x_origin - cursor_x + gui->x_offset);
3254 int y = (int)(gui->y_origin - cursor_y + gui->y_offset);
3259 update_scrollbars(0);
3266 result = do_ruler(0, 1, 0, 0);
3269 case CWINDOW_CAMERA:
3270 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3273 case CWINDOW_PROJECTOR:
3274 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3279 result = test_crop(0, redraw);
3280 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3287 case CWINDOW_MASK_CONTROL_IN:
3288 case CWINDOW_MASK_CONTROL_OUT:
3289 case CWINDOW_MASK_TRANSLATE:
3290 result = do_mask(redraw, rerender, 0, 1, 0);
3293 case CWINDOW_EYEDROP:
3294 result = do_eyedrop(rerender, 0, 0);
3303 // cursor font changes
3306 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3308 // mwindow->edl->session->cwindow_operation);
3309 switch(mwindow->edl->session->cwindow_operation)
3312 result = test_crop(0, redraw);
3315 result = do_ruler(0, 1, 0, 0);
3318 result = do_mask(redraw, rerender, 0, 1, 0);
3323 int change_type = rerender ? CHANGE_PARAMS : -1;
3324 gui->sync_parameters(change_type, redraw, redraw_canvas);
3329 int CWindowCanvas::button_press_event()
3333 int redraw_canvas = 0;
3336 if(Canvas::button_press_event()) return 1;
3338 gui->translating_zoom = gui->shift_down();
3341 //printf("CWindowCanvas::button_press_event 2 %f %f\n", gui->x_origin, gui->y_origin, gui->x_origin, gui->y_origin);
3343 float zoom_x, zoom_y, conformed_w, conformed_h;
3344 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3345 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3346 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3349 if( mwindow->edl->session->cwindow_operation != CWINDOW_PROTECT &&
3350 get_buttonpress() == MIDDLE_BUTTON && !get_canvas()->shift_down() )
3352 gui->current_operation = CWINDOW_SCROLL;
3358 switch(mwindow->edl->session->cwindow_operation)
3361 result = do_ruler(0, 0, 1, 0);
3364 case CWINDOW_CAMERA:
3365 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3368 case CWINDOW_PROJECTOR:
3369 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3373 result = test_zoom(redraw);
3377 result = test_crop(1, redraw);
3381 switch( get_buttonpress() ) {
3383 result = do_mask(redraw, rerender, 1, 0, 0);
3385 case MIDDLE_BUTTON: { // && shift_down()
3386 result = do_mask_focus();
3387 redraw = redraw_canvas = 1;
3391 result = do_mask(redraw, rerender, 1, 1, 0);
3394 if( result ) redraw_canvas = 1;
3397 case CWINDOW_EYEDROP:
3398 result = do_eyedrop(rerender, 1, 0);
3403 int change_type = rerender ? CHANGE_PARAMS : -1;
3404 gui->sync_parameters(change_type, redraw, redraw_canvas);
3409 int CWindowCanvas::button_release_event()
3412 const char *undo_label = 0;
3414 switch(gui->current_operation)
3416 case CWINDOW_SCROLL:
3421 do_ruler(0, 0, 0, 1);
3424 case CWINDOW_CAMERA:
3425 undo_label = _("camera");
3428 case CWINDOW_PROJECTOR:
3429 undo_label = _("projector");
3433 case CWINDOW_MASK_CONTROL_IN:
3434 case CWINDOW_MASK_CONTROL_OUT:
3435 case CWINDOW_MASK_TRANSLATE:
3436 // Finish mask operation
3437 gui->mask_keyframe = 0;
3438 undo_label = _("mask");
3440 case CWINDOW_MASK_ROTATE:
3441 gui->mask_keyframe = 0;
3442 undo_label = _("mask rotate");
3444 case CWINDOW_MASK_SCALE:
3445 gui->mask_keyframe = 0;
3446 undo_label = _("mask scale");
3449 result = Canvas::button_release_event();
3454 mwindow->undo->update_undo_after(undo_label, LOAD_AUTOMATION);
3455 gui->current_operation = CWINDOW_NONE;
3459 void CWindowCanvas::zoom_resize_window(float percentage)
3461 int canvas_w, canvas_h;
3465 // Get required canvas size
3466 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3467 mwindow->edl->session->output_w,
3468 mwindow->edl->session->output_h,
3473 // Estimate window size from current borders
3474 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3475 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3477 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3478 mwindow->session->cwindow_w = new_w;
3479 mwindow->session->cwindow_h = new_h;
3481 mwindow->theme->get_cwindow_sizes(gui,
3482 mwindow->session->cwindow_controls);
3484 // Estimate again from new borders
3485 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3486 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3487 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3489 gui->resize_window(new_w, new_h);
3490 gui->resize_event(new_w, new_h);
3493 void CWindowCanvas::toggle_controls()
3495 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3496 gui->resize_event(gui->get_w(), gui->get_h());
3499 int CWindowCanvas::get_cwindow_controls()
3501 return mwindow->session->cwindow_controls;