4 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "automation.h"
24 #include "bcsignals.h"
28 #include "cplayback.h"
31 #include "cwindowgui.h"
33 #include "cwindowtool.h"
34 #include "editpanel.h"
36 #include "edlsession.h"
37 #include "floatauto.h"
38 #include "floatautos.h"
41 #include "localsession.h"
42 #include "mainclock.h"
45 #include "mainsession.h"
47 #include "maskautos.h"
49 #include "meterpanel.h"
50 #include "mwindowgui.h"
53 #include "playback3d.h"
54 #include "playtransport.h"
56 #include "trackcanvas.h"
58 #include "transportque.h"
62 static double my_zoom_table[] =
75 static int total_zooms = sizeof(my_zoom_table) / sizeof(double);
78 CWindowGUI::CWindowGUI(MWindow *mwindow, CWindow *cwindow)
79 : BC_Window(_(PROGRAM_NAME ": Compositor"),
80 mwindow->session->cwindow_x,
81 mwindow->session->cwindow_y,
82 mwindow->session->cwindow_w,
83 mwindow->session->cwindow_h,
89 BC_WindowBase::get_resources()->bg_color,
90 mwindow->get_cwindow_display())
92 this->mwindow = mwindow;
93 this->cwindow = cwindow;
95 affected_x = affected_y = affected_z = 0;
97 orig_mask_keyframe = new MaskAuto(0, 0);
99 x_offset = y_offset = 0;
100 x_origin = y_origin = 0;
101 current_operation = CWINDOW_NONE;
105 crop_handle = -1; crop_translate = 0;
106 crop_origin_x = crop_origin_y = 0;
107 crop_origin_x1 = crop_origin_y1 = 0;
108 crop_origin_x2 = crop_origin_y2 = 0;
110 eyedrop_x = eyedrop_y = 0;
111 ruler_origin_x = ruler_origin_y = 0;
112 ruler_handle = -1; ruler_translate = 0;
113 center_x = center_y = center_z = 0;
114 control_in_x = control_in_y = 0;
115 control_out_x = control_out_y = 0;
116 translating_zoom = 0;
120 CWindowGUI::~CWindowGUI()
122 if(tool_panel) delete tool_panel;
124 delete composite_panel;
131 delete orig_mask_keyframe;
134 void CWindowGUI::create_objects()
136 lock_window("CWindowGUI::create_objects");
137 set_icon(mwindow->theme->get_image("cwindow_icon"));
139 active = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_active"));
140 inactive = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_inactive"));
142 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
143 mwindow->theme->draw_cwindow_bg(this);
146 // Meters required by composite panel
147 meters = new CWindowMeters(mwindow,
149 mwindow->theme->cmeter_x,
150 mwindow->theme->cmeter_y,
151 mwindow->theme->cmeter_h);
152 meters->create_objects();
155 composite_panel = new CPanel(mwindow,
157 mwindow->theme->ccomposite_x,
158 mwindow->theme->ccomposite_y,
159 mwindow->theme->ccomposite_w,
160 mwindow->theme->ccomposite_h);
161 composite_panel->create_objects();
163 canvas = new CWindowCanvas(mwindow, this);
165 canvas->create_objects(mwindow->edl);
166 canvas->use_cwindow();
169 add_subwindow(timebar = new CTimeBar(mwindow,
171 mwindow->theme->ctimebar_x,
172 mwindow->theme->ctimebar_y,
173 mwindow->theme->ctimebar_w,
174 mwindow->theme->ctimebar_h));
175 timebar->create_objects();
178 add_subwindow(slider = new CWindowSlider(mwindow,
180 mwindow->theme->cslider_x,
181 mwindow->theme->cslider_y,
182 mwindow->theme->cslider_w));
185 transport = new CWindowTransport(mwindow,
187 mwindow->theme->ctransport_x,
188 mwindow->theme->ctransport_y);
189 transport->create_objects();
191 transport->set_slider(slider);
194 edit_panel = new CWindowEditing(mwindow, cwindow);
195 edit_panel->set_meters(meters);
196 edit_panel->create_objects();
198 // add_subwindow(clock = new MainClock(mwindow,
199 // mwindow->theme->ctime_x,
200 // mwindow->theme->ctime_y));
202 zoom_panel = new CWindowZoom(mwindow,
204 mwindow->theme->czoom_x,
205 mwindow->theme->czoom_y,
206 mwindow->theme->czoom_w);
207 zoom_panel->create_objects();
208 zoom_panel->zoom_text->add_item(new BC_MenuItem(auto_zoom = _(AUTO_ZOOM)));
209 if( !mwindow->edl->session->cwindow_scrollbars )
210 zoom_panel->set_text(auto_zoom);
212 // destination = new CWindowDestination(mwindow,
214 // mwindow->theme->cdest_x,
215 // mwindow->theme->cdest_y);
216 // destination->create_objects();
218 // Must create after meter panel
219 tool_panel = new CWindowTool(mwindow, this);
220 tool_panel->Thread::start();
222 set_operation(mwindow->edl->session->cwindow_operation);
227 int CWindowGUI::translation_event()
229 mwindow->session->cwindow_x = get_x();
230 mwindow->session->cwindow_y = get_y();
234 int CWindowGUI::resize_event(int w, int h)
236 mwindow->session->cwindow_x = get_x();
237 mwindow->session->cwindow_y = get_y();
238 mwindow->session->cwindow_w = w;
239 mwindow->session->cwindow_h = h;
241 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
242 mwindow->theme->draw_cwindow_bg(this);
245 composite_panel->reposition_buttons(mwindow->theme->ccomposite_x,
246 mwindow->theme->ccomposite_y, mwindow->theme->ccomposite_h);
248 canvas->reposition_window(mwindow->edl,
249 mwindow->theme->ccanvas_x,
250 mwindow->theme->ccanvas_y,
251 mwindow->theme->ccanvas_w,
252 mwindow->theme->ccanvas_h);
254 timebar->resize_event();
257 slider->reposition_window(mwindow->theme->cslider_x,
258 mwindow->theme->cslider_y,
259 mwindow->theme->cslider_w);
260 // Recalibrate pointer motion range
261 slider->set_position();
264 transport->reposition_buttons(mwindow->theme->ctransport_x,
265 mwindow->theme->ctransport_y);
267 edit_panel->reposition_buttons(mwindow->theme->cedit_x,
268 mwindow->theme->cedit_y);
270 // clock->reposition_window(mwindow->theme->ctime_x,
271 // mwindow->theme->ctime_y);
273 zoom_panel->reposition_window(mwindow->theme->czoom_x,
274 mwindow->theme->czoom_y);
276 // destination->reposition_window(mwindow->theme->cdest_x,
277 // mwindow->theme->cdest_y);
279 meters->reposition_window(mwindow->theme->cmeter_x,
280 mwindow->theme->cmeter_y,
282 mwindow->theme->cmeter_h);
286 BC_WindowBase::resize_event(w, h);
290 int CWindowGUI::button_press_event()
292 if( current_operation == CWINDOW_NONE &&
293 mwindow->edl != 0 && canvas->get_canvas() &&
294 mwindow->edl->session->cwindow_click2play &&
295 canvas->get_canvas()->get_cursor_over_window() ) {
296 switch( get_buttonpress() ) {
298 if( !cwindow->playback_engine->is_playing_back ) {
299 double length = mwindow->edl->tracks->total_playable_length();
300 double position = cwindow->playback_engine->get_tracking_position();
301 if( position >= length ) transport->goto_start();
303 return transport->forward_play->handle_event();
305 if( !cwindow->playback_engine->is_playing_back ) {
306 double position = cwindow->playback_engine->get_tracking_position();
307 if( position <= 0 ) transport->goto_end();
309 return transport->reverse_play->handle_event();
310 case RIGHT_BUTTON: // activates popup
313 return transport->frame_forward_play->handle_event();
315 return transport->frame_reverse_play->handle_event();
318 if(canvas->get_canvas())
319 return canvas->button_press_event_base(canvas->get_canvas());
323 int CWindowGUI::cursor_leave_event()
325 if(canvas->get_canvas())
326 return canvas->cursor_leave_event_base(canvas->get_canvas());
330 int CWindowGUI::cursor_enter_event()
332 if(canvas->get_canvas())
333 return canvas->cursor_enter_event_base(canvas->get_canvas());
337 int CWindowGUI::button_release_event()
339 if(canvas->get_canvas())
340 return canvas->button_release_event();
344 int CWindowGUI::cursor_motion_event()
346 if(canvas->get_canvas())
348 canvas->get_canvas()->unhide_cursor();
349 return canvas->cursor_motion_event();
360 void CWindowGUI::draw_status(int flush)
362 if( (canvas->get_canvas() && canvas->get_canvas()->get_video_on()) ||
363 canvas->is_processing )
366 mwindow->theme->cstatus_x,
367 mwindow->theme->cstatus_y);
371 draw_pixmap(inactive,
372 mwindow->theme->cstatus_x,
373 mwindow->theme->cstatus_y);
377 // printf("CWindowGUI::draw_status %d %d %d\n", __LINE__, mwindow->theme->cstatus_x,
378 // mwindow->theme->cstatus_y);
379 flash(mwindow->theme->cstatus_x,
380 mwindow->theme->cstatus_y,
386 float CWindowGUI::get_auto_zoom()
388 float conformed_w, conformed_h;
389 mwindow->edl->calculate_conformed_dimensions(0, conformed_w, conformed_h);
390 float zoom_x = canvas->w / conformed_w;
391 float zoom_y = canvas->h / conformed_h;
392 return zoom_x < zoom_y ? zoom_x : zoom_y;
395 void CWindowGUI::zoom_canvas(double value, int update_menu)
398 float zoom = !value ? get_auto_zoom() : value;
399 EDL *edl = mwindow->edl;
400 edl->session->cwindow_scrollbars = !value ? 0 : 1;
402 float cx = 0.5f * canvas->w; x = cx;
403 float cy = 0.5f * canvas->h; y = cy;
404 canvas->canvas_to_output(edl, 0, x, y);
405 canvas->update_zoom(0, 0, zoom);
406 float zoom_x, zoom_y, conformed_w, conformed_h;
407 canvas->get_zooms(edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
412 canvas->update_zoom((int)(x+0.5), (int)(y+0.5), zoom);
415 zoom_panel->update(value);
416 if( mwindow->edl->session->cwindow_operation == CWINDOW_ZOOM )
417 composite_panel->cpanel_zoom->update(zoom);
419 canvas->reposition_window(mwindow->edl,
420 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
421 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
422 canvas->draw_refresh();
425 void CWindowGUI::set_operation(int value)
428 case CWINDOW_TOOL_WINDOW:
429 mwindow->edl->session->tool_window = !mwindow->edl->session->tool_window;
430 composite_panel->operation[CWINDOW_TOOL_WINDOW]->update(mwindow->edl->session->tool_window);
431 tool_panel->update_show_window();
433 case CWINDOW_TITLESAFE:
434 mwindow->edl->session->safe_regions = !mwindow->edl->session->safe_regions;
435 composite_panel->operation[CWINDOW_TITLESAFE]->update(mwindow->edl->session->safe_regions);
436 value = mwindow->edl->session->cwindow_operation;
439 mwindow->edl->session->cwindow_operation = value;
440 composite_panel->set_operation(value);
444 edit_panel->update();
445 tool_panel->start_tool(value);
446 canvas->draw_refresh();
449 void CWindowGUI::update_tool()
451 tool_panel->update_values();
454 int CWindowGUI::close_event()
456 cwindow->hide_window();
461 int CWindowGUI::keypress_event()
464 int cwindow_operation = CWINDOW_NONE;
466 switch(get_keypress())
484 if(mwindow->session->cwindow_fullscreen)
485 canvas->stop_fullscreen();
487 canvas->start_fullscreen();
488 lock_window("CWindowGUI::keypress_event 1");
491 if( ctrl_down() || shift_down() || alt_down() ) break;
493 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
495 mwindow->gui->unlock_window();
496 lock_window("CWindowGUI::keypress_event 2");
500 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
501 mwindow->clear_entry();
502 mwindow->gui->unlock_window();
503 lock_window("CWindowGUI::keypress_event 3");
507 if(mwindow->session->cwindow_fullscreen)
508 canvas->stop_fullscreen();
509 lock_window("CWindowGUI::keypress_event 4");
513 int alt_down = this->alt_down();
514 int shift_down = this->shift_down();
517 mwindow->gui->lock_window("CWindowGUI::keypress_event 5");
519 mwindow->prev_edit_handle(shift_down);
521 mwindow->move_left();
522 mwindow->gui->unlock_window();
523 lock_window("CWindowGUI::keypress_event 6");
529 if( !ctrl_down() && !alt_down() ) {
532 mwindow->gui->lock_window("CWindowGUI::keypress_event 7");
533 mwindow->move_left();
534 mwindow->gui->unlock_window();
535 lock_window("CWindowGUI::keypress_event 8");
542 int alt_down = this->alt_down();
543 int shift_down = this->shift_down();
546 mwindow->gui->lock_window("CWindowGUI::keypress_event 8");
548 mwindow->next_edit_handle(shift_down);
550 mwindow->move_right();
551 mwindow->gui->unlock_window();
552 lock_window("CWindowGUI::keypress_event 9");
558 if( !ctrl_down() && !alt_down() ) {
561 mwindow->gui->lock_window("CWindowGUI::keypress_event 10");
562 mwindow->move_right();
563 mwindow->gui->unlock_window();
564 lock_window("CWindowGUI::keypress_event 11");
569 case KEY_F1: if( shift_down() ) { mwindow->toggle_camera_xyz(); break; }
570 cwindow_operation = CWINDOW_PROTECT; break;
571 case KEY_F2: if( shift_down() ) { mwindow->toggle_projector_xyz(); break; }
572 cwindow_operation = CWINDOW_ZOOM; break;
573 case KEY_F3: cwindow_operation = CWINDOW_MASK; break;
574 case KEY_F4: cwindow_operation = CWINDOW_RULER; break;
575 case KEY_F5: cwindow_operation = CWINDOW_CAMERA; break;
576 case KEY_F6: cwindow_operation = CWINDOW_PROJECTOR; break;
577 case KEY_F7: cwindow_operation = CWINDOW_CROP; break;
578 case KEY_F8: cwindow_operation = CWINDOW_EYEDROP; break;
579 case KEY_F9: cwindow_operation = CWINDOW_TOOL_WINDOW; break;
580 case KEY_F10: cwindow_operation = CWINDOW_TITLESAFE; break;
581 case KEY_F11: canvas->reset_camera(); break;
582 case KEY_F12: canvas->reset_projector(); break;
585 if( cwindow_operation >= 0 ) {
586 set_operation(cwindow_operation);
590 if(!result) result = transport->keypress_event();
596 void CWindowGUI::reset_affected()
603 void CWindowGUI::keyboard_zoomin()
605 // if(mwindow->edl->session->cwindow_scrollbars)
607 zoom_panel->zoom_tumbler->handle_up_event();
614 void CWindowGUI::keyboard_zoomout()
616 // if(mwindow->edl->session->cwindow_scrollbars)
618 zoom_panel->zoom_tumbler->handle_down_event();
626 void CWindowGUI::drag_motion()
628 if(get_hidden()) return;
630 if(mwindow->session->current_operation != DRAG_ASSET &&
631 mwindow->session->current_operation != DRAG_VTRANSITION &&
632 mwindow->session->current_operation != DRAG_VEFFECT) return;
633 int need_highlight = cursor_above() && get_cursor_over_window();
634 if( highlighted == need_highlight ) return;
635 highlighted = need_highlight;
636 canvas->draw_refresh();
639 int CWindowGUI::drag_stop()
642 if(get_hidden()) return 0;
643 if( !highlighted ) return 0;
644 if( mwindow->session->current_operation != DRAG_ASSET &&
645 mwindow->session->current_operation != DRAG_VTRANSITION &&
646 mwindow->session->current_operation != DRAG_VEFFECT) return 0;
648 canvas->draw_refresh();
651 if(mwindow->session->current_operation == DRAG_ASSET)
653 if(mwindow->session->drag_assets->total ||
654 mwindow->session->drag_clips->total)
656 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
657 mwindow->undo->update_undo_before(_("insert assets"), 0);
660 if(mwindow->session->drag_assets->total)
663 mwindow->load_assets(mwindow->session->drag_assets,
664 mwindow->edl->local_session->get_selectionstart(),
666 mwindow->session->track_highlighted,
668 mwindow->edl->session->labels_follow_edits,
669 mwindow->edl->session->plugins_follow_edits,
670 mwindow->edl->session->autos_follow_edits,
674 if(mwindow->session->drag_clips->total)
677 mwindow->paste_edls(mwindow->session->drag_clips,
679 mwindow->session->track_highlighted,
680 mwindow->edl->local_session->get_selectionstart(),
681 mwindow->edl->session->labels_follow_edits,
682 mwindow->edl->session->plugins_follow_edits,
683 mwindow->edl->session->autos_follow_edits,
687 if(mwindow->session->drag_assets->total ||
688 mwindow->session->drag_clips->total)
690 mwindow->save_backup();
691 mwindow->restart_brender();
692 mwindow->gui->update(1, 1, 1, 1, 0, 1, 0);
693 mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
694 mwindow->gui->unlock_window();
695 mwindow->sync_parameters(CHANGE_ALL);
699 if(mwindow->session->current_operation == DRAG_VEFFECT)
701 //printf("CWindowGUI::drag_stop 1\n");
702 Track *affected_track = cwindow->calculate_affected_track();
703 //printf("CWindowGUI::drag_stop 2\n");
705 mwindow->gui->lock_window("CWindowGUI::drag_stop 3");
706 mwindow->insert_effects_cwindow(affected_track);
707 mwindow->session->current_operation = NO_OPERATION;
708 mwindow->gui->unlock_window();
711 if(mwindow->session->current_operation == DRAG_VTRANSITION)
713 Track *affected_track = cwindow->calculate_affected_track();
714 mwindow->gui->lock_window("CWindowGUI::drag_stop 4");
715 mwindow->paste_transition_cwindow(affected_track);
716 mwindow->session->current_operation = NO_OPERATION;
717 mwindow->gui->unlock_window();
723 void CWindowGUI::update_meters()
725 if(mwindow->edl->session->cwindow_meter != meters->visible)
727 meters->set_meters(meters->meter_count, mwindow->edl->session->cwindow_meter);
728 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
729 resize_event(get_w(), get_h());
733 void CWindowGUI::stop_transport(const char *lock_msg)
735 if( lock_msg ) unlock_window();
736 mwindow->stop_transport();
737 if( lock_msg ) lock_window(lock_msg);
741 CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
742 : EditPanel(mwindow, cwindow->gui, CWINDOW_ID,
743 mwindow->theme->cedit_x, mwindow->theme->cedit_y,
744 mwindow->edl->session->editing_mode,
745 0, // use_editing_mode
764 this->mwindow = mwindow;
765 this->cwindow = cwindow;
768 #define CWrapper(fn) void CWindowEditing::fn() { \
769 mwindow->gui->lock_window("CWrapper::" #fn); \
771 mwindow->gui->unlock_window(); \
774 CWrapper(copy_selection)
775 CWrapper(splice_selection)
776 CWrapper(overwrite_selection)
777 CWrapper(set_inpoint)
778 CWrapper(set_outpoint)
779 CWrapper(unset_inoutpoint)
780 CWrapper(toggle_label)
782 #define CWrapper_cut(fn) void CWindowEditing::fn(int cut) { \
783 mwindow->gui->lock_window("CWrapper::" #fn); \
784 EditPanel::fn(cut); \
785 mwindow->gui->unlock_window(); \
787 CWrapper_cut(prev_label)
788 CWrapper_cut(next_label)
789 CWrapper_cut(prev_edit)
790 CWrapper_cut(next_edit)
792 void CWindowEditing::to_clip()
794 mwindow->to_clip(mwindow->edl, _("composer window: "), 0);
798 CWindowMeters::CWindowMeters(MWindow *mwindow,
803 : MeterPanel(mwindow,
809 mwindow->edl->session->audio_channels,
810 mwindow->edl->session->cwindow_meter,
814 this->mwindow = mwindow;
818 CWindowMeters::~CWindowMeters()
822 int CWindowMeters::change_status_event(int new_status)
824 mwindow->edl->session->cwindow_meter = new_status;
825 gui->update_meters();
832 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
833 : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
834 x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
836 this->mwindow = mwindow;
840 CWindowZoom::~CWindowZoom()
844 void CWindowZoom::update(double value)
846 char string[BCSTRLEN];
847 const char *cp = string;
850 int frac = value >= 1.0f ? 1 :
852 value >= .01f ? 3 : 4;
853 sprintf(string, "x %.*f", frac, value);
857 ZoomPanel::update(cp);
860 int CWindowZoom::handle_event()
862 double value = !strcasecmp(gui->auto_zoom, get_text()) ? 0 : get_value();
863 gui->zoom_canvas(value, 0);
870 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
871 : BC_PercentageSlider(x,
880 this->mwindow = mwindow;
881 this->cwindow = cwindow;
882 set_precision(0.00001);
885 CWindowSlider::~CWindowSlider()
889 int CWindowSlider::handle_event()
891 cwindow->update_position((double)get_value());
895 void CWindowSlider::set_position()
897 double new_length = mwindow->edl->tracks->total_length();
898 update(mwindow->theme->cslider_w,
899 mwindow->edl->local_session->get_selectionstart(1),
904 int CWindowSlider::increase_value()
907 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
908 lock_window("CWindowSlider::increase_value");
912 int CWindowSlider::decrease_value()
915 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
916 lock_window("CWindowSlider::decrease_value");
921 // CWindowDestination::CWindowDestination(MWindow *mwindow, CWindowGUI *cwindow, int x, int y)
922 // : BC_PopupTextBox(cwindow,
923 // &cwindow->destinations,
924 // cwindow->destinations.values[cwindow->cwindow->destination]->get_text(),
930 // this->mwindow = mwindow;
931 // this->cwindow = cwindow;
934 // CWindowDestination::~CWindowDestination()
938 // int CWindowDestination::handle_event()
949 CWindowTransport::CWindowTransport(MWindow *mwindow,
953 : PlayTransport(mwindow,
961 EDL* CWindowTransport::get_edl()
966 void CWindowTransport::goto_start()
968 gui->unlock_window();
969 handle_transport(REWIND, 1);
971 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
972 mwindow->goto_start();
973 mwindow->gui->unlock_window();
975 gui->lock_window("CWindowTransport::goto_start 2");
978 void CWindowTransport::goto_end()
980 gui->unlock_window();
981 handle_transport(GOTO_END, 1);
983 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
985 mwindow->gui->unlock_window();
987 gui->lock_window("CWindowTransport::goto_end 2");
992 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
995 mwindow->theme->ccanvas_x,
996 mwindow->theme->ccanvas_y,
997 mwindow->theme->ccanvas_w,
998 mwindow->theme->ccanvas_h,
1001 mwindow->edl->session->cwindow_scrollbars)
1003 this->mwindow = mwindow;
1007 void CWindowCanvas::status_event()
1009 gui->draw_status(1);
1012 int CWindowCanvas::get_fullscreen()
1014 return mwindow->session->cwindow_fullscreen;
1017 void CWindowCanvas::set_fullscreen(int value)
1019 mwindow->session->cwindow_fullscreen = value;
1023 void CWindowCanvas::update_zoom(int x, int y, float zoom)
1025 use_scrollbars = mwindow->edl->session->cwindow_scrollbars;
1027 mwindow->edl->session->cwindow_xscroll = x;
1028 mwindow->edl->session->cwindow_yscroll = y;
1029 mwindow->edl->session->cwindow_zoom = zoom;
1032 void CWindowCanvas::zoom_auto()
1034 gui->zoom_canvas(0, 1);
1037 int CWindowCanvas::get_xscroll()
1039 return mwindow->edl->session->cwindow_xscroll;
1042 int CWindowCanvas::get_yscroll()
1044 return mwindow->edl->session->cwindow_yscroll;
1048 float CWindowCanvas::get_zoom()
1050 return mwindow->edl->session->cwindow_zoom;
1053 void CWindowCanvas::draw_refresh(int flush)
1055 if(get_canvas() && !get_canvas()->get_video_on())
1058 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
1060 float in_x1, in_y1, in_x2, in_y2;
1061 float out_x1, out_y1, out_x2, out_y2;
1062 get_transfers(mwindow->edl,
1072 if(!EQUIV(out_x1, 0) ||
1073 !EQUIV(out_y1, 0) ||
1074 !EQUIV(out_x2, get_canvas()->get_w()) ||
1075 !EQUIV(out_y2, get_canvas()->get_h()))
1077 get_canvas()->clear_box(0,
1079 get_canvas()->get_w(),
1080 get_canvas()->get_h());
1083 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1084 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1087 if(out_x2 > out_x1 &&
1092 // input scaled from session to refresh frame coordinates
1093 int ow = get_output_w(mwindow->edl);
1094 int oh = get_output_h(mwindow->edl);
1095 int rw = refresh_frame->get_w();
1096 int rh = refresh_frame->get_h();
1097 float xs = (float)rw / ow;
1098 float ys = (float)rh / oh;
1099 in_x1 *= xs; in_x2 *= xs;
1100 in_y1 *= ys; in_y2 *= ys;
1101 // Can't use OpenGL here because it is called asynchronously of the
1102 // playback operation.
1103 get_canvas()->draw_vframe(refresh_frame,
1106 (int)(out_x2 - out_x1),
1107 (int)(out_y2 - out_y1),
1110 (int)(in_x2 - in_x1),
1111 (int)(in_y2 - in_y1),
1117 get_canvas()->clear_box(0,
1119 get_canvas()->get_w(),
1120 get_canvas()->get_h());
1124 // allow last opengl write to complete before redraw
1125 // tried sync_display, glFlush, glxMake*Current(0..)
1127 get_canvas()->flash(flush);
1129 //printf("CWindowCanvas::draw_refresh 10\n");
1132 #define CROPHANDLE_W 10
1133 #define CROPHANDLE_H 10
1135 void CWindowCanvas::draw_crophandle(int x, int y)
1137 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1145 #define CONTROL_W 10
1146 #define CONTROL_H 10
1147 #define FIRST_CONTROL_W 20
1148 #define FIRST_CONTROL_H 20
1150 #define BC_INFINITY 65536
1152 #define RULERHANDLE_W 16
1153 #define RULERHANDLE_H 16
1157 int CWindowCanvas::do_ruler(int draw,
1163 float x1 = mwindow->edl->session->ruler_x1;
1164 float y1 = mwindow->edl->session->ruler_y1;
1165 float x2 = mwindow->edl->session->ruler_x2;
1166 float y2 = mwindow->edl->session->ruler_y2;
1167 float canvas_x1 = x1;
1168 float canvas_y1 = y1;
1169 float canvas_x2 = x2;
1170 float canvas_y2 = y2;
1171 float output_x = get_cursor_x();
1172 float output_y = get_cursor_y();
1173 float canvas_cursor_x = output_x;
1174 float canvas_cursor_y = output_y;
1176 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1177 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1178 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1179 mwindow->session->cwindow_output_x = roundf(output_x);
1180 mwindow->session->cwindow_output_y = roundf(output_y);
1182 if(button_press && get_buttonpress() == 1)
1184 gui->ruler_handle = -1;
1185 gui->ruler_translate = 0;
1188 gui->ruler_translate = 1;
1189 gui->ruler_origin_x = x1;
1190 gui->ruler_origin_y = y1;
1193 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1194 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1195 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1196 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1198 gui->ruler_handle = 0;
1199 gui->ruler_origin_x = x1;
1200 gui->ruler_origin_y = y1;
1203 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1204 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1205 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1206 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1208 gui->ruler_handle = 1;
1209 gui->ruler_origin_x = x2;
1210 gui->ruler_origin_y = y2;
1214 // Start new selection
1215 if(!gui->ruler_translate &&
1216 (gui->ruler_handle < 0 ||
1221 do_ruler(1, 0, 0, 0);
1222 get_canvas()->flash();
1223 gui->ruler_handle = 1;
1224 mwindow->edl->session->ruler_x1 = output_x;
1225 mwindow->edl->session->ruler_y1 = output_y;
1226 mwindow->edl->session->ruler_x2 = output_x;
1227 mwindow->edl->session->ruler_y2 = output_y;
1228 gui->ruler_origin_x = mwindow->edl->session->ruler_x2;
1229 gui->ruler_origin_y = mwindow->edl->session->ruler_y2;
1232 gui->x_origin = output_x;
1233 gui->y_origin = output_y;
1234 gui->current_operation = CWINDOW_RULER;
1235 gui->tool_panel->raise_window();
1241 if(gui->current_operation == CWINDOW_RULER)
1243 if(gui->ruler_translate)
1246 do_ruler(1, 0, 0, 0);
1247 float x_difference = mwindow->edl->session->ruler_x1;
1248 float y_difference = mwindow->edl->session->ruler_y1;
1249 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1250 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1251 x_difference -= mwindow->edl->session->ruler_x1;
1252 y_difference -= mwindow->edl->session->ruler_y1;
1253 mwindow->edl->session->ruler_x2 -= x_difference;
1254 mwindow->edl->session->ruler_y2 -= y_difference;
1256 do_ruler(1, 0, 0, 0);
1257 get_canvas()->flash();
1261 switch(gui->ruler_handle)
1264 do_ruler(1, 0, 0, 0);
1265 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1266 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1267 if(gui->alt_down() || gui->ctrl_down())
1269 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1270 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1274 double distance_value =
1275 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1276 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1277 if(angle_value < 22)
1278 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2;
1280 if(angle_value > 67)
1281 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2;
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;
1290 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 && 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;
1296 if(mwindow->edl->session->ruler_x1 > mwindow->edl->session->ruler_x2 &&
1297 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1299 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1300 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1304 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1305 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1308 do_ruler(1, 0, 0, 0);
1309 get_canvas()->flash();
1314 do_ruler(1, 0, 0, 0);
1315 mwindow->edl->session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1316 mwindow->edl->session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1317 if(gui->alt_down() || gui->ctrl_down())
1319 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1320 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1324 double distance_value =
1325 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1326 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1327 if(angle_value < 22)
1328 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1;
1330 if(angle_value > 67)
1331 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1;
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 &&
1341 mwindow->edl->session->ruler_y2 > mwindow->edl->session->ruler_y1)
1343 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1344 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1347 if(mwindow->edl->session->ruler_x2 > mwindow->edl->session->ruler_x1 && mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1349 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1350 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1354 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1355 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1358 do_ruler(1, 0, 0, 0);
1359 get_canvas()->flash();
1363 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1367 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1372 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1373 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1374 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1375 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1377 set_cursor(UPRIGHT_ARROW_CURSOR);
1380 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1381 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1382 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1383 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1385 set_cursor(UPRIGHT_ARROW_CURSOR);
1388 set_cursor(CROSS_CURSOR);
1390 // Update current position
1395 // Assume no ruler measurement if 0 length
1396 if(draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)))
1398 get_canvas()->set_inverse();
1399 get_canvas()->set_color(WHITE);
1400 get_canvas()->draw_line((int)canvas_x1,
1404 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1406 roundf(canvas_x1) + RULERHANDLE_W / 2,
1408 get_canvas()->draw_line(roundf(canvas_x1),
1409 roundf(canvas_y1) - RULERHANDLE_H / 2,
1411 roundf(canvas_y1) + RULERHANDLE_H / 2);
1412 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1414 roundf(canvas_x2) + RULERHANDLE_W / 2,
1416 get_canvas()->draw_line(roundf(canvas_x2),
1417 roundf(canvas_y2) - RULERHANDLE_H / 2,
1419 roundf(canvas_y2) + RULERHANDLE_H / 2);
1420 get_canvas()->set_opaque();
1427 static inline double line_dist(float cx,float cy, float tx,float ty)
1429 double dx = tx-cx, dy = ty-cy;
1430 return sqrt(dx*dx + dy*dy);
1433 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1435 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1436 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1440 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1441 int button_press, int cursor_motion, int draw)
1443 // Retrieve points from top recordable track
1444 //printf("CWindowCanvas::do_mask 1\n");
1445 Track *track = gui->cwindow->calculate_affected_track();
1446 //printf("CWindowCanvas::do_mask 2\n");
1448 if(!track) return 0;
1449 //printf("CWindowCanvas::do_mask 3\n");
1451 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1452 int64_t position = track->to_units(
1453 mwindow->edl->local_session->get_selectionstart(1),
1455 ArrayList<MaskPoint*> points;
1457 // Determine the points based on whether
1458 // new keyframes will be generated or drawing is performed.
1459 // If keyframe generation occurs, use the interpolated mask.
1460 // If no keyframe generation occurs, use the previous mask.
1461 int use_interpolated = 0;
1462 if(button_press || cursor_motion) {
1463 #ifdef USE_KEYFRAME_SPANNING
1464 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1465 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1468 mask_autos->get_prev_auto(track->to_units(selection_start, 0),
1469 PLAY_FORWARD, first, 1);
1471 mask_autos->get_prev_auto(track->to_units(selection_end, 0),
1472 PLAY_FORWARD, last, 1);
1474 if(last == first && (!mwindow->edl->session->auto_keyframes))
1475 use_interpolated = 0;
1477 // If keyframe spanning occurs, use the interpolated points.
1478 // If new keyframe is generated, use the interpolated points.
1479 use_interpolated = 1;
1482 if(mwindow->edl->session->auto_keyframes)
1483 use_interpolated = 1;
1487 use_interpolated = 1;
1489 if(use_interpolated) {
1490 // Interpolate the points to get exactly what is being rendered at this position.
1491 mask_autos->get_points(&points,
1492 mwindow->edl->session->cwindow_mask,
1497 // Use the prev mask
1499 mask_autos->get_prev_auto(position,
1503 ((MaskAuto*)prev)->get_points(&points,
1504 mwindow->edl->session->cwindow_mask);
1507 // Projector zooms relative to the center of the track output.
1508 float half_track_w = (float)track->track_w / 2;
1509 float half_track_h = (float)track->track_h / 2;
1510 // Translate mask to projection
1511 float projector_x, projector_y, projector_z;
1512 track->automation->get_projector(
1513 &projector_x, &projector_y, &projector_z,
1514 position, PLAY_FORWARD);
1517 // Get position of cursor relative to mask
1518 float cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
1519 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1520 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1522 projector_x += mwindow->edl->session->output_w / 2;
1523 projector_y += mwindow->edl->session->output_h / 2;
1524 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1525 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1527 // Fix cursor origin
1529 gui->x_origin = mask_cursor_x;
1530 gui->y_origin = mask_cursor_y;
1534 // Points of closest line
1535 int shortest_point1 = -1;
1536 int shortest_point2 = -1;
1538 int shortest_point = -1;
1539 // Distance to closest line
1540 float shortest_line_distance = BC_INFINITY;
1541 // Distance to closest point
1542 float shortest_point_distance = BC_INFINITY;
1543 int selected_point = -1;
1544 int selected_control_point = -1;
1545 float selected_control_point_distance = BC_INFINITY;
1546 ArrayList<int> x_points;
1547 ArrayList<int> y_points;
1549 if(!cursor_motion) {
1551 get_canvas()->set_color(WHITE);
1552 get_canvas()->set_inverse();
1554 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1556 // Never draw closed polygon and a closed
1557 // polygon is harder to add points to.
1558 for(int i = 0; i < points.size() && !result; i++) {
1559 MaskPoint *point1 = points.get(i);
1560 MaskPoint *point2 = (i >= points.size() - 1) ?
1561 points.get(0) : points.get(i + 1);
1563 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1564 if(point_distance1 < shortest_point_distance || shortest_point < 0) {
1565 shortest_point_distance = point_distance1;
1569 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1570 if(point_distance2 < shortest_point_distance || shortest_point < 0) {
1571 shortest_point_distance = point_distance2;
1572 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1576 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1578 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1579 //point1->x, point1->y, point2->x, point2->y, projector_z);
1580 for(int j = 0; j <= segments && !result; j++) {
1581 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1582 float x0 = point1->x, y0 = point1->y;
1583 float x1 = point1->x + point1->control_x2;
1584 float y1 = point1->y + point1->control_y2;
1585 float x2 = point2->x + point2->control_x1;
1586 float y2 = point2->y + point2->control_y1;
1587 float x3 = point2->x, y3 = point2->y;
1588 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1589 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1590 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1591 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1592 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1593 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1594 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1595 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1597 float t = (float)j / segments;
1598 float tpow2 = t * t;
1599 float tpow3 = t * t * t;
1601 float invtpow2 = invt * invt;
1602 float invtpow3 = invt * invt * invt;
1604 float x = ( invtpow3 * x0
1605 + 3 * t * invtpow2 * x1
1606 + 3 * tpow2 * invt * x2
1608 float y = ( invtpow3 * y0
1609 + 3 * t * invtpow2 * y1
1610 + 3 * tpow2 * invt * y2
1612 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1613 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1614 // Test new point addition
1616 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1618 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1619 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1620 if(line_distance < shortest_line_distance ||
1621 shortest_point1 < 0) {
1622 shortest_line_distance = line_distance;
1623 shortest_point1 = i;
1624 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1625 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1626 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1629 // Test existing point selection
1631 if(gui->ctrl_down()) {
1632 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1634 if(distance < selected_control_point_distance) {
1636 selected_control_point = 1;
1637 selected_control_point_distance = distance;
1641 if(!gui->shift_down()) {
1642 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1643 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
1648 selected_point = shortest_point;
1651 // Test second point
1652 if(gui->ctrl_down()) {
1653 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1655 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1656 if(distance < selected_control_point_distance) {
1657 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1658 selected_control_point = 0;
1659 selected_control_point_distance = distance;
1662 else if(i < points.size() - 1) {
1663 if(!gui->shift_down()) {
1664 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1665 if(test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3)) {
1666 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1670 selected_point = shortest_point;
1675 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1679 if(draw) { // Draw joining line
1680 x_points.append((int)canvas_x);
1681 y_points.append((int)canvas_y);
1685 if(draw) { // Draw second anchor
1686 if(i < points.size() - 1) {
1687 if(i == gui->affected_point - 1)
1688 get_canvas()->draw_disc(
1689 (int)canvas_x - CONTROL_W / 2,
1690 (int)canvas_y - CONTROL_W / 2,
1691 CONTROL_W, CONTROL_H);
1693 get_canvas()->draw_circle(
1694 (int)canvas_x - CONTROL_W / 2,
1695 (int)canvas_y - CONTROL_W / 2,
1696 CONTROL_W, CONTROL_H);
1697 // char string[BCTEXTLEN];
1698 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1699 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1701 // Draw second control point.
1702 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1703 get_canvas()->draw_line(
1704 (int)canvas_x, (int)canvas_y,
1705 (int)canvas_x2, (int)canvas_y2);
1706 get_canvas()->draw_rectangle(
1707 (int)canvas_x2 - CONTROL_W / 2,
1708 (int)canvas_y2 - CONTROL_H / 2,
1709 CONTROL_W, CONTROL_H);
1714 // Draw first anchor
1715 if(i == 0 && draw) {
1716 char mask_label[BCSTRLEN];
1717 sprintf(mask_label, "%d",
1718 mwindow->edl->session->cwindow_mask);
1719 get_canvas()->draw_text(
1720 (int)canvas_x - FIRST_CONTROL_W,
1721 (int)canvas_y - FIRST_CONTROL_H,
1724 get_canvas()->draw_disc(
1725 (int)canvas_x - FIRST_CONTROL_W / 2,
1726 (int)canvas_y - FIRST_CONTROL_H / 2,
1727 FIRST_CONTROL_W, FIRST_CONTROL_H);
1730 // Draw first control point.
1732 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1733 get_canvas()->draw_line(
1734 (int)canvas_x, (int)canvas_y,
1735 (int)canvas_x1, (int)canvas_y1);
1736 get_canvas()->draw_rectangle(
1737 (int)canvas_x1 - CONTROL_W / 2,
1738 (int)canvas_y1 - CONTROL_H / 2,
1739 CONTROL_W, CONTROL_H);
1741 x_points.append((int)canvas_x);
1742 y_points.append((int)canvas_y);
1745 //printf("CWindowCanvas::do_mask 1\n");
1749 //printf("CWindowCanvas::do_mask 1\n");
1752 get_canvas()->draw_polygon(&x_points, &y_points);
1753 get_canvas()->set_opaque();
1755 //printf("CWindowCanvas::do_mask 1\n");
1758 if(button_press && !result) {
1759 gui->affected_track = gui->cwindow->calculate_affected_track();
1761 // Get keyframe outside the EDL to edit. This must be rendered
1762 // instead of the EDL keyframes when it exists. Then it must be
1763 // applied to the EDL keyframes on buttonrelease.
1764 if(gui->affected_track) {
1765 #ifdef USE_KEYFRAME_SPANNING
1766 // Make copy of current parameters in local keyframe
1767 gui->mask_keyframe =
1768 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1771 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1774 gui->mask_keyframe =
1775 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1780 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1783 // Translate entire keyframe
1784 if(gui->alt_down() && mask->points.size()) {
1785 mwindow->undo->update_undo_before(_("mask translate"), 0);
1786 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1787 gui->affected_point = 0;
1790 // Existing point or control point was selected
1791 if(selected_point >= 0) {
1792 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1793 gui->affected_point = selected_point;
1795 if(selected_control_point == 0)
1796 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1798 if(selected_control_point == 1)
1799 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1801 gui->current_operation = mwindow->edl->session->cwindow_operation;
1803 else // No existing point or control point was selected so create a new one
1804 if(!gui->ctrl_down() && !gui->alt_down()) {
1805 mwindow->undo->update_undo_before(_("mask point"), 0);
1806 // Create the template
1807 MaskPoint *point = new MaskPoint;
1808 point->x = mask_cursor_x;
1809 point->y = mask_cursor_y;
1810 point->control_x1 = 0;
1811 point->control_y1 = 0;
1812 point->control_x2 = 0;
1813 point->control_y2 = 0;
1816 if(shortest_point2 < shortest_point1) {
1817 shortest_point2 ^= shortest_point1;
1818 shortest_point1 ^= shortest_point2;
1819 shortest_point2 ^= shortest_point1;
1824 // printf("CWindowGUI::do_mask 40\n");
1825 // mwindow->edl->dump();
1826 // printf("CWindowGUI::do_mask 50\n");
1830 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1831 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1832 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1834 // Append to end of list
1835 if( shortest_point1 == shortest_point2 ||
1836 labs(shortest_point1 - shortest_point2) > 1) {
1837 #ifdef USE_KEYFRAME_SPANNING
1839 MaskPoint *new_point = new MaskPoint;
1840 points.append(new_point);
1841 *new_point = *point;
1842 gui->affected_point = points.size() - 1;
1846 // Need to apply the new point to every keyframe
1847 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1848 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1849 MaskPoint *new_point = new MaskPoint;
1850 submask->points.append(new_point);
1851 *new_point = *point;
1852 if(current == (MaskAuto*)mask_autos->default_auto)
1853 current = (MaskAuto*)mask_autos->first;
1855 current = (MaskAuto*)NEXT;
1857 gui->affected_point = mask->points.size() - 1;
1863 // Insert between 2 points, shifting back point 2
1864 if(shortest_point1 >= 0 && shortest_point2 >= 0) {
1866 #ifdef USE_KEYFRAME_SPANNING
1867 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1869 if(points.size() >= shortest_point2) {
1870 MaskPoint *new_point = new MaskPoint;
1872 for(int i = points.size() - 1;
1873 i > shortest_point2;
1875 points.values[i] = points.values[i - 1];
1876 points.values[shortest_point2] = new_point;
1878 *new_point = *point;
1883 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1884 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1885 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1887 if(submask->points.size() >= shortest_point2) {
1888 MaskPoint *new_point = new MaskPoint;
1889 submask->points.append(0);
1890 for(int i = submask->points.size() - 1;
1891 i > shortest_point2;
1893 submask->points.values[i] = submask->points.values[i - 1];
1894 submask->points.values[shortest_point2] = new_point;
1896 *new_point = *point;
1899 if(current == (MaskAuto*)mask_autos->default_auto)
1900 current = (MaskAuto*)mask_autos->first;
1902 current = (MaskAuto*)NEXT;
1906 gui->affected_point = shortest_point2;
1911 // printf("CWindowGUI::do_mask 20\n");
1912 // mwindow->edl->dump();
1913 // printf("CWindowGUI::do_mask 30\n");
1916 //printf("CWindowCanvas::do_mask 1\n");
1917 // Create the first point.
1918 #ifdef USE_KEYFRAME_SPANNING
1919 MaskPoint *new_point = new MaskPoint;
1920 points.append(new_point);
1921 *new_point = *point;
1922 gui->affected_point = points.size() - 1;
1924 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1925 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1926 MaskPoint *new_point = new MaskPoint;
1927 submask->points.append(new_point);
1928 *new_point = *point;
1929 if(current == (MaskAuto*)mask_autos->default_auto)
1930 current = (MaskAuto*)mask_autos->first;
1932 current = (MaskAuto*)NEXT;
1934 gui->affected_point = points.size() - 1;
1937 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
1940 gui->current_operation = mwindow->edl->session->cwindow_operation;
1941 // Delete the template
1950 if(button_press && result) {
1951 #ifdef USE_KEYFRAME_SPANNING
1952 MaskPoint *point = points.values[gui->affected_point];
1953 gui->center_x = point->x;
1954 gui->center_y = point->y;
1955 gui->control_in_x = point->control_x1;
1956 gui->control_in_y = point->control_y1;
1957 gui->control_out_x = point->control_x2;
1958 gui->control_out_y = point->control_y2;
1959 gui->tool_panel->raise_window();
1961 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1962 MaskPoint *point = mask->points.values[gui->affected_point];
1963 gui->center_x = point->x;
1964 gui->center_y = point->y;
1965 gui->control_in_x = point->control_x1;
1966 gui->control_in_y = point->control_y1;
1967 gui->control_out_x = point->control_x2;
1968 gui->control_out_y = point->control_y2;
1969 gui->tool_panel->raise_window();
1973 //printf("CWindowCanvas::do_mask 8\n");
1976 #ifdef USE_KEYFRAME_SPANNING
1977 // Must update the reference keyframes for every cursor motion
1978 gui->mask_keyframe =
1979 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1982 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1985 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1987 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1988 if( gui->affected_point >= 0 && gui->affected_point < mask->points.size() &&
1989 gui->current_operation != CWINDOW_NONE) {
1990 // mwindow->undo->update_undo_before(_("mask point"), this);
1991 #ifdef USE_KEYFRAME_SPANNING
1992 MaskPoint *point = points.get(gui->affected_point);
1994 MaskPoint *point = mask->points.get(gui->affected_point);
1996 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
1997 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask->points.size(), gui->affected_point);
1999 float last_x = point->x;
2000 float last_y = point->y;
2001 float last_control_x1 = point->control_x1;
2002 float last_control_y1 = point->control_y1;
2003 float last_control_x2 = point->control_x2;
2004 float last_control_y2 = point->control_y2;
2006 switch(gui->current_operation) {
2008 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2009 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
2010 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
2013 case CWINDOW_MASK_CONTROL_IN:
2014 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
2015 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
2018 case CWINDOW_MASK_CONTROL_OUT:
2019 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
2020 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
2023 case CWINDOW_MASK_TRANSLATE:
2024 #ifdef USE_KEYFRAME_SPANNING
2025 for(int i = 0; i < points.size(); i++) {
2026 points.values[i]->x += mask_cursor_x - gui->x_origin;
2027 points.values[i]->y += mask_cursor_y - gui->y_origin;
2030 for(int i = 0; i < mask->points.size(); i++) {
2031 mask->points.values[i]->x += mask_cursor_x - gui->x_origin;
2032 mask->points.values[i]->y += mask_cursor_y - gui->y_origin;
2035 gui->x_origin = mask_cursor_x;
2036 gui->y_origin = mask_cursor_y;
2040 if( !EQUIV(last_x, point->x) ||
2041 !EQUIV(last_y, point->y) ||
2042 !EQUIV(last_control_x1, point->control_x1) ||
2043 !EQUIV(last_control_y1, point->control_y1) ||
2044 !EQUIV(last_control_x2, point->control_x2) ||
2045 !EQUIV(last_control_y2, point->control_y2)) {
2051 if(gui->current_operation == CWINDOW_NONE) {
2052 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
2054 for(int i = 0; i < points.size() && !over_point; i++) {
2055 MaskPoint *point = points.get(i);
2056 float x0 = point->x;
2057 float y0 = point->y;
2058 float x1 = point->x + point->control_x1;
2059 float y1 = point->y + point->control_y1;
2060 float x2 = point->x + point->control_x2;
2061 float y2 = point->y + point->control_y2;
2062 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
2063 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
2065 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
2066 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
2070 if(!over_point && gui->ctrl_down()) {
2071 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
2072 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
2073 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2074 if(test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1)) {
2078 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2079 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2080 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2081 if(test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2)) {
2088 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2093 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2096 #ifdef USE_KEYFRAME_SPANNING
2097 // Must commit change after operation.
2098 if(rerender && track) {
2099 // Swap EDL keyframe with original.
2100 // Apply new values to keyframe span
2101 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2102 temp_keyframe.copy_data(gui->mask_keyframe);
2103 // Apply interpolated points back to keyframe
2104 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2105 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2106 mask_autos->update_parameter(&temp_keyframe);
2110 points.remove_all_objects();
2111 //printf("CWindowCanvas::do_mask 20\n");
2115 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2118 int radius = mwindow->edl->session->eyedrop_radius;
2126 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2131 row1 = gui->eyedrop_y - radius;
2132 row2 = gui->eyedrop_y + radius;
2133 column1 = gui->eyedrop_x - radius;
2134 column2 = gui->eyedrop_x + radius;
2136 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2137 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2138 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2139 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2141 if(row2 <= row1) row2 = row1 + 1;
2142 if(column2 <= column1) column2 = column1 + 1;
2149 output_to_canvas(mwindow->edl, 0, x1, y1);
2150 output_to_canvas(mwindow->edl, 0, x2, y2);
2151 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2153 if(x2 - x1 >= 1 && y2 - y1 >= 1)
2155 get_canvas()->set_inverse();
2156 get_canvas()->set_color(WHITE);
2158 get_canvas()->draw_rectangle((int)x1,
2163 get_canvas()->set_opaque();
2164 get_canvas()->flash();
2172 gui->current_operation = CWINDOW_EYEDROP;
2173 gui->tool_panel->raise_window();
2176 if(gui->current_operation == CWINDOW_EYEDROP)
2178 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2180 // Get color out of frame.
2181 // Doesn't work during playback because that bypasses the refresh frame.
2182 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2184 float cursor_x = get_cursor_x();
2185 float cursor_y = get_cursor_y();
2186 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2187 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2188 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2190 row1 = cursor_y - radius;
2191 row2 = cursor_y + radius;
2192 column1 = cursor_x - radius;
2193 column2 = cursor_x + radius;
2194 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2195 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2196 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2197 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2198 if(row2 <= row1) row2 = row1 + 1;
2199 if(column2 <= column1) column2 = column1 + 1;
2203 if(gui->eyedrop_visible)
2206 do_eyedrop(temp, 0, 1);
2207 gui->eyedrop_visible = 0;
2210 gui->eyedrop_x = cursor_x;
2211 gui->eyedrop_y = cursor_y;
2216 do_eyedrop(temp, 0, 1);
2217 gui->eyedrop_visible = 1;
2220 // Decompression coefficients straight out of jpeglib
2221 #define V_TO_R 1.40200
2222 #define V_TO_G -0.71414
2224 #define U_TO_G -0.34414
2225 #define U_TO_B 1.77200
2227 #define GET_COLOR(type, components, max, do_yuv) \
2229 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2231 float red = (float)*row++ / max; \
2232 float green = (float)*row++ / max; \
2233 float blue = (float)*row++ / max; \
2236 float r = red + V_TO_R * (blue - 0.5); \
2237 float g = red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
2238 float b = red + U_TO_B * (green - 0.5); \
2239 mwindow->edl->local_session->red += r; \
2240 mwindow->edl->local_session->green += g; \
2241 mwindow->edl->local_session->blue += b; \
2242 if(r > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = r; \
2243 if(g > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = g; \
2244 if(b > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = b; \
2248 mwindow->edl->local_session->red += red; \
2249 mwindow->edl->local_session->green += green; \
2250 mwindow->edl->local_session->blue += blue; \
2251 if(red > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = red; \
2252 if(green > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = green; \
2253 if(blue > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = blue; \
2259 mwindow->edl->local_session->red = 0;
2260 mwindow->edl->local_session->green = 0;
2261 mwindow->edl->local_session->blue = 0;
2262 mwindow->edl->local_session->red_max = 0;
2263 mwindow->edl->local_session->green_max = 0;
2264 mwindow->edl->local_session->blue_max = 0;
2265 for(int i = row1; i < row2; i++)
2267 for(int j = column1; j < column2; j++)
2269 switch(refresh_frame->get_color_model())
2272 GET_COLOR(unsigned char, 3, 0xff, 1);
2275 GET_COLOR(unsigned char, 4, 0xff, 1);
2278 GET_COLOR(uint16_t, 3, 0xffff, 1);
2280 case BC_YUVA16161616:
2281 GET_COLOR(uint16_t, 4, 0xffff, 1);
2284 GET_COLOR(unsigned char, 3, 0xff, 0);
2287 GET_COLOR(unsigned char, 4, 0xff, 0);
2290 GET_COLOR(float, 3, 1.0, 0);
2293 GET_COLOR(float, 4, 1.0, 0);
2299 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2300 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2301 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2306 mwindow->edl->local_session->red = 0;
2307 mwindow->edl->local_session->green = 0;
2308 mwindow->edl->local_session->blue = 0;
2309 gui->eyedrop_visible = 0;
2318 // Can't rerender since the color value is from the output of any effect it
2321 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2327 int CWindowCanvas::need_overlays()
2329 if( mwindow->edl->session->safe_regions ) return 1;
2330 if( mwindow->edl->session->cwindow_scrollbars ) return 1;
2331 if( gui->highlighted ) return 1;
2332 switch( mwindow->edl->session->cwindow_operation ) {
2333 case CWINDOW_EYEDROP:
2334 if( ! gui->eyedrop_visible ) break;
2335 case CWINDOW_CAMERA:
2336 case CWINDOW_PROJECTOR:
2345 void CWindowCanvas::draw_overlays()
2347 if(mwindow->edl->session->safe_regions)
2349 draw_safe_regions();
2352 if(mwindow->edl->session->cwindow_scrollbars)
2354 // Always draw output rectangle
2355 float x1, y1, x2, y2;
2357 x2 = mwindow->edl->session->output_w;
2359 y2 = mwindow->edl->session->output_h;
2360 output_to_canvas(mwindow->edl, 0, x1, y1);
2361 output_to_canvas(mwindow->edl, 0, x2, y2);
2363 get_canvas()->set_inverse();
2364 get_canvas()->set_color(WHITE);
2366 get_canvas()->draw_rectangle((int)x1,
2371 get_canvas()->set_opaque();
2374 if(gui->highlighted)
2376 get_canvas()->set_color(WHITE);
2377 get_canvas()->set_inverse();
2378 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2379 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2380 get_canvas()->set_opaque();
2383 int temp1 = 0, temp2 = 0;
2384 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2385 switch(mwindow->edl->session->cwindow_operation)
2387 case CWINDOW_CAMERA:
2391 case CWINDOW_PROJECTOR:
2400 do_mask(temp1, temp2, 0, 0, 1);
2404 do_ruler(1, 0, 0, 0);
2407 case CWINDOW_EYEDROP:
2408 if(gui->eyedrop_visible)
2411 do_eyedrop(rerender, 0, 1);
2412 gui->eyedrop_visible = 1;
2418 void CWindowCanvas::draw_safe_regions()
2420 float action_x1, action_x2, action_y1, action_y2;
2421 float title_x1, title_x2, title_y1, title_y2;
2423 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2424 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2425 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2426 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2427 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2428 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2429 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2430 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2432 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2433 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2434 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2435 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2437 get_canvas()->set_inverse();
2438 get_canvas()->set_color(WHITE);
2440 get_canvas()->draw_rectangle((int)action_x1,
2442 (int)(action_x2 - action_x1),
2443 (int)(action_y2 - action_y1));
2444 get_canvas()->draw_rectangle((int)title_x1,
2446 (int)(title_x2 - title_x1),
2447 (int)(title_y2 - title_y1));
2449 get_canvas()->set_opaque();
2452 void CWindowCanvas::reset_keyframe(int do_camera)
2454 FloatAuto *x_keyframe = 0;
2455 FloatAuto *y_keyframe = 0;
2456 FloatAuto *z_keyframe = 0;
2457 Track *affected_track = 0;
2459 affected_track = gui->cwindow->calculate_affected_track();
2463 gui->cwindow->calculate_affected_autos(&x_keyframe,
2472 x_keyframe->set_value(0);
2473 y_keyframe->set_value(0);
2474 z_keyframe->set_value(1);
2476 mwindow->sync_parameters(CHANGE_PARAMS);
2481 void CWindowCanvas::reset_camera()
2486 void CWindowCanvas::reset_projector()
2491 int CWindowCanvas::test_crop(int button_press, int &redraw)
2494 int handle_selected = -1;
2495 float x1 = mwindow->edl->session->crop_x1;
2496 float y1 = mwindow->edl->session->crop_y1;
2497 float x2 = mwindow->edl->session->crop_x2;
2498 float y2 = mwindow->edl->session->crop_y2;
2499 float cursor_x = get_cursor_x();
2500 float cursor_y = get_cursor_y();
2501 float canvas_x1 = x1;
2502 float canvas_y1 = y1;
2503 float canvas_x2 = x2;
2504 float canvas_y2 = y2;
2505 float canvas_cursor_x = cursor_x;
2506 float canvas_cursor_y = cursor_y;
2508 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2509 // Use screen normalized coordinates for hot spot tests.
2510 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2511 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2514 if(gui->current_operation == CWINDOW_CROP)
2516 handle_selected = gui->crop_handle;
2519 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2520 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2522 handle_selected = 0;
2523 gui->crop_origin_x = x1;
2524 gui->crop_origin_y = y1;
2527 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2528 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2530 handle_selected = 1;
2531 gui->crop_origin_x = x2;
2532 gui->crop_origin_y = y1;
2535 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2536 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2538 handle_selected = 2;
2539 gui->crop_origin_x = x1;
2540 gui->crop_origin_y = y2;
2543 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2544 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2546 handle_selected = 3;
2547 gui->crop_origin_x = x2;
2548 gui->crop_origin_y = y2;
2553 gui->crop_origin_x = cursor_x;
2554 gui->crop_origin_y = cursor_y;
2557 // printf("test crop %d %d\n",
2558 // gui->current_operation,
2559 // handle_selected);
2566 gui->crop_translate = 1;
2567 gui->crop_origin_x1 = x1;
2568 gui->crop_origin_y1 = y1;
2569 gui->crop_origin_x2 = x2;
2570 gui->crop_origin_y2 = y2;
2573 gui->crop_translate = 0;
2575 gui->current_operation = CWINDOW_CROP;
2576 gui->crop_handle = handle_selected;
2577 gui->x_origin = cursor_x;
2578 gui->y_origin = cursor_y;
2579 gui->tool_panel->raise_window();
2582 if(handle_selected < 0 && !gui->crop_translate)
2586 mwindow->edl->session->crop_x1 = (int)x1;
2587 mwindow->edl->session->crop_y1 = (int)y1;
2588 mwindow->edl->session->crop_x2 = (int)x2;
2589 mwindow->edl->session->crop_y2 = (int)y2;
2594 // Translate all 4 points
2595 if(gui->current_operation == CWINDOW_CROP && gui->crop_translate)
2597 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2598 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2599 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2600 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2602 mwindow->edl->session->crop_x1 = (int)x1;
2603 mwindow->edl->session->crop_y1 = (int)y1;
2604 mwindow->edl->session->crop_x2 = (int)x2;
2605 mwindow->edl->session->crop_y2 = (int)y2;
2611 if(gui->current_operation == CWINDOW_CROP)
2613 switch(gui->crop_handle)
2616 x1 = gui->crop_origin_x;
2617 y1 = gui->crop_origin_y;
2618 x2 = gui->crop_origin_x;
2619 y2 = gui->crop_origin_y;
2620 if(cursor_x < gui->x_origin)
2622 if(cursor_y < gui->y_origin)
2628 if(cursor_y >= gui->y_origin)
2635 if(cursor_x >= gui->x_origin)
2637 if(cursor_y < gui->y_origin)
2643 if(cursor_y >= gui->y_origin)
2650 // printf("test crop %d %d %d %d\n",
2651 // mwindow->edl->session->crop_x1,
2652 // mwindow->edl->session->crop_y1,
2653 // mwindow->edl->session->crop_x2,
2654 // mwindow->edl->session->crop_y2);
2657 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2658 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2661 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2662 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2665 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2666 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2669 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2670 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2674 if(!EQUIV(mwindow->edl->session->crop_x1, x1) ||
2675 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2676 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2677 !EQUIV(mwindow->edl->session->crop_y2, y2))
2684 switch (gui->crop_handle)
2686 case 0: gui->crop_handle = 1; break;
2687 case 1: gui->crop_handle = 0; break;
2688 case 2: gui->crop_handle = 3; break;
2689 case 3: gui->crop_handle = 2; break;
2699 switch (gui->crop_handle)
2701 case 0: gui->crop_handle = 2; break;
2702 case 1: gui->crop_handle = 3; break;
2703 case 2: gui->crop_handle = 0; break;
2704 case 3: gui->crop_handle = 1; break;
2709 mwindow->edl->session->crop_x1 = (int)x1;
2710 mwindow->edl->session->crop_y1 = (int)y1;
2711 mwindow->edl->session->crop_x2 = (int)x2;
2712 mwindow->edl->session->crop_y2 = (int)y2;
2718 // Update cursor font
2719 if(handle_selected >= 0)
2721 switch(handle_selected)
2724 set_cursor(UPLEFT_RESIZE);
2727 set_cursor(UPRIGHT_RESIZE);
2730 set_cursor(DOWNLEFT_RESIZE);
2733 set_cursor(DOWNRIGHT_RESIZE);
2740 set_cursor(ARROW_CURSOR);
2742 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2746 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2747 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2748 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2749 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2750 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2751 // mwindow->edl->session->crop_x2,
2752 // mwindow->edl->session->crop_y2,
2753 // mwindow->edl->calculate_output_w(0),
2754 // mwindow->edl->calculate_output_h(0));
2760 void CWindowCanvas::draw_crop()
2762 get_canvas()->set_inverse();
2763 get_canvas()->set_color(WHITE);
2765 float x1 = mwindow->edl->session->crop_x1;
2766 float y1 = mwindow->edl->session->crop_y1;
2767 float x2 = mwindow->edl->session->crop_x2;
2768 float y2 = mwindow->edl->session->crop_y2;
2770 output_to_canvas(mwindow->edl, 0, x1, y1);
2771 output_to_canvas(mwindow->edl, 0, x2, y2);
2773 if(x2 - x1 && y2 - y1)
2774 get_canvas()->draw_rectangle((int)x1,
2779 draw_crophandle((int)x1, (int)y1);
2780 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2781 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2782 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2783 get_canvas()->set_opaque();
2793 void CWindowCanvas::draw_bezier(int do_camera)
2795 Track *track = gui->cwindow->calculate_affected_track();
2802 int64_t position = track->to_units(
2803 mwindow->edl->local_session->get_selectionstart(1),
2806 track->automation->get_projector(¢er_x,
2812 // center_x += track->track_w / 2;
2813 // center_y += track->track_h / 2;
2814 center_x += mwindow->edl->session->output_w / 2;
2815 center_y += mwindow->edl->session->output_h / 2;
2816 float track_x1 = center_x - track->track_w / 2 * center_z;
2817 float track_y1 = center_y - track->track_h / 2 * center_z;
2818 float track_x2 = track_x1 + track->track_w * center_z;
2819 float track_y2 = track_y1 + track->track_h * center_z;
2821 output_to_canvas(mwindow->edl, 0, track_x1, track_y1);
2822 output_to_canvas(mwindow->edl, 0, track_x2, track_y2);
2824 #define DRAW_PROJECTION(offset) \
2825 get_canvas()->draw_rectangle((int)track_x1 + offset, \
2826 (int)track_y1 + offset, \
2827 (int)(track_x2 - track_x1), \
2828 (int)(track_y2 - track_y1)); \
2829 get_canvas()->draw_line((int)track_x1 + offset, \
2830 (int)track_y1 + offset, \
2831 (int)track_x2 + offset, \
2832 (int)track_y2 + offset); \
2833 get_canvas()->draw_line((int)track_x2 + offset, \
2834 (int)track_y1 + offset, \
2835 (int)track_x1 + offset, \
2836 (int)track_y2 + offset); \
2840 get_canvas()->set_color(BLACK);
2843 // canvas->set_inverse();
2845 get_canvas()->set_color(GREEN);
2847 get_canvas()->set_color(RED);
2850 // canvas->set_opaque();
2854 int CWindowCanvas::test_bezier(int button_press,
2862 // Processing drag operation.
2863 // Create keyframe during first cursor motion.
2867 float cursor_x = get_cursor_x();
2868 float cursor_y = get_cursor_y();
2869 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2871 if(gui->current_operation == CWINDOW_CAMERA ||
2872 gui->current_operation == CWINDOW_PROJECTOR)
2874 if(!gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom)
2876 gui->translating_zoom = 1;
2877 gui->reset_affected();
2880 if(!gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom)
2882 gui->translating_zoom = 0;
2883 gui->reset_affected();
2886 // Get target keyframe
2887 float last_center_x;
2888 float last_center_y;
2889 float last_center_z;
2892 if(!gui->affected_x && !gui->affected_y && !gui->affected_z)
2894 FloatAutos *affected_x_autos;
2895 FloatAutos *affected_y_autos;
2896 FloatAutos *affected_z_autos;
2897 if(!gui->affected_track) return 0;
2898 double position = mwindow->edl->local_session->get_selectionstart(1);
2899 int64_t track_position = gui->affected_track->to_units(position, 0);
2901 if(mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA)
2903 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_X];
2904 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Y];
2905 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Z];
2909 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_X];
2910 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Y];
2911 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Z];
2915 if(gui->translating_zoom)
2917 FloatAuto *previous = 0;
2918 FloatAuto *next = 0;
2919 float new_z = affected_z_autos->get_value(
2925 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2926 affected_z_autos, 1, &created, 0);
2928 gui->affected_z->set_value(new_z);
2934 FloatAuto *previous = 0;
2935 FloatAuto *next = 0;
2936 float new_x = affected_x_autos->get_value(
2943 float new_y = affected_y_autos->get_value(
2949 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2950 affected_x_autos, 1, &created, 0);
2952 gui->affected_x->set_value(new_x);
2956 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2957 affected_y_autos, 1, &created, 0);
2959 gui->affected_y->set_value(new_y);
2966 if(gui->translating_zoom)
2968 gui->center_z = gui->affected_z->get_value();
2972 gui->center_x = gui->affected_x->get_value();
2973 gui->center_y = gui->affected_y->get_value();
2980 if(gui->translating_zoom)
2982 last_center_z = gui->affected_z->get_value();
2983 float z = gui->center_z + (cursor_y - gui->y_origin) / 128;
2985 if(!EQUIV(last_center_z, z))
2991 gui->affected_z->set_value(z);
2995 last_center_x = gui->affected_x->get_value();
2996 last_center_y = gui->affected_y->get_value();
2997 float dx = cursor_x - gui->x_origin;
2998 float dy = cursor_y - gui->y_origin;
2999 if(gui->current_operation == CWINDOW_CAMERA ) {
3002 float x = gui->center_x + dx;
3003 float y = gui->center_y + dy;
3004 gui->affected_x->set_value(x);
3005 gui->affected_y->set_value(y);
3006 if( !EQUIV(last_center_x, x) || !EQUIV(last_center_y, y) )
3012 gui->affected_x->set_value(x);
3013 gui->affected_y->set_value(y);
3020 // Begin drag operation. Don't create keyframe here.
3022 // Get affected track off of the first recordable video track.
3023 // Calculating based on the alpha channel would require recording what layer
3024 // each output pixel belongs to as they're rendered and stacked. Forget it.
3025 gui->affected_track = gui->cwindow->calculate_affected_track();
3026 gui->reset_affected();
3028 if(gui->affected_track)
3030 if(gui->current_operation == CWINDOW_CAMERA)
3031 mwindow->undo->update_undo_before(_("camera"), this);
3033 mwindow->undo->update_undo_before(_("projector"), this);
3035 gui->current_operation =
3036 mwindow->edl->session->cwindow_operation;
3037 gui->tool_panel->raise_window();
3046 int CWindowCanvas::test_zoom(int &redraw)
3052 if( mwindow->edl->session->cwindow_scrollbars ) {
3053 if( *gui->zoom_panel->get_text() != 'x' ) {
3054 // Find current zoom in table
3055 int idx = total_zooms; float old_zoom = get_zoom();
3056 while( --idx >= 0 && !EQUIV(my_zoom_table[idx], old_zoom) );
3058 idx += get_buttonpress() == 5 ||
3059 gui->ctrl_down() || gui->shift_down() ? -1 : +1 ;
3060 CLAMP(idx, 0, total_zooms-1);
3061 zoom = my_zoom_table[idx];
3064 x = get_cursor_x(); y = get_cursor_y();
3066 mwindow->edl->session->cwindow_scrollbars = 0;
3067 gui->zoom_panel->update(0);
3068 zoom = gui->get_auto_zoom();
3071 gui->zoom_panel->ZoomPanel::update(zoom);
3072 float output_x = x, output_y = y;
3073 canvas_to_output(mwindow->edl, 0, output_x, output_y);
3074 x = output_x - x / zoom;
3075 y = output_y - y / zoom;
3079 mwindow->edl->session->cwindow_scrollbars = 1;
3080 x = (mwindow->edl->session->output_w - w) / 2;
3081 y = (mwindow->edl->session->output_h - h) / 2;
3084 update_zoom((int)x, (int)y, zoom);
3086 gui->composite_panel->cpanel_zoom->update(zoom);
3088 reposition_window(mwindow->edl,
3089 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
3090 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
3091 redraw = 1; result = 1;
3097 void CWindowCanvas::calculate_origin()
3099 gui->x_origin = get_cursor_x();
3100 gui->y_origin = get_cursor_y();
3101 //printf("CWindowCanvas::calculate_origin 1 %f %f\n", gui->x_origin, gui->y_origin);
3102 canvas_to_output(mwindow->edl, 0, gui->x_origin, gui->y_origin);
3103 //printf("CWindowCanvas::calculate_origin 2 %f %f\n", gui->x_origin, gui->y_origin);
3107 int CWindowCanvas::cursor_leave_event()
3109 set_cursor(ARROW_CURSOR);
3113 int CWindowCanvas::cursor_enter_event()
3116 switch(mwindow->edl->session->cwindow_operation)
3118 case CWINDOW_CAMERA:
3119 case CWINDOW_PROJECTOR:
3120 set_cursor(MOVE_CURSOR);
3123 set_cursor(MOVE_CURSOR);
3126 test_crop(0, redraw);
3128 case CWINDOW_PROTECT:
3129 set_cursor(ARROW_CURSOR);
3133 set_cursor(CROSS_CURSOR);
3135 case CWINDOW_EYEDROP:
3136 set_cursor(CROSS_CURSOR);
3142 int CWindowCanvas::cursor_motion_event()
3144 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3147 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3148 switch(gui->current_operation)
3150 case CWINDOW_SCROLL:
3152 float zoom = get_zoom();
3153 float cursor_x = get_cursor_x();
3154 float cursor_y = get_cursor_y();
3156 float zoom_x, zoom_y, conformed_w, conformed_h;
3157 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3158 cursor_x = (float)cursor_x / zoom_x + gui->x_offset;
3159 cursor_y = (float)cursor_y / zoom_y + gui->y_offset;
3163 int x = (int)(gui->x_origin - cursor_x + gui->x_offset);
3164 int y = (int)(gui->y_origin - cursor_y + gui->y_offset);
3169 update_scrollbars(0);
3176 result = do_ruler(0, 1, 0, 0);
3179 case CWINDOW_CAMERA:
3180 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3183 case CWINDOW_PROJECTOR:
3184 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3189 result = test_crop(0, redraw);
3190 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3197 case CWINDOW_MASK_CONTROL_IN:
3198 case CWINDOW_MASK_CONTROL_OUT:
3199 case CWINDOW_MASK_TRANSLATE:
3201 result = do_mask(redraw,
3208 case CWINDOW_EYEDROP:
3209 result = do_eyedrop(rerender, 0, 0);
3218 // cursor font changes
3221 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3223 // mwindow->edl->session->cwindow_operation);
3224 switch(mwindow->edl->session->cwindow_operation)
3227 result = test_crop(0, redraw);
3230 result = do_ruler(0, 1, 0, 0);
3233 result = do_mask(redraw,
3243 // If the window is never unlocked before calling send_command the
3244 // display shouldn't get stuck on the old video frame although it will
3245 // flicker between the old video frame and the new video frame.
3255 gui->unlock_window();
3258 mwindow->gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3259 mwindow->gui->draw_overlays(1);
3260 mwindow->gui->unlock_window();
3262 gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3267 gui->unlock_window();
3268 mwindow->restart_brender();
3269 mwindow->sync_parameters(CHANGE_PARAMS);
3270 mwindow->cwindow->refresh_frame(CHANGE_NONE);
3271 if(!redraw) gui->update_tool();
3272 gui->lock_window("CWindowCanvas::cursor_motion_event 2");
3277 int CWindowCanvas::button_press_event()
3281 int redraw_canvas = 0;
3284 if(Canvas::button_press_event()) return 1;
3286 gui->translating_zoom = gui->shift_down();
3289 //printf("CWindowCanvas::button_press_event 2 %f %f\n", gui->x_origin, gui->y_origin, gui->x_origin, gui->y_origin);
3291 float zoom_x, zoom_y, conformed_w, conformed_h;
3292 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3293 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3294 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3297 if( mwindow->edl->session->cwindow_operation != CWINDOW_PROTECT &&
3298 get_buttonpress() == 2 )
3300 gui->current_operation = CWINDOW_SCROLL;
3306 switch(mwindow->edl->session->cwindow_operation)
3309 result = do_ruler(0, 0, 1, 0);
3312 case CWINDOW_CAMERA:
3313 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3316 case CWINDOW_PROJECTOR:
3317 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3321 result = test_zoom(redraw);
3325 result = test_crop(1, redraw);
3329 if(get_buttonpress() == 1)
3330 result = do_mask(redraw, rerender, 1, 0, 0);
3333 case CWINDOW_EYEDROP:
3334 result = do_eyedrop(rerender, 1, 0);
3342 gui->unlock_window();
3345 mwindow->gui->lock_window("CWindowCanvas::button_press_event 1");
3346 mwindow->gui->draw_overlays(1);
3347 mwindow->gui->unlock_window();
3350 gui->lock_window("CWindowCanvas::button_press_event 1");
3353 // rerendering can also be caused by press event
3356 gui->unlock_window();
3358 mwindow->restart_brender();
3359 mwindow->sync_parameters(CHANGE_PARAMS);
3360 mwindow->cwindow->refresh_frame(CHANGE_NONE);
3361 if(!redraw) gui->update_tool();
3362 gui->lock_window("CWindowCanvas::button_press_event 2");
3367 int CWindowCanvas::button_release_event()
3371 switch(gui->current_operation)
3373 case CWINDOW_SCROLL:
3378 do_ruler(0, 0, 0, 1);
3381 case CWINDOW_CAMERA:
3382 mwindow->undo->update_undo_after(_("camera"), LOAD_AUTOMATION);
3385 case CWINDOW_PROJECTOR:
3386 mwindow->undo->update_undo_after(_("projector"), LOAD_AUTOMATION);
3390 case CWINDOW_MASK_CONTROL_IN:
3391 case CWINDOW_MASK_CONTROL_OUT:
3392 case CWINDOW_MASK_TRANSLATE:
3393 // Finish mask operation
3394 gui->mask_keyframe = 0;
3395 mwindow->undo->update_undo_after(_("mask"), LOAD_AUTOMATION);
3398 result = Canvas::button_release_event();
3402 gui->current_operation = CWINDOW_NONE;
3406 void CWindowCanvas::zoom_resize_window(float percentage)
3408 int canvas_w, canvas_h;
3412 // Get required canvas size
3413 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3414 mwindow->edl->session->output_w,
3415 mwindow->edl->session->output_h,
3420 // Estimate window size from current borders
3421 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3422 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3424 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3425 mwindow->session->cwindow_w = new_w;
3426 mwindow->session->cwindow_h = new_h;
3428 mwindow->theme->get_cwindow_sizes(gui,
3429 mwindow->session->cwindow_controls);
3431 // Estimate again from new borders
3432 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3433 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3434 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3436 gui->resize_window(new_w, new_h);
3437 gui->resize_event(new_w, new_h);
3440 void CWindowCanvas::toggle_controls()
3442 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3443 gui->resize_event(gui->get_w(), gui->get_h());
3446 int CWindowCanvas::get_cwindow_controls()
3448 return mwindow->session->cwindow_controls;