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( canvas->get_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( canvas->get_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 && cwindow_operation < 0 && ctrl_down() && shift_down() ) {
574 switch( get_keypress() ) {
575 case KEY_F1 ... KEY_F4: // mainmenu, load layout
576 resend_event(mwindow->gui);
581 if( !result && !ctrl_down() ) {
582 switch( get_keypress() ) {
585 mwindow->toggle_camera_xyz(); result = 1;
588 cwindow_operation = CWINDOW_PROTECT;
592 mwindow->toggle_projector_xyz(); result = 1;
595 cwindow_operation = CWINDOW_ZOOM;
599 if( !result && cwindow_operation < 0 && !ctrl_down() && !shift_down() ) {
600 switch( get_keypress() ) {
601 case KEY_F3: cwindow_operation = CWINDOW_MASK; break;
602 case KEY_F4: cwindow_operation = CWINDOW_RULER; break;
603 case KEY_F5: cwindow_operation = CWINDOW_CAMERA; break;
604 case KEY_F6: cwindow_operation = CWINDOW_PROJECTOR; break;
605 case KEY_F7: cwindow_operation = CWINDOW_CROP; break;
606 case KEY_F8: cwindow_operation = CWINDOW_EYEDROP; break;
607 case KEY_F9: cwindow_operation = CWINDOW_TOOL_WINDOW; break;
608 case KEY_F10: cwindow_operation = CWINDOW_TITLESAFE; break;
611 if( !result && cwindow_operation < 0 && !ctrl_down() ) {
612 switch( get_keypress() ) {
615 canvas->reset_camera();
617 canvas->camera_keyframe();
622 canvas->reset_projector();
624 canvas->projector_keyframe();
630 if( cwindow_operation >= 0 ) {
631 set_operation(cwindow_operation);
636 result = transport->keypress_event();
642 void CWindowGUI::reset_affected()
649 void CWindowGUI::keyboard_zoomin()
651 // if(mwindow->edl->session->cwindow_scrollbars)
653 zoom_panel->zoom_tumbler->handle_up_event();
660 void CWindowGUI::keyboard_zoomout()
662 // if(mwindow->edl->session->cwindow_scrollbars)
664 zoom_panel->zoom_tumbler->handle_down_event();
671 void CWindowGUI::sync_parameters(int change_type, int redraw, int overlay)
675 canvas->draw_refresh();
677 if( change_type < 0 && !overlay ) return;
679 if( change_type >= 0 ) {
680 mwindow->restart_brender();
681 mwindow->sync_parameters(change_type);
684 mwindow->gui->lock_window("CWindowGUI::sync_parameters");
685 mwindow->gui->draw_overlays(1);
686 mwindow->gui->unlock_window();
688 lock_window("CWindowGUI::sync_parameters");
691 void CWindowGUI::drag_motion()
693 if(get_hidden()) return;
695 if(mwindow->session->current_operation != DRAG_ASSET &&
696 mwindow->session->current_operation != DRAG_VTRANSITION &&
697 mwindow->session->current_operation != DRAG_VEFFECT) return;
698 int need_highlight = cursor_above() && get_cursor_over_window();
699 if( highlighted == need_highlight ) return;
700 highlighted = need_highlight;
701 canvas->draw_refresh();
704 int CWindowGUI::drag_stop()
707 if(get_hidden()) return 0;
708 if( !highlighted ) return 0;
709 if( mwindow->session->current_operation != DRAG_ASSET &&
710 mwindow->session->current_operation != DRAG_VTRANSITION &&
711 mwindow->session->current_operation != DRAG_VEFFECT) return 0;
713 canvas->draw_refresh();
716 if(mwindow->session->current_operation == DRAG_ASSET)
718 if(mwindow->session->drag_assets->total ||
719 mwindow->session->drag_clips->total)
721 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
722 mwindow->undo->update_undo_before(_("insert assets"), 0);
725 if(mwindow->session->drag_assets->total)
728 mwindow->load_assets(mwindow->session->drag_assets,
729 mwindow->edl->local_session->get_selectionstart(),
731 mwindow->session->track_highlighted,
733 mwindow->edl->session->labels_follow_edits,
734 mwindow->edl->session->plugins_follow_edits,
735 mwindow->edl->session->autos_follow_edits,
739 if(mwindow->session->drag_clips->total)
742 mwindow->paste_edls(mwindow->session->drag_clips,
744 mwindow->session->track_highlighted,
745 mwindow->edl->local_session->get_selectionstart(),
746 mwindow->edl->session->labels_follow_edits,
747 mwindow->edl->session->plugins_follow_edits,
748 mwindow->edl->session->autos_follow_edits,
752 if(mwindow->session->drag_assets->total ||
753 mwindow->session->drag_clips->total)
755 mwindow->save_backup();
756 mwindow->restart_brender();
757 mwindow->gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
758 mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
759 mwindow->gui->unlock_window();
760 sync_parameters(CHANGE_ALL);
764 if(mwindow->session->current_operation == DRAG_VEFFECT)
766 //printf("CWindowGUI::drag_stop 1\n");
767 Track *affected_track = cwindow->calculate_affected_track();
768 //printf("CWindowGUI::drag_stop 2\n");
770 mwindow->gui->lock_window("CWindowGUI::drag_stop 3");
771 mwindow->insert_effects_cwindow(affected_track);
772 mwindow->session->current_operation = NO_OPERATION;
773 mwindow->gui->unlock_window();
776 if(mwindow->session->current_operation == DRAG_VTRANSITION)
778 Track *affected_track = cwindow->calculate_affected_track();
779 mwindow->gui->lock_window("CWindowGUI::drag_stop 4");
780 mwindow->paste_transition_cwindow(affected_track);
781 mwindow->session->current_operation = NO_OPERATION;
782 mwindow->gui->unlock_window();
788 void CWindowGUI::update_meters()
790 if(mwindow->edl->session->cwindow_meter != meters->visible)
792 meters->set_meters(meters->meter_count, mwindow->edl->session->cwindow_meter);
793 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
794 resize_event(get_w(), get_h());
798 void CWindowGUI::stop_transport(const char *lock_msg)
800 if( lock_msg ) unlock_window();
801 mwindow->stop_transport();
802 if( lock_msg ) lock_window(lock_msg);
806 CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
807 : EditPanel(mwindow, cwindow->gui, CWINDOW_ID,
808 mwindow->theme->cedit_x, mwindow->theme->cedit_y,
809 mwindow->edl->session->editing_mode,
810 0, // use_editing_mode
827 this->mwindow = mwindow;
828 this->cwindow = cwindow;
831 #define relock_cm(s) \
832 cwindow->gui->unlock_window(); \
833 mwindow->gui->lock_window("CWindowEditing::" s)
834 #define relock_mc(s) \
835 mwindow->gui->unlock_window(); \
836 cwindow->gui->lock_window("CWindowEditing::" s)
837 #define panel_fn(fn, args, s) \
838 CWindowEditing::fn args { relock_cm(#fn); s; relock_mc(#fn); }
840 // transmit lock to mwindow, and run mbutton->edit_panel->s
841 #define panel_btn(fn, args, s) \
842 panel_fn(panel_##fn, args, mwindow->gui->mbuttons->edit_panel->panel_##s)
845 double CWindowEditing::get_position()
847 relock_cm("get_position");
848 double ret = mwindow->edl->local_session->get_selectionstart(1);
849 relock_mc("get_position");
853 void CWindowEditing::set_position(double position)
855 relock_cm("set_position");
856 mwindow->gui->mbuttons->edit_panel->set_position(position);
857 relock_mc("set_position");
860 void CWindowEditing::set_click_to_play(int v)
862 relock_cm("set_position");
863 mwindow->edl->session->cwindow_click2play = v;
864 relock_mc("set_position");
865 click2play->update(v);
869 void panel_btn(stop_transport,(), stop_transport())
870 void panel_btn(toggle_label,(), toggle_label())
871 void panel_btn(next_label,(int cut), next_label(cut))
872 void panel_btn(prev_label,(int cut), prev_label(cut))
873 void panel_btn(next_edit,(int cut), next_edit(cut))
874 void panel_btn(prev_edit,(int cut), prev_edit(cut))
875 void panel_fn(panel_copy_selection,(), mwindow->copy())
876 void CWindowEditing::panel_overwrite_selection() {} // not used
877 void CWindowEditing::panel_splice_selection() {} // not used
878 void panel_btn(set_inpoint,(), set_inpoint())
879 void panel_btn(set_outpoint,(), set_outpoint())
880 void panel_btn(unset_inoutpoint,(), unset_inoutpoint())
881 void panel_fn(panel_to_clip,(), mwindow->to_clip(mwindow->edl, _("main window: "), 0))
882 void panel_btn(cut,(), cut())
883 void panel_btn(paste,(), paste())
884 void panel_btn(fit_selection,(), fit_selection())
885 void panel_btn(fit_autos,(int all), fit_autos(all))
886 void panel_btn(set_editing_mode,(int mode), set_editing_mode(mode))
887 void panel_btn(set_auto_keyframes,(int v), set_auto_keyframes(v))
888 void panel_btn(set_labels_follow_edits,(int v), set_labels_follow_edits(v))
891 CWindowMeters::CWindowMeters(MWindow *mwindow,
892 CWindowGUI *gui, int x, int y, int h)
893 : MeterPanel(mwindow, gui, x, y, -1, h,
894 mwindow->edl->session->audio_channels,
895 mwindow->edl->session->cwindow_meter,
898 this->mwindow = mwindow;
902 CWindowMeters::~CWindowMeters()
906 int CWindowMeters::change_status_event(int new_status)
908 mwindow->edl->session->cwindow_meter = new_status;
909 gui->update_meters();
916 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
917 : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
918 x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
920 this->mwindow = mwindow;
924 CWindowZoom::~CWindowZoom()
928 void CWindowZoom::update(double value)
930 char string[BCSTRLEN];
931 const char *cp = string;
934 int frac = value >= 1.0f ? 1 :
936 value >= .01f ? 3 : 4;
937 sprintf(string, "x %.*f", frac, value);
941 ZoomPanel::update(cp);
944 int CWindowZoom::handle_event()
946 double value = !strcasecmp(gui->auto_zoom, get_text()) ? 0 : get_value();
947 gui->zoom_canvas(value, 0);
954 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
955 : BC_PercentageSlider(x,
964 this->mwindow = mwindow;
965 this->cwindow = cwindow;
966 set_precision(0.00001);
969 CWindowSlider::~CWindowSlider()
973 int CWindowSlider::handle_event()
975 cwindow->update_position((double)get_value());
979 void CWindowSlider::set_position()
981 double new_length = mwindow->edl->tracks->total_length();
982 update(mwindow->theme->cslider_w,
983 mwindow->edl->local_session->get_selectionstart(1),
988 int CWindowSlider::increase_value()
991 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
992 lock_window("CWindowSlider::increase_value");
996 int CWindowSlider::decrease_value()
999 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
1000 lock_window("CWindowSlider::decrease_value");
1005 // CWindowDestination::CWindowDestination(MWindow *mwindow, CWindowGUI *cwindow, int x, int y)
1006 // : BC_PopupTextBox(cwindow,
1007 // &cwindow->destinations,
1008 // cwindow->destinations.values[cwindow->cwindow->destination]->get_text(),
1014 // this->mwindow = mwindow;
1015 // this->cwindow = cwindow;
1018 // CWindowDestination::~CWindowDestination()
1022 // int CWindowDestination::handle_event()
1026 #endif // USE_SLIDER
1033 CWindowTransport::CWindowTransport(MWindow *mwindow,
1037 : PlayTransport(mwindow,
1045 EDL* CWindowTransport::get_edl()
1047 return mwindow->edl;
1050 void CWindowTransport::goto_start()
1052 gui->unlock_window();
1053 handle_transport(REWIND, 1);
1055 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
1056 mwindow->goto_start();
1057 mwindow->gui->unlock_window();
1059 gui->lock_window("CWindowTransport::goto_start 2");
1062 void CWindowTransport::goto_end()
1064 gui->unlock_window();
1065 handle_transport(GOTO_END, 1);
1067 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
1068 mwindow->goto_end();
1069 mwindow->gui->unlock_window();
1071 gui->lock_window("CWindowTransport::goto_end 2");
1076 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
1079 mwindow->theme->ccanvas_x,
1080 mwindow->theme->ccanvas_y,
1081 mwindow->theme->ccanvas_w,
1082 mwindow->theme->ccanvas_h,
1085 mwindow->edl->session->cwindow_scrollbars)
1087 this->mwindow = mwindow;
1091 void CWindowCanvas::status_event()
1093 gui->draw_status(1);
1096 void CWindowCanvas::update_zoom(int x, int y, float zoom)
1098 use_scrollbars = mwindow->edl->session->cwindow_scrollbars;
1100 mwindow->edl->session->cwindow_xscroll = x;
1101 mwindow->edl->session->cwindow_yscroll = y;
1102 mwindow->edl->session->cwindow_zoom = zoom;
1105 void CWindowCanvas::zoom_auto()
1107 gui->zoom_canvas(0, 1);
1110 int CWindowCanvas::get_xscroll()
1112 return mwindow->edl->session->cwindow_xscroll;
1115 int CWindowCanvas::get_yscroll()
1117 return mwindow->edl->session->cwindow_yscroll;
1121 float CWindowCanvas::get_zoom()
1123 return mwindow->edl->session->cwindow_zoom;
1126 void CWindowCanvas::draw_refresh(int flush)
1128 if( get_canvas() && !get_canvas()->get_video_on() ) {
1130 if( mwindow->uses_opengl() ) {
1131 get_canvas()->unlock_window();
1132 mwindow->playback_3d->finish_output();
1133 get_canvas()->lock_window("CWindowCanvas::draw_refresh");
1134 get_canvas()->flush();
1135 get_canvas()->sync_display();
1137 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
1138 float in_x1, in_y1, in_x2, in_y2;
1139 float out_x1, out_y1, out_x2, out_y2;
1140 get_transfers(mwindow->edl,
1141 in_x1, in_y1, in_x2, in_y2,
1142 out_x1, out_y1, out_x2, out_y2);
1145 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1146 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1149 if( out_x2 > out_x1 && out_y2 > out_y1 &&
1150 in_x2 > in_x1 && in_y2 > in_y1 ) {
1151 // input scaled from session to refresh frame coordinates
1152 int ow = get_output_w(mwindow->edl);
1153 int oh = get_output_h(mwindow->edl);
1154 int rw = refresh_frame->get_w();
1155 int rh = refresh_frame->get_h();
1156 float xs = (float)rw / ow;
1157 float ys = (float)rh / oh;
1158 in_x1 *= xs; in_x2 *= xs;
1159 in_y1 *= ys; in_y2 *= ys;
1160 // Can't use OpenGL here because it is called asynchronously of the
1161 // playback operation.
1162 get_canvas()->draw_vframe(refresh_frame,
1163 (int)out_x1, (int)out_y1,
1164 (int)(out_x2 - out_x1),
1165 (int)(out_y2 - out_y1),
1166 (int)in_x1, (int)in_y1,
1167 (int)(in_x2 - in_x1),
1168 (int)(in_y2 - in_y1),
1174 get_canvas()->flash(flush);
1176 //printf("CWindowCanvas::draw_refresh 10\n");
1179 #define CROPHANDLE_W 10
1180 #define CROPHANDLE_H 10
1182 void CWindowCanvas::draw_crophandle(int x, int y)
1184 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1192 #define CONTROL_W 10
1193 #define CONTROL_H 10
1194 #define FIRST_CONTROL_W 20
1195 #define FIRST_CONTROL_H 20
1197 #define BC_INFINITY 65536
1199 #define RULERHANDLE_W 16
1200 #define RULERHANDLE_H 16
1204 int CWindowCanvas::do_ruler(int draw,
1210 float x1 = mwindow->edl->session->ruler_x1;
1211 float y1 = mwindow->edl->session->ruler_y1;
1212 float x2 = mwindow->edl->session->ruler_x2;
1213 float y2 = mwindow->edl->session->ruler_y2;
1214 float canvas_x1 = x1;
1215 float canvas_y1 = y1;
1216 float canvas_x2 = x2;
1217 float canvas_y2 = y2;
1218 float output_x = get_cursor_x();
1219 float output_y = get_cursor_y();
1220 float canvas_cursor_x = output_x;
1221 float canvas_cursor_y = output_y;
1223 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1224 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1225 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1226 mwindow->session->cwindow_output_x = roundf(output_x);
1227 mwindow->session->cwindow_output_y = roundf(output_y);
1229 if(button_press && get_buttonpress() == 1)
1231 gui->ruler_handle = -1;
1232 gui->ruler_translate = 0;
1235 gui->ruler_translate = 1;
1236 gui->ruler_origin_x = x1;
1237 gui->ruler_origin_y = y1;
1240 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1241 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1242 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1243 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1245 gui->ruler_handle = 0;
1246 gui->ruler_origin_x = x1;
1247 gui->ruler_origin_y = y1;
1250 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1251 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1252 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1253 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1255 gui->ruler_handle = 1;
1256 gui->ruler_origin_x = x2;
1257 gui->ruler_origin_y = y2;
1261 // Start new selection
1262 if(!gui->ruler_translate &&
1263 (gui->ruler_handle < 0 ||
1268 do_ruler(1, 0, 0, 0);
1269 get_canvas()->flash();
1270 gui->ruler_handle = 1;
1271 mwindow->edl->session->ruler_x1 = output_x;
1272 mwindow->edl->session->ruler_y1 = output_y;
1273 mwindow->edl->session->ruler_x2 = output_x;
1274 mwindow->edl->session->ruler_y2 = output_y;
1275 gui->ruler_origin_x = mwindow->edl->session->ruler_x2;
1276 gui->ruler_origin_y = mwindow->edl->session->ruler_y2;
1279 gui->x_origin = output_x;
1280 gui->y_origin = output_y;
1281 gui->current_operation = CWINDOW_RULER;
1282 gui->tool_panel->raise_window();
1288 if(gui->current_operation == CWINDOW_RULER)
1290 if(gui->ruler_translate)
1293 do_ruler(1, 0, 0, 0);
1294 float x_difference = mwindow->edl->session->ruler_x1;
1295 float y_difference = mwindow->edl->session->ruler_y1;
1296 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1297 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1298 x_difference -= mwindow->edl->session->ruler_x1;
1299 y_difference -= mwindow->edl->session->ruler_y1;
1300 mwindow->edl->session->ruler_x2 -= x_difference;
1301 mwindow->edl->session->ruler_y2 -= y_difference;
1303 do_ruler(1, 0, 0, 0);
1304 get_canvas()->flash();
1308 switch(gui->ruler_handle)
1311 do_ruler(1, 0, 0, 0);
1312 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1313 mwindow->edl->session->ruler_y1 = 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_y1 = mwindow->edl->session->ruler_y2;
1327 if(angle_value > 67)
1328 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2;
1330 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 &&
1331 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1333 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1334 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1337 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 && mwindow->edl->session->ruler_y1 > mwindow->edl->session->ruler_y2)
1339 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1340 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1343 if(mwindow->edl->session->ruler_x1 > mwindow->edl->session->ruler_x2 &&
1344 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1346 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1347 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1351 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1352 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1355 do_ruler(1, 0, 0, 0);
1356 get_canvas()->flash();
1361 do_ruler(1, 0, 0, 0);
1362 mwindow->edl->session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1363 mwindow->edl->session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1364 if(gui->alt_down() || gui->ctrl_down())
1366 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1367 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1371 double distance_value =
1372 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1373 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1374 if(angle_value < 22)
1375 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1;
1377 if(angle_value > 67)
1378 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1;
1380 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1381 mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1383 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1384 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1387 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1388 mwindow->edl->session->ruler_y2 > mwindow->edl->session->ruler_y1)
1390 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1391 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1394 if(mwindow->edl->session->ruler_x2 > mwindow->edl->session->ruler_x1 && mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1396 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1397 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1401 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1402 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1405 do_ruler(1, 0, 0, 0);
1406 get_canvas()->flash();
1410 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1414 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1419 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1420 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1421 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1422 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1424 set_cursor(UPRIGHT_ARROW_CURSOR);
1427 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1428 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1429 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1430 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1432 set_cursor(UPRIGHT_ARROW_CURSOR);
1435 set_cursor(CROSS_CURSOR);
1437 // Update current position
1442 // Assume no ruler measurement if 0 length
1443 if(draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)))
1445 get_canvas()->set_inverse();
1446 get_canvas()->set_color(WHITE);
1447 get_canvas()->draw_line((int)canvas_x1,
1451 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1453 roundf(canvas_x1) + RULERHANDLE_W / 2,
1455 get_canvas()->draw_line(roundf(canvas_x1),
1456 roundf(canvas_y1) - RULERHANDLE_H / 2,
1458 roundf(canvas_y1) + RULERHANDLE_H / 2);
1459 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1461 roundf(canvas_x2) + RULERHANDLE_W / 2,
1463 get_canvas()->draw_line(roundf(canvas_x2),
1464 roundf(canvas_y2) - RULERHANDLE_H / 2,
1466 roundf(canvas_y2) + RULERHANDLE_H / 2);
1467 get_canvas()->set_opaque();
1474 static inline double line_dist(float cx,float cy, float tx,float ty)
1476 double dx = tx-cx, dy = ty-cy;
1477 return sqrt(dx*dx + dy*dy);
1480 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1482 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1483 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1487 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1488 int button_press, int cursor_motion, int draw)
1490 // Retrieve points from top recordable track
1491 //printf("CWindowCanvas::do_mask 1\n");
1492 Track *track = gui->cwindow->calculate_affected_track();
1493 //printf("CWindowCanvas::do_mask 2\n");
1495 if(!track) return 0;
1496 //printf("CWindowCanvas::do_mask 3\n");
1498 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1499 int64_t position = track->to_units(
1500 mwindow->edl->local_session->get_selectionstart(1),
1502 ArrayList<MaskPoint*> points;
1504 // Determine the points based on whether
1505 // new keyframes will be generated or drawing is performed.
1506 // If keyframe generation occurs, use the interpolated mask.
1507 // If no keyframe generation occurs, use the previous mask.
1508 int use_interpolated = 0;
1509 if(button_press || cursor_motion) {
1510 #ifdef USE_KEYFRAME_SPANNING
1511 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1512 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1515 mask_autos->get_prev_auto(track->to_units(selection_start, 0),
1516 PLAY_FORWARD, first, 1);
1518 mask_autos->get_prev_auto(track->to_units(selection_end, 0),
1519 PLAY_FORWARD, last, 1);
1521 if(last == first && (!mwindow->edl->session->auto_keyframes))
1522 use_interpolated = 0;
1524 // If keyframe spanning occurs, use the interpolated points.
1525 // If new keyframe is generated, use the interpolated points.
1526 use_interpolated = 1;
1529 if(mwindow->edl->session->auto_keyframes)
1530 use_interpolated = 1;
1534 use_interpolated = 1;
1536 if(use_interpolated) {
1537 // Interpolate the points to get exactly what is being rendered at this position.
1538 mask_autos->get_points(&points,
1539 mwindow->edl->session->cwindow_mask,
1544 // Use the prev mask
1546 mask_autos->get_prev_auto(position,
1550 ((MaskAuto*)prev)->get_points(&points,
1551 mwindow->edl->session->cwindow_mask);
1554 // Projector zooms relative to the center of the track output.
1555 float half_track_w = (float)track->track_w / 2;
1556 float half_track_h = (float)track->track_h / 2;
1557 // Translate mask to projection
1558 float projector_x, projector_y, projector_z;
1559 track->automation->get_projector(
1560 &projector_x, &projector_y, &projector_z,
1561 position, PLAY_FORWARD);
1564 // Get position of cursor relative to mask
1565 float cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
1566 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1567 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1569 projector_x += mwindow->edl->session->output_w / 2;
1570 projector_y += mwindow->edl->session->output_h / 2;
1571 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1572 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1574 // Fix cursor origin
1576 gui->x_origin = mask_cursor_x;
1577 gui->y_origin = mask_cursor_y;
1581 // Points of closest line
1582 int shortest_point1 = -1;
1583 int shortest_point2 = -1;
1585 int shortest_point = -1;
1586 // Distance to closest line
1587 float shortest_line_distance = BC_INFINITY;
1588 // Distance to closest point
1589 float shortest_point_distance = BC_INFINITY;
1590 int selected_point = -1;
1591 int selected_control_point = -1;
1592 float selected_control_point_distance = BC_INFINITY;
1593 ArrayList<int> x_points;
1594 ArrayList<int> y_points;
1596 if(!cursor_motion) {
1598 get_canvas()->set_color(WHITE);
1599 get_canvas()->set_inverse();
1601 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1603 // Never draw closed polygon and a closed
1604 // polygon is harder to add points to.
1605 for(int i = 0; i < points.size() && !result; i++) {
1606 MaskPoint *point1 = points.get(i);
1607 MaskPoint *point2 = (i >= points.size() - 1) ?
1608 points.get(0) : points.get(i + 1);
1610 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1611 if(point_distance1 < shortest_point_distance || shortest_point < 0) {
1612 shortest_point_distance = point_distance1;
1616 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1617 if(point_distance2 < shortest_point_distance || shortest_point < 0) {
1618 shortest_point_distance = point_distance2;
1619 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1623 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1625 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1626 //point1->x, point1->y, point2->x, point2->y, projector_z);
1627 for(int j = 0; j <= segments && !result; j++) {
1628 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1629 float x0 = point1->x, y0 = point1->y;
1630 float x1 = point1->x + point1->control_x2;
1631 float y1 = point1->y + point1->control_y2;
1632 float x2 = point2->x + point2->control_x1;
1633 float y2 = point2->y + point2->control_y1;
1634 float x3 = point2->x, y3 = point2->y;
1635 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1636 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1637 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1638 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1639 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1640 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1641 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1642 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1644 float t = (float)j / segments;
1645 float tpow2 = t * t;
1646 float tpow3 = t * t * t;
1648 float invtpow2 = invt * invt;
1649 float invtpow3 = invt * invt * invt;
1651 float x = ( invtpow3 * x0
1652 + 3 * t * invtpow2 * x1
1653 + 3 * tpow2 * invt * x2
1655 float y = ( invtpow3 * y0
1656 + 3 * t * invtpow2 * y1
1657 + 3 * tpow2 * invt * y2
1659 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1660 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1661 // Test new point addition
1663 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1665 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1666 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1667 if(line_distance < shortest_line_distance ||
1668 shortest_point1 < 0) {
1669 shortest_line_distance = line_distance;
1670 shortest_point1 = i;
1671 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1672 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1673 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1676 // Test existing point selection
1678 if(gui->ctrl_down()) {
1679 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1681 if(distance < selected_control_point_distance) {
1683 selected_control_point = 1;
1684 selected_control_point_distance = distance;
1688 if(!gui->shift_down()) {
1689 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1690 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
1695 selected_point = shortest_point;
1698 // Test second point
1699 if(gui->ctrl_down()) {
1700 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1702 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1703 if(distance < selected_control_point_distance) {
1704 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1705 selected_control_point = 0;
1706 selected_control_point_distance = distance;
1709 else if(i < points.size() - 1) {
1710 if(!gui->shift_down()) {
1711 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1712 if(test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3)) {
1713 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1717 selected_point = shortest_point;
1722 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1726 if(draw) { // Draw joining line
1727 x_points.append((int)canvas_x);
1728 y_points.append((int)canvas_y);
1732 if(draw) { // Draw second anchor
1733 if(i < points.size() - 1) {
1734 if(i == gui->affected_point - 1)
1735 get_canvas()->draw_disc(
1736 (int)canvas_x - CONTROL_W / 2,
1737 (int)canvas_y - CONTROL_W / 2,
1738 CONTROL_W, CONTROL_H);
1740 get_canvas()->draw_circle(
1741 (int)canvas_x - CONTROL_W / 2,
1742 (int)canvas_y - CONTROL_W / 2,
1743 CONTROL_W, CONTROL_H);
1744 // char string[BCTEXTLEN];
1745 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1746 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1748 // Draw second control point.
1749 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1750 get_canvas()->draw_line(
1751 (int)canvas_x, (int)canvas_y,
1752 (int)canvas_x2, (int)canvas_y2);
1753 get_canvas()->draw_rectangle(
1754 (int)canvas_x2 - CONTROL_W / 2,
1755 (int)canvas_y2 - CONTROL_H / 2,
1756 CONTROL_W, CONTROL_H);
1761 // Draw first anchor
1762 if(i == 0 && draw) {
1763 char mask_label[BCSTRLEN];
1764 sprintf(mask_label, "%d",
1765 mwindow->edl->session->cwindow_mask);
1766 get_canvas()->draw_text(
1767 (int)canvas_x - FIRST_CONTROL_W,
1768 (int)canvas_y - FIRST_CONTROL_H,
1771 get_canvas()->draw_disc(
1772 (int)canvas_x - FIRST_CONTROL_W / 2,
1773 (int)canvas_y - FIRST_CONTROL_H / 2,
1774 FIRST_CONTROL_W, FIRST_CONTROL_H);
1777 // Draw first control point.
1779 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1780 get_canvas()->draw_line(
1781 (int)canvas_x, (int)canvas_y,
1782 (int)canvas_x1, (int)canvas_y1);
1783 get_canvas()->draw_rectangle(
1784 (int)canvas_x1 - CONTROL_W / 2,
1785 (int)canvas_y1 - CONTROL_H / 2,
1786 CONTROL_W, CONTROL_H);
1788 x_points.append((int)canvas_x);
1789 y_points.append((int)canvas_y);
1792 //printf("CWindowCanvas::do_mask 1\n");
1796 //printf("CWindowCanvas::do_mask 1\n");
1799 get_canvas()->draw_polygon(&x_points, &y_points);
1800 get_canvas()->set_opaque();
1802 //printf("CWindowCanvas::do_mask 1\n");
1805 if(button_press && !result) {
1806 gui->affected_track = gui->cwindow->calculate_affected_track();
1808 // Get keyframe outside the EDL to edit. This must be rendered
1809 // instead of the EDL keyframes when it exists. Then it must be
1810 // applied to the EDL keyframes on buttonrelease.
1811 if(gui->affected_track) {
1812 #ifdef USE_KEYFRAME_SPANNING
1813 // Make copy of current parameters in local keyframe
1814 gui->mask_keyframe =
1815 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1818 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1821 gui->mask_keyframe =
1822 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1827 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1830 // Translate entire keyframe
1831 if(gui->alt_down() && mask->points.size()) {
1832 mwindow->undo->update_undo_before(_("mask translate"), 0);
1833 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1834 gui->affected_point = 0;
1837 // Existing point or control point was selected
1838 if(selected_point >= 0) {
1839 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1840 gui->affected_point = selected_point;
1842 if(selected_control_point == 0)
1843 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1845 if(selected_control_point == 1)
1846 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1848 gui->current_operation = mwindow->edl->session->cwindow_operation;
1850 else // No existing point or control point was selected so create a new one
1851 if(!gui->ctrl_down() && !gui->alt_down()) {
1852 mwindow->undo->update_undo_before(_("mask point"), 0);
1853 // Create the template
1854 MaskPoint *point = new MaskPoint;
1855 point->x = mask_cursor_x;
1856 point->y = mask_cursor_y;
1857 point->control_x1 = 0;
1858 point->control_y1 = 0;
1859 point->control_x2 = 0;
1860 point->control_y2 = 0;
1863 if(shortest_point2 < shortest_point1) {
1864 shortest_point2 ^= shortest_point1;
1865 shortest_point1 ^= shortest_point2;
1866 shortest_point2 ^= shortest_point1;
1871 // printf("CWindowGUI::do_mask 40\n");
1872 // mwindow->edl->dump();
1873 // printf("CWindowGUI::do_mask 50\n");
1877 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1878 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1879 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1881 // Append to end of list
1882 if( shortest_point1 == shortest_point2 ||
1883 labs(shortest_point1 - shortest_point2) > 1) {
1884 #ifdef USE_KEYFRAME_SPANNING
1886 MaskPoint *new_point = new MaskPoint;
1887 points.append(new_point);
1888 *new_point = *point;
1889 gui->affected_point = points.size() - 1;
1893 // Need to apply the new point to every keyframe
1894 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1895 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1896 MaskPoint *new_point = new MaskPoint;
1897 submask->points.append(new_point);
1898 *new_point = *point;
1899 if(current == (MaskAuto*)mask_autos->default_auto)
1900 current = (MaskAuto*)mask_autos->first;
1902 current = (MaskAuto*)NEXT;
1904 gui->affected_point = mask->points.size() - 1;
1910 // Insert between 2 points, shifting back point 2
1911 if(shortest_point1 >= 0 && shortest_point2 >= 0) {
1913 #ifdef USE_KEYFRAME_SPANNING
1914 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1916 if(points.size() >= shortest_point2) {
1917 MaskPoint *new_point = new MaskPoint;
1919 for(int i = points.size() - 1;
1920 i > shortest_point2;
1922 points.values[i] = points.values[i - 1];
1923 points.values[shortest_point2] = new_point;
1925 *new_point = *point;
1930 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1931 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1932 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1934 if(submask->points.size() >= shortest_point2) {
1935 MaskPoint *new_point = new MaskPoint;
1936 submask->points.append(0);
1937 for(int i = submask->points.size() - 1;
1938 i > shortest_point2;
1940 submask->points.values[i] = submask->points.values[i - 1];
1941 submask->points.values[shortest_point2] = new_point;
1943 *new_point = *point;
1946 if(current == (MaskAuto*)mask_autos->default_auto)
1947 current = (MaskAuto*)mask_autos->first;
1949 current = (MaskAuto*)NEXT;
1953 gui->affected_point = shortest_point2;
1958 // printf("CWindowGUI::do_mask 20\n");
1959 // mwindow->edl->dump();
1960 // printf("CWindowGUI::do_mask 30\n");
1963 //printf("CWindowCanvas::do_mask 1\n");
1964 // Create the first point.
1965 #ifdef USE_KEYFRAME_SPANNING
1966 MaskPoint *new_point = new MaskPoint;
1967 points.append(new_point);
1968 *new_point = *point;
1969 gui->affected_point = points.size() - 1;
1971 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1972 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1973 MaskPoint *new_point = new MaskPoint;
1974 submask->points.append(new_point);
1975 *new_point = *point;
1976 if(current == (MaskAuto*)mask_autos->default_auto)
1977 current = (MaskAuto*)mask_autos->first;
1979 current = (MaskAuto*)NEXT;
1981 gui->affected_point = points.size() - 1;
1984 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
1987 gui->current_operation = mwindow->edl->session->cwindow_operation;
1988 // Delete the template
1997 if(button_press && result) {
1998 #ifdef USE_KEYFRAME_SPANNING
1999 MaskPoint *point = points.values[gui->affected_point];
2000 gui->center_x = point->x;
2001 gui->center_y = point->y;
2002 gui->control_in_x = point->control_x1;
2003 gui->control_in_y = point->control_y1;
2004 gui->control_out_x = point->control_x2;
2005 gui->control_out_y = point->control_y2;
2006 gui->tool_panel->raise_window();
2008 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
2009 MaskPoint *point = mask->points.values[gui->affected_point];
2010 gui->center_x = point->x;
2011 gui->center_y = point->y;
2012 gui->control_in_x = point->control_x1;
2013 gui->control_in_y = point->control_y1;
2014 gui->control_out_x = point->control_x2;
2015 gui->control_out_y = point->control_y2;
2016 gui->tool_panel->raise_window();
2020 //printf("CWindowCanvas::do_mask 8\n");
2023 #ifdef USE_KEYFRAME_SPANNING
2024 // Must update the reference keyframes for every cursor motion
2025 gui->mask_keyframe =
2026 (MaskAuto*)gui->cwindow->calculate_affected_auto(
2029 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
2032 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2034 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
2035 if( gui->affected_point >= 0 && gui->affected_point < mask->points.size() &&
2036 gui->current_operation != CWINDOW_NONE) {
2037 // mwindow->undo->update_undo_before(_("mask point"), this);
2038 #ifdef USE_KEYFRAME_SPANNING
2039 MaskPoint *point = points.get(gui->affected_point);
2041 MaskPoint *point = mask->points.get(gui->affected_point);
2043 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2044 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask->points.size(), gui->affected_point);
2046 float last_x = point->x;
2047 float last_y = point->y;
2048 float last_control_x1 = point->control_x1;
2049 float last_control_y1 = point->control_y1;
2050 float last_control_x2 = point->control_x2;
2051 float last_control_y2 = point->control_y2;
2053 switch(gui->current_operation) {
2055 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2056 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
2057 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
2060 case CWINDOW_MASK_CONTROL_IN:
2061 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
2062 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
2065 case CWINDOW_MASK_CONTROL_OUT:
2066 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
2067 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
2070 case CWINDOW_MASK_TRANSLATE:
2071 #ifdef USE_KEYFRAME_SPANNING
2072 for(int i = 0; i < points.size(); i++) {
2073 points.values[i]->x += mask_cursor_x - gui->x_origin;
2074 points.values[i]->y += mask_cursor_y - gui->y_origin;
2077 for(int i = 0; i < mask->points.size(); i++) {
2078 mask->points.values[i]->x += mask_cursor_x - gui->x_origin;
2079 mask->points.values[i]->y += mask_cursor_y - gui->y_origin;
2082 gui->x_origin = mask_cursor_x;
2083 gui->y_origin = mask_cursor_y;
2087 if( !EQUIV(last_x, point->x) ||
2088 !EQUIV(last_y, point->y) ||
2089 !EQUIV(last_control_x1, point->control_x1) ||
2090 !EQUIV(last_control_y1, point->control_y1) ||
2091 !EQUIV(last_control_x2, point->control_x2) ||
2092 !EQUIV(last_control_y2, point->control_y2)) {
2098 if(gui->current_operation == CWINDOW_NONE) {
2099 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
2101 for(int i = 0; i < points.size() && !over_point; i++) {
2102 MaskPoint *point = points.get(i);
2103 float x0 = point->x;
2104 float y0 = point->y;
2105 float x1 = point->x + point->control_x1;
2106 float y1 = point->y + point->control_y1;
2107 float x2 = point->x + point->control_x2;
2108 float y2 = point->y + point->control_y2;
2109 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
2110 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
2112 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
2113 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
2117 if(!over_point && gui->ctrl_down()) {
2118 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
2119 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
2120 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2121 if(test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1)) {
2125 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2126 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2127 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2128 if(test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2)) {
2135 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2140 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2143 #ifdef USE_KEYFRAME_SPANNING
2144 // Must commit change after operation.
2145 if(rerender && track) {
2146 // Swap EDL keyframe with original.
2147 // Apply new values to keyframe span
2148 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2149 temp_keyframe.copy_data(gui->mask_keyframe);
2150 // Apply interpolated points back to keyframe
2151 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2152 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2153 mask_autos->update_parameter(&temp_keyframe);
2157 points.remove_all_objects();
2158 //printf("CWindowCanvas::do_mask 20\n");
2162 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2165 int radius = mwindow->edl->session->eyedrop_radius;
2173 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2178 row1 = gui->eyedrop_y - radius;
2179 row2 = gui->eyedrop_y + radius;
2180 column1 = gui->eyedrop_x - radius;
2181 column2 = gui->eyedrop_x + radius;
2183 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2184 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2185 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2186 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2188 if(row2 <= row1) row2 = row1 + 1;
2189 if(column2 <= column1) column2 = column1 + 1;
2196 output_to_canvas(mwindow->edl, 0, x1, y1);
2197 output_to_canvas(mwindow->edl, 0, x2, y2);
2198 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2200 if(x2 - x1 >= 1 && y2 - y1 >= 1)
2202 get_canvas()->set_inverse();
2203 get_canvas()->set_color(WHITE);
2205 get_canvas()->draw_rectangle((int)x1,
2210 get_canvas()->set_opaque();
2211 get_canvas()->flash();
2219 gui->current_operation = CWINDOW_EYEDROP;
2220 gui->tool_panel->raise_window();
2223 if(gui->current_operation == CWINDOW_EYEDROP)
2225 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2227 // Get color out of frame.
2228 // Doesn't work during playback because that bypasses the refresh frame.
2229 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2231 float cursor_x = get_cursor_x();
2232 float cursor_y = get_cursor_y();
2233 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2234 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2235 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2237 row1 = cursor_y - radius;
2238 row2 = cursor_y + radius;
2239 column1 = cursor_x - radius;
2240 column2 = cursor_x + radius;
2241 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2242 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2243 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2244 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2245 if(row2 <= row1) row2 = row1 + 1;
2246 if(column2 <= column1) column2 = column1 + 1;
2250 if(gui->eyedrop_visible)
2253 do_eyedrop(temp, 0, 1);
2254 gui->eyedrop_visible = 0;
2257 gui->eyedrop_x = cursor_x;
2258 gui->eyedrop_y = cursor_y;
2263 do_eyedrop(temp, 0, 1);
2264 gui->eyedrop_visible = 1;
2267 // Decompression coefficients straight out of jpeglib
2268 #define V_TO_R 1.40200
2269 #define V_TO_G -0.71414
2271 #define U_TO_G -0.34414
2272 #define U_TO_B 1.77200
2274 #define GET_COLOR(type, components, max, do_yuv) \
2276 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2278 float red = (float)*row++ / max; \
2279 float green = (float)*row++ / max; \
2280 float blue = (float)*row++ / max; \
2283 float r = red + V_TO_R * (blue - 0.5); \
2284 float g = red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
2285 float b = red + U_TO_B * (green - 0.5); \
2286 mwindow->edl->local_session->red += r; \
2287 mwindow->edl->local_session->green += g; \
2288 mwindow->edl->local_session->blue += b; \
2289 if(r > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = r; \
2290 if(g > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = g; \
2291 if(b > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = b; \
2295 mwindow->edl->local_session->red += red; \
2296 mwindow->edl->local_session->green += green; \
2297 mwindow->edl->local_session->blue += blue; \
2298 if(red > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = red; \
2299 if(green > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = green; \
2300 if(blue > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = blue; \
2306 mwindow->edl->local_session->red = 0;
2307 mwindow->edl->local_session->green = 0;
2308 mwindow->edl->local_session->blue = 0;
2309 mwindow->edl->local_session->red_max = 0;
2310 mwindow->edl->local_session->green_max = 0;
2311 mwindow->edl->local_session->blue_max = 0;
2312 for(int i = row1; i < row2; i++)
2314 for(int j = column1; j < column2; j++)
2316 switch(refresh_frame->get_color_model())
2319 GET_COLOR(unsigned char, 3, 0xff, 1);
2322 GET_COLOR(unsigned char, 4, 0xff, 1);
2325 GET_COLOR(uint16_t, 3, 0xffff, 1);
2327 case BC_YUVA16161616:
2328 GET_COLOR(uint16_t, 4, 0xffff, 1);
2331 GET_COLOR(unsigned char, 3, 0xff, 0);
2334 GET_COLOR(unsigned char, 4, 0xff, 0);
2337 GET_COLOR(float, 3, 1.0, 0);
2340 GET_COLOR(float, 4, 1.0, 0);
2346 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2347 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2348 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2353 mwindow->edl->local_session->red = 0;
2354 mwindow->edl->local_session->green = 0;
2355 mwindow->edl->local_session->blue = 0;
2356 gui->eyedrop_visible = 0;
2365 // Can't rerender since the color value is from the output of any effect it
2368 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2374 int CWindowCanvas::need_overlays()
2376 if( mwindow->edl->session->safe_regions ) return 1;
2377 if( mwindow->edl->session->cwindow_scrollbars ) return 1;
2378 if( gui->highlighted ) return 1;
2379 switch( mwindow->edl->session->cwindow_operation ) {
2380 case CWINDOW_EYEDROP:
2381 if( ! gui->eyedrop_visible ) break;
2382 case CWINDOW_CAMERA:
2383 case CWINDOW_PROJECTOR:
2392 void CWindowCanvas::draw_overlays()
2394 if(mwindow->edl->session->safe_regions)
2396 draw_safe_regions();
2399 if(mwindow->edl->session->cwindow_scrollbars)
2401 // Always draw output rectangle
2402 float x1, y1, x2, y2;
2404 x2 = mwindow->edl->session->output_w;
2406 y2 = mwindow->edl->session->output_h;
2407 output_to_canvas(mwindow->edl, 0, x1, y1);
2408 output_to_canvas(mwindow->edl, 0, x2, y2);
2410 get_canvas()->set_inverse();
2411 get_canvas()->set_color(WHITE);
2413 get_canvas()->draw_rectangle((int)x1,
2418 get_canvas()->set_opaque();
2421 if(gui->highlighted)
2423 get_canvas()->set_color(WHITE);
2424 get_canvas()->set_inverse();
2425 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2426 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2427 get_canvas()->set_opaque();
2430 int temp1 = 0, temp2 = 0;
2431 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2432 switch(mwindow->edl->session->cwindow_operation)
2434 case CWINDOW_CAMERA:
2438 case CWINDOW_PROJECTOR:
2447 do_mask(temp1, temp2, 0, 0, 1);
2451 do_ruler(1, 0, 0, 0);
2454 case CWINDOW_EYEDROP:
2455 if(gui->eyedrop_visible)
2458 do_eyedrop(rerender, 0, 1);
2459 gui->eyedrop_visible = 1;
2465 void CWindowCanvas::draw_safe_regions()
2467 float action_x1, action_x2, action_y1, action_y2;
2468 float title_x1, title_x2, title_y1, title_y2;
2470 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2471 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2472 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2473 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2474 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2475 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2476 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2477 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2479 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2480 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2481 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2482 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2484 get_canvas()->set_inverse();
2485 get_canvas()->set_color(WHITE);
2487 get_canvas()->draw_rectangle((int)action_x1,
2489 (int)(action_x2 - action_x1),
2490 (int)(action_y2 - action_y1));
2491 get_canvas()->draw_rectangle((int)title_x1,
2493 (int)(title_x2 - title_x1),
2494 (int)(title_y2 - title_y1));
2496 get_canvas()->set_opaque();
2500 void CWindowCanvas::create_keyframe(int do_camera)
2502 Track *affected_track = gui->cwindow->calculate_affected_track();
2503 if( affected_track ) {
2504 double pos = mwindow->edl->local_session->get_selectionstart(1);
2505 int64_t position = affected_track->to_units(pos, 0);
2506 int ix = do_camera ? AUTOMATION_CAMERA_X : AUTOMATION_PROJECTOR_X;
2507 int iy = do_camera ? AUTOMATION_CAMERA_Y : AUTOMATION_PROJECTOR_Y;
2508 int iz = do_camera ? AUTOMATION_CAMERA_Z : AUTOMATION_PROJECTOR_Z;
2509 FloatAuto *prev, *next;
2510 FloatAutos **autos = (FloatAutos**)affected_track->automation->autos;
2511 FloatAutos *x_autos = autos[ix]; prev = 0; next = 0;
2512 float x_value = x_autos->get_value(position, PLAY_FORWARD, prev, next);
2513 FloatAutos *y_autos = autos[iy]; prev = 0; next = 0;
2514 float y_value = y_autos->get_value(position, PLAY_FORWARD, prev, next);
2515 FloatAutos *z_autos = autos[iz]; prev = 0; next = 0;
2516 float z_value = z_autos->get_value(position, PLAY_FORWARD, prev, next);
2517 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2519 gui->cwindow->calculate_affected_autos(affected_track,
2520 &x_keyframe, &y_keyframe, &z_keyframe,
2521 do_camera, -1, -1, -1, 0);
2522 x_keyframe->set_value(x_value);
2523 y_keyframe->set_value(y_value);
2524 z_keyframe->set_value(z_value);
2526 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2530 void CWindowCanvas::camera_keyframe() { create_keyframe(1); }
2531 void CWindowCanvas::projector_keyframe() { create_keyframe(0); }
2533 void CWindowCanvas::reset_keyframe(int do_camera)
2535 Track *affected_track = gui->cwindow->calculate_affected_track();
2536 if( affected_track ) {
2537 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2538 gui->cwindow->calculate_affected_autos(affected_track,
2539 &x_keyframe, &y_keyframe, &z_keyframe,
2540 do_camera, 1, 1, 1);
2542 x_keyframe->set_value(0);
2543 y_keyframe->set_value(0);
2544 z_keyframe->set_value(1);
2546 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2550 void CWindowCanvas::reset_camera() { reset_keyframe(1); }
2551 void CWindowCanvas::reset_projector() { reset_keyframe(0); }
2554 int CWindowCanvas::test_crop(int button_press, int &redraw)
2557 int handle_selected = -1;
2558 float x1 = mwindow->edl->session->crop_x1;
2559 float y1 = mwindow->edl->session->crop_y1;
2560 float x2 = mwindow->edl->session->crop_x2;
2561 float y2 = mwindow->edl->session->crop_y2;
2562 float cursor_x = get_cursor_x();
2563 float cursor_y = get_cursor_y();
2564 float canvas_x1 = x1;
2565 float canvas_y1 = y1;
2566 float canvas_x2 = x2;
2567 float canvas_y2 = y2;
2568 float canvas_cursor_x = cursor_x;
2569 float canvas_cursor_y = cursor_y;
2571 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2572 // Use screen normalized coordinates for hot spot tests.
2573 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2574 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2577 if(gui->current_operation == CWINDOW_CROP)
2579 handle_selected = gui->crop_handle;
2582 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2583 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2585 handle_selected = 0;
2586 gui->crop_origin_x = x1;
2587 gui->crop_origin_y = y1;
2590 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2591 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2593 handle_selected = 1;
2594 gui->crop_origin_x = x2;
2595 gui->crop_origin_y = y1;
2598 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2599 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2601 handle_selected = 2;
2602 gui->crop_origin_x = x1;
2603 gui->crop_origin_y = y2;
2606 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2607 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2609 handle_selected = 3;
2610 gui->crop_origin_x = x2;
2611 gui->crop_origin_y = y2;
2616 gui->crop_origin_x = cursor_x;
2617 gui->crop_origin_y = cursor_y;
2620 // printf("test crop %d %d\n",
2621 // gui->current_operation,
2622 // handle_selected);
2629 gui->crop_translate = 1;
2630 gui->crop_origin_x1 = x1;
2631 gui->crop_origin_y1 = y1;
2632 gui->crop_origin_x2 = x2;
2633 gui->crop_origin_y2 = y2;
2636 gui->crop_translate = 0;
2638 gui->current_operation = CWINDOW_CROP;
2639 gui->crop_handle = handle_selected;
2640 gui->x_origin = cursor_x;
2641 gui->y_origin = cursor_y;
2642 gui->tool_panel->raise_window();
2645 if(handle_selected < 0 && !gui->crop_translate)
2649 mwindow->edl->session->crop_x1 = (int)x1;
2650 mwindow->edl->session->crop_y1 = (int)y1;
2651 mwindow->edl->session->crop_x2 = (int)x2;
2652 mwindow->edl->session->crop_y2 = (int)y2;
2657 // Translate all 4 points
2658 if(gui->current_operation == CWINDOW_CROP && gui->crop_translate)
2660 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2661 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2662 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2663 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2665 mwindow->edl->session->crop_x1 = (int)x1;
2666 mwindow->edl->session->crop_y1 = (int)y1;
2667 mwindow->edl->session->crop_x2 = (int)x2;
2668 mwindow->edl->session->crop_y2 = (int)y2;
2674 if(gui->current_operation == CWINDOW_CROP)
2676 switch(gui->crop_handle)
2679 x1 = gui->crop_origin_x;
2680 y1 = gui->crop_origin_y;
2681 x2 = gui->crop_origin_x;
2682 y2 = gui->crop_origin_y;
2683 if(cursor_x < gui->x_origin)
2685 if(cursor_y < gui->y_origin)
2691 if(cursor_y >= gui->y_origin)
2698 if(cursor_x >= gui->x_origin)
2700 if(cursor_y < gui->y_origin)
2706 if(cursor_y >= gui->y_origin)
2713 // printf("test crop %d %d %d %d\n",
2714 // mwindow->edl->session->crop_x1,
2715 // mwindow->edl->session->crop_y1,
2716 // mwindow->edl->session->crop_x2,
2717 // mwindow->edl->session->crop_y2);
2720 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2721 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2724 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2725 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2728 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2729 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2732 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2733 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2737 if(!EQUIV(mwindow->edl->session->crop_x1, x1) ||
2738 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2739 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2740 !EQUIV(mwindow->edl->session->crop_y2, y2))
2747 switch (gui->crop_handle)
2749 case 0: gui->crop_handle = 1; break;
2750 case 1: gui->crop_handle = 0; break;
2751 case 2: gui->crop_handle = 3; break;
2752 case 3: gui->crop_handle = 2; break;
2762 switch (gui->crop_handle)
2764 case 0: gui->crop_handle = 2; break;
2765 case 1: gui->crop_handle = 3; break;
2766 case 2: gui->crop_handle = 0; break;
2767 case 3: gui->crop_handle = 1; break;
2772 mwindow->edl->session->crop_x1 = (int)x1;
2773 mwindow->edl->session->crop_y1 = (int)y1;
2774 mwindow->edl->session->crop_x2 = (int)x2;
2775 mwindow->edl->session->crop_y2 = (int)y2;
2781 // Update cursor font
2782 if(handle_selected >= 0)
2784 switch(handle_selected)
2787 set_cursor(UPLEFT_RESIZE);
2790 set_cursor(UPRIGHT_RESIZE);
2793 set_cursor(DOWNLEFT_RESIZE);
2796 set_cursor(DOWNRIGHT_RESIZE);
2803 set_cursor(ARROW_CURSOR);
2805 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2809 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2810 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2811 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2812 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2813 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2814 // mwindow->edl->session->crop_x2,
2815 // mwindow->edl->session->crop_y2,
2816 // mwindow->edl->calculate_output_w(0),
2817 // mwindow->edl->calculate_output_h(0));
2823 void CWindowCanvas::draw_crop()
2825 get_canvas()->set_inverse();
2826 get_canvas()->set_color(WHITE);
2828 float x1 = mwindow->edl->session->crop_x1;
2829 float y1 = mwindow->edl->session->crop_y1;
2830 float x2 = mwindow->edl->session->crop_x2;
2831 float y2 = mwindow->edl->session->crop_y2;
2833 output_to_canvas(mwindow->edl, 0, x1, y1);
2834 output_to_canvas(mwindow->edl, 0, x2, y2);
2836 if(x2 - x1 && y2 - y1)
2837 get_canvas()->draw_rectangle((int)x1,
2842 draw_crophandle((int)x1, (int)y1);
2843 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2844 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2845 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2846 get_canvas()->set_opaque();
2856 void CWindowCanvas::draw_bezier(int do_camera)
2858 Track *track = gui->cwindow->calculate_affected_track();
2865 int64_t position = track->to_units(
2866 mwindow->edl->local_session->get_selectionstart(1),
2868 // if( do_camera ) {
2869 // track->automation->get_camera(¢er_x,
2870 // ¢er_y, ¢er_z, position, PLAY_FORWARD);
2871 // follow image, not camera
2872 // center_x = -center_x * center_z; center_y = -center_y * center_z;
2875 track->automation->get_projector(¢er_x,
2876 ¢er_y, ¢er_z, position, PLAY_FORWARD);
2878 // center_x += track->track_w / 2;
2879 // center_y += track->track_h / 2;
2880 center_x += mwindow->edl->session->output_w / 2;
2881 center_y += mwindow->edl->session->output_h / 2;
2882 float track_x1 = center_x - track->track_w / 2 * center_z;
2883 float track_y1 = center_y - track->track_h / 2 * center_z;
2884 float track_x2 = track_x1 + track->track_w * center_z;
2885 float track_y2 = track_y1 + track->track_h * center_z;
2887 output_to_canvas(mwindow->edl, 0, track_x1, track_y1);
2888 output_to_canvas(mwindow->edl, 0, track_x2, track_y2);
2890 #define DRAW_PROJECTION(offset) \
2891 get_canvas()->draw_rectangle((int)track_x1 + offset, \
2892 (int)track_y1 + offset, \
2893 (int)(track_x2 - track_x1), \
2894 (int)(track_y2 - track_y1)); \
2895 get_canvas()->draw_line((int)track_x1 + offset, \
2896 (int)track_y1 + offset, \
2897 (int)track_x2 + offset, \
2898 (int)track_y2 + offset); \
2899 get_canvas()->draw_line((int)track_x2 + offset, \
2900 (int)track_y1 + offset, \
2901 (int)track_x1 + offset, \
2902 (int)track_y2 + offset); \
2906 get_canvas()->set_color(BLACK);
2909 // canvas->set_inverse();
2911 get_canvas()->set_color(GREEN);
2913 get_canvas()->set_color(RED);
2916 // canvas->set_opaque();
2920 int CWindowCanvas::test_bezier(int button_press,
2928 // Processing drag operation.
2929 // Create keyframe during first cursor motion.
2930 if( !button_press ) {
2932 float cursor_x = get_cursor_x();
2933 float cursor_y = get_cursor_y();
2934 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2936 if( gui->current_operation == CWINDOW_CAMERA ||
2937 gui->current_operation == CWINDOW_PROJECTOR ) {
2938 if( !gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom ) {
2939 gui->translating_zoom = 1;
2940 gui->reset_affected();
2942 else if( !gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom ) {
2943 gui->translating_zoom = 0;
2944 gui->reset_affected();
2947 // Get target keyframe
2948 if( !gui->affected_x && !gui->affected_y && !gui->affected_z ) {
2949 if(!gui->affected_track) return 0;
2950 FloatAutos *affected_x_autos, *affected_y_autos, *affected_z_autos;
2951 FloatAutos** autos = (FloatAutos**) gui->affected_track->automation->autos;
2952 if( mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA ) {
2953 affected_x_autos = autos[AUTOMATION_CAMERA_X];
2954 affected_y_autos = autos[AUTOMATION_CAMERA_Y];
2955 affected_z_autos = autos[AUTOMATION_CAMERA_Z];
2958 affected_x_autos = autos[AUTOMATION_PROJECTOR_X];
2959 affected_y_autos = autos[AUTOMATION_PROJECTOR_Y];
2960 affected_z_autos = autos[AUTOMATION_PROJECTOR_Z];
2962 double position = mwindow->edl->local_session->get_selectionstart(1);
2963 int64_t track_position = gui->affected_track->to_units(position, 0);
2964 FloatAuto *prev_x = 0, *next_x = 0;
2965 float new_x = affected_x_autos->get_value(track_position, PLAY_FORWARD, prev_x, next_x);
2966 FloatAuto *prev_y = 0, *next_y = 0;
2967 float new_y = affected_y_autos->get_value(track_position, PLAY_FORWARD, prev_y, next_y);
2968 FloatAuto *prev_z = 0, *next_z = 0;
2969 float new_z = affected_z_autos->get_value(track_position, PLAY_FORWARD, prev_z, next_z);
2970 int zooming = gui->translating_zoom, created;
2971 gui->affected_x = (FloatAuto*)gui->cwindow->calculate_affected_auto(
2972 affected_x_autos, !zooming, &created, 0);
2974 gui->affected_x->set_value(new_x);
2977 gui->affected_y = (FloatAuto*)gui->cwindow->calculate_affected_auto(
2978 affected_y_autos, !zooming, &created, 0);
2980 gui->affected_y->set_value(new_y);
2983 gui->affected_z = (FloatAuto*)gui->cwindow->calculate_affected_auto(
2984 affected_z_autos, zooming, &created, 0);
2986 gui->affected_z->set_value(new_z);
2991 if( gui->translating_zoom ) {
2992 gui->center_z = gui->affected_z->get_value();
2995 gui->center_x = gui->affected_x->get_value();
2996 gui->center_y = gui->affected_y->get_value();
3003 float x_val = gui->affected_x->get_value();
3004 float y_val = gui->affected_y->get_value();
3005 float z_val = gui->affected_z->get_value();
3007 if( gui->translating_zoom ) {
3008 float z = gui->center_z + (cursor_y - gui->y_origin) / 128;
3010 if( !EQUIV(z_val, z) ) {
3015 gui->affected_z->set_value(z);
3018 float dx = cursor_x - gui->x_origin;
3019 float dy = cursor_y - gui->y_origin;
3020 // follow image, not camera
3021 if( gui->current_operation == CWINDOW_CAMERA ) {
3022 dx = -dx / z_val; dy = -dy / z_val;
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(x_val, x) || !EQUIV(y_val, y) ) {
3039 // Begin drag operation. Don't create keyframe here.
3041 // Get affected track off of the first recordable video track.
3042 // Calculating based on the alpha channel would require recording what layer
3043 // each output pixel belongs to as they're rendered and stacked. Forget it.
3044 gui->affected_track = gui->cwindow->calculate_affected_track();
3045 gui->reset_affected();
3047 if(gui->affected_track)
3050 mwindow->undo->update_undo_before(_("camera"), this);
3052 mwindow->undo->update_undo_before(_("projector"), this);
3054 gui->current_operation =
3055 mwindow->edl->session->cwindow_operation;
3056 gui->tool_panel->raise_window();
3065 int CWindowCanvas::test_zoom(int &redraw)
3071 if( mwindow->edl->session->cwindow_scrollbars ) {
3072 if( *gui->zoom_panel->get_text() != 'x' ) {
3073 // Find current zoom in table
3074 int idx = total_zooms; float old_zoom = get_zoom();
3075 while( --idx >= 0 && !EQUIV(my_zoom_table[idx], old_zoom) );
3077 idx += get_buttonpress() == 5 ||
3078 gui->ctrl_down() || gui->shift_down() ? -1 : +1 ;
3079 CLAMP(idx, 0, total_zooms-1);
3080 zoom = my_zoom_table[idx];
3083 x = get_cursor_x(); y = get_cursor_y();
3085 mwindow->edl->session->cwindow_scrollbars = 0;
3086 gui->zoom_panel->update(0);
3087 zoom = gui->get_auto_zoom();
3090 gui->zoom_panel->ZoomPanel::update(zoom);
3091 float output_x = x, output_y = y;
3092 canvas_to_output(mwindow->edl, 0, output_x, output_y);
3093 x = output_x - x / zoom;
3094 y = output_y - y / zoom;
3098 mwindow->edl->session->cwindow_scrollbars = 1;
3099 x = (mwindow->edl->session->output_w - w) / 2;
3100 y = (mwindow->edl->session->output_h - h) / 2;
3103 update_zoom((int)x, (int)y, zoom);
3105 gui->composite_panel->cpanel_zoom->update(zoom);
3107 reposition_window(mwindow->edl,
3108 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
3109 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
3110 redraw = 1; result = 1;
3116 void CWindowCanvas::calculate_origin()
3118 gui->x_origin = get_cursor_x();
3119 gui->y_origin = get_cursor_y();
3120 //printf("CWindowCanvas::calculate_origin 1 %f %f\n", gui->x_origin, gui->y_origin);
3121 canvas_to_output(mwindow->edl, 0, gui->x_origin, gui->y_origin);
3122 //printf("CWindowCanvas::calculate_origin 2 %f %f\n", gui->x_origin, gui->y_origin);
3126 int CWindowCanvas::cursor_leave_event()
3128 set_cursor(ARROW_CURSOR);
3132 int CWindowCanvas::cursor_enter_event()
3135 switch(mwindow->edl->session->cwindow_operation)
3137 case CWINDOW_CAMERA:
3138 case CWINDOW_PROJECTOR:
3139 set_cursor(MOVE_CURSOR);
3142 set_cursor(MOVE_CURSOR);
3145 test_crop(0, redraw);
3147 case CWINDOW_PROTECT:
3148 set_cursor(ARROW_CURSOR);
3152 set_cursor(CROSS_CURSOR);
3154 case CWINDOW_EYEDROP:
3155 set_cursor(CROSS_CURSOR);
3161 int CWindowCanvas::cursor_motion_event()
3163 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3166 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3167 switch(gui->current_operation)
3169 case CWINDOW_SCROLL:
3171 float zoom = get_zoom();
3172 float cursor_x = get_cursor_x();
3173 float cursor_y = get_cursor_y();
3175 float zoom_x, zoom_y, conformed_w, conformed_h;
3176 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3177 cursor_x = (float)cursor_x / zoom_x + gui->x_offset;
3178 cursor_y = (float)cursor_y / zoom_y + gui->y_offset;
3182 int x = (int)(gui->x_origin - cursor_x + gui->x_offset);
3183 int y = (int)(gui->y_origin - cursor_y + gui->y_offset);
3188 update_scrollbars(0);
3195 result = do_ruler(0, 1, 0, 0);
3198 case CWINDOW_CAMERA:
3199 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3202 case CWINDOW_PROJECTOR:
3203 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3208 result = test_crop(0, redraw);
3209 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3216 case CWINDOW_MASK_CONTROL_IN:
3217 case CWINDOW_MASK_CONTROL_OUT:
3218 case CWINDOW_MASK_TRANSLATE:
3220 result = do_mask(redraw,
3227 case CWINDOW_EYEDROP:
3228 result = do_eyedrop(rerender, 0, 0);
3237 // cursor font changes
3240 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3242 // mwindow->edl->session->cwindow_operation);
3243 switch(mwindow->edl->session->cwindow_operation)
3246 result = test_crop(0, redraw);
3249 result = do_ruler(0, 1, 0, 0);
3252 result = do_mask(redraw,
3261 int change_type = rerender ? CHANGE_PARAMS : -1;
3262 gui->sync_parameters(change_type, redraw, redraw_canvas);
3267 int CWindowCanvas::button_press_event()
3271 int redraw_canvas = 0;
3274 if(Canvas::button_press_event()) return 1;
3276 gui->translating_zoom = gui->shift_down();
3279 //printf("CWindowCanvas::button_press_event 2 %f %f\n", gui->x_origin, gui->y_origin, gui->x_origin, gui->y_origin);
3281 float zoom_x, zoom_y, conformed_w, conformed_h;
3282 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3283 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3284 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3287 if( mwindow->edl->session->cwindow_operation != CWINDOW_PROTECT &&
3288 get_buttonpress() == 2 )
3290 gui->current_operation = CWINDOW_SCROLL;
3296 switch(mwindow->edl->session->cwindow_operation)
3299 result = do_ruler(0, 0, 1, 0);
3302 case CWINDOW_CAMERA:
3303 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3306 case CWINDOW_PROJECTOR:
3307 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3311 result = test_zoom(redraw);
3315 result = test_crop(1, redraw);
3319 if(get_buttonpress() == 1)
3320 result = do_mask(redraw, rerender, 1, 0, 0);
3323 case CWINDOW_EYEDROP:
3324 result = do_eyedrop(rerender, 1, 0);
3329 int change_type = rerender ? CHANGE_PARAMS : -1;
3330 gui->sync_parameters(change_type, redraw, redraw_canvas);
3335 int CWindowCanvas::button_release_event()
3339 switch(gui->current_operation)
3341 case CWINDOW_SCROLL:
3346 do_ruler(0, 0, 0, 1);
3349 case CWINDOW_CAMERA:
3350 mwindow->undo->update_undo_after(_("camera"), LOAD_AUTOMATION);
3353 case CWINDOW_PROJECTOR:
3354 mwindow->undo->update_undo_after(_("projector"), LOAD_AUTOMATION);
3358 case CWINDOW_MASK_CONTROL_IN:
3359 case CWINDOW_MASK_CONTROL_OUT:
3360 case CWINDOW_MASK_TRANSLATE:
3361 // Finish mask operation
3362 gui->mask_keyframe = 0;
3363 mwindow->undo->update_undo_after(_("mask"), LOAD_AUTOMATION);
3366 result = Canvas::button_release_event();
3370 gui->current_operation = CWINDOW_NONE;
3374 void CWindowCanvas::zoom_resize_window(float percentage)
3376 int canvas_w, canvas_h;
3380 // Get required canvas size
3381 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3382 mwindow->edl->session->output_w,
3383 mwindow->edl->session->output_h,
3388 // Estimate window size from current borders
3389 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3390 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3392 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3393 mwindow->session->cwindow_w = new_w;
3394 mwindow->session->cwindow_h = new_h;
3396 mwindow->theme->get_cwindow_sizes(gui,
3397 mwindow->session->cwindow_controls);
3399 // Estimate again from new borders
3400 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3401 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3402 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3404 gui->resize_window(new_w, new_h);
3405 gui->resize_event(new_w, new_h);
3408 void CWindowCanvas::toggle_controls()
3410 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3411 gui->resize_event(gui->get_w(), gui->get_h());
3414 int CWindowCanvas::get_cwindow_controls()
3416 return mwindow->session->cwindow_controls;