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 cwindow->stop_playback(1);
123 if(tool_panel) delete tool_panel;
125 delete composite_panel;
132 delete orig_mask_keyframe;
135 void CWindowGUI::create_objects()
137 lock_window("CWindowGUI::create_objects");
138 set_icon(mwindow->theme->get_image("cwindow_icon"));
140 active = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_active"));
141 inactive = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_inactive"));
143 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
144 mwindow->theme->draw_cwindow_bg(this);
147 // Meters required by composite panel
148 meters = new CWindowMeters(mwindow,
150 mwindow->theme->cmeter_x,
151 mwindow->theme->cmeter_y,
152 mwindow->theme->cmeter_h);
153 meters->create_objects();
156 composite_panel = new CPanel(mwindow,
158 mwindow->theme->ccomposite_x,
159 mwindow->theme->ccomposite_y,
160 mwindow->theme->ccomposite_w,
161 mwindow->theme->ccomposite_h);
162 composite_panel->create_objects();
164 canvas = new CWindowCanvas(mwindow, this);
166 canvas->create_objects(mwindow->edl);
167 canvas->use_cwindow();
170 add_subwindow(timebar = new CTimeBar(mwindow,
172 mwindow->theme->ctimebar_x,
173 mwindow->theme->ctimebar_y,
174 mwindow->theme->ctimebar_w,
175 mwindow->theme->ctimebar_h));
176 timebar->create_objects();
179 add_subwindow(slider = new CWindowSlider(mwindow,
181 mwindow->theme->cslider_x,
182 mwindow->theme->cslider_y,
183 mwindow->theme->cslider_w));
186 transport = new CWindowTransport(mwindow,
188 mwindow->theme->ctransport_x,
189 mwindow->theme->ctransport_y);
190 transport->create_objects();
192 transport->set_slider(slider);
195 edit_panel = new CWindowEditing(mwindow, cwindow);
196 edit_panel->set_meters(meters);
197 edit_panel->create_objects();
199 // add_subwindow(clock = new MainClock(mwindow,
200 // mwindow->theme->ctime_x,
201 // mwindow->theme->ctime_y));
203 zoom_panel = new CWindowZoom(mwindow,
205 mwindow->theme->czoom_x,
206 mwindow->theme->czoom_y,
207 mwindow->theme->czoom_w);
208 zoom_panel->create_objects();
209 zoom_panel->zoom_text->add_item(new BC_MenuItem(auto_zoom = _(AUTO_ZOOM)));
210 if( !mwindow->edl->session->cwindow_scrollbars )
211 zoom_panel->set_text(auto_zoom);
213 // destination = new CWindowDestination(mwindow,
215 // mwindow->theme->cdest_x,
216 // mwindow->theme->cdest_y);
217 // destination->create_objects();
219 // Must create after meter panel
220 tool_panel = new CWindowTool(mwindow, this);
221 tool_panel->Thread::start();
223 set_operation(mwindow->edl->session->cwindow_operation);
228 int CWindowGUI::translation_event()
230 mwindow->session->cwindow_x = get_x();
231 mwindow->session->cwindow_y = get_y();
235 int CWindowGUI::resize_event(int w, int h)
237 mwindow->session->cwindow_x = get_x();
238 mwindow->session->cwindow_y = get_y();
239 mwindow->session->cwindow_w = w;
240 mwindow->session->cwindow_h = h;
242 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
243 mwindow->theme->draw_cwindow_bg(this);
246 composite_panel->reposition_buttons(mwindow->theme->ccomposite_x,
247 mwindow->theme->ccomposite_y, mwindow->theme->ccomposite_h);
249 canvas->reposition_window(mwindow->edl,
250 mwindow->theme->ccanvas_x,
251 mwindow->theme->ccanvas_y,
252 mwindow->theme->ccanvas_w,
253 mwindow->theme->ccanvas_h);
255 timebar->resize_event();
258 slider->reposition_window(mwindow->theme->cslider_x,
259 mwindow->theme->cslider_y,
260 mwindow->theme->cslider_w);
261 // Recalibrate pointer motion range
262 slider->set_position();
265 transport->reposition_buttons(mwindow->theme->ctransport_x,
266 mwindow->theme->ctransport_y);
268 edit_panel->reposition_buttons(mwindow->theme->cedit_x,
269 mwindow->theme->cedit_y);
271 // clock->reposition_window(mwindow->theme->ctime_x,
272 // mwindow->theme->ctime_y);
274 zoom_panel->reposition_window(mwindow->theme->czoom_x,
275 mwindow->theme->czoom_y);
277 // destination->reposition_window(mwindow->theme->cdest_x,
278 // mwindow->theme->cdest_y);
280 meters->reposition_window(mwindow->theme->cmeter_x,
281 mwindow->theme->cmeter_y,
283 mwindow->theme->cmeter_h);
287 BC_WindowBase::resize_event(w, h);
291 int CWindowGUI::button_press_event()
293 if( current_operation == CWINDOW_NONE &&
294 mwindow->edl != 0 && canvas->get_canvas() &&
295 mwindow->edl->session->cwindow_click2play &&
296 canvas->get_canvas()->get_cursor_over_window() ) {
297 switch( get_buttonpress() ) {
299 if( !cwindow->playback_engine->is_playing_back ) {
300 double length = mwindow->edl->tracks->total_playable_length();
301 double position = cwindow->playback_engine->get_tracking_position();
302 if( position >= length ) transport->goto_start();
304 return transport->forward_play->handle_event();
306 if( !cwindow->playback_engine->is_playing_back ) {
307 double position = cwindow->playback_engine->get_tracking_position();
308 if( position <= 0 ) transport->goto_end();
310 return transport->reverse_play->handle_event();
311 case RIGHT_BUTTON: // activates popup
314 return transport->frame_forward_play->handle_event();
316 return transport->frame_reverse_play->handle_event();
319 if(canvas->get_canvas())
320 return canvas->button_press_event_base(canvas->get_canvas());
324 int CWindowGUI::cursor_leave_event()
326 if(canvas->get_canvas())
327 return canvas->cursor_leave_event_base(canvas->get_canvas());
331 int CWindowGUI::cursor_enter_event()
333 if(canvas->get_canvas())
334 return canvas->cursor_enter_event_base(canvas->get_canvas());
338 int CWindowGUI::button_release_event()
340 if(canvas->get_canvas())
341 return canvas->button_release_event();
345 int CWindowGUI::cursor_motion_event()
347 if(canvas->get_canvas())
349 canvas->get_canvas()->unhide_cursor();
350 return canvas->cursor_motion_event();
361 void CWindowGUI::draw_status(int flush)
363 if( (canvas->get_canvas() && canvas->get_canvas()->get_video_on()) ||
364 canvas->is_processing )
367 mwindow->theme->cstatus_x,
368 mwindow->theme->cstatus_y);
372 draw_pixmap(inactive,
373 mwindow->theme->cstatus_x,
374 mwindow->theme->cstatus_y);
378 // printf("CWindowGUI::draw_status %d %d %d\n", __LINE__, mwindow->theme->cstatus_x,
379 // mwindow->theme->cstatus_y);
380 flash(mwindow->theme->cstatus_x,
381 mwindow->theme->cstatus_y,
387 float CWindowGUI::get_auto_zoom()
389 float conformed_w, conformed_h;
390 mwindow->edl->calculate_conformed_dimensions(0, conformed_w, conformed_h);
391 float zoom_x = canvas->w / conformed_w;
392 float zoom_y = canvas->h / conformed_h;
393 return zoom_x < zoom_y ? zoom_x : zoom_y;
396 void CWindowGUI::zoom_canvas(double value, int update_menu)
399 float zoom = !value ? get_auto_zoom() : value;
400 EDL *edl = mwindow->edl;
401 edl->session->cwindow_scrollbars = !value ? 0 : 1;
403 float cx = 0.5f * canvas->w; x = cx;
404 float cy = 0.5f * canvas->h; y = cy;
405 canvas->canvas_to_output(edl, 0, x, y);
406 canvas->update_zoom(0, 0, zoom);
407 float zoom_x, zoom_y, conformed_w, conformed_h;
408 canvas->get_zooms(edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
413 canvas->update_zoom((int)(x+0.5), (int)(y+0.5), zoom);
416 zoom_panel->update(value);
417 if( mwindow->edl->session->cwindow_operation == CWINDOW_ZOOM )
418 composite_panel->cpanel_zoom->update(zoom);
420 canvas->reposition_window(mwindow->edl,
421 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
422 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
426 void CWindowGUI::set_operation(int value)
429 case CWINDOW_TOOL_WINDOW:
430 mwindow->edl->session->tool_window = !mwindow->edl->session->tool_window;
431 composite_panel->operation[CWINDOW_TOOL_WINDOW]->update(mwindow->edl->session->tool_window);
432 tool_panel->update_show_window();
434 case CWINDOW_TITLESAFE:
435 mwindow->edl->session->safe_regions = !mwindow->edl->session->safe_regions;
436 composite_panel->operation[CWINDOW_TITLESAFE]->update(mwindow->edl->session->safe_regions);
437 value = mwindow->edl->session->cwindow_operation;
440 mwindow->edl->session->cwindow_operation = value;
441 composite_panel->set_operation(value);
445 edit_panel->update();
446 tool_panel->start_tool(value);
450 void CWindowGUI::update_tool()
452 tool_panel->update_values();
455 int CWindowGUI::close_event()
457 cwindow->hide_window();
462 int CWindowGUI::keypress_event()
465 int cwindow_operation = CWINDOW_NONE;
467 switch( get_keypress() ) {
484 if( canvas->get_fullscreen() )
485 canvas->stop_fullscreen();
487 canvas->start_fullscreen();
488 lock_window("CWindowGUI::keypress_event 1");
492 if( ctrl_down() || shift_down() || alt_down() ) break;
494 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
496 mwindow->gui->unlock_window();
497 lock_window("CWindowGUI::keypress_event 2");
502 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
503 mwindow->clear_entry();
504 mwindow->gui->unlock_window();
505 lock_window("CWindowGUI::keypress_event 3");
510 if( canvas->get_fullscreen() )
511 canvas->stop_fullscreen();
512 lock_window("CWindowGUI::keypress_event 4");
517 int alt_down = this->alt_down();
518 int shift_down = this->shift_down();
521 mwindow->gui->lock_window("CWindowGUI::keypress_event 5");
523 mwindow->prev_edit_handle(shift_down);
525 mwindow->move_left();
526 mwindow->gui->unlock_window();
527 lock_window("CWindowGUI::keypress_event 6");
533 if( !ctrl_down() && !alt_down() ) {
536 mwindow->gui->lock_window("CWindowGUI::keypress_event 7");
537 mwindow->move_left();
538 mwindow->gui->unlock_window();
539 lock_window("CWindowGUI::keypress_event 8");
546 int alt_down = this->alt_down();
547 int shift_down = this->shift_down();
550 mwindow->gui->lock_window("CWindowGUI::keypress_event 8");
552 mwindow->next_edit_handle(shift_down);
554 mwindow->move_right();
555 mwindow->gui->unlock_window();
556 lock_window("CWindowGUI::keypress_event 9");
562 if( !ctrl_down() && !alt_down() ) {
565 mwindow->gui->lock_window("CWindowGUI::keypress_event 10");
566 mwindow->move_right();
567 mwindow->gui->unlock_window();
568 lock_window("CWindowGUI::keypress_event 11");
574 if( !result && cwindow_operation < 0 && ctrl_down() && shift_down() ) {
575 switch( get_keypress() ) {
576 case KEY_F1 ... KEY_F4: // mainmenu, load layout
577 resend_event(mwindow->gui);
582 if( !result && !ctrl_down() ) {
583 switch( get_keypress() ) {
586 mwindow->toggle_camera_xyz(); result = 1;
589 cwindow_operation = CWINDOW_PROTECT;
593 mwindow->toggle_projector_xyz(); result = 1;
596 cwindow_operation = CWINDOW_ZOOM;
600 if( !result && cwindow_operation < 0 && !ctrl_down() && !shift_down() ) {
601 switch( get_keypress() ) {
602 case KEY_F3: cwindow_operation = CWINDOW_MASK; break;
603 case KEY_F4: cwindow_operation = CWINDOW_RULER; break;
604 case KEY_F5: cwindow_operation = CWINDOW_CAMERA; break;
605 case KEY_F6: cwindow_operation = CWINDOW_PROJECTOR; break;
606 case KEY_F7: cwindow_operation = CWINDOW_CROP; break;
607 case KEY_F8: cwindow_operation = CWINDOW_EYEDROP; break;
608 case KEY_F9: cwindow_operation = CWINDOW_TOOL_WINDOW; break;
609 case KEY_F10: cwindow_operation = CWINDOW_TITLESAFE; break;
612 if( !result && cwindow_operation < 0 && !ctrl_down() ) {
613 switch( get_keypress() ) {
616 canvas->reset_camera();
618 canvas->camera_keyframe();
623 canvas->reset_projector();
625 canvas->projector_keyframe();
631 if( cwindow_operation >= 0 ) {
632 set_operation(cwindow_operation);
637 result = transport->keypress_event();
643 void CWindowGUI::reset_affected()
650 void CWindowGUI::keyboard_zoomin()
652 // if(mwindow->edl->session->cwindow_scrollbars)
654 zoom_panel->zoom_tumbler->handle_up_event();
661 void CWindowGUI::keyboard_zoomout()
663 // if(mwindow->edl->session->cwindow_scrollbars)
665 zoom_panel->zoom_tumbler->handle_down_event();
672 void CWindowGUI::sync_parameters(int change_type, int redraw, int overlay)
678 if( change_type < 0 && !overlay ) return;
680 if( change_type >= 0 ) {
681 mwindow->restart_brender();
682 mwindow->sync_parameters(change_type);
685 mwindow->gui->lock_window("CWindowGUI::sync_parameters");
686 mwindow->gui->draw_overlays(1);
687 mwindow->gui->unlock_window();
689 lock_window("CWindowGUI::sync_parameters");
692 void CWindowGUI::drag_motion()
694 if(get_hidden()) return;
696 if(mwindow->session->current_operation != DRAG_ASSET &&
697 mwindow->session->current_operation != DRAG_VTRANSITION &&
698 mwindow->session->current_operation != DRAG_VEFFECT) return;
699 int need_highlight = cursor_above() && get_cursor_over_window();
700 if( highlighted == need_highlight ) return;
701 highlighted = need_highlight;
705 int CWindowGUI::drag_stop()
708 if(get_hidden()) return 0;
709 if( !highlighted ) return 0;
710 if( mwindow->session->current_operation != DRAG_ASSET &&
711 mwindow->session->current_operation != DRAG_VTRANSITION &&
712 mwindow->session->current_operation != DRAG_VEFFECT) return 0;
717 if(mwindow->session->current_operation == DRAG_ASSET)
719 if(mwindow->session->drag_assets->total ||
720 mwindow->session->drag_clips->total)
722 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
723 mwindow->undo->update_undo_before(_("insert assets"), 0);
726 if(mwindow->session->drag_assets->total)
729 mwindow->load_assets(mwindow->session->drag_assets,
730 mwindow->edl->local_session->get_selectionstart(),
732 mwindow->session->track_highlighted,
734 mwindow->edl->session->labels_follow_edits,
735 mwindow->edl->session->plugins_follow_edits,
736 mwindow->edl->session->autos_follow_edits,
740 if(mwindow->session->drag_clips->total)
743 mwindow->paste_edls(mwindow->session->drag_clips,
745 mwindow->session->track_highlighted,
746 mwindow->edl->local_session->get_selectionstart(),
747 mwindow->edl->session->labels_follow_edits,
748 mwindow->edl->session->plugins_follow_edits,
749 mwindow->edl->session->autos_follow_edits,
753 if(mwindow->session->drag_assets->total ||
754 mwindow->session->drag_clips->total)
756 mwindow->save_backup();
757 mwindow->restart_brender();
758 mwindow->gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
759 mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
760 mwindow->gui->unlock_window();
761 sync_parameters(CHANGE_ALL);
765 if(mwindow->session->current_operation == DRAG_VEFFECT)
767 //printf("CWindowGUI::drag_stop 1\n");
768 Track *affected_track = cwindow->calculate_affected_track();
769 //printf("CWindowGUI::drag_stop 2\n");
771 mwindow->gui->lock_window("CWindowGUI::drag_stop 3");
772 mwindow->insert_effects_cwindow(affected_track);
773 mwindow->session->current_operation = NO_OPERATION;
774 mwindow->gui->unlock_window();
777 if(mwindow->session->current_operation == DRAG_VTRANSITION)
779 Track *affected_track = cwindow->calculate_affected_track();
780 mwindow->gui->lock_window("CWindowGUI::drag_stop 4");
781 mwindow->paste_transition_cwindow(affected_track);
782 mwindow->session->current_operation = NO_OPERATION;
783 mwindow->gui->unlock_window();
789 void CWindowGUI::update_meters()
791 if(mwindow->edl->session->cwindow_meter != meters->visible)
793 meters->set_meters(meters->meter_count, mwindow->edl->session->cwindow_meter);
794 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
795 resize_event(get_w(), get_h());
799 void CWindowGUI::stop_transport(const char *lock_msg)
801 if( lock_msg ) unlock_window();
802 mwindow->stop_transport();
803 if( lock_msg ) lock_window(lock_msg);
807 CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
808 : EditPanel(mwindow, cwindow->gui, CWINDOW_ID,
809 mwindow->theme->cedit_x, mwindow->theme->cedit_y,
810 mwindow->edl->session->editing_mode,
811 0, // use_editing_mode
828 this->mwindow = mwindow;
829 this->cwindow = cwindow;
832 #define relock_cm(s) \
833 cwindow->gui->unlock_window(); \
834 mwindow->gui->lock_window("CWindowEditing::" s)
835 #define relock_mc(s) \
836 mwindow->gui->unlock_window(); \
837 cwindow->gui->lock_window("CWindowEditing::" s)
838 #define panel_fn(fn, args, s) \
839 CWindowEditing::fn args { relock_cm(#fn); s; relock_mc(#fn); }
841 // transmit lock to mwindow, and run mbutton->edit_panel->s
842 #define panel_btn(fn, args, s) \
843 panel_fn(panel_##fn, args, mwindow->gui->mbuttons->edit_panel->panel_##s)
846 double CWindowEditing::get_position()
848 relock_cm("get_position");
849 double ret = mwindow->edl->local_session->get_selectionstart(1);
850 relock_mc("get_position");
854 void CWindowEditing::set_position(double position)
856 relock_cm("set_position");
857 mwindow->gui->mbuttons->edit_panel->set_position(position);
858 relock_mc("set_position");
861 void CWindowEditing::set_click_to_play(int v)
863 relock_cm("set_position");
864 mwindow->edl->session->cwindow_click2play = v;
865 relock_mc("set_position");
866 click2play->update(v);
870 void panel_btn(stop_transport,(), stop_transport())
871 void panel_btn(toggle_label,(), toggle_label())
872 void panel_btn(next_label,(int cut), next_label(cut))
873 void panel_btn(prev_label,(int cut), prev_label(cut))
874 void panel_btn(next_edit,(int cut), next_edit(cut))
875 void panel_btn(prev_edit,(int cut), prev_edit(cut))
876 void panel_fn(panel_copy_selection,(), mwindow->copy())
877 void CWindowEditing::panel_overwrite_selection() {} // not used
878 void CWindowEditing::panel_splice_selection() {} // not used
879 void panel_btn(set_inpoint,(), set_inpoint())
880 void panel_btn(set_outpoint,(), set_outpoint())
881 void panel_btn(unset_inoutpoint,(), unset_inoutpoint())
882 void panel_fn(panel_to_clip,(), mwindow->to_clip(mwindow->edl, _("main window: "), 0))
883 void panel_btn(cut,(), cut())
884 void panel_btn(paste,(), paste())
885 void panel_btn(fit_selection,(), fit_selection())
886 void panel_btn(fit_autos,(int all), fit_autos(all))
887 void panel_btn(set_editing_mode,(int mode), set_editing_mode(mode))
888 void panel_btn(set_auto_keyframes,(int v), set_auto_keyframes(v))
889 void panel_btn(set_labels_follow_edits,(int v), set_labels_follow_edits(v))
892 CWindowMeters::CWindowMeters(MWindow *mwindow,
893 CWindowGUI *gui, int x, int y, int h)
894 : MeterPanel(mwindow, gui, x, y, -1, h,
895 mwindow->edl->session->audio_channels,
896 mwindow->edl->session->cwindow_meter,
899 this->mwindow = mwindow;
903 CWindowMeters::~CWindowMeters()
907 int CWindowMeters::change_status_event(int new_status)
909 mwindow->edl->session->cwindow_meter = new_status;
910 gui->update_meters();
917 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
918 : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
919 x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
921 this->mwindow = mwindow;
925 CWindowZoom::~CWindowZoom()
929 void CWindowZoom::update(double value)
931 char string[BCSTRLEN];
932 const char *cp = string;
935 int frac = value >= 1.0f ? 1 :
937 value >= .01f ? 3 : 4;
938 sprintf(string, "x %.*f", frac, value);
942 ZoomPanel::update(cp);
945 int CWindowZoom::handle_event()
947 double value = !strcasecmp(gui->auto_zoom, get_text()) ? 0 : get_value();
948 gui->zoom_canvas(value, 0);
955 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
956 : BC_PercentageSlider(x,
965 this->mwindow = mwindow;
966 this->cwindow = cwindow;
967 set_precision(0.00001);
970 CWindowSlider::~CWindowSlider()
974 int CWindowSlider::handle_event()
976 cwindow->update_position((double)get_value());
980 void CWindowSlider::set_position()
982 double new_length = mwindow->edl->tracks->total_length();
983 update(mwindow->theme->cslider_w,
984 mwindow->edl->local_session->get_selectionstart(1),
989 int CWindowSlider::increase_value()
992 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
993 lock_window("CWindowSlider::increase_value");
997 int CWindowSlider::decrease_value()
1000 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
1001 lock_window("CWindowSlider::decrease_value");
1006 // CWindowDestination::CWindowDestination(MWindow *mwindow, CWindowGUI *cwindow, int x, int y)
1007 // : BC_PopupTextBox(cwindow,
1008 // &cwindow->destinations,
1009 // cwindow->destinations.values[cwindow->cwindow->destination]->get_text(),
1015 // this->mwindow = mwindow;
1016 // this->cwindow = cwindow;
1019 // CWindowDestination::~CWindowDestination()
1023 // int CWindowDestination::handle_event()
1027 #endif // USE_SLIDER
1034 CWindowTransport::CWindowTransport(MWindow *mwindow,
1038 : PlayTransport(mwindow,
1046 EDL* CWindowTransport::get_edl()
1048 return mwindow->edl;
1051 void CWindowTransport::goto_start()
1053 gui->unlock_window();
1054 handle_transport(REWIND, 1);
1056 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
1057 mwindow->goto_start();
1058 mwindow->gui->unlock_window();
1060 gui->lock_window("CWindowTransport::goto_start 2");
1063 void CWindowTransport::goto_end()
1065 gui->unlock_window();
1066 handle_transport(GOTO_END, 1);
1068 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
1069 mwindow->goto_end();
1070 mwindow->gui->unlock_window();
1072 gui->lock_window("CWindowTransport::goto_end 2");
1077 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
1080 mwindow->theme->ccanvas_x,
1081 mwindow->theme->ccanvas_y,
1082 mwindow->theme->ccanvas_w,
1083 mwindow->theme->ccanvas_h,
1086 mwindow->edl->session->cwindow_scrollbars)
1088 this->mwindow = mwindow;
1092 void CWindowCanvas::status_event()
1094 gui->draw_status(1);
1097 void CWindowCanvas::update_zoom(int x, int y, float zoom)
1099 use_scrollbars = mwindow->edl->session->cwindow_scrollbars;
1101 mwindow->edl->session->cwindow_xscroll = x;
1102 mwindow->edl->session->cwindow_yscroll = y;
1103 mwindow->edl->session->cwindow_zoom = zoom;
1106 void CWindowCanvas::zoom_auto()
1108 gui->zoom_canvas(0, 1);
1111 int CWindowCanvas::get_xscroll()
1113 return mwindow->edl->session->cwindow_xscroll;
1116 int CWindowCanvas::get_yscroll()
1118 return mwindow->edl->session->cwindow_yscroll;
1122 float CWindowCanvas::get_zoom()
1124 return mwindow->edl->session->cwindow_zoom;
1127 void CWindowCanvas::draw_refresh(int flush)
1129 BC_WindowBase *window = get_canvas();
1130 if( window && !window->get_video_on() ) {
1132 if( mwindow->uses_opengl() ) {
1133 // this code is to idle rendering before drawing overlays on refresh frame
1134 // if this is not done, occationally opengl finishs late, and overwrites
1135 // the x11 refresh frame and the overlay is not visible. Rarely happens.
1137 mwindow->playback_3d->finish_output(this);
1138 lock_canvas("CWindowCanvas::draw_refresh");
1140 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
1141 float in_x1, in_y1, in_x2, in_y2;
1142 float out_x1, out_y1, out_x2, out_y2;
1143 get_transfers(mwindow->edl,
1144 in_x1, in_y1, in_x2, in_y2,
1145 out_x1, out_y1, out_x2, out_y2);
1148 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1149 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1152 if( out_x2 > out_x1 && out_y2 > out_y1 &&
1153 in_x2 > in_x1 && in_y2 > in_y1 ) {
1154 // input scaled from session to refresh frame coordinates
1155 int ow = get_output_w(mwindow->edl);
1156 int oh = get_output_h(mwindow->edl);
1157 int rw = refresh_frame->get_w();
1158 int rh = refresh_frame->get_h();
1159 float xs = (float)rw / ow;
1160 float ys = (float)rh / oh;
1161 in_x1 *= xs; in_x2 *= xs;
1162 in_y1 *= ys; in_y2 *= ys;
1163 // Can't use OpenGL here because it is called asynchronously of the
1164 // playback operation.
1165 window->draw_vframe(refresh_frame,
1166 (int)out_x1, (int)out_y1,
1167 (int)(out_x2 - out_x1),
1168 (int)(out_y2 - out_y1),
1169 (int)in_x1, (int)in_y1,
1170 (int)(in_x2 - in_x1),
1171 (int)(in_y2 - in_y1),
1177 window->flash(flush);
1179 //printf("CWindowCanvas::draw_refresh 10\n");
1182 #define CROPHANDLE_W 10
1183 #define CROPHANDLE_H 10
1185 void CWindowCanvas::draw_crophandle(int x, int y)
1187 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1191 #define CONTROL_W 10
1192 #define CONTROL_H 10
1193 #define FIRST_CONTROL_W 20
1194 #define FIRST_CONTROL_H 20
1196 #define BC_INFINITY 65536
1198 #define RULERHANDLE_W 16
1199 #define RULERHANDLE_H 16
1201 int CWindowCanvas::do_ruler(int draw,
1207 float x1 = mwindow->edl->session->ruler_x1;
1208 float y1 = mwindow->edl->session->ruler_y1;
1209 float x2 = mwindow->edl->session->ruler_x2;
1210 float y2 = mwindow->edl->session->ruler_y2;
1211 float canvas_x1 = x1;
1212 float canvas_y1 = y1;
1213 float canvas_x2 = x2;
1214 float canvas_y2 = y2;
1215 float output_x = get_cursor_x();
1216 float output_y = get_cursor_y();
1217 float canvas_cursor_x = output_x;
1218 float canvas_cursor_y = output_y;
1220 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1221 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1222 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1223 mwindow->session->cwindow_output_x = roundf(output_x);
1224 mwindow->session->cwindow_output_y = roundf(output_y);
1226 if(button_press && get_buttonpress() == 1)
1228 gui->ruler_handle = -1;
1229 gui->ruler_translate = 0;
1232 gui->ruler_translate = 1;
1233 gui->ruler_origin_x = x1;
1234 gui->ruler_origin_y = y1;
1237 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1238 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1239 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1240 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1242 gui->ruler_handle = 0;
1243 gui->ruler_origin_x = x1;
1244 gui->ruler_origin_y = y1;
1247 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1248 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1249 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1250 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1252 gui->ruler_handle = 1;
1253 gui->ruler_origin_x = x2;
1254 gui->ruler_origin_y = y2;
1258 // Start new selection
1259 if(!gui->ruler_translate &&
1260 (gui->ruler_handle < 0 ||
1265 do_ruler(1, 0, 0, 0);
1266 get_canvas()->flash();
1267 gui->ruler_handle = 1;
1268 mwindow->edl->session->ruler_x1 = output_x;
1269 mwindow->edl->session->ruler_y1 = output_y;
1270 mwindow->edl->session->ruler_x2 = output_x;
1271 mwindow->edl->session->ruler_y2 = output_y;
1272 gui->ruler_origin_x = mwindow->edl->session->ruler_x2;
1273 gui->ruler_origin_y = mwindow->edl->session->ruler_y2;
1276 gui->x_origin = output_x;
1277 gui->y_origin = output_y;
1278 gui->current_operation = CWINDOW_RULER;
1279 gui->tool_panel->raise_window();
1285 if(gui->current_operation == CWINDOW_RULER)
1287 if(gui->ruler_translate)
1290 do_ruler(1, 0, 0, 0);
1291 float x_difference = mwindow->edl->session->ruler_x1;
1292 float y_difference = mwindow->edl->session->ruler_y1;
1293 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1294 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1295 x_difference -= mwindow->edl->session->ruler_x1;
1296 y_difference -= mwindow->edl->session->ruler_y1;
1297 mwindow->edl->session->ruler_x2 -= x_difference;
1298 mwindow->edl->session->ruler_y2 -= y_difference;
1300 do_ruler(1, 0, 0, 0);
1301 get_canvas()->flash();
1305 switch(gui->ruler_handle)
1308 do_ruler(1, 0, 0, 0);
1309 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1310 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1311 if(gui->alt_down() || gui->ctrl_down())
1313 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1314 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1318 double distance_value =
1319 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1320 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1321 if(angle_value < 22)
1322 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2;
1324 if(angle_value > 67)
1325 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2;
1327 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 &&
1328 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1330 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1331 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1334 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 && mwindow->edl->session->ruler_y1 > mwindow->edl->session->ruler_y2)
1336 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1337 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1340 if(mwindow->edl->session->ruler_x1 > mwindow->edl->session->ruler_x2 &&
1341 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1343 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1344 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1348 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1349 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1352 do_ruler(1, 0, 0, 0);
1353 get_canvas()->flash();
1358 do_ruler(1, 0, 0, 0);
1359 mwindow->edl->session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1360 mwindow->edl->session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1361 if(gui->alt_down() || gui->ctrl_down())
1363 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1364 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1368 double distance_value =
1369 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1370 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1371 if(angle_value < 22)
1372 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1;
1374 if(angle_value > 67)
1375 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1;
1377 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1378 mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1380 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1381 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1384 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1385 mwindow->edl->session->ruler_y2 > mwindow->edl->session->ruler_y1)
1387 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1388 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1391 if(mwindow->edl->session->ruler_x2 > mwindow->edl->session->ruler_x1 && mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1393 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1394 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1398 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1399 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1402 do_ruler(1, 0, 0, 0);
1403 get_canvas()->flash();
1407 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1411 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1416 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1417 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1418 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1419 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1421 set_cursor(UPRIGHT_ARROW_CURSOR);
1424 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1425 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1426 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1427 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1429 set_cursor(UPRIGHT_ARROW_CURSOR);
1432 set_cursor(CROSS_CURSOR);
1434 // Update current position
1439 // Assume no ruler measurement if 0 length
1440 if(draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)))
1442 get_canvas()->set_inverse();
1443 get_canvas()->set_color(WHITE);
1444 get_canvas()->draw_line((int)canvas_x1,
1448 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1450 roundf(canvas_x1) + RULERHANDLE_W / 2,
1452 get_canvas()->draw_line(roundf(canvas_x1),
1453 roundf(canvas_y1) - RULERHANDLE_H / 2,
1455 roundf(canvas_y1) + RULERHANDLE_H / 2);
1456 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1458 roundf(canvas_x2) + RULERHANDLE_W / 2,
1460 get_canvas()->draw_line(roundf(canvas_x2),
1461 roundf(canvas_y2) - RULERHANDLE_H / 2,
1463 roundf(canvas_y2) + RULERHANDLE_H / 2);
1464 get_canvas()->set_opaque();
1471 static inline double line_dist(float cx,float cy, float tx,float ty)
1473 double dx = tx-cx, dy = ty-cy;
1474 return sqrt(dx*dx + dy*dy);
1477 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1479 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1480 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1484 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1485 int button_press, int cursor_motion, int draw)
1487 // Retrieve points from top recordable track
1488 //printf("CWindowCanvas::do_mask 1\n");
1489 Track *track = gui->cwindow->calculate_affected_track();
1490 //printf("CWindowCanvas::do_mask 2\n");
1492 if(!track) return 0;
1493 //printf("CWindowCanvas::do_mask 3\n");
1495 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1496 int64_t position = track->to_units(
1497 mwindow->edl->local_session->get_selectionstart(1),
1499 ArrayList<MaskPoint*> points;
1501 // Determine the points based on whether
1502 // new keyframes will be generated or drawing is performed.
1503 // If keyframe generation occurs, use the interpolated mask.
1504 // If no keyframe generation occurs, use the previous mask.
1505 int use_interpolated = 0;
1506 if(button_press || cursor_motion) {
1507 #ifdef USE_KEYFRAME_SPANNING
1508 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1509 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1512 mask_autos->get_prev_auto(track->to_units(selection_start, 0),
1513 PLAY_FORWARD, first, 1);
1515 mask_autos->get_prev_auto(track->to_units(selection_end, 0),
1516 PLAY_FORWARD, last, 1);
1518 if(last == first && (!mwindow->edl->session->auto_keyframes))
1519 use_interpolated = 0;
1521 // If keyframe spanning occurs, use the interpolated points.
1522 // If new keyframe is generated, use the interpolated points.
1523 use_interpolated = 1;
1526 if(mwindow->edl->session->auto_keyframes)
1527 use_interpolated = 1;
1531 use_interpolated = 1;
1533 if(use_interpolated) {
1534 // Interpolate the points to get exactly what is being rendered at this position.
1535 mask_autos->get_points(&points,
1536 mwindow->edl->session->cwindow_mask,
1541 // Use the prev mask
1543 mask_autos->get_prev_auto(position,
1547 ((MaskAuto*)prev)->get_points(&points,
1548 mwindow->edl->session->cwindow_mask);
1551 // Projector zooms relative to the center of the track output.
1552 float half_track_w = (float)track->track_w / 2;
1553 float half_track_h = (float)track->track_h / 2;
1554 // Translate mask to projection
1555 float projector_x, projector_y, projector_z;
1556 track->automation->get_projector(
1557 &projector_x, &projector_y, &projector_z,
1558 position, PLAY_FORWARD);
1561 // Get position of cursor relative to mask
1562 float cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
1563 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1564 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1566 projector_x += mwindow->edl->session->output_w / 2;
1567 projector_y += mwindow->edl->session->output_h / 2;
1568 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1569 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1571 // Fix cursor origin
1573 gui->x_origin = mask_cursor_x;
1574 gui->y_origin = mask_cursor_y;
1578 // Points of closest line
1579 int shortest_point1 = -1;
1580 int shortest_point2 = -1;
1582 int shortest_point = -1;
1583 // Distance to closest line
1584 float shortest_line_distance = BC_INFINITY;
1585 // Distance to closest point
1586 float shortest_point_distance = BC_INFINITY;
1587 int selected_point = -1;
1588 int selected_control_point = -1;
1589 float selected_control_point_distance = BC_INFINITY;
1590 ArrayList<int> x_points;
1591 ArrayList<int> y_points;
1593 if(!cursor_motion) {
1595 get_canvas()->set_color(WHITE);
1596 get_canvas()->set_inverse();
1598 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1600 // Never draw closed polygon and a closed
1601 // polygon is harder to add points to.
1602 for(int i = 0; i < points.size() && !result; i++) {
1603 MaskPoint *point1 = points.get(i);
1604 MaskPoint *point2 = (i >= points.size() - 1) ?
1605 points.get(0) : points.get(i + 1);
1607 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1608 if(point_distance1 < shortest_point_distance || shortest_point < 0) {
1609 shortest_point_distance = point_distance1;
1613 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1614 if(point_distance2 < shortest_point_distance || shortest_point < 0) {
1615 shortest_point_distance = point_distance2;
1616 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1620 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1622 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1623 //point1->x, point1->y, point2->x, point2->y, projector_z);
1624 for(int j = 0; j <= segments && !result; j++) {
1625 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1626 float x0 = point1->x, y0 = point1->y;
1627 float x1 = point1->x + point1->control_x2;
1628 float y1 = point1->y + point1->control_y2;
1629 float x2 = point2->x + point2->control_x1;
1630 float y2 = point2->y + point2->control_y1;
1631 float x3 = point2->x, y3 = point2->y;
1632 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1633 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1634 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1635 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1636 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1637 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1638 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1639 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1641 float t = (float)j / segments;
1642 float tpow2 = t * t;
1643 float tpow3 = t * t * t;
1645 float invtpow2 = invt * invt;
1646 float invtpow3 = invt * invt * invt;
1648 float x = ( invtpow3 * x0
1649 + 3 * t * invtpow2 * x1
1650 + 3 * tpow2 * invt * x2
1652 float y = ( invtpow3 * y0
1653 + 3 * t * invtpow2 * y1
1654 + 3 * tpow2 * invt * y2
1656 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1657 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1658 // Test new point addition
1660 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1662 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1663 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1664 if(line_distance < shortest_line_distance ||
1665 shortest_point1 < 0) {
1666 shortest_line_distance = line_distance;
1667 shortest_point1 = i;
1668 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1669 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1670 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1673 // Test existing point selection
1675 if(gui->ctrl_down()) {
1676 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1678 if(distance < selected_control_point_distance) {
1680 selected_control_point = 1;
1681 selected_control_point_distance = distance;
1685 if(!gui->shift_down()) {
1686 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1687 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
1692 selected_point = shortest_point;
1695 // Test second point
1696 if(gui->ctrl_down()) {
1697 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1699 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1700 if(distance < selected_control_point_distance) {
1701 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1702 selected_control_point = 0;
1703 selected_control_point_distance = distance;
1706 else if(i < points.size() - 1) {
1707 if(!gui->shift_down()) {
1708 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1709 if(test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3)) {
1710 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1714 selected_point = shortest_point;
1719 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1723 if(draw) { // Draw joining line
1724 x_points.append((int)canvas_x);
1725 y_points.append((int)canvas_y);
1729 if(draw) { // Draw second anchor
1730 if(i < points.size() - 1) {
1731 if(i == gui->affected_point - 1)
1732 get_canvas()->draw_disc(
1733 (int)canvas_x - CONTROL_W / 2,
1734 (int)canvas_y - CONTROL_W / 2,
1735 CONTROL_W, CONTROL_H);
1737 get_canvas()->draw_circle(
1738 (int)canvas_x - CONTROL_W / 2,
1739 (int)canvas_y - CONTROL_W / 2,
1740 CONTROL_W, CONTROL_H);
1741 // char string[BCTEXTLEN];
1742 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1743 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1745 // Draw second control point.
1746 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1747 get_canvas()->draw_line(
1748 (int)canvas_x, (int)canvas_y,
1749 (int)canvas_x2, (int)canvas_y2);
1750 get_canvas()->draw_rectangle(
1751 (int)canvas_x2 - CONTROL_W / 2,
1752 (int)canvas_y2 - CONTROL_H / 2,
1753 CONTROL_W, CONTROL_H);
1758 // Draw first anchor
1759 if(i == 0 && draw) {
1760 char mask_label[BCSTRLEN];
1761 sprintf(mask_label, "%d",
1762 mwindow->edl->session->cwindow_mask);
1763 get_canvas()->draw_text(
1764 (int)canvas_x - FIRST_CONTROL_W,
1765 (int)canvas_y - FIRST_CONTROL_H,
1768 get_canvas()->draw_disc(
1769 (int)canvas_x - FIRST_CONTROL_W / 2,
1770 (int)canvas_y - FIRST_CONTROL_H / 2,
1771 FIRST_CONTROL_W, FIRST_CONTROL_H);
1774 // Draw first control point.
1776 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1777 get_canvas()->draw_line(
1778 (int)canvas_x, (int)canvas_y,
1779 (int)canvas_x1, (int)canvas_y1);
1780 get_canvas()->draw_rectangle(
1781 (int)canvas_x1 - CONTROL_W / 2,
1782 (int)canvas_y1 - CONTROL_H / 2,
1783 CONTROL_W, CONTROL_H);
1785 x_points.append((int)canvas_x);
1786 y_points.append((int)canvas_y);
1789 //printf("CWindowCanvas::do_mask 1\n");
1793 //printf("CWindowCanvas::do_mask 1\n");
1795 BC_WindowBase *cvs_win = get_canvas();
1797 cvs_win->draw_polygon(&x_points, &y_points);
1798 cvs_win->set_opaque();
1800 if( draw && gui->tool_panel ) {
1801 CWindowMaskGUI *mask_gui = (CWindowMaskGUI*)gui->tool_panel->tool_gui;
1802 if( mask_gui && mask_gui->focused ) {
1803 float fx = atof(mask_gui->focus_x->get_text());
1804 float fy = atof(mask_gui->focus_y->get_text());
1805 output_to_canvas(mwindow->edl, 0, fx, fy);
1806 float r = bmax(cvs_win->get_w(), cvs_win->get_h());
1808 cvs_win->set_line_width((int)(0.0025*r) + 1);
1809 cvs_win->set_color(BLUE);
1810 cvs_win->draw_line(fx-d,fy-d, fx+d, fy+d);
1811 cvs_win->draw_line(fx-d,fy+d, fx+d, fy-d);
1812 cvs_win->set_line_width(0);
1813 cvs_win->set_color(WHITE);
1816 //printf("CWindowCanvas::do_mask 1\n");
1819 if(button_press && !result) {
1820 gui->affected_track = gui->cwindow->calculate_affected_track();
1822 // Get keyframe outside the EDL to edit. This must be rendered
1823 // instead of the EDL keyframes when it exists. Then it must be
1824 // applied to the EDL keyframes on buttonrelease.
1825 if(gui->affected_track) {
1826 #ifdef USE_KEYFRAME_SPANNING
1827 // Make copy of current parameters in local keyframe
1828 gui->mask_keyframe =
1829 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1832 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1835 gui->mask_keyframe =
1836 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1841 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1843 if( get_buttonpress() == WHEEL_UP || get_buttonpress() == WHEEL_DOWN ) {
1844 if( !gui->shift_down() ) {
1845 mwindow->undo->update_undo_before(_("mask rotate"), this);
1846 gui->current_operation = CWINDOW_MASK_ROTATE;
1849 mwindow->undo->update_undo_before(_("mask scale"), this);
1850 gui->current_operation = CWINDOW_MASK_SCALE;
1852 gui->affected_point = 0;
1855 // Translate entire keyframe
1856 if(gui->alt_down() && mask->points.size()) {
1857 mwindow->undo->update_undo_before(_("mask translate"), 0);
1858 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1859 gui->affected_point = 0;
1862 // Existing point or control point was selected
1863 if(selected_point >= 0) {
1864 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1865 gui->affected_point = selected_point;
1867 if(selected_control_point == 0)
1868 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1870 if(selected_control_point == 1)
1871 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1873 gui->current_operation = mwindow->edl->session->cwindow_operation;
1875 else // No existing point or control point was selected so create a new one
1876 if(!gui->ctrl_down() && !gui->alt_down()) {
1877 mwindow->undo->update_undo_before(_("mask point"), 0);
1878 // Create the template
1879 MaskPoint *point = new MaskPoint;
1880 point->x = mask_cursor_x;
1881 point->y = mask_cursor_y;
1882 point->control_x1 = 0;
1883 point->control_y1 = 0;
1884 point->control_x2 = 0;
1885 point->control_y2 = 0;
1888 if(shortest_point2 < shortest_point1) {
1889 shortest_point2 ^= shortest_point1;
1890 shortest_point1 ^= shortest_point2;
1891 shortest_point2 ^= shortest_point1;
1896 // printf("CWindowGUI::do_mask 40\n");
1897 // mwindow->edl->dump();
1898 // printf("CWindowGUI::do_mask 50\n");
1902 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1903 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1904 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1906 // Append to end of list
1907 if( shortest_point1 == shortest_point2 ||
1908 labs(shortest_point1 - shortest_point2) > 1) {
1909 #ifdef USE_KEYFRAME_SPANNING
1911 MaskPoint *new_point = new MaskPoint;
1912 points.append(new_point);
1913 *new_point = *point;
1914 gui->affected_point = points.size() - 1;
1918 // Need to apply the new point to every keyframe
1919 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1920 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1921 MaskPoint *new_point = new MaskPoint;
1922 submask->points.append(new_point);
1923 *new_point = *point;
1924 if(current == (MaskAuto*)mask_autos->default_auto)
1925 current = (MaskAuto*)mask_autos->first;
1927 current = (MaskAuto*)NEXT;
1929 gui->affected_point = mask->points.size() - 1;
1935 // Insert between 2 points, shifting back point 2
1936 if(shortest_point1 >= 0 && shortest_point2 >= 0) {
1938 #ifdef USE_KEYFRAME_SPANNING
1939 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1941 if(points.size() >= shortest_point2) {
1942 MaskPoint *new_point = new MaskPoint;
1944 for(int i = points.size() - 1;
1945 i > shortest_point2;
1947 points.values[i] = points.values[i - 1];
1948 points.values[shortest_point2] = new_point;
1950 *new_point = *point;
1955 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1956 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1957 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1959 if(submask->points.size() >= shortest_point2) {
1960 MaskPoint *new_point = new MaskPoint;
1961 submask->points.append(0);
1962 for(int i = submask->points.size() - 1;
1963 i > shortest_point2;
1965 submask->points.values[i] = submask->points.values[i - 1];
1966 submask->points.values[shortest_point2] = new_point;
1968 *new_point = *point;
1971 if(current == (MaskAuto*)mask_autos->default_auto)
1972 current = (MaskAuto*)mask_autos->first;
1974 current = (MaskAuto*)NEXT;
1978 gui->affected_point = shortest_point2;
1983 // printf("CWindowGUI::do_mask 20\n");
1984 // mwindow->edl->dump();
1985 // printf("CWindowGUI::do_mask 30\n");
1988 //printf("CWindowCanvas::do_mask 1\n");
1989 // Create the first point.
1990 #ifdef USE_KEYFRAME_SPANNING
1991 MaskPoint *new_point = new MaskPoint;
1992 points.append(new_point);
1993 *new_point = *point;
1994 gui->affected_point = points.size() - 1;
1996 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1997 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1998 MaskPoint *new_point = new MaskPoint;
1999 submask->points.append(new_point);
2000 *new_point = *point;
2001 if(current == (MaskAuto*)mask_autos->default_auto)
2002 current = (MaskAuto*)mask_autos->first;
2004 current = (MaskAuto*)NEXT;
2006 gui->affected_point = points.size() - 1;
2009 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
2012 gui->current_operation = mwindow->edl->session->cwindow_operation;
2013 // Delete the template
2022 if(button_press && result) {
2023 #ifdef USE_KEYFRAME_SPANNING
2024 ArrayList<MaskPoint*> &mask_points = points;
2026 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
2027 ArrayList<MaskPoint*> &mask_points = mask->points;
2029 MaskPoint *point = mask_points.values[gui->affected_point];
2030 gui->center_x = point->x;
2031 gui->center_y = point->y;
2032 gui->control_in_x = point->control_x1;
2033 gui->control_in_y = point->control_y1;
2034 gui->control_out_x = point->control_x2;
2035 gui->control_out_y = point->control_y2;
2036 gui->tool_panel->raise_window();
2039 //printf("CWindowCanvas::do_mask 8\n");
2040 if( cursor_motion ) {
2042 #ifdef USE_KEYFRAME_SPANNING
2043 // Must update the reference keyframes for every cursor motion
2044 gui->mask_keyframe = (MaskAuto*)gui->cwindow->
2045 calculate_affected_auto(mask_autos, 0);
2046 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
2049 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2051 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
2052 if( gui->affected_point >= 0 && gui->affected_point < mask->points.size() &&
2053 gui->current_operation != CWINDOW_NONE) {
2054 // mwindow->undo->update_undo_before(_("mask point"), this);
2055 #ifdef USE_KEYFRAME_SPANNING
2056 ArrayList<MaskPoint*> &mask_points = points;
2058 ArrayList<MaskPoint*> &mask_points = mask->points;
2060 MaskPoint *point = mask_points.get(gui->affected_point);
2061 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2062 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask_points.size(), gui->affected_point);
2064 float last_x = point->x;
2065 float last_y = point->y;
2066 float last_control_x1 = point->control_x1;
2067 float last_control_y1 = point->control_y1;
2068 float last_control_x2 = point->control_x2;
2069 float last_control_y2 = point->control_y2;
2072 switch(gui->current_operation) {
2074 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2075 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
2076 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
2079 case CWINDOW_MASK_CONTROL_IN:
2080 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
2081 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
2084 case CWINDOW_MASK_CONTROL_OUT:
2085 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
2086 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
2089 case CWINDOW_MASK_TRANSLATE:
2090 for(int i = 0; i < mask_points.size(); i++) {
2091 mask_points.values[i]->x += mask_cursor_x - gui->x_origin;
2092 mask_points.values[i]->y += mask_cursor_y - gui->y_origin;
2094 gui->x_origin = mask_cursor_x;
2095 gui->y_origin = mask_cursor_y;
2097 case CWINDOW_MASK_ROTATE:
2099 case CWINDOW_MASK_SCALE: {
2100 int button_no = get_buttonpress();
2101 double scale = button_no == WHEEL_UP ? 1.02 : 0.98;
2102 double theta = button_no == WHEEL_UP ? M_PI/360. : -M_PI/360.;
2103 float st = sin(theta), ct = cos(theta);
2104 gui->x_origin = mask_cursor_x;
2105 gui->y_origin = mask_cursor_y;
2106 if( gui->tool_panel ) {
2107 CWindowMaskGUI *mask_gui = (CWindowMaskGUI*)gui->tool_panel->tool_gui;
2108 if( mask_gui && mask_gui->focused ) {
2109 gui->x_origin = atof(mask_gui->focus_x->get_text());
2110 gui->y_origin = atof(mask_gui->focus_y->get_text());
2113 for( int i=0; i<mask_points.size(); ++i ) {
2114 MaskPoint *point = mask_points.values[i];
2115 float px = point->x - gui->x_origin;
2116 float py = point->y - gui->y_origin;
2117 float nx = !rotate ? px*scale : px*ct + py*st;
2118 float ny = !rotate ? py*scale : py*ct - px*st;
2119 point->x = nx + gui->x_origin;
2120 point->y = ny + gui->y_origin;
2125 if( !EQUIV(last_x, point->x) ||
2126 !EQUIV(last_y, point->y) ||
2127 !EQUIV(last_control_x1, point->control_x1) ||
2128 !EQUIV(last_control_y1, point->control_y1) ||
2129 !EQUIV(last_control_x2, point->control_x2) ||
2130 !EQUIV(last_control_y2, point->control_y2)) {
2136 if(gui->current_operation == CWINDOW_NONE) {
2137 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
2139 for(int i = 0; i < points.size() && !over_point; i++) {
2140 MaskPoint *point = points.get(i);
2141 float x0 = point->x;
2142 float y0 = point->y;
2143 float x1 = point->x + point->control_x1;
2144 float y1 = point->y + point->control_y1;
2145 float x2 = point->x + point->control_x2;
2146 float y2 = point->y + point->control_y2;
2147 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
2148 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
2150 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
2151 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
2155 if(!over_point && gui->ctrl_down()) {
2156 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
2157 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
2158 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2159 if(test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1)) {
2163 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2164 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2165 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2166 if(test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2)) {
2173 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2178 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2181 #ifdef USE_KEYFRAME_SPANNING
2182 // Must commit change after operation.
2183 if(rerender && track) {
2184 // Swap EDL keyframe with original.
2185 // Apply new values to keyframe span
2186 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2187 temp_keyframe.copy_data(gui->mask_keyframe);
2188 // Apply interpolated points back to keyframe
2189 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2190 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2191 mask_autos->update_parameter(&temp_keyframe);
2195 points.remove_all_objects();
2196 //printf("CWindowCanvas::do_mask 20\n");
2200 int CWindowCanvas::do_mask_focus()
2202 CWindowMaskGUI *mask_gui = (CWindowMaskGUI*) gui->tool_panel->tool_gui;
2203 float cx = get_cursor_x(), cy = get_cursor_y();
2204 canvas_to_output(mwindow->edl, 0, cx, cy);
2205 int v = mask_gui->focused ? 0 : 1;
2206 get_canvas()->unlock_window();
2207 mask_gui->lock_window("CWindowCanvas::do_mask_focus");
2208 mask_gui->set_focused(v, cx, cy);
2209 mask_gui->unlock_window();
2210 get_canvas()->lock_window("CWindowCanvas::do_mask_focus");
2214 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2217 int radius = mwindow->edl->session->eyedrop_radius;
2225 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2230 row1 = gui->eyedrop_y - radius;
2231 row2 = gui->eyedrop_y + radius;
2232 column1 = gui->eyedrop_x - radius;
2233 column2 = gui->eyedrop_x + radius;
2235 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2236 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2237 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2238 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2240 if(row2 <= row1) row2 = row1 + 1;
2241 if(column2 <= column1) column2 = column1 + 1;
2248 output_to_canvas(mwindow->edl, 0, x1, y1);
2249 output_to_canvas(mwindow->edl, 0, x2, y2);
2250 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2252 if(x2 - x1 >= 1 && y2 - y1 >= 1)
2254 get_canvas()->set_inverse();
2255 get_canvas()->set_color(WHITE);
2257 get_canvas()->draw_rectangle((int)x1,
2262 get_canvas()->set_opaque();
2263 get_canvas()->flash();
2271 gui->current_operation = CWINDOW_EYEDROP;
2272 gui->tool_panel->raise_window();
2275 if(gui->current_operation == CWINDOW_EYEDROP)
2277 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2279 // Get color out of frame.
2280 // Doesn't work during playback because that bypasses the refresh frame.
2281 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2283 float cursor_x = get_cursor_x();
2284 float cursor_y = get_cursor_y();
2285 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2286 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2287 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2289 row1 = cursor_y - radius;
2290 row2 = cursor_y + radius;
2291 column1 = cursor_x - radius;
2292 column2 = cursor_x + radius;
2293 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2294 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2295 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2296 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2297 if(row2 <= row1) row2 = row1 + 1;
2298 if(column2 <= column1) column2 = column1 + 1;
2302 if(gui->eyedrop_visible)
2305 do_eyedrop(temp, 0, 1);
2306 gui->eyedrop_visible = 0;
2309 gui->eyedrop_x = cursor_x;
2310 gui->eyedrop_y = cursor_y;
2315 do_eyedrop(temp, 0, 1);
2316 gui->eyedrop_visible = 1;
2319 // Decompression coefficients straight out of jpeglib
2320 #define V_TO_R 1.40200
2321 #define V_TO_G -0.71414
2323 #define U_TO_G -0.34414
2324 #define U_TO_B 1.77200
2326 #define GET_COLOR(type, components, max, do_yuv) \
2328 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2330 float red = (float)*row++ / max; \
2331 float green = (float)*row++ / max; \
2332 float blue = (float)*row++ / max; \
2335 float r = red + V_TO_R * (blue - 0.5); \
2336 float g = red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
2337 float b = red + U_TO_B * (green - 0.5); \
2338 mwindow->edl->local_session->red += r; \
2339 mwindow->edl->local_session->green += g; \
2340 mwindow->edl->local_session->blue += b; \
2341 if(r > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = r; \
2342 if(g > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = g; \
2343 if(b > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = b; \
2347 mwindow->edl->local_session->red += red; \
2348 mwindow->edl->local_session->green += green; \
2349 mwindow->edl->local_session->blue += blue; \
2350 if(red > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = red; \
2351 if(green > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = green; \
2352 if(blue > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = blue; \
2358 mwindow->edl->local_session->red = 0;
2359 mwindow->edl->local_session->green = 0;
2360 mwindow->edl->local_session->blue = 0;
2361 mwindow->edl->local_session->red_max = 0;
2362 mwindow->edl->local_session->green_max = 0;
2363 mwindow->edl->local_session->blue_max = 0;
2364 for(int i = row1; i < row2; i++)
2366 for(int j = column1; j < column2; j++)
2368 switch(refresh_frame->get_color_model())
2371 GET_COLOR(unsigned char, 3, 0xff, 1);
2374 GET_COLOR(unsigned char, 4, 0xff, 1);
2377 GET_COLOR(uint16_t, 3, 0xffff, 1);
2379 case BC_YUVA16161616:
2380 GET_COLOR(uint16_t, 4, 0xffff, 1);
2383 GET_COLOR(unsigned char, 3, 0xff, 0);
2386 GET_COLOR(unsigned char, 4, 0xff, 0);
2389 GET_COLOR(float, 3, 1.0, 0);
2392 GET_COLOR(float, 4, 1.0, 0);
2398 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2399 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2400 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2405 mwindow->edl->local_session->red = 0;
2406 mwindow->edl->local_session->green = 0;
2407 mwindow->edl->local_session->blue = 0;
2408 gui->eyedrop_visible = 0;
2417 // Can't rerender since the color value is from the output of any effect it
2420 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2426 int CWindowCanvas::need_overlays()
2428 if( mwindow->edl->session->safe_regions ) return 1;
2429 if( mwindow->edl->session->cwindow_scrollbars ) return 1;
2430 if( gui->highlighted ) return 1;
2431 switch( mwindow->edl->session->cwindow_operation ) {
2432 case CWINDOW_EYEDROP:
2433 if( ! gui->eyedrop_visible ) break;
2434 case CWINDOW_CAMERA:
2435 case CWINDOW_PROJECTOR:
2444 void CWindowCanvas::draw_overlays()
2446 if(mwindow->edl->session->safe_regions)
2448 draw_safe_regions();
2451 if(mwindow->edl->session->cwindow_scrollbars)
2453 // Always draw output rectangle
2454 float x1, y1, x2, y2;
2456 x2 = mwindow->edl->session->output_w;
2458 y2 = mwindow->edl->session->output_h;
2459 output_to_canvas(mwindow->edl, 0, x1, y1);
2460 output_to_canvas(mwindow->edl, 0, x2, y2);
2462 get_canvas()->set_inverse();
2463 get_canvas()->set_color(WHITE);
2465 get_canvas()->draw_rectangle((int)x1,
2470 get_canvas()->set_opaque();
2473 if(gui->highlighted)
2475 get_canvas()->set_color(WHITE);
2476 get_canvas()->set_inverse();
2477 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2478 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2479 get_canvas()->set_opaque();
2482 int temp1 = 0, temp2 = 0;
2483 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2484 switch(mwindow->edl->session->cwindow_operation)
2486 case CWINDOW_CAMERA:
2490 case CWINDOW_PROJECTOR:
2499 do_mask(temp1, temp2, 0, 0, 1);
2503 do_ruler(1, 0, 0, 0);
2506 case CWINDOW_EYEDROP:
2507 if(gui->eyedrop_visible)
2510 do_eyedrop(rerender, 0, 1);
2511 gui->eyedrop_visible = 1;
2517 void CWindowCanvas::draw_safe_regions()
2519 float action_x1, action_x2, action_y1, action_y2;
2520 float title_x1, title_x2, title_y1, title_y2;
2522 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2523 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2524 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2525 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2526 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2527 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2528 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2529 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2531 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2532 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2533 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2534 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2536 get_canvas()->set_inverse();
2537 get_canvas()->set_color(WHITE);
2539 get_canvas()->draw_rectangle((int)action_x1,
2541 (int)(action_x2 - action_x1),
2542 (int)(action_y2 - action_y1));
2543 get_canvas()->draw_rectangle((int)title_x1,
2545 (int)(title_x2 - title_x1),
2546 (int)(title_y2 - title_y1));
2548 get_canvas()->set_opaque();
2552 void CWindowCanvas::create_keyframe(int do_camera)
2554 Track *affected_track = gui->cwindow->calculate_affected_track();
2555 if( affected_track ) {
2556 double pos = mwindow->edl->local_session->get_selectionstart(1);
2557 int64_t position = affected_track->to_units(pos, 0);
2558 int ix = do_camera ? AUTOMATION_CAMERA_X : AUTOMATION_PROJECTOR_X;
2559 int iy = do_camera ? AUTOMATION_CAMERA_Y : AUTOMATION_PROJECTOR_Y;
2560 int iz = do_camera ? AUTOMATION_CAMERA_Z : AUTOMATION_PROJECTOR_Z;
2561 FloatAuto *prev, *next;
2562 FloatAutos **autos = (FloatAutos**)affected_track->automation->autos;
2563 FloatAutos *x_autos = autos[ix]; prev = 0; next = 0;
2564 float x_value = x_autos->get_value(position, PLAY_FORWARD, prev, next);
2565 FloatAutos *y_autos = autos[iy]; prev = 0; next = 0;
2566 float y_value = y_autos->get_value(position, PLAY_FORWARD, prev, next);
2567 FloatAutos *z_autos = autos[iz]; prev = 0; next = 0;
2568 float z_value = z_autos->get_value(position, PLAY_FORWARD, prev, next);
2569 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2571 gui->cwindow->calculate_affected_autos(affected_track,
2572 &x_keyframe, &y_keyframe, &z_keyframe,
2573 do_camera, -1, -1, -1, 0);
2574 x_keyframe->set_value(x_value);
2575 y_keyframe->set_value(y_value);
2576 z_keyframe->set_value(z_value);
2578 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2582 void CWindowCanvas::camera_keyframe() { create_keyframe(1); }
2583 void CWindowCanvas::projector_keyframe() { create_keyframe(0); }
2585 void CWindowCanvas::reset_keyframe(int do_camera)
2587 Track *affected_track = gui->cwindow->calculate_affected_track();
2588 if( affected_track ) {
2589 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2590 gui->cwindow->calculate_affected_autos(affected_track,
2591 &x_keyframe, &y_keyframe, &z_keyframe,
2592 do_camera, 1, 1, 1);
2594 x_keyframe->set_value(0);
2595 y_keyframe->set_value(0);
2596 z_keyframe->set_value(1);
2598 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2602 void CWindowCanvas::reset_camera() { reset_keyframe(1); }
2603 void CWindowCanvas::reset_projector() { reset_keyframe(0); }
2606 int CWindowCanvas::test_crop(int button_press, int &redraw)
2609 int handle_selected = -1;
2610 float x1 = mwindow->edl->session->crop_x1;
2611 float y1 = mwindow->edl->session->crop_y1;
2612 float x2 = mwindow->edl->session->crop_x2;
2613 float y2 = mwindow->edl->session->crop_y2;
2614 float cursor_x = get_cursor_x();
2615 float cursor_y = get_cursor_y();
2616 float canvas_x1 = x1;
2617 float canvas_y1 = y1;
2618 float canvas_x2 = x2;
2619 float canvas_y2 = y2;
2620 float canvas_cursor_x = cursor_x;
2621 float canvas_cursor_y = cursor_y;
2623 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2624 // Use screen normalized coordinates for hot spot tests.
2625 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2626 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2629 if(gui->current_operation == CWINDOW_CROP)
2631 handle_selected = gui->crop_handle;
2634 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2635 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2637 handle_selected = 0;
2638 gui->crop_origin_x = x1;
2639 gui->crop_origin_y = y1;
2642 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2643 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2645 handle_selected = 1;
2646 gui->crop_origin_x = x2;
2647 gui->crop_origin_y = y1;
2650 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2651 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2653 handle_selected = 2;
2654 gui->crop_origin_x = x1;
2655 gui->crop_origin_y = y2;
2658 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2659 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2661 handle_selected = 3;
2662 gui->crop_origin_x = x2;
2663 gui->crop_origin_y = y2;
2668 gui->crop_origin_x = cursor_x;
2669 gui->crop_origin_y = cursor_y;
2672 // printf("test crop %d %d\n",
2673 // gui->current_operation,
2674 // handle_selected);
2681 gui->crop_translate = 1;
2682 gui->crop_origin_x1 = x1;
2683 gui->crop_origin_y1 = y1;
2684 gui->crop_origin_x2 = x2;
2685 gui->crop_origin_y2 = y2;
2688 gui->crop_translate = 0;
2690 gui->current_operation = CWINDOW_CROP;
2691 gui->crop_handle = handle_selected;
2692 gui->x_origin = cursor_x;
2693 gui->y_origin = cursor_y;
2694 gui->tool_panel->raise_window();
2697 if(handle_selected < 0 && !gui->crop_translate)
2701 mwindow->edl->session->crop_x1 = (int)x1;
2702 mwindow->edl->session->crop_y1 = (int)y1;
2703 mwindow->edl->session->crop_x2 = (int)x2;
2704 mwindow->edl->session->crop_y2 = (int)y2;
2709 // Translate all 4 points
2710 if(gui->current_operation == CWINDOW_CROP && gui->crop_translate)
2712 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2713 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2714 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2715 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2717 mwindow->edl->session->crop_x1 = (int)x1;
2718 mwindow->edl->session->crop_y1 = (int)y1;
2719 mwindow->edl->session->crop_x2 = (int)x2;
2720 mwindow->edl->session->crop_y2 = (int)y2;
2726 if(gui->current_operation == CWINDOW_CROP)
2728 switch(gui->crop_handle)
2731 x1 = gui->crop_origin_x;
2732 y1 = gui->crop_origin_y;
2733 x2 = gui->crop_origin_x;
2734 y2 = gui->crop_origin_y;
2735 if(cursor_x < gui->x_origin)
2737 if(cursor_y < gui->y_origin)
2743 if(cursor_y >= gui->y_origin)
2750 if(cursor_x >= gui->x_origin)
2752 if(cursor_y < gui->y_origin)
2758 if(cursor_y >= gui->y_origin)
2765 // printf("test crop %d %d %d %d\n",
2766 // mwindow->edl->session->crop_x1,
2767 // mwindow->edl->session->crop_y1,
2768 // mwindow->edl->session->crop_x2,
2769 // mwindow->edl->session->crop_y2);
2772 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2773 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2776 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2777 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2780 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2781 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2784 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2785 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2789 if(!EQUIV(mwindow->edl->session->crop_x1, x1) ||
2790 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2791 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2792 !EQUIV(mwindow->edl->session->crop_y2, y2))
2799 switch (gui->crop_handle)
2801 case 0: gui->crop_handle = 1; break;
2802 case 1: gui->crop_handle = 0; break;
2803 case 2: gui->crop_handle = 3; break;
2804 case 3: gui->crop_handle = 2; break;
2814 switch (gui->crop_handle)
2816 case 0: gui->crop_handle = 2; break;
2817 case 1: gui->crop_handle = 3; break;
2818 case 2: gui->crop_handle = 0; break;
2819 case 3: gui->crop_handle = 1; break;
2824 mwindow->edl->session->crop_x1 = (int)x1;
2825 mwindow->edl->session->crop_y1 = (int)y1;
2826 mwindow->edl->session->crop_x2 = (int)x2;
2827 mwindow->edl->session->crop_y2 = (int)y2;
2833 // Update cursor font
2834 if(handle_selected >= 0)
2836 switch(handle_selected)
2839 set_cursor(UPLEFT_RESIZE);
2842 set_cursor(UPRIGHT_RESIZE);
2845 set_cursor(DOWNLEFT_RESIZE);
2848 set_cursor(DOWNRIGHT_RESIZE);
2855 set_cursor(ARROW_CURSOR);
2857 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2861 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2862 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2863 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2864 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2865 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2866 // mwindow->edl->session->crop_x2,
2867 // mwindow->edl->session->crop_y2,
2868 // mwindow->edl->calculate_output_w(0),
2869 // mwindow->edl->calculate_output_h(0));
2875 void CWindowCanvas::draw_crop()
2877 get_canvas()->set_inverse();
2878 get_canvas()->set_color(WHITE);
2880 float x1 = mwindow->edl->session->crop_x1;
2881 float y1 = mwindow->edl->session->crop_y1;
2882 float x2 = mwindow->edl->session->crop_x2;
2883 float y2 = mwindow->edl->session->crop_y2;
2885 output_to_canvas(mwindow->edl, 0, x1, y1);
2886 output_to_canvas(mwindow->edl, 0, x2, y2);
2888 if(x2 - x1 && y2 - y1)
2889 get_canvas()->draw_rectangle((int)x1,
2894 draw_crophandle((int)x1, (int)y1);
2895 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2896 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2897 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2898 get_canvas()->set_opaque();
2902 void CWindowCanvas::draw_outlines(int do_camera)
2904 Track *track = gui->cwindow->calculate_affected_track();
2908 float proj_x, proj_y, proj_z;
2909 int64_t position = track->to_units(
2910 mwindow->edl->local_session->get_selectionstart(1),
2912 track->automation->get_projector(&proj_x, &proj_y, &proj_z,
2913 position, PLAY_FORWARD);
2915 proj_x += mwindow->edl->session->output_w/2.;
2916 proj_y += mwindow->edl->session->output_h/2.;
2917 float proj_x1 = proj_x - track->track_w/2. * proj_z;
2918 float proj_y1 = proj_y - track->track_h/2. * proj_z;
2919 float proj_x2 = proj_x + track->track_w/2. * proj_z;
2920 float proj_y2 = proj_y + track->track_h/2. * proj_z;
2921 float x1 = proj_x1, x2 = proj_x2;
2922 float y1 = proj_y1, y2 = proj_y2;
2923 output_to_canvas(mwindow->edl, 0, x1, y1);
2924 output_to_canvas(mwindow->edl, 0, x2, y2);
2926 #define DRAW_PROJECTION(offset) \
2927 get_canvas()->draw_rectangle(x1+offset, y1+offset, (x2-x1), (y2-y1)); \
2928 get_canvas()->draw_line(x1+offset, y1+offset, x2+offset, y2+offset); \
2929 get_canvas()->draw_line(x2+offset, y1+offset, x1+offset, y2+offset); \
2932 get_canvas()->set_color(BLACK);
2934 get_canvas()->set_color(do_camera ? GREEN : RED);
2938 float cam_x, cam_y, cam_z;
2939 track->automation->get_camera(&cam_x, &cam_y, &cam_z,
2940 position, PLAY_FORWARD);
2941 cam_x += track->track_w / 2.;
2942 cam_y += track->track_h / 2.;
2943 // follow image, not camera
2944 cam_x = -cam_x; cam_y = -cam_y; cam_z *= proj_z;
2945 float cam_x1 = cam_x * cam_z + proj_x;
2946 float cam_y1 = cam_y * cam_z + proj_y;
2947 float cam_x2 = (cam_x + track->track_w) * cam_z + proj_x;
2948 float cam_y2 = (cam_y + track->track_h) * cam_z + proj_y;
2949 output_to_canvas(mwindow->edl, 0, cam_x1, cam_y1);
2950 output_to_canvas(mwindow->edl, 0, cam_x2, cam_y2);
2951 get_canvas()->set_color(YELLOW);
2952 get_canvas()->draw_rectangle(cam_x1, cam_y1, cam_x2-cam_x1, cam_y2-cam_y1);
2956 int CWindowCanvas::test_bezier(int button_press,
2964 // Processing drag operation.
2965 // Create keyframe during first cursor motion.
2966 if( !button_press ) {
2968 float cursor_x = get_cursor_x();
2969 float cursor_y = get_cursor_y();
2970 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2972 if( gui->current_operation == CWINDOW_CAMERA ||
2973 gui->current_operation == CWINDOW_PROJECTOR ) {
2974 if( !gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom ) {
2975 gui->translating_zoom = 1;
2976 gui->reset_affected();
2978 else if( !gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom ) {
2979 gui->translating_zoom = 0;
2980 gui->reset_affected();
2983 // Get target keyframe
2984 if( !gui->affected_x && !gui->affected_y && !gui->affected_z ) {
2985 if(!gui->affected_track) return 0;
2986 FloatAutos *affected_x_autos, *affected_y_autos, *affected_z_autos;
2987 FloatAutos** autos = (FloatAutos**) gui->affected_track->automation->autos;
2988 if( mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA ) {
2989 affected_x_autos = autos[AUTOMATION_CAMERA_X];
2990 affected_y_autos = autos[AUTOMATION_CAMERA_Y];
2991 affected_z_autos = autos[AUTOMATION_CAMERA_Z];
2994 affected_x_autos = autos[AUTOMATION_PROJECTOR_X];
2995 affected_y_autos = autos[AUTOMATION_PROJECTOR_Y];
2996 affected_z_autos = autos[AUTOMATION_PROJECTOR_Z];
2998 double position = mwindow->edl->local_session->get_selectionstart(1);
2999 int64_t track_position = gui->affected_track->to_units(position, 0);
3000 FloatAuto *prev_x = 0, *next_x = 0;
3001 float new_x = affected_x_autos->get_value(track_position, PLAY_FORWARD, prev_x, next_x);
3002 FloatAuto *prev_y = 0, *next_y = 0;
3003 float new_y = affected_y_autos->get_value(track_position, PLAY_FORWARD, prev_y, next_y);
3004 FloatAuto *prev_z = 0, *next_z = 0;
3005 float new_z = affected_z_autos->get_value(track_position, PLAY_FORWARD, prev_z, next_z);
3006 int zooming = gui->translating_zoom, created;
3007 gui->affected_x = (FloatAuto*)gui->cwindow->calculate_affected_auto(
3008 affected_x_autos, !zooming, &created, 0);
3010 gui->affected_x->set_value(new_x);
3013 gui->affected_y = (FloatAuto*)gui->cwindow->calculate_affected_auto(
3014 affected_y_autos, !zooming, &created, 0);
3016 gui->affected_y->set_value(new_y);
3019 gui->affected_z = (FloatAuto*)gui->cwindow->calculate_affected_auto(
3020 affected_z_autos, zooming, &created, 0);
3022 gui->affected_z->set_value(new_z);
3027 if( gui->translating_zoom ) {
3028 gui->center_z = gui->affected_z->get_value();
3031 gui->center_x = gui->affected_x->get_value();
3032 gui->center_y = gui->affected_y->get_value();
3039 float x_val = gui->affected_x->get_value();
3040 float y_val = gui->affected_y->get_value();
3041 float z_val = gui->affected_z->get_value();
3043 if( gui->translating_zoom ) {
3044 float z = gui->center_z + (cursor_y - gui->y_origin) / 128;
3046 if( !EQUIV(z_val, z) ) {
3051 gui->affected_z->set_value(z);
3054 float dx = cursor_x - gui->x_origin;
3055 float dy = cursor_y - gui->y_origin;
3056 // follow image, not camera
3057 if( gui->current_operation == CWINDOW_CAMERA ) {
3058 dx = -dx / z_val; dy = -dy / z_val;
3060 float x = gui->center_x + dx;
3061 float y = gui->center_y + dy;
3062 gui->affected_x->set_value(x);
3063 gui->affected_y->set_value(y);
3064 if( !EQUIV(x_val, x) || !EQUIV(y_val, y) ) {
3075 // Begin drag operation. Don't create keyframe here.
3077 // Get affected track off of the first recordable video track.
3078 // Calculating based on the alpha channel would require recording what layer
3079 // each output pixel belongs to as they're rendered and stacked. Forget it.
3080 gui->affected_track = gui->cwindow->calculate_affected_track();
3081 gui->reset_affected();
3083 if(gui->affected_track)
3086 mwindow->undo->update_undo_before(_("camera"), this);
3088 mwindow->undo->update_undo_before(_("projector"), this);
3090 gui->current_operation =
3091 mwindow->edl->session->cwindow_operation;
3092 gui->tool_panel->raise_window();
3101 int CWindowCanvas::test_zoom(int &redraw)
3107 if( mwindow->edl->session->cwindow_scrollbars ) {
3108 if( *gui->zoom_panel->get_text() != 'x' ) {
3109 // Find current zoom in table
3110 int idx = total_zooms; float old_zoom = get_zoom();
3111 while( --idx >= 0 && !EQUIV(my_zoom_table[idx], old_zoom) );
3113 idx += get_buttonpress() == 5 ||
3114 gui->ctrl_down() || gui->shift_down() ? -1 : +1 ;
3115 CLAMP(idx, 0, total_zooms-1);
3116 zoom = my_zoom_table[idx];
3119 x = get_cursor_x(); y = get_cursor_y();
3121 mwindow->edl->session->cwindow_scrollbars = 0;
3122 gui->zoom_panel->update(0);
3123 zoom = gui->get_auto_zoom();
3126 gui->zoom_panel->ZoomPanel::update(zoom);
3127 float output_x = x, output_y = y;
3128 canvas_to_output(mwindow->edl, 0, output_x, output_y);
3129 x = output_x - x / zoom;
3130 y = output_y - y / zoom;
3134 mwindow->edl->session->cwindow_scrollbars = 1;
3135 x = (mwindow->edl->session->output_w - w) / 2;
3136 y = (mwindow->edl->session->output_h - h) / 2;
3139 update_zoom((int)x, (int)y, zoom);
3141 gui->composite_panel->cpanel_zoom->update(zoom);
3143 reposition_window(mwindow->edl,
3144 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
3145 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
3146 redraw = 1; result = 1;
3152 void CWindowCanvas::calculate_origin()
3154 gui->x_origin = get_cursor_x();
3155 gui->y_origin = get_cursor_y();
3156 //printf("CWindowCanvas::calculate_origin 1 %f %f\n", gui->x_origin, gui->y_origin);
3157 canvas_to_output(mwindow->edl, 0, gui->x_origin, gui->y_origin);
3158 //printf("CWindowCanvas::calculate_origin 2 %f %f\n", gui->x_origin, gui->y_origin);
3162 int CWindowCanvas::cursor_leave_event()
3164 set_cursor(ARROW_CURSOR);
3168 int CWindowCanvas::cursor_enter_event()
3171 switch(mwindow->edl->session->cwindow_operation)
3173 case CWINDOW_CAMERA:
3174 case CWINDOW_PROJECTOR:
3175 set_cursor(MOVE_CURSOR);
3178 set_cursor(MOVE_CURSOR);
3181 test_crop(0, redraw);
3183 case CWINDOW_PROTECT:
3184 set_cursor(ARROW_CURSOR);
3188 set_cursor(CROSS_CURSOR);
3190 case CWINDOW_EYEDROP:
3191 set_cursor(CROSS_CURSOR);
3197 int CWindowCanvas::cursor_motion_event()
3199 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3202 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3203 switch(gui->current_operation)
3205 case CWINDOW_SCROLL:
3207 float zoom = get_zoom();
3208 float cursor_x = get_cursor_x();
3209 float cursor_y = get_cursor_y();
3211 float zoom_x, zoom_y, conformed_w, conformed_h;
3212 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3213 cursor_x = (float)cursor_x / zoom_x + gui->x_offset;
3214 cursor_y = (float)cursor_y / zoom_y + gui->y_offset;
3218 int x = (int)(gui->x_origin - cursor_x + gui->x_offset);
3219 int y = (int)(gui->y_origin - cursor_y + gui->y_offset);
3224 update_scrollbars(0);
3231 result = do_ruler(0, 1, 0, 0);
3234 case CWINDOW_CAMERA:
3235 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3238 case CWINDOW_PROJECTOR:
3239 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3244 result = test_crop(0, redraw);
3245 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3252 case CWINDOW_MASK_CONTROL_IN:
3253 case CWINDOW_MASK_CONTROL_OUT:
3254 case CWINDOW_MASK_TRANSLATE:
3256 result = do_mask(redraw,
3263 case CWINDOW_EYEDROP:
3264 result = do_eyedrop(rerender, 0, 0);
3273 // cursor font changes
3276 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3278 // mwindow->edl->session->cwindow_operation);
3279 switch(mwindow->edl->session->cwindow_operation)
3282 result = test_crop(0, redraw);
3285 result = do_ruler(0, 1, 0, 0);
3288 result = do_mask(redraw,
3297 int change_type = rerender ? CHANGE_PARAMS : -1;
3298 gui->sync_parameters(change_type, redraw, redraw_canvas);
3303 int CWindowCanvas::button_press_event()
3307 int redraw_canvas = 0;
3310 if(Canvas::button_press_event()) return 1;
3312 gui->translating_zoom = gui->shift_down();
3315 //printf("CWindowCanvas::button_press_event 2 %f %f\n", gui->x_origin, gui->y_origin, gui->x_origin, gui->y_origin);
3317 float zoom_x, zoom_y, conformed_w, conformed_h;
3318 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3319 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3320 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3323 if( mwindow->edl->session->cwindow_operation != CWINDOW_PROTECT &&
3324 get_buttonpress() == MIDDLE_BUTTON && !get_canvas()->shift_down() )
3326 gui->current_operation = CWINDOW_SCROLL;
3332 switch(mwindow->edl->session->cwindow_operation)
3335 result = do_ruler(0, 0, 1, 0);
3338 case CWINDOW_CAMERA:
3339 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3342 case CWINDOW_PROJECTOR:
3343 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3347 result = test_zoom(redraw);
3351 result = test_crop(1, redraw);
3355 switch( get_buttonpress() ) {
3357 result = do_mask(redraw, rerender, 1, 0, 0);
3359 case MIDDLE_BUTTON: { // && shift_down()
3360 result = do_mask_focus();
3366 result = do_mask(redraw, rerender, 1, 1, 0);
3369 if( result ) redraw_canvas = 1;
3372 case CWINDOW_EYEDROP:
3373 result = do_eyedrop(rerender, 1, 0);
3378 int change_type = rerender ? CHANGE_PARAMS : -1;
3379 gui->sync_parameters(change_type, redraw, redraw_canvas);
3384 int CWindowCanvas::button_release_event()
3387 const char *undo_label = 0;
3389 switch(gui->current_operation)
3391 case CWINDOW_SCROLL:
3396 do_ruler(0, 0, 0, 1);
3399 case CWINDOW_CAMERA:
3400 undo_label = _("camera");
3403 case CWINDOW_PROJECTOR:
3404 undo_label = _("projector");
3408 case CWINDOW_MASK_CONTROL_IN:
3409 case CWINDOW_MASK_CONTROL_OUT:
3410 case CWINDOW_MASK_TRANSLATE:
3411 // Finish mask operation
3412 gui->mask_keyframe = 0;
3413 undo_label = _("mask");
3415 case CWINDOW_MASK_ROTATE:
3416 gui->mask_keyframe = 0;
3417 undo_label = _("mask rotate");
3419 case CWINDOW_MASK_SCALE:
3420 gui->mask_keyframe = 0;
3421 undo_label = _("mask scale");
3424 result = Canvas::button_release_event();
3429 mwindow->undo->update_undo_after(undo_label, LOAD_AUTOMATION);
3430 gui->current_operation = CWINDOW_NONE;
3434 void CWindowCanvas::zoom_resize_window(float percentage)
3436 int canvas_w, canvas_h;
3440 // Get required canvas size
3441 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3442 mwindow->edl->session->output_w,
3443 mwindow->edl->session->output_h,
3448 // Estimate window size from current borders
3449 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3450 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3452 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3453 mwindow->session->cwindow_w = new_w;
3454 mwindow->session->cwindow_h = new_h;
3456 mwindow->theme->get_cwindow_sizes(gui,
3457 mwindow->session->cwindow_controls);
3459 // Estimate again from new borders
3460 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3461 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3462 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3464 gui->resize_window(new_w, new_h);
3465 gui->resize_event(new_w, new_h);
3468 void CWindowCanvas::toggle_controls()
3470 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3471 gui->resize_event(gui->get_w(), gui->get_h());
3474 int CWindowCanvas::get_cwindow_controls()
3476 return mwindow->session->cwindow_controls;