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 mwindow->edl->session->cwindow_scrollbars = !value ? 0 : 1;
401 float cx = canvas->get_xscroll() + 0.5f*canvas->w_visible;
402 float cy = canvas->get_yscroll() + 0.5f*canvas->h_visible;
403 float output_x = cx, output_y = cy;
404 canvas->output_to_canvas(mwindow->edl, 0, cx, cy);
405 x = output_x - cx / zoom;
406 y = output_y - cy / zoom;
408 canvas->update_zoom((int)(x+0.5), (int)(y+0.5), zoom);
411 zoom_panel->update(value);
412 if( mwindow->edl->session->cwindow_operation == CWINDOW_ZOOM )
413 composite_panel->cpanel_zoom->update(zoom);
415 canvas->reposition_window(mwindow->edl,
416 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
417 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
418 canvas->draw_refresh();
421 void CWindowGUI::set_operation(int value)
424 case CWINDOW_TOOL_WINDOW:
425 mwindow->edl->session->tool_window = !mwindow->edl->session->tool_window;
426 composite_panel->operation[CWINDOW_TOOL_WINDOW]->update(mwindow->edl->session->tool_window);
427 tool_panel->update_show_window();
429 case CWINDOW_TITLESAFE:
430 mwindow->edl->session->safe_regions = !mwindow->edl->session->safe_regions;
431 composite_panel->operation[CWINDOW_TITLESAFE]->update(mwindow->edl->session->safe_regions);
432 value = mwindow->edl->session->cwindow_operation;
435 mwindow->edl->session->cwindow_operation = value;
436 composite_panel->set_operation(value);
440 edit_panel->update();
441 tool_panel->start_tool(value);
442 canvas->draw_refresh();
445 void CWindowGUI::update_tool()
447 tool_panel->update_values();
450 int CWindowGUI::close_event()
452 cwindow->hide_window();
457 int CWindowGUI::keypress_event()
460 int cwindow_operation = CWINDOW_NONE;
462 switch(get_keypress())
480 if(mwindow->session->cwindow_fullscreen)
481 canvas->stop_fullscreen();
483 canvas->start_fullscreen();
484 lock_window("CWindowGUI::keypress_event 1");
488 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
490 mwindow->gui->unlock_window();
491 lock_window("CWindowGUI::keypress_event 2");
495 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
496 mwindow->clear_entry();
497 mwindow->gui->unlock_window();
498 lock_window("CWindowGUI::keypress_event 3");
502 if(mwindow->session->cwindow_fullscreen)
503 canvas->stop_fullscreen();
504 lock_window("CWindowGUI::keypress_event 4");
508 int alt_down = this->alt_down();
509 int shift_down = this->shift_down();
512 mwindow->gui->lock_window("CWindowGUI::keypress_event 5");
514 mwindow->prev_edit_handle(shift_down);
516 mwindow->move_left();
517 mwindow->gui->unlock_window();
518 lock_window("CWindowGUI::keypress_event 6");
524 if( !ctrl_down() && !alt_down() ) {
527 mwindow->gui->lock_window("CWindowGUI::keypress_event 7");
528 mwindow->move_left();
529 mwindow->gui->unlock_window();
530 lock_window("CWindowGUI::keypress_event 8");
537 int alt_down = this->alt_down();
538 int shift_down = this->shift_down();
541 mwindow->gui->lock_window("CWindowGUI::keypress_event 8");
543 mwindow->next_edit_handle(shift_down);
545 mwindow->move_right();
546 mwindow->gui->unlock_window();
547 lock_window("CWindowGUI::keypress_event 9");
553 if( !ctrl_down() && !alt_down() ) {
556 mwindow->gui->lock_window("CWindowGUI::keypress_event 10");
557 mwindow->move_right();
558 mwindow->gui->unlock_window();
559 lock_window("CWindowGUI::keypress_event 11");
564 case KEY_F1: cwindow_operation = CWINDOW_PROTECT; break;
565 case KEY_F2: cwindow_operation = CWINDOW_ZOOM; break;
566 case KEY_F3: cwindow_operation = CWINDOW_MASK; break;
567 case KEY_F4: cwindow_operation = CWINDOW_RULER; break;
568 case KEY_F5: cwindow_operation = CWINDOW_CAMERA; break;
569 case KEY_F6: cwindow_operation = CWINDOW_PROJECTOR; break;
570 case KEY_F7: cwindow_operation = CWINDOW_CROP; break;
571 case KEY_F8: cwindow_operation = CWINDOW_EYEDROP; break;
572 case KEY_F9: cwindow_operation = CWINDOW_TOOL_WINDOW; break;
573 case KEY_F10: cwindow_operation = CWINDOW_TITLESAFE; break;
576 if( cwindow_operation >= 0 ) {
577 set_operation(cwindow_operation);
581 if(!result) result = transport->keypress_event();
587 void CWindowGUI::reset_affected()
594 void CWindowGUI::keyboard_zoomin()
596 // if(mwindow->edl->session->cwindow_scrollbars)
598 zoom_panel->zoom_tumbler->handle_up_event();
605 void CWindowGUI::keyboard_zoomout()
607 // if(mwindow->edl->session->cwindow_scrollbars)
609 zoom_panel->zoom_tumbler->handle_down_event();
617 void CWindowGUI::drag_motion()
619 if(get_hidden()) return;
621 if(mwindow->session->current_operation != DRAG_ASSET &&
622 mwindow->session->current_operation != DRAG_VTRANSITION &&
623 mwindow->session->current_operation != DRAG_VEFFECT) return;
624 int need_highlight = cursor_above() && get_cursor_over_window();
625 if( highlighted == need_highlight ) return;
626 highlighted = need_highlight;
627 canvas->draw_refresh();
630 int CWindowGUI::drag_stop()
633 if(get_hidden()) return 0;
634 if( !highlighted ) return 0;
635 if( mwindow->session->current_operation != DRAG_ASSET &&
636 mwindow->session->current_operation != DRAG_VTRANSITION &&
637 mwindow->session->current_operation != DRAG_VEFFECT) return 0;
639 canvas->draw_refresh();
642 if(mwindow->session->current_operation == DRAG_ASSET)
644 if(mwindow->session->drag_assets->total ||
645 mwindow->session->drag_clips->total)
647 mwindow->gui->lock_window("CWindowGUI::drag_stop 5");
648 mwindow->undo->update_undo_before(_("insert assets"), 0);
649 mwindow->gui->unlock_window();
652 if(mwindow->session->drag_assets->total)
654 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
656 mwindow->load_assets(mwindow->session->drag_assets,
657 mwindow->edl->local_session->get_selectionstart(),
659 mwindow->session->track_highlighted,
661 mwindow->edl->session->labels_follow_edits,
662 mwindow->edl->session->plugins_follow_edits,
663 mwindow->edl->session->autos_follow_edits,
667 if(mwindow->session->drag_clips->total)
669 mwindow->gui->lock_window("CWindowGUI::drag_stop 2");
671 mwindow->paste_edls(mwindow->session->drag_clips,
673 mwindow->session->track_highlighted,
674 mwindow->edl->local_session->get_selectionstart(),
675 mwindow->edl->session->labels_follow_edits,
676 mwindow->edl->session->plugins_follow_edits,
677 mwindow->edl->session->autos_follow_edits,
681 if(mwindow->session->drag_assets->total ||
682 mwindow->session->drag_clips->total)
684 mwindow->save_backup();
685 mwindow->restart_brender();
686 mwindow->gui->update(1, 1, 1, 1, 0, 1, 0);
687 mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
688 mwindow->gui->unlock_window();
689 mwindow->sync_parameters(LOAD_ALL);
693 if(mwindow->session->current_operation == DRAG_VEFFECT)
695 //printf("CWindowGUI::drag_stop 1\n");
696 Track *affected_track = cwindow->calculate_affected_track();
697 //printf("CWindowGUI::drag_stop 2\n");
699 mwindow->gui->lock_window("CWindowGUI::drag_stop 3");
700 mwindow->insert_effects_cwindow(affected_track);
701 mwindow->session->current_operation = NO_OPERATION;
702 mwindow->gui->unlock_window();
705 if(mwindow->session->current_operation == DRAG_VTRANSITION)
707 Track *affected_track = cwindow->calculate_affected_track();
708 mwindow->gui->lock_window("CWindowGUI::drag_stop 4");
709 mwindow->paste_transition_cwindow(affected_track);
710 mwindow->session->current_operation = NO_OPERATION;
711 mwindow->gui->unlock_window();
717 void CWindowGUI::update_meters()
719 if(mwindow->edl->session->cwindow_meter != meters->visible)
721 meters->set_meters(meters->meter_count, mwindow->edl->session->cwindow_meter);
722 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
723 resize_event(get_w(), get_h());
727 void CWindowGUI::stop_transport(const char *lock_msg)
729 if( lock_msg ) unlock_window();
730 mwindow->stop_transport();
731 if( lock_msg ) lock_window(lock_msg);
735 CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
736 : EditPanel(mwindow, cwindow->gui, CWINDOW_ID,
737 mwindow->theme->cedit_x, mwindow->theme->cedit_y,
738 mwindow->edl->session->editing_mode,
739 0, // use_editing_mode
758 this->mwindow = mwindow;
759 this->cwindow = cwindow;
762 #define CWrapper(fn) void CWindowEditing::fn() { \
763 mwindow->gui->lock_window("CWrapper::" #fn); \
765 mwindow->gui->unlock_window(); \
768 CWrapper(copy_selection)
769 CWrapper(splice_selection)
770 CWrapper(overwrite_selection)
771 CWrapper(set_inpoint)
772 CWrapper(set_outpoint)
773 CWrapper(unset_inoutpoint)
774 CWrapper(toggle_label)
776 #define CWrapper_cut(fn) void CWindowEditing::fn(int cut) { \
777 mwindow->gui->lock_window("CWrapper::" #fn); \
778 EditPanel::fn(cut); \
779 mwindow->gui->unlock_window(); \
781 CWrapper_cut(prev_label)
782 CWrapper_cut(next_label)
783 CWrapper_cut(prev_edit)
784 CWrapper_cut(next_edit)
786 void CWindowEditing::to_clip()
788 mwindow->to_clip(mwindow->edl, _("composer window: "), 0);
792 CWindowMeters::CWindowMeters(MWindow *mwindow,
797 : MeterPanel(mwindow,
803 mwindow->edl->session->audio_channels,
804 mwindow->edl->session->cwindow_meter,
808 this->mwindow = mwindow;
812 CWindowMeters::~CWindowMeters()
816 int CWindowMeters::change_status_event(int new_status)
818 mwindow->edl->session->cwindow_meter = new_status;
819 gui->update_meters();
826 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
827 : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
828 x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
830 this->mwindow = mwindow;
834 CWindowZoom::~CWindowZoom()
838 void CWindowZoom::update(double value)
840 char string[BCSTRLEN];
841 const char *cp = string;
844 int frac = value >= 1.0f ? 1 :
846 value >= .01f ? 3 : 4;
847 sprintf(string, "x %.*f", frac, value);
851 ZoomPanel::update(cp);
854 int CWindowZoom::handle_event()
856 double value = !strcasecmp(gui->auto_zoom, get_text()) ? 0 : get_value();
857 gui->zoom_canvas(value, 0);
864 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
865 : BC_PercentageSlider(x,
874 this->mwindow = mwindow;
875 this->cwindow = cwindow;
876 set_precision(0.00001);
879 CWindowSlider::~CWindowSlider()
883 int CWindowSlider::handle_event()
885 cwindow->update_position((double)get_value());
889 void CWindowSlider::set_position()
891 double new_length = mwindow->edl->tracks->total_length();
892 // if(mwindow->edl->local_session->preview_end <= 0 ||
893 // mwindow->edl->local_session->preview_end > new_length)
894 // mwindow->edl->local_session->preview_end = new_length;
895 // if(mwindow->edl->local_session->preview_start >
896 // mwindow->edl->local_session->preview_end)
897 // mwindow->edl->local_session->preview_start = 0;
900 update(mwindow->theme->cslider_w,
901 mwindow->edl->local_session->get_selectionstart(1),
904 // mwindow->edl->local_session->preview_start,
905 // mwindow->edl->local_session->preview_end);
909 int CWindowSlider::increase_value()
912 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
913 lock_window("CWindowSlider::increase_value");
917 int CWindowSlider::decrease_value()
920 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
921 lock_window("CWindowSlider::decrease_value");
926 // CWindowDestination::CWindowDestination(MWindow *mwindow, CWindowGUI *cwindow, int x, int y)
927 // : BC_PopupTextBox(cwindow,
928 // &cwindow->destinations,
929 // cwindow->destinations.values[cwindow->cwindow->destination]->get_text(),
935 // this->mwindow = mwindow;
936 // this->cwindow = cwindow;
939 // CWindowDestination::~CWindowDestination()
943 // int CWindowDestination::handle_event()
954 CWindowTransport::CWindowTransport(MWindow *mwindow,
958 : PlayTransport(mwindow,
966 EDL* CWindowTransport::get_edl()
971 void CWindowTransport::goto_start()
973 gui->unlock_window();
974 handle_transport(REWIND, 1);
976 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
977 mwindow->goto_start();
978 mwindow->gui->unlock_window();
980 gui->lock_window("CWindowTransport::goto_start 2");
983 void CWindowTransport::goto_end()
985 gui->unlock_window();
986 handle_transport(GOTO_END, 1);
988 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
990 mwindow->gui->unlock_window();
992 gui->lock_window("CWindowTransport::goto_end 2");
997 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
1000 mwindow->theme->ccanvas_x,
1001 mwindow->theme->ccanvas_y,
1002 mwindow->theme->ccanvas_w,
1003 mwindow->theme->ccanvas_h,
1006 mwindow->edl->session->cwindow_scrollbars)
1008 this->mwindow = mwindow;
1012 void CWindowCanvas::status_event()
1014 gui->draw_status(1);
1017 int CWindowCanvas::get_fullscreen()
1019 return mwindow->session->cwindow_fullscreen;
1022 void CWindowCanvas::set_fullscreen(int value)
1024 mwindow->session->cwindow_fullscreen = value;
1028 void CWindowCanvas::update_zoom(int x, int y, float zoom)
1030 use_scrollbars = mwindow->edl->session->cwindow_scrollbars;
1032 mwindow->edl->session->cwindow_xscroll = x;
1033 mwindow->edl->session->cwindow_yscroll = y;
1034 mwindow->edl->session->cwindow_zoom = zoom;
1037 void CWindowCanvas::zoom_auto()
1039 gui->zoom_canvas(0, 1);
1042 int CWindowCanvas::get_xscroll()
1044 return mwindow->edl->session->cwindow_xscroll;
1047 int CWindowCanvas::get_yscroll()
1049 return mwindow->edl->session->cwindow_yscroll;
1053 float CWindowCanvas::get_zoom()
1055 return mwindow->edl->session->cwindow_zoom;
1058 void CWindowCanvas::draw_refresh(int flush)
1060 if(get_canvas() && !get_canvas()->get_video_on())
1063 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
1065 float in_x1, in_y1, in_x2, in_y2;
1066 float out_x1, out_y1, out_x2, out_y2;
1067 get_transfers(mwindow->edl,
1077 if(!EQUIV(out_x1, 0) ||
1078 !EQUIV(out_y1, 0) ||
1079 !EQUIV(out_x2, get_canvas()->get_w()) ||
1080 !EQUIV(out_y2, get_canvas()->get_h()))
1082 get_canvas()->clear_box(0,
1084 get_canvas()->get_w(),
1085 get_canvas()->get_h());
1088 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1089 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1092 if(out_x2 > out_x1 &&
1097 // Can't use OpenGL here because it is called asynchronously of the
1098 // playback operation.
1099 get_canvas()->draw_vframe(refresh_frame,
1102 (int)(out_x2 - out_x1),
1103 (int)(out_y2 - out_y1),
1106 (int)(in_x2 - in_x1),
1107 (int)(in_y2 - in_y1),
1113 get_canvas()->clear_box(0,
1115 get_canvas()->get_w(),
1116 get_canvas()->get_h());
1120 get_canvas()->flash(flush);
1122 //printf("CWindowCanvas::draw_refresh 10\n");
1125 #define CROPHANDLE_W 10
1126 #define CROPHANDLE_H 10
1128 void CWindowCanvas::draw_crophandle(int x, int y)
1130 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1138 #define CONTROL_W 10
1139 #define CONTROL_H 10
1140 #define FIRST_CONTROL_W 20
1141 #define FIRST_CONTROL_H 20
1143 #define BC_INFINITY 65536
1145 #define RULERHANDLE_W 16
1146 #define RULERHANDLE_H 16
1150 int CWindowCanvas::do_ruler(int draw,
1156 float x1 = mwindow->edl->session->ruler_x1;
1157 float y1 = mwindow->edl->session->ruler_y1;
1158 float x2 = mwindow->edl->session->ruler_x2;
1159 float y2 = mwindow->edl->session->ruler_y2;
1160 float canvas_x1 = x1;
1161 float canvas_y1 = y1;
1162 float canvas_x2 = x2;
1163 float canvas_y2 = y2;
1164 float output_x = get_cursor_x();
1165 float output_y = get_cursor_y();
1166 float canvas_cursor_x = output_x;
1167 float canvas_cursor_y = output_y;
1169 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1170 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1171 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1172 mwindow->session->cwindow_output_x = roundf(output_x);
1173 mwindow->session->cwindow_output_y = roundf(output_y);
1175 if(button_press && get_buttonpress() == 1)
1177 gui->ruler_handle = -1;
1178 gui->ruler_translate = 0;
1181 gui->ruler_translate = 1;
1182 gui->ruler_origin_x = x1;
1183 gui->ruler_origin_y = y1;
1186 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1187 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1188 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1189 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1191 gui->ruler_handle = 0;
1192 gui->ruler_origin_x = x1;
1193 gui->ruler_origin_y = y1;
1196 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1197 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1198 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1199 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1201 gui->ruler_handle = 1;
1202 gui->ruler_origin_x = x2;
1203 gui->ruler_origin_y = y2;
1207 // Start new selection
1208 if(!gui->ruler_translate &&
1209 (gui->ruler_handle < 0 ||
1214 do_ruler(1, 0, 0, 0);
1215 get_canvas()->flash();
1216 gui->ruler_handle = 1;
1217 mwindow->edl->session->ruler_x1 = output_x;
1218 mwindow->edl->session->ruler_y1 = output_y;
1219 mwindow->edl->session->ruler_x2 = output_x;
1220 mwindow->edl->session->ruler_y2 = output_y;
1221 gui->ruler_origin_x = mwindow->edl->session->ruler_x2;
1222 gui->ruler_origin_y = mwindow->edl->session->ruler_y2;
1225 gui->x_origin = output_x;
1226 gui->y_origin = output_y;
1227 gui->current_operation = CWINDOW_RULER;
1228 gui->tool_panel->raise_window();
1234 if(gui->current_operation == CWINDOW_RULER)
1236 if(gui->ruler_translate)
1239 do_ruler(1, 0, 0, 0);
1240 float x_difference = mwindow->edl->session->ruler_x1;
1241 float y_difference = mwindow->edl->session->ruler_y1;
1242 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1243 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1244 x_difference -= mwindow->edl->session->ruler_x1;
1245 y_difference -= mwindow->edl->session->ruler_y1;
1246 mwindow->edl->session->ruler_x2 -= x_difference;
1247 mwindow->edl->session->ruler_y2 -= y_difference;
1249 do_ruler(1, 0, 0, 0);
1250 get_canvas()->flash();
1254 switch(gui->ruler_handle)
1257 do_ruler(1, 0, 0, 0);
1258 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1259 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1260 if(gui->alt_down() || gui->ctrl_down())
1262 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1263 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1267 double distance_value =
1268 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1269 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1270 if(angle_value < 22)
1271 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2;
1273 if(angle_value > 67)
1274 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2;
1276 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 &&
1277 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1279 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1280 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1283 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 && mwindow->edl->session->ruler_y1 > mwindow->edl->session->ruler_y2)
1285 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1286 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1289 if(mwindow->edl->session->ruler_x1 > mwindow->edl->session->ruler_x2 &&
1290 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1292 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1293 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1297 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1298 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1301 do_ruler(1, 0, 0, 0);
1302 get_canvas()->flash();
1307 do_ruler(1, 0, 0, 0);
1308 mwindow->edl->session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1309 mwindow->edl->session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1310 if(gui->alt_down() || gui->ctrl_down())
1312 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1313 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1317 double distance_value =
1318 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1319 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1320 if(angle_value < 22)
1321 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1;
1323 if(angle_value > 67)
1324 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1;
1326 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1327 mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1329 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1330 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1333 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1334 mwindow->edl->session->ruler_y2 > mwindow->edl->session->ruler_y1)
1336 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1337 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1340 if(mwindow->edl->session->ruler_x2 > mwindow->edl->session->ruler_x1 && mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1342 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1343 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1347 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1348 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1351 do_ruler(1, 0, 0, 0);
1352 get_canvas()->flash();
1356 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1360 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1365 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1366 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1367 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1368 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1370 set_cursor(UPRIGHT_ARROW_CURSOR);
1373 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1374 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1375 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1376 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1378 set_cursor(UPRIGHT_ARROW_CURSOR);
1381 set_cursor(CROSS_CURSOR);
1383 // Update current position
1388 // Assume no ruler measurement if 0 length
1389 if(draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)))
1391 get_canvas()->set_inverse();
1392 get_canvas()->set_color(WHITE);
1393 get_canvas()->draw_line((int)canvas_x1,
1397 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1399 roundf(canvas_x1) + RULERHANDLE_W / 2,
1401 get_canvas()->draw_line(roundf(canvas_x1),
1402 roundf(canvas_y1) - RULERHANDLE_H / 2,
1404 roundf(canvas_y1) + RULERHANDLE_H / 2);
1405 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1407 roundf(canvas_x2) + RULERHANDLE_W / 2,
1409 get_canvas()->draw_line(roundf(canvas_x2),
1410 roundf(canvas_y2) - RULERHANDLE_H / 2,
1412 roundf(canvas_y2) + RULERHANDLE_H / 2);
1413 get_canvas()->set_opaque();
1420 static inline double line_dist(float cx,float cy, float tx,float ty)
1422 double dx = tx-cx, dy = ty-cy;
1423 return sqrt(dx*dx + dy*dy);
1426 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1428 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1429 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1433 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1434 int button_press, int cursor_motion, int draw)
1436 // Retrieve points from top recordable track
1437 //printf("CWindowCanvas::do_mask 1\n");
1438 Track *track = gui->cwindow->calculate_affected_track();
1439 //printf("CWindowCanvas::do_mask 2\n");
1441 if(!track) return 0;
1442 //printf("CWindowCanvas::do_mask 3\n");
1444 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1445 int64_t position = track->to_units(
1446 mwindow->edl->local_session->get_selectionstart(1),
1448 ArrayList<MaskPoint*> points;
1450 // Determine the points based on whether
1451 // new keyframes will be generated or drawing is performed.
1452 // If keyframe generation occurs, use the interpolated mask.
1453 // If no keyframe generation occurs, use the previous mask.
1454 int use_interpolated = 0;
1455 if(button_press || cursor_motion) {
1456 #ifdef USE_KEYFRAME_SPANNING
1457 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1458 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1461 mask_autos->get_prev_auto(track->to_units(selection_start, 0),
1462 PLAY_FORWARD, first, 1);
1464 mask_autos->get_prev_auto(track->to_units(selection_end, 0),
1465 PLAY_FORWARD, last, 1);
1467 if(last == first && (!mwindow->edl->session->auto_keyframes))
1468 use_interpolated = 0;
1470 // If keyframe spanning occurs, use the interpolated points.
1471 // If new keyframe is generated, use the interpolated points.
1472 use_interpolated = 1;
1475 if(mwindow->edl->session->auto_keyframes)
1476 use_interpolated = 1;
1480 use_interpolated = 1;
1482 if(use_interpolated) {
1483 // Interpolate the points to get exactly what is being rendered at this position.
1484 mask_autos->get_points(&points,
1485 mwindow->edl->session->cwindow_mask,
1490 // Use the prev mask
1492 mask_autos->get_prev_auto(position,
1496 ((MaskAuto*)prev)->get_points(&points,
1497 mwindow->edl->session->cwindow_mask);
1500 // Projector zooms relative to the center of the track output.
1501 float half_track_w = (float)track->track_w / 2;
1502 float half_track_h = (float)track->track_h / 2;
1503 // Translate mask to projection
1504 float projector_x, projector_y, projector_z;
1505 track->automation->get_projector(
1506 &projector_x, &projector_y, &projector_z,
1507 position, PLAY_FORWARD);
1510 // Get position of cursor relative to mask
1511 float cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
1512 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1513 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1515 projector_x += mwindow->edl->session->output_w / 2;
1516 projector_y += mwindow->edl->session->output_h / 2;
1517 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1518 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1520 // Fix cursor origin
1522 gui->x_origin = mask_cursor_x;
1523 gui->y_origin = mask_cursor_y;
1527 // Points of closest line
1528 int shortest_point1 = -1;
1529 int shortest_point2 = -1;
1531 int shortest_point = -1;
1532 // Distance to closest line
1533 float shortest_line_distance = BC_INFINITY;
1534 // Distance to closest point
1535 float shortest_point_distance = BC_INFINITY;
1536 int selected_point = -1;
1537 int selected_control_point = -1;
1538 float selected_control_point_distance = BC_INFINITY;
1539 ArrayList<int> x_points;
1540 ArrayList<int> y_points;
1542 if(!cursor_motion) {
1544 get_canvas()->set_color(WHITE);
1545 get_canvas()->set_inverse();
1547 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1549 // Never draw closed polygon and a closed
1550 // polygon is harder to add points to.
1551 for(int i = 0; i < points.size() && !result; i++) {
1552 MaskPoint *point1 = points.get(i);
1553 MaskPoint *point2 = (i >= points.size() - 1) ?
1554 points.get(0) : points.get(i + 1);
1556 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1557 if(point_distance1 < shortest_point_distance || shortest_point < 0) {
1558 shortest_point_distance = point_distance1;
1562 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1563 if(point_distance2 < shortest_point_distance || shortest_point < 0) {
1564 shortest_point_distance = point_distance2;
1565 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1569 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1571 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1572 //point1->x, point1->y, point2->x, point2->y, projector_z);
1573 for(int j = 0; j <= segments && !result; j++) {
1574 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1575 float x0 = point1->x, y0 = point1->y;
1576 float x1 = point1->x + point1->control_x2;
1577 float y1 = point1->y + point1->control_y2;
1578 float x2 = point2->x + point2->control_x1;
1579 float y2 = point2->y + point2->control_y1;
1580 float x3 = point2->x, y3 = point2->y;
1581 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1582 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1583 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1584 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1585 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1586 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1587 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1588 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1590 float t = (float)j / segments;
1591 float tpow2 = t * t;
1592 float tpow3 = t * t * t;
1594 float invtpow2 = invt * invt;
1595 float invtpow3 = invt * invt * invt;
1597 float x = ( invtpow3 * x0
1598 + 3 * t * invtpow2 * x1
1599 + 3 * tpow2 * invt * x2
1601 float y = ( invtpow3 * y0
1602 + 3 * t * invtpow2 * y1
1603 + 3 * tpow2 * invt * y2
1605 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1606 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1607 // Test new point addition
1609 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1611 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1612 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1613 if(line_distance < shortest_line_distance ||
1614 shortest_point1 < 0) {
1615 shortest_line_distance = line_distance;
1616 shortest_point1 = i;
1617 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1618 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1619 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1622 // Test existing point selection
1624 if(gui->ctrl_down()) {
1625 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1627 if(distance < selected_control_point_distance) {
1629 selected_control_point = 1;
1630 selected_control_point_distance = distance;
1634 if(!gui->shift_down()) {
1635 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1636 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
1641 selected_point = shortest_point;
1644 // Test second point
1645 if(gui->ctrl_down()) {
1646 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1648 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1649 if(distance < selected_control_point_distance) {
1650 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1651 selected_control_point = 0;
1652 selected_control_point_distance = distance;
1655 else if(i < points.size() - 1) {
1656 if(!gui->shift_down()) {
1657 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1658 if(test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3)) {
1659 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1663 selected_point = shortest_point;
1668 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1672 if(draw) { // Draw joining line
1673 x_points.append((int)canvas_x);
1674 y_points.append((int)canvas_y);
1678 if(draw) { // Draw second anchor
1679 if(i < points.size() - 1) {
1680 if(i == gui->affected_point - 1)
1681 get_canvas()->draw_disc(
1682 (int)canvas_x - CONTROL_W / 2,
1683 (int)canvas_y - CONTROL_W / 2,
1684 CONTROL_W, CONTROL_H);
1686 get_canvas()->draw_circle(
1687 (int)canvas_x - CONTROL_W / 2,
1688 (int)canvas_y - CONTROL_W / 2,
1689 CONTROL_W, CONTROL_H);
1690 // char string[BCTEXTLEN];
1691 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1692 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1694 // Draw second control point.
1695 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1696 get_canvas()->draw_line(
1697 (int)canvas_x, (int)canvas_y,
1698 (int)canvas_x2, (int)canvas_y2);
1699 get_canvas()->draw_rectangle(
1700 (int)canvas_x2 - CONTROL_W / 2,
1701 (int)canvas_y2 - CONTROL_H / 2,
1702 CONTROL_W, CONTROL_H);
1707 // Draw first anchor
1708 if(i == 0 && draw) {
1709 char mask_label[BCSTRLEN];
1710 sprintf(mask_label, "%d",
1711 mwindow->edl->session->cwindow_mask);
1712 get_canvas()->draw_text(
1713 (int)canvas_x - FIRST_CONTROL_W,
1714 (int)canvas_y - FIRST_CONTROL_H,
1717 get_canvas()->draw_disc(
1718 (int)canvas_x - FIRST_CONTROL_W / 2,
1719 (int)canvas_y - FIRST_CONTROL_H / 2,
1720 FIRST_CONTROL_W, FIRST_CONTROL_H);
1723 // Draw first control point.
1725 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1726 get_canvas()->draw_line(
1727 (int)canvas_x, (int)canvas_y,
1728 (int)canvas_x1, (int)canvas_y1);
1729 get_canvas()->draw_rectangle(
1730 (int)canvas_x1 - CONTROL_W / 2,
1731 (int)canvas_y1 - CONTROL_H / 2,
1732 CONTROL_W, CONTROL_H);
1734 x_points.append((int)canvas_x);
1735 y_points.append((int)canvas_y);
1738 //printf("CWindowCanvas::do_mask 1\n");
1742 //printf("CWindowCanvas::do_mask 1\n");
1745 get_canvas()->draw_polygon(&x_points, &y_points);
1746 get_canvas()->set_opaque();
1748 //printf("CWindowCanvas::do_mask 1\n");
1751 if(button_press && !result) {
1752 gui->affected_track = gui->cwindow->calculate_affected_track();
1754 // Get keyframe outside the EDL to edit. This must be rendered
1755 // instead of the EDL keyframes when it exists. Then it must be
1756 // applied to the EDL keyframes on buttonrelease.
1757 if(gui->affected_track) {
1758 #ifdef USE_KEYFRAME_SPANNING
1759 // Make copy of current parameters in local keyframe
1760 gui->mask_keyframe =
1761 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1764 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1767 gui->mask_keyframe =
1768 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1773 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1776 // Translate entire keyframe
1777 if(gui->alt_down() && mask->points.size()) {
1778 mwindow->undo->update_undo_before(_("mask translate"), 0);
1779 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1780 gui->affected_point = 0;
1783 // Existing point or control point was selected
1784 if(selected_point >= 0) {
1785 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1786 gui->affected_point = selected_point;
1788 if(selected_control_point == 0)
1789 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1791 if(selected_control_point == 1)
1792 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1794 gui->current_operation = mwindow->edl->session->cwindow_operation;
1796 else // No existing point or control point was selected so create a new one
1797 if(!gui->ctrl_down() && !gui->alt_down()) {
1798 mwindow->undo->update_undo_before(_("mask point"), 0);
1799 // Create the template
1800 MaskPoint *point = new MaskPoint;
1801 point->x = mask_cursor_x;
1802 point->y = mask_cursor_y;
1803 point->control_x1 = 0;
1804 point->control_y1 = 0;
1805 point->control_x2 = 0;
1806 point->control_y2 = 0;
1809 if(shortest_point2 < shortest_point1) {
1810 shortest_point2 ^= shortest_point1;
1811 shortest_point1 ^= shortest_point2;
1812 shortest_point2 ^= shortest_point1;
1817 // printf("CWindowGUI::do_mask 40\n");
1818 // mwindow->edl->dump();
1819 // printf("CWindowGUI::do_mask 50\n");
1823 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1824 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1825 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1827 // Append to end of list
1828 if( shortest_point1 == shortest_point2 ||
1829 labs(shortest_point1 - shortest_point2) > 1) {
1830 #ifdef USE_KEYFRAME_SPANNING
1832 MaskPoint *new_point = new MaskPoint;
1833 points.append(new_point);
1834 *new_point = *point;
1835 gui->affected_point = points.size() - 1;
1839 // Need to apply the new point to every keyframe
1840 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1841 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1842 MaskPoint *new_point = new MaskPoint;
1843 submask->points.append(new_point);
1844 *new_point = *point;
1845 if(current == (MaskAuto*)mask_autos->default_auto)
1846 current = (MaskAuto*)mask_autos->first;
1848 current = (MaskAuto*)NEXT;
1850 gui->affected_point = mask->points.size() - 1;
1856 // Insert between 2 points, shifting back point 2
1857 if(shortest_point1 >= 0 && shortest_point2 >= 0) {
1859 #ifdef USE_KEYFRAME_SPANNING
1860 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1862 if(points.size() >= shortest_point2) {
1863 MaskPoint *new_point = new MaskPoint;
1865 for(int i = points.size() - 1;
1866 i > shortest_point2;
1868 points.values[i] = points.values[i - 1];
1869 points.values[shortest_point2] = new_point;
1871 *new_point = *point;
1876 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1877 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1878 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1880 if(submask->points.size() >= shortest_point2) {
1881 MaskPoint *new_point = new MaskPoint;
1882 submask->points.append(0);
1883 for(int i = submask->points.size() - 1;
1884 i > shortest_point2;
1886 submask->points.values[i] = submask->points.values[i - 1];
1887 submask->points.values[shortest_point2] = new_point;
1889 *new_point = *point;
1892 if(current == (MaskAuto*)mask_autos->default_auto)
1893 current = (MaskAuto*)mask_autos->first;
1895 current = (MaskAuto*)NEXT;
1899 gui->affected_point = shortest_point2;
1904 // printf("CWindowGUI::do_mask 20\n");
1905 // mwindow->edl->dump();
1906 // printf("CWindowGUI::do_mask 30\n");
1909 //printf("CWindowCanvas::do_mask 1\n");
1910 // Create the first point.
1911 #ifdef USE_KEYFRAME_SPANNING
1912 MaskPoint *new_point = new MaskPoint;
1913 points.append(new_point);
1914 *new_point = *point;
1915 gui->affected_point = points.size() - 1;
1917 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1918 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1919 MaskPoint *new_point = new MaskPoint;
1920 submask->points.append(new_point);
1921 *new_point = *point;
1922 if(current == (MaskAuto*)mask_autos->default_auto)
1923 current = (MaskAuto*)mask_autos->first;
1925 current = (MaskAuto*)NEXT;
1927 gui->affected_point = points.size() - 1;
1930 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
1933 gui->current_operation = mwindow->edl->session->cwindow_operation;
1934 // Delete the template
1943 if(button_press && result) {
1944 #ifdef USE_KEYFRAME_SPANNING
1945 MaskPoint *point = points.values[gui->affected_point];
1946 gui->center_x = point->x;
1947 gui->center_y = point->y;
1948 gui->control_in_x = point->control_x1;
1949 gui->control_in_y = point->control_y1;
1950 gui->control_out_x = point->control_x2;
1951 gui->control_out_y = point->control_y2;
1952 gui->tool_panel->raise_window();
1954 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1955 MaskPoint *point = mask->points.values[gui->affected_point];
1956 gui->center_x = point->x;
1957 gui->center_y = point->y;
1958 gui->control_in_x = point->control_x1;
1959 gui->control_in_y = point->control_y1;
1960 gui->control_out_x = point->control_x2;
1961 gui->control_out_y = point->control_y2;
1962 gui->tool_panel->raise_window();
1966 //printf("CWindowCanvas::do_mask 8\n");
1969 #ifdef USE_KEYFRAME_SPANNING
1970 // Must update the reference keyframes for every cursor motion
1971 gui->mask_keyframe =
1972 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1975 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1978 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1980 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1981 if( gui->affected_point >= 0 && gui->affected_point < mask->points.size() &&
1982 gui->current_operation != CWINDOW_NONE) {
1983 // mwindow->undo->update_undo_before(_("mask point"), this);
1984 #ifdef USE_KEYFRAME_SPANNING
1985 MaskPoint *point = points.get(gui->affected_point);
1987 MaskPoint *point = mask->points.get(gui->affected_point);
1989 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
1990 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask->points.size(), gui->affected_point);
1992 float last_x = point->x;
1993 float last_y = point->y;
1994 float last_control_x1 = point->control_x1;
1995 float last_control_y1 = point->control_y1;
1996 float last_control_x2 = point->control_x2;
1997 float last_control_y2 = point->control_y2;
1999 switch(gui->current_operation) {
2001 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2002 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
2003 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
2006 case CWINDOW_MASK_CONTROL_IN:
2007 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
2008 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
2011 case CWINDOW_MASK_CONTROL_OUT:
2012 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
2013 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
2016 case CWINDOW_MASK_TRANSLATE:
2017 #ifdef USE_KEYFRAME_SPANNING
2018 for(int i = 0; i < points.size(); i++) {
2019 points.values[i]->x += mask_cursor_x - gui->x_origin;
2020 points.values[i]->y += mask_cursor_y - gui->y_origin;
2023 for(int i = 0; i < mask->points.size(); i++) {
2024 mask->points.values[i]->x += mask_cursor_x - gui->x_origin;
2025 mask->points.values[i]->y += mask_cursor_y - gui->y_origin;
2028 gui->x_origin = mask_cursor_x;
2029 gui->y_origin = mask_cursor_y;
2033 if( !EQUIV(last_x, point->x) ||
2034 !EQUIV(last_y, point->y) ||
2035 !EQUIV(last_control_x1, point->control_x1) ||
2036 !EQUIV(last_control_y1, point->control_y1) ||
2037 !EQUIV(last_control_x2, point->control_x2) ||
2038 !EQUIV(last_control_y2, point->control_y2)) {
2044 if(gui->current_operation == CWINDOW_NONE) {
2045 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
2047 for(int i = 0; i < points.size() && !over_point; i++) {
2048 MaskPoint *point = points.get(i);
2049 float x0 = point->x;
2050 float y0 = point->y;
2051 float x1 = point->x + point->control_x1;
2052 float y1 = point->y + point->control_y1;
2053 float x2 = point->x + point->control_x2;
2054 float y2 = point->y + point->control_y2;
2055 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
2056 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
2058 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
2059 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
2063 if(!over_point && gui->ctrl_down()) {
2064 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
2065 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
2066 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2067 if(test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1)) {
2071 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2072 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2073 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2074 if(test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2)) {
2081 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2086 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2089 #ifdef USE_KEYFRAME_SPANNING
2090 // Must commit change after operation.
2091 if(rerender && track) {
2092 // Swap EDL keyframe with original.
2093 // Apply new values to keyframe span
2094 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2095 temp_keyframe.copy_data(gui->mask_keyframe);
2096 // Apply interpolated points back to keyframe
2097 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2098 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2099 mask_autos->update_parameter(&temp_keyframe);
2103 points.remove_all_objects();
2104 //printf("CWindowCanvas::do_mask 20\n");
2108 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2111 int radius = mwindow->edl->session->eyedrop_radius;
2119 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2124 row1 = gui->eyedrop_y - radius;
2125 row2 = gui->eyedrop_y + radius;
2126 column1 = gui->eyedrop_x - radius;
2127 column2 = gui->eyedrop_x + radius;
2129 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2130 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2131 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2132 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2134 if(row2 <= row1) row2 = row1 + 1;
2135 if(column2 <= column1) column2 = column1 + 1;
2142 output_to_canvas(mwindow->edl, 0, x1, y1);
2143 output_to_canvas(mwindow->edl, 0, x2, y2);
2144 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2146 if(x2 - x1 >= 1 && y2 - y1 >= 1)
2148 get_canvas()->set_inverse();
2149 get_canvas()->set_color(WHITE);
2151 get_canvas()->draw_rectangle((int)x1,
2156 get_canvas()->set_opaque();
2157 get_canvas()->flash();
2165 gui->current_operation = CWINDOW_EYEDROP;
2166 gui->tool_panel->raise_window();
2169 if(gui->current_operation == CWINDOW_EYEDROP)
2171 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2173 // Get color out of frame.
2174 // Doesn't work during playback because that bypasses the refresh frame.
2175 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2177 float cursor_x = get_cursor_x();
2178 float cursor_y = get_cursor_y();
2179 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2180 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2181 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2183 row1 = cursor_y - radius;
2184 row2 = cursor_y + radius;
2185 column1 = cursor_x - radius;
2186 column2 = cursor_x + radius;
2187 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2188 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2189 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2190 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2191 if(row2 <= row1) row2 = row1 + 1;
2192 if(column2 <= column1) column2 = column1 + 1;
2196 if(gui->eyedrop_visible)
2199 do_eyedrop(temp, 0, 1);
2200 gui->eyedrop_visible = 0;
2203 gui->eyedrop_x = cursor_x;
2204 gui->eyedrop_y = cursor_y;
2209 do_eyedrop(temp, 0, 1);
2210 gui->eyedrop_visible = 1;
2213 // Decompression coefficients straight out of jpeglib
2214 #define V_TO_R 1.40200
2215 #define V_TO_G -0.71414
2217 #define U_TO_G -0.34414
2218 #define U_TO_B 1.77200
2220 #define GET_COLOR(type, components, max, do_yuv) \
2222 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2224 float red = (float)*row++ / max; \
2225 float green = (float)*row++ / max; \
2226 float blue = (float)*row++ / max; \
2229 float r = red + V_TO_R * (blue - 0.5); \
2230 float g = red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
2231 float b = red + U_TO_B * (green - 0.5); \
2232 mwindow->edl->local_session->red += r; \
2233 mwindow->edl->local_session->green += g; \
2234 mwindow->edl->local_session->blue += b; \
2235 if(r > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = r; \
2236 if(g > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = g; \
2237 if(b > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = b; \
2241 mwindow->edl->local_session->red += red; \
2242 mwindow->edl->local_session->green += green; \
2243 mwindow->edl->local_session->blue += blue; \
2244 if(red > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = red; \
2245 if(green > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = green; \
2246 if(blue > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = blue; \
2252 mwindow->edl->local_session->red = 0;
2253 mwindow->edl->local_session->green = 0;
2254 mwindow->edl->local_session->blue = 0;
2255 mwindow->edl->local_session->red_max = 0;
2256 mwindow->edl->local_session->green_max = 0;
2257 mwindow->edl->local_session->blue_max = 0;
2258 for(int i = row1; i < row2; i++)
2260 for(int j = column1; j < column2; j++)
2262 switch(refresh_frame->get_color_model())
2265 GET_COLOR(unsigned char, 3, 0xff, 1);
2268 GET_COLOR(unsigned char, 4, 0xff, 1);
2271 GET_COLOR(uint16_t, 3, 0xffff, 1);
2273 case BC_YUVA16161616:
2274 GET_COLOR(uint16_t, 4, 0xffff, 1);
2277 GET_COLOR(unsigned char, 3, 0xff, 0);
2280 GET_COLOR(unsigned char, 4, 0xff, 0);
2283 GET_COLOR(float, 3, 1.0, 0);
2286 GET_COLOR(float, 4, 1.0, 0);
2292 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2293 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2294 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2299 mwindow->edl->local_session->red = 0;
2300 mwindow->edl->local_session->green = 0;
2301 mwindow->edl->local_session->blue = 0;
2302 gui->eyedrop_visible = 0;
2311 // Can't rerender since the color value is from the output of any effect it
2314 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2320 void CWindowCanvas::draw_overlays()
2322 if(mwindow->edl->session->safe_regions)
2324 draw_safe_regions();
2327 if(mwindow->edl->session->cwindow_scrollbars)
2329 // Always draw output rectangle
2330 float x1, y1, x2, y2;
2332 x2 = mwindow->edl->session->output_w;
2334 y2 = mwindow->edl->session->output_h;
2335 output_to_canvas(mwindow->edl, 0, x1, y1);
2336 output_to_canvas(mwindow->edl, 0, x2, y2);
2338 get_canvas()->set_inverse();
2339 get_canvas()->set_color(WHITE);
2341 get_canvas()->draw_rectangle((int)x1,
2346 get_canvas()->set_opaque();
2349 if(gui->highlighted)
2351 get_canvas()->set_color(WHITE);
2352 get_canvas()->set_inverse();
2353 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2354 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2355 get_canvas()->set_opaque();
2358 int temp1 = 0, temp2 = 0;
2359 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2360 switch(mwindow->edl->session->cwindow_operation)
2362 case CWINDOW_CAMERA:
2366 case CWINDOW_PROJECTOR:
2375 do_mask(temp1, temp2, 0, 0, 1);
2379 do_ruler(1, 0, 0, 0);
2382 case CWINDOW_EYEDROP:
2383 if(gui->eyedrop_visible)
2386 do_eyedrop(rerender, 0, 1);
2387 gui->eyedrop_visible = 1;
2393 void CWindowCanvas::draw_safe_regions()
2395 float action_x1, action_x2, action_y1, action_y2;
2396 float title_x1, title_x2, title_y1, title_y2;
2398 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2399 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2400 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2401 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2402 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2403 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2404 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2405 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2407 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2408 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2409 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2410 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2412 get_canvas()->set_inverse();
2413 get_canvas()->set_color(WHITE);
2415 get_canvas()->draw_rectangle((int)action_x1,
2417 (int)(action_x2 - action_x1),
2418 (int)(action_y2 - action_y1));
2419 get_canvas()->draw_rectangle((int)title_x1,
2421 (int)(title_x2 - title_x1),
2422 (int)(title_y2 - title_y1));
2424 get_canvas()->set_opaque();
2427 void CWindowCanvas::reset_keyframe(int do_camera)
2429 FloatAuto *x_keyframe = 0;
2430 FloatAuto *y_keyframe = 0;
2431 FloatAuto *z_keyframe = 0;
2432 Track *affected_track = 0;
2434 affected_track = gui->cwindow->calculate_affected_track();
2438 gui->cwindow->calculate_affected_autos(&x_keyframe,
2447 x_keyframe->set_value(0);
2448 y_keyframe->set_value(0);
2449 z_keyframe->set_value(1);
2451 mwindow->sync_parameters(CHANGE_PARAMS);
2456 void CWindowCanvas::reset_camera()
2461 void CWindowCanvas::reset_projector()
2466 int CWindowCanvas::test_crop(int button_press, int &redraw)
2469 int handle_selected = -1;
2470 float x1 = mwindow->edl->session->crop_x1;
2471 float y1 = mwindow->edl->session->crop_y1;
2472 float x2 = mwindow->edl->session->crop_x2;
2473 float y2 = mwindow->edl->session->crop_y2;
2474 float cursor_x = get_cursor_x();
2475 float cursor_y = get_cursor_y();
2476 float canvas_x1 = x1;
2477 float canvas_y1 = y1;
2478 float canvas_x2 = x2;
2479 float canvas_y2 = y2;
2480 float canvas_cursor_x = cursor_x;
2481 float canvas_cursor_y = cursor_y;
2483 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2484 // Use screen normalized coordinates for hot spot tests.
2485 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2486 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2489 if(gui->current_operation == CWINDOW_CROP)
2491 handle_selected = gui->crop_handle;
2494 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2495 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2497 handle_selected = 0;
2498 gui->crop_origin_x = x1;
2499 gui->crop_origin_y = y1;
2502 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2503 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2505 handle_selected = 1;
2506 gui->crop_origin_x = x2;
2507 gui->crop_origin_y = y1;
2510 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2511 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2513 handle_selected = 2;
2514 gui->crop_origin_x = x1;
2515 gui->crop_origin_y = y2;
2518 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2519 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2521 handle_selected = 3;
2522 gui->crop_origin_x = x2;
2523 gui->crop_origin_y = y2;
2528 gui->crop_origin_x = cursor_x;
2529 gui->crop_origin_y = cursor_y;
2532 // printf("test crop %d %d\n",
2533 // gui->current_operation,
2534 // handle_selected);
2541 gui->crop_translate = 1;
2542 gui->crop_origin_x1 = x1;
2543 gui->crop_origin_y1 = y1;
2544 gui->crop_origin_x2 = x2;
2545 gui->crop_origin_y2 = y2;
2548 gui->crop_translate = 0;
2550 gui->current_operation = CWINDOW_CROP;
2551 gui->crop_handle = handle_selected;
2552 gui->x_origin = cursor_x;
2553 gui->y_origin = cursor_y;
2554 gui->tool_panel->raise_window();
2557 if(handle_selected < 0 && !gui->crop_translate)
2561 mwindow->edl->session->crop_x1 = (int)x1;
2562 mwindow->edl->session->crop_y1 = (int)y1;
2563 mwindow->edl->session->crop_x2 = (int)x2;
2564 mwindow->edl->session->crop_y2 = (int)y2;
2569 // Translate all 4 points
2570 if(gui->current_operation == CWINDOW_CROP && gui->crop_translate)
2572 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2573 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2574 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2575 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2577 mwindow->edl->session->crop_x1 = (int)x1;
2578 mwindow->edl->session->crop_y1 = (int)y1;
2579 mwindow->edl->session->crop_x2 = (int)x2;
2580 mwindow->edl->session->crop_y2 = (int)y2;
2586 if(gui->current_operation == CWINDOW_CROP)
2588 switch(gui->crop_handle)
2591 x1 = gui->crop_origin_x;
2592 y1 = gui->crop_origin_y;
2593 x2 = gui->crop_origin_x;
2594 y2 = gui->crop_origin_y;
2595 if(cursor_x < gui->x_origin)
2597 if(cursor_y < gui->y_origin)
2603 if(cursor_y >= gui->y_origin)
2610 if(cursor_x >= gui->x_origin)
2612 if(cursor_y < gui->y_origin)
2618 if(cursor_y >= gui->y_origin)
2625 // printf("test crop %d %d %d %d\n",
2626 // mwindow->edl->session->crop_x1,
2627 // mwindow->edl->session->crop_y1,
2628 // mwindow->edl->session->crop_x2,
2629 // mwindow->edl->session->crop_y2);
2632 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2633 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2636 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2637 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2640 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2641 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2644 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2645 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2649 if(!EQUIV(mwindow->edl->session->crop_x1, x1) ||
2650 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2651 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2652 !EQUIV(mwindow->edl->session->crop_y2, y2))
2659 switch (gui->crop_handle)
2661 case 0: gui->crop_handle = 1; break;
2662 case 1: gui->crop_handle = 0; break;
2663 case 2: gui->crop_handle = 3; break;
2664 case 3: gui->crop_handle = 2; break;
2674 switch (gui->crop_handle)
2676 case 0: gui->crop_handle = 2; break;
2677 case 1: gui->crop_handle = 3; break;
2678 case 2: gui->crop_handle = 0; break;
2679 case 3: gui->crop_handle = 1; break;
2684 mwindow->edl->session->crop_x1 = (int)x1;
2685 mwindow->edl->session->crop_y1 = (int)y1;
2686 mwindow->edl->session->crop_x2 = (int)x2;
2687 mwindow->edl->session->crop_y2 = (int)y2;
2693 // Update cursor font
2694 if(handle_selected >= 0)
2696 switch(handle_selected)
2699 set_cursor(UPLEFT_RESIZE);
2702 set_cursor(UPRIGHT_RESIZE);
2705 set_cursor(DOWNLEFT_RESIZE);
2708 set_cursor(DOWNRIGHT_RESIZE);
2715 set_cursor(ARROW_CURSOR);
2717 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2721 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2722 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2723 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2724 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2725 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2726 // mwindow->edl->session->crop_x2,
2727 // mwindow->edl->session->crop_y2,
2728 // mwindow->edl->calculate_output_w(0),
2729 // mwindow->edl->calculate_output_h(0));
2735 void CWindowCanvas::draw_crop()
2737 get_canvas()->set_inverse();
2738 get_canvas()->set_color(WHITE);
2740 float x1 = mwindow->edl->session->crop_x1;
2741 float y1 = mwindow->edl->session->crop_y1;
2742 float x2 = mwindow->edl->session->crop_x2;
2743 float y2 = mwindow->edl->session->crop_y2;
2745 output_to_canvas(mwindow->edl, 0, x1, y1);
2746 output_to_canvas(mwindow->edl, 0, x2, y2);
2748 if(x2 - x1 && y2 - y1)
2749 get_canvas()->draw_rectangle((int)x1,
2754 draw_crophandle((int)x1, (int)y1);
2755 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2756 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2757 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2758 get_canvas()->set_opaque();
2768 void CWindowCanvas::draw_bezier(int do_camera)
2770 Track *track = gui->cwindow->calculate_affected_track();
2777 int64_t position = track->to_units(
2778 mwindow->edl->local_session->get_selectionstart(1),
2781 track->automation->get_projector(¢er_x,
2787 // center_x += track->track_w / 2;
2788 // center_y += track->track_h / 2;
2789 center_x += mwindow->edl->session->output_w / 2;
2790 center_y += mwindow->edl->session->output_h / 2;
2791 float track_x1 = center_x - track->track_w / 2 * center_z;
2792 float track_y1 = center_y - track->track_h / 2 * center_z;
2793 float track_x2 = track_x1 + track->track_w * center_z;
2794 float track_y2 = track_y1 + track->track_h * center_z;
2796 output_to_canvas(mwindow->edl, 0, track_x1, track_y1);
2797 output_to_canvas(mwindow->edl, 0, track_x2, track_y2);
2799 #define DRAW_PROJECTION(offset) \
2800 get_canvas()->draw_rectangle((int)track_x1 + offset, \
2801 (int)track_y1 + offset, \
2802 (int)(track_x2 - track_x1), \
2803 (int)(track_y2 - track_y1)); \
2804 get_canvas()->draw_line((int)track_x1 + offset, \
2805 (int)track_y1 + offset, \
2806 (int)track_x2 + offset, \
2807 (int)track_y2 + offset); \
2808 get_canvas()->draw_line((int)track_x2 + offset, \
2809 (int)track_y1 + offset, \
2810 (int)track_x1 + offset, \
2811 (int)track_y2 + offset); \
2815 get_canvas()->set_color(BLACK);
2818 // canvas->set_inverse();
2820 get_canvas()->set_color(GREEN);
2822 get_canvas()->set_color(RED);
2825 // canvas->set_opaque();
2829 int CWindowCanvas::test_bezier(int button_press,
2837 // Processing drag operation.
2838 // Create keyframe during first cursor motion.
2842 float cursor_x = get_cursor_x();
2843 float cursor_y = get_cursor_y();
2844 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2846 if(gui->current_operation == CWINDOW_CAMERA ||
2847 gui->current_operation == CWINDOW_PROJECTOR)
2849 if(!gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom)
2851 gui->translating_zoom = 1;
2852 gui->reset_affected();
2855 if(!gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom)
2857 gui->translating_zoom = 0;
2858 gui->reset_affected();
2861 // Get target keyframe
2862 float last_center_x;
2863 float last_center_y;
2864 float last_center_z;
2867 if(!gui->affected_x && !gui->affected_y && !gui->affected_z)
2869 FloatAutos *affected_x_autos;
2870 FloatAutos *affected_y_autos;
2871 FloatAutos *affected_z_autos;
2872 if(!gui->affected_track) return 0;
2873 double position = mwindow->edl->local_session->get_selectionstart(1);
2874 int64_t track_position = gui->affected_track->to_units(position, 0);
2876 if(mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA)
2878 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_X];
2879 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Y];
2880 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Z];
2884 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_X];
2885 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Y];
2886 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Z];
2890 if(gui->translating_zoom)
2892 FloatAuto *previous = 0;
2893 FloatAuto *next = 0;
2894 float new_z = affected_z_autos->get_value(
2900 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2901 affected_z_autos, 1, &created, 0);
2903 gui->affected_z->set_value(new_z);
2909 FloatAuto *previous = 0;
2910 FloatAuto *next = 0;
2911 float new_x = affected_x_autos->get_value(
2918 float new_y = affected_y_autos->get_value(
2924 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2925 affected_x_autos, 1, &created, 0);
2927 gui->affected_x->set_value(new_x);
2931 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2932 affected_y_autos, 1, &created, 0);
2934 gui->affected_y->set_value(new_y);
2941 if(gui->translating_zoom)
2943 gui->center_z = gui->affected_z->get_value();
2947 gui->center_x = gui->affected_x->get_value();
2948 gui->center_y = gui->affected_y->get_value();
2955 if(gui->translating_zoom)
2957 last_center_z = gui->affected_z->get_value();
2958 float z = gui->center_z + (cursor_y - gui->y_origin) / 128;
2960 if(!EQUIV(last_center_z, z))
2966 gui->affected_z->set_value(z);
2970 last_center_x = gui->affected_x->get_value();
2971 last_center_y = gui->affected_y->get_value();
2972 float x = gui->center_x + cursor_x - gui->x_origin;
2973 float y = gui->center_y + cursor_y - gui->y_origin;
2974 gui->affected_x->set_value(x);
2975 gui->affected_y->set_value(y);
2976 if( !EQUIV(last_center_x, x) || !EQUIV(last_center_y, y) )
2982 gui->affected_x->set_value(x);
2983 gui->affected_y->set_value(y);
2990 // Begin drag operation. Don't create keyframe here.
2992 // Get affected track off of the first recordable video track.
2993 // Calculating based on the alpha channel would require recording what layer
2994 // each output pixel belongs to as they're rendered and stacked. Forget it.
2995 gui->affected_track = gui->cwindow->calculate_affected_track();
2996 gui->reset_affected();
2998 if(gui->affected_track)
3000 if(gui->current_operation == CWINDOW_CAMERA)
3001 mwindow->undo->update_undo_before(_("camera"), this);
3003 mwindow->undo->update_undo_before(_("projector"), this);
3005 gui->current_operation =
3006 mwindow->edl->session->cwindow_operation;
3007 gui->tool_panel->raise_window();
3016 int CWindowCanvas::test_zoom(int &redraw)
3022 if( mwindow->edl->session->cwindow_scrollbars ) {
3023 if( *gui->zoom_panel->get_text() != 'x' ) {
3024 // Find current zoom in table
3025 int idx = total_zooms; float old_zoom = get_zoom();
3026 while( --idx >= 0 && !EQUIV(my_zoom_table[idx], old_zoom) );
3028 idx += get_buttonpress() == 5 ||
3029 gui->ctrl_down() || gui->shift_down() ? -1 : +1 ;
3030 CLAMP(idx, 0, total_zooms-1);
3031 zoom = my_zoom_table[idx];
3034 x = get_cursor_x(); y = get_cursor_y();
3036 mwindow->edl->session->cwindow_scrollbars = 0;
3037 gui->zoom_panel->update(0);
3038 zoom = gui->get_auto_zoom();
3041 gui->zoom_panel->ZoomPanel::update(zoom);
3042 float output_x = x, output_y = y;
3043 canvas_to_output(mwindow->edl, 0, output_x, output_y);
3044 x = output_x - x / zoom;
3045 y = output_y - y / zoom;
3049 mwindow->edl->session->cwindow_scrollbars = 1;
3050 x = (mwindow->edl->session->output_w - w) / 2;
3051 y = (mwindow->edl->session->output_h - h) / 2;
3054 update_zoom((int)x, (int)y, zoom);
3056 gui->composite_panel->cpanel_zoom->update(zoom);
3058 reposition_window(mwindow->edl,
3059 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
3060 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
3061 redraw = 1; result = 1;
3067 void CWindowCanvas::calculate_origin()
3069 gui->x_origin = get_cursor_x();
3070 gui->y_origin = get_cursor_y();
3071 //printf("CWindowCanvas::calculate_origin 1 %f %f\n", gui->x_origin, gui->y_origin);
3072 canvas_to_output(mwindow->edl, 0, gui->x_origin, gui->y_origin);
3073 //printf("CWindowCanvas::calculate_origin 2 %f %f\n", gui->x_origin, gui->y_origin);
3077 int CWindowCanvas::cursor_leave_event()
3079 set_cursor(ARROW_CURSOR);
3083 int CWindowCanvas::cursor_enter_event()
3086 switch(mwindow->edl->session->cwindow_operation)
3088 case CWINDOW_CAMERA:
3089 case CWINDOW_PROJECTOR:
3090 set_cursor(MOVE_CURSOR);
3093 set_cursor(MOVE_CURSOR);
3096 test_crop(0, redraw);
3098 case CWINDOW_PROTECT:
3099 set_cursor(ARROW_CURSOR);
3103 set_cursor(CROSS_CURSOR);
3105 case CWINDOW_EYEDROP:
3106 set_cursor(CROSS_CURSOR);
3112 int CWindowCanvas::cursor_motion_event()
3114 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3117 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3118 switch(gui->current_operation)
3120 case CWINDOW_SCROLL:
3122 float zoom = get_zoom();
3123 float cursor_x = get_cursor_x();
3124 float cursor_y = get_cursor_y();
3126 float zoom_x, zoom_y, conformed_w, conformed_h;
3127 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3128 cursor_x = (float)cursor_x / zoom_x + gui->x_offset;
3129 cursor_y = (float)cursor_y / zoom_y + gui->y_offset;
3133 int x = (int)(gui->x_origin - cursor_x + gui->x_offset);
3134 int y = (int)(gui->y_origin - cursor_y + gui->y_offset);
3139 update_scrollbars(0);
3146 result = do_ruler(0, 1, 0, 0);
3149 case CWINDOW_CAMERA:
3150 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3153 case CWINDOW_PROJECTOR:
3154 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3159 result = test_crop(0, redraw);
3160 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3167 case CWINDOW_MASK_CONTROL_IN:
3168 case CWINDOW_MASK_CONTROL_OUT:
3169 case CWINDOW_MASK_TRANSLATE:
3171 result = do_mask(redraw,
3178 case CWINDOW_EYEDROP:
3179 result = do_eyedrop(rerender, 0, 0);
3188 // cursor font changes
3191 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3193 // mwindow->edl->session->cwindow_operation);
3194 switch(mwindow->edl->session->cwindow_operation)
3197 result = test_crop(0, redraw);
3200 result = do_ruler(0, 1, 0, 0);
3203 result = do_mask(redraw,
3213 // If the window is never unlocked before calling send_command the
3214 // display shouldn't get stuck on the old video frame although it will
3215 // flicker between the old video frame and the new video frame.
3225 gui->unlock_window();
3228 mwindow->gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3229 mwindow->gui->draw_overlays(1);
3230 mwindow->gui->unlock_window();
3232 gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3237 gui->unlock_window();
3238 mwindow->restart_brender();
3239 mwindow->sync_parameters(CHANGE_PARAMS);
3240 mwindow->cwindow->refresh_frame(CHANGE_NONE);
3241 if(!redraw) gui->update_tool();
3242 gui->lock_window("CWindowCanvas::cursor_motion_event 2");
3247 int CWindowCanvas::button_press_event()
3251 int redraw_canvas = 0;
3254 if(Canvas::button_press_event()) return 1;
3256 gui->translating_zoom = gui->shift_down();
3259 //printf("CWindowCanvas::button_press_event 2 %f %f\n", gui->x_origin, gui->y_origin, gui->x_origin, gui->y_origin);
3261 float zoom_x, zoom_y, conformed_w, conformed_h;
3262 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3263 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3264 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3267 if( mwindow->edl->session->cwindow_operation != CWINDOW_PROTECT &&
3268 get_buttonpress() == 2 )
3270 gui->current_operation = CWINDOW_SCROLL;
3276 switch(mwindow->edl->session->cwindow_operation)
3279 result = do_ruler(0, 0, 1, 0);
3282 case CWINDOW_CAMERA:
3283 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3286 case CWINDOW_PROJECTOR:
3287 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3291 result = test_zoom(redraw);
3295 result = test_crop(1, redraw);
3299 if(get_buttonpress() == 1)
3300 result = do_mask(redraw, rerender, 1, 0, 0);
3303 case CWINDOW_EYEDROP:
3304 result = do_eyedrop(rerender, 1, 0);
3312 gui->unlock_window();
3315 mwindow->gui->lock_window("CWindowCanvas::button_press_event 1");
3316 mwindow->gui->draw_overlays(1);
3317 mwindow->gui->unlock_window();
3320 gui->lock_window("CWindowCanvas::button_press_event 1");
3323 // rerendering can also be caused by press event
3326 gui->unlock_window();
3328 mwindow->restart_brender();
3329 mwindow->sync_parameters(CHANGE_PARAMS);
3330 mwindow->cwindow->refresh_frame(CHANGE_NONE);
3331 if(!redraw) gui->update_tool();
3332 gui->lock_window("CWindowCanvas::button_press_event 2");
3337 int CWindowCanvas::button_release_event()
3341 switch(gui->current_operation)
3343 case CWINDOW_SCROLL:
3348 do_ruler(0, 0, 0, 1);
3351 case CWINDOW_CAMERA:
3352 mwindow->undo->update_undo_after(_("camera"), LOAD_AUTOMATION);
3355 case CWINDOW_PROJECTOR:
3356 mwindow->undo->update_undo_after(_("projector"), LOAD_AUTOMATION);
3360 case CWINDOW_MASK_CONTROL_IN:
3361 case CWINDOW_MASK_CONTROL_OUT:
3362 case CWINDOW_MASK_TRANSLATE:
3363 // Finish mask operation
3364 gui->mask_keyframe = 0;
3365 mwindow->undo->update_undo_after(_("mask"), LOAD_AUTOMATION);
3368 result = Canvas::button_release_event();
3372 gui->current_operation = CWINDOW_NONE;
3376 void CWindowCanvas::zoom_resize_window(float percentage)
3378 int canvas_w, canvas_h;
3382 // Get required canvas size
3383 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3384 mwindow->edl->session->output_w,
3385 mwindow->edl->session->output_h,
3390 // Estimate window size from current borders
3391 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3392 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3394 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3395 mwindow->session->cwindow_w = new_w;
3396 mwindow->session->cwindow_h = new_h;
3398 mwindow->theme->get_cwindow_sizes(gui,
3399 mwindow->session->cwindow_controls);
3401 // Estimate again from new borders
3402 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3403 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3404 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3406 gui->resize_window(new_w, new_h);
3407 gui->resize_event(new_w, new_h);
3410 void CWindowCanvas::toggle_controls()
3412 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3413 gui->resize_event(gui->get_w(), gui->get_h());
3416 int CWindowCanvas::get_cwindow_controls()
3418 return mwindow->session->cwindow_controls;