4 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "automation.h"
24 #include "bcsignals.h"
28 #include "cplayback.h"
31 #include "cwindowgui.h"
33 #include "cwindowtool.h"
34 #include "editpanel.h"
36 #include "edlsession.h"
37 #include "floatauto.h"
38 #include "floatautos.h"
41 #include "localsession.h"
42 #include "mainclock.h"
45 #include "mainsession.h"
47 #include "maskautos.h"
49 #include "meterpanel.h"
50 #include "mwindowgui.h"
53 #include "playback3d.h"
54 #include "playtransport.h"
56 #include "trackcanvas.h"
58 #include "transportque.h"
62 static double my_zoom_table[] =
75 static int total_zooms = sizeof(my_zoom_table) / sizeof(double);
78 CWindowGUI::CWindowGUI(MWindow *mwindow, CWindow *cwindow)
79 : BC_Window(_(PROGRAM_NAME ": Compositor"),
80 mwindow->session->cwindow_x,
81 mwindow->session->cwindow_y,
82 mwindow->session->cwindow_w,
83 mwindow->session->cwindow_h,
89 BC_WindowBase::get_resources()->bg_color,
90 mwindow->get_cwindow_display())
92 this->mwindow = mwindow;
93 this->cwindow = cwindow;
95 affected_x = affected_y = affected_z = 0;
97 orig_mask_keyframe = new MaskAuto(0, 0);
99 x_offset = y_offset = 0;
100 x_origin = y_origin = 0;
101 current_operation = CWINDOW_NONE;
105 crop_handle = -1; crop_translate = 0;
106 crop_origin_x = crop_origin_y = 0;
107 crop_origin_x1 = crop_origin_y1 = 0;
108 crop_origin_x2 = crop_origin_y2 = 0;
110 eyedrop_x = eyedrop_y = 0;
111 ruler_origin_x = ruler_origin_y = 0;
112 ruler_handle = -1; ruler_translate = 0;
113 center_x = center_y = center_z = 0;
114 control_in_x = control_in_y = 0;
115 control_out_x = control_out_y = 0;
116 translating_zoom = 0;
120 CWindowGUI::~CWindowGUI()
122 if(tool_panel) delete tool_panel;
124 delete composite_panel;
131 delete orig_mask_keyframe;
134 void CWindowGUI::create_objects()
136 lock_window("CWindowGUI::create_objects");
137 set_icon(mwindow->theme->get_image("cwindow_icon"));
139 active = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_active"));
140 inactive = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_inactive"));
142 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
143 mwindow->theme->draw_cwindow_bg(this);
146 // Meters required by composite panel
147 meters = new CWindowMeters(mwindow,
149 mwindow->theme->cmeter_x,
150 mwindow->theme->cmeter_y,
151 mwindow->theme->cmeter_h);
152 meters->create_objects();
155 composite_panel = new CPanel(mwindow,
157 mwindow->theme->ccomposite_x,
158 mwindow->theme->ccomposite_y,
159 mwindow->theme->ccomposite_w,
160 mwindow->theme->ccomposite_h);
161 composite_panel->create_objects();
163 canvas = new CWindowCanvas(mwindow, this);
165 canvas->create_objects(mwindow->edl);
166 canvas->use_cwindow();
169 add_subwindow(timebar = new CTimeBar(mwindow,
171 mwindow->theme->ctimebar_x,
172 mwindow->theme->ctimebar_y,
173 mwindow->theme->ctimebar_w,
174 mwindow->theme->ctimebar_h));
175 timebar->create_objects();
178 add_subwindow(slider = new CWindowSlider(mwindow,
180 mwindow->theme->cslider_x,
181 mwindow->theme->cslider_y,
182 mwindow->theme->cslider_w));
185 transport = new CWindowTransport(mwindow,
187 mwindow->theme->ctransport_x,
188 mwindow->theme->ctransport_y);
189 transport->create_objects();
191 transport->set_slider(slider);
194 edit_panel = new CWindowEditing(mwindow, cwindow);
195 edit_panel->set_meters(meters);
196 edit_panel->create_objects();
198 // add_subwindow(clock = new MainClock(mwindow,
199 // mwindow->theme->ctime_x,
200 // mwindow->theme->ctime_y));
202 zoom_panel = new CWindowZoom(mwindow,
204 mwindow->theme->czoom_x,
205 mwindow->theme->czoom_y,
206 mwindow->theme->czoom_w);
207 zoom_panel->create_objects();
208 zoom_panel->zoom_text->add_item(new BC_MenuItem(auto_zoom = _(AUTO_ZOOM)));
209 if( !mwindow->edl->session->cwindow_scrollbars )
210 zoom_panel->set_text(auto_zoom);
212 // destination = new CWindowDestination(mwindow,
214 // mwindow->theme->cdest_x,
215 // mwindow->theme->cdest_y);
216 // destination->create_objects();
218 // Must create after meter panel
219 tool_panel = new CWindowTool(mwindow, this);
220 tool_panel->Thread::start();
222 set_operation(mwindow->edl->session->cwindow_operation);
227 int CWindowGUI::translation_event()
229 mwindow->session->cwindow_x = get_x();
230 mwindow->session->cwindow_y = get_y();
234 int CWindowGUI::resize_event(int w, int h)
236 mwindow->session->cwindow_x = get_x();
237 mwindow->session->cwindow_y = get_y();
238 mwindow->session->cwindow_w = w;
239 mwindow->session->cwindow_h = h;
241 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
242 mwindow->theme->draw_cwindow_bg(this);
245 composite_panel->reposition_buttons(mwindow->theme->ccomposite_x,
246 mwindow->theme->ccomposite_y, mwindow->theme->ccomposite_h);
248 canvas->reposition_window(mwindow->edl,
249 mwindow->theme->ccanvas_x,
250 mwindow->theme->ccanvas_y,
251 mwindow->theme->ccanvas_w,
252 mwindow->theme->ccanvas_h);
254 timebar->resize_event();
257 slider->reposition_window(mwindow->theme->cslider_x,
258 mwindow->theme->cslider_y,
259 mwindow->theme->cslider_w);
260 // Recalibrate pointer motion range
261 slider->set_position();
264 transport->reposition_buttons(mwindow->theme->ctransport_x,
265 mwindow->theme->ctransport_y);
267 edit_panel->reposition_buttons(mwindow->theme->cedit_x,
268 mwindow->theme->cedit_y);
270 // clock->reposition_window(mwindow->theme->ctime_x,
271 // mwindow->theme->ctime_y);
273 zoom_panel->reposition_window(mwindow->theme->czoom_x,
274 mwindow->theme->czoom_y);
276 // destination->reposition_window(mwindow->theme->cdest_x,
277 // mwindow->theme->cdest_y);
279 meters->reposition_window(mwindow->theme->cmeter_x,
280 mwindow->theme->cmeter_y,
282 mwindow->theme->cmeter_h);
286 BC_WindowBase::resize_event(w, h);
290 int CWindowGUI::button_press_event()
292 if( current_operation == CWINDOW_NONE &&
293 mwindow->edl != 0 && canvas->get_canvas() &&
294 mwindow->edl->session->cwindow_click2play &&
295 canvas->get_canvas()->get_cursor_over_window() ) {
296 switch( get_buttonpress() ) {
298 if( !cwindow->playback_engine->is_playing_back ) {
299 double length = mwindow->edl->tracks->total_playable_length();
300 double position = cwindow->playback_engine->get_tracking_position();
301 if( position >= length ) transport->goto_start();
303 return transport->forward_play->handle_event();
305 if( !cwindow->playback_engine->is_playing_back ) {
306 double position = cwindow->playback_engine->get_tracking_position();
307 if( position <= 0 ) transport->goto_end();
309 return transport->reverse_play->handle_event();
310 case RIGHT_BUTTON: // activates popup
313 return transport->frame_forward_play->handle_event();
315 return transport->frame_reverse_play->handle_event();
318 if(canvas->get_canvas())
319 return canvas->button_press_event_base(canvas->get_canvas());
323 int CWindowGUI::cursor_leave_event()
325 if(canvas->get_canvas())
326 return canvas->cursor_leave_event_base(canvas->get_canvas());
330 int CWindowGUI::cursor_enter_event()
332 if(canvas->get_canvas())
333 return canvas->cursor_enter_event_base(canvas->get_canvas());
337 int CWindowGUI::button_release_event()
339 if(canvas->get_canvas())
340 return canvas->button_release_event();
344 int CWindowGUI::cursor_motion_event()
346 if(canvas->get_canvas())
348 canvas->get_canvas()->unhide_cursor();
349 return canvas->cursor_motion_event();
360 void CWindowGUI::draw_status(int flush)
362 if( (canvas->get_canvas() && canvas->get_canvas()->get_video_on()) ||
363 canvas->is_processing )
366 mwindow->theme->cstatus_x,
367 mwindow->theme->cstatus_y);
371 draw_pixmap(inactive,
372 mwindow->theme->cstatus_x,
373 mwindow->theme->cstatus_y);
377 // printf("CWindowGUI::draw_status %d %d %d\n", __LINE__, mwindow->theme->cstatus_x,
378 // mwindow->theme->cstatus_y);
379 flash(mwindow->theme->cstatus_x,
380 mwindow->theme->cstatus_y,
386 float CWindowGUI::get_auto_zoom()
388 float conformed_w, conformed_h;
389 mwindow->edl->calculate_conformed_dimensions(0, conformed_w, conformed_h);
390 float zoom_x = canvas->w / conformed_w;
391 float zoom_y = canvas->h / conformed_h;
392 return zoom_x < zoom_y ? zoom_x : zoom_y;
395 void CWindowGUI::zoom_canvas(double value, int update_menu)
398 float zoom = !value ? get_auto_zoom() : value;
399 EDL *edl = mwindow->edl;
400 edl->session->cwindow_scrollbars = !value ? 0 : 1;
402 float cx = 0.5f * canvas->w; x = cx;
403 float cy = 0.5f * canvas->h; y = cy;
404 canvas->canvas_to_output(edl, 0, x, y);
405 canvas->update_zoom(0, 0, zoom);
406 float zoom_x, zoom_y, conformed_w, conformed_h;
407 canvas->get_zooms(edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
412 canvas->update_zoom((int)(x+0.5), (int)(y+0.5), zoom);
415 zoom_panel->update(value);
416 if( mwindow->edl->session->cwindow_operation == CWINDOW_ZOOM )
417 composite_panel->cpanel_zoom->update(zoom);
419 canvas->reposition_window(mwindow->edl,
420 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
421 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
422 canvas->draw_refresh();
425 void CWindowGUI::set_operation(int value)
428 case CWINDOW_TOOL_WINDOW:
429 mwindow->edl->session->tool_window = !mwindow->edl->session->tool_window;
430 composite_panel->operation[CWINDOW_TOOL_WINDOW]->update(mwindow->edl->session->tool_window);
431 tool_panel->update_show_window();
433 case CWINDOW_TITLESAFE:
434 mwindow->edl->session->safe_regions = !mwindow->edl->session->safe_regions;
435 composite_panel->operation[CWINDOW_TITLESAFE]->update(mwindow->edl->session->safe_regions);
436 value = mwindow->edl->session->cwindow_operation;
439 mwindow->edl->session->cwindow_operation = value;
440 composite_panel->set_operation(value);
444 edit_panel->update();
445 tool_panel->start_tool(value);
446 canvas->draw_refresh();
449 void CWindowGUI::update_tool()
451 tool_panel->update_values();
454 int CWindowGUI::close_event()
456 cwindow->hide_window();
461 int CWindowGUI::keypress_event()
464 int cwindow_operation = CWINDOW_NONE;
466 switch( get_keypress() ) {
483 if(mwindow->session->cwindow_fullscreen)
484 canvas->stop_fullscreen();
486 canvas->start_fullscreen();
487 lock_window("CWindowGUI::keypress_event 1");
491 if( ctrl_down() || shift_down() || alt_down() ) break;
493 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
495 mwindow->gui->unlock_window();
496 lock_window("CWindowGUI::keypress_event 2");
501 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
502 mwindow->clear_entry();
503 mwindow->gui->unlock_window();
504 lock_window("CWindowGUI::keypress_event 3");
509 if(mwindow->session->cwindow_fullscreen)
510 canvas->stop_fullscreen();
511 lock_window("CWindowGUI::keypress_event 4");
516 int alt_down = this->alt_down();
517 int shift_down = this->shift_down();
520 mwindow->gui->lock_window("CWindowGUI::keypress_event 5");
522 mwindow->prev_edit_handle(shift_down);
524 mwindow->move_left();
525 mwindow->gui->unlock_window();
526 lock_window("CWindowGUI::keypress_event 6");
532 if( !ctrl_down() && !alt_down() ) {
535 mwindow->gui->lock_window("CWindowGUI::keypress_event 7");
536 mwindow->move_left();
537 mwindow->gui->unlock_window();
538 lock_window("CWindowGUI::keypress_event 8");
545 int alt_down = this->alt_down();
546 int shift_down = this->shift_down();
549 mwindow->gui->lock_window("CWindowGUI::keypress_event 8");
551 mwindow->next_edit_handle(shift_down);
553 mwindow->move_right();
554 mwindow->gui->unlock_window();
555 lock_window("CWindowGUI::keypress_event 9");
561 if( !ctrl_down() && !alt_down() ) {
564 mwindow->gui->lock_window("CWindowGUI::keypress_event 10");
565 mwindow->move_right();
566 mwindow->gui->unlock_window();
567 lock_window("CWindowGUI::keypress_event 11");
573 if( !result && !ctrl_down() ) {
574 switch( get_keypress() ) {
577 mwindow->toggle_camera_xyz(); result = 1;
580 cwindow_operation = CWINDOW_PROTECT;
584 mwindow->toggle_projector_xyz(); result = 1;
587 cwindow_operation = CWINDOW_ZOOM;
591 if( !result && cwindow_operation < 0 && !ctrl_down() && !shift_down() ) {
592 switch( get_keypress() ) {
593 case KEY_F3: cwindow_operation = CWINDOW_MASK; break;
594 case KEY_F4: cwindow_operation = CWINDOW_RULER; break;
595 case KEY_F5: cwindow_operation = CWINDOW_CAMERA; break;
596 case KEY_F6: cwindow_operation = CWINDOW_PROJECTOR; break;
597 case KEY_F7: cwindow_operation = CWINDOW_CROP; break;
598 case KEY_F8: cwindow_operation = CWINDOW_EYEDROP; break;
599 case KEY_F9: cwindow_operation = CWINDOW_TOOL_WINDOW; break;
600 case KEY_F10: cwindow_operation = CWINDOW_TITLESAFE; break;
601 case KEY_F11: canvas->reset_camera(); result = 1; break;
602 case KEY_F12: canvas->reset_projector(); result = 1; break;
606 if( cwindow_operation >= 0 ) {
607 set_operation(cwindow_operation);
612 result = transport->keypress_event();
618 void CWindowGUI::reset_affected()
625 void CWindowGUI::keyboard_zoomin()
627 // if(mwindow->edl->session->cwindow_scrollbars)
629 zoom_panel->zoom_tumbler->handle_up_event();
636 void CWindowGUI::keyboard_zoomout()
638 // if(mwindow->edl->session->cwindow_scrollbars)
640 zoom_panel->zoom_tumbler->handle_down_event();
648 void CWindowGUI::drag_motion()
650 if(get_hidden()) return;
652 if(mwindow->session->current_operation != DRAG_ASSET &&
653 mwindow->session->current_operation != DRAG_VTRANSITION &&
654 mwindow->session->current_operation != DRAG_VEFFECT) return;
655 int need_highlight = cursor_above() && get_cursor_over_window();
656 if( highlighted == need_highlight ) return;
657 highlighted = need_highlight;
658 canvas->draw_refresh();
661 int CWindowGUI::drag_stop()
664 if(get_hidden()) return 0;
665 if( !highlighted ) return 0;
666 if( mwindow->session->current_operation != DRAG_ASSET &&
667 mwindow->session->current_operation != DRAG_VTRANSITION &&
668 mwindow->session->current_operation != DRAG_VEFFECT) return 0;
670 canvas->draw_refresh();
673 if(mwindow->session->current_operation == DRAG_ASSET)
675 if(mwindow->session->drag_assets->total ||
676 mwindow->session->drag_clips->total)
678 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
679 mwindow->undo->update_undo_before(_("insert assets"), 0);
682 if(mwindow->session->drag_assets->total)
685 mwindow->load_assets(mwindow->session->drag_assets,
686 mwindow->edl->local_session->get_selectionstart(),
688 mwindow->session->track_highlighted,
690 mwindow->edl->session->labels_follow_edits,
691 mwindow->edl->session->plugins_follow_edits,
692 mwindow->edl->session->autos_follow_edits,
696 if(mwindow->session->drag_clips->total)
699 mwindow->paste_edls(mwindow->session->drag_clips,
701 mwindow->session->track_highlighted,
702 mwindow->edl->local_session->get_selectionstart(),
703 mwindow->edl->session->labels_follow_edits,
704 mwindow->edl->session->plugins_follow_edits,
705 mwindow->edl->session->autos_follow_edits,
709 if(mwindow->session->drag_assets->total ||
710 mwindow->session->drag_clips->total)
712 mwindow->save_backup();
713 mwindow->restart_brender();
714 mwindow->gui->update(1, 1, 1, 1, 0, 1, 0);
715 mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
716 mwindow->gui->unlock_window();
717 mwindow->sync_parameters(CHANGE_ALL);
721 if(mwindow->session->current_operation == DRAG_VEFFECT)
723 //printf("CWindowGUI::drag_stop 1\n");
724 Track *affected_track = cwindow->calculate_affected_track();
725 //printf("CWindowGUI::drag_stop 2\n");
727 mwindow->gui->lock_window("CWindowGUI::drag_stop 3");
728 mwindow->insert_effects_cwindow(affected_track);
729 mwindow->session->current_operation = NO_OPERATION;
730 mwindow->gui->unlock_window();
733 if(mwindow->session->current_operation == DRAG_VTRANSITION)
735 Track *affected_track = cwindow->calculate_affected_track();
736 mwindow->gui->lock_window("CWindowGUI::drag_stop 4");
737 mwindow->paste_transition_cwindow(affected_track);
738 mwindow->session->current_operation = NO_OPERATION;
739 mwindow->gui->unlock_window();
745 void CWindowGUI::update_meters()
747 if(mwindow->edl->session->cwindow_meter != meters->visible)
749 meters->set_meters(meters->meter_count, mwindow->edl->session->cwindow_meter);
750 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
751 resize_event(get_w(), get_h());
755 void CWindowGUI::stop_transport(const char *lock_msg)
757 if( lock_msg ) unlock_window();
758 mwindow->stop_transport();
759 if( lock_msg ) lock_window(lock_msg);
763 CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
764 : EditPanel(mwindow, cwindow->gui, CWINDOW_ID,
765 mwindow->theme->cedit_x, mwindow->theme->cedit_y,
766 mwindow->edl->session->editing_mode,
767 0, // use_editing_mode
786 this->mwindow = mwindow;
787 this->cwindow = cwindow;
790 #define CWrapper(fn) void CWindowEditing::fn() { \
791 mwindow->gui->lock_window("CWrapper::" #fn); \
793 mwindow->gui->unlock_window(); \
796 CWrapper(copy_selection)
797 CWrapper(splice_selection)
798 CWrapper(overwrite_selection)
799 CWrapper(set_inpoint)
800 CWrapper(set_outpoint)
801 CWrapper(unset_inoutpoint)
802 CWrapper(toggle_label)
804 #define CWrapper_cut(fn) void CWindowEditing::fn(int cut) { \
805 mwindow->gui->lock_window("CWrapper::" #fn); \
806 EditPanel::fn(cut); \
807 mwindow->gui->unlock_window(); \
809 CWrapper_cut(prev_label)
810 CWrapper_cut(next_label)
811 CWrapper_cut(prev_edit)
812 CWrapper_cut(next_edit)
814 void CWindowEditing::to_clip()
816 mwindow->to_clip(mwindow->edl, _("composer window: "), 0);
820 CWindowMeters::CWindowMeters(MWindow *mwindow,
825 : MeterPanel(mwindow,
831 mwindow->edl->session->audio_channels,
832 mwindow->edl->session->cwindow_meter,
836 this->mwindow = mwindow;
840 CWindowMeters::~CWindowMeters()
844 int CWindowMeters::change_status_event(int new_status)
846 mwindow->edl->session->cwindow_meter = new_status;
847 gui->update_meters();
854 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
855 : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
856 x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
858 this->mwindow = mwindow;
862 CWindowZoom::~CWindowZoom()
866 void CWindowZoom::update(double value)
868 char string[BCSTRLEN];
869 const char *cp = string;
872 int frac = value >= 1.0f ? 1 :
874 value >= .01f ? 3 : 4;
875 sprintf(string, "x %.*f", frac, value);
879 ZoomPanel::update(cp);
882 int CWindowZoom::handle_event()
884 double value = !strcasecmp(gui->auto_zoom, get_text()) ? 0 : get_value();
885 gui->zoom_canvas(value, 0);
892 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
893 : BC_PercentageSlider(x,
902 this->mwindow = mwindow;
903 this->cwindow = cwindow;
904 set_precision(0.00001);
907 CWindowSlider::~CWindowSlider()
911 int CWindowSlider::handle_event()
913 cwindow->update_position((double)get_value());
917 void CWindowSlider::set_position()
919 double new_length = mwindow->edl->tracks->total_length();
920 update(mwindow->theme->cslider_w,
921 mwindow->edl->local_session->get_selectionstart(1),
926 int CWindowSlider::increase_value()
929 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
930 lock_window("CWindowSlider::increase_value");
934 int CWindowSlider::decrease_value()
937 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
938 lock_window("CWindowSlider::decrease_value");
943 // CWindowDestination::CWindowDestination(MWindow *mwindow, CWindowGUI *cwindow, int x, int y)
944 // : BC_PopupTextBox(cwindow,
945 // &cwindow->destinations,
946 // cwindow->destinations.values[cwindow->cwindow->destination]->get_text(),
952 // this->mwindow = mwindow;
953 // this->cwindow = cwindow;
956 // CWindowDestination::~CWindowDestination()
960 // int CWindowDestination::handle_event()
971 CWindowTransport::CWindowTransport(MWindow *mwindow,
975 : PlayTransport(mwindow,
983 EDL* CWindowTransport::get_edl()
988 void CWindowTransport::goto_start()
990 gui->unlock_window();
991 handle_transport(REWIND, 1);
993 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
994 mwindow->goto_start();
995 mwindow->gui->unlock_window();
997 gui->lock_window("CWindowTransport::goto_start 2");
1000 void CWindowTransport::goto_end()
1002 gui->unlock_window();
1003 handle_transport(GOTO_END, 1);
1005 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
1006 mwindow->goto_end();
1007 mwindow->gui->unlock_window();
1009 gui->lock_window("CWindowTransport::goto_end 2");
1014 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
1017 mwindow->theme->ccanvas_x,
1018 mwindow->theme->ccanvas_y,
1019 mwindow->theme->ccanvas_w,
1020 mwindow->theme->ccanvas_h,
1023 mwindow->edl->session->cwindow_scrollbars)
1025 this->mwindow = mwindow;
1029 void CWindowCanvas::status_event()
1031 gui->draw_status(1);
1034 int CWindowCanvas::get_fullscreen()
1036 return mwindow->session->cwindow_fullscreen;
1039 void CWindowCanvas::set_fullscreen(int value)
1041 mwindow->session->cwindow_fullscreen = value;
1045 void CWindowCanvas::update_zoom(int x, int y, float zoom)
1047 use_scrollbars = mwindow->edl->session->cwindow_scrollbars;
1049 mwindow->edl->session->cwindow_xscroll = x;
1050 mwindow->edl->session->cwindow_yscroll = y;
1051 mwindow->edl->session->cwindow_zoom = zoom;
1054 void CWindowCanvas::zoom_auto()
1056 gui->zoom_canvas(0, 1);
1059 int CWindowCanvas::get_xscroll()
1061 return mwindow->edl->session->cwindow_xscroll;
1064 int CWindowCanvas::get_yscroll()
1066 return mwindow->edl->session->cwindow_yscroll;
1070 float CWindowCanvas::get_zoom()
1072 return mwindow->edl->session->cwindow_zoom;
1075 void CWindowCanvas::draw_refresh(int flush)
1077 if(get_canvas() && !get_canvas()->get_video_on())
1080 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
1082 float in_x1, in_y1, in_x2, in_y2;
1083 float out_x1, out_y1, out_x2, out_y2;
1084 get_transfers(mwindow->edl,
1094 if(!EQUIV(out_x1, 0) ||
1095 !EQUIV(out_y1, 0) ||
1096 !EQUIV(out_x2, get_canvas()->get_w()) ||
1097 !EQUIV(out_y2, get_canvas()->get_h()))
1099 get_canvas()->clear_box(0,
1101 get_canvas()->get_w(),
1102 get_canvas()->get_h());
1105 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1106 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1109 if(out_x2 > out_x1 &&
1114 // input scaled from session to refresh frame coordinates
1115 int ow = get_output_w(mwindow->edl);
1116 int oh = get_output_h(mwindow->edl);
1117 int rw = refresh_frame->get_w();
1118 int rh = refresh_frame->get_h();
1119 float xs = (float)rw / ow;
1120 float ys = (float)rh / oh;
1121 in_x1 *= xs; in_x2 *= xs;
1122 in_y1 *= ys; in_y2 *= ys;
1123 // Can't use OpenGL here because it is called asynchronously of the
1124 // playback operation.
1125 get_canvas()->draw_vframe(refresh_frame,
1128 (int)(out_x2 - out_x1),
1129 (int)(out_y2 - out_y1),
1132 (int)(in_x2 - in_x1),
1133 (int)(in_y2 - in_y1),
1139 get_canvas()->clear_box(0,
1141 get_canvas()->get_w(),
1142 get_canvas()->get_h());
1146 // allow last opengl write to complete before redraw
1147 // tried sync_display, glFlush, glxMake*Current(0..)
1149 get_canvas()->flash(flush);
1151 //printf("CWindowCanvas::draw_refresh 10\n");
1154 #define CROPHANDLE_W 10
1155 #define CROPHANDLE_H 10
1157 void CWindowCanvas::draw_crophandle(int x, int y)
1159 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1167 #define CONTROL_W 10
1168 #define CONTROL_H 10
1169 #define FIRST_CONTROL_W 20
1170 #define FIRST_CONTROL_H 20
1172 #define BC_INFINITY 65536
1174 #define RULERHANDLE_W 16
1175 #define RULERHANDLE_H 16
1179 int CWindowCanvas::do_ruler(int draw,
1185 float x1 = mwindow->edl->session->ruler_x1;
1186 float y1 = mwindow->edl->session->ruler_y1;
1187 float x2 = mwindow->edl->session->ruler_x2;
1188 float y2 = mwindow->edl->session->ruler_y2;
1189 float canvas_x1 = x1;
1190 float canvas_y1 = y1;
1191 float canvas_x2 = x2;
1192 float canvas_y2 = y2;
1193 float output_x = get_cursor_x();
1194 float output_y = get_cursor_y();
1195 float canvas_cursor_x = output_x;
1196 float canvas_cursor_y = output_y;
1198 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1199 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1200 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1201 mwindow->session->cwindow_output_x = roundf(output_x);
1202 mwindow->session->cwindow_output_y = roundf(output_y);
1204 if(button_press && get_buttonpress() == 1)
1206 gui->ruler_handle = -1;
1207 gui->ruler_translate = 0;
1210 gui->ruler_translate = 1;
1211 gui->ruler_origin_x = x1;
1212 gui->ruler_origin_y = y1;
1215 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1216 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1217 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1218 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1220 gui->ruler_handle = 0;
1221 gui->ruler_origin_x = x1;
1222 gui->ruler_origin_y = y1;
1225 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1226 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1227 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1228 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1230 gui->ruler_handle = 1;
1231 gui->ruler_origin_x = x2;
1232 gui->ruler_origin_y = y2;
1236 // Start new selection
1237 if(!gui->ruler_translate &&
1238 (gui->ruler_handle < 0 ||
1243 do_ruler(1, 0, 0, 0);
1244 get_canvas()->flash();
1245 gui->ruler_handle = 1;
1246 mwindow->edl->session->ruler_x1 = output_x;
1247 mwindow->edl->session->ruler_y1 = output_y;
1248 mwindow->edl->session->ruler_x2 = output_x;
1249 mwindow->edl->session->ruler_y2 = output_y;
1250 gui->ruler_origin_x = mwindow->edl->session->ruler_x2;
1251 gui->ruler_origin_y = mwindow->edl->session->ruler_y2;
1254 gui->x_origin = output_x;
1255 gui->y_origin = output_y;
1256 gui->current_operation = CWINDOW_RULER;
1257 gui->tool_panel->raise_window();
1263 if(gui->current_operation == CWINDOW_RULER)
1265 if(gui->ruler_translate)
1268 do_ruler(1, 0, 0, 0);
1269 float x_difference = mwindow->edl->session->ruler_x1;
1270 float y_difference = mwindow->edl->session->ruler_y1;
1271 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1272 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1273 x_difference -= mwindow->edl->session->ruler_x1;
1274 y_difference -= mwindow->edl->session->ruler_y1;
1275 mwindow->edl->session->ruler_x2 -= x_difference;
1276 mwindow->edl->session->ruler_y2 -= y_difference;
1278 do_ruler(1, 0, 0, 0);
1279 get_canvas()->flash();
1283 switch(gui->ruler_handle)
1286 do_ruler(1, 0, 0, 0);
1287 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1288 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1289 if(gui->alt_down() || gui->ctrl_down())
1291 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1292 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1296 double distance_value =
1297 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1298 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1299 if(angle_value < 22)
1300 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2;
1302 if(angle_value > 67)
1303 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2;
1305 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 &&
1306 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1308 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1309 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1312 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 && mwindow->edl->session->ruler_y1 > mwindow->edl->session->ruler_y2)
1314 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1315 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1318 if(mwindow->edl->session->ruler_x1 > mwindow->edl->session->ruler_x2 &&
1319 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1321 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1322 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1326 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1327 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1330 do_ruler(1, 0, 0, 0);
1331 get_canvas()->flash();
1336 do_ruler(1, 0, 0, 0);
1337 mwindow->edl->session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1338 mwindow->edl->session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1339 if(gui->alt_down() || gui->ctrl_down())
1341 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1342 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1346 double distance_value =
1347 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1348 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1349 if(angle_value < 22)
1350 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1;
1352 if(angle_value > 67)
1353 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1;
1355 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1356 mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1358 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1359 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1362 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1363 mwindow->edl->session->ruler_y2 > mwindow->edl->session->ruler_y1)
1365 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1366 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1369 if(mwindow->edl->session->ruler_x2 > mwindow->edl->session->ruler_x1 && mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1371 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1372 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1376 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1377 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1380 do_ruler(1, 0, 0, 0);
1381 get_canvas()->flash();
1385 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1389 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1394 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1395 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1396 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1397 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1399 set_cursor(UPRIGHT_ARROW_CURSOR);
1402 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1403 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1404 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1405 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1407 set_cursor(UPRIGHT_ARROW_CURSOR);
1410 set_cursor(CROSS_CURSOR);
1412 // Update current position
1417 // Assume no ruler measurement if 0 length
1418 if(draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)))
1420 get_canvas()->set_inverse();
1421 get_canvas()->set_color(WHITE);
1422 get_canvas()->draw_line((int)canvas_x1,
1426 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1428 roundf(canvas_x1) + RULERHANDLE_W / 2,
1430 get_canvas()->draw_line(roundf(canvas_x1),
1431 roundf(canvas_y1) - RULERHANDLE_H / 2,
1433 roundf(canvas_y1) + RULERHANDLE_H / 2);
1434 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1436 roundf(canvas_x2) + RULERHANDLE_W / 2,
1438 get_canvas()->draw_line(roundf(canvas_x2),
1439 roundf(canvas_y2) - RULERHANDLE_H / 2,
1441 roundf(canvas_y2) + RULERHANDLE_H / 2);
1442 get_canvas()->set_opaque();
1449 static inline double line_dist(float cx,float cy, float tx,float ty)
1451 double dx = tx-cx, dy = ty-cy;
1452 return sqrt(dx*dx + dy*dy);
1455 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1457 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1458 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1462 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1463 int button_press, int cursor_motion, int draw)
1465 // Retrieve points from top recordable track
1466 //printf("CWindowCanvas::do_mask 1\n");
1467 Track *track = gui->cwindow->calculate_affected_track();
1468 //printf("CWindowCanvas::do_mask 2\n");
1470 if(!track) return 0;
1471 //printf("CWindowCanvas::do_mask 3\n");
1473 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1474 int64_t position = track->to_units(
1475 mwindow->edl->local_session->get_selectionstart(1),
1477 ArrayList<MaskPoint*> points;
1479 // Determine the points based on whether
1480 // new keyframes will be generated or drawing is performed.
1481 // If keyframe generation occurs, use the interpolated mask.
1482 // If no keyframe generation occurs, use the previous mask.
1483 int use_interpolated = 0;
1484 if(button_press || cursor_motion) {
1485 #ifdef USE_KEYFRAME_SPANNING
1486 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1487 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1490 mask_autos->get_prev_auto(track->to_units(selection_start, 0),
1491 PLAY_FORWARD, first, 1);
1493 mask_autos->get_prev_auto(track->to_units(selection_end, 0),
1494 PLAY_FORWARD, last, 1);
1496 if(last == first && (!mwindow->edl->session->auto_keyframes))
1497 use_interpolated = 0;
1499 // If keyframe spanning occurs, use the interpolated points.
1500 // If new keyframe is generated, use the interpolated points.
1501 use_interpolated = 1;
1504 if(mwindow->edl->session->auto_keyframes)
1505 use_interpolated = 1;
1509 use_interpolated = 1;
1511 if(use_interpolated) {
1512 // Interpolate the points to get exactly what is being rendered at this position.
1513 mask_autos->get_points(&points,
1514 mwindow->edl->session->cwindow_mask,
1519 // Use the prev mask
1521 mask_autos->get_prev_auto(position,
1525 ((MaskAuto*)prev)->get_points(&points,
1526 mwindow->edl->session->cwindow_mask);
1529 // Projector zooms relative to the center of the track output.
1530 float half_track_w = (float)track->track_w / 2;
1531 float half_track_h = (float)track->track_h / 2;
1532 // Translate mask to projection
1533 float projector_x, projector_y, projector_z;
1534 track->automation->get_projector(
1535 &projector_x, &projector_y, &projector_z,
1536 position, PLAY_FORWARD);
1539 // Get position of cursor relative to mask
1540 float cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
1541 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1542 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1544 projector_x += mwindow->edl->session->output_w / 2;
1545 projector_y += mwindow->edl->session->output_h / 2;
1546 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1547 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1549 // Fix cursor origin
1551 gui->x_origin = mask_cursor_x;
1552 gui->y_origin = mask_cursor_y;
1556 // Points of closest line
1557 int shortest_point1 = -1;
1558 int shortest_point2 = -1;
1560 int shortest_point = -1;
1561 // Distance to closest line
1562 float shortest_line_distance = BC_INFINITY;
1563 // Distance to closest point
1564 float shortest_point_distance = BC_INFINITY;
1565 int selected_point = -1;
1566 int selected_control_point = -1;
1567 float selected_control_point_distance = BC_INFINITY;
1568 ArrayList<int> x_points;
1569 ArrayList<int> y_points;
1571 if(!cursor_motion) {
1573 get_canvas()->set_color(WHITE);
1574 get_canvas()->set_inverse();
1576 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1578 // Never draw closed polygon and a closed
1579 // polygon is harder to add points to.
1580 for(int i = 0; i < points.size() && !result; i++) {
1581 MaskPoint *point1 = points.get(i);
1582 MaskPoint *point2 = (i >= points.size() - 1) ?
1583 points.get(0) : points.get(i + 1);
1585 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1586 if(point_distance1 < shortest_point_distance || shortest_point < 0) {
1587 shortest_point_distance = point_distance1;
1591 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1592 if(point_distance2 < shortest_point_distance || shortest_point < 0) {
1593 shortest_point_distance = point_distance2;
1594 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1598 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1600 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1601 //point1->x, point1->y, point2->x, point2->y, projector_z);
1602 for(int j = 0; j <= segments && !result; j++) {
1603 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1604 float x0 = point1->x, y0 = point1->y;
1605 float x1 = point1->x + point1->control_x2;
1606 float y1 = point1->y + point1->control_y2;
1607 float x2 = point2->x + point2->control_x1;
1608 float y2 = point2->y + point2->control_y1;
1609 float x3 = point2->x, y3 = point2->y;
1610 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1611 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1612 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1613 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1614 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1615 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1616 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1617 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1619 float t = (float)j / segments;
1620 float tpow2 = t * t;
1621 float tpow3 = t * t * t;
1623 float invtpow2 = invt * invt;
1624 float invtpow3 = invt * invt * invt;
1626 float x = ( invtpow3 * x0
1627 + 3 * t * invtpow2 * x1
1628 + 3 * tpow2 * invt * x2
1630 float y = ( invtpow3 * y0
1631 + 3 * t * invtpow2 * y1
1632 + 3 * tpow2 * invt * y2
1634 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1635 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1636 // Test new point addition
1638 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1640 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1641 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1642 if(line_distance < shortest_line_distance ||
1643 shortest_point1 < 0) {
1644 shortest_line_distance = line_distance;
1645 shortest_point1 = i;
1646 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1647 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1648 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1651 // Test existing point selection
1653 if(gui->ctrl_down()) {
1654 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1656 if(distance < selected_control_point_distance) {
1658 selected_control_point = 1;
1659 selected_control_point_distance = distance;
1663 if(!gui->shift_down()) {
1664 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1665 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
1670 selected_point = shortest_point;
1673 // Test second point
1674 if(gui->ctrl_down()) {
1675 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1677 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1678 if(distance < selected_control_point_distance) {
1679 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1680 selected_control_point = 0;
1681 selected_control_point_distance = distance;
1684 else if(i < points.size() - 1) {
1685 if(!gui->shift_down()) {
1686 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1687 if(test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3)) {
1688 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1692 selected_point = shortest_point;
1697 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1701 if(draw) { // Draw joining line
1702 x_points.append((int)canvas_x);
1703 y_points.append((int)canvas_y);
1707 if(draw) { // Draw second anchor
1708 if(i < points.size() - 1) {
1709 if(i == gui->affected_point - 1)
1710 get_canvas()->draw_disc(
1711 (int)canvas_x - CONTROL_W / 2,
1712 (int)canvas_y - CONTROL_W / 2,
1713 CONTROL_W, CONTROL_H);
1715 get_canvas()->draw_circle(
1716 (int)canvas_x - CONTROL_W / 2,
1717 (int)canvas_y - CONTROL_W / 2,
1718 CONTROL_W, CONTROL_H);
1719 // char string[BCTEXTLEN];
1720 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1721 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1723 // Draw second control point.
1724 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1725 get_canvas()->draw_line(
1726 (int)canvas_x, (int)canvas_y,
1727 (int)canvas_x2, (int)canvas_y2);
1728 get_canvas()->draw_rectangle(
1729 (int)canvas_x2 - CONTROL_W / 2,
1730 (int)canvas_y2 - CONTROL_H / 2,
1731 CONTROL_W, CONTROL_H);
1736 // Draw first anchor
1737 if(i == 0 && draw) {
1738 char mask_label[BCSTRLEN];
1739 sprintf(mask_label, "%d",
1740 mwindow->edl->session->cwindow_mask);
1741 get_canvas()->draw_text(
1742 (int)canvas_x - FIRST_CONTROL_W,
1743 (int)canvas_y - FIRST_CONTROL_H,
1746 get_canvas()->draw_disc(
1747 (int)canvas_x - FIRST_CONTROL_W / 2,
1748 (int)canvas_y - FIRST_CONTROL_H / 2,
1749 FIRST_CONTROL_W, FIRST_CONTROL_H);
1752 // Draw first control point.
1754 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1755 get_canvas()->draw_line(
1756 (int)canvas_x, (int)canvas_y,
1757 (int)canvas_x1, (int)canvas_y1);
1758 get_canvas()->draw_rectangle(
1759 (int)canvas_x1 - CONTROL_W / 2,
1760 (int)canvas_y1 - CONTROL_H / 2,
1761 CONTROL_W, CONTROL_H);
1763 x_points.append((int)canvas_x);
1764 y_points.append((int)canvas_y);
1767 //printf("CWindowCanvas::do_mask 1\n");
1771 //printf("CWindowCanvas::do_mask 1\n");
1774 get_canvas()->draw_polygon(&x_points, &y_points);
1775 get_canvas()->set_opaque();
1777 //printf("CWindowCanvas::do_mask 1\n");
1780 if(button_press && !result) {
1781 gui->affected_track = gui->cwindow->calculate_affected_track();
1783 // Get keyframe outside the EDL to edit. This must be rendered
1784 // instead of the EDL keyframes when it exists. Then it must be
1785 // applied to the EDL keyframes on buttonrelease.
1786 if(gui->affected_track) {
1787 #ifdef USE_KEYFRAME_SPANNING
1788 // Make copy of current parameters in local keyframe
1789 gui->mask_keyframe =
1790 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1793 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1796 gui->mask_keyframe =
1797 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1802 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1805 // Translate entire keyframe
1806 if(gui->alt_down() && mask->points.size()) {
1807 mwindow->undo->update_undo_before(_("mask translate"), 0);
1808 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1809 gui->affected_point = 0;
1812 // Existing point or control point was selected
1813 if(selected_point >= 0) {
1814 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1815 gui->affected_point = selected_point;
1817 if(selected_control_point == 0)
1818 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1820 if(selected_control_point == 1)
1821 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1823 gui->current_operation = mwindow->edl->session->cwindow_operation;
1825 else // No existing point or control point was selected so create a new one
1826 if(!gui->ctrl_down() && !gui->alt_down()) {
1827 mwindow->undo->update_undo_before(_("mask point"), 0);
1828 // Create the template
1829 MaskPoint *point = new MaskPoint;
1830 point->x = mask_cursor_x;
1831 point->y = mask_cursor_y;
1832 point->control_x1 = 0;
1833 point->control_y1 = 0;
1834 point->control_x2 = 0;
1835 point->control_y2 = 0;
1838 if(shortest_point2 < shortest_point1) {
1839 shortest_point2 ^= shortest_point1;
1840 shortest_point1 ^= shortest_point2;
1841 shortest_point2 ^= shortest_point1;
1846 // printf("CWindowGUI::do_mask 40\n");
1847 // mwindow->edl->dump();
1848 // printf("CWindowGUI::do_mask 50\n");
1852 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1853 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1854 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1856 // Append to end of list
1857 if( shortest_point1 == shortest_point2 ||
1858 labs(shortest_point1 - shortest_point2) > 1) {
1859 #ifdef USE_KEYFRAME_SPANNING
1861 MaskPoint *new_point = new MaskPoint;
1862 points.append(new_point);
1863 *new_point = *point;
1864 gui->affected_point = points.size() - 1;
1868 // Need to apply the new point to every keyframe
1869 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1870 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1871 MaskPoint *new_point = new MaskPoint;
1872 submask->points.append(new_point);
1873 *new_point = *point;
1874 if(current == (MaskAuto*)mask_autos->default_auto)
1875 current = (MaskAuto*)mask_autos->first;
1877 current = (MaskAuto*)NEXT;
1879 gui->affected_point = mask->points.size() - 1;
1885 // Insert between 2 points, shifting back point 2
1886 if(shortest_point1 >= 0 && shortest_point2 >= 0) {
1888 #ifdef USE_KEYFRAME_SPANNING
1889 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1891 if(points.size() >= shortest_point2) {
1892 MaskPoint *new_point = new MaskPoint;
1894 for(int i = points.size() - 1;
1895 i > shortest_point2;
1897 points.values[i] = points.values[i - 1];
1898 points.values[shortest_point2] = new_point;
1900 *new_point = *point;
1905 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1906 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1907 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1909 if(submask->points.size() >= shortest_point2) {
1910 MaskPoint *new_point = new MaskPoint;
1911 submask->points.append(0);
1912 for(int i = submask->points.size() - 1;
1913 i > shortest_point2;
1915 submask->points.values[i] = submask->points.values[i - 1];
1916 submask->points.values[shortest_point2] = new_point;
1918 *new_point = *point;
1921 if(current == (MaskAuto*)mask_autos->default_auto)
1922 current = (MaskAuto*)mask_autos->first;
1924 current = (MaskAuto*)NEXT;
1928 gui->affected_point = shortest_point2;
1933 // printf("CWindowGUI::do_mask 20\n");
1934 // mwindow->edl->dump();
1935 // printf("CWindowGUI::do_mask 30\n");
1938 //printf("CWindowCanvas::do_mask 1\n");
1939 // Create the first point.
1940 #ifdef USE_KEYFRAME_SPANNING
1941 MaskPoint *new_point = new MaskPoint;
1942 points.append(new_point);
1943 *new_point = *point;
1944 gui->affected_point = points.size() - 1;
1946 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1947 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1948 MaskPoint *new_point = new MaskPoint;
1949 submask->points.append(new_point);
1950 *new_point = *point;
1951 if(current == (MaskAuto*)mask_autos->default_auto)
1952 current = (MaskAuto*)mask_autos->first;
1954 current = (MaskAuto*)NEXT;
1956 gui->affected_point = points.size() - 1;
1959 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
1962 gui->current_operation = mwindow->edl->session->cwindow_operation;
1963 // Delete the template
1972 if(button_press && result) {
1973 #ifdef USE_KEYFRAME_SPANNING
1974 MaskPoint *point = points.values[gui->affected_point];
1975 gui->center_x = point->x;
1976 gui->center_y = point->y;
1977 gui->control_in_x = point->control_x1;
1978 gui->control_in_y = point->control_y1;
1979 gui->control_out_x = point->control_x2;
1980 gui->control_out_y = point->control_y2;
1981 gui->tool_panel->raise_window();
1983 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1984 MaskPoint *point = mask->points.values[gui->affected_point];
1985 gui->center_x = point->x;
1986 gui->center_y = point->y;
1987 gui->control_in_x = point->control_x1;
1988 gui->control_in_y = point->control_y1;
1989 gui->control_out_x = point->control_x2;
1990 gui->control_out_y = point->control_y2;
1991 gui->tool_panel->raise_window();
1995 //printf("CWindowCanvas::do_mask 8\n");
1998 #ifdef USE_KEYFRAME_SPANNING
1999 // Must update the reference keyframes for every cursor motion
2000 gui->mask_keyframe =
2001 (MaskAuto*)gui->cwindow->calculate_affected_auto(
2004 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
2007 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2009 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
2010 if( gui->affected_point >= 0 && gui->affected_point < mask->points.size() &&
2011 gui->current_operation != CWINDOW_NONE) {
2012 // mwindow->undo->update_undo_before(_("mask point"), this);
2013 #ifdef USE_KEYFRAME_SPANNING
2014 MaskPoint *point = points.get(gui->affected_point);
2016 MaskPoint *point = mask->points.get(gui->affected_point);
2018 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2019 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask->points.size(), gui->affected_point);
2021 float last_x = point->x;
2022 float last_y = point->y;
2023 float last_control_x1 = point->control_x1;
2024 float last_control_y1 = point->control_y1;
2025 float last_control_x2 = point->control_x2;
2026 float last_control_y2 = point->control_y2;
2028 switch(gui->current_operation) {
2030 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2031 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
2032 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
2035 case CWINDOW_MASK_CONTROL_IN:
2036 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
2037 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
2040 case CWINDOW_MASK_CONTROL_OUT:
2041 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
2042 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
2045 case CWINDOW_MASK_TRANSLATE:
2046 #ifdef USE_KEYFRAME_SPANNING
2047 for(int i = 0; i < points.size(); i++) {
2048 points.values[i]->x += mask_cursor_x - gui->x_origin;
2049 points.values[i]->y += mask_cursor_y - gui->y_origin;
2052 for(int i = 0; i < mask->points.size(); i++) {
2053 mask->points.values[i]->x += mask_cursor_x - gui->x_origin;
2054 mask->points.values[i]->y += mask_cursor_y - gui->y_origin;
2057 gui->x_origin = mask_cursor_x;
2058 gui->y_origin = mask_cursor_y;
2062 if( !EQUIV(last_x, point->x) ||
2063 !EQUIV(last_y, point->y) ||
2064 !EQUIV(last_control_x1, point->control_x1) ||
2065 !EQUIV(last_control_y1, point->control_y1) ||
2066 !EQUIV(last_control_x2, point->control_x2) ||
2067 !EQUIV(last_control_y2, point->control_y2)) {
2073 if(gui->current_operation == CWINDOW_NONE) {
2074 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
2076 for(int i = 0; i < points.size() && !over_point; i++) {
2077 MaskPoint *point = points.get(i);
2078 float x0 = point->x;
2079 float y0 = point->y;
2080 float x1 = point->x + point->control_x1;
2081 float y1 = point->y + point->control_y1;
2082 float x2 = point->x + point->control_x2;
2083 float y2 = point->y + point->control_y2;
2084 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
2085 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
2087 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
2088 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
2092 if(!over_point && gui->ctrl_down()) {
2093 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
2094 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
2095 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2096 if(test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1)) {
2100 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2101 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2102 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2103 if(test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2)) {
2110 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2115 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2118 #ifdef USE_KEYFRAME_SPANNING
2119 // Must commit change after operation.
2120 if(rerender && track) {
2121 // Swap EDL keyframe with original.
2122 // Apply new values to keyframe span
2123 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2124 temp_keyframe.copy_data(gui->mask_keyframe);
2125 // Apply interpolated points back to keyframe
2126 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2127 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2128 mask_autos->update_parameter(&temp_keyframe);
2132 points.remove_all_objects();
2133 //printf("CWindowCanvas::do_mask 20\n");
2137 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2140 int radius = mwindow->edl->session->eyedrop_radius;
2148 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2153 row1 = gui->eyedrop_y - radius;
2154 row2 = gui->eyedrop_y + radius;
2155 column1 = gui->eyedrop_x - radius;
2156 column2 = gui->eyedrop_x + radius;
2158 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2159 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2160 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2161 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2163 if(row2 <= row1) row2 = row1 + 1;
2164 if(column2 <= column1) column2 = column1 + 1;
2171 output_to_canvas(mwindow->edl, 0, x1, y1);
2172 output_to_canvas(mwindow->edl, 0, x2, y2);
2173 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2175 if(x2 - x1 >= 1 && y2 - y1 >= 1)
2177 get_canvas()->set_inverse();
2178 get_canvas()->set_color(WHITE);
2180 get_canvas()->draw_rectangle((int)x1,
2185 get_canvas()->set_opaque();
2186 get_canvas()->flash();
2194 gui->current_operation = CWINDOW_EYEDROP;
2195 gui->tool_panel->raise_window();
2198 if(gui->current_operation == CWINDOW_EYEDROP)
2200 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2202 // Get color out of frame.
2203 // Doesn't work during playback because that bypasses the refresh frame.
2204 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2206 float cursor_x = get_cursor_x();
2207 float cursor_y = get_cursor_y();
2208 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2209 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2210 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2212 row1 = cursor_y - radius;
2213 row2 = cursor_y + radius;
2214 column1 = cursor_x - radius;
2215 column2 = cursor_x + radius;
2216 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2217 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2218 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2219 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2220 if(row2 <= row1) row2 = row1 + 1;
2221 if(column2 <= column1) column2 = column1 + 1;
2225 if(gui->eyedrop_visible)
2228 do_eyedrop(temp, 0, 1);
2229 gui->eyedrop_visible = 0;
2232 gui->eyedrop_x = cursor_x;
2233 gui->eyedrop_y = cursor_y;
2238 do_eyedrop(temp, 0, 1);
2239 gui->eyedrop_visible = 1;
2242 // Decompression coefficients straight out of jpeglib
2243 #define V_TO_R 1.40200
2244 #define V_TO_G -0.71414
2246 #define U_TO_G -0.34414
2247 #define U_TO_B 1.77200
2249 #define GET_COLOR(type, components, max, do_yuv) \
2251 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2253 float red = (float)*row++ / max; \
2254 float green = (float)*row++ / max; \
2255 float blue = (float)*row++ / max; \
2258 float r = red + V_TO_R * (blue - 0.5); \
2259 float g = red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
2260 float b = red + U_TO_B * (green - 0.5); \
2261 mwindow->edl->local_session->red += r; \
2262 mwindow->edl->local_session->green += g; \
2263 mwindow->edl->local_session->blue += b; \
2264 if(r > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = r; \
2265 if(g > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = g; \
2266 if(b > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = b; \
2270 mwindow->edl->local_session->red += red; \
2271 mwindow->edl->local_session->green += green; \
2272 mwindow->edl->local_session->blue += blue; \
2273 if(red > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = red; \
2274 if(green > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = green; \
2275 if(blue > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = blue; \
2281 mwindow->edl->local_session->red = 0;
2282 mwindow->edl->local_session->green = 0;
2283 mwindow->edl->local_session->blue = 0;
2284 mwindow->edl->local_session->red_max = 0;
2285 mwindow->edl->local_session->green_max = 0;
2286 mwindow->edl->local_session->blue_max = 0;
2287 for(int i = row1; i < row2; i++)
2289 for(int j = column1; j < column2; j++)
2291 switch(refresh_frame->get_color_model())
2294 GET_COLOR(unsigned char, 3, 0xff, 1);
2297 GET_COLOR(unsigned char, 4, 0xff, 1);
2300 GET_COLOR(uint16_t, 3, 0xffff, 1);
2302 case BC_YUVA16161616:
2303 GET_COLOR(uint16_t, 4, 0xffff, 1);
2306 GET_COLOR(unsigned char, 3, 0xff, 0);
2309 GET_COLOR(unsigned char, 4, 0xff, 0);
2312 GET_COLOR(float, 3, 1.0, 0);
2315 GET_COLOR(float, 4, 1.0, 0);
2321 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2322 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2323 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2328 mwindow->edl->local_session->red = 0;
2329 mwindow->edl->local_session->green = 0;
2330 mwindow->edl->local_session->blue = 0;
2331 gui->eyedrop_visible = 0;
2340 // Can't rerender since the color value is from the output of any effect it
2343 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2349 int CWindowCanvas::need_overlays()
2351 if( mwindow->edl->session->safe_regions ) return 1;
2352 if( mwindow->edl->session->cwindow_scrollbars ) return 1;
2353 if( gui->highlighted ) return 1;
2354 switch( mwindow->edl->session->cwindow_operation ) {
2355 case CWINDOW_EYEDROP:
2356 if( ! gui->eyedrop_visible ) break;
2357 case CWINDOW_CAMERA:
2358 case CWINDOW_PROJECTOR:
2367 void CWindowCanvas::draw_overlays()
2369 if(mwindow->edl->session->safe_regions)
2371 draw_safe_regions();
2374 if(mwindow->edl->session->cwindow_scrollbars)
2376 // Always draw output rectangle
2377 float x1, y1, x2, y2;
2379 x2 = mwindow->edl->session->output_w;
2381 y2 = mwindow->edl->session->output_h;
2382 output_to_canvas(mwindow->edl, 0, x1, y1);
2383 output_to_canvas(mwindow->edl, 0, x2, y2);
2385 get_canvas()->set_inverse();
2386 get_canvas()->set_color(WHITE);
2388 get_canvas()->draw_rectangle((int)x1,
2393 get_canvas()->set_opaque();
2396 if(gui->highlighted)
2398 get_canvas()->set_color(WHITE);
2399 get_canvas()->set_inverse();
2400 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2401 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2402 get_canvas()->set_opaque();
2405 int temp1 = 0, temp2 = 0;
2406 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2407 switch(mwindow->edl->session->cwindow_operation)
2409 case CWINDOW_CAMERA:
2413 case CWINDOW_PROJECTOR:
2422 do_mask(temp1, temp2, 0, 0, 1);
2426 do_ruler(1, 0, 0, 0);
2429 case CWINDOW_EYEDROP:
2430 if(gui->eyedrop_visible)
2433 do_eyedrop(rerender, 0, 1);
2434 gui->eyedrop_visible = 1;
2440 void CWindowCanvas::draw_safe_regions()
2442 float action_x1, action_x2, action_y1, action_y2;
2443 float title_x1, title_x2, title_y1, title_y2;
2445 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2446 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2447 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2448 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2449 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2450 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2451 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2452 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2454 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2455 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2456 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2457 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2459 get_canvas()->set_inverse();
2460 get_canvas()->set_color(WHITE);
2462 get_canvas()->draw_rectangle((int)action_x1,
2464 (int)(action_x2 - action_x1),
2465 (int)(action_y2 - action_y1));
2466 get_canvas()->draw_rectangle((int)title_x1,
2468 (int)(title_x2 - title_x1),
2469 (int)(title_y2 - title_y1));
2471 get_canvas()->set_opaque();
2474 void CWindowCanvas::reset_keyframe(int do_camera)
2476 FloatAuto *x_keyframe = 0;
2477 FloatAuto *y_keyframe = 0;
2478 FloatAuto *z_keyframe = 0;
2479 Track *affected_track = 0;
2481 affected_track = gui->cwindow->calculate_affected_track();
2485 gui->cwindow->calculate_affected_autos(&x_keyframe,
2494 x_keyframe->set_value(0);
2495 y_keyframe->set_value(0);
2496 z_keyframe->set_value(1);
2498 mwindow->sync_parameters(CHANGE_PARAMS);
2503 void CWindowCanvas::reset_camera()
2508 void CWindowCanvas::reset_projector()
2513 int CWindowCanvas::test_crop(int button_press, int &redraw)
2516 int handle_selected = -1;
2517 float x1 = mwindow->edl->session->crop_x1;
2518 float y1 = mwindow->edl->session->crop_y1;
2519 float x2 = mwindow->edl->session->crop_x2;
2520 float y2 = mwindow->edl->session->crop_y2;
2521 float cursor_x = get_cursor_x();
2522 float cursor_y = get_cursor_y();
2523 float canvas_x1 = x1;
2524 float canvas_y1 = y1;
2525 float canvas_x2 = x2;
2526 float canvas_y2 = y2;
2527 float canvas_cursor_x = cursor_x;
2528 float canvas_cursor_y = cursor_y;
2530 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2531 // Use screen normalized coordinates for hot spot tests.
2532 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2533 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2536 if(gui->current_operation == CWINDOW_CROP)
2538 handle_selected = gui->crop_handle;
2541 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2542 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2544 handle_selected = 0;
2545 gui->crop_origin_x = x1;
2546 gui->crop_origin_y = y1;
2549 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2550 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2552 handle_selected = 1;
2553 gui->crop_origin_x = x2;
2554 gui->crop_origin_y = y1;
2557 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2558 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2560 handle_selected = 2;
2561 gui->crop_origin_x = x1;
2562 gui->crop_origin_y = y2;
2565 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2566 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2568 handle_selected = 3;
2569 gui->crop_origin_x = x2;
2570 gui->crop_origin_y = y2;
2575 gui->crop_origin_x = cursor_x;
2576 gui->crop_origin_y = cursor_y;
2579 // printf("test crop %d %d\n",
2580 // gui->current_operation,
2581 // handle_selected);
2588 gui->crop_translate = 1;
2589 gui->crop_origin_x1 = x1;
2590 gui->crop_origin_y1 = y1;
2591 gui->crop_origin_x2 = x2;
2592 gui->crop_origin_y2 = y2;
2595 gui->crop_translate = 0;
2597 gui->current_operation = CWINDOW_CROP;
2598 gui->crop_handle = handle_selected;
2599 gui->x_origin = cursor_x;
2600 gui->y_origin = cursor_y;
2601 gui->tool_panel->raise_window();
2604 if(handle_selected < 0 && !gui->crop_translate)
2608 mwindow->edl->session->crop_x1 = (int)x1;
2609 mwindow->edl->session->crop_y1 = (int)y1;
2610 mwindow->edl->session->crop_x2 = (int)x2;
2611 mwindow->edl->session->crop_y2 = (int)y2;
2616 // Translate all 4 points
2617 if(gui->current_operation == CWINDOW_CROP && gui->crop_translate)
2619 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2620 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2621 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2622 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2624 mwindow->edl->session->crop_x1 = (int)x1;
2625 mwindow->edl->session->crop_y1 = (int)y1;
2626 mwindow->edl->session->crop_x2 = (int)x2;
2627 mwindow->edl->session->crop_y2 = (int)y2;
2633 if(gui->current_operation == CWINDOW_CROP)
2635 switch(gui->crop_handle)
2638 x1 = gui->crop_origin_x;
2639 y1 = gui->crop_origin_y;
2640 x2 = gui->crop_origin_x;
2641 y2 = gui->crop_origin_y;
2642 if(cursor_x < gui->x_origin)
2644 if(cursor_y < gui->y_origin)
2650 if(cursor_y >= gui->y_origin)
2657 if(cursor_x >= gui->x_origin)
2659 if(cursor_y < gui->y_origin)
2665 if(cursor_y >= gui->y_origin)
2672 // printf("test crop %d %d %d %d\n",
2673 // mwindow->edl->session->crop_x1,
2674 // mwindow->edl->session->crop_y1,
2675 // mwindow->edl->session->crop_x2,
2676 // mwindow->edl->session->crop_y2);
2679 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2680 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2683 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2684 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2687 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2688 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2691 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2692 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2696 if(!EQUIV(mwindow->edl->session->crop_x1, x1) ||
2697 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2698 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2699 !EQUIV(mwindow->edl->session->crop_y2, y2))
2706 switch (gui->crop_handle)
2708 case 0: gui->crop_handle = 1; break;
2709 case 1: gui->crop_handle = 0; break;
2710 case 2: gui->crop_handle = 3; break;
2711 case 3: gui->crop_handle = 2; break;
2721 switch (gui->crop_handle)
2723 case 0: gui->crop_handle = 2; break;
2724 case 1: gui->crop_handle = 3; break;
2725 case 2: gui->crop_handle = 0; break;
2726 case 3: gui->crop_handle = 1; break;
2731 mwindow->edl->session->crop_x1 = (int)x1;
2732 mwindow->edl->session->crop_y1 = (int)y1;
2733 mwindow->edl->session->crop_x2 = (int)x2;
2734 mwindow->edl->session->crop_y2 = (int)y2;
2740 // Update cursor font
2741 if(handle_selected >= 0)
2743 switch(handle_selected)
2746 set_cursor(UPLEFT_RESIZE);
2749 set_cursor(UPRIGHT_RESIZE);
2752 set_cursor(DOWNLEFT_RESIZE);
2755 set_cursor(DOWNRIGHT_RESIZE);
2762 set_cursor(ARROW_CURSOR);
2764 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2768 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2769 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2770 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2771 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2772 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2773 // mwindow->edl->session->crop_x2,
2774 // mwindow->edl->session->crop_y2,
2775 // mwindow->edl->calculate_output_w(0),
2776 // mwindow->edl->calculate_output_h(0));
2782 void CWindowCanvas::draw_crop()
2784 get_canvas()->set_inverse();
2785 get_canvas()->set_color(WHITE);
2787 float x1 = mwindow->edl->session->crop_x1;
2788 float y1 = mwindow->edl->session->crop_y1;
2789 float x2 = mwindow->edl->session->crop_x2;
2790 float y2 = mwindow->edl->session->crop_y2;
2792 output_to_canvas(mwindow->edl, 0, x1, y1);
2793 output_to_canvas(mwindow->edl, 0, x2, y2);
2795 if(x2 - x1 && y2 - y1)
2796 get_canvas()->draw_rectangle((int)x1,
2801 draw_crophandle((int)x1, (int)y1);
2802 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2803 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2804 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2805 get_canvas()->set_opaque();
2815 void CWindowCanvas::draw_bezier(int do_camera)
2817 Track *track = gui->cwindow->calculate_affected_track();
2824 int64_t position = track->to_units(
2825 mwindow->edl->local_session->get_selectionstart(1),
2828 track->automation->get_projector(¢er_x,
2834 // center_x += track->track_w / 2;
2835 // center_y += track->track_h / 2;
2836 center_x += mwindow->edl->session->output_w / 2;
2837 center_y += mwindow->edl->session->output_h / 2;
2838 float track_x1 = center_x - track->track_w / 2 * center_z;
2839 float track_y1 = center_y - track->track_h / 2 * center_z;
2840 float track_x2 = track_x1 + track->track_w * center_z;
2841 float track_y2 = track_y1 + track->track_h * center_z;
2843 output_to_canvas(mwindow->edl, 0, track_x1, track_y1);
2844 output_to_canvas(mwindow->edl, 0, track_x2, track_y2);
2846 #define DRAW_PROJECTION(offset) \
2847 get_canvas()->draw_rectangle((int)track_x1 + offset, \
2848 (int)track_y1 + offset, \
2849 (int)(track_x2 - track_x1), \
2850 (int)(track_y2 - track_y1)); \
2851 get_canvas()->draw_line((int)track_x1 + offset, \
2852 (int)track_y1 + offset, \
2853 (int)track_x2 + offset, \
2854 (int)track_y2 + offset); \
2855 get_canvas()->draw_line((int)track_x2 + offset, \
2856 (int)track_y1 + offset, \
2857 (int)track_x1 + offset, \
2858 (int)track_y2 + offset); \
2862 get_canvas()->set_color(BLACK);
2865 // canvas->set_inverse();
2867 get_canvas()->set_color(GREEN);
2869 get_canvas()->set_color(RED);
2872 // canvas->set_opaque();
2876 int CWindowCanvas::test_bezier(int button_press,
2884 // Processing drag operation.
2885 // Create keyframe during first cursor motion.
2889 float cursor_x = get_cursor_x();
2890 float cursor_y = get_cursor_y();
2891 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2893 if(gui->current_operation == CWINDOW_CAMERA ||
2894 gui->current_operation == CWINDOW_PROJECTOR)
2896 if(!gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom)
2898 gui->translating_zoom = 1;
2899 gui->reset_affected();
2902 if(!gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom)
2904 gui->translating_zoom = 0;
2905 gui->reset_affected();
2908 // Get target keyframe
2909 float last_center_x;
2910 float last_center_y;
2911 float last_center_z;
2914 if(!gui->affected_x && !gui->affected_y && !gui->affected_z)
2916 FloatAutos *affected_x_autos;
2917 FloatAutos *affected_y_autos;
2918 FloatAutos *affected_z_autos;
2919 if(!gui->affected_track) return 0;
2920 double position = mwindow->edl->local_session->get_selectionstart(1);
2921 int64_t track_position = gui->affected_track->to_units(position, 0);
2923 if(mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA)
2925 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_X];
2926 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Y];
2927 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Z];
2931 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_X];
2932 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Y];
2933 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Z];
2937 if(gui->translating_zoom)
2939 FloatAuto *previous = 0;
2940 FloatAuto *next = 0;
2941 float new_z = affected_z_autos->get_value(
2947 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2948 affected_z_autos, 1, &created, 0);
2950 gui->affected_z->set_value(new_z);
2956 FloatAuto *previous = 0;
2957 FloatAuto *next = 0;
2958 float new_x = affected_x_autos->get_value(
2965 float new_y = affected_y_autos->get_value(
2971 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2972 affected_x_autos, 1, &created, 0);
2974 gui->affected_x->set_value(new_x);
2978 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2979 affected_y_autos, 1, &created, 0);
2981 gui->affected_y->set_value(new_y);
2988 if(gui->translating_zoom)
2990 gui->center_z = gui->affected_z->get_value();
2994 gui->center_x = gui->affected_x->get_value();
2995 gui->center_y = gui->affected_y->get_value();
3002 if(gui->translating_zoom)
3004 last_center_z = gui->affected_z->get_value();
3005 float z = gui->center_z + (cursor_y - gui->y_origin) / 128;
3007 if(!EQUIV(last_center_z, z))
3013 gui->affected_z->set_value(z);
3017 last_center_x = gui->affected_x->get_value();
3018 last_center_y = gui->affected_y->get_value();
3019 float dx = cursor_x - gui->x_origin;
3020 float dy = cursor_y - gui->y_origin;
3021 if(gui->current_operation == CWINDOW_CAMERA ) {
3024 float x = gui->center_x + dx;
3025 float y = gui->center_y + dy;
3026 gui->affected_x->set_value(x);
3027 gui->affected_y->set_value(y);
3028 if( !EQUIV(last_center_x, x) || !EQUIV(last_center_y, y) )
3034 gui->affected_x->set_value(x);
3035 gui->affected_y->set_value(y);
3042 // Begin drag operation. Don't create keyframe here.
3044 // Get affected track off of the first recordable video track.
3045 // Calculating based on the alpha channel would require recording what layer
3046 // each output pixel belongs to as they're rendered and stacked. Forget it.
3047 gui->affected_track = gui->cwindow->calculate_affected_track();
3048 gui->reset_affected();
3050 if(gui->affected_track)
3052 if(gui->current_operation == CWINDOW_CAMERA)
3053 mwindow->undo->update_undo_before(_("camera"), this);
3055 mwindow->undo->update_undo_before(_("projector"), this);
3057 gui->current_operation =
3058 mwindow->edl->session->cwindow_operation;
3059 gui->tool_panel->raise_window();
3068 int CWindowCanvas::test_zoom(int &redraw)
3074 if( mwindow->edl->session->cwindow_scrollbars ) {
3075 if( *gui->zoom_panel->get_text() != 'x' ) {
3076 // Find current zoom in table
3077 int idx = total_zooms; float old_zoom = get_zoom();
3078 while( --idx >= 0 && !EQUIV(my_zoom_table[idx], old_zoom) );
3080 idx += get_buttonpress() == 5 ||
3081 gui->ctrl_down() || gui->shift_down() ? -1 : +1 ;
3082 CLAMP(idx, 0, total_zooms-1);
3083 zoom = my_zoom_table[idx];
3086 x = get_cursor_x(); y = get_cursor_y();
3088 mwindow->edl->session->cwindow_scrollbars = 0;
3089 gui->zoom_panel->update(0);
3090 zoom = gui->get_auto_zoom();
3093 gui->zoom_panel->ZoomPanel::update(zoom);
3094 float output_x = x, output_y = y;
3095 canvas_to_output(mwindow->edl, 0, output_x, output_y);
3096 x = output_x - x / zoom;
3097 y = output_y - y / zoom;
3101 mwindow->edl->session->cwindow_scrollbars = 1;
3102 x = (mwindow->edl->session->output_w - w) / 2;
3103 y = (mwindow->edl->session->output_h - h) / 2;
3106 update_zoom((int)x, (int)y, zoom);
3108 gui->composite_panel->cpanel_zoom->update(zoom);
3110 reposition_window(mwindow->edl,
3111 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
3112 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
3113 redraw = 1; result = 1;
3119 void CWindowCanvas::calculate_origin()
3121 gui->x_origin = get_cursor_x();
3122 gui->y_origin = get_cursor_y();
3123 //printf("CWindowCanvas::calculate_origin 1 %f %f\n", gui->x_origin, gui->y_origin);
3124 canvas_to_output(mwindow->edl, 0, gui->x_origin, gui->y_origin);
3125 //printf("CWindowCanvas::calculate_origin 2 %f %f\n", gui->x_origin, gui->y_origin);
3129 int CWindowCanvas::cursor_leave_event()
3131 set_cursor(ARROW_CURSOR);
3135 int CWindowCanvas::cursor_enter_event()
3138 switch(mwindow->edl->session->cwindow_operation)
3140 case CWINDOW_CAMERA:
3141 case CWINDOW_PROJECTOR:
3142 set_cursor(MOVE_CURSOR);
3145 set_cursor(MOVE_CURSOR);
3148 test_crop(0, redraw);
3150 case CWINDOW_PROTECT:
3151 set_cursor(ARROW_CURSOR);
3155 set_cursor(CROSS_CURSOR);
3157 case CWINDOW_EYEDROP:
3158 set_cursor(CROSS_CURSOR);
3164 int CWindowCanvas::cursor_motion_event()
3166 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3169 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3170 switch(gui->current_operation)
3172 case CWINDOW_SCROLL:
3174 float zoom = get_zoom();
3175 float cursor_x = get_cursor_x();
3176 float cursor_y = get_cursor_y();
3178 float zoom_x, zoom_y, conformed_w, conformed_h;
3179 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3180 cursor_x = (float)cursor_x / zoom_x + gui->x_offset;
3181 cursor_y = (float)cursor_y / zoom_y + gui->y_offset;
3185 int x = (int)(gui->x_origin - cursor_x + gui->x_offset);
3186 int y = (int)(gui->y_origin - cursor_y + gui->y_offset);
3191 update_scrollbars(0);
3198 result = do_ruler(0, 1, 0, 0);
3201 case CWINDOW_CAMERA:
3202 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3205 case CWINDOW_PROJECTOR:
3206 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3211 result = test_crop(0, redraw);
3212 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3219 case CWINDOW_MASK_CONTROL_IN:
3220 case CWINDOW_MASK_CONTROL_OUT:
3221 case CWINDOW_MASK_TRANSLATE:
3223 result = do_mask(redraw,
3230 case CWINDOW_EYEDROP:
3231 result = do_eyedrop(rerender, 0, 0);
3240 // cursor font changes
3243 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3245 // mwindow->edl->session->cwindow_operation);
3246 switch(mwindow->edl->session->cwindow_operation)
3249 result = test_crop(0, redraw);
3252 result = do_ruler(0, 1, 0, 0);
3255 result = do_mask(redraw,
3265 // If the window is never unlocked before calling send_command the
3266 // display shouldn't get stuck on the old video frame although it will
3267 // flicker between the old video frame and the new video frame.
3277 gui->unlock_window();
3280 mwindow->gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3281 mwindow->gui->draw_overlays(1);
3282 mwindow->gui->unlock_window();
3284 gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3289 gui->unlock_window();
3290 mwindow->restart_brender();
3291 mwindow->sync_parameters(CHANGE_PARAMS);
3292 mwindow->cwindow->refresh_frame(CHANGE_NONE);
3293 if(!redraw) gui->update_tool();
3294 gui->lock_window("CWindowCanvas::cursor_motion_event 2");
3299 int CWindowCanvas::button_press_event()
3303 int redraw_canvas = 0;
3306 if(Canvas::button_press_event()) return 1;
3308 gui->translating_zoom = gui->shift_down();
3311 //printf("CWindowCanvas::button_press_event 2 %f %f\n", gui->x_origin, gui->y_origin, gui->x_origin, gui->y_origin);
3313 float zoom_x, zoom_y, conformed_w, conformed_h;
3314 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3315 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3316 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3319 if( mwindow->edl->session->cwindow_operation != CWINDOW_PROTECT &&
3320 get_buttonpress() == 2 )
3322 gui->current_operation = CWINDOW_SCROLL;
3328 switch(mwindow->edl->session->cwindow_operation)
3331 result = do_ruler(0, 0, 1, 0);
3334 case CWINDOW_CAMERA:
3335 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3338 case CWINDOW_PROJECTOR:
3339 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3343 result = test_zoom(redraw);
3347 result = test_crop(1, redraw);
3351 if(get_buttonpress() == 1)
3352 result = do_mask(redraw, rerender, 1, 0, 0);
3355 case CWINDOW_EYEDROP:
3356 result = do_eyedrop(rerender, 1, 0);
3364 gui->unlock_window();
3367 mwindow->gui->lock_window("CWindowCanvas::button_press_event 1");
3368 mwindow->gui->draw_overlays(1);
3369 mwindow->gui->unlock_window();
3372 gui->lock_window("CWindowCanvas::button_press_event 1");
3375 // rerendering can also be caused by press event
3378 gui->unlock_window();
3380 mwindow->restart_brender();
3381 mwindow->sync_parameters(CHANGE_PARAMS);
3382 mwindow->cwindow->refresh_frame(CHANGE_NONE);
3383 if(!redraw) gui->update_tool();
3384 gui->lock_window("CWindowCanvas::button_press_event 2");
3389 int CWindowCanvas::button_release_event()
3393 switch(gui->current_operation)
3395 case CWINDOW_SCROLL:
3400 do_ruler(0, 0, 0, 1);
3403 case CWINDOW_CAMERA:
3404 mwindow->undo->update_undo_after(_("camera"), LOAD_AUTOMATION);
3407 case CWINDOW_PROJECTOR:
3408 mwindow->undo->update_undo_after(_("projector"), LOAD_AUTOMATION);
3412 case CWINDOW_MASK_CONTROL_IN:
3413 case CWINDOW_MASK_CONTROL_OUT:
3414 case CWINDOW_MASK_TRANSLATE:
3415 // Finish mask operation
3416 gui->mask_keyframe = 0;
3417 mwindow->undo->update_undo_after(_("mask"), LOAD_AUTOMATION);
3420 result = Canvas::button_release_event();
3424 gui->current_operation = CWINDOW_NONE;
3428 void CWindowCanvas::zoom_resize_window(float percentage)
3430 int canvas_w, canvas_h;
3434 // Get required canvas size
3435 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3436 mwindow->edl->session->output_w,
3437 mwindow->edl->session->output_h,
3442 // Estimate window size from current borders
3443 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3444 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3446 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3447 mwindow->session->cwindow_w = new_w;
3448 mwindow->session->cwindow_h = new_h;
3450 mwindow->theme->get_cwindow_sizes(gui,
3451 mwindow->session->cwindow_controls);
3453 // Estimate again from new borders
3454 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3455 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3456 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3458 gui->resize_window(new_w, new_h);
3459 gui->resize_event(new_w, new_h);
3462 void CWindowCanvas::toggle_controls()
3464 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3465 gui->resize_event(gui->get_w(), gui->get_h());
3468 int CWindowCanvas::get_cwindow_controls()
3470 return mwindow->session->cwindow_controls;