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;
133 delete orig_mask_keyframe;
136 void CWindowGUI::create_objects()
138 lock_window("CWindowGUI::create_objects");
139 set_icon(mwindow->theme->get_image("cwindow_icon"));
141 active = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_active"));
142 inactive = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_inactive"));
143 focus_frame = new VFramePng(mwindow->theme->get_image_data("cwindow_focus.png"));
145 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
146 mwindow->theme->draw_cwindow_bg(this);
149 // Meters required by composite panel
150 meters = new CWindowMeters(mwindow,
152 mwindow->theme->cmeter_x,
153 mwindow->theme->cmeter_y,
154 mwindow->theme->cmeter_h);
155 meters->create_objects();
158 composite_panel = new CPanel(mwindow,
160 mwindow->theme->ccomposite_x,
161 mwindow->theme->ccomposite_y,
162 mwindow->theme->ccomposite_w,
163 mwindow->theme->ccomposite_h);
164 composite_panel->create_objects();
166 canvas = new CWindowCanvas(mwindow, this);
168 canvas->create_objects(mwindow->edl);
169 canvas->use_cwindow();
172 add_subwindow(timebar = new CTimeBar(mwindow,
174 mwindow->theme->ctimebar_x,
175 mwindow->theme->ctimebar_y,
176 mwindow->theme->ctimebar_w,
177 mwindow->theme->ctimebar_h));
178 timebar->create_objects();
181 add_subwindow(slider = new CWindowSlider(mwindow,
183 mwindow->theme->cslider_x,
184 mwindow->theme->cslider_y,
185 mwindow->theme->cslider_w));
188 transport = new CWindowTransport(mwindow,
190 mwindow->theme->ctransport_x,
191 mwindow->theme->ctransport_y);
192 transport->create_objects();
194 transport->set_slider(slider);
197 edit_panel = new CWindowEditing(mwindow, cwindow);
198 edit_panel->set_meters(meters);
199 edit_panel->create_objects();
201 // add_subwindow(clock = new MainClock(mwindow,
202 // mwindow->theme->ctime_x,
203 // mwindow->theme->ctime_y));
205 zoom_panel = new CWindowZoom(mwindow,
207 mwindow->theme->czoom_x,
208 mwindow->theme->czoom_y,
209 mwindow->theme->czoom_w);
210 zoom_panel->create_objects();
211 zoom_panel->zoom_text->add_item(new BC_MenuItem(auto_zoom = _(AUTO_ZOOM)));
212 if( !mwindow->edl->session->cwindow_scrollbars )
213 zoom_panel->set_text(auto_zoom);
215 // destination = new CWindowDestination(mwindow,
217 // mwindow->theme->cdest_x,
218 // mwindow->theme->cdest_y);
219 // destination->create_objects();
221 // Must create after meter panel
222 tool_panel = new CWindowTool(mwindow, this);
223 tool_panel->Thread::start();
225 set_operation(mwindow->edl->session->cwindow_operation);
230 int CWindowGUI::translation_event()
232 mwindow->session->cwindow_x = get_x();
233 mwindow->session->cwindow_y = get_y();
237 int CWindowGUI::resize_event(int w, int h)
239 mwindow->session->cwindow_x = get_x();
240 mwindow->session->cwindow_y = get_y();
241 mwindow->session->cwindow_w = w;
242 mwindow->session->cwindow_h = h;
244 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
245 mwindow->theme->draw_cwindow_bg(this);
248 composite_panel->reposition_buttons(mwindow->theme->ccomposite_x,
249 mwindow->theme->ccomposite_y, mwindow->theme->ccomposite_h);
251 canvas->reposition_window(mwindow->edl,
252 mwindow->theme->ccanvas_x,
253 mwindow->theme->ccanvas_y,
254 mwindow->theme->ccanvas_w,
255 mwindow->theme->ccanvas_h);
257 timebar->resize_event();
260 slider->reposition_window(mwindow->theme->cslider_x,
261 mwindow->theme->cslider_y,
262 mwindow->theme->cslider_w);
263 // Recalibrate pointer motion range
264 slider->set_position();
267 transport->reposition_buttons(mwindow->theme->ctransport_x,
268 mwindow->theme->ctransport_y);
270 edit_panel->reposition_buttons(mwindow->theme->cedit_x,
271 mwindow->theme->cedit_y);
273 // clock->reposition_window(mwindow->theme->ctime_x,
274 // mwindow->theme->ctime_y);
276 zoom_panel->reposition_window(mwindow->theme->czoom_x,
277 mwindow->theme->czoom_y);
279 // destination->reposition_window(mwindow->theme->cdest_x,
280 // mwindow->theme->cdest_y);
282 meters->reposition_window(mwindow->theme->cmeter_x,
283 mwindow->theme->cmeter_y,
285 mwindow->theme->cmeter_h);
289 BC_WindowBase::resize_event(w, h);
293 int CWindowGUI::button_press_event()
295 if( current_operation == CWINDOW_NONE &&
296 mwindow->edl != 0 && canvas->get_canvas() &&
297 mwindow->edl->session->cwindow_click2play &&
298 canvas->get_canvas()->get_cursor_over_window() ) {
299 switch( get_buttonpress() ) {
301 if( !cwindow->playback_engine->is_playing_back ) {
302 double length = mwindow->edl->tracks->total_playable_length();
303 double position = cwindow->playback_engine->get_tracking_position();
304 if( position >= length ) transport->goto_start();
306 return transport->forward_play->handle_event();
308 if( !cwindow->playback_engine->is_playing_back ) {
309 double position = cwindow->playback_engine->get_tracking_position();
310 if( position <= 0 ) transport->goto_end();
312 return transport->reverse_play->handle_event();
313 case RIGHT_BUTTON: // activates popup
316 return transport->frame_forward_play->handle_event();
318 return transport->frame_reverse_play->handle_event();
321 if(canvas->get_canvas())
322 return canvas->button_press_event_base(canvas->get_canvas());
326 int CWindowGUI::cursor_leave_event()
328 if(canvas->get_canvas())
329 return canvas->cursor_leave_event_base(canvas->get_canvas());
333 int CWindowGUI::cursor_enter_event()
335 if(canvas->get_canvas())
336 return canvas->cursor_enter_event_base(canvas->get_canvas());
340 int CWindowGUI::button_release_event()
342 if(canvas->get_canvas())
343 return canvas->button_release_event();
347 int CWindowGUI::cursor_motion_event()
349 if(canvas->get_canvas())
351 canvas->get_canvas()->unhide_cursor();
352 return canvas->cursor_motion_event();
363 void CWindowGUI::draw_status(int flush)
365 if( (canvas->get_canvas() && canvas->get_canvas()->get_video_on()) ||
366 canvas->is_processing )
369 mwindow->theme->cstatus_x,
370 mwindow->theme->cstatus_y);
374 draw_pixmap(inactive,
375 mwindow->theme->cstatus_x,
376 mwindow->theme->cstatus_y);
380 // printf("CWindowGUI::draw_status %d %d %d\n", __LINE__, mwindow->theme->cstatus_x,
381 // mwindow->theme->cstatus_y);
382 flash(mwindow->theme->cstatus_x,
383 mwindow->theme->cstatus_y,
389 float CWindowGUI::get_auto_zoom()
391 float conformed_w, conformed_h;
392 mwindow->edl->calculate_conformed_dimensions(0, conformed_w, conformed_h);
393 float zoom_x = canvas->w / conformed_w;
394 float zoom_y = canvas->h / conformed_h;
395 return zoom_x < zoom_y ? zoom_x : zoom_y;
398 void CWindowGUI::zoom_canvas(double value, int update_menu)
401 float zoom = !value ? get_auto_zoom() : value;
402 EDL *edl = mwindow->edl;
403 edl->session->cwindow_scrollbars = !value ? 0 : 1;
405 float cx = 0.5f * canvas->w; x = cx;
406 float cy = 0.5f * canvas->h; y = cy;
407 canvas->canvas_to_output(edl, 0, x, y);
408 canvas->update_zoom(0, 0, zoom);
409 float zoom_x, zoom_y, conformed_w, conformed_h;
410 canvas->get_zooms(edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
415 canvas->update_zoom((int)(x+0.5), (int)(y+0.5), zoom);
418 zoom_panel->update(value);
419 if( mwindow->edl->session->cwindow_operation == CWINDOW_ZOOM )
420 composite_panel->cpanel_zoom->update(zoom);
422 canvas->reposition_window(mwindow->edl,
423 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
424 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
428 void CWindowGUI::set_operation(int value)
431 case CWINDOW_TOOL_WINDOW:
432 mwindow->edl->session->tool_window = !mwindow->edl->session->tool_window;
433 composite_panel->operation[CWINDOW_TOOL_WINDOW]->update(mwindow->edl->session->tool_window);
434 tool_panel->update_show_window();
436 case CWINDOW_TITLESAFE:
437 mwindow->edl->session->safe_regions = !mwindow->edl->session->safe_regions;
438 composite_panel->operation[CWINDOW_TITLESAFE]->update(mwindow->edl->session->safe_regions);
439 value = mwindow->edl->session->cwindow_operation;
442 mwindow->edl->session->cwindow_operation = value;
443 composite_panel->set_operation(value);
447 edit_panel->update();
448 tool_panel->start_tool(value);
452 void CWindowGUI::update_tool()
454 tool_panel->update_values();
457 int CWindowGUI::close_event()
459 cwindow->hide_window();
464 int CWindowGUI::keypress_event()
467 int cwindow_operation = CWINDOW_NONE;
469 switch( get_keypress() ) {
486 if( canvas->get_fullscreen() )
487 canvas->stop_fullscreen();
489 canvas->start_fullscreen();
490 lock_window("CWindowGUI::keypress_event 1");
494 if( ctrl_down() || shift_down() || alt_down() ) break;
496 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
498 mwindow->gui->unlock_window();
499 lock_window("CWindowGUI::keypress_event 2");
504 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
505 mwindow->clear_entry();
506 mwindow->gui->unlock_window();
507 lock_window("CWindowGUI::keypress_event 3");
512 if( canvas->get_fullscreen() )
513 canvas->stop_fullscreen();
514 lock_window("CWindowGUI::keypress_event 4");
519 int alt_down = this->alt_down();
520 int shift_down = this->shift_down();
523 mwindow->gui->lock_window("CWindowGUI::keypress_event 5");
525 mwindow->prev_edit_handle(shift_down);
527 mwindow->move_left();
528 mwindow->gui->unlock_window();
529 lock_window("CWindowGUI::keypress_event 6");
535 if( !ctrl_down() && !alt_down() ) {
538 mwindow->gui->lock_window("CWindowGUI::keypress_event 7");
539 mwindow->move_left();
540 mwindow->gui->unlock_window();
541 lock_window("CWindowGUI::keypress_event 8");
548 int alt_down = this->alt_down();
549 int shift_down = this->shift_down();
552 mwindow->gui->lock_window("CWindowGUI::keypress_event 8");
554 mwindow->next_edit_handle(shift_down);
556 mwindow->move_right();
557 mwindow->gui->unlock_window();
558 lock_window("CWindowGUI::keypress_event 9");
564 if( !ctrl_down() && !alt_down() ) {
567 mwindow->gui->lock_window("CWindowGUI::keypress_event 10");
568 mwindow->move_right();
569 mwindow->gui->unlock_window();
570 lock_window("CWindowGUI::keypress_event 11");
576 if( !result && cwindow_operation < 0 && ctrl_down() && shift_down() ) {
577 switch( get_keypress() ) {
578 case KEY_F1 ... KEY_F4: // mainmenu, load layout
579 resend_event(mwindow->gui);
584 if( !result && !ctrl_down() ) {
585 switch( get_keypress() ) {
588 mwindow->toggle_camera_xyz(); result = 1;
591 cwindow_operation = CWINDOW_PROTECT;
595 mwindow->toggle_projector_xyz(); result = 1;
598 cwindow_operation = CWINDOW_ZOOM;
602 if( !result && cwindow_operation < 0 && !ctrl_down() && !shift_down() ) {
603 switch( get_keypress() ) {
604 case KEY_F3: cwindow_operation = CWINDOW_MASK; break;
605 case KEY_F4: cwindow_operation = CWINDOW_RULER; break;
606 case KEY_F5: cwindow_operation = CWINDOW_CAMERA; break;
607 case KEY_F6: cwindow_operation = CWINDOW_PROJECTOR; break;
608 case KEY_F7: cwindow_operation = CWINDOW_CROP; break;
609 case KEY_F8: cwindow_operation = CWINDOW_EYEDROP; break;
610 case KEY_F9: cwindow_operation = CWINDOW_TOOL_WINDOW; break;
611 case KEY_F10: cwindow_operation = CWINDOW_TITLESAFE; break;
614 if( !result && cwindow_operation < 0 && !ctrl_down() ) {
615 switch( get_keypress() ) {
618 canvas->reset_camera();
620 canvas->camera_keyframe();
625 canvas->reset_projector();
627 canvas->projector_keyframe();
633 if( cwindow_operation >= 0 ) {
634 set_operation(cwindow_operation);
639 result = transport->keypress_event();
645 void CWindowGUI::reset_affected()
652 void CWindowGUI::keyboard_zoomin()
654 // if(mwindow->edl->session->cwindow_scrollbars)
656 zoom_panel->zoom_tumbler->handle_up_event();
663 void CWindowGUI::keyboard_zoomout()
665 // if(mwindow->edl->session->cwindow_scrollbars)
667 zoom_panel->zoom_tumbler->handle_down_event();
674 void CWindowGUI::sync_parameters(int change_type, int redraw, int overlay)
680 if( change_type < 0 && !overlay ) return;
682 if( change_type >= 0 ) {
683 mwindow->restart_brender();
684 mwindow->sync_parameters(change_type);
687 mwindow->gui->lock_window("CWindowGUI::sync_parameters");
688 mwindow->gui->draw_overlays(1);
689 mwindow->gui->unlock_window();
691 lock_window("CWindowGUI::sync_parameters");
694 void CWindowGUI::drag_motion()
696 if(get_hidden()) return;
698 if(mwindow->session->current_operation != DRAG_ASSET &&
699 mwindow->session->current_operation != DRAG_VTRANSITION &&
700 mwindow->session->current_operation != DRAG_VEFFECT) return;
701 int need_highlight = cursor_above() && get_cursor_over_window();
702 if( highlighted == need_highlight ) return;
703 highlighted = need_highlight;
707 int CWindowGUI::drag_stop()
710 if(get_hidden()) return 0;
711 if( !highlighted ) return 0;
712 if( mwindow->session->current_operation != DRAG_ASSET &&
713 mwindow->session->current_operation != DRAG_VTRANSITION &&
714 mwindow->session->current_operation != DRAG_VEFFECT) return 0;
719 if(mwindow->session->current_operation == DRAG_ASSET)
721 if(mwindow->session->drag_assets->total ||
722 mwindow->session->drag_clips->total)
724 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
725 mwindow->undo->update_undo_before(_("insert assets"), 0);
728 if(mwindow->session->drag_assets->total)
731 mwindow->load_assets(mwindow->session->drag_assets,
732 mwindow->edl->local_session->get_selectionstart(),
734 mwindow->session->track_highlighted,
736 mwindow->edl->session->labels_follow_edits,
737 mwindow->edl->session->plugins_follow_edits,
738 mwindow->edl->session->autos_follow_edits,
742 if(mwindow->session->drag_clips->total)
745 mwindow->paste_edls(mwindow->session->drag_clips,
747 mwindow->session->track_highlighted,
748 mwindow->edl->local_session->get_selectionstart(),
749 mwindow->edl->session->labels_follow_edits,
750 mwindow->edl->session->plugins_follow_edits,
751 mwindow->edl->session->autos_follow_edits,
755 if(mwindow->session->drag_assets->total ||
756 mwindow->session->drag_clips->total)
758 mwindow->save_backup();
759 mwindow->restart_brender();
760 mwindow->gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
761 mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
762 mwindow->gui->unlock_window();
763 sync_parameters(CHANGE_ALL);
767 if(mwindow->session->current_operation == DRAG_VEFFECT)
769 //printf("CWindowGUI::drag_stop 1\n");
770 Track *affected_track = cwindow->calculate_affected_track();
771 //printf("CWindowGUI::drag_stop 2\n");
773 mwindow->gui->lock_window("CWindowGUI::drag_stop 3");
774 mwindow->insert_effects_cwindow(affected_track);
775 mwindow->session->current_operation = NO_OPERATION;
776 mwindow->gui->unlock_window();
779 if(mwindow->session->current_operation == DRAG_VTRANSITION)
781 Track *affected_track = cwindow->calculate_affected_track();
782 mwindow->gui->lock_window("CWindowGUI::drag_stop 4");
783 mwindow->paste_transition_cwindow(affected_track);
784 mwindow->session->current_operation = NO_OPERATION;
785 mwindow->gui->unlock_window();
791 void CWindowGUI::update_meters()
793 if(mwindow->edl->session->cwindow_meter != meters->visible)
795 meters->set_meters(meters->meter_count, mwindow->edl->session->cwindow_meter);
796 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
797 resize_event(get_w(), get_h());
801 void CWindowGUI::stop_transport(const char *lock_msg)
803 if( lock_msg ) unlock_window();
804 mwindow->stop_transport();
805 if( lock_msg ) lock_window(lock_msg);
809 CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
810 : EditPanel(mwindow, cwindow->gui, CWINDOW_ID,
811 mwindow->theme->cedit_x, mwindow->theme->cedit_y,
812 mwindow->edl->session->editing_mode,
813 0, // use_editing_mode
830 this->mwindow = mwindow;
831 this->cwindow = cwindow;
834 #define relock_cm(s) \
835 cwindow->gui->unlock_window(); \
836 mwindow->gui->lock_window("CWindowEditing::" s)
837 #define relock_mc(s) \
838 mwindow->gui->unlock_window(); \
839 cwindow->gui->lock_window("CWindowEditing::" s)
840 #define panel_fn(fn, args, s) \
841 CWindowEditing::fn args { relock_cm(#fn); s; relock_mc(#fn); }
843 // transmit lock to mwindow, and run mbutton->edit_panel->s
844 #define panel_btn(fn, args, s) \
845 panel_fn(panel_##fn, args, mwindow->gui->mbuttons->edit_panel->panel_##s)
848 double CWindowEditing::get_position()
850 relock_cm("get_position");
851 double ret = mwindow->edl->local_session->get_selectionstart(1);
852 relock_mc("get_position");
856 void CWindowEditing::set_position(double position)
858 relock_cm("set_position");
859 mwindow->gui->mbuttons->edit_panel->set_position(position);
860 relock_mc("set_position");
863 void CWindowEditing::set_click_to_play(int v)
865 relock_cm("set_position");
866 mwindow->edl->session->cwindow_click2play = v;
867 relock_mc("set_position");
868 click2play->update(v);
872 void panel_btn(stop_transport,(), stop_transport())
873 void panel_btn(toggle_label,(), toggle_label())
874 void panel_btn(next_label,(int cut), next_label(cut))
875 void panel_btn(prev_label,(int cut), prev_label(cut))
876 void panel_btn(next_edit,(int cut), next_edit(cut))
877 void panel_btn(prev_edit,(int cut), prev_edit(cut))
878 void panel_fn(panel_copy_selection,(), mwindow->copy())
879 void CWindowEditing::panel_overwrite_selection() {} // not used
880 void CWindowEditing::panel_splice_selection() {} // not used
881 void panel_btn(set_inpoint,(), set_inpoint())
882 void panel_btn(set_outpoint,(), set_outpoint())
883 void panel_btn(unset_inoutpoint,(), unset_inoutpoint())
884 void panel_fn(panel_to_clip,(), mwindow->to_clip(mwindow->edl, _("main window: "), 0))
885 void panel_btn(cut,(), cut())
886 void panel_btn(paste,(), paste())
887 void panel_btn(fit_selection,(), fit_selection())
888 void panel_btn(fit_autos,(int all), fit_autos(all))
889 void panel_btn(set_editing_mode,(int mode), set_editing_mode(mode))
890 void panel_btn(set_auto_keyframes,(int v), set_auto_keyframes(v))
891 void panel_btn(set_labels_follow_edits,(int v), set_labels_follow_edits(v))
894 CWindowMeters::CWindowMeters(MWindow *mwindow,
895 CWindowGUI *gui, int x, int y, int h)
896 : MeterPanel(mwindow, gui, x, y, -1, h,
897 mwindow->edl->session->audio_channels,
898 mwindow->edl->session->cwindow_meter,
901 this->mwindow = mwindow;
905 CWindowMeters::~CWindowMeters()
909 int CWindowMeters::change_status_event(int new_status)
911 mwindow->edl->session->cwindow_meter = new_status;
912 gui->update_meters();
919 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
920 : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
921 x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
923 this->mwindow = mwindow;
927 CWindowZoom::~CWindowZoom()
931 void CWindowZoom::update(double value)
933 char string[BCSTRLEN];
934 const char *cp = string;
937 int frac = value >= 1.0f ? 1 :
939 value >= .01f ? 3 : 4;
940 sprintf(string, "x %.*f", frac, value);
944 ZoomPanel::update(cp);
947 int CWindowZoom::handle_event()
949 double value = !strcasecmp(gui->auto_zoom, get_text()) ? 0 : get_value();
950 gui->zoom_canvas(value, 0);
957 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
958 : BC_PercentageSlider(x,
967 this->mwindow = mwindow;
968 this->cwindow = cwindow;
969 set_precision(0.00001);
972 CWindowSlider::~CWindowSlider()
976 int CWindowSlider::handle_event()
978 cwindow->update_position((double)get_value());
982 void CWindowSlider::set_position()
984 double new_length = mwindow->edl->tracks->total_length();
985 update(mwindow->theme->cslider_w,
986 mwindow->edl->local_session->get_selectionstart(1),
991 int CWindowSlider::increase_value()
994 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
995 lock_window("CWindowSlider::increase_value");
999 int CWindowSlider::decrease_value()
1002 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
1003 lock_window("CWindowSlider::decrease_value");
1008 // CWindowDestination::CWindowDestination(MWindow *mwindow, CWindowGUI *cwindow, int x, int y)
1009 // : BC_PopupTextBox(cwindow,
1010 // &cwindow->destinations,
1011 // cwindow->destinations.values[cwindow->cwindow->destination]->get_text(),
1017 // this->mwindow = mwindow;
1018 // this->cwindow = cwindow;
1021 // CWindowDestination::~CWindowDestination()
1025 // int CWindowDestination::handle_event()
1029 #endif // USE_SLIDER
1036 CWindowTransport::CWindowTransport(MWindow *mwindow,
1040 : PlayTransport(mwindow,
1048 EDL* CWindowTransport::get_edl()
1050 return mwindow->edl;
1053 void CWindowTransport::goto_start()
1055 gui->unlock_window();
1056 handle_transport(REWIND, 1);
1058 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
1059 mwindow->goto_start();
1060 mwindow->gui->unlock_window();
1062 gui->lock_window("CWindowTransport::goto_start 2");
1065 void CWindowTransport::goto_end()
1067 gui->unlock_window();
1068 handle_transport(GOTO_END, 1);
1070 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
1071 mwindow->goto_end();
1072 mwindow->gui->unlock_window();
1074 gui->lock_window("CWindowTransport::goto_end 2");
1079 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
1082 mwindow->theme->ccanvas_x,
1083 mwindow->theme->ccanvas_y,
1084 mwindow->theme->ccanvas_w,
1085 mwindow->theme->ccanvas_h,
1088 mwindow->edl->session->cwindow_scrollbars)
1090 this->mwindow = mwindow;
1094 void CWindowCanvas::status_event()
1096 gui->draw_status(1);
1099 void CWindowCanvas::update_zoom(int x, int y, float zoom)
1101 use_scrollbars = mwindow->edl->session->cwindow_scrollbars;
1103 mwindow->edl->session->cwindow_xscroll = x;
1104 mwindow->edl->session->cwindow_yscroll = y;
1105 mwindow->edl->session->cwindow_zoom = zoom;
1108 void CWindowCanvas::zoom_auto()
1110 gui->zoom_canvas(0, 1);
1113 int CWindowCanvas::get_xscroll()
1115 return mwindow->edl->session->cwindow_xscroll;
1118 int CWindowCanvas::get_yscroll()
1120 return mwindow->edl->session->cwindow_yscroll;
1124 float CWindowCanvas::get_zoom()
1126 return mwindow->edl->session->cwindow_zoom;
1129 void CWindowCanvas::draw_refresh(int flush)
1131 BC_WindowBase *window = get_canvas();
1132 if( window && !window->get_video_on() ) {
1134 if( refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0 ) {
1135 float in_x1, in_y1, in_x2, in_y2;
1136 float out_x1, out_y1, out_x2, out_y2;
1137 get_transfers(mwindow->edl,
1138 in_x1, in_y1, in_x2, in_y2,
1139 out_x1, out_y1, out_x2, out_y2);
1142 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1143 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1146 if( out_x2 > out_x1 && out_y2 > out_y1 &&
1147 in_x2 > in_x1 && in_y2 > in_y1 ) {
1148 // input scaled from session to refresh frame coordinates
1149 int ow = get_output_w(mwindow->edl);
1150 int oh = get_output_h(mwindow->edl);
1151 int rw = refresh_frame->get_w();
1152 int rh = refresh_frame->get_h();
1153 float xs = (float)rw / ow;
1154 float ys = (float)rh / oh;
1155 in_x1 *= xs; in_x2 *= xs;
1156 in_y1 *= ys; in_y2 *= ys;
1157 // Can't use OpenGL here because it is called asynchronously of the
1158 // playback operation.
1159 window->draw_vframe(refresh_frame,
1160 (int)out_x1, (int)out_y1,
1161 (int)(out_x2 - out_x1),
1162 (int)(out_y2 - out_y1),
1163 (int)in_x1, (int)in_y1,
1164 (int)(in_x2 - in_x1),
1165 (int)(in_y2 - in_y1),
1171 window->flash(flush);
1173 //printf("CWindowCanvas::draw_refresh 10\n");
1176 #define CROPHANDLE_W 10
1177 #define CROPHANDLE_H 10
1179 void CWindowCanvas::draw_crophandle(int x, int y)
1181 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1185 #define CONTROL_W 10
1186 #define CONTROL_H 10
1187 #define FIRST_CONTROL_W 20
1188 #define FIRST_CONTROL_H 20
1190 #define BC_INFINITY 65536
1192 #define RULERHANDLE_W 16
1193 #define RULERHANDLE_H 16
1195 int CWindowCanvas::do_ruler(int draw,
1201 float x1 = mwindow->edl->session->ruler_x1;
1202 float y1 = mwindow->edl->session->ruler_y1;
1203 float x2 = mwindow->edl->session->ruler_x2;
1204 float y2 = mwindow->edl->session->ruler_y2;
1205 float canvas_x1 = x1;
1206 float canvas_y1 = y1;
1207 float canvas_x2 = x2;
1208 float canvas_y2 = y2;
1209 float output_x = get_cursor_x();
1210 float output_y = get_cursor_y();
1211 float canvas_cursor_x = output_x;
1212 float canvas_cursor_y = output_y;
1214 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1215 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1216 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1217 mwindow->session->cwindow_output_x = roundf(output_x);
1218 mwindow->session->cwindow_output_y = roundf(output_y);
1220 if(button_press && get_buttonpress() == 1)
1222 gui->ruler_handle = -1;
1223 gui->ruler_translate = 0;
1226 gui->ruler_translate = 1;
1227 gui->ruler_origin_x = x1;
1228 gui->ruler_origin_y = y1;
1231 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1232 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1233 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1234 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1236 gui->ruler_handle = 0;
1237 gui->ruler_origin_x = x1;
1238 gui->ruler_origin_y = y1;
1241 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1242 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1243 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1244 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1246 gui->ruler_handle = 1;
1247 gui->ruler_origin_x = x2;
1248 gui->ruler_origin_y = y2;
1252 // Start new selection
1253 if(!gui->ruler_translate &&
1254 (gui->ruler_handle < 0 ||
1259 do_ruler(1, 0, 0, 0);
1260 get_canvas()->flash();
1261 gui->ruler_handle = 1;
1262 mwindow->edl->session->ruler_x1 = output_x;
1263 mwindow->edl->session->ruler_y1 = output_y;
1264 mwindow->edl->session->ruler_x2 = output_x;
1265 mwindow->edl->session->ruler_y2 = output_y;
1266 gui->ruler_origin_x = mwindow->edl->session->ruler_x2;
1267 gui->ruler_origin_y = mwindow->edl->session->ruler_y2;
1270 gui->x_origin = output_x;
1271 gui->y_origin = output_y;
1272 gui->current_operation = CWINDOW_RULER;
1273 gui->tool_panel->raise_window();
1279 if(gui->current_operation == CWINDOW_RULER)
1281 if(gui->ruler_translate)
1284 do_ruler(1, 0, 0, 0);
1285 float x_difference = mwindow->edl->session->ruler_x1;
1286 float y_difference = mwindow->edl->session->ruler_y1;
1287 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1288 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1289 x_difference -= mwindow->edl->session->ruler_x1;
1290 y_difference -= mwindow->edl->session->ruler_y1;
1291 mwindow->edl->session->ruler_x2 -= x_difference;
1292 mwindow->edl->session->ruler_y2 -= y_difference;
1294 do_ruler(1, 0, 0, 0);
1295 get_canvas()->flash();
1299 switch(gui->ruler_handle)
1302 do_ruler(1, 0, 0, 0);
1303 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1304 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1305 if(gui->alt_down() || gui->ctrl_down())
1307 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1308 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1312 double distance_value =
1313 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1314 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1315 if(angle_value < 22)
1316 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2;
1318 if(angle_value > 67)
1319 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2;
1321 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 &&
1322 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1324 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1325 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1328 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 && 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 &&
1335 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1337 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1338 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1342 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1343 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1346 do_ruler(1, 0, 0, 0);
1347 get_canvas()->flash();
1352 do_ruler(1, 0, 0, 0);
1353 mwindow->edl->session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1354 mwindow->edl->session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1355 if(gui->alt_down() || gui->ctrl_down())
1357 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1358 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1362 double distance_value =
1363 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1364 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1365 if(angle_value < 22)
1366 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1;
1368 if(angle_value > 67)
1369 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1;
1371 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1372 mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1374 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1375 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1378 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1379 mwindow->edl->session->ruler_y2 > mwindow->edl->session->ruler_y1)
1381 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1382 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1385 if(mwindow->edl->session->ruler_x2 > mwindow->edl->session->ruler_x1 && 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;
1392 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1393 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1396 do_ruler(1, 0, 0, 0);
1397 get_canvas()->flash();
1401 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1405 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1410 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1411 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1412 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1413 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1415 set_cursor(UPRIGHT_ARROW_CURSOR);
1418 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1419 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1420 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1421 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1423 set_cursor(UPRIGHT_ARROW_CURSOR);
1426 set_cursor(CROSS_CURSOR);
1428 // Update current position
1433 // Assume no ruler measurement if 0 length
1434 if(draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)))
1436 get_canvas()->set_inverse();
1437 get_canvas()->set_color(WHITE);
1438 get_canvas()->draw_line((int)canvas_x1,
1442 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1444 roundf(canvas_x1) + RULERHANDLE_W / 2,
1446 get_canvas()->draw_line(roundf(canvas_x1),
1447 roundf(canvas_y1) - RULERHANDLE_H / 2,
1449 roundf(canvas_y1) + RULERHANDLE_H / 2);
1450 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1452 roundf(canvas_x2) + RULERHANDLE_W / 2,
1454 get_canvas()->draw_line(roundf(canvas_x2),
1455 roundf(canvas_y2) - RULERHANDLE_H / 2,
1457 roundf(canvas_y2) + RULERHANDLE_H / 2);
1458 get_canvas()->set_opaque();
1465 static inline double line_dist(float cx,float cy, float tx,float ty)
1467 double dx = tx-cx, dy = ty-cy;
1468 return sqrt(dx*dx + dy*dy);
1471 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1473 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1474 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1478 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1479 int button_press, int cursor_motion, int draw)
1481 // Retrieve points from top recordable track
1482 //printf("CWindowCanvas::do_mask 1\n");
1483 Track *track = gui->cwindow->calculate_affected_track();
1484 //printf("CWindowCanvas::do_mask 2\n");
1486 if(!track) return 0;
1487 //printf("CWindowCanvas::do_mask 3\n");
1488 CWindowMaskGUI *mask_gui = (CWindowMaskGUI *)
1489 (gui->tool_panel ? gui->tool_panel->tool_gui : 0);
1490 int draw_markers = mask_gui ? mask_gui->markers : 0;
1491 int draw_boundary = mask_gui ? mask_gui->boundary : 0;
1492 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1493 int64_t position = track->to_units(
1494 mwindow->edl->local_session->get_selectionstart(1),
1496 Auto *prev_auto = 0;
1497 mask_autos->get_prev_auto(position, PLAY_FORWARD, (Auto *&)prev_auto, 1);
1498 MaskAuto *prev_mask = (MaskAuto *)prev_auto;
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);
1510 int64_t start_pos = track->to_units(selection_start, 0);
1511 int64_t end_pos = track->to_units(selection_end, 0);
1512 Auto *first = 0, *last = 0;
1513 mask_autos->get_prev_auto(start_pos, PLAY_FORWARD, first, 1);
1514 mask_autos->get_prev_auto(end_pos, PLAY_FORWARD, last, 1);
1515 if( last == first && (!mwindow->edl->session->auto_keyframes) )
1516 use_interpolated = 0;
1518 // If keyframe spanning occurs, use the interpolated points.
1519 // If new keyframe is generated, use the interpolated points.
1520 use_interpolated = 1;
1523 if( mwindow->edl->session->auto_keyframes )
1524 use_interpolated = 1;
1528 use_interpolated = 1;
1530 if( use_interpolated ) {
1531 // Interpolate the points to get exactly what is being rendered at this position.
1532 mask_autos->get_points(&points,
1533 mwindow->edl->session->cwindow_mask,
1534 position, PLAY_FORWARD);
1537 // Use the prev mask
1538 prev_mask->get_points(&points,
1539 mwindow->edl->session->cwindow_mask);
1542 // Projector zooms relative to the center of the track output.
1543 float half_track_w = (float)track->track_w / 2;
1544 float half_track_h = (float)track->track_h / 2;
1545 // Translate mask to projection
1546 float projector_x, projector_y, projector_z;
1547 track->automation->get_projector(
1548 &projector_x, &projector_y, &projector_z,
1549 position, PLAY_FORWARD);
1552 // Get position of cursor relative to mask
1553 float cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
1554 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1555 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1557 projector_x += mwindow->edl->session->output_w / 2;
1558 projector_y += mwindow->edl->session->output_h / 2;
1559 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1560 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1562 // Fix cursor origin
1564 gui->x_origin = mask_cursor_x;
1565 gui->y_origin = mask_cursor_y;
1569 // Points of closest line
1570 int shortest_point1 = -1;
1571 int shortest_point2 = -1;
1573 int shortest_point = -1;
1574 // Distance to closest line
1575 float shortest_line_distance = BC_INFINITY;
1576 // Distance to closest point
1577 float shortest_point_distance = BC_INFINITY;
1578 int selected_point = -1;
1579 int selected_control_point = -1;
1580 float selected_control_point_distance = BC_INFINITY;
1581 ArrayList<int> x_points;
1582 ArrayList<int> y_points;
1584 if(!cursor_motion) {
1586 get_canvas()->set_color(WHITE);
1587 get_canvas()->set_inverse();
1589 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1591 // Never draw closed polygon and a closed
1592 // polygon is harder to add points to.
1593 for(int i = 0; i < points.size() && !result; i++) {
1594 MaskPoint *point1 = points.get(i);
1595 MaskPoint *point2 = (i >= points.size() - 1) ?
1596 points.get(0) : points.get(i + 1);
1598 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1599 if(point_distance1 < shortest_point_distance || shortest_point < 0) {
1600 shortest_point_distance = point_distance1;
1604 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1605 if(point_distance2 < shortest_point_distance || shortest_point < 0) {
1606 shortest_point_distance = point_distance2;
1607 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1611 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1613 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1614 //point1->x, point1->y, point2->x, point2->y, projector_z);
1615 for(int j = 0; j <= segments && !result; j++) {
1616 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1617 float x0 = point1->x, y0 = point1->y;
1618 float x1 = point1->x + point1->control_x2;
1619 float y1 = point1->y + point1->control_y2;
1620 float x2 = point2->x + point2->control_x1;
1621 float y2 = point2->y + point2->control_y1;
1622 float x3 = point2->x, y3 = point2->y;
1623 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1624 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1625 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1626 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1627 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1628 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1629 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1630 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1632 float t = (float)j / segments;
1633 float tpow2 = t * t;
1634 float tpow3 = t * t * t;
1636 float invtpow2 = invt * invt;
1637 float invtpow3 = invt * invt * invt;
1639 float x = ( invtpow3 * x0
1640 + 3 * t * invtpow2 * x1
1641 + 3 * tpow2 * invt * x2
1643 float y = ( invtpow3 * y0
1644 + 3 * t * invtpow2 * y1
1645 + 3 * tpow2 * invt * y2
1647 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1648 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1649 // Test new point addition
1651 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1653 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1654 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1655 if(line_distance < shortest_line_distance ||
1656 shortest_point1 < 0) {
1657 shortest_line_distance = line_distance;
1658 shortest_point1 = i;
1659 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1660 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1661 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1664 // Test existing point selection
1666 if(gui->ctrl_down()) {
1667 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1669 if(distance < selected_control_point_distance) {
1671 selected_control_point = 1;
1672 selected_control_point_distance = distance;
1676 if(!gui->shift_down()) {
1677 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1678 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
1683 selected_point = shortest_point;
1686 // Test second point
1687 if(gui->ctrl_down()) {
1688 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1690 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1691 if(distance < selected_control_point_distance) {
1692 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1693 selected_control_point = 0;
1694 selected_control_point_distance = distance;
1697 else if(i < points.size() - 1) {
1698 if(!gui->shift_down()) {
1699 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1700 if(test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3)) {
1701 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1705 selected_point = shortest_point;
1710 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1714 if( draw ) { // Draw joining line
1715 x_points.append((int)canvas_x);
1716 y_points.append((int)canvas_y);
1719 if( j == segments ) {
1720 if( draw && draw_markers ) { // Draw second anchor
1721 if(i < points.size() - 1) {
1722 if(i == gui->affected_point - 1)
1723 get_canvas()->draw_disc(
1724 (int)canvas_x - CONTROL_W / 2,
1725 (int)canvas_y - CONTROL_W / 2,
1726 CONTROL_W, CONTROL_H);
1728 get_canvas()->draw_circle(
1729 (int)canvas_x - CONTROL_W / 2,
1730 (int)canvas_y - CONTROL_W / 2,
1731 CONTROL_W, CONTROL_H);
1732 // char string[BCTEXTLEN];
1733 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1734 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1736 // Draw second control point.
1737 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1738 get_canvas()->draw_line(
1739 (int)canvas_x, (int)canvas_y,
1740 (int)canvas_x2, (int)canvas_y2);
1741 get_canvas()->draw_rectangle(
1742 (int)canvas_x2 - CONTROL_W / 2,
1743 (int)canvas_y2 - CONTROL_H / 2,
1744 CONTROL_W, CONTROL_H);
1749 // Draw first anchor
1750 if( i == 0 && draw ) {
1751 if( draw_boundary ) {
1752 char mask_label[BCSTRLEN];
1753 int k = mwindow->edl->session->cwindow_mask;
1754 if( !prev_mask || k < 0 || k >= prev_mask->masks.size() )
1755 sprintf(mask_label, "%d", k);
1757 sprintf(mask_label, "%s", prev_mask->masks[k]->name);
1758 get_canvas()->draw_text(
1759 (int)canvas_x - FIRST_CONTROL_W,
1760 (int)canvas_y - FIRST_CONTROL_H,
1763 if( draw_markers ) {
1764 get_canvas()->draw_disc(
1765 (int)canvas_x - FIRST_CONTROL_W / 2,
1766 (int)canvas_y - FIRST_CONTROL_H / 2,
1767 FIRST_CONTROL_W, FIRST_CONTROL_H);
1771 // Draw first control point.
1772 if( draw && draw_markers ) {
1773 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1774 get_canvas()->draw_line(
1775 (int)canvas_x, (int)canvas_y,
1776 (int)canvas_x1, (int)canvas_y1);
1777 get_canvas()->draw_rectangle(
1778 (int)canvas_x1 - CONTROL_W / 2,
1779 (int)canvas_y1 - CONTROL_H / 2,
1780 CONTROL_W, CONTROL_H);
1782 x_points.append((int)canvas_x);
1783 y_points.append((int)canvas_y);
1786 //printf("CWindowCanvas::do_mask 1\n");
1790 //printf("CWindowCanvas::do_mask 1\n");
1792 BC_WindowBase *cvs_win = get_canvas();
1793 if( draw && draw_boundary ) {
1794 cvs_win->draw_polygon(&x_points, &y_points);
1795 cvs_win->set_opaque();
1797 if( draw && mask_gui && mask_gui->focused ) {
1798 float fx = atof(mask_gui->focus_x->get_text());
1799 float fy = atof(mask_gui->focus_y->get_text());
1800 output_to_canvas(mwindow->edl, 0, fx, fy);
1801 float r = bmax(cvs_win->get_w(), cvs_win->get_h());
1804 int fw = 2*d+3, fh = fw;
1805 VFrame focus(fw,fh, BC_RGBA8888);
1806 focus.transfer_from(gui->focus_frame);
1807 fx -= fw/2.f; fy -= fh/2.f;
1808 BC_Pixmap focus_pixmap(cvs_win, &focus, PIXMAP_ALPHA);
1809 cvs_win->draw_pixmap(&focus_pixmap,fx,fy);
1811 cvs_win->set_line_width((int)(0.0025*r) + 1);
1812 cvs_win->set_color(BLUE);
1813 cvs_win->draw_line(fx-d,fy-d, fx+d, fy+d);
1814 cvs_win->draw_line(fx-d,fy+d, fx+d, fy-d);
1815 cvs_win->set_line_width(0);
1816 cvs_win->set_color(WHITE);
1819 if( draw && mask_gui && mask_gui->center_mark && points.size() ) {
1820 float cx = 0, cy = 0;
1821 int n = points.size();
1822 for( int i=0; i<n; ++i ) {
1823 MaskPoint *point = points.get(i);
1824 cx += point->x; cy += point->y;
1827 output_to_canvas(mwindow->edl, 0, cx, cy);
1828 float r = bmax(cvs_win->get_w(), cvs_win->get_h());
1830 cvs_win->set_line_width((int)(0.002*r) + 1);
1831 cvs_win->set_color(ORANGE);
1832 cvs_win->draw_line(cx-d,cy, cx+d, cy);
1833 cvs_win->draw_line(cx,cy-d, cx, cy+d);
1834 cvs_win->set_line_width(0);
1835 cvs_win->set_color(WHITE);
1837 //printf("CWindowCanvas::do_mask 1\n");
1840 if(button_press && !result) {
1841 gui->affected_track = gui->cwindow->calculate_affected_track();
1843 // Get keyframe outside the EDL to edit. This must be rendered
1844 // instead of the EDL keyframes when it exists. Then it must be
1845 // applied to the EDL keyframes on buttonrelease.
1846 if(gui->affected_track) {
1847 #ifdef USE_KEYFRAME_SPANNING
1848 // Make copy of current parameters in local keyframe
1849 gui->mask_keyframe =
1850 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1853 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1856 gui->mask_keyframe =
1857 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1862 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1864 if( get_buttonpress() == WHEEL_UP || get_buttonpress() == WHEEL_DOWN ) {
1865 if( !gui->shift_down() ) {
1866 mwindow->undo->update_undo_before(_("mask rotate"), this);
1867 gui->current_operation = CWINDOW_MASK_ROTATE;
1870 mwindow->undo->update_undo_before(_("mask scale"), this);
1871 gui->current_operation = CWINDOW_MASK_SCALE;
1873 gui->affected_point = 0;
1876 // Translate entire keyframe
1877 if(gui->alt_down() && mask->points.size()) {
1878 mwindow->undo->update_undo_before(_("mask translate"), 0);
1879 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1880 gui->affected_point = 0;
1883 // Existing point or control point was selected
1884 if(selected_point >= 0) {
1885 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1886 gui->affected_point = selected_point;
1888 if(selected_control_point == 0)
1889 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1891 if(selected_control_point == 1)
1892 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1894 gui->current_operation = mwindow->edl->session->cwindow_operation;
1896 else // No existing point or control point was selected so create a new one
1897 if(!gui->ctrl_down() && !gui->alt_down()) {
1898 mwindow->undo->update_undo_before(_("mask point"), 0);
1899 // Create the template
1900 MaskPoint *point = new MaskPoint;
1901 point->x = mask_cursor_x;
1902 point->y = mask_cursor_y;
1903 point->control_x1 = 0;
1904 point->control_y1 = 0;
1905 point->control_x2 = 0;
1906 point->control_y2 = 0;
1909 if(shortest_point2 < shortest_point1) {
1910 shortest_point2 ^= shortest_point1;
1911 shortest_point1 ^= shortest_point2;
1912 shortest_point2 ^= shortest_point1;
1917 // printf("CWindowGUI::do_mask 40\n");
1918 // mwindow->edl->dump();
1919 // printf("CWindowGUI::do_mask 50\n");
1923 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1924 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1925 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1927 // Append to end of list
1928 if( shortest_point1 == shortest_point2 ||
1929 labs(shortest_point1 - shortest_point2) > 1) {
1930 #ifdef USE_KEYFRAME_SPANNING
1932 MaskPoint *new_point = new MaskPoint;
1933 points.append(new_point);
1934 *new_point = *point;
1935 gui->affected_point = points.size() - 1;
1939 // Need to apply the new point to every keyframe
1940 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1941 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1942 MaskPoint *new_point = new MaskPoint;
1943 submask->points.append(new_point);
1944 *new_point = *point;
1945 if(current == (MaskAuto*)mask_autos->default_auto)
1946 current = (MaskAuto*)mask_autos->first;
1948 current = (MaskAuto*)NEXT;
1950 gui->affected_point = mask->points.size() - 1;
1956 // Insert between 2 points, shifting back point 2
1957 if(shortest_point1 >= 0 && shortest_point2 >= 0) {
1959 #ifdef USE_KEYFRAME_SPANNING
1960 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1962 if(points.size() >= shortest_point2) {
1963 MaskPoint *new_point = new MaskPoint;
1965 for(int i = points.size() - 1;
1966 i > shortest_point2;
1968 points.values[i] = points.values[i - 1];
1969 points.values[shortest_point2] = new_point;
1971 *new_point = *point;
1976 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1977 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1978 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1980 if(submask->points.size() >= shortest_point2) {
1981 MaskPoint *new_point = new MaskPoint;
1982 submask->points.append(0);
1983 for(int i = submask->points.size() - 1;
1984 i > shortest_point2;
1986 submask->points.values[i] = submask->points.values[i - 1];
1987 submask->points.values[shortest_point2] = new_point;
1989 *new_point = *point;
1992 if(current == (MaskAuto*)mask_autos->default_auto)
1993 current = (MaskAuto*)mask_autos->first;
1995 current = (MaskAuto*)NEXT;
1999 gui->affected_point = shortest_point2;
2004 // printf("CWindowGUI::do_mask 20\n");
2005 // mwindow->edl->dump();
2006 // printf("CWindowGUI::do_mask 30\n");
2009 //printf("CWindowCanvas::do_mask 1\n");
2010 // Create the first point.
2011 #ifdef USE_KEYFRAME_SPANNING
2012 MaskPoint *new_point = new MaskPoint;
2013 points.append(new_point);
2014 *new_point = *point;
2015 gui->affected_point = points.size() - 1;
2017 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
2018 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
2019 MaskPoint *new_point = new MaskPoint;
2020 submask->points.append(new_point);
2021 *new_point = *point;
2022 if(current == (MaskAuto*)mask_autos->default_auto)
2023 current = (MaskAuto*)mask_autos->first;
2025 current = (MaskAuto*)NEXT;
2027 gui->affected_point = points.size() - 1;
2030 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
2033 gui->current_operation = mwindow->edl->session->cwindow_operation;
2034 // Delete the template
2043 if(button_press && result) {
2044 #ifdef USE_KEYFRAME_SPANNING
2045 ArrayList<MaskPoint*> &mask_points = points;
2047 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
2048 ArrayList<MaskPoint*> &mask_points = mask->points;
2050 int k = gui->affected_point;
2051 if( k >= 0 && k < mask_points.size() ) {
2052 MaskPoint *point = mask_points.values[k];
2053 gui->center_x = point->x;
2054 gui->center_y = point->y;
2055 gui->control_in_x = point->control_x1;
2056 gui->control_in_y = point->control_y1;
2057 gui->control_out_x = point->control_x2;
2058 gui->control_out_y = point->control_y2;
2061 gui->center_x = gui->center_y = 0;
2062 gui->control_in_x = gui->control_in_y = 0;
2063 gui->control_out_x = gui->control_out_y = 0;
2065 gui->tool_panel->raise_window();
2068 //printf("CWindowCanvas::do_mask 8\n");
2069 if( cursor_motion ) {
2071 #ifdef USE_KEYFRAME_SPANNING
2072 // Must update the reference keyframes for every cursor motion
2073 gui->mask_keyframe = (MaskAuto*)gui->cwindow->
2074 calculate_affected_auto(mask_autos, 0);
2075 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
2078 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2080 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
2081 if( gui->affected_point >= 0 && gui->affected_point < mask->points.size() &&
2082 gui->current_operation != CWINDOW_NONE) {
2083 // mwindow->undo->update_undo_before(_("mask point"), this);
2084 #ifdef USE_KEYFRAME_SPANNING
2085 ArrayList<MaskPoint*> &mask_points = points;
2087 ArrayList<MaskPoint*> &mask_points = mask->points;
2089 MaskPoint *point = mask_points.get(gui->affected_point);
2090 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2091 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask_points.size(), gui->affected_point);
2093 float last_x = point->x;
2094 float last_y = point->y;
2095 float last_control_x1 = point->control_x1;
2096 float last_control_y1 = point->control_y1;
2097 float last_control_x2 = point->control_x2;
2098 float last_control_y2 = point->control_y2;
2101 switch(gui->current_operation) {
2103 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
2104 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
2105 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
2108 case CWINDOW_MASK_CONTROL_IN:
2109 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
2110 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
2113 case CWINDOW_MASK_CONTROL_OUT:
2114 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
2115 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
2118 case CWINDOW_MASK_TRANSLATE:
2119 for(int i = 0; i < mask_points.size(); i++) {
2120 mask_points.values[i]->x += mask_cursor_x - gui->x_origin;
2121 mask_points.values[i]->y += mask_cursor_y - gui->y_origin;
2123 gui->x_origin = mask_cursor_x;
2124 gui->y_origin = mask_cursor_y;
2126 case CWINDOW_MASK_ROTATE:
2128 case CWINDOW_MASK_SCALE: {
2129 int button_no = get_buttonpress();
2130 double scale = button_no == WHEEL_UP ? 1.02 : 0.98;
2131 double theta = button_no == WHEEL_UP ? M_PI/360. : -M_PI/360.;
2132 float st = sin(theta), ct = cos(theta);
2133 gui->x_origin = mask_cursor_x;
2134 gui->y_origin = mask_cursor_y;
2135 if( mask_gui && mask_gui->focused ) {
2136 gui->x_origin = atof(mask_gui->focus_x->get_text());
2137 gui->y_origin = atof(mask_gui->focus_y->get_text());
2139 for( int i=0; i<mask_points.size(); ++i ) {
2140 MaskPoint *point = mask_points.values[i];
2141 float px = point->x - gui->x_origin;
2142 float py = point->y - gui->y_origin;
2143 float nx = !rotate ? px*scale : px*ct + py*st;
2144 float ny = !rotate ? py*scale : py*ct - px*st;
2145 point->x = nx + gui->x_origin;
2146 point->y = ny + gui->y_origin;
2147 px = point->control_x1; py = point->control_y1;
2148 point->control_x1 = !rotate ? px*scale : px*ct + py*st;
2149 point->control_y1 = !rotate ? py*scale : py*ct - px*st;
2150 px = point->control_x2; py = point->control_y2;
2151 point->control_x2 = !rotate ? px*scale : px*ct + py*st;
2152 point->control_y2 = !rotate ? py*scale : py*ct - px*st;
2159 if( !EQUIV(last_x, point->x) ||
2160 !EQUIV(last_y, point->y) ||
2161 !EQUIV(last_control_x1, point->control_x1) ||
2162 !EQUIV(last_control_y1, point->control_y1) ||
2163 !EQUIV(last_control_x2, point->control_x2) ||
2164 !EQUIV(last_control_y2, point->control_y2)) {
2170 if(gui->current_operation == CWINDOW_NONE) {
2171 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
2173 for(int i = 0; i < points.size() && !over_point; i++) {
2174 MaskPoint *point = points.get(i);
2175 float x0 = point->x;
2176 float y0 = point->y;
2177 float x1 = point->x + point->control_x1;
2178 float y1 = point->y + point->control_y1;
2179 float x2 = point->x + point->control_x2;
2180 float y2 = point->y + point->control_y2;
2181 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
2182 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
2184 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
2185 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
2189 if(!over_point && gui->ctrl_down()) {
2190 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
2191 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
2192 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2193 if(test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1)) {
2197 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2198 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2199 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2200 if(test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2)) {
2207 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2212 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2215 #ifdef USE_KEYFRAME_SPANNING
2216 // Must commit change after operation.
2217 if(rerender && track) {
2218 // Swap EDL keyframe with original.
2219 // Apply new values to keyframe span
2220 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2221 temp_keyframe.copy_data(gui->mask_keyframe);
2222 // Apply interpolated points back to keyframe
2223 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2224 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2225 mask_autos->update_parameter(&temp_keyframe);
2229 points.remove_all_objects();
2230 //printf("CWindowCanvas::do_mask 20\n");
2234 int CWindowCanvas::do_mask_focus()
2236 CWindowMaskGUI *mask_gui = (CWindowMaskGUI*) gui->tool_panel->tool_gui;
2237 float cx = get_cursor_x(), cy = get_cursor_y();
2238 canvas_to_output(mwindow->edl, 0, cx, cy);
2239 int v = mask_gui->focused ? 0 : 1;
2240 get_canvas()->unlock_window();
2241 mask_gui->lock_window("CWindowCanvas::do_mask_focus");
2242 mask_gui->set_focused(v, cx, cy);
2243 mask_gui->unlock_window();
2244 get_canvas()->lock_window("CWindowCanvas::do_mask_focus");
2248 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2251 int radius = mwindow->edl->session->eyedrop_radius;
2259 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2264 row1 = gui->eyedrop_y - radius;
2265 row2 = gui->eyedrop_y + radius;
2266 column1 = gui->eyedrop_x - radius;
2267 column2 = gui->eyedrop_x + radius;
2269 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2270 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2271 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2272 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2274 if(row2 <= row1) row2 = row1 + 1;
2275 if(column2 <= column1) column2 = column1 + 1;
2282 output_to_canvas(mwindow->edl, 0, x1, y1);
2283 output_to_canvas(mwindow->edl, 0, x2, y2);
2284 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2286 if(x2 - x1 >= 1 && y2 - y1 >= 1)
2288 get_canvas()->set_inverse();
2289 get_canvas()->set_color(WHITE);
2291 get_canvas()->draw_rectangle((int)x1,
2296 get_canvas()->set_opaque();
2297 get_canvas()->flash();
2305 gui->current_operation = CWINDOW_EYEDROP;
2306 gui->tool_panel->raise_window();
2309 if(gui->current_operation == CWINDOW_EYEDROP)
2311 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2313 // Get color out of frame.
2314 // Doesn't work during playback because that bypasses the refresh frame.
2315 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2317 float cursor_x = get_cursor_x();
2318 float cursor_y = get_cursor_y();
2319 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2320 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2321 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2323 row1 = cursor_y - radius;
2324 row2 = cursor_y + radius;
2325 column1 = cursor_x - radius;
2326 column2 = cursor_x + radius;
2327 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2328 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2329 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2330 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2331 if(row2 <= row1) row2 = row1 + 1;
2332 if(column2 <= column1) column2 = column1 + 1;
2336 if(gui->eyedrop_visible)
2339 do_eyedrop(temp, 0, 1);
2340 gui->eyedrop_visible = 0;
2343 gui->eyedrop_x = cursor_x;
2344 gui->eyedrop_y = cursor_y;
2349 do_eyedrop(temp, 0, 1);
2350 gui->eyedrop_visible = 1;
2353 // Decompression coefficients straight out of jpeglib
2354 #define V_TO_R 1.40200
2355 #define V_TO_G -0.71414
2357 #define U_TO_G -0.34414
2358 #define U_TO_B 1.77200
2360 #define GET_COLOR(type, components, max, do_yuv) \
2362 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2364 float red = (float)*row++ / max; \
2365 float green = (float)*row++ / max; \
2366 float blue = (float)*row++ / max; \
2369 float r = red + V_TO_R * (blue - 0.5); \
2370 float g = red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
2371 float b = red + U_TO_B * (green - 0.5); \
2372 mwindow->edl->local_session->red += r; \
2373 mwindow->edl->local_session->green += g; \
2374 mwindow->edl->local_session->blue += b; \
2375 if(r > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = r; \
2376 if(g > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = g; \
2377 if(b > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = b; \
2381 mwindow->edl->local_session->red += red; \
2382 mwindow->edl->local_session->green += green; \
2383 mwindow->edl->local_session->blue += blue; \
2384 if(red > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = red; \
2385 if(green > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = green; \
2386 if(blue > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = blue; \
2392 mwindow->edl->local_session->red = 0;
2393 mwindow->edl->local_session->green = 0;
2394 mwindow->edl->local_session->blue = 0;
2395 mwindow->edl->local_session->red_max = 0;
2396 mwindow->edl->local_session->green_max = 0;
2397 mwindow->edl->local_session->blue_max = 0;
2398 for(int i = row1; i < row2; i++)
2400 for(int j = column1; j < column2; j++)
2402 switch(refresh_frame->get_color_model())
2405 GET_COLOR(unsigned char, 3, 0xff, 1);
2408 GET_COLOR(unsigned char, 4, 0xff, 1);
2411 GET_COLOR(uint16_t, 3, 0xffff, 1);
2413 case BC_YUVA16161616:
2414 GET_COLOR(uint16_t, 4, 0xffff, 1);
2417 GET_COLOR(unsigned char, 3, 0xff, 0);
2420 GET_COLOR(unsigned char, 4, 0xff, 0);
2423 GET_COLOR(float, 3, 1.0, 0);
2426 GET_COLOR(float, 4, 1.0, 0);
2432 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2433 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2434 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2439 mwindow->edl->local_session->red = 0;
2440 mwindow->edl->local_session->green = 0;
2441 mwindow->edl->local_session->blue = 0;
2442 gui->eyedrop_visible = 0;
2451 // Can't rerender since the color value is from the output of any effect it
2454 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2460 int CWindowCanvas::need_overlays()
2462 if( mwindow->edl->session->safe_regions ) return 1;
2463 if( mwindow->edl->session->cwindow_scrollbars ) return 1;
2464 if( gui->highlighted ) return 1;
2465 switch( mwindow->edl->session->cwindow_operation ) {
2466 case CWINDOW_EYEDROP:
2467 if( ! gui->eyedrop_visible ) break;
2468 case CWINDOW_CAMERA:
2469 case CWINDOW_PROJECTOR:
2478 void CWindowCanvas::draw_overlays()
2480 if(mwindow->edl->session->safe_regions)
2482 draw_safe_regions();
2485 if(mwindow->edl->session->cwindow_scrollbars)
2487 // Always draw output rectangle
2488 float x1, y1, x2, y2;
2490 x2 = mwindow->edl->session->output_w;
2492 y2 = mwindow->edl->session->output_h;
2493 output_to_canvas(mwindow->edl, 0, x1, y1);
2494 output_to_canvas(mwindow->edl, 0, x2, y2);
2496 get_canvas()->set_inverse();
2497 get_canvas()->set_color(WHITE);
2499 get_canvas()->draw_rectangle((int)x1,
2504 get_canvas()->set_opaque();
2507 if(gui->highlighted)
2509 get_canvas()->set_color(WHITE);
2510 get_canvas()->set_inverse();
2511 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2512 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2513 get_canvas()->set_opaque();
2516 int temp1 = 0, temp2 = 0;
2517 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2518 switch(mwindow->edl->session->cwindow_operation)
2520 case CWINDOW_CAMERA:
2524 case CWINDOW_PROJECTOR:
2533 do_mask(temp1, temp2, 0, 0, 1);
2537 do_ruler(1, 0, 0, 0);
2540 case CWINDOW_EYEDROP:
2541 if(gui->eyedrop_visible)
2544 do_eyedrop(rerender, 0, 1);
2545 gui->eyedrop_visible = 1;
2551 void CWindowCanvas::draw_safe_regions()
2553 float action_x1, action_x2, action_y1, action_y2;
2554 float title_x1, title_x2, title_y1, title_y2;
2556 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2557 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2558 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2559 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2560 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2561 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2562 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2563 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2565 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2566 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2567 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2568 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2570 get_canvas()->set_inverse();
2571 get_canvas()->set_color(WHITE);
2573 get_canvas()->draw_rectangle((int)action_x1,
2575 (int)(action_x2 - action_x1),
2576 (int)(action_y2 - action_y1));
2577 get_canvas()->draw_rectangle((int)title_x1,
2579 (int)(title_x2 - title_x1),
2580 (int)(title_y2 - title_y1));
2582 get_canvas()->set_opaque();
2586 void CWindowCanvas::create_keyframe(int do_camera)
2588 Track *affected_track = gui->cwindow->calculate_affected_track();
2589 if( affected_track ) {
2590 double pos = mwindow->edl->local_session->get_selectionstart(1);
2591 int64_t position = affected_track->to_units(pos, 0);
2592 int ix = do_camera ? AUTOMATION_CAMERA_X : AUTOMATION_PROJECTOR_X;
2593 int iy = do_camera ? AUTOMATION_CAMERA_Y : AUTOMATION_PROJECTOR_Y;
2594 int iz = do_camera ? AUTOMATION_CAMERA_Z : AUTOMATION_PROJECTOR_Z;
2595 FloatAuto *prev, *next;
2596 FloatAutos **autos = (FloatAutos**)affected_track->automation->autos;
2597 FloatAutos *x_autos = autos[ix]; prev = 0; next = 0;
2598 float x_value = x_autos->get_value(position, PLAY_FORWARD, prev, next);
2599 FloatAutos *y_autos = autos[iy]; prev = 0; next = 0;
2600 float y_value = y_autos->get_value(position, PLAY_FORWARD, prev, next);
2601 FloatAutos *z_autos = autos[iz]; prev = 0; next = 0;
2602 float z_value = z_autos->get_value(position, PLAY_FORWARD, prev, next);
2603 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2605 gui->cwindow->calculate_affected_autos(affected_track,
2606 &x_keyframe, &y_keyframe, &z_keyframe,
2607 do_camera, -1, -1, -1, 0);
2608 x_keyframe->set_value(x_value);
2609 y_keyframe->set_value(y_value);
2610 z_keyframe->set_value(z_value);
2612 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2616 void CWindowCanvas::camera_keyframe() { create_keyframe(1); }
2617 void CWindowCanvas::projector_keyframe() { create_keyframe(0); }
2619 void CWindowCanvas::reset_keyframe(int do_camera)
2621 Track *affected_track = gui->cwindow->calculate_affected_track();
2622 if( affected_track ) {
2623 FloatAuto *x_keyframe = 0, *y_keyframe = 0, *z_keyframe = 0;
2624 gui->cwindow->calculate_affected_autos(affected_track,
2625 &x_keyframe, &y_keyframe, &z_keyframe,
2626 do_camera, 1, 1, 1);
2628 x_keyframe->set_value(0);
2629 y_keyframe->set_value(0);
2630 z_keyframe->set_value(1);
2632 gui->sync_parameters(CHANGE_PARAMS, 1, 1);
2636 void CWindowCanvas::reset_camera() { reset_keyframe(1); }
2637 void CWindowCanvas::reset_projector() { reset_keyframe(0); }
2640 int CWindowCanvas::test_crop(int button_press, int &redraw)
2643 int handle_selected = -1;
2644 float x1 = mwindow->edl->session->crop_x1;
2645 float y1 = mwindow->edl->session->crop_y1;
2646 float x2 = mwindow->edl->session->crop_x2;
2647 float y2 = mwindow->edl->session->crop_y2;
2648 float cursor_x = get_cursor_x();
2649 float cursor_y = get_cursor_y();
2650 float canvas_x1 = x1;
2651 float canvas_y1 = y1;
2652 float canvas_x2 = x2;
2653 float canvas_y2 = y2;
2654 float canvas_cursor_x = cursor_x;
2655 float canvas_cursor_y = cursor_y;
2657 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2658 // Use screen normalized coordinates for hot spot tests.
2659 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2660 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2663 if(gui->current_operation == CWINDOW_CROP)
2665 handle_selected = gui->crop_handle;
2668 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2669 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2671 handle_selected = 0;
2672 gui->crop_origin_x = x1;
2673 gui->crop_origin_y = y1;
2676 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2677 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2679 handle_selected = 1;
2680 gui->crop_origin_x = x2;
2681 gui->crop_origin_y = y1;
2684 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2685 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2687 handle_selected = 2;
2688 gui->crop_origin_x = x1;
2689 gui->crop_origin_y = y2;
2692 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2693 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2695 handle_selected = 3;
2696 gui->crop_origin_x = x2;
2697 gui->crop_origin_y = y2;
2702 gui->crop_origin_x = cursor_x;
2703 gui->crop_origin_y = cursor_y;
2706 // printf("test crop %d %d\n",
2707 // gui->current_operation,
2708 // handle_selected);
2715 gui->crop_translate = 1;
2716 gui->crop_origin_x1 = x1;
2717 gui->crop_origin_y1 = y1;
2718 gui->crop_origin_x2 = x2;
2719 gui->crop_origin_y2 = y2;
2722 gui->crop_translate = 0;
2724 gui->current_operation = CWINDOW_CROP;
2725 gui->crop_handle = handle_selected;
2726 gui->x_origin = cursor_x;
2727 gui->y_origin = cursor_y;
2728 gui->tool_panel->raise_window();
2731 if(handle_selected < 0 && !gui->crop_translate)
2735 mwindow->edl->session->crop_x1 = (int)x1;
2736 mwindow->edl->session->crop_y1 = (int)y1;
2737 mwindow->edl->session->crop_x2 = (int)x2;
2738 mwindow->edl->session->crop_y2 = (int)y2;
2743 // Translate all 4 points
2744 if(gui->current_operation == CWINDOW_CROP && gui->crop_translate)
2746 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2747 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2748 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2749 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2751 mwindow->edl->session->crop_x1 = (int)x1;
2752 mwindow->edl->session->crop_y1 = (int)y1;
2753 mwindow->edl->session->crop_x2 = (int)x2;
2754 mwindow->edl->session->crop_y2 = (int)y2;
2760 if(gui->current_operation == CWINDOW_CROP)
2762 switch(gui->crop_handle)
2765 x1 = gui->crop_origin_x;
2766 y1 = gui->crop_origin_y;
2767 x2 = gui->crop_origin_x;
2768 y2 = gui->crop_origin_y;
2769 if(cursor_x < gui->x_origin)
2771 if(cursor_y < gui->y_origin)
2777 if(cursor_y >= gui->y_origin)
2784 if(cursor_x >= gui->x_origin)
2786 if(cursor_y < gui->y_origin)
2792 if(cursor_y >= gui->y_origin)
2799 // printf("test crop %d %d %d %d\n",
2800 // mwindow->edl->session->crop_x1,
2801 // mwindow->edl->session->crop_y1,
2802 // mwindow->edl->session->crop_x2,
2803 // mwindow->edl->session->crop_y2);
2806 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2807 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2810 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2811 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2814 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2815 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2818 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2819 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2823 if(!EQUIV(mwindow->edl->session->crop_x1, x1) ||
2824 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2825 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2826 !EQUIV(mwindow->edl->session->crop_y2, y2))
2833 switch (gui->crop_handle)
2835 case 0: gui->crop_handle = 1; break;
2836 case 1: gui->crop_handle = 0; break;
2837 case 2: gui->crop_handle = 3; break;
2838 case 3: gui->crop_handle = 2; break;
2848 switch (gui->crop_handle)
2850 case 0: gui->crop_handle = 2; break;
2851 case 1: gui->crop_handle = 3; break;
2852 case 2: gui->crop_handle = 0; break;
2853 case 3: gui->crop_handle = 1; break;
2858 mwindow->edl->session->crop_x1 = (int)x1;
2859 mwindow->edl->session->crop_y1 = (int)y1;
2860 mwindow->edl->session->crop_x2 = (int)x2;
2861 mwindow->edl->session->crop_y2 = (int)y2;
2867 // Update cursor font
2868 if(handle_selected >= 0)
2870 switch(handle_selected)
2873 set_cursor(UPLEFT_RESIZE);
2876 set_cursor(UPRIGHT_RESIZE);
2879 set_cursor(DOWNLEFT_RESIZE);
2882 set_cursor(DOWNRIGHT_RESIZE);
2889 set_cursor(ARROW_CURSOR);
2891 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2895 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2896 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2897 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2898 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2899 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2900 // mwindow->edl->session->crop_x2,
2901 // mwindow->edl->session->crop_y2,
2902 // mwindow->edl->calculate_output_w(0),
2903 // mwindow->edl->calculate_output_h(0));
2909 void CWindowCanvas::draw_crop()
2911 get_canvas()->set_inverse();
2912 get_canvas()->set_color(WHITE);
2914 float x1 = mwindow->edl->session->crop_x1;
2915 float y1 = mwindow->edl->session->crop_y1;
2916 float x2 = mwindow->edl->session->crop_x2;
2917 float y2 = mwindow->edl->session->crop_y2;
2919 output_to_canvas(mwindow->edl, 0, x1, y1);
2920 output_to_canvas(mwindow->edl, 0, x2, y2);
2922 if(x2 - x1 && y2 - y1)
2923 get_canvas()->draw_rectangle((int)x1,
2928 draw_crophandle((int)x1, (int)y1);
2929 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2930 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2931 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2932 get_canvas()->set_opaque();
2936 void CWindowCanvas::draw_outlines(int do_camera)
2938 Track *track = gui->cwindow->calculate_affected_track();
2942 float proj_x, proj_y, proj_z;
2943 int64_t position = track->to_units(
2944 mwindow->edl->local_session->get_selectionstart(1),
2946 track->automation->get_projector(&proj_x, &proj_y, &proj_z,
2947 position, PLAY_FORWARD);
2949 proj_x += mwindow->edl->session->output_w/2.;
2950 proj_y += mwindow->edl->session->output_h/2.;
2951 float proj_x1 = proj_x - track->track_w/2. * proj_z;
2952 float proj_y1 = proj_y - track->track_h/2. * proj_z;
2953 float proj_x2 = proj_x + track->track_w/2. * proj_z;
2954 float proj_y2 = proj_y + track->track_h/2. * proj_z;
2955 float x1 = proj_x1, x2 = proj_x2;
2956 float y1 = proj_y1, y2 = proj_y2;
2957 output_to_canvas(mwindow->edl, 0, x1, y1);
2958 output_to_canvas(mwindow->edl, 0, x2, y2);
2960 #define DRAW_PROJECTION(offset) \
2961 get_canvas()->draw_rectangle(x1+offset, y1+offset, (x2-x1), (y2-y1)); \
2962 get_canvas()->draw_line(x1+offset, y1+offset, x2+offset, y2+offset); \
2963 get_canvas()->draw_line(x2+offset, y1+offset, x1+offset, y2+offset); \
2966 get_canvas()->set_color(BLACK);
2968 get_canvas()->set_color(do_camera ? GREEN : RED);
2972 float cam_x, cam_y, cam_z;
2973 track->automation->get_camera(&cam_x, &cam_y, &cam_z,
2974 position, PLAY_FORWARD);
2975 cam_x += track->track_w / 2.;
2976 cam_y += track->track_h / 2.;
2977 // follow image, not camera
2978 cam_x = -cam_x; cam_y = -cam_y; cam_z *= proj_z;
2979 float cam_x1 = cam_x * cam_z + proj_x;
2980 float cam_y1 = cam_y * cam_z + proj_y;
2981 float cam_x2 = (cam_x + track->track_w) * cam_z + proj_x;
2982 float cam_y2 = (cam_y + track->track_h) * cam_z + proj_y;
2983 output_to_canvas(mwindow->edl, 0, cam_x1, cam_y1);
2984 output_to_canvas(mwindow->edl, 0, cam_x2, cam_y2);
2985 get_canvas()->set_color(YELLOW);
2986 get_canvas()->draw_rectangle(cam_x1, cam_y1, cam_x2-cam_x1, cam_y2-cam_y1);
2990 int CWindowCanvas::test_bezier(int button_press,
2998 // Processing drag operation.
2999 // Create keyframe during first cursor motion.
3000 if( !button_press ) {
3002 float cursor_x = get_cursor_x();
3003 float cursor_y = get_cursor_y();
3004 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
3006 if( gui->current_operation == CWINDOW_CAMERA ||
3007 gui->current_operation == CWINDOW_PROJECTOR ) {
3008 if( !gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom ) {
3009 gui->translating_zoom = 1;
3010 gui->reset_affected();
3012 else if( !gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom ) {
3013 gui->translating_zoom = 0;
3014 gui->reset_affected();
3017 // Get target keyframe
3018 if( !gui->affected_x && !gui->affected_y && !gui->affected_z ) {
3019 if(!gui->affected_track) return 0;
3020 FloatAutos *affected_x_autos, *affected_y_autos, *affected_z_autos;
3021 FloatAutos** autos = (FloatAutos**) gui->affected_track->automation->autos;
3022 if( mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA ) {
3023 affected_x_autos = autos[AUTOMATION_CAMERA_X];
3024 affected_y_autos = autos[AUTOMATION_CAMERA_Y];
3025 affected_z_autos = autos[AUTOMATION_CAMERA_Z];
3028 affected_x_autos = autos[AUTOMATION_PROJECTOR_X];
3029 affected_y_autos = autos[AUTOMATION_PROJECTOR_Y];
3030 affected_z_autos = autos[AUTOMATION_PROJECTOR_Z];
3032 double position = mwindow->edl->local_session->get_selectionstart(1);
3033 int64_t track_position = gui->affected_track->to_units(position, 0);
3034 FloatAuto *prev_x = 0, *next_x = 0;
3035 float new_x = affected_x_autos->get_value(track_position, PLAY_FORWARD, prev_x, next_x);
3036 FloatAuto *prev_y = 0, *next_y = 0;
3037 float new_y = affected_y_autos->get_value(track_position, PLAY_FORWARD, prev_y, next_y);
3038 FloatAuto *prev_z = 0, *next_z = 0;
3039 float new_z = affected_z_autos->get_value(track_position, PLAY_FORWARD, prev_z, next_z);
3040 int zooming = gui->translating_zoom, created;
3041 gui->affected_x = (FloatAuto*)gui->cwindow->calculate_affected_auto(
3042 affected_x_autos, !zooming, &created, 0);
3044 gui->affected_x->set_value(new_x);
3047 gui->affected_y = (FloatAuto*)gui->cwindow->calculate_affected_auto(
3048 affected_y_autos, !zooming, &created, 0);
3050 gui->affected_y->set_value(new_y);
3053 gui->affected_z = (FloatAuto*)gui->cwindow->calculate_affected_auto(
3054 affected_z_autos, zooming, &created, 0);
3056 gui->affected_z->set_value(new_z);
3061 if( gui->translating_zoom ) {
3062 gui->center_z = gui->affected_z->get_value();
3065 gui->center_x = gui->affected_x->get_value();
3066 gui->center_y = gui->affected_y->get_value();
3073 float x_val = gui->affected_x->get_value();
3074 float y_val = gui->affected_y->get_value();
3075 float z_val = gui->affected_z->get_value();
3077 if( gui->translating_zoom ) {
3078 float z = gui->center_z + (cursor_y - gui->y_origin) / 128;
3080 if( !EQUIV(z_val, z) ) {
3085 gui->affected_z->set_value(z);
3088 float dx = cursor_x - gui->x_origin;
3089 float dy = cursor_y - gui->y_origin;
3090 // follow image, not camera
3091 if( gui->current_operation == CWINDOW_CAMERA ) {
3092 dx = -dx / z_val; dy = -dy / z_val;
3094 float x = gui->center_x + dx;
3095 float y = gui->center_y + dy;
3096 gui->affected_x->set_value(x);
3097 gui->affected_y->set_value(y);
3098 if( !EQUIV(x_val, x) || !EQUIV(y_val, y) ) {
3109 // Begin drag operation. Don't create keyframe here.
3111 // Get affected track off of the first recordable video track.
3112 // Calculating based on the alpha channel would require recording what layer
3113 // each output pixel belongs to as they're rendered and stacked. Forget it.
3114 gui->affected_track = gui->cwindow->calculate_affected_track();
3115 gui->reset_affected();
3117 if(gui->affected_track)
3120 mwindow->undo->update_undo_before(_("camera"), this);
3122 mwindow->undo->update_undo_before(_("projector"), this);
3124 gui->current_operation =
3125 mwindow->edl->session->cwindow_operation;
3126 gui->tool_panel->raise_window();
3135 int CWindowCanvas::test_zoom(int &redraw)
3141 if( mwindow->edl->session->cwindow_scrollbars ) {
3142 if( *gui->zoom_panel->get_text() != 'x' ) {
3143 // Find current zoom in table
3144 int idx = total_zooms; float old_zoom = get_zoom();
3145 while( --idx >= 0 && !EQUIV(my_zoom_table[idx], old_zoom) );
3147 idx += get_buttonpress() == 5 ||
3148 gui->ctrl_down() || gui->shift_down() ? -1 : +1 ;
3149 CLAMP(idx, 0, total_zooms-1);
3150 zoom = my_zoom_table[idx];
3153 x = get_cursor_x(); y = get_cursor_y();
3155 mwindow->edl->session->cwindow_scrollbars = 0;
3156 gui->zoom_panel->update(0);
3157 zoom = gui->get_auto_zoom();
3160 gui->zoom_panel->ZoomPanel::update(zoom);
3161 float output_x = x, output_y = y;
3162 canvas_to_output(mwindow->edl, 0, output_x, output_y);
3163 x = output_x - x / zoom;
3164 y = output_y - y / zoom;
3168 mwindow->edl->session->cwindow_scrollbars = 1;
3169 x = (mwindow->edl->session->output_w - w) / 2;
3170 y = (mwindow->edl->session->output_h - h) / 2;
3173 update_zoom((int)x, (int)y, zoom);
3175 gui->composite_panel->cpanel_zoom->update(zoom);
3177 reposition_window(mwindow->edl,
3178 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
3179 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
3180 redraw = 1; result = 1;
3186 void CWindowCanvas::calculate_origin()
3188 gui->x_origin = get_cursor_x();
3189 gui->y_origin = get_cursor_y();
3190 //printf("CWindowCanvas::calculate_origin 1 %f %f\n", gui->x_origin, gui->y_origin);
3191 canvas_to_output(mwindow->edl, 0, gui->x_origin, gui->y_origin);
3192 //printf("CWindowCanvas::calculate_origin 2 %f %f\n", gui->x_origin, gui->y_origin);
3196 int CWindowCanvas::cursor_leave_event()
3198 set_cursor(ARROW_CURSOR);
3202 int CWindowCanvas::cursor_enter_event()
3205 switch(mwindow->edl->session->cwindow_operation)
3207 case CWINDOW_CAMERA:
3208 case CWINDOW_PROJECTOR:
3209 set_cursor(MOVE_CURSOR);
3212 set_cursor(MOVE_CURSOR);
3215 test_crop(0, redraw);
3217 case CWINDOW_PROTECT:
3218 set_cursor(ARROW_CURSOR);
3222 set_cursor(CROSS_CURSOR);
3224 case CWINDOW_EYEDROP:
3225 set_cursor(CROSS_CURSOR);
3231 int CWindowCanvas::cursor_motion_event()
3233 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3236 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3237 switch(gui->current_operation)
3239 case CWINDOW_SCROLL:
3241 float zoom = get_zoom();
3242 float cursor_x = get_cursor_x();
3243 float cursor_y = get_cursor_y();
3245 float zoom_x, zoom_y, conformed_w, conformed_h;
3246 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3247 cursor_x = (float)cursor_x / zoom_x + gui->x_offset;
3248 cursor_y = (float)cursor_y / zoom_y + gui->y_offset;
3252 int x = (int)(gui->x_origin - cursor_x + gui->x_offset);
3253 int y = (int)(gui->y_origin - cursor_y + gui->y_offset);
3258 update_scrollbars(0);
3265 result = do_ruler(0, 1, 0, 0);
3268 case CWINDOW_CAMERA:
3269 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3272 case CWINDOW_PROJECTOR:
3273 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3278 result = test_crop(0, redraw);
3279 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3286 case CWINDOW_MASK_CONTROL_IN:
3287 case CWINDOW_MASK_CONTROL_OUT:
3288 case CWINDOW_MASK_TRANSLATE:
3290 result = do_mask(redraw,
3297 case CWINDOW_EYEDROP:
3298 result = do_eyedrop(rerender, 0, 0);
3307 // cursor font changes
3310 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3312 // mwindow->edl->session->cwindow_operation);
3313 switch(mwindow->edl->session->cwindow_operation)
3316 result = test_crop(0, redraw);
3319 result = do_ruler(0, 1, 0, 0);
3322 result = do_mask(redraw,
3331 int change_type = rerender ? CHANGE_PARAMS : -1;
3332 gui->sync_parameters(change_type, redraw, redraw_canvas);
3337 int CWindowCanvas::button_press_event()
3341 int redraw_canvas = 0;
3344 if(Canvas::button_press_event()) return 1;
3346 gui->translating_zoom = gui->shift_down();
3349 //printf("CWindowCanvas::button_press_event 2 %f %f\n", gui->x_origin, gui->y_origin, gui->x_origin, gui->y_origin);
3351 float zoom_x, zoom_y, conformed_w, conformed_h;
3352 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3353 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3354 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3357 if( mwindow->edl->session->cwindow_operation != CWINDOW_PROTECT &&
3358 get_buttonpress() == MIDDLE_BUTTON && !get_canvas()->shift_down() )
3360 gui->current_operation = CWINDOW_SCROLL;
3366 switch(mwindow->edl->session->cwindow_operation)
3369 result = do_ruler(0, 0, 1, 0);
3372 case CWINDOW_CAMERA:
3373 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3376 case CWINDOW_PROJECTOR:
3377 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3381 result = test_zoom(redraw);
3385 result = test_crop(1, redraw);
3389 switch( get_buttonpress() ) {
3391 result = do_mask(redraw, rerender, 1, 0, 0);
3393 case MIDDLE_BUTTON: { // && shift_down()
3394 result = do_mask_focus();
3400 result = do_mask(redraw, rerender, 1, 1, 0);
3403 if( result ) redraw_canvas = 1;
3406 case CWINDOW_EYEDROP:
3407 result = do_eyedrop(rerender, 1, 0);
3412 int change_type = rerender ? CHANGE_PARAMS : -1;
3413 gui->sync_parameters(change_type, redraw, redraw_canvas);
3418 int CWindowCanvas::button_release_event()
3421 const char *undo_label = 0;
3423 switch(gui->current_operation)
3425 case CWINDOW_SCROLL:
3430 do_ruler(0, 0, 0, 1);
3433 case CWINDOW_CAMERA:
3434 undo_label = _("camera");
3437 case CWINDOW_PROJECTOR:
3438 undo_label = _("projector");
3442 case CWINDOW_MASK_CONTROL_IN:
3443 case CWINDOW_MASK_CONTROL_OUT:
3444 case CWINDOW_MASK_TRANSLATE:
3445 // Finish mask operation
3446 gui->mask_keyframe = 0;
3447 undo_label = _("mask");
3449 case CWINDOW_MASK_ROTATE:
3450 gui->mask_keyframe = 0;
3451 undo_label = _("mask rotate");
3453 case CWINDOW_MASK_SCALE:
3454 gui->mask_keyframe = 0;
3455 undo_label = _("mask scale");
3458 result = Canvas::button_release_event();
3463 mwindow->undo->update_undo_after(undo_label, LOAD_AUTOMATION);
3464 gui->current_operation = CWINDOW_NONE;
3468 void CWindowCanvas::zoom_resize_window(float percentage)
3470 int canvas_w, canvas_h;
3474 // Get required canvas size
3475 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3476 mwindow->edl->session->output_w,
3477 mwindow->edl->session->output_h,
3482 // Estimate window size from current borders
3483 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3484 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3486 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3487 mwindow->session->cwindow_w = new_w;
3488 mwindow->session->cwindow_h = new_h;
3490 mwindow->theme->get_cwindow_sizes(gui,
3491 mwindow->session->cwindow_controls);
3493 // Estimate again from new borders
3494 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3495 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3496 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3498 gui->resize_window(new_w, new_h);
3499 gui->resize_event(new_w, new_h);
3502 void CWindowCanvas::toggle_controls()
3504 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3505 gui->resize_event(gui->get_w(), gui->get_h());
3508 int CWindowCanvas::get_cwindow_controls()
3510 return mwindow->session->cwindow_controls;