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();
223 set_operation(mwindow->edl->session->cwindow_operation);
227 canvas->draw_refresh(0);
234 int CWindowGUI::translation_event()
236 mwindow->session->cwindow_x = get_x();
237 mwindow->session->cwindow_y = get_y();
241 int CWindowGUI::resize_event(int w, int h)
243 mwindow->session->cwindow_x = get_x();
244 mwindow->session->cwindow_y = get_y();
245 mwindow->session->cwindow_w = w;
246 mwindow->session->cwindow_h = h;
248 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
249 mwindow->theme->draw_cwindow_bg(this);
252 composite_panel->reposition_buttons(mwindow->theme->ccomposite_x,
253 mwindow->theme->ccomposite_y, mwindow->theme->ccomposite_h);
255 canvas->reposition_window(mwindow->edl,
256 mwindow->theme->ccanvas_x,
257 mwindow->theme->ccanvas_y,
258 mwindow->theme->ccanvas_w,
259 mwindow->theme->ccanvas_h);
261 timebar->resize_event();
264 slider->reposition_window(mwindow->theme->cslider_x,
265 mwindow->theme->cslider_y,
266 mwindow->theme->cslider_w);
267 // Recalibrate pointer motion range
268 slider->set_position();
271 transport->reposition_buttons(mwindow->theme->ctransport_x,
272 mwindow->theme->ctransport_y);
274 edit_panel->reposition_buttons(mwindow->theme->cedit_x,
275 mwindow->theme->cedit_y);
277 // clock->reposition_window(mwindow->theme->ctime_x,
278 // mwindow->theme->ctime_y);
280 zoom_panel->reposition_window(mwindow->theme->czoom_x,
281 mwindow->theme->czoom_y);
283 // destination->reposition_window(mwindow->theme->cdest_x,
284 // mwindow->theme->cdest_y);
286 meters->reposition_window(mwindow->theme->cmeter_x,
287 mwindow->theme->cmeter_y,
289 mwindow->theme->cmeter_h);
293 BC_WindowBase::resize_event(w, h);
297 int CWindowGUI::button_press_event()
299 if( current_operation == CWINDOW_NONE &&
300 mwindow->edl != 0 && canvas->get_canvas() &&
301 mwindow->edl->session->cwindow_click2play &&
302 canvas->get_canvas()->get_cursor_over_window() ) {
303 switch( get_buttonpress() ) {
305 if( !cwindow->playback_engine->is_playing_back ) {
306 double length = mwindow->edl->tracks->total_playable_length();
307 double position = cwindow->playback_engine->get_tracking_position();
308 if( position >= length ) transport->goto_start();
310 return transport->forward_play->handle_event();
312 if( !cwindow->playback_engine->is_playing_back ) {
313 double position = cwindow->playback_engine->get_tracking_position();
314 if( position <= 0 ) transport->goto_end();
316 return transport->reverse_play->handle_event();
317 case RIGHT_BUTTON: // activates popup
320 return transport->frame_forward_play->handle_event();
322 return transport->frame_reverse_play->handle_event();
325 if(canvas->get_canvas())
326 return canvas->button_press_event_base(canvas->get_canvas());
330 int CWindowGUI::cursor_leave_event()
332 if(canvas->get_canvas())
333 return canvas->cursor_leave_event_base(canvas->get_canvas());
337 int CWindowGUI::cursor_enter_event()
339 if(canvas->get_canvas())
340 return canvas->cursor_enter_event_base(canvas->get_canvas());
344 int CWindowGUI::button_release_event()
346 if(canvas->get_canvas())
347 return canvas->button_release_event();
351 int CWindowGUI::cursor_motion_event()
353 if(canvas->get_canvas())
355 canvas->get_canvas()->unhide_cursor();
356 return canvas->cursor_motion_event();
367 void CWindowGUI::draw_status(int flush)
369 if( (canvas->get_canvas() && canvas->get_canvas()->get_video_on()) ||
370 canvas->is_processing )
373 mwindow->theme->cstatus_x,
374 mwindow->theme->cstatus_y);
378 draw_pixmap(inactive,
379 mwindow->theme->cstatus_x,
380 mwindow->theme->cstatus_y);
384 // printf("CWindowGUI::draw_status %d %d %d\n", __LINE__, mwindow->theme->cstatus_x,
385 // mwindow->theme->cstatus_y);
386 flash(mwindow->theme->cstatus_x,
387 mwindow->theme->cstatus_y,
393 float CWindowGUI::get_auto_zoom()
395 float conformed_w, conformed_h;
396 mwindow->edl->calculate_conformed_dimensions(0, conformed_w, conformed_h);
397 float zoom_x = canvas->w / conformed_w;
398 float zoom_y = canvas->h / conformed_h;
399 return zoom_x < zoom_y ? zoom_x : zoom_y;
402 void CWindowGUI::zoom_canvas(double value, int update_menu)
405 float zoom = !value ? get_auto_zoom() : value;
406 mwindow->edl->session->cwindow_scrollbars = !value ? 0 : 1;
408 float cx = canvas->get_xscroll() + 0.5f*canvas->w_visible;
409 float cy = canvas->get_yscroll() + 0.5f*canvas->h_visible;
410 float output_x = cx, output_y = cy;
411 canvas->output_to_canvas(mwindow->edl, 0, cx, cy);
412 x = output_x - cx / zoom;
413 y = output_y - cy / zoom;
415 canvas->update_zoom((int)(x+0.5), (int)(y+0.5), zoom);
418 zoom_panel->update(value);
419 if( mwindow->edl->session->cwindow_operation == CWINDOW_ZOOM )
420 composite_panel->cpanel_zoom->update(zoom);
422 canvas->reposition_window(mwindow->edl,
423 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
424 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
425 canvas->draw_refresh();
430 void CWindowGUI::set_operation(int value)
432 mwindow->edl->session->cwindow_operation = value;
434 composite_panel->set_operation(value);
435 edit_panel->update();
437 tool_panel->start_tool(value);
438 canvas->draw_refresh();
441 void CWindowGUI::update_tool()
443 tool_panel->update_values();
446 int CWindowGUI::close_event()
448 cwindow->hide_window();
453 int CWindowGUI::keypress_event()
457 switch(get_keypress())
475 if(mwindow->session->cwindow_fullscreen)
476 canvas->stop_fullscreen();
478 canvas->start_fullscreen();
479 lock_window("CWindowGUI::keypress_event 1");
483 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
485 mwindow->gui->unlock_window();
486 lock_window("CWindowGUI::keypress_event 2");
490 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
491 mwindow->clear_entry();
492 mwindow->gui->unlock_window();
493 lock_window("CWindowGUI::keypress_event 3");
497 if(mwindow->session->cwindow_fullscreen)
498 canvas->stop_fullscreen();
499 lock_window("CWindowGUI::keypress_event 4");
503 int alt_down = this->alt_down();
504 int shift_down = this->shift_down();
507 mwindow->gui->lock_window("CWindowGUI::keypress_event 5");
509 mwindow->prev_edit_handle(shift_down);
511 mwindow->move_left();
512 mwindow->gui->unlock_window();
513 lock_window("CWindowGUI::keypress_event 6");
519 if( !ctrl_down() && !alt_down() ) {
522 mwindow->gui->lock_window("CWindowGUI::keypress_event 7");
523 mwindow->move_left();
524 mwindow->gui->unlock_window();
525 lock_window("CWindowGUI::keypress_event 8");
532 int alt_down = this->alt_down();
533 int shift_down = this->shift_down();
536 mwindow->gui->lock_window("CWindowGUI::keypress_event 8");
538 mwindow->next_edit_handle(shift_down);
540 mwindow->move_right();
541 mwindow->gui->unlock_window();
542 lock_window("CWindowGUI::keypress_event 9");
548 if( !ctrl_down() && !alt_down() ) {
551 mwindow->gui->lock_window("CWindowGUI::keypress_event 10");
552 mwindow->move_right();
553 mwindow->gui->unlock_window();
554 lock_window("CWindowGUI::keypress_event 11");
561 if(!result) result = transport->keypress_event();
567 void CWindowGUI::reset_affected()
574 void CWindowGUI::keyboard_zoomin()
576 // if(mwindow->edl->session->cwindow_scrollbars)
578 zoom_panel->zoom_tumbler->handle_up_event();
585 void CWindowGUI::keyboard_zoomout()
587 // if(mwindow->edl->session->cwindow_scrollbars)
589 zoom_panel->zoom_tumbler->handle_down_event();
597 void CWindowGUI::drag_motion()
599 if(get_hidden()) return;
601 if(mwindow->session->current_operation != DRAG_ASSET &&
602 mwindow->session->current_operation != DRAG_VTRANSITION &&
603 mwindow->session->current_operation != DRAG_VEFFECT) return;
604 int need_highlight = cursor_above() && get_cursor_over_window();
605 if( highlighted == need_highlight ) return;
606 highlighted = need_highlight;
607 canvas->draw_refresh();
610 int CWindowGUI::drag_stop()
613 if(get_hidden()) return 0;
614 if( !highlighted ) return 0;
615 if( mwindow->session->current_operation != DRAG_ASSET &&
616 mwindow->session->current_operation != DRAG_VTRANSITION &&
617 mwindow->session->current_operation != DRAG_VEFFECT) return 0;
619 canvas->draw_refresh();
622 if(mwindow->session->current_operation == DRAG_ASSET)
624 if(mwindow->session->drag_assets->total ||
625 mwindow->session->drag_clips->total)
627 mwindow->gui->lock_window("CWindowGUI::drag_stop 5");
628 mwindow->undo->update_undo_before(_("insert assets"), 0);
629 mwindow->gui->unlock_window();
632 if(mwindow->session->drag_assets->total)
634 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
636 mwindow->load_assets(mwindow->session->drag_assets,
637 mwindow->edl->local_session->get_selectionstart(),
639 mwindow->session->track_highlighted,
641 mwindow->edl->session->labels_follow_edits,
642 mwindow->edl->session->plugins_follow_edits,
643 mwindow->edl->session->autos_follow_edits,
647 if(mwindow->session->drag_clips->total)
649 mwindow->gui->lock_window("CWindowGUI::drag_stop 2");
651 mwindow->paste_edls(mwindow->session->drag_clips,
653 mwindow->session->track_highlighted,
654 mwindow->edl->local_session->get_selectionstart(),
655 mwindow->edl->session->labels_follow_edits,
656 mwindow->edl->session->plugins_follow_edits,
657 mwindow->edl->session->autos_follow_edits,
661 if(mwindow->session->drag_assets->total ||
662 mwindow->session->drag_clips->total)
664 mwindow->save_backup();
665 mwindow->restart_brender();
666 mwindow->gui->update(1, 1, 1, 1, 0, 1, 0);
667 mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
668 mwindow->gui->unlock_window();
669 mwindow->sync_parameters(LOAD_ALL);
673 if(mwindow->session->current_operation == DRAG_VEFFECT)
675 //printf("CWindowGUI::drag_stop 1\n");
676 Track *affected_track = cwindow->calculate_affected_track();
677 //printf("CWindowGUI::drag_stop 2\n");
679 mwindow->gui->lock_window("CWindowGUI::drag_stop 3");
680 mwindow->insert_effects_cwindow(affected_track);
681 mwindow->session->current_operation = NO_OPERATION;
682 mwindow->gui->unlock_window();
685 if(mwindow->session->current_operation == DRAG_VTRANSITION)
687 Track *affected_track = cwindow->calculate_affected_track();
688 mwindow->gui->lock_window("CWindowGUI::drag_stop 4");
689 mwindow->paste_transition_cwindow(affected_track);
690 mwindow->session->current_operation = NO_OPERATION;
691 mwindow->gui->unlock_window();
697 void CWindowGUI::update_meters()
699 if(mwindow->edl->session->cwindow_meter != meters->visible)
701 meters->set_meters(meters->meter_count, mwindow->edl->session->cwindow_meter);
702 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
703 resize_event(get_w(), get_h());
707 void CWindowGUI::stop_transport(const char *lock_msg)
709 if( lock_msg ) unlock_window();
710 mwindow->stop_transport();
711 if( lock_msg ) lock_window(lock_msg);
715 CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
716 : EditPanel(mwindow, cwindow->gui, CWINDOW_ID,
717 mwindow->theme->cedit_x, mwindow->theme->cedit_y,
718 mwindow->edl->session->editing_mode,
719 0, // use_editing_mode
738 this->mwindow = mwindow;
739 this->cwindow = cwindow;
742 #define CWrapper(fn) void CWindowEditing::fn() { \
743 mwindow->gui->lock_window("CWrapper::" #fn); \
745 mwindow->gui->unlock_window(); \
748 CWrapper(copy_selection)
749 CWrapper(splice_selection)
750 CWrapper(overwrite_selection)
751 CWrapper(set_inpoint)
752 CWrapper(set_outpoint)
753 CWrapper(unset_inoutpoint)
754 CWrapper(toggle_label)
756 #define CWrapper_cut(fn) void CWindowEditing::fn(int cut) { \
757 mwindow->gui->lock_window("CWrapper::" #fn); \
758 EditPanel::fn(cut); \
759 mwindow->gui->unlock_window(); \
761 CWrapper_cut(prev_label)
762 CWrapper_cut(next_label)
763 CWrapper_cut(prev_edit)
764 CWrapper_cut(next_edit)
766 void CWindowEditing::to_clip()
768 mwindow->to_clip(mwindow->edl, _("composer window: "), 0);
772 CWindowMeters::CWindowMeters(MWindow *mwindow,
777 : MeterPanel(mwindow,
783 mwindow->edl->session->audio_channels,
784 mwindow->edl->session->cwindow_meter,
788 this->mwindow = mwindow;
792 CWindowMeters::~CWindowMeters()
796 int CWindowMeters::change_status_event(int new_status)
798 mwindow->edl->session->cwindow_meter = new_status;
799 gui->update_meters();
806 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
807 : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
808 x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
810 this->mwindow = mwindow;
814 CWindowZoom::~CWindowZoom()
818 void CWindowZoom::update(double value)
820 char string[BCSTRLEN];
821 const char *cp = string;
824 int frac = value >= 1.0f ? 1 :
826 value >= .01f ? 3 : 4;
827 sprintf(string, "x %.*f", frac, value);
831 ZoomPanel::update(cp);
834 int CWindowZoom::handle_event()
836 double value = !strcasecmp(gui->auto_zoom, get_text()) ? 0 : get_value();
837 gui->zoom_canvas(value, 0);
844 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
845 : BC_PercentageSlider(x,
854 this->mwindow = mwindow;
855 this->cwindow = cwindow;
856 set_precision(0.00001);
859 CWindowSlider::~CWindowSlider()
863 int CWindowSlider::handle_event()
865 cwindow->update_position((double)get_value());
869 void CWindowSlider::set_position()
871 double new_length = mwindow->edl->tracks->total_length();
872 // if(mwindow->edl->local_session->preview_end <= 0 ||
873 // mwindow->edl->local_session->preview_end > new_length)
874 // mwindow->edl->local_session->preview_end = new_length;
875 // if(mwindow->edl->local_session->preview_start >
876 // mwindow->edl->local_session->preview_end)
877 // mwindow->edl->local_session->preview_start = 0;
880 update(mwindow->theme->cslider_w,
881 mwindow->edl->local_session->get_selectionstart(1),
884 // mwindow->edl->local_session->preview_start,
885 // mwindow->edl->local_session->preview_end);
889 int CWindowSlider::increase_value()
892 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
893 lock_window("CWindowSlider::increase_value");
897 int CWindowSlider::decrease_value()
900 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
901 lock_window("CWindowSlider::decrease_value");
906 // CWindowDestination::CWindowDestination(MWindow *mwindow, CWindowGUI *cwindow, int x, int y)
907 // : BC_PopupTextBox(cwindow,
908 // &cwindow->destinations,
909 // cwindow->destinations.values[cwindow->cwindow->destination]->get_text(),
915 // this->mwindow = mwindow;
916 // this->cwindow = cwindow;
919 // CWindowDestination::~CWindowDestination()
923 // int CWindowDestination::handle_event()
934 CWindowTransport::CWindowTransport(MWindow *mwindow,
938 : PlayTransport(mwindow,
946 EDL* CWindowTransport::get_edl()
951 void CWindowTransport::goto_start()
953 gui->unlock_window();
954 handle_transport(REWIND, 1);
956 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
957 mwindow->goto_start();
958 mwindow->gui->unlock_window();
960 gui->lock_window("CWindowTransport::goto_start 2");
963 void CWindowTransport::goto_end()
965 gui->unlock_window();
966 handle_transport(GOTO_END, 1);
968 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
970 mwindow->gui->unlock_window();
972 gui->lock_window("CWindowTransport::goto_end 2");
977 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
980 mwindow->theme->ccanvas_x,
981 mwindow->theme->ccanvas_y,
982 mwindow->theme->ccanvas_w,
983 mwindow->theme->ccanvas_h,
986 mwindow->edl->session->cwindow_scrollbars)
988 this->mwindow = mwindow;
992 void CWindowCanvas::status_event()
997 int CWindowCanvas::get_fullscreen()
999 return mwindow->session->cwindow_fullscreen;
1002 void CWindowCanvas::set_fullscreen(int value)
1004 mwindow->session->cwindow_fullscreen = value;
1008 void CWindowCanvas::update_zoom(int x, int y, float zoom)
1010 use_scrollbars = mwindow->edl->session->cwindow_scrollbars;
1012 mwindow->edl->session->cwindow_xscroll = x;
1013 mwindow->edl->session->cwindow_yscroll = y;
1014 mwindow->edl->session->cwindow_zoom = zoom;
1017 void CWindowCanvas::zoom_auto()
1019 gui->zoom_canvas(0, 1);
1022 int CWindowCanvas::get_xscroll()
1024 return mwindow->edl->session->cwindow_xscroll;
1027 int CWindowCanvas::get_yscroll()
1029 return mwindow->edl->session->cwindow_yscroll;
1033 float CWindowCanvas::get_zoom()
1035 return mwindow->edl->session->cwindow_zoom;
1038 void CWindowCanvas::draw_refresh(int flush)
1040 if(get_canvas() && !get_canvas()->get_video_on())
1043 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
1045 float in_x1, in_y1, in_x2, in_y2;
1046 float out_x1, out_y1, out_x2, out_y2;
1047 get_transfers(mwindow->edl,
1057 if(!EQUIV(out_x1, 0) ||
1058 !EQUIV(out_y1, 0) ||
1059 !EQUIV(out_x2, get_canvas()->get_w()) ||
1060 !EQUIV(out_y2, get_canvas()->get_h()))
1062 get_canvas()->clear_box(0,
1064 get_canvas()->get_w(),
1065 get_canvas()->get_h());
1068 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1069 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1072 if(out_x2 > out_x1 &&
1077 // Can't use OpenGL here because it is called asynchronously of the
1078 // playback operation.
1079 get_canvas()->draw_vframe(refresh_frame,
1082 (int)(out_x2 - out_x1),
1083 (int)(out_y2 - out_y1),
1086 (int)(in_x2 - in_x1),
1087 (int)(in_y2 - in_y1),
1093 get_canvas()->clear_box(0,
1095 get_canvas()->get_w(),
1096 get_canvas()->get_h());
1100 get_canvas()->flash(flush);
1102 //printf("CWindowCanvas::draw_refresh 10\n");
1105 #define CROPHANDLE_W 10
1106 #define CROPHANDLE_H 10
1108 void CWindowCanvas::draw_crophandle(int x, int y)
1110 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1118 #define CONTROL_W 10
1119 #define CONTROL_H 10
1120 #define FIRST_CONTROL_W 20
1121 #define FIRST_CONTROL_H 20
1123 #define BC_INFINITY 65536
1125 #define RULERHANDLE_W 16
1126 #define RULERHANDLE_H 16
1130 int CWindowCanvas::do_ruler(int draw,
1136 float x1 = mwindow->edl->session->ruler_x1;
1137 float y1 = mwindow->edl->session->ruler_y1;
1138 float x2 = mwindow->edl->session->ruler_x2;
1139 float y2 = mwindow->edl->session->ruler_y2;
1140 float canvas_x1 = x1;
1141 float canvas_y1 = y1;
1142 float canvas_x2 = x2;
1143 float canvas_y2 = y2;
1144 float output_x = get_cursor_x();
1145 float output_y = get_cursor_y();
1146 float canvas_cursor_x = output_x;
1147 float canvas_cursor_y = output_y;
1149 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1150 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1151 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1152 mwindow->session->cwindow_output_x = roundf(output_x);
1153 mwindow->session->cwindow_output_y = roundf(output_y);
1155 if(button_press && get_buttonpress() == 1)
1157 gui->ruler_handle = -1;
1158 gui->ruler_translate = 0;
1161 gui->ruler_translate = 1;
1162 gui->ruler_origin_x = x1;
1163 gui->ruler_origin_y = y1;
1166 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1167 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1168 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1169 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1171 gui->ruler_handle = 0;
1172 gui->ruler_origin_x = x1;
1173 gui->ruler_origin_y = y1;
1176 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1177 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1178 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1179 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1181 gui->ruler_handle = 1;
1182 gui->ruler_origin_x = x2;
1183 gui->ruler_origin_y = y2;
1187 // Start new selection
1188 if(!gui->ruler_translate &&
1189 (gui->ruler_handle < 0 ||
1194 do_ruler(1, 0, 0, 0);
1195 get_canvas()->flash();
1196 gui->ruler_handle = 1;
1197 mwindow->edl->session->ruler_x1 = output_x;
1198 mwindow->edl->session->ruler_y1 = output_y;
1199 mwindow->edl->session->ruler_x2 = output_x;
1200 mwindow->edl->session->ruler_y2 = output_y;
1201 gui->ruler_origin_x = mwindow->edl->session->ruler_x2;
1202 gui->ruler_origin_y = mwindow->edl->session->ruler_y2;
1205 gui->x_origin = output_x;
1206 gui->y_origin = output_y;
1207 gui->current_operation = CWINDOW_RULER;
1208 gui->tool_panel->raise_window();
1214 if(gui->current_operation == CWINDOW_RULER)
1216 if(gui->ruler_translate)
1219 do_ruler(1, 0, 0, 0);
1220 float x_difference = mwindow->edl->session->ruler_x1;
1221 float y_difference = mwindow->edl->session->ruler_y1;
1222 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1223 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1224 x_difference -= mwindow->edl->session->ruler_x1;
1225 y_difference -= mwindow->edl->session->ruler_y1;
1226 mwindow->edl->session->ruler_x2 -= x_difference;
1227 mwindow->edl->session->ruler_y2 -= y_difference;
1229 do_ruler(1, 0, 0, 0);
1230 get_canvas()->flash();
1234 switch(gui->ruler_handle)
1237 do_ruler(1, 0, 0, 0);
1238 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1239 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1240 if(gui->alt_down() || gui->ctrl_down())
1242 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1243 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1247 double distance_value =
1248 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1249 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1250 if(angle_value < 22)
1251 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2;
1253 if(angle_value > 67)
1254 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2;
1256 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 &&
1257 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1259 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1260 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1263 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 && mwindow->edl->session->ruler_y1 > mwindow->edl->session->ruler_y2)
1265 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1266 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1269 if(mwindow->edl->session->ruler_x1 > mwindow->edl->session->ruler_x2 &&
1270 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1272 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1273 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1277 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1278 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1281 do_ruler(1, 0, 0, 0);
1282 get_canvas()->flash();
1287 do_ruler(1, 0, 0, 0);
1288 mwindow->edl->session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1289 mwindow->edl->session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1290 if(gui->alt_down() || gui->ctrl_down())
1292 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1293 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1297 double distance_value =
1298 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1299 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1300 if(angle_value < 22)
1301 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1;
1303 if(angle_value > 67)
1304 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1;
1306 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1307 mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1309 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1310 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1313 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1314 mwindow->edl->session->ruler_y2 > mwindow->edl->session->ruler_y1)
1316 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1317 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1320 if(mwindow->edl->session->ruler_x2 > mwindow->edl->session->ruler_x1 && mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1322 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1323 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1327 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1328 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1331 do_ruler(1, 0, 0, 0);
1332 get_canvas()->flash();
1336 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1340 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1345 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1346 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1347 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1348 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1350 set_cursor(UPRIGHT_ARROW_CURSOR);
1353 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1354 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1355 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1356 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1358 set_cursor(UPRIGHT_ARROW_CURSOR);
1361 set_cursor(CROSS_CURSOR);
1363 // Update current position
1368 // Assume no ruler measurement if 0 length
1369 if(draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)))
1371 get_canvas()->set_inverse();
1372 get_canvas()->set_color(WHITE);
1373 get_canvas()->draw_line((int)canvas_x1,
1377 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1379 roundf(canvas_x1) + RULERHANDLE_W / 2,
1381 get_canvas()->draw_line(roundf(canvas_x1),
1382 roundf(canvas_y1) - RULERHANDLE_H / 2,
1384 roundf(canvas_y1) + RULERHANDLE_H / 2);
1385 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1387 roundf(canvas_x2) + RULERHANDLE_W / 2,
1389 get_canvas()->draw_line(roundf(canvas_x2),
1390 roundf(canvas_y2) - RULERHANDLE_H / 2,
1392 roundf(canvas_y2) + RULERHANDLE_H / 2);
1393 get_canvas()->set_opaque();
1400 static inline double line_dist(float cx,float cy, float tx,float ty)
1402 double dx = tx-cx, dy = ty-cy;
1403 return sqrt(dx*dx + dy*dy);
1406 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1408 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1409 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1413 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1414 int button_press, int cursor_motion, int draw)
1416 // Retrieve points from top recordable track
1417 //printf("CWindowCanvas::do_mask 1\n");
1418 Track *track = gui->cwindow->calculate_affected_track();
1419 //printf("CWindowCanvas::do_mask 2\n");
1421 if(!track) return 0;
1422 //printf("CWindowCanvas::do_mask 3\n");
1424 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1425 int64_t position = track->to_units(
1426 mwindow->edl->local_session->get_selectionstart(1),
1428 ArrayList<MaskPoint*> points;
1430 // Determine the points based on whether
1431 // new keyframes will be generated or drawing is performed.
1432 // If keyframe generation occurs, use the interpolated mask.
1433 // If no keyframe generation occurs, use the previous mask.
1434 int use_interpolated = 0;
1435 if(button_press || cursor_motion) {
1436 #ifdef USE_KEYFRAME_SPANNING
1437 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1438 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1441 mask_autos->get_prev_auto(track->to_units(selection_start, 0),
1442 PLAY_FORWARD, first, 1);
1444 mask_autos->get_prev_auto(track->to_units(selection_end, 0),
1445 PLAY_FORWARD, last, 1);
1447 if(last == first && (!mwindow->edl->session->auto_keyframes))
1448 use_interpolated = 0;
1450 // If keyframe spanning occurs, use the interpolated points.
1451 // If new keyframe is generated, use the interpolated points.
1452 use_interpolated = 1;
1455 if(mwindow->edl->session->auto_keyframes)
1456 use_interpolated = 1;
1460 use_interpolated = 1;
1462 if(use_interpolated) {
1463 // Interpolate the points to get exactly what is being rendered at this position.
1464 mask_autos->get_points(&points,
1465 mwindow->edl->session->cwindow_mask,
1470 // Use the prev mask
1472 mask_autos->get_prev_auto(position,
1476 ((MaskAuto*)prev)->get_points(&points,
1477 mwindow->edl->session->cwindow_mask);
1480 // Projector zooms relative to the center of the track output.
1481 float half_track_w = (float)track->track_w / 2;
1482 float half_track_h = (float)track->track_h / 2;
1483 // Translate mask to projection
1484 float projector_x, projector_y, projector_z;
1485 track->automation->get_projector(
1486 &projector_x, &projector_y, &projector_z,
1487 position, PLAY_FORWARD);
1490 // Get position of cursor relative to mask
1491 float cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
1492 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1493 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1495 projector_x += mwindow->edl->session->output_w / 2;
1496 projector_y += mwindow->edl->session->output_h / 2;
1497 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1498 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1500 // Fix cursor origin
1502 gui->x_origin = mask_cursor_x;
1503 gui->y_origin = mask_cursor_y;
1507 // Points of closest line
1508 int shortest_point1 = -1;
1509 int shortest_point2 = -1;
1511 int shortest_point = -1;
1512 // Distance to closest line
1513 float shortest_line_distance = BC_INFINITY;
1514 // Distance to closest point
1515 float shortest_point_distance = BC_INFINITY;
1516 int selected_point = -1;
1517 int selected_control_point = -1;
1518 float selected_control_point_distance = BC_INFINITY;
1519 ArrayList<int> x_points;
1520 ArrayList<int> y_points;
1522 if(!cursor_motion) {
1524 get_canvas()->set_color(WHITE);
1525 get_canvas()->set_inverse();
1527 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1529 // Never draw closed polygon and a closed
1530 // polygon is harder to add points to.
1531 for(int i = 0; i < points.size() && !result; i++) {
1532 MaskPoint *point1 = points.get(i);
1533 MaskPoint *point2 = (i >= points.size() - 1) ?
1534 points.get(0) : points.get(i + 1);
1536 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1537 if(point_distance1 < shortest_point_distance || shortest_point < 0) {
1538 shortest_point_distance = point_distance1;
1542 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1543 if(point_distance2 < shortest_point_distance || shortest_point < 0) {
1544 shortest_point_distance = point_distance2;
1545 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1549 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1551 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1552 //point1->x, point1->y, point2->x, point2->y, projector_z);
1553 for(int j = 0; j <= segments && !result; j++) {
1554 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1555 float x0 = point1->x, y0 = point1->y;
1556 float x1 = point1->x + point1->control_x2;
1557 float y1 = point1->y + point1->control_y2;
1558 float x2 = point2->x + point2->control_x1;
1559 float y2 = point2->y + point2->control_y1;
1560 float x3 = point2->x, y3 = point2->y;
1561 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1562 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1563 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1564 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1565 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1566 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1567 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1568 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1570 float t = (float)j / segments;
1571 float tpow2 = t * t;
1572 float tpow3 = t * t * t;
1574 float invtpow2 = invt * invt;
1575 float invtpow3 = invt * invt * invt;
1577 float x = ( invtpow3 * x0
1578 + 3 * t * invtpow2 * x1
1579 + 3 * tpow2 * invt * x2
1581 float y = ( invtpow3 * y0
1582 + 3 * t * invtpow2 * y1
1583 + 3 * tpow2 * invt * y2
1585 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1586 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1587 // Test new point addition
1589 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1591 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1592 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1593 if(line_distance < shortest_line_distance ||
1594 shortest_point1 < 0) {
1595 shortest_line_distance = line_distance;
1596 shortest_point1 = i;
1597 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1598 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1599 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1602 // Test existing point selection
1604 if(gui->ctrl_down()) {
1605 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1607 if(distance < selected_control_point_distance) {
1609 selected_control_point = 1;
1610 selected_control_point_distance = distance;
1614 if(!gui->shift_down()) {
1615 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1616 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
1621 selected_point = shortest_point;
1624 // Test second point
1625 if(gui->ctrl_down()) {
1626 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1628 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1629 if(distance < selected_control_point_distance) {
1630 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1631 selected_control_point = 0;
1632 selected_control_point_distance = distance;
1635 else if(i < points.size() - 1) {
1636 if(!gui->shift_down()) {
1637 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1638 if(test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3)) {
1639 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1643 selected_point = shortest_point;
1648 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1652 if(draw) { // Draw joining line
1653 x_points.append((int)canvas_x);
1654 y_points.append((int)canvas_y);
1658 if(draw) { // Draw second anchor
1659 if(i < points.size() - 1) {
1660 if(i == gui->affected_point - 1)
1661 get_canvas()->draw_disc(
1662 (int)canvas_x - CONTROL_W / 2,
1663 (int)canvas_y - CONTROL_W / 2,
1664 CONTROL_W, CONTROL_H);
1666 get_canvas()->draw_circle(
1667 (int)canvas_x - CONTROL_W / 2,
1668 (int)canvas_y - CONTROL_W / 2,
1669 CONTROL_W, CONTROL_H);
1670 // char string[BCTEXTLEN];
1671 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1672 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1674 // Draw second control point.
1675 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1676 get_canvas()->draw_line(
1677 (int)canvas_x, (int)canvas_y,
1678 (int)canvas_x2, (int)canvas_y2);
1679 get_canvas()->draw_rectangle(
1680 (int)canvas_x2 - CONTROL_W / 2,
1681 (int)canvas_y2 - CONTROL_H / 2,
1682 CONTROL_W, CONTROL_H);
1687 // Draw first anchor
1688 if(i == 0 && draw) {
1689 char mask_label[BCSTRLEN];
1690 sprintf(mask_label, "%d",
1691 mwindow->edl->session->cwindow_mask);
1692 get_canvas()->draw_text(
1693 (int)canvas_x - FIRST_CONTROL_W,
1694 (int)canvas_y - FIRST_CONTROL_H,
1697 get_canvas()->draw_disc(
1698 (int)canvas_x - FIRST_CONTROL_W / 2,
1699 (int)canvas_y - FIRST_CONTROL_H / 2,
1700 FIRST_CONTROL_W, FIRST_CONTROL_H);
1703 // Draw first control point.
1705 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1706 get_canvas()->draw_line(
1707 (int)canvas_x, (int)canvas_y,
1708 (int)canvas_x1, (int)canvas_y1);
1709 get_canvas()->draw_rectangle(
1710 (int)canvas_x1 - CONTROL_W / 2,
1711 (int)canvas_y1 - CONTROL_H / 2,
1712 CONTROL_W, CONTROL_H);
1714 x_points.append((int)canvas_x);
1715 y_points.append((int)canvas_y);
1718 //printf("CWindowCanvas::do_mask 1\n");
1722 //printf("CWindowCanvas::do_mask 1\n");
1725 get_canvas()->draw_polygon(&x_points, &y_points);
1726 get_canvas()->set_opaque();
1728 //printf("CWindowCanvas::do_mask 1\n");
1731 if(button_press && !result) {
1732 gui->affected_track = gui->cwindow->calculate_affected_track();
1734 // Get keyframe outside the EDL to edit. This must be rendered
1735 // instead of the EDL keyframes when it exists. Then it must be
1736 // applied to the EDL keyframes on buttonrelease.
1737 if(gui->affected_track) {
1738 #ifdef USE_KEYFRAME_SPANNING
1739 // Make copy of current parameters in local keyframe
1740 gui->mask_keyframe =
1741 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1744 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1747 gui->mask_keyframe =
1748 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1753 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1756 // Translate entire keyframe
1757 if(gui->alt_down() && mask->points.size()) {
1758 mwindow->undo->update_undo_before(_("mask translate"), 0);
1759 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1760 gui->affected_point = 0;
1763 // Existing point or control point was selected
1764 if(selected_point >= 0) {
1765 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1766 gui->affected_point = selected_point;
1768 if(selected_control_point == 0)
1769 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1771 if(selected_control_point == 1)
1772 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1774 gui->current_operation = mwindow->edl->session->cwindow_operation;
1776 else // No existing point or control point was selected so create a new one
1777 if(!gui->ctrl_down() && !gui->alt_down()) {
1778 mwindow->undo->update_undo_before(_("mask point"), 0);
1779 // Create the template
1780 MaskPoint *point = new MaskPoint;
1781 point->x = mask_cursor_x;
1782 point->y = mask_cursor_y;
1783 point->control_x1 = 0;
1784 point->control_y1 = 0;
1785 point->control_x2 = 0;
1786 point->control_y2 = 0;
1789 if(shortest_point2 < shortest_point1) {
1790 shortest_point2 ^= shortest_point1;
1791 shortest_point1 ^= shortest_point2;
1792 shortest_point2 ^= shortest_point1;
1797 // printf("CWindowGUI::do_mask 40\n");
1798 // mwindow->edl->dump();
1799 // printf("CWindowGUI::do_mask 50\n");
1803 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1804 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1805 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1807 // Append to end of list
1808 if( shortest_point1 == shortest_point2 ||
1809 labs(shortest_point1 - shortest_point2) > 1) {
1810 #ifdef USE_KEYFRAME_SPANNING
1812 MaskPoint *new_point = new MaskPoint;
1813 points.append(new_point);
1814 *new_point = *point;
1815 gui->affected_point = points.size() - 1;
1819 // Need to apply the new point to every keyframe
1820 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1821 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1822 MaskPoint *new_point = new MaskPoint;
1823 submask->points.append(new_point);
1824 *new_point = *point;
1825 if(current == (MaskAuto*)mask_autos->default_auto)
1826 current = (MaskAuto*)mask_autos->first;
1828 current = (MaskAuto*)NEXT;
1830 gui->affected_point = mask->points.size() - 1;
1836 // Insert between 2 points, shifting back point 2
1837 if(shortest_point1 >= 0 && shortest_point2 >= 0) {
1839 #ifdef USE_KEYFRAME_SPANNING
1840 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1842 if(points.size() >= shortest_point2) {
1843 MaskPoint *new_point = new MaskPoint;
1845 for(int i = points.size() - 1;
1846 i > shortest_point2;
1848 points.values[i] = points.values[i - 1];
1849 points.values[shortest_point2] = new_point;
1851 *new_point = *point;
1856 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1857 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1858 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1860 if(submask->points.size() >= shortest_point2) {
1861 MaskPoint *new_point = new MaskPoint;
1862 submask->points.append(0);
1863 for(int i = submask->points.size() - 1;
1864 i > shortest_point2;
1866 submask->points.values[i] = submask->points.values[i - 1];
1867 submask->points.values[shortest_point2] = new_point;
1869 *new_point = *point;
1872 if(current == (MaskAuto*)mask_autos->default_auto)
1873 current = (MaskAuto*)mask_autos->first;
1875 current = (MaskAuto*)NEXT;
1879 gui->affected_point = shortest_point2;
1884 // printf("CWindowGUI::do_mask 20\n");
1885 // mwindow->edl->dump();
1886 // printf("CWindowGUI::do_mask 30\n");
1889 //printf("CWindowCanvas::do_mask 1\n");
1890 // Create the first point.
1891 #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;
1897 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1898 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1899 MaskPoint *new_point = new MaskPoint;
1900 submask->points.append(new_point);
1901 *new_point = *point;
1902 if(current == (MaskAuto*)mask_autos->default_auto)
1903 current = (MaskAuto*)mask_autos->first;
1905 current = (MaskAuto*)NEXT;
1907 gui->affected_point = points.size() - 1;
1910 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
1913 gui->current_operation = mwindow->edl->session->cwindow_operation;
1914 // Delete the template
1923 if(button_press && result) {
1924 #ifdef USE_KEYFRAME_SPANNING
1925 MaskPoint *point = points.values[gui->affected_point];
1926 gui->center_x = point->x;
1927 gui->center_y = point->y;
1928 gui->control_in_x = point->control_x1;
1929 gui->control_in_y = point->control_y1;
1930 gui->control_out_x = point->control_x2;
1931 gui->control_out_y = point->control_y2;
1932 gui->tool_panel->raise_window();
1934 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1935 MaskPoint *point = mask->points.values[gui->affected_point];
1936 gui->center_x = point->x;
1937 gui->center_y = point->y;
1938 gui->control_in_x = point->control_x1;
1939 gui->control_in_y = point->control_y1;
1940 gui->control_out_x = point->control_x2;
1941 gui->control_out_y = point->control_y2;
1942 gui->tool_panel->raise_window();
1946 //printf("CWindowCanvas::do_mask 8\n");
1949 #ifdef USE_KEYFRAME_SPANNING
1950 // Must update the reference keyframes for every cursor motion
1951 gui->mask_keyframe =
1952 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1955 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1958 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1960 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1961 if( gui->affected_point >= 0 && gui->affected_point < mask->points.size() &&
1962 gui->current_operation != CWINDOW_NONE) {
1963 // mwindow->undo->update_undo_before(_("mask point"), this);
1964 #ifdef USE_KEYFRAME_SPANNING
1965 MaskPoint *point = points.get(gui->affected_point);
1967 MaskPoint *point = mask->points.get(gui->affected_point);
1969 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
1970 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask->points.size(), gui->affected_point);
1972 float last_x = point->x;
1973 float last_y = point->y;
1974 float last_control_x1 = point->control_x1;
1975 float last_control_y1 = point->control_y1;
1976 float last_control_x2 = point->control_x2;
1977 float last_control_y2 = point->control_y2;
1979 switch(gui->current_operation) {
1981 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1982 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
1983 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
1986 case CWINDOW_MASK_CONTROL_IN:
1987 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
1988 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
1991 case CWINDOW_MASK_CONTROL_OUT:
1992 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
1993 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
1996 case CWINDOW_MASK_TRANSLATE:
1997 #ifdef USE_KEYFRAME_SPANNING
1998 for(int i = 0; i < points.size(); i++) {
1999 points.values[i]->x += mask_cursor_x - gui->x_origin;
2000 points.values[i]->y += mask_cursor_y - gui->y_origin;
2003 for(int i = 0; i < mask->points.size(); i++) {
2004 mask->points.values[i]->x += mask_cursor_x - gui->x_origin;
2005 mask->points.values[i]->y += mask_cursor_y - gui->y_origin;
2008 gui->x_origin = mask_cursor_x;
2009 gui->y_origin = mask_cursor_y;
2013 if( !EQUIV(last_x, point->x) ||
2014 !EQUIV(last_y, point->y) ||
2015 !EQUIV(last_control_x1, point->control_x1) ||
2016 !EQUIV(last_control_y1, point->control_y1) ||
2017 !EQUIV(last_control_x2, point->control_x2) ||
2018 !EQUIV(last_control_y2, point->control_y2)) {
2024 if(gui->current_operation == CWINDOW_NONE) {
2025 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
2027 for(int i = 0; i < points.size() && !over_point; i++) {
2028 MaskPoint *point = points.get(i);
2029 float x0 = point->x;
2030 float y0 = point->y;
2031 float x1 = point->x + point->control_x1;
2032 float y1 = point->y + point->control_y1;
2033 float x2 = point->x + point->control_x2;
2034 float y2 = point->y + point->control_y2;
2035 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
2036 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
2038 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
2039 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
2043 if(!over_point && gui->ctrl_down()) {
2044 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
2045 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
2046 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2047 if(test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1)) {
2051 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2052 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2053 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2054 if(test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2)) {
2061 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2066 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2069 #ifdef USE_KEYFRAME_SPANNING
2070 // Must commit change after operation.
2071 if(rerender && track) {
2072 // Swap EDL keyframe with original.
2073 // Apply new values to keyframe span
2074 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2075 temp_keyframe.copy_data(gui->mask_keyframe);
2076 // Apply interpolated points back to keyframe
2077 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2078 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2079 mask_autos->update_parameter(&temp_keyframe);
2083 points.remove_all_objects();
2084 //printf("CWindowCanvas::do_mask 20\n");
2088 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2091 int radius = mwindow->edl->session->eyedrop_radius;
2099 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2104 row1 = gui->eyedrop_y - radius;
2105 row2 = gui->eyedrop_y + radius;
2106 column1 = gui->eyedrop_x - radius;
2107 column2 = gui->eyedrop_x + radius;
2109 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2110 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2111 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2112 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2114 if(row2 <= row1) row2 = row1 + 1;
2115 if(column2 <= column1) column2 = column1 + 1;
2122 output_to_canvas(mwindow->edl, 0, x1, y1);
2123 output_to_canvas(mwindow->edl, 0, x2, y2);
2124 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2126 if(x2 - x1 >= 1 && y2 - y1 >= 1)
2128 get_canvas()->set_inverse();
2129 get_canvas()->set_color(WHITE);
2131 get_canvas()->draw_rectangle((int)x1,
2136 get_canvas()->set_opaque();
2137 get_canvas()->flash();
2145 gui->current_operation = CWINDOW_EYEDROP;
2146 gui->tool_panel->raise_window();
2149 if(gui->current_operation == CWINDOW_EYEDROP)
2151 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2153 // Get color out of frame.
2154 // Doesn't work during playback because that bypasses the refresh frame.
2155 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2157 float cursor_x = get_cursor_x();
2158 float cursor_y = get_cursor_y();
2159 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2160 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2161 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2163 row1 = cursor_y - radius;
2164 row2 = cursor_y + radius;
2165 column1 = cursor_x - radius;
2166 column2 = cursor_x + radius;
2167 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2168 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2169 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2170 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2171 if(row2 <= row1) row2 = row1 + 1;
2172 if(column2 <= column1) column2 = column1 + 1;
2176 if(gui->eyedrop_visible)
2179 do_eyedrop(temp, 0, 1);
2180 gui->eyedrop_visible = 0;
2183 gui->eyedrop_x = cursor_x;
2184 gui->eyedrop_y = cursor_y;
2189 do_eyedrop(temp, 0, 1);
2190 gui->eyedrop_visible = 1;
2193 // Decompression coefficients straight out of jpeglib
2194 #define V_TO_R 1.40200
2195 #define V_TO_G -0.71414
2197 #define U_TO_G -0.34414
2198 #define U_TO_B 1.77200
2200 #define GET_COLOR(type, components, max, do_yuv) \
2202 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2204 float red = (float)*row++ / max; \
2205 float green = (float)*row++ / max; \
2206 float blue = (float)*row++ / max; \
2209 float r = red + V_TO_R * (blue - 0.5); \
2210 float g = red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
2211 float b = red + U_TO_B * (green - 0.5); \
2212 mwindow->edl->local_session->red += r; \
2213 mwindow->edl->local_session->green += g; \
2214 mwindow->edl->local_session->blue += b; \
2215 if(r > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = r; \
2216 if(g > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = g; \
2217 if(b > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = b; \
2221 mwindow->edl->local_session->red += red; \
2222 mwindow->edl->local_session->green += green; \
2223 mwindow->edl->local_session->blue += blue; \
2224 if(red > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = red; \
2225 if(green > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = green; \
2226 if(blue > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = blue; \
2232 mwindow->edl->local_session->red = 0;
2233 mwindow->edl->local_session->green = 0;
2234 mwindow->edl->local_session->blue = 0;
2235 mwindow->edl->local_session->red_max = 0;
2236 mwindow->edl->local_session->green_max = 0;
2237 mwindow->edl->local_session->blue_max = 0;
2238 for(int i = row1; i < row2; i++)
2240 for(int j = column1; j < column2; j++)
2242 switch(refresh_frame->get_color_model())
2245 GET_COLOR(unsigned char, 3, 0xff, 1);
2248 GET_COLOR(unsigned char, 4, 0xff, 1);
2251 GET_COLOR(uint16_t, 3, 0xffff, 1);
2253 case BC_YUVA16161616:
2254 GET_COLOR(uint16_t, 4, 0xffff, 1);
2257 GET_COLOR(unsigned char, 3, 0xff, 0);
2260 GET_COLOR(unsigned char, 4, 0xff, 0);
2263 GET_COLOR(float, 3, 1.0, 0);
2266 GET_COLOR(float, 4, 1.0, 0);
2272 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2273 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2274 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2279 mwindow->edl->local_session->red = 0;
2280 mwindow->edl->local_session->green = 0;
2281 mwindow->edl->local_session->blue = 0;
2282 gui->eyedrop_visible = 0;
2291 // Can't rerender since the color value is from the output of any effect it
2294 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2300 void CWindowCanvas::draw_overlays()
2302 if(mwindow->edl->session->safe_regions)
2304 draw_safe_regions();
2307 if(mwindow->edl->session->cwindow_scrollbars)
2309 // Always draw output rectangle
2310 float x1, y1, x2, y2;
2312 x2 = mwindow->edl->session->output_w;
2314 y2 = mwindow->edl->session->output_h;
2315 output_to_canvas(mwindow->edl, 0, x1, y1);
2316 output_to_canvas(mwindow->edl, 0, x2, y2);
2318 get_canvas()->set_inverse();
2319 get_canvas()->set_color(WHITE);
2321 get_canvas()->draw_rectangle((int)x1,
2326 get_canvas()->set_opaque();
2329 if(gui->highlighted)
2331 get_canvas()->set_color(WHITE);
2332 get_canvas()->set_inverse();
2333 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2334 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2335 get_canvas()->set_opaque();
2338 int temp1 = 0, temp2 = 0;
2339 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2340 switch(mwindow->edl->session->cwindow_operation)
2342 case CWINDOW_CAMERA:
2346 case CWINDOW_PROJECTOR:
2355 do_mask(temp1, temp2, 0, 0, 1);
2359 do_ruler(1, 0, 0, 0);
2362 case CWINDOW_EYEDROP:
2363 if(gui->eyedrop_visible)
2366 do_eyedrop(rerender, 0, 1);
2367 gui->eyedrop_visible = 1;
2373 void CWindowCanvas::draw_safe_regions()
2375 float action_x1, action_x2, action_y1, action_y2;
2376 float title_x1, title_x2, title_y1, title_y2;
2378 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2379 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2380 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2381 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2382 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2383 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2384 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2385 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2387 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2388 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2389 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2390 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2392 get_canvas()->set_inverse();
2393 get_canvas()->set_color(WHITE);
2395 get_canvas()->draw_rectangle((int)action_x1,
2397 (int)(action_x2 - action_x1),
2398 (int)(action_y2 - action_y1));
2399 get_canvas()->draw_rectangle((int)title_x1,
2401 (int)(title_x2 - title_x1),
2402 (int)(title_y2 - title_y1));
2404 get_canvas()->set_opaque();
2407 void CWindowCanvas::reset_keyframe(int do_camera)
2409 FloatAuto *x_keyframe = 0;
2410 FloatAuto *y_keyframe = 0;
2411 FloatAuto *z_keyframe = 0;
2412 Track *affected_track = 0;
2414 affected_track = gui->cwindow->calculate_affected_track();
2418 gui->cwindow->calculate_affected_autos(&x_keyframe,
2427 x_keyframe->set_value(0);
2428 y_keyframe->set_value(0);
2429 z_keyframe->set_value(1);
2431 mwindow->sync_parameters(CHANGE_PARAMS);
2436 void CWindowCanvas::reset_camera()
2441 void CWindowCanvas::reset_projector()
2446 int CWindowCanvas::test_crop(int button_press, int &redraw)
2449 int handle_selected = -1;
2450 float x1 = mwindow->edl->session->crop_x1;
2451 float y1 = mwindow->edl->session->crop_y1;
2452 float x2 = mwindow->edl->session->crop_x2;
2453 float y2 = mwindow->edl->session->crop_y2;
2454 float cursor_x = get_cursor_x();
2455 float cursor_y = get_cursor_y();
2456 float canvas_x1 = x1;
2457 float canvas_y1 = y1;
2458 float canvas_x2 = x2;
2459 float canvas_y2 = y2;
2460 float canvas_cursor_x = cursor_x;
2461 float canvas_cursor_y = cursor_y;
2463 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2464 // Use screen normalized coordinates for hot spot tests.
2465 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2466 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2469 if(gui->current_operation == CWINDOW_CROP)
2471 handle_selected = gui->crop_handle;
2474 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2475 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2477 handle_selected = 0;
2478 gui->crop_origin_x = x1;
2479 gui->crop_origin_y = y1;
2482 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2483 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2485 handle_selected = 1;
2486 gui->crop_origin_x = x2;
2487 gui->crop_origin_y = y1;
2490 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2491 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2493 handle_selected = 2;
2494 gui->crop_origin_x = x1;
2495 gui->crop_origin_y = y2;
2498 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2499 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2501 handle_selected = 3;
2502 gui->crop_origin_x = x2;
2503 gui->crop_origin_y = y2;
2508 gui->crop_origin_x = cursor_x;
2509 gui->crop_origin_y = cursor_y;
2512 // printf("test crop %d %d\n",
2513 // gui->current_operation,
2514 // handle_selected);
2521 gui->crop_translate = 1;
2522 gui->crop_origin_x1 = x1;
2523 gui->crop_origin_y1 = y1;
2524 gui->crop_origin_x2 = x2;
2525 gui->crop_origin_y2 = y2;
2528 gui->crop_translate = 0;
2530 gui->current_operation = CWINDOW_CROP;
2531 gui->crop_handle = handle_selected;
2532 gui->x_origin = cursor_x;
2533 gui->y_origin = cursor_y;
2534 gui->tool_panel->raise_window();
2537 if(handle_selected < 0 && !gui->crop_translate)
2541 mwindow->edl->session->crop_x1 = (int)x1;
2542 mwindow->edl->session->crop_y1 = (int)y1;
2543 mwindow->edl->session->crop_x2 = (int)x2;
2544 mwindow->edl->session->crop_y2 = (int)y2;
2549 // Translate all 4 points
2550 if(gui->current_operation == CWINDOW_CROP && gui->crop_translate)
2552 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2553 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2554 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2555 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2557 mwindow->edl->session->crop_x1 = (int)x1;
2558 mwindow->edl->session->crop_y1 = (int)y1;
2559 mwindow->edl->session->crop_x2 = (int)x2;
2560 mwindow->edl->session->crop_y2 = (int)y2;
2566 if(gui->current_operation == CWINDOW_CROP)
2568 switch(gui->crop_handle)
2571 x1 = gui->crop_origin_x;
2572 y1 = gui->crop_origin_y;
2573 x2 = gui->crop_origin_x;
2574 y2 = gui->crop_origin_y;
2575 if(cursor_x < gui->x_origin)
2577 if(cursor_y < gui->y_origin)
2583 if(cursor_y >= gui->y_origin)
2590 if(cursor_x >= gui->x_origin)
2592 if(cursor_y < gui->y_origin)
2598 if(cursor_y >= gui->y_origin)
2605 // printf("test crop %d %d %d %d\n",
2606 // mwindow->edl->session->crop_x1,
2607 // mwindow->edl->session->crop_y1,
2608 // mwindow->edl->session->crop_x2,
2609 // mwindow->edl->session->crop_y2);
2612 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2613 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2616 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2617 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2620 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2621 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2624 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2625 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2629 if(!EQUIV(mwindow->edl->session->crop_x1, x1) ||
2630 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2631 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2632 !EQUIV(mwindow->edl->session->crop_y2, y2))
2639 switch (gui->crop_handle)
2641 case 0: gui->crop_handle = 1; break;
2642 case 1: gui->crop_handle = 0; break;
2643 case 2: gui->crop_handle = 3; break;
2644 case 3: gui->crop_handle = 2; break;
2654 switch (gui->crop_handle)
2656 case 0: gui->crop_handle = 2; break;
2657 case 1: gui->crop_handle = 3; break;
2658 case 2: gui->crop_handle = 0; break;
2659 case 3: gui->crop_handle = 1; break;
2664 mwindow->edl->session->crop_x1 = (int)x1;
2665 mwindow->edl->session->crop_y1 = (int)y1;
2666 mwindow->edl->session->crop_x2 = (int)x2;
2667 mwindow->edl->session->crop_y2 = (int)y2;
2673 // Update cursor font
2674 if(handle_selected >= 0)
2676 switch(handle_selected)
2679 set_cursor(UPLEFT_RESIZE);
2682 set_cursor(UPRIGHT_RESIZE);
2685 set_cursor(DOWNLEFT_RESIZE);
2688 set_cursor(DOWNRIGHT_RESIZE);
2695 set_cursor(ARROW_CURSOR);
2697 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2701 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2702 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2703 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2704 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2705 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2706 // mwindow->edl->session->crop_x2,
2707 // mwindow->edl->session->crop_y2,
2708 // mwindow->edl->calculate_output_w(0),
2709 // mwindow->edl->calculate_output_h(0));
2715 void CWindowCanvas::draw_crop()
2717 get_canvas()->set_inverse();
2718 get_canvas()->set_color(WHITE);
2720 float x1 = mwindow->edl->session->crop_x1;
2721 float y1 = mwindow->edl->session->crop_y1;
2722 float x2 = mwindow->edl->session->crop_x2;
2723 float y2 = mwindow->edl->session->crop_y2;
2725 output_to_canvas(mwindow->edl, 0, x1, y1);
2726 output_to_canvas(mwindow->edl, 0, x2, y2);
2728 if(x2 - x1 && y2 - y1)
2729 get_canvas()->draw_rectangle((int)x1,
2734 draw_crophandle((int)x1, (int)y1);
2735 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2736 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2737 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2738 get_canvas()->set_opaque();
2748 void CWindowCanvas::draw_bezier(int do_camera)
2750 Track *track = gui->cwindow->calculate_affected_track();
2757 int64_t position = track->to_units(
2758 mwindow->edl->local_session->get_selectionstart(1),
2761 track->automation->get_projector(¢er_x,
2767 // center_x += track->track_w / 2;
2768 // center_y += track->track_h / 2;
2769 center_x += mwindow->edl->session->output_w / 2;
2770 center_y += mwindow->edl->session->output_h / 2;
2771 float track_x1 = center_x - track->track_w / 2 * center_z;
2772 float track_y1 = center_y - track->track_h / 2 * center_z;
2773 float track_x2 = track_x1 + track->track_w * center_z;
2774 float track_y2 = track_y1 + track->track_h * center_z;
2776 output_to_canvas(mwindow->edl, 0, track_x1, track_y1);
2777 output_to_canvas(mwindow->edl, 0, track_x2, track_y2);
2779 #define DRAW_PROJECTION(offset) \
2780 get_canvas()->draw_rectangle((int)track_x1 + offset, \
2781 (int)track_y1 + offset, \
2782 (int)(track_x2 - track_x1), \
2783 (int)(track_y2 - track_y1)); \
2784 get_canvas()->draw_line((int)track_x1 + offset, \
2785 (int)track_y1 + offset, \
2786 (int)track_x2 + offset, \
2787 (int)track_y2 + offset); \
2788 get_canvas()->draw_line((int)track_x2 + offset, \
2789 (int)track_y1 + offset, \
2790 (int)track_x1 + offset, \
2791 (int)track_y2 + offset); \
2795 get_canvas()->set_color(BLACK);
2798 // canvas->set_inverse();
2800 get_canvas()->set_color(GREEN);
2802 get_canvas()->set_color(RED);
2805 // canvas->set_opaque();
2809 int CWindowCanvas::test_bezier(int button_press,
2817 // Processing drag operation.
2818 // Create keyframe during first cursor motion.
2822 float cursor_x = get_cursor_x();
2823 float cursor_y = get_cursor_y();
2824 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2826 if(gui->current_operation == CWINDOW_CAMERA ||
2827 gui->current_operation == CWINDOW_PROJECTOR)
2829 if(!gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom)
2831 gui->translating_zoom = 1;
2832 gui->reset_affected();
2835 if(!gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom)
2837 gui->translating_zoom = 0;
2838 gui->reset_affected();
2841 // Get target keyframe
2842 float last_center_x;
2843 float last_center_y;
2844 float last_center_z;
2847 if(!gui->affected_x && !gui->affected_y && !gui->affected_z)
2849 FloatAutos *affected_x_autos;
2850 FloatAutos *affected_y_autos;
2851 FloatAutos *affected_z_autos;
2852 if(!gui->affected_track) return 0;
2853 double position = mwindow->edl->local_session->get_selectionstart(1);
2854 int64_t track_position = gui->affected_track->to_units(position, 0);
2856 if(mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA)
2858 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_X];
2859 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Y];
2860 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Z];
2864 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_X];
2865 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Y];
2866 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Z];
2870 if(gui->translating_zoom)
2872 FloatAuto *previous = 0;
2873 FloatAuto *next = 0;
2874 float new_z = affected_z_autos->get_value(
2880 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2881 affected_z_autos, 1, &created, 0);
2883 gui->affected_z->set_value(new_z);
2889 FloatAuto *previous = 0;
2890 FloatAuto *next = 0;
2891 float new_x = affected_x_autos->get_value(
2898 float new_y = affected_y_autos->get_value(
2904 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2905 affected_x_autos, 1, &created, 0);
2907 gui->affected_x->set_value(new_x);
2911 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2912 affected_y_autos, 1, &created, 0);
2914 gui->affected_y->set_value(new_y);
2921 if(gui->translating_zoom)
2923 gui->center_z = gui->affected_z->get_value();
2927 gui->center_x = gui->affected_x->get_value();
2928 gui->center_y = gui->affected_y->get_value();
2935 if(gui->translating_zoom)
2937 last_center_z = gui->affected_z->get_value();
2938 float z = gui->center_z + (cursor_y - gui->y_origin) / 128;
2940 if(!EQUIV(last_center_z, z))
2946 gui->affected_z->set_value(z);
2950 last_center_x = gui->affected_x->get_value();
2951 last_center_y = gui->affected_y->get_value();
2952 float x = gui->center_x + cursor_x - gui->x_origin;
2953 float y = gui->center_y + cursor_y - gui->y_origin;
2954 gui->affected_x->set_value(x);
2955 gui->affected_y->set_value(y);
2956 if( !EQUIV(last_center_x, x) || !EQUIV(last_center_y, y) )
2962 gui->affected_x->set_value(x);
2963 gui->affected_y->set_value(y);
2970 // Begin drag operation. Don't create keyframe here.
2972 // Get affected track off of the first recordable video track.
2973 // Calculating based on the alpha channel would require recording what layer
2974 // each output pixel belongs to as they're rendered and stacked. Forget it.
2975 gui->affected_track = gui->cwindow->calculate_affected_track();
2976 gui->reset_affected();
2978 if(gui->affected_track)
2980 if(gui->current_operation == CWINDOW_CAMERA)
2981 mwindow->undo->update_undo_before(_("camera"), this);
2983 mwindow->undo->update_undo_before(_("projector"), this);
2985 gui->current_operation =
2986 mwindow->edl->session->cwindow_operation;
2987 gui->tool_panel->raise_window();
2996 int CWindowCanvas::test_zoom(int &redraw)
3002 if( mwindow->edl->session->cwindow_scrollbars ) {
3003 if( *gui->zoom_panel->get_text() != 'x' ) {
3004 // Find current zoom in table
3005 int idx = total_zooms; float old_zoom = get_zoom();
3006 while( --idx >= 0 && !EQUIV(my_zoom_table[idx], old_zoom) );
3008 idx += get_buttonpress() == 5 ||
3009 gui->ctrl_down() || gui->shift_down() ? -1 : +1 ;
3010 CLAMP(idx, 0, total_zooms-1);
3011 zoom = my_zoom_table[idx];
3014 x = get_cursor_x(); y = get_cursor_y();
3016 mwindow->edl->session->cwindow_scrollbars = 0;
3017 gui->zoom_panel->update(0);
3018 zoom = gui->get_auto_zoom();
3021 gui->zoom_panel->ZoomPanel::update(zoom);
3022 float output_x = x, output_y = y;
3023 canvas_to_output(mwindow->edl, 0, output_x, output_y);
3024 x = output_x - x / zoom;
3025 y = output_y - y / zoom;
3029 mwindow->edl->session->cwindow_scrollbars = 1;
3030 x = (mwindow->edl->session->output_w - w) / 2;
3031 y = (mwindow->edl->session->output_h - h) / 2;
3034 update_zoom((int)x, (int)y, zoom);
3036 gui->composite_panel->cpanel_zoom->update(zoom);
3038 reposition_window(mwindow->edl,
3039 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
3040 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
3041 redraw = 1; result = 1;
3047 void CWindowCanvas::calculate_origin()
3049 gui->x_origin = get_cursor_x();
3050 gui->y_origin = get_cursor_y();
3051 //printf("CWindowCanvas::calculate_origin 1 %f %f\n", gui->x_origin, gui->y_origin);
3052 canvas_to_output(mwindow->edl, 0, gui->x_origin, gui->y_origin);
3053 //printf("CWindowCanvas::calculate_origin 2 %f %f\n", gui->x_origin, gui->y_origin);
3057 int CWindowCanvas::cursor_leave_event()
3059 set_cursor(ARROW_CURSOR);
3063 int CWindowCanvas::cursor_enter_event()
3066 switch(mwindow->edl->session->cwindow_operation)
3068 case CWINDOW_CAMERA:
3069 case CWINDOW_PROJECTOR:
3070 set_cursor(MOVE_CURSOR);
3073 set_cursor(MOVE_CURSOR);
3076 test_crop(0, redraw);
3078 case CWINDOW_PROTECT:
3079 set_cursor(ARROW_CURSOR);
3083 set_cursor(CROSS_CURSOR);
3085 case CWINDOW_EYEDROP:
3086 set_cursor(CROSS_CURSOR);
3092 int CWindowCanvas::cursor_motion_event()
3094 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3097 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3098 switch(gui->current_operation)
3100 case CWINDOW_SCROLL:
3102 float zoom = get_zoom();
3103 float cursor_x = get_cursor_x();
3104 float cursor_y = get_cursor_y();
3106 float zoom_x, zoom_y, conformed_w, conformed_h;
3107 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3108 cursor_x = (float)cursor_x / zoom_x + gui->x_offset;
3109 cursor_y = (float)cursor_y / zoom_y + gui->y_offset;
3113 int x = (int)(gui->x_origin - cursor_x + gui->x_offset);
3114 int y = (int)(gui->y_origin - cursor_y + gui->y_offset);
3119 update_scrollbars(0);
3126 result = do_ruler(0, 1, 0, 0);
3129 case CWINDOW_CAMERA:
3130 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3133 case CWINDOW_PROJECTOR:
3134 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3139 result = test_crop(0, redraw);
3140 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3147 case CWINDOW_MASK_CONTROL_IN:
3148 case CWINDOW_MASK_CONTROL_OUT:
3149 case CWINDOW_MASK_TRANSLATE:
3151 result = do_mask(redraw,
3158 case CWINDOW_EYEDROP:
3159 result = do_eyedrop(rerender, 0, 0);
3168 // cursor font changes
3171 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3173 // mwindow->edl->session->cwindow_operation);
3174 switch(mwindow->edl->session->cwindow_operation)
3177 result = test_crop(0, redraw);
3180 result = do_ruler(0, 1, 0, 0);
3183 result = do_mask(redraw,
3193 // If the window is never unlocked before calling send_command the
3194 // display shouldn't get stuck on the old video frame although it will
3195 // flicker between the old video frame and the new video frame.
3205 gui->unlock_window();
3208 mwindow->gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3209 mwindow->gui->draw_overlays(1);
3210 mwindow->gui->unlock_window();
3212 gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3217 gui->unlock_window();
3218 mwindow->restart_brender();
3219 mwindow->sync_parameters(CHANGE_PARAMS);
3220 mwindow->cwindow->refresh_frame(CHANGE_NONE);
3221 if(!redraw) gui->update_tool();
3222 gui->lock_window("CWindowCanvas::cursor_motion_event 2");
3227 int CWindowCanvas::button_press_event()
3231 int redraw_canvas = 0;
3234 if(Canvas::button_press_event()) return 1;
3236 gui->translating_zoom = gui->shift_down();
3239 //printf("CWindowCanvas::button_press_event 2 %f %f\n", gui->x_origin, gui->y_origin, gui->x_origin, gui->y_origin);
3241 float zoom_x, zoom_y, conformed_w, conformed_h;
3242 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3243 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3244 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3247 if( mwindow->edl->session->cwindow_operation != CWINDOW_PROTECT &&
3248 get_buttonpress() == 2 )
3250 gui->current_operation = CWINDOW_SCROLL;
3256 switch(mwindow->edl->session->cwindow_operation)
3259 result = do_ruler(0, 0, 1, 0);
3262 case CWINDOW_CAMERA:
3263 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3266 case CWINDOW_PROJECTOR:
3267 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3271 result = test_zoom(redraw);
3275 result = test_crop(1, redraw);
3279 if(get_buttonpress() == 1)
3280 result = do_mask(redraw, rerender, 1, 0, 0);
3283 case CWINDOW_EYEDROP:
3284 result = do_eyedrop(rerender, 1, 0);
3292 gui->unlock_window();
3295 mwindow->gui->lock_window("CWindowCanvas::button_press_event 1");
3296 mwindow->gui->draw_overlays(1);
3297 mwindow->gui->unlock_window();
3300 gui->lock_window("CWindowCanvas::button_press_event 1");
3303 // rerendering can also be caused by press event
3306 gui->unlock_window();
3308 mwindow->restart_brender();
3309 mwindow->sync_parameters(CHANGE_PARAMS);
3310 mwindow->cwindow->refresh_frame(CHANGE_NONE);
3311 if(!redraw) gui->update_tool();
3312 gui->lock_window("CWindowCanvas::button_press_event 2");
3317 int CWindowCanvas::button_release_event()
3321 switch(gui->current_operation)
3323 case CWINDOW_SCROLL:
3328 do_ruler(0, 0, 0, 1);
3331 case CWINDOW_CAMERA:
3332 mwindow->undo->update_undo_after(_("camera"), LOAD_AUTOMATION);
3335 case CWINDOW_PROJECTOR:
3336 mwindow->undo->update_undo_after(_("projector"), LOAD_AUTOMATION);
3340 case CWINDOW_MASK_CONTROL_IN:
3341 case CWINDOW_MASK_CONTROL_OUT:
3342 case CWINDOW_MASK_TRANSLATE:
3343 // Finish mask operation
3344 gui->mask_keyframe = 0;
3345 mwindow->undo->update_undo_after(_("mask"), LOAD_AUTOMATION);
3348 result = Canvas::button_release_event();
3352 gui->current_operation = CWINDOW_NONE;
3356 void CWindowCanvas::zoom_resize_window(float percentage)
3358 int canvas_w, canvas_h;
3362 // Get required canvas size
3363 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3364 mwindow->edl->session->output_w,
3365 mwindow->edl->session->output_h,
3370 // Estimate window size from current borders
3371 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3372 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3374 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3375 mwindow->session->cwindow_w = new_w;
3376 mwindow->session->cwindow_h = new_h;
3378 mwindow->theme->get_cwindow_sizes(gui,
3379 mwindow->session->cwindow_controls);
3381 // Estimate again from new borders
3382 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3383 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3384 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3386 gui->resize_window(new_w, new_h);
3387 gui->resize_event(new_w, new_h);
3390 void CWindowCanvas::toggle_controls()
3392 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3393 gui->resize_event(gui->get_w(), gui->get_h());
3396 int CWindowCanvas::get_cwindow_controls()
3398 return mwindow->session->cwindow_controls;