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");
492 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
494 mwindow->gui->unlock_window();
495 lock_window("CWindowGUI::keypress_event 2");
499 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
500 mwindow->clear_entry();
501 mwindow->gui->unlock_window();
502 lock_window("CWindowGUI::keypress_event 3");
506 if(mwindow->session->cwindow_fullscreen)
507 canvas->stop_fullscreen();
508 lock_window("CWindowGUI::keypress_event 4");
512 int alt_down = this->alt_down();
513 int shift_down = this->shift_down();
516 mwindow->gui->lock_window("CWindowGUI::keypress_event 5");
518 mwindow->prev_edit_handle(shift_down);
520 mwindow->move_left();
521 mwindow->gui->unlock_window();
522 lock_window("CWindowGUI::keypress_event 6");
528 if( !ctrl_down() && !alt_down() ) {
531 mwindow->gui->lock_window("CWindowGUI::keypress_event 7");
532 mwindow->move_left();
533 mwindow->gui->unlock_window();
534 lock_window("CWindowGUI::keypress_event 8");
541 int alt_down = this->alt_down();
542 int shift_down = this->shift_down();
545 mwindow->gui->lock_window("CWindowGUI::keypress_event 8");
547 mwindow->next_edit_handle(shift_down);
549 mwindow->move_right();
550 mwindow->gui->unlock_window();
551 lock_window("CWindowGUI::keypress_event 9");
557 if( !ctrl_down() && !alt_down() ) {
560 mwindow->gui->lock_window("CWindowGUI::keypress_event 10");
561 mwindow->move_right();
562 mwindow->gui->unlock_window();
563 lock_window("CWindowGUI::keypress_event 11");
568 case KEY_F1: cwindow_operation = CWINDOW_PROTECT; break;
569 case KEY_F2: cwindow_operation = CWINDOW_ZOOM; break;
570 case KEY_F3: cwindow_operation = CWINDOW_MASK; break;
571 case KEY_F4: cwindow_operation = CWINDOW_RULER; break;
572 case KEY_F5: cwindow_operation = CWINDOW_CAMERA; break;
573 case KEY_F6: cwindow_operation = CWINDOW_PROJECTOR; break;
574 case KEY_F7: cwindow_operation = CWINDOW_CROP; break;
575 case KEY_F8: cwindow_operation = CWINDOW_EYEDROP; break;
576 case KEY_F9: cwindow_operation = CWINDOW_TOOL_WINDOW; break;
577 case KEY_F10: cwindow_operation = CWINDOW_TITLESAFE; break;
578 case KEY_F11: canvas->reset_camera(); break;
579 case KEY_F12: canvas->reset_projector(); break;
582 if( cwindow_operation >= 0 ) {
583 set_operation(cwindow_operation);
587 if(!result) result = transport->keypress_event();
593 void CWindowGUI::reset_affected()
600 void CWindowGUI::keyboard_zoomin()
602 // if(mwindow->edl->session->cwindow_scrollbars)
604 zoom_panel->zoom_tumbler->handle_up_event();
611 void CWindowGUI::keyboard_zoomout()
613 // if(mwindow->edl->session->cwindow_scrollbars)
615 zoom_panel->zoom_tumbler->handle_down_event();
623 void CWindowGUI::drag_motion()
625 if(get_hidden()) return;
627 if(mwindow->session->current_operation != DRAG_ASSET &&
628 mwindow->session->current_operation != DRAG_VTRANSITION &&
629 mwindow->session->current_operation != DRAG_VEFFECT) return;
630 int need_highlight = cursor_above() && get_cursor_over_window();
631 if( highlighted == need_highlight ) return;
632 highlighted = need_highlight;
633 canvas->draw_refresh();
636 int CWindowGUI::drag_stop()
639 if(get_hidden()) return 0;
640 if( !highlighted ) return 0;
641 if( mwindow->session->current_operation != DRAG_ASSET &&
642 mwindow->session->current_operation != DRAG_VTRANSITION &&
643 mwindow->session->current_operation != DRAG_VEFFECT) return 0;
645 canvas->draw_refresh();
648 if(mwindow->session->current_operation == DRAG_ASSET)
650 if(mwindow->session->drag_assets->total ||
651 mwindow->session->drag_clips->total)
653 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
654 mwindow->undo->update_undo_before(_("insert assets"), 0);
657 if(mwindow->session->drag_assets->total)
660 mwindow->load_assets(mwindow->session->drag_assets,
661 mwindow->edl->local_session->get_selectionstart(),
663 mwindow->session->track_highlighted,
665 mwindow->edl->session->labels_follow_edits,
666 mwindow->edl->session->plugins_follow_edits,
667 mwindow->edl->session->autos_follow_edits,
671 if(mwindow->session->drag_clips->total)
674 mwindow->paste_edls(mwindow->session->drag_clips,
676 mwindow->session->track_highlighted,
677 mwindow->edl->local_session->get_selectionstart(),
678 mwindow->edl->session->labels_follow_edits,
679 mwindow->edl->session->plugins_follow_edits,
680 mwindow->edl->session->autos_follow_edits,
684 if(mwindow->session->drag_assets->total ||
685 mwindow->session->drag_clips->total)
687 mwindow->save_backup();
688 mwindow->restart_brender();
689 mwindow->gui->update(1, 1, 1, 1, 0, 1, 0);
690 mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
691 mwindow->gui->unlock_window();
692 mwindow->sync_parameters(CHANGE_ALL);
696 if(mwindow->session->current_operation == DRAG_VEFFECT)
698 //printf("CWindowGUI::drag_stop 1\n");
699 Track *affected_track = cwindow->calculate_affected_track();
700 //printf("CWindowGUI::drag_stop 2\n");
702 mwindow->gui->lock_window("CWindowGUI::drag_stop 3");
703 mwindow->insert_effects_cwindow(affected_track);
704 mwindow->session->current_operation = NO_OPERATION;
705 mwindow->gui->unlock_window();
708 if(mwindow->session->current_operation == DRAG_VTRANSITION)
710 Track *affected_track = cwindow->calculate_affected_track();
711 mwindow->gui->lock_window("CWindowGUI::drag_stop 4");
712 mwindow->paste_transition_cwindow(affected_track);
713 mwindow->session->current_operation = NO_OPERATION;
714 mwindow->gui->unlock_window();
720 void CWindowGUI::update_meters()
722 if(mwindow->edl->session->cwindow_meter != meters->visible)
724 meters->set_meters(meters->meter_count, mwindow->edl->session->cwindow_meter);
725 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
726 resize_event(get_w(), get_h());
730 void CWindowGUI::stop_transport(const char *lock_msg)
732 if( lock_msg ) unlock_window();
733 mwindow->stop_transport();
734 if( lock_msg ) lock_window(lock_msg);
738 CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
739 : EditPanel(mwindow, cwindow->gui, CWINDOW_ID,
740 mwindow->theme->cedit_x, mwindow->theme->cedit_y,
741 mwindow->edl->session->editing_mode,
742 0, // use_editing_mode
761 this->mwindow = mwindow;
762 this->cwindow = cwindow;
765 #define CWrapper(fn) void CWindowEditing::fn() { \
766 mwindow->gui->lock_window("CWrapper::" #fn); \
768 mwindow->gui->unlock_window(); \
771 CWrapper(copy_selection)
772 CWrapper(splice_selection)
773 CWrapper(overwrite_selection)
774 CWrapper(set_inpoint)
775 CWrapper(set_outpoint)
776 CWrapper(unset_inoutpoint)
777 CWrapper(toggle_label)
779 #define CWrapper_cut(fn) void CWindowEditing::fn(int cut) { \
780 mwindow->gui->lock_window("CWrapper::" #fn); \
781 EditPanel::fn(cut); \
782 mwindow->gui->unlock_window(); \
784 CWrapper_cut(prev_label)
785 CWrapper_cut(next_label)
786 CWrapper_cut(prev_edit)
787 CWrapper_cut(next_edit)
789 void CWindowEditing::to_clip()
791 mwindow->to_clip(mwindow->edl, _("composer window: "), 0);
795 CWindowMeters::CWindowMeters(MWindow *mwindow,
800 : MeterPanel(mwindow,
806 mwindow->edl->session->audio_channels,
807 mwindow->edl->session->cwindow_meter,
811 this->mwindow = mwindow;
815 CWindowMeters::~CWindowMeters()
819 int CWindowMeters::change_status_event(int new_status)
821 mwindow->edl->session->cwindow_meter = new_status;
822 gui->update_meters();
829 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
830 : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
831 x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
833 this->mwindow = mwindow;
837 CWindowZoom::~CWindowZoom()
841 void CWindowZoom::update(double value)
843 char string[BCSTRLEN];
844 const char *cp = string;
847 int frac = value >= 1.0f ? 1 :
849 value >= .01f ? 3 : 4;
850 sprintf(string, "x %.*f", frac, value);
854 ZoomPanel::update(cp);
857 int CWindowZoom::handle_event()
859 double value = !strcasecmp(gui->auto_zoom, get_text()) ? 0 : get_value();
860 gui->zoom_canvas(value, 0);
867 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
868 : BC_PercentageSlider(x,
877 this->mwindow = mwindow;
878 this->cwindow = cwindow;
879 set_precision(0.00001);
882 CWindowSlider::~CWindowSlider()
886 int CWindowSlider::handle_event()
888 cwindow->update_position((double)get_value());
892 void CWindowSlider::set_position()
894 double new_length = mwindow->edl->tracks->total_length();
895 update(mwindow->theme->cslider_w,
896 mwindow->edl->local_session->get_selectionstart(1),
901 int CWindowSlider::increase_value()
904 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
905 lock_window("CWindowSlider::increase_value");
909 int CWindowSlider::decrease_value()
912 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
913 lock_window("CWindowSlider::decrease_value");
918 // CWindowDestination::CWindowDestination(MWindow *mwindow, CWindowGUI *cwindow, int x, int y)
919 // : BC_PopupTextBox(cwindow,
920 // &cwindow->destinations,
921 // cwindow->destinations.values[cwindow->cwindow->destination]->get_text(),
927 // this->mwindow = mwindow;
928 // this->cwindow = cwindow;
931 // CWindowDestination::~CWindowDestination()
935 // int CWindowDestination::handle_event()
946 CWindowTransport::CWindowTransport(MWindow *mwindow,
950 : PlayTransport(mwindow,
958 EDL* CWindowTransport::get_edl()
963 void CWindowTransport::goto_start()
965 gui->unlock_window();
966 handle_transport(REWIND, 1);
968 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
969 mwindow->goto_start();
970 mwindow->gui->unlock_window();
972 gui->lock_window("CWindowTransport::goto_start 2");
975 void CWindowTransport::goto_end()
977 gui->unlock_window();
978 handle_transport(GOTO_END, 1);
980 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
982 mwindow->gui->unlock_window();
984 gui->lock_window("CWindowTransport::goto_end 2");
989 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
992 mwindow->theme->ccanvas_x,
993 mwindow->theme->ccanvas_y,
994 mwindow->theme->ccanvas_w,
995 mwindow->theme->ccanvas_h,
998 mwindow->edl->session->cwindow_scrollbars)
1000 this->mwindow = mwindow;
1004 void CWindowCanvas::status_event()
1006 gui->draw_status(1);
1009 int CWindowCanvas::get_fullscreen()
1011 return mwindow->session->cwindow_fullscreen;
1014 void CWindowCanvas::set_fullscreen(int value)
1016 mwindow->session->cwindow_fullscreen = value;
1020 void CWindowCanvas::update_zoom(int x, int y, float zoom)
1022 use_scrollbars = mwindow->edl->session->cwindow_scrollbars;
1024 mwindow->edl->session->cwindow_xscroll = x;
1025 mwindow->edl->session->cwindow_yscroll = y;
1026 mwindow->edl->session->cwindow_zoom = zoom;
1029 void CWindowCanvas::zoom_auto()
1031 gui->zoom_canvas(0, 1);
1034 int CWindowCanvas::get_xscroll()
1036 return mwindow->edl->session->cwindow_xscroll;
1039 int CWindowCanvas::get_yscroll()
1041 return mwindow->edl->session->cwindow_yscroll;
1045 float CWindowCanvas::get_zoom()
1047 return mwindow->edl->session->cwindow_zoom;
1050 void CWindowCanvas::draw_refresh(int flush)
1052 if(get_canvas() && !get_canvas()->get_video_on())
1055 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
1057 float in_x1, in_y1, in_x2, in_y2;
1058 float out_x1, out_y1, out_x2, out_y2;
1059 get_transfers(mwindow->edl,
1069 if(!EQUIV(out_x1, 0) ||
1070 !EQUIV(out_y1, 0) ||
1071 !EQUIV(out_x2, get_canvas()->get_w()) ||
1072 !EQUIV(out_y2, get_canvas()->get_h()))
1074 get_canvas()->clear_box(0,
1076 get_canvas()->get_w(),
1077 get_canvas()->get_h());
1080 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1081 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1084 if(out_x2 > out_x1 &&
1089 // input scaled from session to refresh frame coordinates
1090 int ow = get_output_w(mwindow->edl);
1091 int oh = get_output_h(mwindow->edl);
1092 int rw = refresh_frame->get_w();
1093 int rh = refresh_frame->get_h();
1094 float xs = (float)rw / ow;
1095 float ys = (float)rh / oh;
1096 in_x1 *= xs; in_x2 *= xs;
1097 in_y1 *= ys; in_y2 *= ys;
1098 // Can't use OpenGL here because it is called asynchronously of the
1099 // playback operation.
1100 get_canvas()->draw_vframe(refresh_frame,
1103 (int)(out_x2 - out_x1),
1104 (int)(out_y2 - out_y1),
1107 (int)(in_x2 - in_x1),
1108 (int)(in_y2 - in_y1),
1114 get_canvas()->clear_box(0,
1116 get_canvas()->get_w(),
1117 get_canvas()->get_h());
1121 // allow last opengl write to complete before redraw
1122 // tried sync_display, glFlush, glxMake*Current(0..)
1124 get_canvas()->flash(flush);
1126 //printf("CWindowCanvas::draw_refresh 10\n");
1129 #define CROPHANDLE_W 10
1130 #define CROPHANDLE_H 10
1132 void CWindowCanvas::draw_crophandle(int x, int y)
1134 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1142 #define CONTROL_W 10
1143 #define CONTROL_H 10
1144 #define FIRST_CONTROL_W 20
1145 #define FIRST_CONTROL_H 20
1147 #define BC_INFINITY 65536
1149 #define RULERHANDLE_W 16
1150 #define RULERHANDLE_H 16
1154 int CWindowCanvas::do_ruler(int draw,
1160 float x1 = mwindow->edl->session->ruler_x1;
1161 float y1 = mwindow->edl->session->ruler_y1;
1162 float x2 = mwindow->edl->session->ruler_x2;
1163 float y2 = mwindow->edl->session->ruler_y2;
1164 float canvas_x1 = x1;
1165 float canvas_y1 = y1;
1166 float canvas_x2 = x2;
1167 float canvas_y2 = y2;
1168 float output_x = get_cursor_x();
1169 float output_y = get_cursor_y();
1170 float canvas_cursor_x = output_x;
1171 float canvas_cursor_y = output_y;
1173 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1174 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1175 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1176 mwindow->session->cwindow_output_x = roundf(output_x);
1177 mwindow->session->cwindow_output_y = roundf(output_y);
1179 if(button_press && get_buttonpress() == 1)
1181 gui->ruler_handle = -1;
1182 gui->ruler_translate = 0;
1185 gui->ruler_translate = 1;
1186 gui->ruler_origin_x = x1;
1187 gui->ruler_origin_y = y1;
1190 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1191 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1192 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1193 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1195 gui->ruler_handle = 0;
1196 gui->ruler_origin_x = x1;
1197 gui->ruler_origin_y = y1;
1200 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1201 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1202 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1203 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1205 gui->ruler_handle = 1;
1206 gui->ruler_origin_x = x2;
1207 gui->ruler_origin_y = y2;
1211 // Start new selection
1212 if(!gui->ruler_translate &&
1213 (gui->ruler_handle < 0 ||
1218 do_ruler(1, 0, 0, 0);
1219 get_canvas()->flash();
1220 gui->ruler_handle = 1;
1221 mwindow->edl->session->ruler_x1 = output_x;
1222 mwindow->edl->session->ruler_y1 = output_y;
1223 mwindow->edl->session->ruler_x2 = output_x;
1224 mwindow->edl->session->ruler_y2 = output_y;
1225 gui->ruler_origin_x = mwindow->edl->session->ruler_x2;
1226 gui->ruler_origin_y = mwindow->edl->session->ruler_y2;
1229 gui->x_origin = output_x;
1230 gui->y_origin = output_y;
1231 gui->current_operation = CWINDOW_RULER;
1232 gui->tool_panel->raise_window();
1238 if(gui->current_operation == CWINDOW_RULER)
1240 if(gui->ruler_translate)
1243 do_ruler(1, 0, 0, 0);
1244 float x_difference = mwindow->edl->session->ruler_x1;
1245 float y_difference = mwindow->edl->session->ruler_y1;
1246 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1247 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1248 x_difference -= mwindow->edl->session->ruler_x1;
1249 y_difference -= mwindow->edl->session->ruler_y1;
1250 mwindow->edl->session->ruler_x2 -= x_difference;
1251 mwindow->edl->session->ruler_y2 -= y_difference;
1253 do_ruler(1, 0, 0, 0);
1254 get_canvas()->flash();
1258 switch(gui->ruler_handle)
1261 do_ruler(1, 0, 0, 0);
1262 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1263 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1264 if(gui->alt_down() || gui->ctrl_down())
1266 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1267 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1271 double distance_value =
1272 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1273 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1274 if(angle_value < 22)
1275 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2;
1277 if(angle_value > 67)
1278 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2;
1280 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 &&
1281 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1283 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1284 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1287 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 && mwindow->edl->session->ruler_y1 > mwindow->edl->session->ruler_y2)
1289 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1290 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1293 if(mwindow->edl->session->ruler_x1 > mwindow->edl->session->ruler_x2 &&
1294 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1296 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1297 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1301 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1302 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1305 do_ruler(1, 0, 0, 0);
1306 get_canvas()->flash();
1311 do_ruler(1, 0, 0, 0);
1312 mwindow->edl->session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1313 mwindow->edl->session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1314 if(gui->alt_down() || gui->ctrl_down())
1316 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1317 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1321 double distance_value =
1322 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1323 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1324 if(angle_value < 22)
1325 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1;
1327 if(angle_value > 67)
1328 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1;
1330 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1331 mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1333 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1334 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1337 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1338 mwindow->edl->session->ruler_y2 > mwindow->edl->session->ruler_y1)
1340 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1341 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1344 if(mwindow->edl->session->ruler_x2 > mwindow->edl->session->ruler_x1 && mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1346 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1347 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1351 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1352 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1355 do_ruler(1, 0, 0, 0);
1356 get_canvas()->flash();
1360 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1364 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1369 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1370 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1371 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1372 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1374 set_cursor(UPRIGHT_ARROW_CURSOR);
1377 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1378 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1379 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1380 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1382 set_cursor(UPRIGHT_ARROW_CURSOR);
1385 set_cursor(CROSS_CURSOR);
1387 // Update current position
1392 // Assume no ruler measurement if 0 length
1393 if(draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)))
1395 get_canvas()->set_inverse();
1396 get_canvas()->set_color(WHITE);
1397 get_canvas()->draw_line((int)canvas_x1,
1401 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1403 roundf(canvas_x1) + RULERHANDLE_W / 2,
1405 get_canvas()->draw_line(roundf(canvas_x1),
1406 roundf(canvas_y1) - RULERHANDLE_H / 2,
1408 roundf(canvas_y1) + RULERHANDLE_H / 2);
1409 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1411 roundf(canvas_x2) + RULERHANDLE_W / 2,
1413 get_canvas()->draw_line(roundf(canvas_x2),
1414 roundf(canvas_y2) - RULERHANDLE_H / 2,
1416 roundf(canvas_y2) + RULERHANDLE_H / 2);
1417 get_canvas()->set_opaque();
1424 static inline double line_dist(float cx,float cy, float tx,float ty)
1426 double dx = tx-cx, dy = ty-cy;
1427 return sqrt(dx*dx + dy*dy);
1430 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1432 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1433 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1437 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1438 int button_press, int cursor_motion, int draw)
1440 // Retrieve points from top recordable track
1441 //printf("CWindowCanvas::do_mask 1\n");
1442 Track *track = gui->cwindow->calculate_affected_track();
1443 //printf("CWindowCanvas::do_mask 2\n");
1445 if(!track) return 0;
1446 //printf("CWindowCanvas::do_mask 3\n");
1448 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1449 int64_t position = track->to_units(
1450 mwindow->edl->local_session->get_selectionstart(1),
1452 ArrayList<MaskPoint*> points;
1454 // Determine the points based on whether
1455 // new keyframes will be generated or drawing is performed.
1456 // If keyframe generation occurs, use the interpolated mask.
1457 // If no keyframe generation occurs, use the previous mask.
1458 int use_interpolated = 0;
1459 if(button_press || cursor_motion) {
1460 #ifdef USE_KEYFRAME_SPANNING
1461 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1462 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1465 mask_autos->get_prev_auto(track->to_units(selection_start, 0),
1466 PLAY_FORWARD, first, 1);
1468 mask_autos->get_prev_auto(track->to_units(selection_end, 0),
1469 PLAY_FORWARD, last, 1);
1471 if(last == first && (!mwindow->edl->session->auto_keyframes))
1472 use_interpolated = 0;
1474 // If keyframe spanning occurs, use the interpolated points.
1475 // If new keyframe is generated, use the interpolated points.
1476 use_interpolated = 1;
1479 if(mwindow->edl->session->auto_keyframes)
1480 use_interpolated = 1;
1484 use_interpolated = 1;
1486 if(use_interpolated) {
1487 // Interpolate the points to get exactly what is being rendered at this position.
1488 mask_autos->get_points(&points,
1489 mwindow->edl->session->cwindow_mask,
1494 // Use the prev mask
1496 mask_autos->get_prev_auto(position,
1500 ((MaskAuto*)prev)->get_points(&points,
1501 mwindow->edl->session->cwindow_mask);
1504 // Projector zooms relative to the center of the track output.
1505 float half_track_w = (float)track->track_w / 2;
1506 float half_track_h = (float)track->track_h / 2;
1507 // Translate mask to projection
1508 float projector_x, projector_y, projector_z;
1509 track->automation->get_projector(
1510 &projector_x, &projector_y, &projector_z,
1511 position, PLAY_FORWARD);
1514 // Get position of cursor relative to mask
1515 float cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
1516 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1517 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1519 projector_x += mwindow->edl->session->output_w / 2;
1520 projector_y += mwindow->edl->session->output_h / 2;
1521 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1522 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1524 // Fix cursor origin
1526 gui->x_origin = mask_cursor_x;
1527 gui->y_origin = mask_cursor_y;
1531 // Points of closest line
1532 int shortest_point1 = -1;
1533 int shortest_point2 = -1;
1535 int shortest_point = -1;
1536 // Distance to closest line
1537 float shortest_line_distance = BC_INFINITY;
1538 // Distance to closest point
1539 float shortest_point_distance = BC_INFINITY;
1540 int selected_point = -1;
1541 int selected_control_point = -1;
1542 float selected_control_point_distance = BC_INFINITY;
1543 ArrayList<int> x_points;
1544 ArrayList<int> y_points;
1546 if(!cursor_motion) {
1548 get_canvas()->set_color(WHITE);
1549 get_canvas()->set_inverse();
1551 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1553 // Never draw closed polygon and a closed
1554 // polygon is harder to add points to.
1555 for(int i = 0; i < points.size() && !result; i++) {
1556 MaskPoint *point1 = points.get(i);
1557 MaskPoint *point2 = (i >= points.size() - 1) ?
1558 points.get(0) : points.get(i + 1);
1560 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1561 if(point_distance1 < shortest_point_distance || shortest_point < 0) {
1562 shortest_point_distance = point_distance1;
1566 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1567 if(point_distance2 < shortest_point_distance || shortest_point < 0) {
1568 shortest_point_distance = point_distance2;
1569 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1573 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1575 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1576 //point1->x, point1->y, point2->x, point2->y, projector_z);
1577 for(int j = 0; j <= segments && !result; j++) {
1578 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1579 float x0 = point1->x, y0 = point1->y;
1580 float x1 = point1->x + point1->control_x2;
1581 float y1 = point1->y + point1->control_y2;
1582 float x2 = point2->x + point2->control_x1;
1583 float y2 = point2->y + point2->control_y1;
1584 float x3 = point2->x, y3 = point2->y;
1585 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1586 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1587 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1588 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1589 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1590 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1591 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1592 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1594 float t = (float)j / segments;
1595 float tpow2 = t * t;
1596 float tpow3 = t * t * t;
1598 float invtpow2 = invt * invt;
1599 float invtpow3 = invt * invt * invt;
1601 float x = ( invtpow3 * x0
1602 + 3 * t * invtpow2 * x1
1603 + 3 * tpow2 * invt * x2
1605 float y = ( invtpow3 * y0
1606 + 3 * t * invtpow2 * y1
1607 + 3 * tpow2 * invt * y2
1609 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1610 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1611 // Test new point addition
1613 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1615 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1616 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1617 if(line_distance < shortest_line_distance ||
1618 shortest_point1 < 0) {
1619 shortest_line_distance = line_distance;
1620 shortest_point1 = i;
1621 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1622 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1623 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1626 // Test existing point selection
1628 if(gui->ctrl_down()) {
1629 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1631 if(distance < selected_control_point_distance) {
1633 selected_control_point = 1;
1634 selected_control_point_distance = distance;
1638 if(!gui->shift_down()) {
1639 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1640 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
1645 selected_point = shortest_point;
1648 // Test second point
1649 if(gui->ctrl_down()) {
1650 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1652 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1653 if(distance < selected_control_point_distance) {
1654 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1655 selected_control_point = 0;
1656 selected_control_point_distance = distance;
1659 else if(i < points.size() - 1) {
1660 if(!gui->shift_down()) {
1661 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1662 if(test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3)) {
1663 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1667 selected_point = shortest_point;
1672 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1676 if(draw) { // Draw joining line
1677 x_points.append((int)canvas_x);
1678 y_points.append((int)canvas_y);
1682 if(draw) { // Draw second anchor
1683 if(i < points.size() - 1) {
1684 if(i == gui->affected_point - 1)
1685 get_canvas()->draw_disc(
1686 (int)canvas_x - CONTROL_W / 2,
1687 (int)canvas_y - CONTROL_W / 2,
1688 CONTROL_W, CONTROL_H);
1690 get_canvas()->draw_circle(
1691 (int)canvas_x - CONTROL_W / 2,
1692 (int)canvas_y - CONTROL_W / 2,
1693 CONTROL_W, CONTROL_H);
1694 // char string[BCTEXTLEN];
1695 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1696 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1698 // Draw second control point.
1699 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1700 get_canvas()->draw_line(
1701 (int)canvas_x, (int)canvas_y,
1702 (int)canvas_x2, (int)canvas_y2);
1703 get_canvas()->draw_rectangle(
1704 (int)canvas_x2 - CONTROL_W / 2,
1705 (int)canvas_y2 - CONTROL_H / 2,
1706 CONTROL_W, CONTROL_H);
1711 // Draw first anchor
1712 if(i == 0 && draw) {
1713 char mask_label[BCSTRLEN];
1714 sprintf(mask_label, "%d",
1715 mwindow->edl->session->cwindow_mask);
1716 get_canvas()->draw_text(
1717 (int)canvas_x - FIRST_CONTROL_W,
1718 (int)canvas_y - FIRST_CONTROL_H,
1721 get_canvas()->draw_disc(
1722 (int)canvas_x - FIRST_CONTROL_W / 2,
1723 (int)canvas_y - FIRST_CONTROL_H / 2,
1724 FIRST_CONTROL_W, FIRST_CONTROL_H);
1727 // Draw first control point.
1729 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1730 get_canvas()->draw_line(
1731 (int)canvas_x, (int)canvas_y,
1732 (int)canvas_x1, (int)canvas_y1);
1733 get_canvas()->draw_rectangle(
1734 (int)canvas_x1 - CONTROL_W / 2,
1735 (int)canvas_y1 - CONTROL_H / 2,
1736 CONTROL_W, CONTROL_H);
1738 x_points.append((int)canvas_x);
1739 y_points.append((int)canvas_y);
1742 //printf("CWindowCanvas::do_mask 1\n");
1746 //printf("CWindowCanvas::do_mask 1\n");
1749 get_canvas()->draw_polygon(&x_points, &y_points);
1750 get_canvas()->set_opaque();
1752 //printf("CWindowCanvas::do_mask 1\n");
1755 if(button_press && !result) {
1756 gui->affected_track = gui->cwindow->calculate_affected_track();
1758 // Get keyframe outside the EDL to edit. This must be rendered
1759 // instead of the EDL keyframes when it exists. Then it must be
1760 // applied to the EDL keyframes on buttonrelease.
1761 if(gui->affected_track) {
1762 #ifdef USE_KEYFRAME_SPANNING
1763 // Make copy of current parameters in local keyframe
1764 gui->mask_keyframe =
1765 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1768 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1771 gui->mask_keyframe =
1772 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1777 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1780 // Translate entire keyframe
1781 if(gui->alt_down() && mask->points.size()) {
1782 mwindow->undo->update_undo_before(_("mask translate"), 0);
1783 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1784 gui->affected_point = 0;
1787 // Existing point or control point was selected
1788 if(selected_point >= 0) {
1789 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1790 gui->affected_point = selected_point;
1792 if(selected_control_point == 0)
1793 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1795 if(selected_control_point == 1)
1796 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1798 gui->current_operation = mwindow->edl->session->cwindow_operation;
1800 else // No existing point or control point was selected so create a new one
1801 if(!gui->ctrl_down() && !gui->alt_down()) {
1802 mwindow->undo->update_undo_before(_("mask point"), 0);
1803 // Create the template
1804 MaskPoint *point = new MaskPoint;
1805 point->x = mask_cursor_x;
1806 point->y = mask_cursor_y;
1807 point->control_x1 = 0;
1808 point->control_y1 = 0;
1809 point->control_x2 = 0;
1810 point->control_y2 = 0;
1813 if(shortest_point2 < shortest_point1) {
1814 shortest_point2 ^= shortest_point1;
1815 shortest_point1 ^= shortest_point2;
1816 shortest_point2 ^= shortest_point1;
1821 // printf("CWindowGUI::do_mask 40\n");
1822 // mwindow->edl->dump();
1823 // printf("CWindowGUI::do_mask 50\n");
1827 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1828 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1829 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1831 // Append to end of list
1832 if( shortest_point1 == shortest_point2 ||
1833 labs(shortest_point1 - shortest_point2) > 1) {
1834 #ifdef USE_KEYFRAME_SPANNING
1836 MaskPoint *new_point = new MaskPoint;
1837 points.append(new_point);
1838 *new_point = *point;
1839 gui->affected_point = points.size() - 1;
1843 // Need to apply the new point to every keyframe
1844 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1845 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1846 MaskPoint *new_point = new MaskPoint;
1847 submask->points.append(new_point);
1848 *new_point = *point;
1849 if(current == (MaskAuto*)mask_autos->default_auto)
1850 current = (MaskAuto*)mask_autos->first;
1852 current = (MaskAuto*)NEXT;
1854 gui->affected_point = mask->points.size() - 1;
1860 // Insert between 2 points, shifting back point 2
1861 if(shortest_point1 >= 0 && shortest_point2 >= 0) {
1863 #ifdef USE_KEYFRAME_SPANNING
1864 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1866 if(points.size() >= shortest_point2) {
1867 MaskPoint *new_point = new MaskPoint;
1869 for(int i = points.size() - 1;
1870 i > shortest_point2;
1872 points.values[i] = points.values[i - 1];
1873 points.values[shortest_point2] = new_point;
1875 *new_point = *point;
1880 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1881 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1882 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1884 if(submask->points.size() >= shortest_point2) {
1885 MaskPoint *new_point = new MaskPoint;
1886 submask->points.append(0);
1887 for(int i = submask->points.size() - 1;
1888 i > shortest_point2;
1890 submask->points.values[i] = submask->points.values[i - 1];
1891 submask->points.values[shortest_point2] = new_point;
1893 *new_point = *point;
1896 if(current == (MaskAuto*)mask_autos->default_auto)
1897 current = (MaskAuto*)mask_autos->first;
1899 current = (MaskAuto*)NEXT;
1903 gui->affected_point = shortest_point2;
1908 // printf("CWindowGUI::do_mask 20\n");
1909 // mwindow->edl->dump();
1910 // printf("CWindowGUI::do_mask 30\n");
1913 //printf("CWindowCanvas::do_mask 1\n");
1914 // Create the first point.
1915 #ifdef USE_KEYFRAME_SPANNING
1916 MaskPoint *new_point = new MaskPoint;
1917 points.append(new_point);
1918 *new_point = *point;
1919 gui->affected_point = points.size() - 1;
1921 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1922 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1923 MaskPoint *new_point = new MaskPoint;
1924 submask->points.append(new_point);
1925 *new_point = *point;
1926 if(current == (MaskAuto*)mask_autos->default_auto)
1927 current = (MaskAuto*)mask_autos->first;
1929 current = (MaskAuto*)NEXT;
1931 gui->affected_point = points.size() - 1;
1934 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
1937 gui->current_operation = mwindow->edl->session->cwindow_operation;
1938 // Delete the template
1947 if(button_press && result) {
1948 #ifdef USE_KEYFRAME_SPANNING
1949 MaskPoint *point = points.values[gui->affected_point];
1950 gui->center_x = point->x;
1951 gui->center_y = point->y;
1952 gui->control_in_x = point->control_x1;
1953 gui->control_in_y = point->control_y1;
1954 gui->control_out_x = point->control_x2;
1955 gui->control_out_y = point->control_y2;
1956 gui->tool_panel->raise_window();
1958 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1959 MaskPoint *point = mask->points.values[gui->affected_point];
1960 gui->center_x = point->x;
1961 gui->center_y = point->y;
1962 gui->control_in_x = point->control_x1;
1963 gui->control_in_y = point->control_y1;
1964 gui->control_out_x = point->control_x2;
1965 gui->control_out_y = point->control_y2;
1966 gui->tool_panel->raise_window();
1970 //printf("CWindowCanvas::do_mask 8\n");
1973 #ifdef USE_KEYFRAME_SPANNING
1974 // Must update the reference keyframes for every cursor motion
1975 gui->mask_keyframe =
1976 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1979 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1982 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1984 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1985 if( gui->affected_point >= 0 && gui->affected_point < mask->points.size() &&
1986 gui->current_operation != CWINDOW_NONE) {
1987 // mwindow->undo->update_undo_before(_("mask point"), this);
1988 #ifdef USE_KEYFRAME_SPANNING
1989 MaskPoint *point = points.get(gui->affected_point);
1991 MaskPoint *point = mask->points.get(gui->affected_point);
1993 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
1994 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask->points.size(), gui->affected_point);
1996 float last_x = point->x;
1997 float last_y = point->y;
1998 float last_control_x1 = point->control_x1;
1999 float last_control_y1 = point->control_y1;
2000 float last_control_x2 = point->control_x2;
2001 float last_control_y2 = point->control_y2;
2003 switch(gui->current_operation) {
2005 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2006 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
2007 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
2010 case CWINDOW_MASK_CONTROL_IN:
2011 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
2012 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
2015 case CWINDOW_MASK_CONTROL_OUT:
2016 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
2017 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
2020 case CWINDOW_MASK_TRANSLATE:
2021 #ifdef USE_KEYFRAME_SPANNING
2022 for(int i = 0; i < points.size(); i++) {
2023 points.values[i]->x += mask_cursor_x - gui->x_origin;
2024 points.values[i]->y += mask_cursor_y - gui->y_origin;
2027 for(int i = 0; i < mask->points.size(); i++) {
2028 mask->points.values[i]->x += mask_cursor_x - gui->x_origin;
2029 mask->points.values[i]->y += mask_cursor_y - gui->y_origin;
2032 gui->x_origin = mask_cursor_x;
2033 gui->y_origin = mask_cursor_y;
2037 if( !EQUIV(last_x, point->x) ||
2038 !EQUIV(last_y, point->y) ||
2039 !EQUIV(last_control_x1, point->control_x1) ||
2040 !EQUIV(last_control_y1, point->control_y1) ||
2041 !EQUIV(last_control_x2, point->control_x2) ||
2042 !EQUIV(last_control_y2, point->control_y2)) {
2048 if(gui->current_operation == CWINDOW_NONE) {
2049 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
2051 for(int i = 0; i < points.size() && !over_point; i++) {
2052 MaskPoint *point = points.get(i);
2053 float x0 = point->x;
2054 float y0 = point->y;
2055 float x1 = point->x + point->control_x1;
2056 float y1 = point->y + point->control_y1;
2057 float x2 = point->x + point->control_x2;
2058 float y2 = point->y + point->control_y2;
2059 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
2060 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
2062 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
2063 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
2067 if(!over_point && gui->ctrl_down()) {
2068 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
2069 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
2070 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2071 if(test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1)) {
2075 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2076 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2077 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2078 if(test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2)) {
2085 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2090 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2093 #ifdef USE_KEYFRAME_SPANNING
2094 // Must commit change after operation.
2095 if(rerender && track) {
2096 // Swap EDL keyframe with original.
2097 // Apply new values to keyframe span
2098 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2099 temp_keyframe.copy_data(gui->mask_keyframe);
2100 // Apply interpolated points back to keyframe
2101 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2102 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2103 mask_autos->update_parameter(&temp_keyframe);
2107 points.remove_all_objects();
2108 //printf("CWindowCanvas::do_mask 20\n");
2112 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2115 int radius = mwindow->edl->session->eyedrop_radius;
2123 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2128 row1 = gui->eyedrop_y - radius;
2129 row2 = gui->eyedrop_y + radius;
2130 column1 = gui->eyedrop_x - radius;
2131 column2 = gui->eyedrop_x + radius;
2133 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2134 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2135 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2136 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2138 if(row2 <= row1) row2 = row1 + 1;
2139 if(column2 <= column1) column2 = column1 + 1;
2146 output_to_canvas(mwindow->edl, 0, x1, y1);
2147 output_to_canvas(mwindow->edl, 0, x2, y2);
2148 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2150 if(x2 - x1 >= 1 && y2 - y1 >= 1)
2152 get_canvas()->set_inverse();
2153 get_canvas()->set_color(WHITE);
2155 get_canvas()->draw_rectangle((int)x1,
2160 get_canvas()->set_opaque();
2161 get_canvas()->flash();
2169 gui->current_operation = CWINDOW_EYEDROP;
2170 gui->tool_panel->raise_window();
2173 if(gui->current_operation == CWINDOW_EYEDROP)
2175 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2177 // Get color out of frame.
2178 // Doesn't work during playback because that bypasses the refresh frame.
2179 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2181 float cursor_x = get_cursor_x();
2182 float cursor_y = get_cursor_y();
2183 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2184 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2185 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2187 row1 = cursor_y - radius;
2188 row2 = cursor_y + radius;
2189 column1 = cursor_x - radius;
2190 column2 = cursor_x + radius;
2191 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2192 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2193 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2194 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2195 if(row2 <= row1) row2 = row1 + 1;
2196 if(column2 <= column1) column2 = column1 + 1;
2200 if(gui->eyedrop_visible)
2203 do_eyedrop(temp, 0, 1);
2204 gui->eyedrop_visible = 0;
2207 gui->eyedrop_x = cursor_x;
2208 gui->eyedrop_y = cursor_y;
2213 do_eyedrop(temp, 0, 1);
2214 gui->eyedrop_visible = 1;
2217 // Decompression coefficients straight out of jpeglib
2218 #define V_TO_R 1.40200
2219 #define V_TO_G -0.71414
2221 #define U_TO_G -0.34414
2222 #define U_TO_B 1.77200
2224 #define GET_COLOR(type, components, max, do_yuv) \
2226 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2228 float red = (float)*row++ / max; \
2229 float green = (float)*row++ / max; \
2230 float blue = (float)*row++ / max; \
2233 float r = red + V_TO_R * (blue - 0.5); \
2234 float g = red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
2235 float b = red + U_TO_B * (green - 0.5); \
2236 mwindow->edl->local_session->red += r; \
2237 mwindow->edl->local_session->green += g; \
2238 mwindow->edl->local_session->blue += b; \
2239 if(r > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = r; \
2240 if(g > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = g; \
2241 if(b > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = b; \
2245 mwindow->edl->local_session->red += red; \
2246 mwindow->edl->local_session->green += green; \
2247 mwindow->edl->local_session->blue += blue; \
2248 if(red > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = red; \
2249 if(green > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = green; \
2250 if(blue > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = blue; \
2256 mwindow->edl->local_session->red = 0;
2257 mwindow->edl->local_session->green = 0;
2258 mwindow->edl->local_session->blue = 0;
2259 mwindow->edl->local_session->red_max = 0;
2260 mwindow->edl->local_session->green_max = 0;
2261 mwindow->edl->local_session->blue_max = 0;
2262 for(int i = row1; i < row2; i++)
2264 for(int j = column1; j < column2; j++)
2266 switch(refresh_frame->get_color_model())
2269 GET_COLOR(unsigned char, 3, 0xff, 1);
2272 GET_COLOR(unsigned char, 4, 0xff, 1);
2275 GET_COLOR(uint16_t, 3, 0xffff, 1);
2277 case BC_YUVA16161616:
2278 GET_COLOR(uint16_t, 4, 0xffff, 1);
2281 GET_COLOR(unsigned char, 3, 0xff, 0);
2284 GET_COLOR(unsigned char, 4, 0xff, 0);
2287 GET_COLOR(float, 3, 1.0, 0);
2290 GET_COLOR(float, 4, 1.0, 0);
2296 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2297 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2298 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2303 mwindow->edl->local_session->red = 0;
2304 mwindow->edl->local_session->green = 0;
2305 mwindow->edl->local_session->blue = 0;
2306 gui->eyedrop_visible = 0;
2315 // Can't rerender since the color value is from the output of any effect it
2318 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2324 int CWindowCanvas::need_overlays()
2326 if( mwindow->edl->session->safe_regions ) return 1;
2327 if( mwindow->edl->session->cwindow_scrollbars ) return 1;
2328 if( gui->highlighted ) return 1;
2329 switch( mwindow->edl->session->cwindow_operation ) {
2330 case CWINDOW_EYEDROP:
2331 if( ! gui->eyedrop_visible ) break;
2332 case CWINDOW_CAMERA:
2333 case CWINDOW_PROJECTOR:
2342 void CWindowCanvas::draw_overlays()
2344 if(mwindow->edl->session->safe_regions)
2346 draw_safe_regions();
2349 if(mwindow->edl->session->cwindow_scrollbars)
2351 // Always draw output rectangle
2352 float x1, y1, x2, y2;
2354 x2 = mwindow->edl->session->output_w;
2356 y2 = mwindow->edl->session->output_h;
2357 output_to_canvas(mwindow->edl, 0, x1, y1);
2358 output_to_canvas(mwindow->edl, 0, x2, y2);
2360 get_canvas()->set_inverse();
2361 get_canvas()->set_color(WHITE);
2363 get_canvas()->draw_rectangle((int)x1,
2368 get_canvas()->set_opaque();
2371 if(gui->highlighted)
2373 get_canvas()->set_color(WHITE);
2374 get_canvas()->set_inverse();
2375 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2376 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2377 get_canvas()->set_opaque();
2380 int temp1 = 0, temp2 = 0;
2381 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2382 switch(mwindow->edl->session->cwindow_operation)
2384 case CWINDOW_CAMERA:
2388 case CWINDOW_PROJECTOR:
2397 do_mask(temp1, temp2, 0, 0, 1);
2401 do_ruler(1, 0, 0, 0);
2404 case CWINDOW_EYEDROP:
2405 if(gui->eyedrop_visible)
2408 do_eyedrop(rerender, 0, 1);
2409 gui->eyedrop_visible = 1;
2415 void CWindowCanvas::draw_safe_regions()
2417 float action_x1, action_x2, action_y1, action_y2;
2418 float title_x1, title_x2, title_y1, title_y2;
2420 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2421 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2422 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2423 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2424 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2425 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2426 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2427 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2429 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2430 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2431 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2432 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2434 get_canvas()->set_inverse();
2435 get_canvas()->set_color(WHITE);
2437 get_canvas()->draw_rectangle((int)action_x1,
2439 (int)(action_x2 - action_x1),
2440 (int)(action_y2 - action_y1));
2441 get_canvas()->draw_rectangle((int)title_x1,
2443 (int)(title_x2 - title_x1),
2444 (int)(title_y2 - title_y1));
2446 get_canvas()->set_opaque();
2449 void CWindowCanvas::reset_keyframe(int do_camera)
2451 FloatAuto *x_keyframe = 0;
2452 FloatAuto *y_keyframe = 0;
2453 FloatAuto *z_keyframe = 0;
2454 Track *affected_track = 0;
2456 affected_track = gui->cwindow->calculate_affected_track();
2460 gui->cwindow->calculate_affected_autos(&x_keyframe,
2469 x_keyframe->set_value(0);
2470 y_keyframe->set_value(0);
2471 z_keyframe->set_value(1);
2473 mwindow->sync_parameters(CHANGE_PARAMS);
2478 void CWindowCanvas::reset_camera()
2483 void CWindowCanvas::reset_projector()
2488 int CWindowCanvas::test_crop(int button_press, int &redraw)
2491 int handle_selected = -1;
2492 float x1 = mwindow->edl->session->crop_x1;
2493 float y1 = mwindow->edl->session->crop_y1;
2494 float x2 = mwindow->edl->session->crop_x2;
2495 float y2 = mwindow->edl->session->crop_y2;
2496 float cursor_x = get_cursor_x();
2497 float cursor_y = get_cursor_y();
2498 float canvas_x1 = x1;
2499 float canvas_y1 = y1;
2500 float canvas_x2 = x2;
2501 float canvas_y2 = y2;
2502 float canvas_cursor_x = cursor_x;
2503 float canvas_cursor_y = cursor_y;
2505 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2506 // Use screen normalized coordinates for hot spot tests.
2507 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2508 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2511 if(gui->current_operation == CWINDOW_CROP)
2513 handle_selected = gui->crop_handle;
2516 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2517 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2519 handle_selected = 0;
2520 gui->crop_origin_x = x1;
2521 gui->crop_origin_y = y1;
2524 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2525 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2527 handle_selected = 1;
2528 gui->crop_origin_x = x2;
2529 gui->crop_origin_y = y1;
2532 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2533 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2535 handle_selected = 2;
2536 gui->crop_origin_x = x1;
2537 gui->crop_origin_y = y2;
2540 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2541 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2543 handle_selected = 3;
2544 gui->crop_origin_x = x2;
2545 gui->crop_origin_y = y2;
2550 gui->crop_origin_x = cursor_x;
2551 gui->crop_origin_y = cursor_y;
2554 // printf("test crop %d %d\n",
2555 // gui->current_operation,
2556 // handle_selected);
2563 gui->crop_translate = 1;
2564 gui->crop_origin_x1 = x1;
2565 gui->crop_origin_y1 = y1;
2566 gui->crop_origin_x2 = x2;
2567 gui->crop_origin_y2 = y2;
2570 gui->crop_translate = 0;
2572 gui->current_operation = CWINDOW_CROP;
2573 gui->crop_handle = handle_selected;
2574 gui->x_origin = cursor_x;
2575 gui->y_origin = cursor_y;
2576 gui->tool_panel->raise_window();
2579 if(handle_selected < 0 && !gui->crop_translate)
2583 mwindow->edl->session->crop_x1 = (int)x1;
2584 mwindow->edl->session->crop_y1 = (int)y1;
2585 mwindow->edl->session->crop_x2 = (int)x2;
2586 mwindow->edl->session->crop_y2 = (int)y2;
2591 // Translate all 4 points
2592 if(gui->current_operation == CWINDOW_CROP && gui->crop_translate)
2594 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2595 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2596 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2597 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2599 mwindow->edl->session->crop_x1 = (int)x1;
2600 mwindow->edl->session->crop_y1 = (int)y1;
2601 mwindow->edl->session->crop_x2 = (int)x2;
2602 mwindow->edl->session->crop_y2 = (int)y2;
2608 if(gui->current_operation == CWINDOW_CROP)
2610 switch(gui->crop_handle)
2613 x1 = gui->crop_origin_x;
2614 y1 = gui->crop_origin_y;
2615 x2 = gui->crop_origin_x;
2616 y2 = gui->crop_origin_y;
2617 if(cursor_x < gui->x_origin)
2619 if(cursor_y < gui->y_origin)
2625 if(cursor_y >= gui->y_origin)
2632 if(cursor_x >= gui->x_origin)
2634 if(cursor_y < gui->y_origin)
2640 if(cursor_y >= gui->y_origin)
2647 // printf("test crop %d %d %d %d\n",
2648 // mwindow->edl->session->crop_x1,
2649 // mwindow->edl->session->crop_y1,
2650 // mwindow->edl->session->crop_x2,
2651 // mwindow->edl->session->crop_y2);
2654 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2655 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2658 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2659 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2662 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2663 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2666 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2667 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2671 if(!EQUIV(mwindow->edl->session->crop_x1, x1) ||
2672 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2673 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2674 !EQUIV(mwindow->edl->session->crop_y2, y2))
2681 switch (gui->crop_handle)
2683 case 0: gui->crop_handle = 1; break;
2684 case 1: gui->crop_handle = 0; break;
2685 case 2: gui->crop_handle = 3; break;
2686 case 3: gui->crop_handle = 2; break;
2696 switch (gui->crop_handle)
2698 case 0: gui->crop_handle = 2; break;
2699 case 1: gui->crop_handle = 3; break;
2700 case 2: gui->crop_handle = 0; break;
2701 case 3: gui->crop_handle = 1; break;
2706 mwindow->edl->session->crop_x1 = (int)x1;
2707 mwindow->edl->session->crop_y1 = (int)y1;
2708 mwindow->edl->session->crop_x2 = (int)x2;
2709 mwindow->edl->session->crop_y2 = (int)y2;
2715 // Update cursor font
2716 if(handle_selected >= 0)
2718 switch(handle_selected)
2721 set_cursor(UPLEFT_RESIZE);
2724 set_cursor(UPRIGHT_RESIZE);
2727 set_cursor(DOWNLEFT_RESIZE);
2730 set_cursor(DOWNRIGHT_RESIZE);
2737 set_cursor(ARROW_CURSOR);
2739 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2743 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2744 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2745 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2746 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2747 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2748 // mwindow->edl->session->crop_x2,
2749 // mwindow->edl->session->crop_y2,
2750 // mwindow->edl->calculate_output_w(0),
2751 // mwindow->edl->calculate_output_h(0));
2757 void CWindowCanvas::draw_crop()
2759 get_canvas()->set_inverse();
2760 get_canvas()->set_color(WHITE);
2762 float x1 = mwindow->edl->session->crop_x1;
2763 float y1 = mwindow->edl->session->crop_y1;
2764 float x2 = mwindow->edl->session->crop_x2;
2765 float y2 = mwindow->edl->session->crop_y2;
2767 output_to_canvas(mwindow->edl, 0, x1, y1);
2768 output_to_canvas(mwindow->edl, 0, x2, y2);
2770 if(x2 - x1 && y2 - y1)
2771 get_canvas()->draw_rectangle((int)x1,
2776 draw_crophandle((int)x1, (int)y1);
2777 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2778 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2779 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2780 get_canvas()->set_opaque();
2790 void CWindowCanvas::draw_bezier(int do_camera)
2792 Track *track = gui->cwindow->calculate_affected_track();
2799 int64_t position = track->to_units(
2800 mwindow->edl->local_session->get_selectionstart(1),
2803 track->automation->get_projector(¢er_x,
2809 // center_x += track->track_w / 2;
2810 // center_y += track->track_h / 2;
2811 center_x += mwindow->edl->session->output_w / 2;
2812 center_y += mwindow->edl->session->output_h / 2;
2813 float track_x1 = center_x - track->track_w / 2 * center_z;
2814 float track_y1 = center_y - track->track_h / 2 * center_z;
2815 float track_x2 = track_x1 + track->track_w * center_z;
2816 float track_y2 = track_y1 + track->track_h * center_z;
2818 output_to_canvas(mwindow->edl, 0, track_x1, track_y1);
2819 output_to_canvas(mwindow->edl, 0, track_x2, track_y2);
2821 #define DRAW_PROJECTION(offset) \
2822 get_canvas()->draw_rectangle((int)track_x1 + offset, \
2823 (int)track_y1 + offset, \
2824 (int)(track_x2 - track_x1), \
2825 (int)(track_y2 - track_y1)); \
2826 get_canvas()->draw_line((int)track_x1 + offset, \
2827 (int)track_y1 + offset, \
2828 (int)track_x2 + offset, \
2829 (int)track_y2 + offset); \
2830 get_canvas()->draw_line((int)track_x2 + offset, \
2831 (int)track_y1 + offset, \
2832 (int)track_x1 + offset, \
2833 (int)track_y2 + offset); \
2837 get_canvas()->set_color(BLACK);
2840 // canvas->set_inverse();
2842 get_canvas()->set_color(GREEN);
2844 get_canvas()->set_color(RED);
2847 // canvas->set_opaque();
2851 int CWindowCanvas::test_bezier(int button_press,
2859 // Processing drag operation.
2860 // Create keyframe during first cursor motion.
2864 float cursor_x = get_cursor_x();
2865 float cursor_y = get_cursor_y();
2866 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2868 if(gui->current_operation == CWINDOW_CAMERA ||
2869 gui->current_operation == CWINDOW_PROJECTOR)
2871 if(!gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom)
2873 gui->translating_zoom = 1;
2874 gui->reset_affected();
2877 if(!gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom)
2879 gui->translating_zoom = 0;
2880 gui->reset_affected();
2883 // Get target keyframe
2884 float last_center_x;
2885 float last_center_y;
2886 float last_center_z;
2889 if(!gui->affected_x && !gui->affected_y && !gui->affected_z)
2891 FloatAutos *affected_x_autos;
2892 FloatAutos *affected_y_autos;
2893 FloatAutos *affected_z_autos;
2894 if(!gui->affected_track) return 0;
2895 double position = mwindow->edl->local_session->get_selectionstart(1);
2896 int64_t track_position = gui->affected_track->to_units(position, 0);
2898 if(mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA)
2900 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_X];
2901 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Y];
2902 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Z];
2906 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_X];
2907 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Y];
2908 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Z];
2912 if(gui->translating_zoom)
2914 FloatAuto *previous = 0;
2915 FloatAuto *next = 0;
2916 float new_z = affected_z_autos->get_value(
2922 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2923 affected_z_autos, 1, &created, 0);
2925 gui->affected_z->set_value(new_z);
2931 FloatAuto *previous = 0;
2932 FloatAuto *next = 0;
2933 float new_x = affected_x_autos->get_value(
2940 float new_y = affected_y_autos->get_value(
2946 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2947 affected_x_autos, 1, &created, 0);
2949 gui->affected_x->set_value(new_x);
2953 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2954 affected_y_autos, 1, &created, 0);
2956 gui->affected_y->set_value(new_y);
2963 if(gui->translating_zoom)
2965 gui->center_z = gui->affected_z->get_value();
2969 gui->center_x = gui->affected_x->get_value();
2970 gui->center_y = gui->affected_y->get_value();
2977 if(gui->translating_zoom)
2979 last_center_z = gui->affected_z->get_value();
2980 float z = gui->center_z + (cursor_y - gui->y_origin) / 128;
2982 if(!EQUIV(last_center_z, z))
2988 gui->affected_z->set_value(z);
2992 last_center_x = gui->affected_x->get_value();
2993 last_center_y = gui->affected_y->get_value();
2994 float dx = cursor_x - gui->x_origin;
2995 float dy = cursor_y - gui->y_origin;
2996 if(gui->current_operation == CWINDOW_CAMERA ) {
2999 float x = gui->center_x + dx;
3000 float y = gui->center_y + dy;
3001 gui->affected_x->set_value(x);
3002 gui->affected_y->set_value(y);
3003 if( !EQUIV(last_center_x, x) || !EQUIV(last_center_y, y) )
3009 gui->affected_x->set_value(x);
3010 gui->affected_y->set_value(y);
3017 // Begin drag operation. Don't create keyframe here.
3019 // Get affected track off of the first recordable video track.
3020 // Calculating based on the alpha channel would require recording what layer
3021 // each output pixel belongs to as they're rendered and stacked. Forget it.
3022 gui->affected_track = gui->cwindow->calculate_affected_track();
3023 gui->reset_affected();
3025 if(gui->affected_track)
3027 if(gui->current_operation == CWINDOW_CAMERA)
3028 mwindow->undo->update_undo_before(_("camera"), this);
3030 mwindow->undo->update_undo_before(_("projector"), this);
3032 gui->current_operation =
3033 mwindow->edl->session->cwindow_operation;
3034 gui->tool_panel->raise_window();
3043 int CWindowCanvas::test_zoom(int &redraw)
3049 if( mwindow->edl->session->cwindow_scrollbars ) {
3050 if( *gui->zoom_panel->get_text() != 'x' ) {
3051 // Find current zoom in table
3052 int idx = total_zooms; float old_zoom = get_zoom();
3053 while( --idx >= 0 && !EQUIV(my_zoom_table[idx], old_zoom) );
3055 idx += get_buttonpress() == 5 ||
3056 gui->ctrl_down() || gui->shift_down() ? -1 : +1 ;
3057 CLAMP(idx, 0, total_zooms-1);
3058 zoom = my_zoom_table[idx];
3061 x = get_cursor_x(); y = get_cursor_y();
3063 mwindow->edl->session->cwindow_scrollbars = 0;
3064 gui->zoom_panel->update(0);
3065 zoom = gui->get_auto_zoom();
3068 gui->zoom_panel->ZoomPanel::update(zoom);
3069 float output_x = x, output_y = y;
3070 canvas_to_output(mwindow->edl, 0, output_x, output_y);
3071 x = output_x - x / zoom;
3072 y = output_y - y / zoom;
3076 mwindow->edl->session->cwindow_scrollbars = 1;
3077 x = (mwindow->edl->session->output_w - w) / 2;
3078 y = (mwindow->edl->session->output_h - h) / 2;
3081 update_zoom((int)x, (int)y, zoom);
3083 gui->composite_panel->cpanel_zoom->update(zoom);
3085 reposition_window(mwindow->edl,
3086 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
3087 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
3088 redraw = 1; result = 1;
3094 void CWindowCanvas::calculate_origin()
3096 gui->x_origin = get_cursor_x();
3097 gui->y_origin = get_cursor_y();
3098 //printf("CWindowCanvas::calculate_origin 1 %f %f\n", gui->x_origin, gui->y_origin);
3099 canvas_to_output(mwindow->edl, 0, gui->x_origin, gui->y_origin);
3100 //printf("CWindowCanvas::calculate_origin 2 %f %f\n", gui->x_origin, gui->y_origin);
3104 int CWindowCanvas::cursor_leave_event()
3106 set_cursor(ARROW_CURSOR);
3110 int CWindowCanvas::cursor_enter_event()
3113 switch(mwindow->edl->session->cwindow_operation)
3115 case CWINDOW_CAMERA:
3116 case CWINDOW_PROJECTOR:
3117 set_cursor(MOVE_CURSOR);
3120 set_cursor(MOVE_CURSOR);
3123 test_crop(0, redraw);
3125 case CWINDOW_PROTECT:
3126 set_cursor(ARROW_CURSOR);
3130 set_cursor(CROSS_CURSOR);
3132 case CWINDOW_EYEDROP:
3133 set_cursor(CROSS_CURSOR);
3139 int CWindowCanvas::cursor_motion_event()
3141 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3144 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3145 switch(gui->current_operation)
3147 case CWINDOW_SCROLL:
3149 float zoom = get_zoom();
3150 float cursor_x = get_cursor_x();
3151 float cursor_y = get_cursor_y();
3153 float zoom_x, zoom_y, conformed_w, conformed_h;
3154 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3155 cursor_x = (float)cursor_x / zoom_x + gui->x_offset;
3156 cursor_y = (float)cursor_y / zoom_y + gui->y_offset;
3160 int x = (int)(gui->x_origin - cursor_x + gui->x_offset);
3161 int y = (int)(gui->y_origin - cursor_y + gui->y_offset);
3166 update_scrollbars(0);
3173 result = do_ruler(0, 1, 0, 0);
3176 case CWINDOW_CAMERA:
3177 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3180 case CWINDOW_PROJECTOR:
3181 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3186 result = test_crop(0, redraw);
3187 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3194 case CWINDOW_MASK_CONTROL_IN:
3195 case CWINDOW_MASK_CONTROL_OUT:
3196 case CWINDOW_MASK_TRANSLATE:
3198 result = do_mask(redraw,
3205 case CWINDOW_EYEDROP:
3206 result = do_eyedrop(rerender, 0, 0);
3215 // cursor font changes
3218 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3220 // mwindow->edl->session->cwindow_operation);
3221 switch(mwindow->edl->session->cwindow_operation)
3224 result = test_crop(0, redraw);
3227 result = do_ruler(0, 1, 0, 0);
3230 result = do_mask(redraw,
3240 // If the window is never unlocked before calling send_command the
3241 // display shouldn't get stuck on the old video frame although it will
3242 // flicker between the old video frame and the new video frame.
3252 gui->unlock_window();
3255 mwindow->gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3256 mwindow->gui->draw_overlays(1);
3257 mwindow->gui->unlock_window();
3259 gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3264 gui->unlock_window();
3265 mwindow->restart_brender();
3266 mwindow->sync_parameters(CHANGE_PARAMS);
3267 mwindow->cwindow->refresh_frame(CHANGE_NONE);
3268 if(!redraw) gui->update_tool();
3269 gui->lock_window("CWindowCanvas::cursor_motion_event 2");
3274 int CWindowCanvas::button_press_event()
3278 int redraw_canvas = 0;
3281 if(Canvas::button_press_event()) return 1;
3283 gui->translating_zoom = gui->shift_down();
3286 //printf("CWindowCanvas::button_press_event 2 %f %f\n", gui->x_origin, gui->y_origin, gui->x_origin, gui->y_origin);
3288 float zoom_x, zoom_y, conformed_w, conformed_h;
3289 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3290 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3291 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3294 if( mwindow->edl->session->cwindow_operation != CWINDOW_PROTECT &&
3295 get_buttonpress() == 2 )
3297 gui->current_operation = CWINDOW_SCROLL;
3303 switch(mwindow->edl->session->cwindow_operation)
3306 result = do_ruler(0, 0, 1, 0);
3309 case CWINDOW_CAMERA:
3310 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3313 case CWINDOW_PROJECTOR:
3314 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3318 result = test_zoom(redraw);
3322 result = test_crop(1, redraw);
3326 if(get_buttonpress() == 1)
3327 result = do_mask(redraw, rerender, 1, 0, 0);
3330 case CWINDOW_EYEDROP:
3331 result = do_eyedrop(rerender, 1, 0);
3339 gui->unlock_window();
3342 mwindow->gui->lock_window("CWindowCanvas::button_press_event 1");
3343 mwindow->gui->draw_overlays(1);
3344 mwindow->gui->unlock_window();
3347 gui->lock_window("CWindowCanvas::button_press_event 1");
3350 // rerendering can also be caused by press event
3353 gui->unlock_window();
3355 mwindow->restart_brender();
3356 mwindow->sync_parameters(CHANGE_PARAMS);
3357 mwindow->cwindow->refresh_frame(CHANGE_NONE);
3358 if(!redraw) gui->update_tool();
3359 gui->lock_window("CWindowCanvas::button_press_event 2");
3364 int CWindowCanvas::button_release_event()
3368 switch(gui->current_operation)
3370 case CWINDOW_SCROLL:
3375 do_ruler(0, 0, 0, 1);
3378 case CWINDOW_CAMERA:
3379 mwindow->undo->update_undo_after(_("camera"), LOAD_AUTOMATION);
3382 case CWINDOW_PROJECTOR:
3383 mwindow->undo->update_undo_after(_("projector"), LOAD_AUTOMATION);
3387 case CWINDOW_MASK_CONTROL_IN:
3388 case CWINDOW_MASK_CONTROL_OUT:
3389 case CWINDOW_MASK_TRANSLATE:
3390 // Finish mask operation
3391 gui->mask_keyframe = 0;
3392 mwindow->undo->update_undo_after(_("mask"), LOAD_AUTOMATION);
3395 result = Canvas::button_release_event();
3399 gui->current_operation = CWINDOW_NONE;
3403 void CWindowCanvas::zoom_resize_window(float percentage)
3405 int canvas_w, canvas_h;
3409 // Get required canvas size
3410 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3411 mwindow->edl->session->output_w,
3412 mwindow->edl->session->output_h,
3417 // Estimate window size from current borders
3418 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3419 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3421 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3422 mwindow->session->cwindow_w = new_w;
3423 mwindow->session->cwindow_h = new_h;
3425 mwindow->theme->get_cwindow_sizes(gui,
3426 mwindow->session->cwindow_controls);
3428 // Estimate again from new borders
3429 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3430 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3431 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3433 gui->resize_window(new_w, new_h);
3434 gui->resize_event(new_w, new_h);
3437 void CWindowCanvas::toggle_controls()
3439 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3440 gui->resize_event(gui->get_w(), gui->get_h());
3443 int CWindowCanvas::get_cwindow_controls()
3445 return mwindow->session->cwindow_controls;