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,
89 BC_WindowBase::get_resources()->bg_color,
90 mwindow->get_cwindow_display())
92 this->mwindow = mwindow;
93 this->cwindow = cwindow;
95 affected_x = affected_y = affected_z = 0;
97 orig_mask_keyframe = new MaskAuto(0, 0);
99 x_offset = y_offset = 0;
100 x_origin = y_origin = 0;
101 current_operation = CWINDOW_NONE;
105 crop_handle = -1; crop_translate = 0;
106 crop_origin_x = crop_origin_y = 0;
107 crop_origin_x1 = crop_origin_y1 = 0;
108 crop_origin_x2 = crop_origin_y2 = 0;
110 eyedrop_x = eyedrop_y = 0;
111 ruler_origin_x = ruler_origin_y = 0;
112 ruler_handle = -1; ruler_translate = 0;
113 center_x = center_y = center_z = 0;
114 control_in_x = control_in_y = 0;
115 control_out_x = control_out_y = 0;
116 translating_zoom = 0;
120 CWindowGUI::~CWindowGUI()
122 if(tool_panel) delete tool_panel;
124 delete composite_panel;
131 delete orig_mask_keyframe;
134 void CWindowGUI::create_objects()
136 lock_window("CWindowGUI::create_objects");
137 set_icon(mwindow->theme->get_image("cwindow_icon"));
139 active = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_active"));
140 inactive = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_inactive"));
142 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
143 mwindow->theme->draw_cwindow_bg(this);
146 // Meters required by composite panel
147 meters = new CWindowMeters(mwindow,
149 mwindow->theme->cmeter_x,
150 mwindow->theme->cmeter_y,
151 mwindow->theme->cmeter_h);
152 meters->create_objects();
155 composite_panel = new CPanel(mwindow,
157 mwindow->theme->ccomposite_x,
158 mwindow->theme->ccomposite_y,
159 mwindow->theme->ccomposite_w,
160 mwindow->theme->ccomposite_h);
161 composite_panel->create_objects();
163 canvas = new CWindowCanvas(mwindow, this);
165 canvas->create_objects(mwindow->edl);
166 canvas->use_cwindow();
169 add_subwindow(timebar = new CTimeBar(mwindow,
171 mwindow->theme->ctimebar_x,
172 mwindow->theme->ctimebar_y,
173 mwindow->theme->ctimebar_w,
174 mwindow->theme->ctimebar_h));
175 timebar->create_objects();
178 add_subwindow(slider = new CWindowSlider(mwindow,
180 mwindow->theme->cslider_x,
181 mwindow->theme->cslider_y,
182 mwindow->theme->cslider_w));
185 transport = new CWindowTransport(mwindow,
187 mwindow->theme->ctransport_x,
188 mwindow->theme->ctransport_y);
189 transport->create_objects();
191 transport->set_slider(slider);
194 edit_panel = new CWindowEditing(mwindow, cwindow);
195 edit_panel->set_meters(meters);
196 edit_panel->create_objects();
198 // add_subwindow(clock = new MainClock(mwindow,
199 // mwindow->theme->ctime_x,
200 // mwindow->theme->ctime_y));
202 zoom_panel = new CWindowZoom(mwindow,
204 mwindow->theme->czoom_x,
205 mwindow->theme->czoom_y,
206 mwindow->theme->czoom_w);
207 zoom_panel->create_objects();
208 zoom_panel->zoom_text->add_item(new BC_MenuItem(auto_zoom = _(AUTO_ZOOM)));
209 if( !mwindow->edl->session->cwindow_scrollbars )
210 zoom_panel->set_text(auto_zoom);
212 // destination = new CWindowDestination(mwindow,
214 // mwindow->theme->cdest_x,
215 // mwindow->theme->cdest_y);
216 // destination->create_objects();
218 // Must create after meter panel
219 tool_panel = new CWindowTool(mwindow, this);
220 tool_panel->Thread::start();
222 set_operation(mwindow->edl->session->cwindow_operation);
227 int CWindowGUI::translation_event()
229 mwindow->session->cwindow_x = get_x();
230 mwindow->session->cwindow_y = get_y();
234 int CWindowGUI::resize_event(int w, int h)
236 mwindow->session->cwindow_x = get_x();
237 mwindow->session->cwindow_y = get_y();
238 mwindow->session->cwindow_w = w;
239 mwindow->session->cwindow_h = h;
241 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
242 mwindow->theme->draw_cwindow_bg(this);
245 composite_panel->reposition_buttons(mwindow->theme->ccomposite_x,
246 mwindow->theme->ccomposite_y, mwindow->theme->ccomposite_h);
248 canvas->reposition_window(mwindow->edl,
249 mwindow->theme->ccanvas_x,
250 mwindow->theme->ccanvas_y,
251 mwindow->theme->ccanvas_w,
252 mwindow->theme->ccanvas_h);
254 timebar->resize_event();
257 slider->reposition_window(mwindow->theme->cslider_x,
258 mwindow->theme->cslider_y,
259 mwindow->theme->cslider_w);
260 // Recalibrate pointer motion range
261 slider->set_position();
264 transport->reposition_buttons(mwindow->theme->ctransport_x,
265 mwindow->theme->ctransport_y);
267 edit_panel->reposition_buttons(mwindow->theme->cedit_x,
268 mwindow->theme->cedit_y);
270 // clock->reposition_window(mwindow->theme->ctime_x,
271 // mwindow->theme->ctime_y);
273 zoom_panel->reposition_window(mwindow->theme->czoom_x,
274 mwindow->theme->czoom_y);
276 // destination->reposition_window(mwindow->theme->cdest_x,
277 // mwindow->theme->cdest_y);
279 meters->reposition_window(mwindow->theme->cmeter_x,
280 mwindow->theme->cmeter_y,
282 mwindow->theme->cmeter_h);
286 BC_WindowBase::resize_event(w, h);
290 int CWindowGUI::button_press_event()
292 if( current_operation == CWINDOW_NONE &&
293 mwindow->edl != 0 && canvas->get_canvas() &&
294 mwindow->edl->session->cwindow_click2play &&
295 canvas->get_canvas()->get_cursor_over_window() ) {
296 switch( get_buttonpress() ) {
298 if( !cwindow->playback_engine->is_playing_back ) {
299 double length = mwindow->edl->tracks->total_playable_length();
300 double position = cwindow->playback_engine->get_tracking_position();
301 if( position >= length ) transport->goto_start();
303 return transport->forward_play->handle_event();
305 if( !cwindow->playback_engine->is_playing_back ) {
306 double position = cwindow->playback_engine->get_tracking_position();
307 if( position <= 0 ) transport->goto_end();
309 return transport->reverse_play->handle_event();
310 case RIGHT_BUTTON: // activates popup
313 return transport->frame_forward_play->handle_event();
315 return transport->frame_reverse_play->handle_event();
318 if(canvas->get_canvas())
319 return canvas->button_press_event_base(canvas->get_canvas());
323 int CWindowGUI::cursor_leave_event()
325 if(canvas->get_canvas())
326 return canvas->cursor_leave_event_base(canvas->get_canvas());
330 int CWindowGUI::cursor_enter_event()
332 if(canvas->get_canvas())
333 return canvas->cursor_enter_event_base(canvas->get_canvas());
337 int CWindowGUI::button_release_event()
339 if(canvas->get_canvas())
340 return canvas->button_release_event();
344 int CWindowGUI::cursor_motion_event()
346 if(canvas->get_canvas())
348 canvas->get_canvas()->unhide_cursor();
349 return canvas->cursor_motion_event();
360 void CWindowGUI::draw_status(int flush)
362 if( (canvas->get_canvas() && canvas->get_canvas()->get_video_on()) ||
363 canvas->is_processing )
366 mwindow->theme->cstatus_x,
367 mwindow->theme->cstatus_y);
371 draw_pixmap(inactive,
372 mwindow->theme->cstatus_x,
373 mwindow->theme->cstatus_y);
377 // printf("CWindowGUI::draw_status %d %d %d\n", __LINE__, mwindow->theme->cstatus_x,
378 // mwindow->theme->cstatus_y);
379 flash(mwindow->theme->cstatus_x,
380 mwindow->theme->cstatus_y,
386 float CWindowGUI::get_auto_zoom()
388 float conformed_w, conformed_h;
389 mwindow->edl->calculate_conformed_dimensions(0, conformed_w, conformed_h);
390 float zoom_x = canvas->w / conformed_w;
391 float zoom_y = canvas->h / conformed_h;
392 return zoom_x < zoom_y ? zoom_x : zoom_y;
395 void CWindowGUI::zoom_canvas(double value, int update_menu)
398 float zoom = !value ? get_auto_zoom() : value;
399 EDL *edl = mwindow->edl;
400 edl->session->cwindow_scrollbars = !value ? 0 : 1;
402 float cx = 0.5f * canvas->w; x = cx;
403 float cy = 0.5f * canvas->h; y = cy;
404 canvas->canvas_to_output(edl, 0, x, y);
405 canvas->update_zoom(0, 0, zoom);
406 float zoom_x, zoom_y, conformed_w, conformed_h;
407 canvas->get_zooms(edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
412 canvas->update_zoom((int)(x+0.5), (int)(y+0.5), zoom);
415 zoom_panel->update(value);
416 if( mwindow->edl->session->cwindow_operation == CWINDOW_ZOOM )
417 composite_panel->cpanel_zoom->update(zoom);
419 canvas->reposition_window(mwindow->edl,
420 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
421 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
422 canvas->draw_refresh();
425 void CWindowGUI::set_operation(int value)
428 case CWINDOW_TOOL_WINDOW:
429 mwindow->edl->session->tool_window = !mwindow->edl->session->tool_window;
430 composite_panel->operation[CWINDOW_TOOL_WINDOW]->update(mwindow->edl->session->tool_window);
431 tool_panel->update_show_window();
433 case CWINDOW_TITLESAFE:
434 mwindow->edl->session->safe_regions = !mwindow->edl->session->safe_regions;
435 composite_panel->operation[CWINDOW_TITLESAFE]->update(mwindow->edl->session->safe_regions);
436 value = mwindow->edl->session->cwindow_operation;
439 mwindow->edl->session->cwindow_operation = value;
440 composite_panel->set_operation(value);
444 edit_panel->update();
445 tool_panel->start_tool(value);
446 canvas->draw_refresh();
449 void CWindowGUI::update_tool()
451 tool_panel->update_values();
454 int CWindowGUI::close_event()
456 cwindow->hide_window();
461 int CWindowGUI::keypress_event()
464 int cwindow_operation = CWINDOW_NONE;
466 switch( get_keypress() ) {
483 if(mwindow->session->cwindow_fullscreen)
484 canvas->stop_fullscreen();
486 canvas->start_fullscreen();
487 lock_window("CWindowGUI::keypress_event 1");
491 if( ctrl_down() || shift_down() || alt_down() ) break;
493 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
495 mwindow->gui->unlock_window();
496 lock_window("CWindowGUI::keypress_event 2");
501 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
502 mwindow->clear_entry();
503 mwindow->gui->unlock_window();
504 lock_window("CWindowGUI::keypress_event 3");
509 if(mwindow->session->cwindow_fullscreen)
510 canvas->stop_fullscreen();
511 lock_window("CWindowGUI::keypress_event 4");
516 int alt_down = this->alt_down();
517 int shift_down = this->shift_down();
520 mwindow->gui->lock_window("CWindowGUI::keypress_event 5");
522 mwindow->prev_edit_handle(shift_down);
524 mwindow->move_left();
525 mwindow->gui->unlock_window();
526 lock_window("CWindowGUI::keypress_event 6");
532 if( !ctrl_down() && !alt_down() ) {
535 mwindow->gui->lock_window("CWindowGUI::keypress_event 7");
536 mwindow->move_left();
537 mwindow->gui->unlock_window();
538 lock_window("CWindowGUI::keypress_event 8");
545 int alt_down = this->alt_down();
546 int shift_down = this->shift_down();
549 mwindow->gui->lock_window("CWindowGUI::keypress_event 8");
551 mwindow->next_edit_handle(shift_down);
553 mwindow->move_right();
554 mwindow->gui->unlock_window();
555 lock_window("CWindowGUI::keypress_event 9");
561 if( !ctrl_down() && !alt_down() ) {
564 mwindow->gui->lock_window("CWindowGUI::keypress_event 10");
565 mwindow->move_right();
566 mwindow->gui->unlock_window();
567 lock_window("CWindowGUI::keypress_event 11");
573 if( !result && cwindow_operation < 0 && ctrl_down() && shift_down() ) {
574 switch( get_keypress() ) {
579 resend_event(mwindow->gui);
584 if( !result && !ctrl_down() ) {
585 switch( get_keypress() ) {
588 mwindow->toggle_camera_xyz(); result = 1;
591 cwindow_operation = CWINDOW_PROTECT;
595 mwindow->toggle_projector_xyz(); result = 1;
598 cwindow_operation = CWINDOW_ZOOM;
602 if( !result && cwindow_operation < 0 && !ctrl_down() && !shift_down() ) {
603 switch( get_keypress() ) {
604 case KEY_F3: cwindow_operation = CWINDOW_MASK; break;
605 case KEY_F4: cwindow_operation = CWINDOW_RULER; break;
606 case KEY_F5: cwindow_operation = CWINDOW_CAMERA; break;
607 case KEY_F6: cwindow_operation = CWINDOW_PROJECTOR; break;
608 case KEY_F7: cwindow_operation = CWINDOW_CROP; break;
609 case KEY_F8: cwindow_operation = CWINDOW_EYEDROP; break;
610 case KEY_F9: cwindow_operation = CWINDOW_TOOL_WINDOW; break;
611 case KEY_F10: cwindow_operation = CWINDOW_TITLESAFE; break;
612 case KEY_F11: canvas->reset_camera(); result = 1; break;
613 case KEY_F12: canvas->reset_projector(); result = 1; break;
617 if( cwindow_operation >= 0 ) {
618 set_operation(cwindow_operation);
623 result = transport->keypress_event();
629 void CWindowGUI::reset_affected()
636 void CWindowGUI::keyboard_zoomin()
638 // if(mwindow->edl->session->cwindow_scrollbars)
640 zoom_panel->zoom_tumbler->handle_up_event();
647 void CWindowGUI::keyboard_zoomout()
649 // if(mwindow->edl->session->cwindow_scrollbars)
651 zoom_panel->zoom_tumbler->handle_down_event();
659 void CWindowGUI::drag_motion()
661 if(get_hidden()) return;
663 if(mwindow->session->current_operation != DRAG_ASSET &&
664 mwindow->session->current_operation != DRAG_VTRANSITION &&
665 mwindow->session->current_operation != DRAG_VEFFECT) return;
666 int need_highlight = cursor_above() && get_cursor_over_window();
667 if( highlighted == need_highlight ) return;
668 highlighted = need_highlight;
669 canvas->draw_refresh();
672 int CWindowGUI::drag_stop()
675 if(get_hidden()) return 0;
676 if( !highlighted ) return 0;
677 if( mwindow->session->current_operation != DRAG_ASSET &&
678 mwindow->session->current_operation != DRAG_VTRANSITION &&
679 mwindow->session->current_operation != DRAG_VEFFECT) return 0;
681 canvas->draw_refresh();
684 if(mwindow->session->current_operation == DRAG_ASSET)
686 if(mwindow->session->drag_assets->total ||
687 mwindow->session->drag_clips->total)
689 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
690 mwindow->undo->update_undo_before(_("insert assets"), 0);
693 if(mwindow->session->drag_assets->total)
696 mwindow->load_assets(mwindow->session->drag_assets,
697 mwindow->edl->local_session->get_selectionstart(),
699 mwindow->session->track_highlighted,
701 mwindow->edl->session->labels_follow_edits,
702 mwindow->edl->session->plugins_follow_edits,
703 mwindow->edl->session->autos_follow_edits,
707 if(mwindow->session->drag_clips->total)
710 mwindow->paste_edls(mwindow->session->drag_clips,
712 mwindow->session->track_highlighted,
713 mwindow->edl->local_session->get_selectionstart(),
714 mwindow->edl->session->labels_follow_edits,
715 mwindow->edl->session->plugins_follow_edits,
716 mwindow->edl->session->autos_follow_edits,
720 if(mwindow->session->drag_assets->total ||
721 mwindow->session->drag_clips->total)
723 mwindow->save_backup();
724 mwindow->restart_brender();
725 mwindow->gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
726 mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
727 mwindow->gui->unlock_window();
728 mwindow->sync_parameters(CHANGE_ALL);
732 if(mwindow->session->current_operation == DRAG_VEFFECT)
734 //printf("CWindowGUI::drag_stop 1\n");
735 Track *affected_track = cwindow->calculate_affected_track();
736 //printf("CWindowGUI::drag_stop 2\n");
738 mwindow->gui->lock_window("CWindowGUI::drag_stop 3");
739 mwindow->insert_effects_cwindow(affected_track);
740 mwindow->session->current_operation = NO_OPERATION;
741 mwindow->gui->unlock_window();
744 if(mwindow->session->current_operation == DRAG_VTRANSITION)
746 Track *affected_track = cwindow->calculate_affected_track();
747 mwindow->gui->lock_window("CWindowGUI::drag_stop 4");
748 mwindow->paste_transition_cwindow(affected_track);
749 mwindow->session->current_operation = NO_OPERATION;
750 mwindow->gui->unlock_window();
756 void CWindowGUI::update_meters()
758 if(mwindow->edl->session->cwindow_meter != meters->visible)
760 meters->set_meters(meters->meter_count, mwindow->edl->session->cwindow_meter);
761 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
762 resize_event(get_w(), get_h());
766 void CWindowGUI::stop_transport(const char *lock_msg)
768 if( lock_msg ) unlock_window();
769 mwindow->stop_transport();
770 if( lock_msg ) lock_window(lock_msg);
774 CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
775 : EditPanel(mwindow, cwindow->gui, CWINDOW_ID,
776 mwindow->theme->cedit_x, mwindow->theme->cedit_y,
777 mwindow->edl->session->editing_mode,
778 0, // use_editing_mode
797 this->mwindow = mwindow;
798 this->cwindow = cwindow;
801 #define CWrapper(fn) void CWindowEditing::fn() { \
802 mwindow->gui->lock_window("CWrapper::" #fn); \
804 mwindow->gui->unlock_window(); \
807 CWrapper(copy_selection)
808 CWrapper(splice_selection)
809 CWrapper(overwrite_selection)
810 CWrapper(set_inpoint)
811 CWrapper(set_outpoint)
812 CWrapper(unset_inoutpoint)
813 CWrapper(toggle_label)
815 #define CWrapper_cut(fn) void CWindowEditing::fn(int cut) { \
816 mwindow->gui->lock_window("CWrapper::" #fn); \
817 EditPanel::fn(cut); \
818 mwindow->gui->unlock_window(); \
820 CWrapper_cut(prev_label)
821 CWrapper_cut(next_label)
822 CWrapper_cut(prev_edit)
823 CWrapper_cut(next_edit)
825 void CWindowEditing::to_clip()
827 mwindow->to_clip(mwindow->edl, _("composer window: "), 0);
831 CWindowMeters::CWindowMeters(MWindow *mwindow,
836 : MeterPanel(mwindow,
842 mwindow->edl->session->audio_channels,
843 mwindow->edl->session->cwindow_meter,
847 this->mwindow = mwindow;
851 CWindowMeters::~CWindowMeters()
855 int CWindowMeters::change_status_event(int new_status)
857 mwindow->edl->session->cwindow_meter = new_status;
858 gui->update_meters();
865 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
866 : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
867 x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
869 this->mwindow = mwindow;
873 CWindowZoom::~CWindowZoom()
877 void CWindowZoom::update(double value)
879 char string[BCSTRLEN];
880 const char *cp = string;
883 int frac = value >= 1.0f ? 1 :
885 value >= .01f ? 3 : 4;
886 sprintf(string, "x %.*f", frac, value);
890 ZoomPanel::update(cp);
893 int CWindowZoom::handle_event()
895 double value = !strcasecmp(gui->auto_zoom, get_text()) ? 0 : get_value();
896 gui->zoom_canvas(value, 0);
903 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
904 : BC_PercentageSlider(x,
913 this->mwindow = mwindow;
914 this->cwindow = cwindow;
915 set_precision(0.00001);
918 CWindowSlider::~CWindowSlider()
922 int CWindowSlider::handle_event()
924 cwindow->update_position((double)get_value());
928 void CWindowSlider::set_position()
930 double new_length = mwindow->edl->tracks->total_length();
931 update(mwindow->theme->cslider_w,
932 mwindow->edl->local_session->get_selectionstart(1),
937 int CWindowSlider::increase_value()
940 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
941 lock_window("CWindowSlider::increase_value");
945 int CWindowSlider::decrease_value()
948 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
949 lock_window("CWindowSlider::decrease_value");
954 // CWindowDestination::CWindowDestination(MWindow *mwindow, CWindowGUI *cwindow, int x, int y)
955 // : BC_PopupTextBox(cwindow,
956 // &cwindow->destinations,
957 // cwindow->destinations.values[cwindow->cwindow->destination]->get_text(),
963 // this->mwindow = mwindow;
964 // this->cwindow = cwindow;
967 // CWindowDestination::~CWindowDestination()
971 // int CWindowDestination::handle_event()
982 CWindowTransport::CWindowTransport(MWindow *mwindow,
986 : PlayTransport(mwindow,
994 EDL* CWindowTransport::get_edl()
999 void CWindowTransport::goto_start()
1001 gui->unlock_window();
1002 handle_transport(REWIND, 1);
1004 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
1005 mwindow->goto_start();
1006 mwindow->gui->unlock_window();
1008 gui->lock_window("CWindowTransport::goto_start 2");
1011 void CWindowTransport::goto_end()
1013 gui->unlock_window();
1014 handle_transport(GOTO_END, 1);
1016 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
1017 mwindow->goto_end();
1018 mwindow->gui->unlock_window();
1020 gui->lock_window("CWindowTransport::goto_end 2");
1025 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
1028 mwindow->theme->ccanvas_x,
1029 mwindow->theme->ccanvas_y,
1030 mwindow->theme->ccanvas_w,
1031 mwindow->theme->ccanvas_h,
1034 mwindow->edl->session->cwindow_scrollbars)
1036 this->mwindow = mwindow;
1040 void CWindowCanvas::status_event()
1042 gui->draw_status(1);
1045 int CWindowCanvas::get_fullscreen()
1047 return mwindow->session->cwindow_fullscreen;
1050 void CWindowCanvas::set_fullscreen(int value)
1052 mwindow->session->cwindow_fullscreen = value;
1056 void CWindowCanvas::update_zoom(int x, int y, float zoom)
1058 use_scrollbars = mwindow->edl->session->cwindow_scrollbars;
1060 mwindow->edl->session->cwindow_xscroll = x;
1061 mwindow->edl->session->cwindow_yscroll = y;
1062 mwindow->edl->session->cwindow_zoom = zoom;
1065 void CWindowCanvas::zoom_auto()
1067 gui->zoom_canvas(0, 1);
1070 int CWindowCanvas::get_xscroll()
1072 return mwindow->edl->session->cwindow_xscroll;
1075 int CWindowCanvas::get_yscroll()
1077 return mwindow->edl->session->cwindow_yscroll;
1081 float CWindowCanvas::get_zoom()
1083 return mwindow->edl->session->cwindow_zoom;
1086 void CWindowCanvas::draw_refresh(int flush)
1088 if(get_canvas() && !get_canvas()->get_video_on())
1091 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,
1105 if(!EQUIV(out_x1, 0) ||
1106 !EQUIV(out_y1, 0) ||
1107 !EQUIV(out_x2, get_canvas()->get_w()) ||
1108 !EQUIV(out_y2, get_canvas()->get_h()))
1110 get_canvas()->clear_box(0,
1112 get_canvas()->get_w(),
1113 get_canvas()->get_h());
1116 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1117 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1120 if(out_x2 > out_x1 &&
1125 // input scaled from session to refresh frame coordinates
1126 int ow = get_output_w(mwindow->edl);
1127 int oh = get_output_h(mwindow->edl);
1128 int rw = refresh_frame->get_w();
1129 int rh = refresh_frame->get_h();
1130 float xs = (float)rw / ow;
1131 float ys = (float)rh / oh;
1132 in_x1 *= xs; in_x2 *= xs;
1133 in_y1 *= ys; in_y2 *= ys;
1134 // Can't use OpenGL here because it is called asynchronously of the
1135 // playback operation.
1136 get_canvas()->draw_vframe(refresh_frame,
1139 (int)(out_x2 - out_x1),
1140 (int)(out_y2 - out_y1),
1143 (int)(in_x2 - in_x1),
1144 (int)(in_y2 - in_y1),
1150 get_canvas()->clear_box(0,
1152 get_canvas()->get_w(),
1153 get_canvas()->get_h());
1157 // allow last opengl write to complete before redraw
1158 // tried sync_display, glFlush, glxMake*Current(0..)
1160 get_canvas()->flash(flush);
1162 //printf("CWindowCanvas::draw_refresh 10\n");
1165 #define CROPHANDLE_W 10
1166 #define CROPHANDLE_H 10
1168 void CWindowCanvas::draw_crophandle(int x, int y)
1170 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1178 #define CONTROL_W 10
1179 #define CONTROL_H 10
1180 #define FIRST_CONTROL_W 20
1181 #define FIRST_CONTROL_H 20
1183 #define BC_INFINITY 65536
1185 #define RULERHANDLE_W 16
1186 #define RULERHANDLE_H 16
1190 int CWindowCanvas::do_ruler(int draw,
1196 float x1 = mwindow->edl->session->ruler_x1;
1197 float y1 = mwindow->edl->session->ruler_y1;
1198 float x2 = mwindow->edl->session->ruler_x2;
1199 float y2 = mwindow->edl->session->ruler_y2;
1200 float canvas_x1 = x1;
1201 float canvas_y1 = y1;
1202 float canvas_x2 = x2;
1203 float canvas_y2 = y2;
1204 float output_x = get_cursor_x();
1205 float output_y = get_cursor_y();
1206 float canvas_cursor_x = output_x;
1207 float canvas_cursor_y = output_y;
1209 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1210 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1211 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1212 mwindow->session->cwindow_output_x = roundf(output_x);
1213 mwindow->session->cwindow_output_y = roundf(output_y);
1215 if(button_press && get_buttonpress() == 1)
1217 gui->ruler_handle = -1;
1218 gui->ruler_translate = 0;
1221 gui->ruler_translate = 1;
1222 gui->ruler_origin_x = x1;
1223 gui->ruler_origin_y = y1;
1226 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1227 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1228 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1229 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1231 gui->ruler_handle = 0;
1232 gui->ruler_origin_x = x1;
1233 gui->ruler_origin_y = y1;
1236 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1237 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1238 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1239 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1241 gui->ruler_handle = 1;
1242 gui->ruler_origin_x = x2;
1243 gui->ruler_origin_y = y2;
1247 // Start new selection
1248 if(!gui->ruler_translate &&
1249 (gui->ruler_handle < 0 ||
1254 do_ruler(1, 0, 0, 0);
1255 get_canvas()->flash();
1256 gui->ruler_handle = 1;
1257 mwindow->edl->session->ruler_x1 = output_x;
1258 mwindow->edl->session->ruler_y1 = output_y;
1259 mwindow->edl->session->ruler_x2 = output_x;
1260 mwindow->edl->session->ruler_y2 = output_y;
1261 gui->ruler_origin_x = mwindow->edl->session->ruler_x2;
1262 gui->ruler_origin_y = mwindow->edl->session->ruler_y2;
1265 gui->x_origin = output_x;
1266 gui->y_origin = output_y;
1267 gui->current_operation = CWINDOW_RULER;
1268 gui->tool_panel->raise_window();
1274 if(gui->current_operation == CWINDOW_RULER)
1276 if(gui->ruler_translate)
1279 do_ruler(1, 0, 0, 0);
1280 float x_difference = mwindow->edl->session->ruler_x1;
1281 float y_difference = mwindow->edl->session->ruler_y1;
1282 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1283 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1284 x_difference -= mwindow->edl->session->ruler_x1;
1285 y_difference -= mwindow->edl->session->ruler_y1;
1286 mwindow->edl->session->ruler_x2 -= x_difference;
1287 mwindow->edl->session->ruler_y2 -= y_difference;
1289 do_ruler(1, 0, 0, 0);
1290 get_canvas()->flash();
1294 switch(gui->ruler_handle)
1297 do_ruler(1, 0, 0, 0);
1298 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1299 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1300 if(gui->alt_down() || gui->ctrl_down())
1302 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1303 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1307 double distance_value =
1308 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1309 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1310 if(angle_value < 22)
1311 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2;
1313 if(angle_value > 67)
1314 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2;
1316 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 &&
1317 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1319 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1320 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1323 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 && mwindow->edl->session->ruler_y1 > mwindow->edl->session->ruler_y2)
1325 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1326 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1329 if(mwindow->edl->session->ruler_x1 > mwindow->edl->session->ruler_x2 &&
1330 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1332 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1333 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1337 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1338 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1341 do_ruler(1, 0, 0, 0);
1342 get_canvas()->flash();
1347 do_ruler(1, 0, 0, 0);
1348 mwindow->edl->session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1349 mwindow->edl->session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1350 if(gui->alt_down() || gui->ctrl_down())
1352 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1353 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1357 double distance_value =
1358 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1359 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1360 if(angle_value < 22)
1361 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1;
1363 if(angle_value > 67)
1364 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1;
1366 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1367 mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1369 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1370 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1373 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1374 mwindow->edl->session->ruler_y2 > mwindow->edl->session->ruler_y1)
1376 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1377 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1380 if(mwindow->edl->session->ruler_x2 > mwindow->edl->session->ruler_x1 && mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1382 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1383 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1387 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1388 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1391 do_ruler(1, 0, 0, 0);
1392 get_canvas()->flash();
1396 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1400 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1405 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1406 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1407 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1408 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1410 set_cursor(UPRIGHT_ARROW_CURSOR);
1413 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1414 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1415 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1416 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1418 set_cursor(UPRIGHT_ARROW_CURSOR);
1421 set_cursor(CROSS_CURSOR);
1423 // Update current position
1428 // Assume no ruler measurement if 0 length
1429 if(draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)))
1431 get_canvas()->set_inverse();
1432 get_canvas()->set_color(WHITE);
1433 get_canvas()->draw_line((int)canvas_x1,
1437 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1439 roundf(canvas_x1) + RULERHANDLE_W / 2,
1441 get_canvas()->draw_line(roundf(canvas_x1),
1442 roundf(canvas_y1) - RULERHANDLE_H / 2,
1444 roundf(canvas_y1) + RULERHANDLE_H / 2);
1445 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1447 roundf(canvas_x2) + RULERHANDLE_W / 2,
1449 get_canvas()->draw_line(roundf(canvas_x2),
1450 roundf(canvas_y2) - RULERHANDLE_H / 2,
1452 roundf(canvas_y2) + RULERHANDLE_H / 2);
1453 get_canvas()->set_opaque();
1460 static inline double line_dist(float cx,float cy, float tx,float ty)
1462 double dx = tx-cx, dy = ty-cy;
1463 return sqrt(dx*dx + dy*dy);
1466 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1468 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1469 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1473 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1474 int button_press, int cursor_motion, int draw)
1476 // Retrieve points from top recordable track
1477 //printf("CWindowCanvas::do_mask 1\n");
1478 Track *track = gui->cwindow->calculate_affected_track();
1479 //printf("CWindowCanvas::do_mask 2\n");
1481 if(!track) return 0;
1482 //printf("CWindowCanvas::do_mask 3\n");
1484 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1485 int64_t position = track->to_units(
1486 mwindow->edl->local_session->get_selectionstart(1),
1488 ArrayList<MaskPoint*> points;
1490 // Determine the points based on whether
1491 // new keyframes will be generated or drawing is performed.
1492 // If keyframe generation occurs, use the interpolated mask.
1493 // If no keyframe generation occurs, use the previous mask.
1494 int use_interpolated = 0;
1495 if(button_press || cursor_motion) {
1496 #ifdef USE_KEYFRAME_SPANNING
1497 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1498 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1501 mask_autos->get_prev_auto(track->to_units(selection_start, 0),
1502 PLAY_FORWARD, first, 1);
1504 mask_autos->get_prev_auto(track->to_units(selection_end, 0),
1505 PLAY_FORWARD, last, 1);
1507 if(last == first && (!mwindow->edl->session->auto_keyframes))
1508 use_interpolated = 0;
1510 // If keyframe spanning occurs, use the interpolated points.
1511 // If new keyframe is generated, use the interpolated points.
1512 use_interpolated = 1;
1515 if(mwindow->edl->session->auto_keyframes)
1516 use_interpolated = 1;
1520 use_interpolated = 1;
1522 if(use_interpolated) {
1523 // Interpolate the points to get exactly what is being rendered at this position.
1524 mask_autos->get_points(&points,
1525 mwindow->edl->session->cwindow_mask,
1530 // Use the prev mask
1532 mask_autos->get_prev_auto(position,
1536 ((MaskAuto*)prev)->get_points(&points,
1537 mwindow->edl->session->cwindow_mask);
1540 // Projector zooms relative to the center of the track output.
1541 float half_track_w = (float)track->track_w / 2;
1542 float half_track_h = (float)track->track_h / 2;
1543 // Translate mask to projection
1544 float projector_x, projector_y, projector_z;
1545 track->automation->get_projector(
1546 &projector_x, &projector_y, &projector_z,
1547 position, PLAY_FORWARD);
1550 // Get position of cursor relative to mask
1551 float cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
1552 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1553 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1555 projector_x += mwindow->edl->session->output_w / 2;
1556 projector_y += mwindow->edl->session->output_h / 2;
1557 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1558 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1560 // Fix cursor origin
1562 gui->x_origin = mask_cursor_x;
1563 gui->y_origin = mask_cursor_y;
1567 // Points of closest line
1568 int shortest_point1 = -1;
1569 int shortest_point2 = -1;
1571 int shortest_point = -1;
1572 // Distance to closest line
1573 float shortest_line_distance = BC_INFINITY;
1574 // Distance to closest point
1575 float shortest_point_distance = BC_INFINITY;
1576 int selected_point = -1;
1577 int selected_control_point = -1;
1578 float selected_control_point_distance = BC_INFINITY;
1579 ArrayList<int> x_points;
1580 ArrayList<int> y_points;
1582 if(!cursor_motion) {
1584 get_canvas()->set_color(WHITE);
1585 get_canvas()->set_inverse();
1587 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1589 // Never draw closed polygon and a closed
1590 // polygon is harder to add points to.
1591 for(int i = 0; i < points.size() && !result; i++) {
1592 MaskPoint *point1 = points.get(i);
1593 MaskPoint *point2 = (i >= points.size() - 1) ?
1594 points.get(0) : points.get(i + 1);
1596 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1597 if(point_distance1 < shortest_point_distance || shortest_point < 0) {
1598 shortest_point_distance = point_distance1;
1602 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1603 if(point_distance2 < shortest_point_distance || shortest_point < 0) {
1604 shortest_point_distance = point_distance2;
1605 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1609 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1611 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1612 //point1->x, point1->y, point2->x, point2->y, projector_z);
1613 for(int j = 0; j <= segments && !result; j++) {
1614 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1615 float x0 = point1->x, y0 = point1->y;
1616 float x1 = point1->x + point1->control_x2;
1617 float y1 = point1->y + point1->control_y2;
1618 float x2 = point2->x + point2->control_x1;
1619 float y2 = point2->y + point2->control_y1;
1620 float x3 = point2->x, y3 = point2->y;
1621 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1622 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1623 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1624 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1625 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1626 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1627 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1628 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1630 float t = (float)j / segments;
1631 float tpow2 = t * t;
1632 float tpow3 = t * t * t;
1634 float invtpow2 = invt * invt;
1635 float invtpow3 = invt * invt * invt;
1637 float x = ( invtpow3 * x0
1638 + 3 * t * invtpow2 * x1
1639 + 3 * tpow2 * invt * x2
1641 float y = ( invtpow3 * y0
1642 + 3 * t * invtpow2 * y1
1643 + 3 * tpow2 * invt * y2
1645 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1646 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1647 // Test new point addition
1649 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1651 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1652 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1653 if(line_distance < shortest_line_distance ||
1654 shortest_point1 < 0) {
1655 shortest_line_distance = line_distance;
1656 shortest_point1 = i;
1657 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1658 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1659 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1662 // Test existing point selection
1664 if(gui->ctrl_down()) {
1665 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1667 if(distance < selected_control_point_distance) {
1669 selected_control_point = 1;
1670 selected_control_point_distance = distance;
1674 if(!gui->shift_down()) {
1675 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1676 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
1681 selected_point = shortest_point;
1684 // Test second point
1685 if(gui->ctrl_down()) {
1686 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1688 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1689 if(distance < selected_control_point_distance) {
1690 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1691 selected_control_point = 0;
1692 selected_control_point_distance = distance;
1695 else if(i < points.size() - 1) {
1696 if(!gui->shift_down()) {
1697 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1698 if(test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3)) {
1699 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1703 selected_point = shortest_point;
1708 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1712 if(draw) { // Draw joining line
1713 x_points.append((int)canvas_x);
1714 y_points.append((int)canvas_y);
1718 if(draw) { // Draw second anchor
1719 if(i < points.size() - 1) {
1720 if(i == gui->affected_point - 1)
1721 get_canvas()->draw_disc(
1722 (int)canvas_x - CONTROL_W / 2,
1723 (int)canvas_y - CONTROL_W / 2,
1724 CONTROL_W, CONTROL_H);
1726 get_canvas()->draw_circle(
1727 (int)canvas_x - CONTROL_W / 2,
1728 (int)canvas_y - CONTROL_W / 2,
1729 CONTROL_W, CONTROL_H);
1730 // char string[BCTEXTLEN];
1731 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1732 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1734 // Draw second control point.
1735 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1736 get_canvas()->draw_line(
1737 (int)canvas_x, (int)canvas_y,
1738 (int)canvas_x2, (int)canvas_y2);
1739 get_canvas()->draw_rectangle(
1740 (int)canvas_x2 - CONTROL_W / 2,
1741 (int)canvas_y2 - CONTROL_H / 2,
1742 CONTROL_W, CONTROL_H);
1747 // Draw first anchor
1748 if(i == 0 && draw) {
1749 char mask_label[BCSTRLEN];
1750 sprintf(mask_label, "%d",
1751 mwindow->edl->session->cwindow_mask);
1752 get_canvas()->draw_text(
1753 (int)canvas_x - FIRST_CONTROL_W,
1754 (int)canvas_y - FIRST_CONTROL_H,
1757 get_canvas()->draw_disc(
1758 (int)canvas_x - FIRST_CONTROL_W / 2,
1759 (int)canvas_y - FIRST_CONTROL_H / 2,
1760 FIRST_CONTROL_W, FIRST_CONTROL_H);
1763 // Draw first control point.
1765 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1766 get_canvas()->draw_line(
1767 (int)canvas_x, (int)canvas_y,
1768 (int)canvas_x1, (int)canvas_y1);
1769 get_canvas()->draw_rectangle(
1770 (int)canvas_x1 - CONTROL_W / 2,
1771 (int)canvas_y1 - CONTROL_H / 2,
1772 CONTROL_W, CONTROL_H);
1774 x_points.append((int)canvas_x);
1775 y_points.append((int)canvas_y);
1778 //printf("CWindowCanvas::do_mask 1\n");
1782 //printf("CWindowCanvas::do_mask 1\n");
1785 get_canvas()->draw_polygon(&x_points, &y_points);
1786 get_canvas()->set_opaque();
1788 //printf("CWindowCanvas::do_mask 1\n");
1791 if(button_press && !result) {
1792 gui->affected_track = gui->cwindow->calculate_affected_track();
1794 // Get keyframe outside the EDL to edit. This must be rendered
1795 // instead of the EDL keyframes when it exists. Then it must be
1796 // applied to the EDL keyframes on buttonrelease.
1797 if(gui->affected_track) {
1798 #ifdef USE_KEYFRAME_SPANNING
1799 // Make copy of current parameters in local keyframe
1800 gui->mask_keyframe =
1801 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1804 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1807 gui->mask_keyframe =
1808 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1813 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1816 // Translate entire keyframe
1817 if(gui->alt_down() && mask->points.size()) {
1818 mwindow->undo->update_undo_before(_("mask translate"), 0);
1819 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1820 gui->affected_point = 0;
1823 // Existing point or control point was selected
1824 if(selected_point >= 0) {
1825 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1826 gui->affected_point = selected_point;
1828 if(selected_control_point == 0)
1829 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1831 if(selected_control_point == 1)
1832 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1834 gui->current_operation = mwindow->edl->session->cwindow_operation;
1836 else // No existing point or control point was selected so create a new one
1837 if(!gui->ctrl_down() && !gui->alt_down()) {
1838 mwindow->undo->update_undo_before(_("mask point"), 0);
1839 // Create the template
1840 MaskPoint *point = new MaskPoint;
1841 point->x = mask_cursor_x;
1842 point->y = mask_cursor_y;
1843 point->control_x1 = 0;
1844 point->control_y1 = 0;
1845 point->control_x2 = 0;
1846 point->control_y2 = 0;
1849 if(shortest_point2 < shortest_point1) {
1850 shortest_point2 ^= shortest_point1;
1851 shortest_point1 ^= shortest_point2;
1852 shortest_point2 ^= shortest_point1;
1857 // printf("CWindowGUI::do_mask 40\n");
1858 // mwindow->edl->dump();
1859 // printf("CWindowGUI::do_mask 50\n");
1863 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1864 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1865 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1867 // Append to end of list
1868 if( shortest_point1 == shortest_point2 ||
1869 labs(shortest_point1 - shortest_point2) > 1) {
1870 #ifdef USE_KEYFRAME_SPANNING
1872 MaskPoint *new_point = new MaskPoint;
1873 points.append(new_point);
1874 *new_point = *point;
1875 gui->affected_point = points.size() - 1;
1879 // Need to apply the new point to every keyframe
1880 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1881 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1882 MaskPoint *new_point = new MaskPoint;
1883 submask->points.append(new_point);
1884 *new_point = *point;
1885 if(current == (MaskAuto*)mask_autos->default_auto)
1886 current = (MaskAuto*)mask_autos->first;
1888 current = (MaskAuto*)NEXT;
1890 gui->affected_point = mask->points.size() - 1;
1896 // Insert between 2 points, shifting back point 2
1897 if(shortest_point1 >= 0 && shortest_point2 >= 0) {
1899 #ifdef USE_KEYFRAME_SPANNING
1900 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1902 if(points.size() >= shortest_point2) {
1903 MaskPoint *new_point = new MaskPoint;
1905 for(int i = points.size() - 1;
1906 i > shortest_point2;
1908 points.values[i] = points.values[i - 1];
1909 points.values[shortest_point2] = new_point;
1911 *new_point = *point;
1916 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1917 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1918 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1920 if(submask->points.size() >= shortest_point2) {
1921 MaskPoint *new_point = new MaskPoint;
1922 submask->points.append(0);
1923 for(int i = submask->points.size() - 1;
1924 i > shortest_point2;
1926 submask->points.values[i] = submask->points.values[i - 1];
1927 submask->points.values[shortest_point2] = new_point;
1929 *new_point = *point;
1932 if(current == (MaskAuto*)mask_autos->default_auto)
1933 current = (MaskAuto*)mask_autos->first;
1935 current = (MaskAuto*)NEXT;
1939 gui->affected_point = shortest_point2;
1944 // printf("CWindowGUI::do_mask 20\n");
1945 // mwindow->edl->dump();
1946 // printf("CWindowGUI::do_mask 30\n");
1949 //printf("CWindowCanvas::do_mask 1\n");
1950 // Create the first point.
1951 #ifdef USE_KEYFRAME_SPANNING
1952 MaskPoint *new_point = new MaskPoint;
1953 points.append(new_point);
1954 *new_point = *point;
1955 gui->affected_point = points.size() - 1;
1957 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1958 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1959 MaskPoint *new_point = new MaskPoint;
1960 submask->points.append(new_point);
1961 *new_point = *point;
1962 if(current == (MaskAuto*)mask_autos->default_auto)
1963 current = (MaskAuto*)mask_autos->first;
1965 current = (MaskAuto*)NEXT;
1967 gui->affected_point = points.size() - 1;
1970 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
1973 gui->current_operation = mwindow->edl->session->cwindow_operation;
1974 // Delete the template
1983 if(button_press && result) {
1984 #ifdef USE_KEYFRAME_SPANNING
1985 MaskPoint *point = points.values[gui->affected_point];
1986 gui->center_x = point->x;
1987 gui->center_y = point->y;
1988 gui->control_in_x = point->control_x1;
1989 gui->control_in_y = point->control_y1;
1990 gui->control_out_x = point->control_x2;
1991 gui->control_out_y = point->control_y2;
1992 gui->tool_panel->raise_window();
1994 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1995 MaskPoint *point = mask->points.values[gui->affected_point];
1996 gui->center_x = point->x;
1997 gui->center_y = point->y;
1998 gui->control_in_x = point->control_x1;
1999 gui->control_in_y = point->control_y1;
2000 gui->control_out_x = point->control_x2;
2001 gui->control_out_y = point->control_y2;
2002 gui->tool_panel->raise_window();
2006 //printf("CWindowCanvas::do_mask 8\n");
2009 #ifdef USE_KEYFRAME_SPANNING
2010 // Must update the reference keyframes for every cursor motion
2011 gui->mask_keyframe =
2012 (MaskAuto*)gui->cwindow->calculate_affected_auto(
2015 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
2018 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2020 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
2021 if( gui->affected_point >= 0 && gui->affected_point < mask->points.size() &&
2022 gui->current_operation != CWINDOW_NONE) {
2023 // mwindow->undo->update_undo_before(_("mask point"), this);
2024 #ifdef USE_KEYFRAME_SPANNING
2025 MaskPoint *point = points.get(gui->affected_point);
2027 MaskPoint *point = mask->points.get(gui->affected_point);
2029 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2030 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask->points.size(), gui->affected_point);
2032 float last_x = point->x;
2033 float last_y = point->y;
2034 float last_control_x1 = point->control_x1;
2035 float last_control_y1 = point->control_y1;
2036 float last_control_x2 = point->control_x2;
2037 float last_control_y2 = point->control_y2;
2039 switch(gui->current_operation) {
2041 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2042 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
2043 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
2046 case CWINDOW_MASK_CONTROL_IN:
2047 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
2048 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
2051 case CWINDOW_MASK_CONTROL_OUT:
2052 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
2053 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
2056 case CWINDOW_MASK_TRANSLATE:
2057 #ifdef USE_KEYFRAME_SPANNING
2058 for(int i = 0; i < points.size(); i++) {
2059 points.values[i]->x += mask_cursor_x - gui->x_origin;
2060 points.values[i]->y += mask_cursor_y - gui->y_origin;
2063 for(int i = 0; i < mask->points.size(); i++) {
2064 mask->points.values[i]->x += mask_cursor_x - gui->x_origin;
2065 mask->points.values[i]->y += mask_cursor_y - gui->y_origin;
2068 gui->x_origin = mask_cursor_x;
2069 gui->y_origin = mask_cursor_y;
2073 if( !EQUIV(last_x, point->x) ||
2074 !EQUIV(last_y, point->y) ||
2075 !EQUIV(last_control_x1, point->control_x1) ||
2076 !EQUIV(last_control_y1, point->control_y1) ||
2077 !EQUIV(last_control_x2, point->control_x2) ||
2078 !EQUIV(last_control_y2, point->control_y2)) {
2084 if(gui->current_operation == CWINDOW_NONE) {
2085 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
2087 for(int i = 0; i < points.size() && !over_point; i++) {
2088 MaskPoint *point = points.get(i);
2089 float x0 = point->x;
2090 float y0 = point->y;
2091 float x1 = point->x + point->control_x1;
2092 float y1 = point->y + point->control_y1;
2093 float x2 = point->x + point->control_x2;
2094 float y2 = point->y + point->control_y2;
2095 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
2096 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
2098 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
2099 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
2103 if(!over_point && gui->ctrl_down()) {
2104 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
2105 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
2106 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2107 if(test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1)) {
2111 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2112 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2113 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2114 if(test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2)) {
2121 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2126 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2129 #ifdef USE_KEYFRAME_SPANNING
2130 // Must commit change after operation.
2131 if(rerender && track) {
2132 // Swap EDL keyframe with original.
2133 // Apply new values to keyframe span
2134 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2135 temp_keyframe.copy_data(gui->mask_keyframe);
2136 // Apply interpolated points back to keyframe
2137 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2138 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2139 mask_autos->update_parameter(&temp_keyframe);
2143 points.remove_all_objects();
2144 //printf("CWindowCanvas::do_mask 20\n");
2148 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2151 int radius = mwindow->edl->session->eyedrop_radius;
2159 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2164 row1 = gui->eyedrop_y - radius;
2165 row2 = gui->eyedrop_y + radius;
2166 column1 = gui->eyedrop_x - radius;
2167 column2 = gui->eyedrop_x + radius;
2169 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2170 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2171 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2172 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2174 if(row2 <= row1) row2 = row1 + 1;
2175 if(column2 <= column1) column2 = column1 + 1;
2182 output_to_canvas(mwindow->edl, 0, x1, y1);
2183 output_to_canvas(mwindow->edl, 0, x2, y2);
2184 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2186 if(x2 - x1 >= 1 && y2 - y1 >= 1)
2188 get_canvas()->set_inverse();
2189 get_canvas()->set_color(WHITE);
2191 get_canvas()->draw_rectangle((int)x1,
2196 get_canvas()->set_opaque();
2197 get_canvas()->flash();
2205 gui->current_operation = CWINDOW_EYEDROP;
2206 gui->tool_panel->raise_window();
2209 if(gui->current_operation == CWINDOW_EYEDROP)
2211 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2213 // Get color out of frame.
2214 // Doesn't work during playback because that bypasses the refresh frame.
2215 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2217 float cursor_x = get_cursor_x();
2218 float cursor_y = get_cursor_y();
2219 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2220 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2221 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2223 row1 = cursor_y - radius;
2224 row2 = cursor_y + radius;
2225 column1 = cursor_x - radius;
2226 column2 = cursor_x + radius;
2227 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2228 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2229 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2230 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2231 if(row2 <= row1) row2 = row1 + 1;
2232 if(column2 <= column1) column2 = column1 + 1;
2236 if(gui->eyedrop_visible)
2239 do_eyedrop(temp, 0, 1);
2240 gui->eyedrop_visible = 0;
2243 gui->eyedrop_x = cursor_x;
2244 gui->eyedrop_y = cursor_y;
2249 do_eyedrop(temp, 0, 1);
2250 gui->eyedrop_visible = 1;
2253 // Decompression coefficients straight out of jpeglib
2254 #define V_TO_R 1.40200
2255 #define V_TO_G -0.71414
2257 #define U_TO_G -0.34414
2258 #define U_TO_B 1.77200
2260 #define GET_COLOR(type, components, max, do_yuv) \
2262 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2264 float red = (float)*row++ / max; \
2265 float green = (float)*row++ / max; \
2266 float blue = (float)*row++ / max; \
2269 float r = red + V_TO_R * (blue - 0.5); \
2270 float g = red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
2271 float b = red + U_TO_B * (green - 0.5); \
2272 mwindow->edl->local_session->red += r; \
2273 mwindow->edl->local_session->green += g; \
2274 mwindow->edl->local_session->blue += b; \
2275 if(r > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = r; \
2276 if(g > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = g; \
2277 if(b > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = b; \
2281 mwindow->edl->local_session->red += red; \
2282 mwindow->edl->local_session->green += green; \
2283 mwindow->edl->local_session->blue += blue; \
2284 if(red > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = red; \
2285 if(green > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = green; \
2286 if(blue > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = blue; \
2292 mwindow->edl->local_session->red = 0;
2293 mwindow->edl->local_session->green = 0;
2294 mwindow->edl->local_session->blue = 0;
2295 mwindow->edl->local_session->red_max = 0;
2296 mwindow->edl->local_session->green_max = 0;
2297 mwindow->edl->local_session->blue_max = 0;
2298 for(int i = row1; i < row2; i++)
2300 for(int j = column1; j < column2; j++)
2302 switch(refresh_frame->get_color_model())
2305 GET_COLOR(unsigned char, 3, 0xff, 1);
2308 GET_COLOR(unsigned char, 4, 0xff, 1);
2311 GET_COLOR(uint16_t, 3, 0xffff, 1);
2313 case BC_YUVA16161616:
2314 GET_COLOR(uint16_t, 4, 0xffff, 1);
2317 GET_COLOR(unsigned char, 3, 0xff, 0);
2320 GET_COLOR(unsigned char, 4, 0xff, 0);
2323 GET_COLOR(float, 3, 1.0, 0);
2326 GET_COLOR(float, 4, 1.0, 0);
2332 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2333 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2334 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2339 mwindow->edl->local_session->red = 0;
2340 mwindow->edl->local_session->green = 0;
2341 mwindow->edl->local_session->blue = 0;
2342 gui->eyedrop_visible = 0;
2351 // Can't rerender since the color value is from the output of any effect it
2354 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2360 int CWindowCanvas::need_overlays()
2362 if( mwindow->edl->session->safe_regions ) return 1;
2363 if( mwindow->edl->session->cwindow_scrollbars ) return 1;
2364 if( gui->highlighted ) return 1;
2365 switch( mwindow->edl->session->cwindow_operation ) {
2366 case CWINDOW_EYEDROP:
2367 if( ! gui->eyedrop_visible ) break;
2368 case CWINDOW_CAMERA:
2369 case CWINDOW_PROJECTOR:
2378 void CWindowCanvas::draw_overlays()
2380 if(mwindow->edl->session->safe_regions)
2382 draw_safe_regions();
2385 if(mwindow->edl->session->cwindow_scrollbars)
2387 // Always draw output rectangle
2388 float x1, y1, x2, y2;
2390 x2 = mwindow->edl->session->output_w;
2392 y2 = mwindow->edl->session->output_h;
2393 output_to_canvas(mwindow->edl, 0, x1, y1);
2394 output_to_canvas(mwindow->edl, 0, x2, y2);
2396 get_canvas()->set_inverse();
2397 get_canvas()->set_color(WHITE);
2399 get_canvas()->draw_rectangle((int)x1,
2404 get_canvas()->set_opaque();
2407 if(gui->highlighted)
2409 get_canvas()->set_color(WHITE);
2410 get_canvas()->set_inverse();
2411 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2412 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2413 get_canvas()->set_opaque();
2416 int temp1 = 0, temp2 = 0;
2417 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2418 switch(mwindow->edl->session->cwindow_operation)
2420 case CWINDOW_CAMERA:
2424 case CWINDOW_PROJECTOR:
2433 do_mask(temp1, temp2, 0, 0, 1);
2437 do_ruler(1, 0, 0, 0);
2440 case CWINDOW_EYEDROP:
2441 if(gui->eyedrop_visible)
2444 do_eyedrop(rerender, 0, 1);
2445 gui->eyedrop_visible = 1;
2451 void CWindowCanvas::draw_safe_regions()
2453 float action_x1, action_x2, action_y1, action_y2;
2454 float title_x1, title_x2, title_y1, title_y2;
2456 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2457 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2458 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2459 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2460 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2461 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2462 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2463 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2465 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2466 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2467 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2468 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2470 get_canvas()->set_inverse();
2471 get_canvas()->set_color(WHITE);
2473 get_canvas()->draw_rectangle((int)action_x1,
2475 (int)(action_x2 - action_x1),
2476 (int)(action_y2 - action_y1));
2477 get_canvas()->draw_rectangle((int)title_x1,
2479 (int)(title_x2 - title_x1),
2480 (int)(title_y2 - title_y1));
2482 get_canvas()->set_opaque();
2485 void CWindowCanvas::reset_keyframe(int do_camera)
2487 FloatAuto *x_keyframe = 0;
2488 FloatAuto *y_keyframe = 0;
2489 FloatAuto *z_keyframe = 0;
2490 Track *affected_track = 0;
2492 affected_track = gui->cwindow->calculate_affected_track();
2496 gui->cwindow->calculate_affected_autos(&x_keyframe,
2505 x_keyframe->set_value(0);
2506 y_keyframe->set_value(0);
2507 z_keyframe->set_value(1);
2509 mwindow->sync_parameters(CHANGE_PARAMS);
2514 void CWindowCanvas::reset_camera()
2519 void CWindowCanvas::reset_projector()
2524 int CWindowCanvas::test_crop(int button_press, int &redraw)
2527 int handle_selected = -1;
2528 float x1 = mwindow->edl->session->crop_x1;
2529 float y1 = mwindow->edl->session->crop_y1;
2530 float x2 = mwindow->edl->session->crop_x2;
2531 float y2 = mwindow->edl->session->crop_y2;
2532 float cursor_x = get_cursor_x();
2533 float cursor_y = get_cursor_y();
2534 float canvas_x1 = x1;
2535 float canvas_y1 = y1;
2536 float canvas_x2 = x2;
2537 float canvas_y2 = y2;
2538 float canvas_cursor_x = cursor_x;
2539 float canvas_cursor_y = cursor_y;
2541 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2542 // Use screen normalized coordinates for hot spot tests.
2543 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2544 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2547 if(gui->current_operation == CWINDOW_CROP)
2549 handle_selected = gui->crop_handle;
2552 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2553 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2555 handle_selected = 0;
2556 gui->crop_origin_x = x1;
2557 gui->crop_origin_y = y1;
2560 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2561 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2563 handle_selected = 1;
2564 gui->crop_origin_x = x2;
2565 gui->crop_origin_y = y1;
2568 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2569 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2571 handle_selected = 2;
2572 gui->crop_origin_x = x1;
2573 gui->crop_origin_y = y2;
2576 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2577 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2579 handle_selected = 3;
2580 gui->crop_origin_x = x2;
2581 gui->crop_origin_y = y2;
2586 gui->crop_origin_x = cursor_x;
2587 gui->crop_origin_y = cursor_y;
2590 // printf("test crop %d %d\n",
2591 // gui->current_operation,
2592 // handle_selected);
2599 gui->crop_translate = 1;
2600 gui->crop_origin_x1 = x1;
2601 gui->crop_origin_y1 = y1;
2602 gui->crop_origin_x2 = x2;
2603 gui->crop_origin_y2 = y2;
2606 gui->crop_translate = 0;
2608 gui->current_operation = CWINDOW_CROP;
2609 gui->crop_handle = handle_selected;
2610 gui->x_origin = cursor_x;
2611 gui->y_origin = cursor_y;
2612 gui->tool_panel->raise_window();
2615 if(handle_selected < 0 && !gui->crop_translate)
2619 mwindow->edl->session->crop_x1 = (int)x1;
2620 mwindow->edl->session->crop_y1 = (int)y1;
2621 mwindow->edl->session->crop_x2 = (int)x2;
2622 mwindow->edl->session->crop_y2 = (int)y2;
2627 // Translate all 4 points
2628 if(gui->current_operation == CWINDOW_CROP && gui->crop_translate)
2630 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2631 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2632 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2633 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2635 mwindow->edl->session->crop_x1 = (int)x1;
2636 mwindow->edl->session->crop_y1 = (int)y1;
2637 mwindow->edl->session->crop_x2 = (int)x2;
2638 mwindow->edl->session->crop_y2 = (int)y2;
2644 if(gui->current_operation == CWINDOW_CROP)
2646 switch(gui->crop_handle)
2649 x1 = gui->crop_origin_x;
2650 y1 = gui->crop_origin_y;
2651 x2 = gui->crop_origin_x;
2652 y2 = gui->crop_origin_y;
2653 if(cursor_x < gui->x_origin)
2655 if(cursor_y < gui->y_origin)
2661 if(cursor_y >= gui->y_origin)
2668 if(cursor_x >= gui->x_origin)
2670 if(cursor_y < gui->y_origin)
2676 if(cursor_y >= gui->y_origin)
2683 // printf("test crop %d %d %d %d\n",
2684 // mwindow->edl->session->crop_x1,
2685 // mwindow->edl->session->crop_y1,
2686 // mwindow->edl->session->crop_x2,
2687 // mwindow->edl->session->crop_y2);
2690 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2691 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2694 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2695 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2698 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2699 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2702 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2703 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2707 if(!EQUIV(mwindow->edl->session->crop_x1, x1) ||
2708 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2709 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2710 !EQUIV(mwindow->edl->session->crop_y2, y2))
2717 switch (gui->crop_handle)
2719 case 0: gui->crop_handle = 1; break;
2720 case 1: gui->crop_handle = 0; break;
2721 case 2: gui->crop_handle = 3; break;
2722 case 3: gui->crop_handle = 2; break;
2732 switch (gui->crop_handle)
2734 case 0: gui->crop_handle = 2; break;
2735 case 1: gui->crop_handle = 3; break;
2736 case 2: gui->crop_handle = 0; break;
2737 case 3: gui->crop_handle = 1; break;
2742 mwindow->edl->session->crop_x1 = (int)x1;
2743 mwindow->edl->session->crop_y1 = (int)y1;
2744 mwindow->edl->session->crop_x2 = (int)x2;
2745 mwindow->edl->session->crop_y2 = (int)y2;
2751 // Update cursor font
2752 if(handle_selected >= 0)
2754 switch(handle_selected)
2757 set_cursor(UPLEFT_RESIZE);
2760 set_cursor(UPRIGHT_RESIZE);
2763 set_cursor(DOWNLEFT_RESIZE);
2766 set_cursor(DOWNRIGHT_RESIZE);
2773 set_cursor(ARROW_CURSOR);
2775 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2779 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2780 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2781 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2782 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2783 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2784 // mwindow->edl->session->crop_x2,
2785 // mwindow->edl->session->crop_y2,
2786 // mwindow->edl->calculate_output_w(0),
2787 // mwindow->edl->calculate_output_h(0));
2793 void CWindowCanvas::draw_crop()
2795 get_canvas()->set_inverse();
2796 get_canvas()->set_color(WHITE);
2798 float x1 = mwindow->edl->session->crop_x1;
2799 float y1 = mwindow->edl->session->crop_y1;
2800 float x2 = mwindow->edl->session->crop_x2;
2801 float y2 = mwindow->edl->session->crop_y2;
2803 output_to_canvas(mwindow->edl, 0, x1, y1);
2804 output_to_canvas(mwindow->edl, 0, x2, y2);
2806 if(x2 - x1 && y2 - y1)
2807 get_canvas()->draw_rectangle((int)x1,
2812 draw_crophandle((int)x1, (int)y1);
2813 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2814 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2815 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2816 get_canvas()->set_opaque();
2826 void CWindowCanvas::draw_bezier(int do_camera)
2828 Track *track = gui->cwindow->calculate_affected_track();
2835 int64_t position = track->to_units(
2836 mwindow->edl->local_session->get_selectionstart(1),
2839 track->automation->get_projector(¢er_x,
2845 // center_x += track->track_w / 2;
2846 // center_y += track->track_h / 2;
2847 center_x += mwindow->edl->session->output_w / 2;
2848 center_y += mwindow->edl->session->output_h / 2;
2849 float track_x1 = center_x - track->track_w / 2 * center_z;
2850 float track_y1 = center_y - track->track_h / 2 * center_z;
2851 float track_x2 = track_x1 + track->track_w * center_z;
2852 float track_y2 = track_y1 + track->track_h * center_z;
2854 output_to_canvas(mwindow->edl, 0, track_x1, track_y1);
2855 output_to_canvas(mwindow->edl, 0, track_x2, track_y2);
2857 #define DRAW_PROJECTION(offset) \
2858 get_canvas()->draw_rectangle((int)track_x1 + offset, \
2859 (int)track_y1 + offset, \
2860 (int)(track_x2 - track_x1), \
2861 (int)(track_y2 - track_y1)); \
2862 get_canvas()->draw_line((int)track_x1 + offset, \
2863 (int)track_y1 + offset, \
2864 (int)track_x2 + offset, \
2865 (int)track_y2 + offset); \
2866 get_canvas()->draw_line((int)track_x2 + offset, \
2867 (int)track_y1 + offset, \
2868 (int)track_x1 + offset, \
2869 (int)track_y2 + offset); \
2873 get_canvas()->set_color(BLACK);
2876 // canvas->set_inverse();
2878 get_canvas()->set_color(GREEN);
2880 get_canvas()->set_color(RED);
2883 // canvas->set_opaque();
2887 int CWindowCanvas::test_bezier(int button_press,
2895 // Processing drag operation.
2896 // Create keyframe during first cursor motion.
2900 float cursor_x = get_cursor_x();
2901 float cursor_y = get_cursor_y();
2902 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2904 if(gui->current_operation == CWINDOW_CAMERA ||
2905 gui->current_operation == CWINDOW_PROJECTOR)
2907 if(!gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom)
2909 gui->translating_zoom = 1;
2910 gui->reset_affected();
2913 if(!gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom)
2915 gui->translating_zoom = 0;
2916 gui->reset_affected();
2919 // Get target keyframe
2920 float last_center_x;
2921 float last_center_y;
2922 float last_center_z;
2925 if(!gui->affected_x && !gui->affected_y && !gui->affected_z)
2927 FloatAutos *affected_x_autos;
2928 FloatAutos *affected_y_autos;
2929 FloatAutos *affected_z_autos;
2930 if(!gui->affected_track) return 0;
2931 double position = mwindow->edl->local_session->get_selectionstart(1);
2932 int64_t track_position = gui->affected_track->to_units(position, 0);
2934 if(mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA)
2936 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_X];
2937 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Y];
2938 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Z];
2942 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_X];
2943 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Y];
2944 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Z];
2948 if(gui->translating_zoom)
2950 FloatAuto *previous = 0;
2951 FloatAuto *next = 0;
2952 float new_z = affected_z_autos->get_value(
2958 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2959 affected_z_autos, 1, &created, 0);
2961 gui->affected_z->set_value(new_z);
2967 FloatAuto *previous = 0;
2968 FloatAuto *next = 0;
2969 float new_x = affected_x_autos->get_value(
2976 float new_y = affected_y_autos->get_value(
2982 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2983 affected_x_autos, 1, &created, 0);
2985 gui->affected_x->set_value(new_x);
2989 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2990 affected_y_autos, 1, &created, 0);
2992 gui->affected_y->set_value(new_y);
2999 if(gui->translating_zoom)
3001 gui->center_z = gui->affected_z->get_value();
3005 gui->center_x = gui->affected_x->get_value();
3006 gui->center_y = gui->affected_y->get_value();
3013 if(gui->translating_zoom)
3015 last_center_z = gui->affected_z->get_value();
3016 float z = gui->center_z + (cursor_y - gui->y_origin) / 128;
3018 if(!EQUIV(last_center_z, z))
3024 gui->affected_z->set_value(z);
3028 last_center_x = gui->affected_x->get_value();
3029 last_center_y = gui->affected_y->get_value();
3030 float dx = cursor_x - gui->x_origin;
3031 float dy = cursor_y - gui->y_origin;
3032 if(gui->current_operation == CWINDOW_CAMERA ) {
3035 float x = gui->center_x + dx;
3036 float y = gui->center_y + dy;
3037 gui->affected_x->set_value(x);
3038 gui->affected_y->set_value(y);
3039 if( !EQUIV(last_center_x, x) || !EQUIV(last_center_y, y) )
3045 gui->affected_x->set_value(x);
3046 gui->affected_y->set_value(y);
3053 // Begin drag operation. Don't create keyframe here.
3055 // Get affected track off of the first recordable video track.
3056 // Calculating based on the alpha channel would require recording what layer
3057 // each output pixel belongs to as they're rendered and stacked. Forget it.
3058 gui->affected_track = gui->cwindow->calculate_affected_track();
3059 gui->reset_affected();
3061 if(gui->affected_track)
3063 if(gui->current_operation == CWINDOW_CAMERA)
3064 mwindow->undo->update_undo_before(_("camera"), this);
3066 mwindow->undo->update_undo_before(_("projector"), this);
3068 gui->current_operation =
3069 mwindow->edl->session->cwindow_operation;
3070 gui->tool_panel->raise_window();
3079 int CWindowCanvas::test_zoom(int &redraw)
3085 if( mwindow->edl->session->cwindow_scrollbars ) {
3086 if( *gui->zoom_panel->get_text() != 'x' ) {
3087 // Find current zoom in table
3088 int idx = total_zooms; float old_zoom = get_zoom();
3089 while( --idx >= 0 && !EQUIV(my_zoom_table[idx], old_zoom) );
3091 idx += get_buttonpress() == 5 ||
3092 gui->ctrl_down() || gui->shift_down() ? -1 : +1 ;
3093 CLAMP(idx, 0, total_zooms-1);
3094 zoom = my_zoom_table[idx];
3097 x = get_cursor_x(); y = get_cursor_y();
3099 mwindow->edl->session->cwindow_scrollbars = 0;
3100 gui->zoom_panel->update(0);
3101 zoom = gui->get_auto_zoom();
3104 gui->zoom_panel->ZoomPanel::update(zoom);
3105 float output_x = x, output_y = y;
3106 canvas_to_output(mwindow->edl, 0, output_x, output_y);
3107 x = output_x - x / zoom;
3108 y = output_y - y / zoom;
3112 mwindow->edl->session->cwindow_scrollbars = 1;
3113 x = (mwindow->edl->session->output_w - w) / 2;
3114 y = (mwindow->edl->session->output_h - h) / 2;
3117 update_zoom((int)x, (int)y, zoom);
3119 gui->composite_panel->cpanel_zoom->update(zoom);
3121 reposition_window(mwindow->edl,
3122 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
3123 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
3124 redraw = 1; result = 1;
3130 void CWindowCanvas::calculate_origin()
3132 gui->x_origin = get_cursor_x();
3133 gui->y_origin = get_cursor_y();
3134 //printf("CWindowCanvas::calculate_origin 1 %f %f\n", gui->x_origin, gui->y_origin);
3135 canvas_to_output(mwindow->edl, 0, gui->x_origin, gui->y_origin);
3136 //printf("CWindowCanvas::calculate_origin 2 %f %f\n", gui->x_origin, gui->y_origin);
3140 int CWindowCanvas::cursor_leave_event()
3142 set_cursor(ARROW_CURSOR);
3146 int CWindowCanvas::cursor_enter_event()
3149 switch(mwindow->edl->session->cwindow_operation)
3151 case CWINDOW_CAMERA:
3152 case CWINDOW_PROJECTOR:
3153 set_cursor(MOVE_CURSOR);
3156 set_cursor(MOVE_CURSOR);
3159 test_crop(0, redraw);
3161 case CWINDOW_PROTECT:
3162 set_cursor(ARROW_CURSOR);
3166 set_cursor(CROSS_CURSOR);
3168 case CWINDOW_EYEDROP:
3169 set_cursor(CROSS_CURSOR);
3175 int CWindowCanvas::cursor_motion_event()
3177 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3180 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3181 switch(gui->current_operation)
3183 case CWINDOW_SCROLL:
3185 float zoom = get_zoom();
3186 float cursor_x = get_cursor_x();
3187 float cursor_y = get_cursor_y();
3189 float zoom_x, zoom_y, conformed_w, conformed_h;
3190 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3191 cursor_x = (float)cursor_x / zoom_x + gui->x_offset;
3192 cursor_y = (float)cursor_y / zoom_y + gui->y_offset;
3196 int x = (int)(gui->x_origin - cursor_x + gui->x_offset);
3197 int y = (int)(gui->y_origin - cursor_y + gui->y_offset);
3202 update_scrollbars(0);
3209 result = do_ruler(0, 1, 0, 0);
3212 case CWINDOW_CAMERA:
3213 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3216 case CWINDOW_PROJECTOR:
3217 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3222 result = test_crop(0, redraw);
3223 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3230 case CWINDOW_MASK_CONTROL_IN:
3231 case CWINDOW_MASK_CONTROL_OUT:
3232 case CWINDOW_MASK_TRANSLATE:
3234 result = do_mask(redraw,
3241 case CWINDOW_EYEDROP:
3242 result = do_eyedrop(rerender, 0, 0);
3251 // cursor font changes
3254 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3256 // mwindow->edl->session->cwindow_operation);
3257 switch(mwindow->edl->session->cwindow_operation)
3260 result = test_crop(0, redraw);
3263 result = do_ruler(0, 1, 0, 0);
3266 result = do_mask(redraw,
3276 // If the window is never unlocked before calling send_command the
3277 // display shouldn't get stuck on the old video frame although it will
3278 // flicker between the old video frame and the new video frame.
3288 gui->unlock_window();
3291 mwindow->gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3292 mwindow->gui->draw_overlays(1);
3293 mwindow->gui->unlock_window();
3295 gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3300 gui->unlock_window();
3301 mwindow->restart_brender();
3302 mwindow->sync_parameters(CHANGE_PARAMS);
3303 mwindow->cwindow->refresh_frame(CHANGE_NONE);
3304 if(!redraw) gui->update_tool();
3305 gui->lock_window("CWindowCanvas::cursor_motion_event 2");
3310 int CWindowCanvas::button_press_event()
3314 int redraw_canvas = 0;
3317 if(Canvas::button_press_event()) return 1;
3319 gui->translating_zoom = gui->shift_down();
3322 //printf("CWindowCanvas::button_press_event 2 %f %f\n", gui->x_origin, gui->y_origin, gui->x_origin, gui->y_origin);
3324 float zoom_x, zoom_y, conformed_w, conformed_h;
3325 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3326 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3327 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3330 if( mwindow->edl->session->cwindow_operation != CWINDOW_PROTECT &&
3331 get_buttonpress() == 2 )
3333 gui->current_operation = CWINDOW_SCROLL;
3339 switch(mwindow->edl->session->cwindow_operation)
3342 result = do_ruler(0, 0, 1, 0);
3345 case CWINDOW_CAMERA:
3346 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3349 case CWINDOW_PROJECTOR:
3350 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3354 result = test_zoom(redraw);
3358 result = test_crop(1, redraw);
3362 if(get_buttonpress() == 1)
3363 result = do_mask(redraw, rerender, 1, 0, 0);
3366 case CWINDOW_EYEDROP:
3367 result = do_eyedrop(rerender, 1, 0);
3375 gui->unlock_window();
3378 mwindow->gui->lock_window("CWindowCanvas::button_press_event 1");
3379 mwindow->gui->draw_overlays(1);
3380 mwindow->gui->unlock_window();
3383 gui->lock_window("CWindowCanvas::button_press_event 1");
3386 // rerendering can also be caused by press event
3389 gui->unlock_window();
3391 mwindow->restart_brender();
3392 mwindow->sync_parameters(CHANGE_PARAMS);
3393 mwindow->cwindow->refresh_frame(CHANGE_NONE);
3394 if(!redraw) gui->update_tool();
3395 gui->lock_window("CWindowCanvas::button_press_event 2");
3400 int CWindowCanvas::button_release_event()
3404 switch(gui->current_operation)
3406 case CWINDOW_SCROLL:
3411 do_ruler(0, 0, 0, 1);
3414 case CWINDOW_CAMERA:
3415 mwindow->undo->update_undo_after(_("camera"), LOAD_AUTOMATION);
3418 case CWINDOW_PROJECTOR:
3419 mwindow->undo->update_undo_after(_("projector"), LOAD_AUTOMATION);
3423 case CWINDOW_MASK_CONTROL_IN:
3424 case CWINDOW_MASK_CONTROL_OUT:
3425 case CWINDOW_MASK_TRANSLATE:
3426 // Finish mask operation
3427 gui->mask_keyframe = 0;
3428 mwindow->undo->update_undo_after(_("mask"), LOAD_AUTOMATION);
3431 result = Canvas::button_release_event();
3435 gui->current_operation = CWINDOW_NONE;
3439 void CWindowCanvas::zoom_resize_window(float percentage)
3441 int canvas_w, canvas_h;
3445 // Get required canvas size
3446 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3447 mwindow->edl->session->output_w,
3448 mwindow->edl->session->output_h,
3453 // Estimate window size from current borders
3454 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3455 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3457 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3458 mwindow->session->cwindow_w = new_w;
3459 mwindow->session->cwindow_h = new_h;
3461 mwindow->theme->get_cwindow_sizes(gui,
3462 mwindow->session->cwindow_controls);
3464 // Estimate again from new borders
3465 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3466 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3467 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3469 gui->resize_window(new_w, new_h);
3470 gui->resize_event(new_w, new_h);
3473 void CWindowCanvas::toggle_controls()
3475 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3476 gui->resize_event(gui->get_w(), gui->get_h());
3479 int CWindowCanvas::get_cwindow_controls()
3481 return mwindow->session->cwindow_controls;