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;
574 case KEY_F11: canvas->reset_camera(); break;
575 case KEY_F12: canvas->reset_projector(); break;
578 if( cwindow_operation >= 0 ) {
579 set_operation(cwindow_operation);
583 if(!result) result = transport->keypress_event();
589 void CWindowGUI::reset_affected()
596 void CWindowGUI::keyboard_zoomin()
598 // if(mwindow->edl->session->cwindow_scrollbars)
600 zoom_panel->zoom_tumbler->handle_up_event();
607 void CWindowGUI::keyboard_zoomout()
609 // if(mwindow->edl->session->cwindow_scrollbars)
611 zoom_panel->zoom_tumbler->handle_down_event();
619 void CWindowGUI::drag_motion()
621 if(get_hidden()) return;
623 if(mwindow->session->current_operation != DRAG_ASSET &&
624 mwindow->session->current_operation != DRAG_VTRANSITION &&
625 mwindow->session->current_operation != DRAG_VEFFECT) return;
626 int need_highlight = cursor_above() && get_cursor_over_window();
627 if( highlighted == need_highlight ) return;
628 highlighted = need_highlight;
629 canvas->draw_refresh();
632 int CWindowGUI::drag_stop()
635 if(get_hidden()) return 0;
636 if( !highlighted ) return 0;
637 if( mwindow->session->current_operation != DRAG_ASSET &&
638 mwindow->session->current_operation != DRAG_VTRANSITION &&
639 mwindow->session->current_operation != DRAG_VEFFECT) return 0;
641 canvas->draw_refresh();
644 if(mwindow->session->current_operation == DRAG_ASSET)
646 if(mwindow->session->drag_assets->total ||
647 mwindow->session->drag_clips->total)
649 mwindow->gui->lock_window("CWindowGUI::drag_stop 5");
650 mwindow->undo->update_undo_before(_("insert assets"), 0);
651 mwindow->gui->unlock_window();
654 if(mwindow->session->drag_assets->total)
656 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
658 mwindow->load_assets(mwindow->session->drag_assets,
659 mwindow->edl->local_session->get_selectionstart(),
661 mwindow->session->track_highlighted,
663 mwindow->edl->session->labels_follow_edits,
664 mwindow->edl->session->plugins_follow_edits,
665 mwindow->edl->session->autos_follow_edits,
669 if(mwindow->session->drag_clips->total)
671 mwindow->gui->lock_window("CWindowGUI::drag_stop 2");
673 mwindow->paste_edls(mwindow->session->drag_clips,
675 mwindow->session->track_highlighted,
676 mwindow->edl->local_session->get_selectionstart(),
677 mwindow->edl->session->labels_follow_edits,
678 mwindow->edl->session->plugins_follow_edits,
679 mwindow->edl->session->autos_follow_edits,
683 if(mwindow->session->drag_assets->total ||
684 mwindow->session->drag_clips->total)
686 mwindow->save_backup();
687 mwindow->restart_brender();
688 mwindow->gui->update(1, 1, 1, 1, 0, 1, 0);
689 mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
690 mwindow->gui->unlock_window();
691 mwindow->sync_parameters(LOAD_ALL);
695 if(mwindow->session->current_operation == DRAG_VEFFECT)
697 //printf("CWindowGUI::drag_stop 1\n");
698 Track *affected_track = cwindow->calculate_affected_track();
699 //printf("CWindowGUI::drag_stop 2\n");
701 mwindow->gui->lock_window("CWindowGUI::drag_stop 3");
702 mwindow->insert_effects_cwindow(affected_track);
703 mwindow->session->current_operation = NO_OPERATION;
704 mwindow->gui->unlock_window();
707 if(mwindow->session->current_operation == DRAG_VTRANSITION)
709 Track *affected_track = cwindow->calculate_affected_track();
710 mwindow->gui->lock_window("CWindowGUI::drag_stop 4");
711 mwindow->paste_transition_cwindow(affected_track);
712 mwindow->session->current_operation = NO_OPERATION;
713 mwindow->gui->unlock_window();
719 void CWindowGUI::update_meters()
721 if(mwindow->edl->session->cwindow_meter != meters->visible)
723 meters->set_meters(meters->meter_count, mwindow->edl->session->cwindow_meter);
724 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
725 resize_event(get_w(), get_h());
729 void CWindowGUI::stop_transport(const char *lock_msg)
731 if( lock_msg ) unlock_window();
732 mwindow->stop_transport();
733 if( lock_msg ) lock_window(lock_msg);
737 CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
738 : EditPanel(mwindow, cwindow->gui, CWINDOW_ID,
739 mwindow->theme->cedit_x, mwindow->theme->cedit_y,
740 mwindow->edl->session->editing_mode,
741 0, // use_editing_mode
760 this->mwindow = mwindow;
761 this->cwindow = cwindow;
764 #define CWrapper(fn) void CWindowEditing::fn() { \
765 mwindow->gui->lock_window("CWrapper::" #fn); \
767 mwindow->gui->unlock_window(); \
770 CWrapper(copy_selection)
771 CWrapper(splice_selection)
772 CWrapper(overwrite_selection)
773 CWrapper(set_inpoint)
774 CWrapper(set_outpoint)
775 CWrapper(unset_inoutpoint)
776 CWrapper(toggle_label)
778 #define CWrapper_cut(fn) void CWindowEditing::fn(int cut) { \
779 mwindow->gui->lock_window("CWrapper::" #fn); \
780 EditPanel::fn(cut); \
781 mwindow->gui->unlock_window(); \
783 CWrapper_cut(prev_label)
784 CWrapper_cut(next_label)
785 CWrapper_cut(prev_edit)
786 CWrapper_cut(next_edit)
788 void CWindowEditing::to_clip()
790 mwindow->to_clip(mwindow->edl, _("composer window: "), 0);
794 CWindowMeters::CWindowMeters(MWindow *mwindow,
799 : MeterPanel(mwindow,
805 mwindow->edl->session->audio_channels,
806 mwindow->edl->session->cwindow_meter,
810 this->mwindow = mwindow;
814 CWindowMeters::~CWindowMeters()
818 int CWindowMeters::change_status_event(int new_status)
820 mwindow->edl->session->cwindow_meter = new_status;
821 gui->update_meters();
828 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
829 : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
830 x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
832 this->mwindow = mwindow;
836 CWindowZoom::~CWindowZoom()
840 void CWindowZoom::update(double value)
842 char string[BCSTRLEN];
843 const char *cp = string;
846 int frac = value >= 1.0f ? 1 :
848 value >= .01f ? 3 : 4;
849 sprintf(string, "x %.*f", frac, value);
853 ZoomPanel::update(cp);
856 int CWindowZoom::handle_event()
858 double value = !strcasecmp(gui->auto_zoom, get_text()) ? 0 : get_value();
859 gui->zoom_canvas(value, 0);
866 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
867 : BC_PercentageSlider(x,
876 this->mwindow = mwindow;
877 this->cwindow = cwindow;
878 set_precision(0.00001);
881 CWindowSlider::~CWindowSlider()
885 int CWindowSlider::handle_event()
887 cwindow->update_position((double)get_value());
891 void CWindowSlider::set_position()
893 double new_length = mwindow->edl->tracks->total_length();
894 update(mwindow->theme->cslider_w,
895 mwindow->edl->local_session->get_selectionstart(1),
900 int CWindowSlider::increase_value()
903 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
904 lock_window("CWindowSlider::increase_value");
908 int CWindowSlider::decrease_value()
911 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
912 lock_window("CWindowSlider::decrease_value");
917 // CWindowDestination::CWindowDestination(MWindow *mwindow, CWindowGUI *cwindow, int x, int y)
918 // : BC_PopupTextBox(cwindow,
919 // &cwindow->destinations,
920 // cwindow->destinations.values[cwindow->cwindow->destination]->get_text(),
926 // this->mwindow = mwindow;
927 // this->cwindow = cwindow;
930 // CWindowDestination::~CWindowDestination()
934 // int CWindowDestination::handle_event()
945 CWindowTransport::CWindowTransport(MWindow *mwindow,
949 : PlayTransport(mwindow,
957 EDL* CWindowTransport::get_edl()
962 void CWindowTransport::goto_start()
964 gui->unlock_window();
965 handle_transport(REWIND, 1);
967 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
968 mwindow->goto_start();
969 mwindow->gui->unlock_window();
971 gui->lock_window("CWindowTransport::goto_start 2");
974 void CWindowTransport::goto_end()
976 gui->unlock_window();
977 handle_transport(GOTO_END, 1);
979 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
981 mwindow->gui->unlock_window();
983 gui->lock_window("CWindowTransport::goto_end 2");
988 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
991 mwindow->theme->ccanvas_x,
992 mwindow->theme->ccanvas_y,
993 mwindow->theme->ccanvas_w,
994 mwindow->theme->ccanvas_h,
997 mwindow->edl->session->cwindow_scrollbars)
999 this->mwindow = mwindow;
1003 void CWindowCanvas::status_event()
1005 gui->draw_status(1);
1008 int CWindowCanvas::get_fullscreen()
1010 return mwindow->session->cwindow_fullscreen;
1013 void CWindowCanvas::set_fullscreen(int value)
1015 mwindow->session->cwindow_fullscreen = value;
1019 void CWindowCanvas::update_zoom(int x, int y, float zoom)
1021 use_scrollbars = mwindow->edl->session->cwindow_scrollbars;
1023 mwindow->edl->session->cwindow_xscroll = x;
1024 mwindow->edl->session->cwindow_yscroll = y;
1025 mwindow->edl->session->cwindow_zoom = zoom;
1028 void CWindowCanvas::zoom_auto()
1030 gui->zoom_canvas(0, 1);
1033 int CWindowCanvas::get_xscroll()
1035 return mwindow->edl->session->cwindow_xscroll;
1038 int CWindowCanvas::get_yscroll()
1040 return mwindow->edl->session->cwindow_yscroll;
1044 float CWindowCanvas::get_zoom()
1046 return mwindow->edl->session->cwindow_zoom;
1049 void CWindowCanvas::draw_refresh(int flush)
1051 if(get_canvas() && !get_canvas()->get_video_on())
1054 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
1056 float in_x1, in_y1, in_x2, in_y2;
1057 float out_x1, out_y1, out_x2, out_y2;
1058 get_transfers(mwindow->edl,
1068 if(!EQUIV(out_x1, 0) ||
1069 !EQUIV(out_y1, 0) ||
1070 !EQUIV(out_x2, get_canvas()->get_w()) ||
1071 !EQUIV(out_y2, get_canvas()->get_h()))
1073 get_canvas()->clear_box(0,
1075 get_canvas()->get_w(),
1076 get_canvas()->get_h());
1079 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1080 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1083 if(out_x2 > out_x1 &&
1088 // Can't use OpenGL here because it is called asynchronously of the
1089 // playback operation.
1090 get_canvas()->draw_vframe(refresh_frame,
1093 (int)(out_x2 - out_x1),
1094 (int)(out_y2 - out_y1),
1097 (int)(in_x2 - in_x1),
1098 (int)(in_y2 - in_y1),
1104 get_canvas()->clear_box(0,
1106 get_canvas()->get_w(),
1107 get_canvas()->get_h());
1111 // allow last opengl write to complete before redraw
1112 // tried sync_display, glFlush, glxMake*Current(0..)
1114 get_canvas()->flash(flush);
1116 //printf("CWindowCanvas::draw_refresh 10\n");
1119 #define CROPHANDLE_W 10
1120 #define CROPHANDLE_H 10
1122 void CWindowCanvas::draw_crophandle(int x, int y)
1124 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1132 #define CONTROL_W 10
1133 #define CONTROL_H 10
1134 #define FIRST_CONTROL_W 20
1135 #define FIRST_CONTROL_H 20
1137 #define BC_INFINITY 65536
1139 #define RULERHANDLE_W 16
1140 #define RULERHANDLE_H 16
1144 int CWindowCanvas::do_ruler(int draw,
1150 float x1 = mwindow->edl->session->ruler_x1;
1151 float y1 = mwindow->edl->session->ruler_y1;
1152 float x2 = mwindow->edl->session->ruler_x2;
1153 float y2 = mwindow->edl->session->ruler_y2;
1154 float canvas_x1 = x1;
1155 float canvas_y1 = y1;
1156 float canvas_x2 = x2;
1157 float canvas_y2 = y2;
1158 float output_x = get_cursor_x();
1159 float output_y = get_cursor_y();
1160 float canvas_cursor_x = output_x;
1161 float canvas_cursor_y = output_y;
1163 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1164 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1165 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1166 mwindow->session->cwindow_output_x = roundf(output_x);
1167 mwindow->session->cwindow_output_y = roundf(output_y);
1169 if(button_press && get_buttonpress() == 1)
1171 gui->ruler_handle = -1;
1172 gui->ruler_translate = 0;
1175 gui->ruler_translate = 1;
1176 gui->ruler_origin_x = x1;
1177 gui->ruler_origin_y = y1;
1180 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1181 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1182 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1183 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1185 gui->ruler_handle = 0;
1186 gui->ruler_origin_x = x1;
1187 gui->ruler_origin_y = y1;
1190 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1191 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1192 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1193 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1195 gui->ruler_handle = 1;
1196 gui->ruler_origin_x = x2;
1197 gui->ruler_origin_y = y2;
1201 // Start new selection
1202 if(!gui->ruler_translate &&
1203 (gui->ruler_handle < 0 ||
1208 do_ruler(1, 0, 0, 0);
1209 get_canvas()->flash();
1210 gui->ruler_handle = 1;
1211 mwindow->edl->session->ruler_x1 = output_x;
1212 mwindow->edl->session->ruler_y1 = output_y;
1213 mwindow->edl->session->ruler_x2 = output_x;
1214 mwindow->edl->session->ruler_y2 = output_y;
1215 gui->ruler_origin_x = mwindow->edl->session->ruler_x2;
1216 gui->ruler_origin_y = mwindow->edl->session->ruler_y2;
1219 gui->x_origin = output_x;
1220 gui->y_origin = output_y;
1221 gui->current_operation = CWINDOW_RULER;
1222 gui->tool_panel->raise_window();
1228 if(gui->current_operation == CWINDOW_RULER)
1230 if(gui->ruler_translate)
1233 do_ruler(1, 0, 0, 0);
1234 float x_difference = mwindow->edl->session->ruler_x1;
1235 float y_difference = mwindow->edl->session->ruler_y1;
1236 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1237 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1238 x_difference -= mwindow->edl->session->ruler_x1;
1239 y_difference -= mwindow->edl->session->ruler_y1;
1240 mwindow->edl->session->ruler_x2 -= x_difference;
1241 mwindow->edl->session->ruler_y2 -= y_difference;
1243 do_ruler(1, 0, 0, 0);
1244 get_canvas()->flash();
1248 switch(gui->ruler_handle)
1251 do_ruler(1, 0, 0, 0);
1252 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1253 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1254 if(gui->alt_down() || gui->ctrl_down())
1256 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1257 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1261 double distance_value =
1262 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1263 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1264 if(angle_value < 22)
1265 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2;
1267 if(angle_value > 67)
1268 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2;
1270 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 &&
1271 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1273 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1274 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1277 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 && 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 &&
1284 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1286 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1287 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1291 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1292 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1295 do_ruler(1, 0, 0, 0);
1296 get_canvas()->flash();
1301 do_ruler(1, 0, 0, 0);
1302 mwindow->edl->session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1303 mwindow->edl->session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1304 if(gui->alt_down() || gui->ctrl_down())
1306 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1307 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1311 double distance_value =
1312 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1313 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1314 if(angle_value < 22)
1315 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1;
1317 if(angle_value > 67)
1318 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1;
1320 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1321 mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1323 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1324 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1327 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1328 mwindow->edl->session->ruler_y2 > mwindow->edl->session->ruler_y1)
1330 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1331 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1334 if(mwindow->edl->session->ruler_x2 > mwindow->edl->session->ruler_x1 && 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;
1341 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1342 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1345 do_ruler(1, 0, 0, 0);
1346 get_canvas()->flash();
1350 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1354 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1359 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1360 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1361 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1362 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1364 set_cursor(UPRIGHT_ARROW_CURSOR);
1367 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1368 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1369 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1370 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1372 set_cursor(UPRIGHT_ARROW_CURSOR);
1375 set_cursor(CROSS_CURSOR);
1377 // Update current position
1382 // Assume no ruler measurement if 0 length
1383 if(draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)))
1385 get_canvas()->set_inverse();
1386 get_canvas()->set_color(WHITE);
1387 get_canvas()->draw_line((int)canvas_x1,
1391 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1393 roundf(canvas_x1) + RULERHANDLE_W / 2,
1395 get_canvas()->draw_line(roundf(canvas_x1),
1396 roundf(canvas_y1) - RULERHANDLE_H / 2,
1398 roundf(canvas_y1) + RULERHANDLE_H / 2);
1399 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1401 roundf(canvas_x2) + RULERHANDLE_W / 2,
1403 get_canvas()->draw_line(roundf(canvas_x2),
1404 roundf(canvas_y2) - RULERHANDLE_H / 2,
1406 roundf(canvas_y2) + RULERHANDLE_H / 2);
1407 get_canvas()->set_opaque();
1414 static inline double line_dist(float cx,float cy, float tx,float ty)
1416 double dx = tx-cx, dy = ty-cy;
1417 return sqrt(dx*dx + dy*dy);
1420 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1422 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1423 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1427 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1428 int button_press, int cursor_motion, int draw)
1430 // Retrieve points from top recordable track
1431 //printf("CWindowCanvas::do_mask 1\n");
1432 Track *track = gui->cwindow->calculate_affected_track();
1433 //printf("CWindowCanvas::do_mask 2\n");
1435 if(!track) return 0;
1436 //printf("CWindowCanvas::do_mask 3\n");
1438 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1439 int64_t position = track->to_units(
1440 mwindow->edl->local_session->get_selectionstart(1),
1442 ArrayList<MaskPoint*> points;
1444 // Determine the points based on whether
1445 // new keyframes will be generated or drawing is performed.
1446 // If keyframe generation occurs, use the interpolated mask.
1447 // If no keyframe generation occurs, use the previous mask.
1448 int use_interpolated = 0;
1449 if(button_press || cursor_motion) {
1450 #ifdef USE_KEYFRAME_SPANNING
1451 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1452 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1455 mask_autos->get_prev_auto(track->to_units(selection_start, 0),
1456 PLAY_FORWARD, first, 1);
1458 mask_autos->get_prev_auto(track->to_units(selection_end, 0),
1459 PLAY_FORWARD, last, 1);
1461 if(last == first && (!mwindow->edl->session->auto_keyframes))
1462 use_interpolated = 0;
1464 // If keyframe spanning occurs, use the interpolated points.
1465 // If new keyframe is generated, use the interpolated points.
1466 use_interpolated = 1;
1469 if(mwindow->edl->session->auto_keyframes)
1470 use_interpolated = 1;
1474 use_interpolated = 1;
1476 if(use_interpolated) {
1477 // Interpolate the points to get exactly what is being rendered at this position.
1478 mask_autos->get_points(&points,
1479 mwindow->edl->session->cwindow_mask,
1484 // Use the prev mask
1486 mask_autos->get_prev_auto(position,
1490 ((MaskAuto*)prev)->get_points(&points,
1491 mwindow->edl->session->cwindow_mask);
1494 // Projector zooms relative to the center of the track output.
1495 float half_track_w = (float)track->track_w / 2;
1496 float half_track_h = (float)track->track_h / 2;
1497 // Translate mask to projection
1498 float projector_x, projector_y, projector_z;
1499 track->automation->get_projector(
1500 &projector_x, &projector_y, &projector_z,
1501 position, PLAY_FORWARD);
1504 // Get position of cursor relative to mask
1505 float cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
1506 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1507 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1509 projector_x += mwindow->edl->session->output_w / 2;
1510 projector_y += mwindow->edl->session->output_h / 2;
1511 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1512 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1514 // Fix cursor origin
1516 gui->x_origin = mask_cursor_x;
1517 gui->y_origin = mask_cursor_y;
1521 // Points of closest line
1522 int shortest_point1 = -1;
1523 int shortest_point2 = -1;
1525 int shortest_point = -1;
1526 // Distance to closest line
1527 float shortest_line_distance = BC_INFINITY;
1528 // Distance to closest point
1529 float shortest_point_distance = BC_INFINITY;
1530 int selected_point = -1;
1531 int selected_control_point = -1;
1532 float selected_control_point_distance = BC_INFINITY;
1533 ArrayList<int> x_points;
1534 ArrayList<int> y_points;
1536 if(!cursor_motion) {
1538 get_canvas()->set_color(WHITE);
1539 get_canvas()->set_inverse();
1541 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1543 // Never draw closed polygon and a closed
1544 // polygon is harder to add points to.
1545 for(int i = 0; i < points.size() && !result; i++) {
1546 MaskPoint *point1 = points.get(i);
1547 MaskPoint *point2 = (i >= points.size() - 1) ?
1548 points.get(0) : points.get(i + 1);
1550 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1551 if(point_distance1 < shortest_point_distance || shortest_point < 0) {
1552 shortest_point_distance = point_distance1;
1556 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1557 if(point_distance2 < shortest_point_distance || shortest_point < 0) {
1558 shortest_point_distance = point_distance2;
1559 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1563 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1565 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1566 //point1->x, point1->y, point2->x, point2->y, projector_z);
1567 for(int j = 0; j <= segments && !result; j++) {
1568 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1569 float x0 = point1->x, y0 = point1->y;
1570 float x1 = point1->x + point1->control_x2;
1571 float y1 = point1->y + point1->control_y2;
1572 float x2 = point2->x + point2->control_x1;
1573 float y2 = point2->y + point2->control_y1;
1574 float x3 = point2->x, y3 = point2->y;
1575 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1576 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1577 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1578 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1579 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1580 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1581 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1582 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1584 float t = (float)j / segments;
1585 float tpow2 = t * t;
1586 float tpow3 = t * t * t;
1588 float invtpow2 = invt * invt;
1589 float invtpow3 = invt * invt * invt;
1591 float x = ( invtpow3 * x0
1592 + 3 * t * invtpow2 * x1
1593 + 3 * tpow2 * invt * x2
1595 float y = ( invtpow3 * y0
1596 + 3 * t * invtpow2 * y1
1597 + 3 * tpow2 * invt * y2
1599 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1600 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1601 // Test new point addition
1603 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1605 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1606 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1607 if(line_distance < shortest_line_distance ||
1608 shortest_point1 < 0) {
1609 shortest_line_distance = line_distance;
1610 shortest_point1 = i;
1611 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1612 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1613 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1616 // Test existing point selection
1618 if(gui->ctrl_down()) {
1619 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1621 if(distance < selected_control_point_distance) {
1623 selected_control_point = 1;
1624 selected_control_point_distance = distance;
1628 if(!gui->shift_down()) {
1629 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1630 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
1635 selected_point = shortest_point;
1638 // Test second point
1639 if(gui->ctrl_down()) {
1640 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1642 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1643 if(distance < selected_control_point_distance) {
1644 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1645 selected_control_point = 0;
1646 selected_control_point_distance = distance;
1649 else if(i < points.size() - 1) {
1650 if(!gui->shift_down()) {
1651 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1652 if(test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3)) {
1653 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1657 selected_point = shortest_point;
1662 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1666 if(draw) { // Draw joining line
1667 x_points.append((int)canvas_x);
1668 y_points.append((int)canvas_y);
1672 if(draw) { // Draw second anchor
1673 if(i < points.size() - 1) {
1674 if(i == gui->affected_point - 1)
1675 get_canvas()->draw_disc(
1676 (int)canvas_x - CONTROL_W / 2,
1677 (int)canvas_y - CONTROL_W / 2,
1678 CONTROL_W, CONTROL_H);
1680 get_canvas()->draw_circle(
1681 (int)canvas_x - CONTROL_W / 2,
1682 (int)canvas_y - CONTROL_W / 2,
1683 CONTROL_W, CONTROL_H);
1684 // char string[BCTEXTLEN];
1685 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1686 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1688 // Draw second control point.
1689 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1690 get_canvas()->draw_line(
1691 (int)canvas_x, (int)canvas_y,
1692 (int)canvas_x2, (int)canvas_y2);
1693 get_canvas()->draw_rectangle(
1694 (int)canvas_x2 - CONTROL_W / 2,
1695 (int)canvas_y2 - CONTROL_H / 2,
1696 CONTROL_W, CONTROL_H);
1701 // Draw first anchor
1702 if(i == 0 && draw) {
1703 char mask_label[BCSTRLEN];
1704 sprintf(mask_label, "%d",
1705 mwindow->edl->session->cwindow_mask);
1706 get_canvas()->draw_text(
1707 (int)canvas_x - FIRST_CONTROL_W,
1708 (int)canvas_y - FIRST_CONTROL_H,
1711 get_canvas()->draw_disc(
1712 (int)canvas_x - FIRST_CONTROL_W / 2,
1713 (int)canvas_y - FIRST_CONTROL_H / 2,
1714 FIRST_CONTROL_W, FIRST_CONTROL_H);
1717 // Draw first control point.
1719 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1720 get_canvas()->draw_line(
1721 (int)canvas_x, (int)canvas_y,
1722 (int)canvas_x1, (int)canvas_y1);
1723 get_canvas()->draw_rectangle(
1724 (int)canvas_x1 - CONTROL_W / 2,
1725 (int)canvas_y1 - CONTROL_H / 2,
1726 CONTROL_W, CONTROL_H);
1728 x_points.append((int)canvas_x);
1729 y_points.append((int)canvas_y);
1732 //printf("CWindowCanvas::do_mask 1\n");
1736 //printf("CWindowCanvas::do_mask 1\n");
1739 get_canvas()->draw_polygon(&x_points, &y_points);
1740 get_canvas()->set_opaque();
1742 //printf("CWindowCanvas::do_mask 1\n");
1745 if(button_press && !result) {
1746 gui->affected_track = gui->cwindow->calculate_affected_track();
1748 // Get keyframe outside the EDL to edit. This must be rendered
1749 // instead of the EDL keyframes when it exists. Then it must be
1750 // applied to the EDL keyframes on buttonrelease.
1751 if(gui->affected_track) {
1752 #ifdef USE_KEYFRAME_SPANNING
1753 // Make copy of current parameters in local keyframe
1754 gui->mask_keyframe =
1755 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1758 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1761 gui->mask_keyframe =
1762 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1767 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1770 // Translate entire keyframe
1771 if(gui->alt_down() && mask->points.size()) {
1772 mwindow->undo->update_undo_before(_("mask translate"), 0);
1773 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1774 gui->affected_point = 0;
1777 // Existing point or control point was selected
1778 if(selected_point >= 0) {
1779 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1780 gui->affected_point = selected_point;
1782 if(selected_control_point == 0)
1783 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1785 if(selected_control_point == 1)
1786 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1788 gui->current_operation = mwindow->edl->session->cwindow_operation;
1790 else // No existing point or control point was selected so create a new one
1791 if(!gui->ctrl_down() && !gui->alt_down()) {
1792 mwindow->undo->update_undo_before(_("mask point"), 0);
1793 // Create the template
1794 MaskPoint *point = new MaskPoint;
1795 point->x = mask_cursor_x;
1796 point->y = mask_cursor_y;
1797 point->control_x1 = 0;
1798 point->control_y1 = 0;
1799 point->control_x2 = 0;
1800 point->control_y2 = 0;
1803 if(shortest_point2 < shortest_point1) {
1804 shortest_point2 ^= shortest_point1;
1805 shortest_point1 ^= shortest_point2;
1806 shortest_point2 ^= shortest_point1;
1811 // printf("CWindowGUI::do_mask 40\n");
1812 // mwindow->edl->dump();
1813 // printf("CWindowGUI::do_mask 50\n");
1817 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1818 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1819 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1821 // Append to end of list
1822 if( shortest_point1 == shortest_point2 ||
1823 labs(shortest_point1 - shortest_point2) > 1) {
1824 #ifdef USE_KEYFRAME_SPANNING
1826 MaskPoint *new_point = new MaskPoint;
1827 points.append(new_point);
1828 *new_point = *point;
1829 gui->affected_point = points.size() - 1;
1833 // Need to apply the new point to every keyframe
1834 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1835 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1836 MaskPoint *new_point = new MaskPoint;
1837 submask->points.append(new_point);
1838 *new_point = *point;
1839 if(current == (MaskAuto*)mask_autos->default_auto)
1840 current = (MaskAuto*)mask_autos->first;
1842 current = (MaskAuto*)NEXT;
1844 gui->affected_point = mask->points.size() - 1;
1850 // Insert between 2 points, shifting back point 2
1851 if(shortest_point1 >= 0 && shortest_point2 >= 0) {
1853 #ifdef USE_KEYFRAME_SPANNING
1854 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1856 if(points.size() >= shortest_point2) {
1857 MaskPoint *new_point = new MaskPoint;
1859 for(int i = points.size() - 1;
1860 i > shortest_point2;
1862 points.values[i] = points.values[i - 1];
1863 points.values[shortest_point2] = new_point;
1865 *new_point = *point;
1870 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1871 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1872 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1874 if(submask->points.size() >= shortest_point2) {
1875 MaskPoint *new_point = new MaskPoint;
1876 submask->points.append(0);
1877 for(int i = submask->points.size() - 1;
1878 i > shortest_point2;
1880 submask->points.values[i] = submask->points.values[i - 1];
1881 submask->points.values[shortest_point2] = new_point;
1883 *new_point = *point;
1886 if(current == (MaskAuto*)mask_autos->default_auto)
1887 current = (MaskAuto*)mask_autos->first;
1889 current = (MaskAuto*)NEXT;
1893 gui->affected_point = shortest_point2;
1898 // printf("CWindowGUI::do_mask 20\n");
1899 // mwindow->edl->dump();
1900 // printf("CWindowGUI::do_mask 30\n");
1903 //printf("CWindowCanvas::do_mask 1\n");
1904 // Create the first point.
1905 #ifdef USE_KEYFRAME_SPANNING
1906 MaskPoint *new_point = new MaskPoint;
1907 points.append(new_point);
1908 *new_point = *point;
1909 gui->affected_point = points.size() - 1;
1911 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1912 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1913 MaskPoint *new_point = new MaskPoint;
1914 submask->points.append(new_point);
1915 *new_point = *point;
1916 if(current == (MaskAuto*)mask_autos->default_auto)
1917 current = (MaskAuto*)mask_autos->first;
1919 current = (MaskAuto*)NEXT;
1921 gui->affected_point = points.size() - 1;
1924 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
1927 gui->current_operation = mwindow->edl->session->cwindow_operation;
1928 // Delete the template
1937 if(button_press && result) {
1938 #ifdef USE_KEYFRAME_SPANNING
1939 MaskPoint *point = points.values[gui->affected_point];
1940 gui->center_x = point->x;
1941 gui->center_y = point->y;
1942 gui->control_in_x = point->control_x1;
1943 gui->control_in_y = point->control_y1;
1944 gui->control_out_x = point->control_x2;
1945 gui->control_out_y = point->control_y2;
1946 gui->tool_panel->raise_window();
1948 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1949 MaskPoint *point = mask->points.values[gui->affected_point];
1950 gui->center_x = point->x;
1951 gui->center_y = point->y;
1952 gui->control_in_x = point->control_x1;
1953 gui->control_in_y = point->control_y1;
1954 gui->control_out_x = point->control_x2;
1955 gui->control_out_y = point->control_y2;
1956 gui->tool_panel->raise_window();
1960 //printf("CWindowCanvas::do_mask 8\n");
1963 #ifdef USE_KEYFRAME_SPANNING
1964 // Must update the reference keyframes for every cursor motion
1965 gui->mask_keyframe =
1966 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1969 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1972 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1974 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1975 if( gui->affected_point >= 0 && gui->affected_point < mask->points.size() &&
1976 gui->current_operation != CWINDOW_NONE) {
1977 // mwindow->undo->update_undo_before(_("mask point"), this);
1978 #ifdef USE_KEYFRAME_SPANNING
1979 MaskPoint *point = points.get(gui->affected_point);
1981 MaskPoint *point = mask->points.get(gui->affected_point);
1983 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
1984 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask->points.size(), gui->affected_point);
1986 float last_x = point->x;
1987 float last_y = point->y;
1988 float last_control_x1 = point->control_x1;
1989 float last_control_y1 = point->control_y1;
1990 float last_control_x2 = point->control_x2;
1991 float last_control_y2 = point->control_y2;
1993 switch(gui->current_operation) {
1995 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1996 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
1997 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
2000 case CWINDOW_MASK_CONTROL_IN:
2001 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
2002 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
2005 case CWINDOW_MASK_CONTROL_OUT:
2006 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
2007 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
2010 case CWINDOW_MASK_TRANSLATE:
2011 #ifdef USE_KEYFRAME_SPANNING
2012 for(int i = 0; i < points.size(); i++) {
2013 points.values[i]->x += mask_cursor_x - gui->x_origin;
2014 points.values[i]->y += mask_cursor_y - gui->y_origin;
2017 for(int i = 0; i < mask->points.size(); i++) {
2018 mask->points.values[i]->x += mask_cursor_x - gui->x_origin;
2019 mask->points.values[i]->y += mask_cursor_y - gui->y_origin;
2022 gui->x_origin = mask_cursor_x;
2023 gui->y_origin = mask_cursor_y;
2027 if( !EQUIV(last_x, point->x) ||
2028 !EQUIV(last_y, point->y) ||
2029 !EQUIV(last_control_x1, point->control_x1) ||
2030 !EQUIV(last_control_y1, point->control_y1) ||
2031 !EQUIV(last_control_x2, point->control_x2) ||
2032 !EQUIV(last_control_y2, point->control_y2)) {
2038 if(gui->current_operation == CWINDOW_NONE) {
2039 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
2041 for(int i = 0; i < points.size() && !over_point; i++) {
2042 MaskPoint *point = points.get(i);
2043 float x0 = point->x;
2044 float y0 = point->y;
2045 float x1 = point->x + point->control_x1;
2046 float y1 = point->y + point->control_y1;
2047 float x2 = point->x + point->control_x2;
2048 float y2 = point->y + point->control_y2;
2049 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
2050 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
2052 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
2053 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
2057 if(!over_point && gui->ctrl_down()) {
2058 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
2059 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
2060 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2061 if(test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1)) {
2065 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2066 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2067 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2068 if(test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2)) {
2075 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2080 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2083 #ifdef USE_KEYFRAME_SPANNING
2084 // Must commit change after operation.
2085 if(rerender && track) {
2086 // Swap EDL keyframe with original.
2087 // Apply new values to keyframe span
2088 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2089 temp_keyframe.copy_data(gui->mask_keyframe);
2090 // Apply interpolated points back to keyframe
2091 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2092 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2093 mask_autos->update_parameter(&temp_keyframe);
2097 points.remove_all_objects();
2098 //printf("CWindowCanvas::do_mask 20\n");
2102 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2105 int radius = mwindow->edl->session->eyedrop_radius;
2113 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2118 row1 = gui->eyedrop_y - radius;
2119 row2 = gui->eyedrop_y + radius;
2120 column1 = gui->eyedrop_x - radius;
2121 column2 = gui->eyedrop_x + radius;
2123 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2124 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2125 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2126 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2128 if(row2 <= row1) row2 = row1 + 1;
2129 if(column2 <= column1) column2 = column1 + 1;
2136 output_to_canvas(mwindow->edl, 0, x1, y1);
2137 output_to_canvas(mwindow->edl, 0, x2, y2);
2138 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2140 if(x2 - x1 >= 1 && y2 - y1 >= 1)
2142 get_canvas()->set_inverse();
2143 get_canvas()->set_color(WHITE);
2145 get_canvas()->draw_rectangle((int)x1,
2150 get_canvas()->set_opaque();
2151 get_canvas()->flash();
2159 gui->current_operation = CWINDOW_EYEDROP;
2160 gui->tool_panel->raise_window();
2163 if(gui->current_operation == CWINDOW_EYEDROP)
2165 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2167 // Get color out of frame.
2168 // Doesn't work during playback because that bypasses the refresh frame.
2169 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2171 float cursor_x = get_cursor_x();
2172 float cursor_y = get_cursor_y();
2173 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2174 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2175 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2177 row1 = cursor_y - radius;
2178 row2 = cursor_y + radius;
2179 column1 = cursor_x - radius;
2180 column2 = cursor_x + radius;
2181 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2182 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2183 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2184 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2185 if(row2 <= row1) row2 = row1 + 1;
2186 if(column2 <= column1) column2 = column1 + 1;
2190 if(gui->eyedrop_visible)
2193 do_eyedrop(temp, 0, 1);
2194 gui->eyedrop_visible = 0;
2197 gui->eyedrop_x = cursor_x;
2198 gui->eyedrop_y = cursor_y;
2203 do_eyedrop(temp, 0, 1);
2204 gui->eyedrop_visible = 1;
2207 // Decompression coefficients straight out of jpeglib
2208 #define V_TO_R 1.40200
2209 #define V_TO_G -0.71414
2211 #define U_TO_G -0.34414
2212 #define U_TO_B 1.77200
2214 #define GET_COLOR(type, components, max, do_yuv) \
2216 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2218 float red = (float)*row++ / max; \
2219 float green = (float)*row++ / max; \
2220 float blue = (float)*row++ / max; \
2223 float r = red + V_TO_R * (blue - 0.5); \
2224 float g = red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
2225 float b = red + U_TO_B * (green - 0.5); \
2226 mwindow->edl->local_session->red += r; \
2227 mwindow->edl->local_session->green += g; \
2228 mwindow->edl->local_session->blue += b; \
2229 if(r > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = r; \
2230 if(g > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = g; \
2231 if(b > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = b; \
2235 mwindow->edl->local_session->red += red; \
2236 mwindow->edl->local_session->green += green; \
2237 mwindow->edl->local_session->blue += blue; \
2238 if(red > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = red; \
2239 if(green > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = green; \
2240 if(blue > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = blue; \
2246 mwindow->edl->local_session->red = 0;
2247 mwindow->edl->local_session->green = 0;
2248 mwindow->edl->local_session->blue = 0;
2249 mwindow->edl->local_session->red_max = 0;
2250 mwindow->edl->local_session->green_max = 0;
2251 mwindow->edl->local_session->blue_max = 0;
2252 for(int i = row1; i < row2; i++)
2254 for(int j = column1; j < column2; j++)
2256 switch(refresh_frame->get_color_model())
2259 GET_COLOR(unsigned char, 3, 0xff, 1);
2262 GET_COLOR(unsigned char, 4, 0xff, 1);
2265 GET_COLOR(uint16_t, 3, 0xffff, 1);
2267 case BC_YUVA16161616:
2268 GET_COLOR(uint16_t, 4, 0xffff, 1);
2271 GET_COLOR(unsigned char, 3, 0xff, 0);
2274 GET_COLOR(unsigned char, 4, 0xff, 0);
2277 GET_COLOR(float, 3, 1.0, 0);
2280 GET_COLOR(float, 4, 1.0, 0);
2286 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2287 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2288 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2293 mwindow->edl->local_session->red = 0;
2294 mwindow->edl->local_session->green = 0;
2295 mwindow->edl->local_session->blue = 0;
2296 gui->eyedrop_visible = 0;
2305 // Can't rerender since the color value is from the output of any effect it
2308 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2314 void CWindowCanvas::draw_overlays()
2316 if(mwindow->edl->session->safe_regions)
2318 draw_safe_regions();
2321 if(mwindow->edl->session->cwindow_scrollbars)
2323 // Always draw output rectangle
2324 float x1, y1, x2, y2;
2326 x2 = mwindow->edl->session->output_w;
2328 y2 = mwindow->edl->session->output_h;
2329 output_to_canvas(mwindow->edl, 0, x1, y1);
2330 output_to_canvas(mwindow->edl, 0, x2, y2);
2332 get_canvas()->set_inverse();
2333 get_canvas()->set_color(WHITE);
2335 get_canvas()->draw_rectangle((int)x1,
2340 get_canvas()->set_opaque();
2343 if(gui->highlighted)
2345 get_canvas()->set_color(WHITE);
2346 get_canvas()->set_inverse();
2347 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2348 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2349 get_canvas()->set_opaque();
2352 int temp1 = 0, temp2 = 0;
2353 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2354 switch(mwindow->edl->session->cwindow_operation)
2356 case CWINDOW_CAMERA:
2360 case CWINDOW_PROJECTOR:
2369 do_mask(temp1, temp2, 0, 0, 1);
2373 do_ruler(1, 0, 0, 0);
2376 case CWINDOW_EYEDROP:
2377 if(gui->eyedrop_visible)
2380 do_eyedrop(rerender, 0, 1);
2381 gui->eyedrop_visible = 1;
2387 void CWindowCanvas::draw_safe_regions()
2389 float action_x1, action_x2, action_y1, action_y2;
2390 float title_x1, title_x2, title_y1, title_y2;
2392 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2393 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2394 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2395 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2396 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2397 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2398 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2399 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2401 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2402 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2403 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2404 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2406 get_canvas()->set_inverse();
2407 get_canvas()->set_color(WHITE);
2409 get_canvas()->draw_rectangle((int)action_x1,
2411 (int)(action_x2 - action_x1),
2412 (int)(action_y2 - action_y1));
2413 get_canvas()->draw_rectangle((int)title_x1,
2415 (int)(title_x2 - title_x1),
2416 (int)(title_y2 - title_y1));
2418 get_canvas()->set_opaque();
2421 void CWindowCanvas::reset_keyframe(int do_camera)
2423 FloatAuto *x_keyframe = 0;
2424 FloatAuto *y_keyframe = 0;
2425 FloatAuto *z_keyframe = 0;
2426 Track *affected_track = 0;
2428 affected_track = gui->cwindow->calculate_affected_track();
2432 gui->cwindow->calculate_affected_autos(&x_keyframe,
2441 x_keyframe->set_value(0);
2442 y_keyframe->set_value(0);
2443 z_keyframe->set_value(1);
2445 mwindow->sync_parameters(CHANGE_PARAMS);
2450 void CWindowCanvas::reset_camera()
2455 void CWindowCanvas::reset_projector()
2460 int CWindowCanvas::test_crop(int button_press, int &redraw)
2463 int handle_selected = -1;
2464 float x1 = mwindow->edl->session->crop_x1;
2465 float y1 = mwindow->edl->session->crop_y1;
2466 float x2 = mwindow->edl->session->crop_x2;
2467 float y2 = mwindow->edl->session->crop_y2;
2468 float cursor_x = get_cursor_x();
2469 float cursor_y = get_cursor_y();
2470 float canvas_x1 = x1;
2471 float canvas_y1 = y1;
2472 float canvas_x2 = x2;
2473 float canvas_y2 = y2;
2474 float canvas_cursor_x = cursor_x;
2475 float canvas_cursor_y = cursor_y;
2477 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2478 // Use screen normalized coordinates for hot spot tests.
2479 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2480 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2483 if(gui->current_operation == CWINDOW_CROP)
2485 handle_selected = gui->crop_handle;
2488 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2489 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2491 handle_selected = 0;
2492 gui->crop_origin_x = x1;
2493 gui->crop_origin_y = y1;
2496 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2497 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2499 handle_selected = 1;
2500 gui->crop_origin_x = x2;
2501 gui->crop_origin_y = y1;
2504 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2505 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2507 handle_selected = 2;
2508 gui->crop_origin_x = x1;
2509 gui->crop_origin_y = y2;
2512 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2513 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2515 handle_selected = 3;
2516 gui->crop_origin_x = x2;
2517 gui->crop_origin_y = y2;
2522 gui->crop_origin_x = cursor_x;
2523 gui->crop_origin_y = cursor_y;
2526 // printf("test crop %d %d\n",
2527 // gui->current_operation,
2528 // handle_selected);
2535 gui->crop_translate = 1;
2536 gui->crop_origin_x1 = x1;
2537 gui->crop_origin_y1 = y1;
2538 gui->crop_origin_x2 = x2;
2539 gui->crop_origin_y2 = y2;
2542 gui->crop_translate = 0;
2544 gui->current_operation = CWINDOW_CROP;
2545 gui->crop_handle = handle_selected;
2546 gui->x_origin = cursor_x;
2547 gui->y_origin = cursor_y;
2548 gui->tool_panel->raise_window();
2551 if(handle_selected < 0 && !gui->crop_translate)
2555 mwindow->edl->session->crop_x1 = (int)x1;
2556 mwindow->edl->session->crop_y1 = (int)y1;
2557 mwindow->edl->session->crop_x2 = (int)x2;
2558 mwindow->edl->session->crop_y2 = (int)y2;
2563 // Translate all 4 points
2564 if(gui->current_operation == CWINDOW_CROP && gui->crop_translate)
2566 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2567 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2568 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2569 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2571 mwindow->edl->session->crop_x1 = (int)x1;
2572 mwindow->edl->session->crop_y1 = (int)y1;
2573 mwindow->edl->session->crop_x2 = (int)x2;
2574 mwindow->edl->session->crop_y2 = (int)y2;
2580 if(gui->current_operation == CWINDOW_CROP)
2582 switch(gui->crop_handle)
2585 x1 = gui->crop_origin_x;
2586 y1 = gui->crop_origin_y;
2587 x2 = gui->crop_origin_x;
2588 y2 = gui->crop_origin_y;
2589 if(cursor_x < gui->x_origin)
2591 if(cursor_y < gui->y_origin)
2597 if(cursor_y >= gui->y_origin)
2604 if(cursor_x >= gui->x_origin)
2606 if(cursor_y < gui->y_origin)
2612 if(cursor_y >= gui->y_origin)
2619 // printf("test crop %d %d %d %d\n",
2620 // mwindow->edl->session->crop_x1,
2621 // mwindow->edl->session->crop_y1,
2622 // mwindow->edl->session->crop_x2,
2623 // mwindow->edl->session->crop_y2);
2626 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2627 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2630 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2631 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2634 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2635 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2638 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2639 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2643 if(!EQUIV(mwindow->edl->session->crop_x1, x1) ||
2644 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2645 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2646 !EQUIV(mwindow->edl->session->crop_y2, y2))
2653 switch (gui->crop_handle)
2655 case 0: gui->crop_handle = 1; break;
2656 case 1: gui->crop_handle = 0; break;
2657 case 2: gui->crop_handle = 3; break;
2658 case 3: gui->crop_handle = 2; break;
2668 switch (gui->crop_handle)
2670 case 0: gui->crop_handle = 2; break;
2671 case 1: gui->crop_handle = 3; break;
2672 case 2: gui->crop_handle = 0; break;
2673 case 3: gui->crop_handle = 1; break;
2678 mwindow->edl->session->crop_x1 = (int)x1;
2679 mwindow->edl->session->crop_y1 = (int)y1;
2680 mwindow->edl->session->crop_x2 = (int)x2;
2681 mwindow->edl->session->crop_y2 = (int)y2;
2687 // Update cursor font
2688 if(handle_selected >= 0)
2690 switch(handle_selected)
2693 set_cursor(UPLEFT_RESIZE);
2696 set_cursor(UPRIGHT_RESIZE);
2699 set_cursor(DOWNLEFT_RESIZE);
2702 set_cursor(DOWNRIGHT_RESIZE);
2709 set_cursor(ARROW_CURSOR);
2711 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2715 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2716 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2717 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2718 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2719 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2720 // mwindow->edl->session->crop_x2,
2721 // mwindow->edl->session->crop_y2,
2722 // mwindow->edl->calculate_output_w(0),
2723 // mwindow->edl->calculate_output_h(0));
2729 void CWindowCanvas::draw_crop()
2731 get_canvas()->set_inverse();
2732 get_canvas()->set_color(WHITE);
2734 float x1 = mwindow->edl->session->crop_x1;
2735 float y1 = mwindow->edl->session->crop_y1;
2736 float x2 = mwindow->edl->session->crop_x2;
2737 float y2 = mwindow->edl->session->crop_y2;
2739 output_to_canvas(mwindow->edl, 0, x1, y1);
2740 output_to_canvas(mwindow->edl, 0, x2, y2);
2742 if(x2 - x1 && y2 - y1)
2743 get_canvas()->draw_rectangle((int)x1,
2748 draw_crophandle((int)x1, (int)y1);
2749 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2750 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2751 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2752 get_canvas()->set_opaque();
2762 void CWindowCanvas::draw_bezier(int do_camera)
2764 Track *track = gui->cwindow->calculate_affected_track();
2771 int64_t position = track->to_units(
2772 mwindow->edl->local_session->get_selectionstart(1),
2775 track->automation->get_projector(¢er_x,
2781 // center_x += track->track_w / 2;
2782 // center_y += track->track_h / 2;
2783 center_x += mwindow->edl->session->output_w / 2;
2784 center_y += mwindow->edl->session->output_h / 2;
2785 float track_x1 = center_x - track->track_w / 2 * center_z;
2786 float track_y1 = center_y - track->track_h / 2 * center_z;
2787 float track_x2 = track_x1 + track->track_w * center_z;
2788 float track_y2 = track_y1 + track->track_h * center_z;
2790 output_to_canvas(mwindow->edl, 0, track_x1, track_y1);
2791 output_to_canvas(mwindow->edl, 0, track_x2, track_y2);
2793 #define DRAW_PROJECTION(offset) \
2794 get_canvas()->draw_rectangle((int)track_x1 + offset, \
2795 (int)track_y1 + offset, \
2796 (int)(track_x2 - track_x1), \
2797 (int)(track_y2 - track_y1)); \
2798 get_canvas()->draw_line((int)track_x1 + offset, \
2799 (int)track_y1 + offset, \
2800 (int)track_x2 + offset, \
2801 (int)track_y2 + offset); \
2802 get_canvas()->draw_line((int)track_x2 + offset, \
2803 (int)track_y1 + offset, \
2804 (int)track_x1 + offset, \
2805 (int)track_y2 + offset); \
2809 get_canvas()->set_color(BLACK);
2812 // canvas->set_inverse();
2814 get_canvas()->set_color(GREEN);
2816 get_canvas()->set_color(RED);
2819 // canvas->set_opaque();
2823 int CWindowCanvas::test_bezier(int button_press,
2831 // Processing drag operation.
2832 // Create keyframe during first cursor motion.
2836 float cursor_x = get_cursor_x();
2837 float cursor_y = get_cursor_y();
2838 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2840 if(gui->current_operation == CWINDOW_CAMERA ||
2841 gui->current_operation == CWINDOW_PROJECTOR)
2843 if(!gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom)
2845 gui->translating_zoom = 1;
2846 gui->reset_affected();
2849 if(!gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom)
2851 gui->translating_zoom = 0;
2852 gui->reset_affected();
2855 // Get target keyframe
2856 float last_center_x;
2857 float last_center_y;
2858 float last_center_z;
2861 if(!gui->affected_x && !gui->affected_y && !gui->affected_z)
2863 FloatAutos *affected_x_autos;
2864 FloatAutos *affected_y_autos;
2865 FloatAutos *affected_z_autos;
2866 if(!gui->affected_track) return 0;
2867 double position = mwindow->edl->local_session->get_selectionstart(1);
2868 int64_t track_position = gui->affected_track->to_units(position, 0);
2870 if(mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA)
2872 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_X];
2873 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Y];
2874 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Z];
2878 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_X];
2879 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Y];
2880 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Z];
2884 if(gui->translating_zoom)
2886 FloatAuto *previous = 0;
2887 FloatAuto *next = 0;
2888 float new_z = affected_z_autos->get_value(
2894 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2895 affected_z_autos, 1, &created, 0);
2897 gui->affected_z->set_value(new_z);
2903 FloatAuto *previous = 0;
2904 FloatAuto *next = 0;
2905 float new_x = affected_x_autos->get_value(
2912 float new_y = affected_y_autos->get_value(
2918 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2919 affected_x_autos, 1, &created, 0);
2921 gui->affected_x->set_value(new_x);
2925 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2926 affected_y_autos, 1, &created, 0);
2928 gui->affected_y->set_value(new_y);
2935 if(gui->translating_zoom)
2937 gui->center_z = gui->affected_z->get_value();
2941 gui->center_x = gui->affected_x->get_value();
2942 gui->center_y = gui->affected_y->get_value();
2949 if(gui->translating_zoom)
2951 last_center_z = gui->affected_z->get_value();
2952 float z = gui->center_z + (cursor_y - gui->y_origin) / 128;
2954 if(!EQUIV(last_center_z, z))
2960 gui->affected_z->set_value(z);
2964 last_center_x = gui->affected_x->get_value();
2965 last_center_y = gui->affected_y->get_value();
2966 float x = gui->center_x + cursor_x - gui->x_origin;
2967 float y = gui->center_y + cursor_y - gui->y_origin;
2968 gui->affected_x->set_value(x);
2969 gui->affected_y->set_value(y);
2970 if( !EQUIV(last_center_x, x) || !EQUIV(last_center_y, y) )
2976 gui->affected_x->set_value(x);
2977 gui->affected_y->set_value(y);
2984 // Begin drag operation. Don't create keyframe here.
2986 // Get affected track off of the first recordable video track.
2987 // Calculating based on the alpha channel would require recording what layer
2988 // each output pixel belongs to as they're rendered and stacked. Forget it.
2989 gui->affected_track = gui->cwindow->calculate_affected_track();
2990 gui->reset_affected();
2992 if(gui->affected_track)
2994 if(gui->current_operation == CWINDOW_CAMERA)
2995 mwindow->undo->update_undo_before(_("camera"), this);
2997 mwindow->undo->update_undo_before(_("projector"), this);
2999 gui->current_operation =
3000 mwindow->edl->session->cwindow_operation;
3001 gui->tool_panel->raise_window();
3010 int CWindowCanvas::test_zoom(int &redraw)
3016 if( mwindow->edl->session->cwindow_scrollbars ) {
3017 if( *gui->zoom_panel->get_text() != 'x' ) {
3018 // Find current zoom in table
3019 int idx = total_zooms; float old_zoom = get_zoom();
3020 while( --idx >= 0 && !EQUIV(my_zoom_table[idx], old_zoom) );
3022 idx += get_buttonpress() == 5 ||
3023 gui->ctrl_down() || gui->shift_down() ? -1 : +1 ;
3024 CLAMP(idx, 0, total_zooms-1);
3025 zoom = my_zoom_table[idx];
3028 x = get_cursor_x(); y = get_cursor_y();
3030 mwindow->edl->session->cwindow_scrollbars = 0;
3031 gui->zoom_panel->update(0);
3032 zoom = gui->get_auto_zoom();
3035 gui->zoom_panel->ZoomPanel::update(zoom);
3036 float output_x = x, output_y = y;
3037 canvas_to_output(mwindow->edl, 0, output_x, output_y);
3038 x = output_x - x / zoom;
3039 y = output_y - y / zoom;
3043 mwindow->edl->session->cwindow_scrollbars = 1;
3044 x = (mwindow->edl->session->output_w - w) / 2;
3045 y = (mwindow->edl->session->output_h - h) / 2;
3048 update_zoom((int)x, (int)y, zoom);
3050 gui->composite_panel->cpanel_zoom->update(zoom);
3052 reposition_window(mwindow->edl,
3053 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
3054 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
3055 redraw = 1; result = 1;
3061 void CWindowCanvas::calculate_origin()
3063 gui->x_origin = get_cursor_x();
3064 gui->y_origin = get_cursor_y();
3065 //printf("CWindowCanvas::calculate_origin 1 %f %f\n", gui->x_origin, gui->y_origin);
3066 canvas_to_output(mwindow->edl, 0, gui->x_origin, gui->y_origin);
3067 //printf("CWindowCanvas::calculate_origin 2 %f %f\n", gui->x_origin, gui->y_origin);
3071 int CWindowCanvas::cursor_leave_event()
3073 set_cursor(ARROW_CURSOR);
3077 int CWindowCanvas::cursor_enter_event()
3080 switch(mwindow->edl->session->cwindow_operation)
3082 case CWINDOW_CAMERA:
3083 case CWINDOW_PROJECTOR:
3084 set_cursor(MOVE_CURSOR);
3087 set_cursor(MOVE_CURSOR);
3090 test_crop(0, redraw);
3092 case CWINDOW_PROTECT:
3093 set_cursor(ARROW_CURSOR);
3097 set_cursor(CROSS_CURSOR);
3099 case CWINDOW_EYEDROP:
3100 set_cursor(CROSS_CURSOR);
3106 int CWindowCanvas::cursor_motion_event()
3108 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3111 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3112 switch(gui->current_operation)
3114 case CWINDOW_SCROLL:
3116 float zoom = get_zoom();
3117 float cursor_x = get_cursor_x();
3118 float cursor_y = get_cursor_y();
3120 float zoom_x, zoom_y, conformed_w, conformed_h;
3121 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3122 cursor_x = (float)cursor_x / zoom_x + gui->x_offset;
3123 cursor_y = (float)cursor_y / zoom_y + gui->y_offset;
3127 int x = (int)(gui->x_origin - cursor_x + gui->x_offset);
3128 int y = (int)(gui->y_origin - cursor_y + gui->y_offset);
3133 update_scrollbars(0);
3140 result = do_ruler(0, 1, 0, 0);
3143 case CWINDOW_CAMERA:
3144 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3147 case CWINDOW_PROJECTOR:
3148 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3153 result = test_crop(0, redraw);
3154 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3161 case CWINDOW_MASK_CONTROL_IN:
3162 case CWINDOW_MASK_CONTROL_OUT:
3163 case CWINDOW_MASK_TRANSLATE:
3165 result = do_mask(redraw,
3172 case CWINDOW_EYEDROP:
3173 result = do_eyedrop(rerender, 0, 0);
3182 // cursor font changes
3185 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3187 // mwindow->edl->session->cwindow_operation);
3188 switch(mwindow->edl->session->cwindow_operation)
3191 result = test_crop(0, redraw);
3194 result = do_ruler(0, 1, 0, 0);
3197 result = do_mask(redraw,
3207 // If the window is never unlocked before calling send_command the
3208 // display shouldn't get stuck on the old video frame although it will
3209 // flicker between the old video frame and the new video frame.
3219 gui->unlock_window();
3222 mwindow->gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3223 mwindow->gui->draw_overlays(1);
3224 mwindow->gui->unlock_window();
3226 gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3231 gui->unlock_window();
3232 mwindow->restart_brender();
3233 mwindow->sync_parameters(CHANGE_PARAMS);
3234 mwindow->cwindow->refresh_frame(CHANGE_NONE);
3235 if(!redraw) gui->update_tool();
3236 gui->lock_window("CWindowCanvas::cursor_motion_event 2");
3241 int CWindowCanvas::button_press_event()
3245 int redraw_canvas = 0;
3248 if(Canvas::button_press_event()) return 1;
3250 gui->translating_zoom = gui->shift_down();
3253 //printf("CWindowCanvas::button_press_event 2 %f %f\n", gui->x_origin, gui->y_origin, gui->x_origin, gui->y_origin);
3255 float zoom_x, zoom_y, conformed_w, conformed_h;
3256 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3257 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3258 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3261 if( mwindow->edl->session->cwindow_operation != CWINDOW_PROTECT &&
3262 get_buttonpress() == 2 )
3264 gui->current_operation = CWINDOW_SCROLL;
3270 switch(mwindow->edl->session->cwindow_operation)
3273 result = do_ruler(0, 0, 1, 0);
3276 case CWINDOW_CAMERA:
3277 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3280 case CWINDOW_PROJECTOR:
3281 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3285 result = test_zoom(redraw);
3289 result = test_crop(1, redraw);
3293 if(get_buttonpress() == 1)
3294 result = do_mask(redraw, rerender, 1, 0, 0);
3297 case CWINDOW_EYEDROP:
3298 result = do_eyedrop(rerender, 1, 0);
3306 gui->unlock_window();
3309 mwindow->gui->lock_window("CWindowCanvas::button_press_event 1");
3310 mwindow->gui->draw_overlays(1);
3311 mwindow->gui->unlock_window();
3314 gui->lock_window("CWindowCanvas::button_press_event 1");
3317 // rerendering can also be caused by press event
3320 gui->unlock_window();
3322 mwindow->restart_brender();
3323 mwindow->sync_parameters(CHANGE_PARAMS);
3324 mwindow->cwindow->refresh_frame(CHANGE_NONE);
3325 if(!redraw) gui->update_tool();
3326 gui->lock_window("CWindowCanvas::button_press_event 2");
3331 int CWindowCanvas::button_release_event()
3335 switch(gui->current_operation)
3337 case CWINDOW_SCROLL:
3342 do_ruler(0, 0, 0, 1);
3345 case CWINDOW_CAMERA:
3346 mwindow->undo->update_undo_after(_("camera"), LOAD_AUTOMATION);
3349 case CWINDOW_PROJECTOR:
3350 mwindow->undo->update_undo_after(_("projector"), LOAD_AUTOMATION);
3354 case CWINDOW_MASK_CONTROL_IN:
3355 case CWINDOW_MASK_CONTROL_OUT:
3356 case CWINDOW_MASK_TRANSLATE:
3357 // Finish mask operation
3358 gui->mask_keyframe = 0;
3359 mwindow->undo->update_undo_after(_("mask"), LOAD_AUTOMATION);
3362 result = Canvas::button_release_event();
3366 gui->current_operation = CWINDOW_NONE;
3370 void CWindowCanvas::zoom_resize_window(float percentage)
3372 int canvas_w, canvas_h;
3376 // Get required canvas size
3377 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3378 mwindow->edl->session->output_w,
3379 mwindow->edl->session->output_h,
3384 // Estimate window size from current borders
3385 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3386 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3388 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3389 mwindow->session->cwindow_w = new_w;
3390 mwindow->session->cwindow_h = new_h;
3392 mwindow->theme->get_cwindow_sizes(gui,
3393 mwindow->session->cwindow_controls);
3395 // Estimate again from new borders
3396 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3397 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3398 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3400 gui->resize_window(new_w, new_h);
3401 gui->resize_event(new_w, new_h);
3404 void CWindowCanvas::toggle_controls()
3406 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3407 gui->resize_event(gui->get_w(), gui->get_h());
3410 int CWindowCanvas::get_cwindow_controls()
3412 return mwindow->session->cwindow_controls;