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;
99 orig_mask_keyframe = new MaskAuto(0, 0);
105 current_operation = CWINDOW_NONE;
107 translating_zoom = 0;
115 CWindowGUI::~CWindowGUI()
117 if(tool_panel) delete tool_panel;
119 delete composite_panel;
126 delete orig_mask_keyframe;
129 void CWindowGUI::create_objects()
131 lock_window("CWindowGUI::create_objects");
132 set_icon(mwindow->theme->get_image("cwindow_icon"));
134 active = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_active"));
135 inactive = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_inactive"));
137 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
138 mwindow->theme->draw_cwindow_bg(this);
141 // Meters required by composite panel
142 meters = new CWindowMeters(mwindow,
144 mwindow->theme->cmeter_x,
145 mwindow->theme->cmeter_y,
146 mwindow->theme->cmeter_h);
147 meters->create_objects();
150 composite_panel = new CPanel(mwindow,
152 mwindow->theme->ccomposite_x,
153 mwindow->theme->ccomposite_y,
154 mwindow->theme->ccomposite_w,
155 mwindow->theme->ccomposite_h);
156 composite_panel->create_objects();
158 canvas = new CWindowCanvas(mwindow, this);
160 canvas->create_objects(mwindow->edl);
161 canvas->use_cwindow();
164 add_subwindow(timebar = new CTimeBar(mwindow,
166 mwindow->theme->ctimebar_x,
167 mwindow->theme->ctimebar_y,
168 mwindow->theme->ctimebar_w,
169 mwindow->theme->ctimebar_h));
170 timebar->create_objects();
173 add_subwindow(slider = new CWindowSlider(mwindow,
175 mwindow->theme->cslider_x,
176 mwindow->theme->cslider_y,
177 mwindow->theme->cslider_w));
180 transport = new CWindowTransport(mwindow,
182 mwindow->theme->ctransport_x,
183 mwindow->theme->ctransport_y);
184 transport->create_objects();
186 transport->set_slider(slider);
189 edit_panel = new CWindowEditing(mwindow, cwindow);
190 edit_panel->set_meters(meters);
191 edit_panel->create_objects();
193 // add_subwindow(clock = new MainClock(mwindow,
194 // mwindow->theme->ctime_x,
195 // mwindow->theme->ctime_y));
197 zoom_panel = new CWindowZoom(mwindow,
199 mwindow->theme->czoom_x,
200 mwindow->theme->czoom_y,
201 mwindow->theme->czoom_w);
202 zoom_panel->create_objects();
203 auto_zoom = _(AUTO_ZOOM);
204 zoom_panel->zoom_text->add_item(new BC_MenuItem(auto_zoom));
205 if(!mwindow->edl->session->cwindow_scrollbars) zoom_panel->set_text(auto_zoom);
207 // destination = new CWindowDestination(mwindow,
209 // mwindow->theme->cdest_x,
210 // mwindow->theme->cdest_y);
211 // destination->create_objects();
213 // Must create after meter panel
214 tool_panel = new CWindowTool(mwindow, this);
215 tool_panel->Thread::start();
218 set_operation(mwindow->edl->session->cwindow_operation);
222 canvas->draw_refresh(0);
229 int CWindowGUI::translation_event()
231 mwindow->session->cwindow_x = get_x();
232 mwindow->session->cwindow_y = get_y();
236 int CWindowGUI::resize_event(int w, int h)
238 mwindow->session->cwindow_x = get_x();
239 mwindow->session->cwindow_y = get_y();
240 mwindow->session->cwindow_w = w;
241 mwindow->session->cwindow_h = h;
243 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
244 mwindow->theme->draw_cwindow_bg(this);
247 composite_panel->reposition_buttons(mwindow->theme->ccomposite_x,
248 mwindow->theme->ccomposite_y);
250 canvas->reposition_window(mwindow->edl,
251 mwindow->theme->ccanvas_x,
252 mwindow->theme->ccanvas_y,
253 mwindow->theme->ccanvas_w,
254 mwindow->theme->ccanvas_h);
256 timebar->resize_event();
259 slider->reposition_window(mwindow->theme->cslider_x,
260 mwindow->theme->cslider_y,
261 mwindow->theme->cslider_w);
262 // Recalibrate pointer motion range
263 slider->set_position();
266 transport->reposition_buttons(mwindow->theme->ctransport_x,
267 mwindow->theme->ctransport_y);
269 edit_panel->reposition_buttons(mwindow->theme->cedit_x,
270 mwindow->theme->cedit_y);
272 // clock->reposition_window(mwindow->theme->ctime_x,
273 // mwindow->theme->ctime_y);
275 zoom_panel->reposition_window(mwindow->theme->czoom_x,
276 mwindow->theme->czoom_y);
278 // destination->reposition_window(mwindow->theme->cdest_x,
279 // mwindow->theme->cdest_y);
281 meters->reposition_window(mwindow->theme->cmeter_x,
282 mwindow->theme->cmeter_y,
284 mwindow->theme->cmeter_h);
288 BC_WindowBase::resize_event(w, h);
292 int CWindowGUI::button_press_event()
294 if(canvas->get_canvas())
295 return canvas->button_press_event_base(canvas->get_canvas());
299 int CWindowGUI::cursor_leave_event()
301 if(canvas->get_canvas())
302 return canvas->cursor_leave_event_base(canvas->get_canvas());
306 int CWindowGUI::cursor_enter_event()
308 if(canvas->get_canvas())
309 return canvas->cursor_enter_event_base(canvas->get_canvas());
313 int CWindowGUI::button_release_event()
315 if(canvas->get_canvas())
316 return canvas->button_release_event();
320 int CWindowGUI::cursor_motion_event()
322 if(canvas->get_canvas())
324 canvas->get_canvas()->unhide_cursor();
325 return canvas->cursor_motion_event();
336 void CWindowGUI::draw_status(int flush)
338 if( (canvas->get_canvas() && canvas->get_canvas()->get_video_on()) ||
339 canvas->is_processing )
342 mwindow->theme->cstatus_x,
343 mwindow->theme->cstatus_y);
347 draw_pixmap(inactive,
348 mwindow->theme->cstatus_x,
349 mwindow->theme->cstatus_y);
353 // printf("CWindowGUI::draw_status %d %d %d\n", __LINE__, mwindow->theme->cstatus_x,
354 // mwindow->theme->cstatus_y);
355 flash(mwindow->theme->cstatus_x,
356 mwindow->theme->cstatus_y,
362 float CWindowGUI::get_auto_zoom()
364 float conformed_w, conformed_h;
365 mwindow->edl->calculate_conformed_dimensions(0, conformed_w, conformed_h);
366 float zoom_x = canvas->w / conformed_w;
367 float zoom_y = canvas->h / conformed_h;
368 return zoom_x < zoom_y ? zoom_x : zoom_y;
371 void CWindowGUI::zoom_canvas(int do_auto, double value, int update_menu)
373 EDL *edl = mwindow->edl;
375 float old_zoom = mwindow->edl->session->cwindow_zoom;
376 float new_zoom = value;
377 edl->session->cwindow_scrollbars = do_auto ? 0 : 1;
378 if( !do_auto && canvas->scrollbars_exist() ) {
379 float z = 1 - old_zoom / new_zoom;
380 x = canvas->get_xscroll() + 0.5f*canvas->w_visible * z;
381 y = canvas->get_yscroll() + 0.5f*canvas->h_visible * z;
386 int frac = new_zoom >= 1.0f ? 1 :
387 new_zoom >= 0.1f ? 2 :
388 new_zoom >= .01f ? 3 : 4;
389 char string[BCSTRLEN];
390 sprintf(string,"x %.*f", frac, new_zoom);
391 zoom_panel->update(string);
394 zoom_panel->update(auto_zoom);
395 composite_panel->cpanel_zoom->update(new_zoom);
398 else if( mwindow->edl->session->cwindow_operation == CWINDOW_ZOOM ) {
399 composite_panel->cpanel_zoom->update(new_zoom);
402 canvas->update_zoom((int)x, (int)y, new_zoom);
403 canvas->reposition_window(mwindow->edl,
404 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
405 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
406 canvas->draw_refresh();
411 void CWindowGUI::set_operation(int value)
413 mwindow->edl->session->cwindow_operation = value;
415 composite_panel->set_operation(value);
416 edit_panel->update();
418 tool_panel->start_tool(value);
419 canvas->draw_refresh();
422 void CWindowGUI::update_tool()
424 tool_panel->update_values();
427 int CWindowGUI::close_event()
429 cwindow->hide_window();
434 int CWindowGUI::keypress_event()
438 switch(get_keypress())
456 if(mwindow->session->cwindow_fullscreen)
457 canvas->stop_fullscreen();
459 canvas->start_fullscreen();
460 lock_window("CWindowGUI::keypress_event 1");
464 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
466 mwindow->gui->unlock_window();
467 lock_window("CWindowGUI::keypress_event 2");
471 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
472 mwindow->clear_entry();
473 mwindow->gui->unlock_window();
474 lock_window("CWindowGUI::keypress_event 3");
478 if(mwindow->session->cwindow_fullscreen)
479 canvas->stop_fullscreen();
480 lock_window("CWindowGUI::keypress_event 4");
487 int shift_down = this->shift_down();
489 mwindow->gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
491 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
492 mwindow->prev_edit_handle(shift_down);
493 mwindow->gui->unlock_window();
495 lock_window("CWindowGUI::keypress_event 1");
501 mwindow->gui->lock_window("CWindowGUI::keypress_event 3");
502 mwindow->move_left();
503 mwindow->gui->unlock_window();
505 lock_window("CWindowGUI::keypress_event 2");
515 int shift_down = this->shift_down();
517 mwindow->gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
519 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
520 mwindow->next_edit_handle(shift_down);
521 mwindow->gui->unlock_window();
523 lock_window("CWindowGUI::keypress_event 2");
529 mwindow->gui->lock_window("CWindowGUI::keypress_event 4");
530 mwindow->move_right();
531 mwindow->gui->unlock_window();
533 lock_window("CWindowGUI::keypress_event 3");
540 if(!result) result = transport->keypress_event();
546 void CWindowGUI::reset_affected()
553 void CWindowGUI::keyboard_zoomin()
555 // if(mwindow->edl->session->cwindow_scrollbars)
557 zoom_panel->zoom_tumbler->handle_up_event();
564 void CWindowGUI::keyboard_zoomout()
566 // if(mwindow->edl->session->cwindow_scrollbars)
568 zoom_panel->zoom_tumbler->handle_down_event();
576 void CWindowGUI::drag_motion()
578 if(get_hidden()) return;
580 if(mwindow->session->current_operation != DRAG_ASSET &&
581 mwindow->session->current_operation != DRAG_VTRANSITION &&
582 mwindow->session->current_operation != DRAG_VEFFECT) return;
583 int need_highlight = cursor_above() && get_cursor_over_window();
584 if( highlighted == need_highlight ) return;
585 highlighted = need_highlight;
586 canvas->draw_refresh();
589 int CWindowGUI::drag_stop()
592 if(get_hidden()) return 0;
593 if( !highlighted ) return 0;
594 if( mwindow->session->current_operation != DRAG_ASSET &&
595 mwindow->session->current_operation != DRAG_VTRANSITION &&
596 mwindow->session->current_operation != DRAG_VEFFECT) return 0;
598 canvas->draw_refresh();
601 if(mwindow->session->current_operation == DRAG_ASSET)
603 if(mwindow->session->drag_assets->total ||
604 mwindow->session->drag_clips->total)
606 mwindow->gui->lock_window("CWindowGUI::drag_stop 5");
607 mwindow->undo->update_undo_before(_("insert assets"), 0);
608 mwindow->gui->unlock_window();
611 if(mwindow->session->drag_assets->total)
613 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
615 mwindow->load_assets(mwindow->session->drag_assets,
616 mwindow->edl->local_session->get_selectionstart(),
618 mwindow->session->track_highlighted,
620 mwindow->edl->session->labels_follow_edits,
621 mwindow->edl->session->plugins_follow_edits,
622 mwindow->edl->session->autos_follow_edits,
626 if(mwindow->session->drag_clips->total)
628 mwindow->gui->lock_window("CWindowGUI::drag_stop 2");
630 mwindow->paste_edls(mwindow->session->drag_clips,
632 mwindow->session->track_highlighted,
633 mwindow->edl->local_session->get_selectionstart(),
634 mwindow->edl->session->labels_follow_edits,
635 mwindow->edl->session->plugins_follow_edits,
636 mwindow->edl->session->autos_follow_edits,
640 if(mwindow->session->drag_assets->total ||
641 mwindow->session->drag_clips->total)
643 mwindow->save_backup();
644 mwindow->restart_brender();
645 mwindow->gui->update(1, 1, 1, 1, 0, 1, 0);
646 mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
647 mwindow->gui->unlock_window();
648 mwindow->sync_parameters(LOAD_ALL);
652 if(mwindow->session->current_operation == DRAG_VEFFECT)
654 //printf("CWindowGUI::drag_stop 1\n");
655 Track *affected_track = cwindow->calculate_affected_track();
656 //printf("CWindowGUI::drag_stop 2\n");
658 mwindow->gui->lock_window("CWindowGUI::drag_stop 3");
659 mwindow->insert_effects_cwindow(affected_track);
660 mwindow->session->current_operation = NO_OPERATION;
661 mwindow->gui->unlock_window();
664 if(mwindow->session->current_operation == DRAG_VTRANSITION)
666 Track *affected_track = cwindow->calculate_affected_track();
667 mwindow->gui->lock_window("CWindowGUI::drag_stop 4");
668 mwindow->paste_transition_cwindow(affected_track);
669 mwindow->session->current_operation = NO_OPERATION;
670 mwindow->gui->unlock_window();
676 void CWindowGUI::update_meters()
678 if(mwindow->edl->session->cwindow_meter != meters->visible)
680 meters->set_meters(meters->meter_count, mwindow->edl->session->cwindow_meter);
681 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
682 resize_event(get_w(), get_h());
687 CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
690 mwindow->theme->cedit_x,
691 mwindow->theme->cedit_y,
692 mwindow->edl->session->editing_mode,
711 this->mwindow = mwindow;
712 this->cwindow = cwindow;
715 #define CWrapper(fn) void CWindowEditing::fn() { \
716 mwindow->gui->lock_window("CWrapper::" #fn); \
718 mwindow->gui->unlock_window(); \
721 CWrapper(copy_selection)
722 CWrapper(splice_selection)
723 CWrapper(overwrite_selection)
724 CWrapper(set_inpoint)
725 CWrapper(set_outpoint)
726 CWrapper(clear_inpoint)
727 CWrapper(clear_outpoint)
729 CWrapper(toggle_label)
737 CWindowMeters::CWindowMeters(MWindow *mwindow,
742 : MeterPanel(mwindow,
748 mwindow->edl->session->audio_channels,
749 mwindow->edl->session->cwindow_meter,
753 this->mwindow = mwindow;
757 CWindowMeters::~CWindowMeters()
761 int CWindowMeters::change_status_event(int new_status)
763 mwindow->edl->session->cwindow_meter = new_status;
764 gui->update_meters();
771 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
772 : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
773 x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
775 this->mwindow = mwindow;
779 CWindowZoom::~CWindowZoom()
783 int CWindowZoom::handle_event()
785 int do_auto = !strcasecmp(gui->auto_zoom, get_text()) ? 1 : 0;
786 float zoom = do_auto ? gui->get_auto_zoom() : get_value();
787 gui->zoom_canvas(do_auto, zoom, 0);
794 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
795 : BC_PercentageSlider(x,
804 this->mwindow = mwindow;
805 this->cwindow = cwindow;
806 set_precision(0.00001);
809 CWindowSlider::~CWindowSlider()
813 int CWindowSlider::handle_event()
815 cwindow->update_position((double)get_value());
819 void CWindowSlider::set_position()
821 double new_length = mwindow->edl->tracks->total_playable_length();
822 // if(mwindow->edl->local_session->preview_end <= 0 ||
823 // mwindow->edl->local_session->preview_end > new_length)
824 // mwindow->edl->local_session->preview_end = new_length;
825 // if(mwindow->edl->local_session->preview_start >
826 // mwindow->edl->local_session->preview_end)
827 // mwindow->edl->local_session->preview_start = 0;
830 update(mwindow->theme->cslider_w,
831 mwindow->edl->local_session->get_selectionstart(1),
834 // mwindow->edl->local_session->preview_start,
835 // mwindow->edl->local_session->preview_end);
839 int CWindowSlider::increase_value()
842 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
843 lock_window("CWindowSlider::increase_value");
847 int CWindowSlider::decrease_value()
850 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
851 lock_window("CWindowSlider::decrease_value");
856 // CWindowDestination::CWindowDestination(MWindow *mwindow, CWindowGUI *cwindow, int x, int y)
857 // : BC_PopupTextBox(cwindow,
858 // &cwindow->destinations,
859 // cwindow->destinations.values[cwindow->cwindow->destination]->get_text(),
865 // this->mwindow = mwindow;
866 // this->cwindow = cwindow;
869 // CWindowDestination::~CWindowDestination()
873 // int CWindowDestination::handle_event()
884 CWindowTransport::CWindowTransport(MWindow *mwindow,
888 : PlayTransport(mwindow,
896 EDL* CWindowTransport::get_edl()
901 void CWindowTransport::goto_start()
903 gui->unlock_window();
904 handle_transport(REWIND, 1);
906 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
907 mwindow->goto_start();
908 mwindow->gui->unlock_window();
910 gui->lock_window("CWindowTransport::goto_start 2");
913 void CWindowTransport::goto_end()
915 gui->unlock_window();
916 handle_transport(GOTO_END, 1);
918 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
920 mwindow->gui->unlock_window();
922 gui->lock_window("CWindowTransport::goto_end 2");
927 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
930 mwindow->theme->ccanvas_x,
931 mwindow->theme->ccanvas_y,
932 mwindow->theme->ccanvas_w,
933 mwindow->theme->ccanvas_h,
936 mwindow->edl->session->cwindow_scrollbars)
938 this->mwindow = mwindow;
942 void CWindowCanvas::status_event()
947 int CWindowCanvas::get_fullscreen()
949 return mwindow->session->cwindow_fullscreen;
952 void CWindowCanvas::set_fullscreen(int value)
954 mwindow->session->cwindow_fullscreen = value;
958 void CWindowCanvas::update_zoom(int x, int y, float zoom)
960 use_scrollbars = mwindow->edl->session->cwindow_scrollbars;
962 mwindow->edl->session->cwindow_xscroll = x;
963 mwindow->edl->session->cwindow_yscroll = y;
964 mwindow->edl->session->cwindow_zoom = zoom;
967 void CWindowCanvas::zoom_auto()
969 gui->zoom_canvas(1, gui->get_auto_zoom(), 1);
972 int CWindowCanvas::get_xscroll()
974 return mwindow->edl->session->cwindow_xscroll;
977 int CWindowCanvas::get_yscroll()
979 return mwindow->edl->session->cwindow_yscroll;
983 float CWindowCanvas::get_zoom()
985 return mwindow->edl->session->cwindow_zoom;
988 void CWindowCanvas::draw_refresh(int flush)
990 if(get_canvas() && !get_canvas()->get_video_on())
993 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
995 float in_x1, in_y1, in_x2, in_y2;
996 float out_x1, out_y1, out_x2, out_y2;
997 get_transfers(mwindow->edl,
1007 if(!EQUIV(out_x1, 0) ||
1008 !EQUIV(out_y1, 0) ||
1009 !EQUIV(out_x2, get_canvas()->get_w()) ||
1010 !EQUIV(out_y2, get_canvas()->get_h()))
1012 get_canvas()->clear_box(0,
1014 get_canvas()->get_w(),
1015 get_canvas()->get_h());
1018 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1019 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1022 if(out_x2 > out_x1 &&
1027 // Can't use OpenGL here because it is called asynchronously of the
1028 // playback operation.
1029 get_canvas()->draw_vframe(refresh_frame,
1032 (int)(out_x2 - out_x1),
1033 (int)(out_y2 - out_y1),
1036 (int)(in_x2 - in_x1),
1037 (int)(in_y2 - in_y1),
1043 get_canvas()->clear_box(0,
1045 get_canvas()->get_w(),
1046 get_canvas()->get_h());
1050 get_canvas()->flash(flush);
1052 //printf("CWindowCanvas::draw_refresh 10\n");
1055 #define CROPHANDLE_W 10
1056 #define CROPHANDLE_H 10
1058 void CWindowCanvas::draw_crophandle(int x, int y)
1060 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1068 #define CONTROL_W 10
1069 #define CONTROL_H 10
1070 #define FIRST_CONTROL_W 20
1071 #define FIRST_CONTROL_H 20
1073 #define BC_INFINITY 65536
1075 #define RULERHANDLE_W 16
1076 #define RULERHANDLE_H 16
1080 int CWindowCanvas::do_ruler(int draw,
1086 float x1 = mwindow->edl->session->ruler_x1;
1087 float y1 = mwindow->edl->session->ruler_y1;
1088 float x2 = mwindow->edl->session->ruler_x2;
1089 float y2 = mwindow->edl->session->ruler_y2;
1090 float canvas_x1 = x1;
1091 float canvas_y1 = y1;
1092 float canvas_x2 = x2;
1093 float canvas_y2 = y2;
1094 float output_x = get_cursor_x();
1095 float output_y = get_cursor_y();
1096 float canvas_cursor_x = output_x;
1097 float canvas_cursor_y = output_y;
1099 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1100 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1101 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1102 mwindow->session->cwindow_output_x = roundf(output_x);
1103 mwindow->session->cwindow_output_y = roundf(output_y);
1105 if(button_press && get_buttonpress() == 1)
1107 gui->ruler_handle = -1;
1108 gui->ruler_translate = 0;
1111 gui->ruler_translate = 1;
1112 gui->ruler_origin_x = x1;
1113 gui->ruler_origin_y = y1;
1116 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1117 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1118 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1119 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1121 gui->ruler_handle = 0;
1122 gui->ruler_origin_x = x1;
1123 gui->ruler_origin_y = y1;
1126 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1127 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1128 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1129 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1131 gui->ruler_handle = 1;
1132 gui->ruler_origin_x = x2;
1133 gui->ruler_origin_y = y2;
1137 // Start new selection
1138 if(!gui->ruler_translate &&
1139 (gui->ruler_handle < 0 ||
1144 do_ruler(1, 0, 0, 0);
1145 get_canvas()->flash();
1146 gui->ruler_handle = 1;
1147 mwindow->edl->session->ruler_x1 = output_x;
1148 mwindow->edl->session->ruler_y1 = output_y;
1149 mwindow->edl->session->ruler_x2 = output_x;
1150 mwindow->edl->session->ruler_y2 = output_y;
1151 gui->ruler_origin_x = mwindow->edl->session->ruler_x2;
1152 gui->ruler_origin_y = mwindow->edl->session->ruler_y2;
1155 gui->x_origin = output_x;
1156 gui->y_origin = output_y;
1157 gui->current_operation = CWINDOW_RULER;
1158 gui->tool_panel->raise_window();
1164 if(gui->current_operation == CWINDOW_RULER)
1166 if(gui->ruler_translate)
1169 do_ruler(1, 0, 0, 0);
1170 float x_difference = mwindow->edl->session->ruler_x1;
1171 float y_difference = mwindow->edl->session->ruler_y1;
1172 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1173 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1174 x_difference -= mwindow->edl->session->ruler_x1;
1175 y_difference -= mwindow->edl->session->ruler_y1;
1176 mwindow->edl->session->ruler_x2 -= x_difference;
1177 mwindow->edl->session->ruler_y2 -= y_difference;
1179 do_ruler(1, 0, 0, 0);
1180 get_canvas()->flash();
1184 switch(gui->ruler_handle)
1187 do_ruler(1, 0, 0, 0);
1188 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1189 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1190 if(gui->alt_down() || gui->ctrl_down())
1192 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1193 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1197 double distance_value =
1198 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1199 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1200 if(angle_value < 22)
1201 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2;
1203 if(angle_value > 67)
1204 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2;
1206 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 &&
1207 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1209 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1210 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1213 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 && mwindow->edl->session->ruler_y1 > mwindow->edl->session->ruler_y2)
1215 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1216 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1219 if(mwindow->edl->session->ruler_x1 > mwindow->edl->session->ruler_x2 &&
1220 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1222 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1223 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1227 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1228 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1231 do_ruler(1, 0, 0, 0);
1232 get_canvas()->flash();
1237 do_ruler(1, 0, 0, 0);
1238 mwindow->edl->session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1239 mwindow->edl->session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1240 if(gui->alt_down() || gui->ctrl_down())
1242 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1243 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1247 double distance_value =
1248 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1249 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1250 if(angle_value < 22)
1251 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1;
1253 if(angle_value > 67)
1254 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1;
1256 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1257 mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1259 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1260 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1263 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1264 mwindow->edl->session->ruler_y2 > mwindow->edl->session->ruler_y1)
1266 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1267 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1270 if(mwindow->edl->session->ruler_x2 > mwindow->edl->session->ruler_x1 && mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1272 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1273 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1277 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1278 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1281 do_ruler(1, 0, 0, 0);
1282 get_canvas()->flash();
1286 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1290 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1295 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1296 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1297 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1298 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1300 set_cursor(UPRIGHT_ARROW_CURSOR);
1303 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1304 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1305 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1306 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1308 set_cursor(UPRIGHT_ARROW_CURSOR);
1311 set_cursor(CROSS_CURSOR);
1313 // Update current position
1318 // Assume no ruler measurement if 0 length
1319 if(draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)))
1321 get_canvas()->set_inverse();
1322 get_canvas()->set_color(WHITE);
1323 get_canvas()->draw_line((int)canvas_x1,
1327 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1329 roundf(canvas_x1) + RULERHANDLE_W / 2,
1331 get_canvas()->draw_line(roundf(canvas_x1),
1332 roundf(canvas_y1) - RULERHANDLE_H / 2,
1334 roundf(canvas_y1) + RULERHANDLE_H / 2);
1335 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1337 roundf(canvas_x2) + RULERHANDLE_W / 2,
1339 get_canvas()->draw_line(roundf(canvas_x2),
1340 roundf(canvas_y2) - RULERHANDLE_H / 2,
1342 roundf(canvas_y2) + RULERHANDLE_H / 2);
1343 get_canvas()->set_opaque();
1350 static inline double line_dist(float cx,float cy, float tx,float ty)
1352 double dx = tx-cx, dy = ty-cy;
1353 return sqrt(dx*dx + dy*dy);
1356 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1358 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1359 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1363 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1364 int button_press, int cursor_motion, int draw)
1366 // Retrieve points from top recordable track
1367 //printf("CWindowCanvas::do_mask 1\n");
1368 Track *track = gui->cwindow->calculate_affected_track();
1369 //printf("CWindowCanvas::do_mask 2\n");
1371 if(!track) return 0;
1372 //printf("CWindowCanvas::do_mask 3\n");
1374 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1375 int64_t position = track->to_units(
1376 mwindow->edl->local_session->get_selectionstart(1),
1378 ArrayList<MaskPoint*> points;
1380 // Determine the points based on whether
1381 // new keyframes will be generated or drawing is performed.
1382 // If keyframe generation occurs, use the interpolated mask.
1383 // If no keyframe generation occurs, use the previous mask.
1384 int use_interpolated = 0;
1385 if(button_press || cursor_motion) {
1386 #ifdef USE_KEYFRAME_SPANNING
1387 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1388 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1391 mask_autos->get_prev_auto(track->to_units(selection_start, 0),
1392 PLAY_FORWARD, first, 1);
1394 mask_autos->get_prev_auto(track->to_units(selection_end, 0),
1395 PLAY_FORWARD, last, 1);
1397 if(last == first && (!mwindow->edl->session->auto_keyframes))
1398 use_interpolated = 0;
1400 // If keyframe spanning occurs, use the interpolated points.
1401 // If new keyframe is generated, use the interpolated points.
1402 use_interpolated = 1;
1405 if(mwindow->edl->session->auto_keyframes)
1406 use_interpolated = 1;
1410 use_interpolated = 1;
1412 if(use_interpolated) {
1413 // Interpolate the points to get exactly what is being rendered at this position.
1414 mask_autos->get_points(&points,
1415 mwindow->edl->session->cwindow_mask,
1420 // Use the prev mask
1422 mask_autos->get_prev_auto(position,
1426 ((MaskAuto*)prev)->get_points(&points,
1427 mwindow->edl->session->cwindow_mask);
1430 // Projector zooms relative to the center of the track output.
1431 float half_track_w = (float)track->track_w / 2;
1432 float half_track_h = (float)track->track_h / 2;
1433 // Translate mask to projection
1434 float projector_x, projector_y, projector_z;
1435 track->automation->get_projector(
1436 &projector_x, &projector_y, &projector_z,
1437 position, PLAY_FORWARD);
1440 // Get position of cursor relative to mask
1441 float cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
1442 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1443 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1445 projector_x += mwindow->edl->session->output_w / 2;
1446 projector_y += mwindow->edl->session->output_h / 2;
1447 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1448 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1450 // Fix cursor origin
1452 gui->x_origin = mask_cursor_x;
1453 gui->y_origin = mask_cursor_y;
1457 // Points of closest line
1458 int shortest_point1 = -1;
1459 int shortest_point2 = -1;
1461 int shortest_point = -1;
1462 // Distance to closest line
1463 float shortest_line_distance = BC_INFINITY;
1464 // Distance to closest point
1465 float shortest_point_distance = BC_INFINITY;
1466 int selected_point = -1;
1467 int selected_control_point = -1;
1468 float selected_control_point_distance = BC_INFINITY;
1469 ArrayList<int> x_points;
1470 ArrayList<int> y_points;
1472 if(!cursor_motion) {
1474 get_canvas()->set_color(WHITE);
1475 get_canvas()->set_inverse();
1477 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1479 // Never draw closed polygon and a closed
1480 // polygon is harder to add points to.
1481 for(int i = 0; i < points.size() && !result; i++) {
1482 MaskPoint *point1 = points.get(i);
1483 MaskPoint *point2 = (i >= points.size() - 1) ?
1484 points.get(0) : points.get(i + 1);
1486 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1487 if(point_distance1 < shortest_point_distance || shortest_point < 0) {
1488 shortest_point_distance = point_distance1;
1492 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1493 if(point_distance2 < shortest_point_distance || shortest_point < 0) {
1494 shortest_point_distance = point_distance2;
1495 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1499 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1501 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1502 //point1->x, point1->y, point2->x, point2->y, projector_z);
1503 for(int j = 0; j <= segments && !result; j++) {
1504 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1505 float x0 = point1->x, y0 = point1->y;
1506 float x1 = point1->x + point1->control_x2;
1507 float y1 = point1->y + point1->control_y2;
1508 float x2 = point2->x + point2->control_x1;
1509 float y2 = point2->y + point2->control_y1;
1510 float x3 = point2->x, y3 = point2->y;
1511 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1512 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1513 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1514 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1515 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1516 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1517 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1518 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1520 float t = (float)j / segments;
1521 float tpow2 = t * t;
1522 float tpow3 = t * t * t;
1524 float invtpow2 = invt * invt;
1525 float invtpow3 = invt * invt * invt;
1527 float x = ( invtpow3 * x0
1528 + 3 * t * invtpow2 * x1
1529 + 3 * tpow2 * invt * x2
1531 float y = ( invtpow3 * y0
1532 + 3 * t * invtpow2 * y1
1533 + 3 * tpow2 * invt * y2
1535 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1536 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1537 // Test new point addition
1539 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1541 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1542 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1543 if(line_distance < shortest_line_distance ||
1544 shortest_point1 < 0) {
1545 shortest_line_distance = line_distance;
1546 shortest_point1 = i;
1547 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1548 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1549 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1552 // Test existing point selection
1554 if(gui->ctrl_down()) {
1555 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1557 if(distance < selected_control_point_distance) {
1559 selected_control_point = 1;
1560 selected_control_point_distance = distance;
1564 if(!gui->shift_down()) {
1565 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1566 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
1571 selected_point = shortest_point;
1574 // Test second point
1575 if(gui->ctrl_down()) {
1576 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1578 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1579 if(distance < selected_control_point_distance) {
1580 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1581 selected_control_point = 0;
1582 selected_control_point_distance = distance;
1585 else if(i < points.size() - 1) {
1586 if(!gui->shift_down()) {
1587 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1588 if(test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3)) {
1589 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1593 selected_point = shortest_point;
1598 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1602 if(draw) { // Draw joining line
1603 x_points.append((int)canvas_x);
1604 y_points.append((int)canvas_y);
1608 if(draw) { // Draw second anchor
1609 if(i < points.size() - 1) {
1610 if(i == gui->affected_point - 1)
1611 get_canvas()->draw_disc(
1612 (int)canvas_x - CONTROL_W / 2,
1613 (int)canvas_y - CONTROL_W / 2,
1614 CONTROL_W, CONTROL_H);
1616 get_canvas()->draw_circle(
1617 (int)canvas_x - CONTROL_W / 2,
1618 (int)canvas_y - CONTROL_W / 2,
1619 CONTROL_W, CONTROL_H);
1620 // char string[BCTEXTLEN];
1621 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1622 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1624 // Draw second control point.
1625 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1626 get_canvas()->draw_line(
1627 (int)canvas_x, (int)canvas_y,
1628 (int)canvas_x2, (int)canvas_y2);
1629 get_canvas()->draw_rectangle(
1630 (int)canvas_x2 - CONTROL_W / 2,
1631 (int)canvas_y2 - CONTROL_H / 2,
1632 CONTROL_W, CONTROL_H);
1637 // Draw first anchor
1638 if(i == 0 && draw) {
1639 char mask_label[BCSTRLEN];
1640 sprintf(mask_label, "%d",
1641 mwindow->edl->session->cwindow_mask);
1642 get_canvas()->draw_text(
1643 (int)canvas_x - FIRST_CONTROL_W,
1644 (int)canvas_y - FIRST_CONTROL_H,
1647 get_canvas()->draw_disc(
1648 (int)canvas_x - FIRST_CONTROL_W / 2,
1649 (int)canvas_y - FIRST_CONTROL_H / 2,
1650 FIRST_CONTROL_W, FIRST_CONTROL_H);
1653 // Draw first control point.
1655 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1656 get_canvas()->draw_line(
1657 (int)canvas_x, (int)canvas_y,
1658 (int)canvas_x1, (int)canvas_y1);
1659 get_canvas()->draw_rectangle(
1660 (int)canvas_x1 - CONTROL_W / 2,
1661 (int)canvas_y1 - CONTROL_H / 2,
1662 CONTROL_W, CONTROL_H);
1664 x_points.append((int)canvas_x);
1665 y_points.append((int)canvas_y);
1668 //printf("CWindowCanvas::do_mask 1\n");
1672 //printf("CWindowCanvas::do_mask 1\n");
1675 get_canvas()->draw_polygon(&x_points, &y_points);
1676 get_canvas()->set_opaque();
1678 //printf("CWindowCanvas::do_mask 1\n");
1681 if(button_press && !result) {
1682 gui->affected_track = gui->cwindow->calculate_affected_track();
1684 // Get keyframe outside the EDL to edit. This must be rendered
1685 // instead of the EDL keyframes when it exists. Then it must be
1686 // applied to the EDL keyframes on buttonrelease.
1687 if(gui->affected_track) {
1688 #ifdef USE_KEYFRAME_SPANNING
1689 // Make copy of current parameters in local keyframe
1690 gui->mask_keyframe =
1691 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1694 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1697 gui->mask_keyframe =
1698 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1703 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1706 // Translate entire keyframe
1707 if(gui->alt_down() && mask->points.size()) {
1708 mwindow->undo->update_undo_before(_("mask translate"), 0);
1709 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1710 gui->affected_point = 0;
1713 // Existing point or control point was selected
1714 if(selected_point >= 0) {
1715 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1716 gui->affected_point = selected_point;
1718 if(selected_control_point == 0)
1719 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1721 if(selected_control_point == 1)
1722 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1724 gui->current_operation = mwindow->edl->session->cwindow_operation;
1726 else // No existing point or control point was selected so create a new one
1727 if(!gui->ctrl_down() && !gui->alt_down()) {
1728 mwindow->undo->update_undo_before(_("mask point"), 0);
1729 // Create the template
1730 MaskPoint *point = new MaskPoint;
1731 point->x = mask_cursor_x;
1732 point->y = mask_cursor_y;
1733 point->control_x1 = 0;
1734 point->control_y1 = 0;
1735 point->control_x2 = 0;
1736 point->control_y2 = 0;
1739 if(shortest_point2 < shortest_point1) {
1740 shortest_point2 ^= shortest_point1;
1741 shortest_point1 ^= shortest_point2;
1742 shortest_point2 ^= shortest_point1;
1747 // printf("CWindowGUI::do_mask 40\n");
1748 // mwindow->edl->dump();
1749 // printf("CWindowGUI::do_mask 50\n");
1753 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1754 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1755 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1757 // Append to end of list
1758 if( shortest_point1 == shortest_point2 ||
1759 labs(shortest_point1 - shortest_point2) > 1) {
1760 #ifdef USE_KEYFRAME_SPANNING
1762 MaskPoint *new_point = new MaskPoint;
1763 points.append(new_point);
1764 *new_point = *point;
1765 gui->affected_point = points.size() - 1;
1769 // Need to apply the new point to every keyframe
1770 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1771 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1772 MaskPoint *new_point = new MaskPoint;
1773 submask->points.append(new_point);
1774 *new_point = *point;
1775 if(current == (MaskAuto*)mask_autos->default_auto)
1776 current = (MaskAuto*)mask_autos->first;
1778 current = (MaskAuto*)NEXT;
1780 gui->affected_point = mask->points.size() - 1;
1786 // Insert between 2 points, shifting back point 2
1787 if(shortest_point1 >= 0 && shortest_point2 >= 0) {
1789 #ifdef USE_KEYFRAME_SPANNING
1790 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1792 if(points.size() >= shortest_point2) {
1793 MaskPoint *new_point = new MaskPoint;
1795 for(int i = points.size() - 1;
1796 i > shortest_point2;
1798 points.values[i] = points.values[i - 1];
1799 points.values[shortest_point2] = new_point;
1801 *new_point = *point;
1806 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1807 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1808 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1810 if(submask->points.size() >= shortest_point2) {
1811 MaskPoint *new_point = new MaskPoint;
1812 submask->points.append(0);
1813 for(int i = submask->points.size() - 1;
1814 i > shortest_point2;
1816 submask->points.values[i] = submask->points.values[i - 1];
1817 submask->points.values[shortest_point2] = new_point;
1819 *new_point = *point;
1822 if(current == (MaskAuto*)mask_autos->default_auto)
1823 current = (MaskAuto*)mask_autos->first;
1825 current = (MaskAuto*)NEXT;
1829 gui->affected_point = shortest_point2;
1834 // printf("CWindowGUI::do_mask 20\n");
1835 // mwindow->edl->dump();
1836 // printf("CWindowGUI::do_mask 30\n");
1839 //printf("CWindowCanvas::do_mask 1\n");
1840 // Create the first point.
1841 #ifdef USE_KEYFRAME_SPANNING
1842 MaskPoint *new_point = new MaskPoint;
1843 points.append(new_point);
1844 *new_point = *point;
1845 gui->affected_point = points.size() - 1;
1847 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1848 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1849 MaskPoint *new_point = new MaskPoint;
1850 submask->points.append(new_point);
1851 *new_point = *point;
1852 if(current == (MaskAuto*)mask_autos->default_auto)
1853 current = (MaskAuto*)mask_autos->first;
1855 current = (MaskAuto*)NEXT;
1857 gui->affected_point = points.size() - 1;
1860 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
1863 gui->current_operation = mwindow->edl->session->cwindow_operation;
1864 // Delete the template
1873 if(button_press && result) {
1874 #ifdef USE_KEYFRAME_SPANNING
1875 MaskPoint *point = points.values[gui->affected_point];
1876 gui->center_x = point->x;
1877 gui->center_y = point->y;
1878 gui->control_in_x = point->control_x1;
1879 gui->control_in_y = point->control_y1;
1880 gui->control_out_x = point->control_x2;
1881 gui->control_out_y = point->control_y2;
1882 gui->tool_panel->raise_window();
1884 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1885 MaskPoint *point = mask->points.values[gui->affected_point];
1886 gui->center_x = point->x;
1887 gui->center_y = point->y;
1888 gui->control_in_x = point->control_x1;
1889 gui->control_in_y = point->control_y1;
1890 gui->control_out_x = point->control_x2;
1891 gui->control_out_y = point->control_y2;
1892 gui->tool_panel->raise_window();
1896 //printf("CWindowCanvas::do_mask 8\n");
1899 #ifdef USE_KEYFRAME_SPANNING
1900 // Must update the reference keyframes for every cursor motion
1901 gui->mask_keyframe =
1902 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1905 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1908 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1910 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1911 if( gui->affected_point >= 0 && gui->affected_point < mask->points.size() &&
1912 gui->current_operation != CWINDOW_NONE) {
1913 // mwindow->undo->update_undo_before(_("mask point"), this);
1914 #ifdef USE_KEYFRAME_SPANNING
1915 MaskPoint *point = points.get(gui->affected_point);
1917 MaskPoint *point = mask->points.get(gui->affected_point);
1919 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
1920 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask->points.size(), gui->affected_point);
1922 float last_x = point->x;
1923 float last_y = point->y;
1924 float last_control_x1 = point->control_x1;
1925 float last_control_y1 = point->control_y1;
1926 float last_control_x2 = point->control_x2;
1927 float last_control_y2 = point->control_y2;
1929 switch(gui->current_operation) {
1931 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1932 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
1933 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
1936 case CWINDOW_MASK_CONTROL_IN:
1937 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
1938 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
1941 case CWINDOW_MASK_CONTROL_OUT:
1942 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
1943 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
1946 case CWINDOW_MASK_TRANSLATE:
1947 #ifdef USE_KEYFRAME_SPANNING
1948 for(int i = 0; i < points.size(); i++) {
1949 points.values[i]->x += mask_cursor_x - gui->x_origin;
1950 points.values[i]->y += mask_cursor_y - gui->y_origin;
1953 for(int i = 0; i < mask->points.size(); i++) {
1954 mask->points.values[i]->x += mask_cursor_x - gui->x_origin;
1955 mask->points.values[i]->y += mask_cursor_y - gui->y_origin;
1958 gui->x_origin = mask_cursor_x;
1959 gui->y_origin = mask_cursor_y;
1963 if( !EQUIV(last_x, point->x) ||
1964 !EQUIV(last_y, point->y) ||
1965 !EQUIV(last_control_x1, point->control_x1) ||
1966 !EQUIV(last_control_y1, point->control_y1) ||
1967 !EQUIV(last_control_x2, point->control_x2) ||
1968 !EQUIV(last_control_y2, point->control_y2)) {
1974 if(gui->current_operation == CWINDOW_NONE) {
1975 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
1977 for(int i = 0; i < points.size() && !over_point; i++) {
1978 MaskPoint *point = points.get(i);
1979 float x0 = point->x;
1980 float y0 = point->y;
1981 float x1 = point->x + point->control_x1;
1982 float y1 = point->y + point->control_y1;
1983 float x2 = point->x + point->control_x2;
1984 float y2 = point->y + point->control_y2;
1985 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1986 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1988 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1989 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
1993 if(!over_point && gui->ctrl_down()) {
1994 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1995 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1996 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1997 if(test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1)) {
2001 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2002 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2003 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2004 if(test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2)) {
2011 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2016 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2019 #ifdef USE_KEYFRAME_SPANNING
2020 // Must commit change after operation.
2021 if(rerender && track) {
2022 // Swap EDL keyframe with original.
2023 // Apply new values to keyframe span
2024 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2025 temp_keyframe.copy_data(gui->mask_keyframe);
2026 // Apply interpolated points back to keyframe
2027 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2028 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2029 mask_autos->update_parameter(&temp_keyframe);
2033 points.remove_all_objects();
2034 //printf("CWindowCanvas::do_mask 20\n");
2038 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2041 int radius = mwindow->edl->session->eyedrop_radius;
2049 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2054 row1 = gui->eyedrop_y - radius;
2055 row2 = gui->eyedrop_y + radius;
2056 column1 = gui->eyedrop_x - radius;
2057 column2 = gui->eyedrop_x + radius;
2059 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2060 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2061 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2062 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2064 if(row2 <= row1) row2 = row1 + 1;
2065 if(column2 <= column1) column2 = column1 + 1;
2072 output_to_canvas(mwindow->edl, 0, x1, y1);
2073 output_to_canvas(mwindow->edl, 0, x2, y2);
2074 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2076 if(x2 - x1 >= 1 && y2 - y1 >= 1)
2078 get_canvas()->set_inverse();
2079 get_canvas()->set_color(WHITE);
2081 get_canvas()->draw_rectangle((int)x1,
2086 get_canvas()->set_opaque();
2087 get_canvas()->flash();
2095 gui->current_operation = CWINDOW_EYEDROP;
2096 gui->tool_panel->raise_window();
2099 if(gui->current_operation == CWINDOW_EYEDROP)
2101 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2103 // Get color out of frame.
2104 // Doesn't work during playback because that bypasses the refresh frame.
2105 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2107 float cursor_x = get_cursor_x();
2108 float cursor_y = get_cursor_y();
2109 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2110 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2111 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2113 row1 = cursor_y - radius;
2114 row2 = cursor_y + radius;
2115 column1 = cursor_x - radius;
2116 column2 = cursor_x + radius;
2117 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2118 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2119 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2120 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2121 if(row2 <= row1) row2 = row1 + 1;
2122 if(column2 <= column1) column2 = column1 + 1;
2126 if(gui->eyedrop_visible)
2129 do_eyedrop(temp, 0, 1);
2130 gui->eyedrop_visible = 0;
2133 gui->eyedrop_x = cursor_x;
2134 gui->eyedrop_y = cursor_y;
2139 do_eyedrop(temp, 0, 1);
2140 gui->eyedrop_visible = 1;
2143 // Decompression coefficients straight out of jpeglib
2144 #define V_TO_R 1.40200
2145 #define V_TO_G -0.71414
2147 #define U_TO_G -0.34414
2148 #define U_TO_B 1.77200
2150 #define GET_COLOR(type, components, max, do_yuv) \
2152 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2154 float red = (float)*row++ / max; \
2155 float green = (float)*row++ / max; \
2156 float blue = (float)*row++ / max; \
2159 mwindow->edl->local_session->red += red + V_TO_R * (blue - 0.5); \
2160 mwindow->edl->local_session->green += red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
2161 mwindow->edl->local_session->blue += red + U_TO_B * (green - 0.5); \
2165 mwindow->edl->local_session->red += red; \
2166 mwindow->edl->local_session->green += green; \
2167 mwindow->edl->local_session->blue += blue; \
2173 mwindow->edl->local_session->red = 0;
2174 mwindow->edl->local_session->green = 0;
2175 mwindow->edl->local_session->blue = 0;
2176 for(int i = row1; i < row2; i++)
2178 for(int j = column1; j < column2; j++)
2180 switch(refresh_frame->get_color_model())
2183 GET_COLOR(unsigned char, 3, 0xff, 1);
2186 GET_COLOR(unsigned char, 4, 0xff, 1);
2189 GET_COLOR(uint16_t, 3, 0xffff, 1);
2191 case BC_YUVA16161616:
2192 GET_COLOR(uint16_t, 4, 0xffff, 1);
2195 GET_COLOR(unsigned char, 3, 0xff, 0);
2198 GET_COLOR(unsigned char, 4, 0xff, 0);
2201 GET_COLOR(float, 3, 1.0, 0);
2204 GET_COLOR(float, 4, 1.0, 0);
2210 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2211 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2212 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2217 mwindow->edl->local_session->red = 0;
2218 mwindow->edl->local_session->green = 0;
2219 mwindow->edl->local_session->blue = 0;
2220 gui->eyedrop_visible = 0;
2229 // Can't rerender since the color value is from the output of any effect it
2232 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2238 void CWindowCanvas::draw_overlays()
2240 if(mwindow->edl->session->safe_regions)
2242 draw_safe_regions();
2245 if(mwindow->edl->session->cwindow_scrollbars)
2247 // Always draw output rectangle
2248 float x1, y1, x2, y2;
2250 x2 = mwindow->edl->session->output_w;
2252 y2 = mwindow->edl->session->output_h;
2253 output_to_canvas(mwindow->edl, 0, x1, y1);
2254 output_to_canvas(mwindow->edl, 0, x2, y2);
2256 get_canvas()->set_inverse();
2257 get_canvas()->set_color(WHITE);
2259 get_canvas()->draw_rectangle((int)x1,
2264 get_canvas()->set_opaque();
2267 if(gui->highlighted)
2269 get_canvas()->set_color(WHITE);
2270 get_canvas()->set_inverse();
2271 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2272 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2273 get_canvas()->set_opaque();
2276 int temp1 = 0, temp2 = 0;
2277 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2278 switch(mwindow->edl->session->cwindow_operation)
2280 case CWINDOW_CAMERA:
2284 case CWINDOW_PROJECTOR:
2293 do_mask(temp1, temp2, 0, 0, 1);
2297 do_ruler(1, 0, 0, 0);
2300 case CWINDOW_EYEDROP:
2301 if(gui->eyedrop_visible)
2304 do_eyedrop(rerender, 0, 1);
2305 gui->eyedrop_visible = 1;
2311 void CWindowCanvas::draw_safe_regions()
2313 float action_x1, action_x2, action_y1, action_y2;
2314 float title_x1, title_x2, title_y1, title_y2;
2316 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2317 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2318 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2319 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2320 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2321 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2322 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2323 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2325 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2326 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2327 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2328 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2330 get_canvas()->set_inverse();
2331 get_canvas()->set_color(WHITE);
2333 get_canvas()->draw_rectangle((int)action_x1,
2335 (int)(action_x2 - action_x1),
2336 (int)(action_y2 - action_y1));
2337 get_canvas()->draw_rectangle((int)title_x1,
2339 (int)(title_x2 - title_x1),
2340 (int)(title_y2 - title_y1));
2342 get_canvas()->set_opaque();
2345 void CWindowCanvas::reset_keyframe(int do_camera)
2347 FloatAuto *x_keyframe = 0;
2348 FloatAuto *y_keyframe = 0;
2349 FloatAuto *z_keyframe = 0;
2350 Track *affected_track = 0;
2352 affected_track = gui->cwindow->calculate_affected_track();
2356 gui->cwindow->calculate_affected_autos(&x_keyframe,
2365 x_keyframe->set_value(0);
2366 y_keyframe->set_value(0);
2367 z_keyframe->set_value(1);
2369 mwindow->sync_parameters(CHANGE_PARAMS);
2374 void CWindowCanvas::reset_camera()
2379 void CWindowCanvas::reset_projector()
2384 int CWindowCanvas::test_crop(int button_press, int &redraw)
2387 int handle_selected = -1;
2388 float x1 = mwindow->edl->session->crop_x1;
2389 float y1 = mwindow->edl->session->crop_y1;
2390 float x2 = mwindow->edl->session->crop_x2;
2391 float y2 = mwindow->edl->session->crop_y2;
2392 float cursor_x = get_cursor_x();
2393 float cursor_y = get_cursor_y();
2394 float canvas_x1 = x1;
2395 float canvas_y1 = y1;
2396 float canvas_x2 = x2;
2397 float canvas_y2 = y2;
2398 float canvas_cursor_x = cursor_x;
2399 float canvas_cursor_y = cursor_y;
2401 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2402 // Use screen normalized coordinates for hot spot tests.
2403 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2404 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2407 if(gui->current_operation == CWINDOW_CROP)
2409 handle_selected = gui->crop_handle;
2412 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2413 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2415 handle_selected = 0;
2416 gui->crop_origin_x = x1;
2417 gui->crop_origin_y = y1;
2420 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2421 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2423 handle_selected = 1;
2424 gui->crop_origin_x = x2;
2425 gui->crop_origin_y = y1;
2428 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2429 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2431 handle_selected = 2;
2432 gui->crop_origin_x = x1;
2433 gui->crop_origin_y = y2;
2436 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2437 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2439 handle_selected = 3;
2440 gui->crop_origin_x = x2;
2441 gui->crop_origin_y = y2;
2446 gui->crop_origin_x = cursor_x;
2447 gui->crop_origin_y = cursor_y;
2450 // printf("test crop %d %d\n",
2451 // gui->current_operation,
2452 // handle_selected);
2459 gui->crop_translate = 1;
2460 gui->crop_origin_x1 = x1;
2461 gui->crop_origin_y1 = y1;
2462 gui->crop_origin_x2 = x2;
2463 gui->crop_origin_y2 = y2;
2466 gui->crop_translate = 0;
2468 gui->current_operation = CWINDOW_CROP;
2469 gui->crop_handle = handle_selected;
2470 gui->x_origin = cursor_x;
2471 gui->y_origin = cursor_y;
2472 gui->tool_panel->raise_window();
2475 if(handle_selected < 0 && !gui->crop_translate)
2479 mwindow->edl->session->crop_x1 = (int)x1;
2480 mwindow->edl->session->crop_y1 = (int)y1;
2481 mwindow->edl->session->crop_x2 = (int)x2;
2482 mwindow->edl->session->crop_y2 = (int)y2;
2487 // Translate all 4 points
2488 if(gui->current_operation == CWINDOW_CROP && gui->crop_translate)
2490 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2491 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2492 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2493 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2495 mwindow->edl->session->crop_x1 = (int)x1;
2496 mwindow->edl->session->crop_y1 = (int)y1;
2497 mwindow->edl->session->crop_x2 = (int)x2;
2498 mwindow->edl->session->crop_y2 = (int)y2;
2504 if(gui->current_operation == CWINDOW_CROP)
2506 switch(gui->crop_handle)
2509 x1 = gui->crop_origin_x;
2510 y1 = gui->crop_origin_y;
2511 x2 = gui->crop_origin_x;
2512 y2 = gui->crop_origin_y;
2513 if(cursor_x < gui->x_origin)
2515 if(cursor_y < gui->y_origin)
2521 if(cursor_y >= gui->y_origin)
2528 if(cursor_x >= gui->x_origin)
2530 if(cursor_y < gui->y_origin)
2536 if(cursor_y >= gui->y_origin)
2543 // printf("test crop %d %d %d %d\n",
2544 // mwindow->edl->session->crop_x1,
2545 // mwindow->edl->session->crop_y1,
2546 // mwindow->edl->session->crop_x2,
2547 // mwindow->edl->session->crop_y2);
2550 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2551 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2554 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2555 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2558 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2559 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2562 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2563 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2567 if(!EQUIV(mwindow->edl->session->crop_x1, x1) ||
2568 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2569 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2570 !EQUIV(mwindow->edl->session->crop_y2, y2))
2577 switch (gui->crop_handle)
2579 case 0: gui->crop_handle = 1; break;
2580 case 1: gui->crop_handle = 0; break;
2581 case 2: gui->crop_handle = 3; break;
2582 case 3: gui->crop_handle = 2; break;
2592 switch (gui->crop_handle)
2594 case 0: gui->crop_handle = 2; break;
2595 case 1: gui->crop_handle = 3; break;
2596 case 2: gui->crop_handle = 0; break;
2597 case 3: gui->crop_handle = 1; break;
2602 mwindow->edl->session->crop_x1 = (int)x1;
2603 mwindow->edl->session->crop_y1 = (int)y1;
2604 mwindow->edl->session->crop_x2 = (int)x2;
2605 mwindow->edl->session->crop_y2 = (int)y2;
2611 // Update cursor font
2612 if(handle_selected >= 0)
2614 switch(handle_selected)
2617 set_cursor(UPLEFT_RESIZE);
2620 set_cursor(UPRIGHT_RESIZE);
2623 set_cursor(DOWNLEFT_RESIZE);
2626 set_cursor(DOWNRIGHT_RESIZE);
2633 set_cursor(ARROW_CURSOR);
2635 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2639 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2640 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2641 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2642 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2643 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2644 // mwindow->edl->session->crop_x2,
2645 // mwindow->edl->session->crop_y2,
2646 // mwindow->edl->calculate_output_w(0),
2647 // mwindow->edl->calculate_output_h(0));
2653 void CWindowCanvas::draw_crop()
2655 get_canvas()->set_inverse();
2656 get_canvas()->set_color(WHITE);
2658 float x1 = mwindow->edl->session->crop_x1;
2659 float y1 = mwindow->edl->session->crop_y1;
2660 float x2 = mwindow->edl->session->crop_x2;
2661 float y2 = mwindow->edl->session->crop_y2;
2663 output_to_canvas(mwindow->edl, 0, x1, y1);
2664 output_to_canvas(mwindow->edl, 0, x2, y2);
2666 if(x2 - x1 && y2 - y1)
2667 get_canvas()->draw_rectangle((int)x1,
2672 draw_crophandle((int)x1, (int)y1);
2673 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2674 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2675 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2676 get_canvas()->set_opaque();
2686 void CWindowCanvas::draw_bezier(int do_camera)
2688 Track *track = gui->cwindow->calculate_affected_track();
2695 int64_t position = track->to_units(
2696 mwindow->edl->local_session->get_selectionstart(1),
2699 track->automation->get_projector(¢er_x,
2705 // center_x += track->track_w / 2;
2706 // center_y += track->track_h / 2;
2707 center_x += mwindow->edl->session->output_w / 2;
2708 center_y += mwindow->edl->session->output_h / 2;
2709 float track_x1 = center_x - track->track_w / 2 * center_z;
2710 float track_y1 = center_y - track->track_h / 2 * center_z;
2711 float track_x2 = track_x1 + track->track_w * center_z;
2712 float track_y2 = track_y1 + track->track_h * center_z;
2714 output_to_canvas(mwindow->edl, 0, track_x1, track_y1);
2715 output_to_canvas(mwindow->edl, 0, track_x2, track_y2);
2717 #define DRAW_PROJECTION(offset) \
2718 get_canvas()->draw_rectangle((int)track_x1 + offset, \
2719 (int)track_y1 + offset, \
2720 (int)(track_x2 - track_x1), \
2721 (int)(track_y2 - track_y1)); \
2722 get_canvas()->draw_line((int)track_x1 + offset, \
2723 (int)track_y1 + offset, \
2724 (int)track_x2 + offset, \
2725 (int)track_y2 + offset); \
2726 get_canvas()->draw_line((int)track_x2 + offset, \
2727 (int)track_y1 + offset, \
2728 (int)track_x1 + offset, \
2729 (int)track_y2 + offset); \
2733 get_canvas()->set_color(BLACK);
2736 // canvas->set_inverse();
2738 get_canvas()->set_color(GREEN);
2740 get_canvas()->set_color(RED);
2743 // canvas->set_opaque();
2747 int CWindowCanvas::test_bezier(int button_press,
2755 // Processing drag operation.
2756 // Create keyframe during first cursor motion.
2760 float cursor_x = get_cursor_x();
2761 float cursor_y = get_cursor_y();
2762 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2764 if(gui->current_operation == CWINDOW_CAMERA ||
2765 gui->current_operation == CWINDOW_PROJECTOR)
2767 if(!gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom)
2769 gui->translating_zoom = 1;
2770 gui->reset_affected();
2773 if(!gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom)
2775 gui->translating_zoom = 0;
2776 gui->reset_affected();
2779 // Get target keyframe
2780 float last_center_x;
2781 float last_center_y;
2782 float last_center_z;
2785 if(!gui->affected_x && !gui->affected_y && !gui->affected_z)
2787 FloatAutos *affected_x_autos;
2788 FloatAutos *affected_y_autos;
2789 FloatAutos *affected_z_autos;
2790 if(!gui->affected_track) return 0;
2791 double position = mwindow->edl->local_session->get_selectionstart(1);
2792 int64_t track_position = gui->affected_track->to_units(position, 0);
2794 if(mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA)
2796 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_X];
2797 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Y];
2798 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Z];
2802 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_X];
2803 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Y];
2804 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Z];
2808 if(gui->translating_zoom)
2810 FloatAuto *previous = 0;
2811 FloatAuto *next = 0;
2812 float new_z = affected_z_autos->get_value(
2818 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2819 affected_z_autos, 1, &created, 0);
2821 gui->affected_z->set_value(new_z);
2827 FloatAuto *previous = 0;
2828 FloatAuto *next = 0;
2829 float new_x = affected_x_autos->get_value(
2836 float new_y = affected_y_autos->get_value(
2842 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2843 affected_x_autos, 1, &created, 0);
2845 gui->affected_x->set_value(new_x);
2849 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2850 affected_y_autos, 1, &created, 0);
2852 gui->affected_y->set_value(new_y);
2859 if(gui->translating_zoom)
2861 gui->center_z = gui->affected_z->get_value();
2865 gui->center_x = gui->affected_x->get_value();
2866 gui->center_y = gui->affected_y->get_value();
2873 if(gui->translating_zoom)
2875 last_center_z = gui->affected_z->get_value();
2876 float z = gui->center_z + (cursor_y - gui->y_origin) / 128;
2878 if(!EQUIV(last_center_z, z))
2884 gui->affected_z->set_value(z);
2888 last_center_x = gui->affected_x->get_value();
2889 last_center_y = gui->affected_y->get_value();
2890 float x = gui->center_x + cursor_x - gui->x_origin;
2891 float y = gui->center_y + cursor_y - gui->y_origin;
2892 gui->affected_x->set_value(x);
2893 gui->affected_y->set_value(y);
2894 if( !EQUIV(last_center_x, x) || !EQUIV(last_center_y, y) )
2900 gui->affected_x->set_value(x);
2901 gui->affected_y->set_value(y);
2908 // Begin drag operation. Don't create keyframe here.
2910 // Get affected track off of the first recordable video track.
2911 // Calculating based on the alpha channel would require recording what layer
2912 // each output pixel belongs to as they're rendered and stacked. Forget it.
2913 gui->affected_track = gui->cwindow->calculate_affected_track();
2914 gui->reset_affected();
2916 if(gui->affected_track)
2918 if(gui->current_operation == CWINDOW_CAMERA)
2919 mwindow->undo->update_undo_before(_("camera"), this);
2921 mwindow->undo->update_undo_before(_("projector"), this);
2923 gui->current_operation =
2924 mwindow->edl->session->cwindow_operation;
2925 gui->tool_panel->raise_window();
2934 int CWindowCanvas::test_zoom(int &redraw)
2937 float zoom = get_zoom();
2941 if(!mwindow->edl->session->cwindow_scrollbars)
2943 mwindow->edl->session->cwindow_scrollbars = 1;
2945 x = mwindow->edl->session->output_w / 2;
2946 y = mwindow->edl->session->output_h / 2;
2947 x = x - w / zoom / 2;
2948 y = y - h / zoom / 2;
2952 // Cursor position relative to canvas
2955 // cursor position relative to output
2958 canvas_to_output(mwindow->edl,
2963 //printf("CWindowCanvas::test_zoom 1 %f %f\n", x, y);
2965 // Find current zoom in table
2966 int current_index = 0;
2967 for(current_index = 0 ; current_index < total_zooms; current_index++)
2968 if(EQUIV(my_zoom_table[current_index], zoom)) break;
2972 if(get_buttonpress() == 5 ||
2984 CLAMP(current_index, 0, total_zooms - 1);
2985 zoom = my_zoom_table[current_index];
2987 x = output_x - x / zoom;
2988 y = output_y - y / zoom;
2997 // check_boundaries(mwindow->edl, x_i, y_i, zoom);
2999 //printf("CWindowCanvas::test_zoom 2 %d %d\n", x_i, y_i);
3004 reposition_window(mwindow->edl,
3005 mwindow->theme->ccanvas_x,
3006 mwindow->theme->ccanvas_y,
3007 mwindow->theme->ccanvas_w,
3008 mwindow->theme->ccanvas_h);
3013 gui->zoom_panel->update(zoom);
3014 if( gui->mwindow->edl->session->cwindow_operation == CWINDOW_ZOOM ) {
3015 gui->composite_panel->cpanel_zoom->update(zoom);
3022 void CWindowCanvas::calculate_origin()
3024 gui->x_origin = get_cursor_x();
3025 gui->y_origin = get_cursor_y();
3026 //printf("CWindowCanvas::calculate_origin 1 %f %f\n", gui->x_origin, gui->y_origin);
3027 canvas_to_output(mwindow->edl, 0, gui->x_origin, gui->y_origin);
3028 //printf("CWindowCanvas::calculate_origin 2 %f %f\n", gui->x_origin, gui->y_origin);
3032 int CWindowCanvas::cursor_leave_event()
3034 set_cursor(ARROW_CURSOR);
3038 int CWindowCanvas::cursor_enter_event()
3041 switch(mwindow->edl->session->cwindow_operation)
3043 case CWINDOW_CAMERA:
3044 case CWINDOW_PROJECTOR:
3045 set_cursor(MOVE_CURSOR);
3048 set_cursor(MOVE_CURSOR);
3051 test_crop(0, redraw);
3053 case CWINDOW_PROTECT:
3054 set_cursor(ARROW_CURSOR);
3058 set_cursor(CROSS_CURSOR);
3060 case CWINDOW_EYEDROP:
3061 set_cursor(CROSS_CURSOR);
3067 int CWindowCanvas::cursor_motion_event()
3069 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3072 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3073 switch(gui->current_operation)
3075 case CWINDOW_SCROLL:
3077 float zoom = get_zoom();
3078 float cursor_x = get_cursor_x();
3079 float cursor_y = get_cursor_y();
3081 float zoom_x, zoom_y, conformed_w, conformed_h;
3082 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3083 cursor_x = (float)cursor_x / zoom_x + gui->x_offset;
3084 cursor_y = (float)cursor_y / zoom_y + gui->y_offset;
3088 int x = (int)(gui->x_origin - cursor_x + gui->x_offset);
3089 int y = (int)(gui->y_origin - cursor_y + gui->y_offset);
3094 update_scrollbars(0);
3101 result = do_ruler(0, 1, 0, 0);
3104 case CWINDOW_CAMERA:
3105 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3108 case CWINDOW_PROJECTOR:
3109 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3114 result = test_crop(0, redraw);
3115 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3122 case CWINDOW_MASK_CONTROL_IN:
3123 case CWINDOW_MASK_CONTROL_OUT:
3124 case CWINDOW_MASK_TRANSLATE:
3126 result = do_mask(redraw,
3133 case CWINDOW_EYEDROP:
3134 result = do_eyedrop(rerender, 0, 0);
3143 // cursor font changes
3146 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3148 // mwindow->edl->session->cwindow_operation);
3149 switch(mwindow->edl->session->cwindow_operation)
3152 result = test_crop(0, redraw);
3155 result = do_ruler(0, 1, 0, 0);
3158 result = do_mask(redraw,
3168 // If the window is never unlocked before calling send_command the
3169 // display shouldn't get stuck on the old video frame although it will
3170 // flicker between the old video frame and the new video frame.
3180 gui->unlock_window();
3183 mwindow->gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3184 mwindow->gui->draw_overlays(1);
3185 mwindow->gui->unlock_window();
3187 gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3192 gui->unlock_window();
3193 mwindow->restart_brender();
3194 mwindow->sync_parameters(CHANGE_PARAMS);
3195 gui->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
3199 if(!redraw) gui->update_tool();
3200 gui->lock_window("CWindowCanvas::cursor_motion_event 2");
3205 int CWindowCanvas::button_press_event()
3209 int redraw_canvas = 0;
3212 if(Canvas::button_press_event()) return 1;
3214 gui->translating_zoom = gui->shift_down();
3217 //printf("CWindowCanvas::button_press_event 2 %f %f\n", gui->x_origin, gui->y_origin, gui->x_origin, gui->y_origin);
3219 float zoom_x, zoom_y, conformed_w, conformed_h;
3220 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3221 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3222 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3225 if(get_buttonpress() == 2)
3227 gui->current_operation = CWINDOW_SCROLL;
3233 switch(mwindow->edl->session->cwindow_operation)
3236 result = do_ruler(0, 0, 1, 0);
3239 case CWINDOW_CAMERA:
3240 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3243 case CWINDOW_PROJECTOR:
3244 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3248 result = test_zoom(redraw);
3252 result = test_crop(1, redraw);
3256 if(get_buttonpress() == 1)
3257 result = do_mask(redraw, rerender, 1, 0, 0);
3260 case CWINDOW_EYEDROP:
3261 result = do_eyedrop(rerender, 1, 0);
3269 gui->unlock_window();
3272 mwindow->gui->lock_window("CWindowCanvas::button_press_event 1");
3273 mwindow->gui->draw_overlays(1);
3274 mwindow->gui->unlock_window();
3277 gui->lock_window("CWindowCanvas::button_press_event 1");
3280 // rerendering can also be caused by press event
3283 gui->unlock_window();
3285 mwindow->restart_brender();
3286 mwindow->sync_parameters(CHANGE_PARAMS);
3287 gui->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
3291 if(!redraw) gui->update_tool();
3292 gui->lock_window("CWindowCanvas::button_press_event 2");
3297 int CWindowCanvas::button_release_event()
3301 switch(gui->current_operation)
3303 case CWINDOW_SCROLL:
3308 do_ruler(0, 0, 0, 1);
3311 case CWINDOW_CAMERA:
3312 mwindow->undo->update_undo_after(_("camera"), LOAD_AUTOMATION);
3315 case CWINDOW_PROJECTOR:
3316 mwindow->undo->update_undo_after(_("projector"), LOAD_AUTOMATION);
3320 case CWINDOW_MASK_CONTROL_IN:
3321 case CWINDOW_MASK_CONTROL_OUT:
3322 case CWINDOW_MASK_TRANSLATE:
3323 // Finish mask operation
3324 gui->mask_keyframe = 0;
3325 mwindow->undo->update_undo_after(_("mask"), LOAD_AUTOMATION);
3328 result = Canvas::button_release_event();
3332 gui->current_operation = CWINDOW_NONE;
3336 void CWindowCanvas::zoom_resize_window(float percentage)
3338 int canvas_w, canvas_h;
3342 // Get required canvas size
3343 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3344 mwindow->edl->session->output_w,
3345 mwindow->edl->session->output_h,
3350 // Estimate window size from current borders
3351 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3352 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3354 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3355 mwindow->session->cwindow_w = new_w;
3356 mwindow->session->cwindow_h = new_h;
3358 mwindow->theme->get_cwindow_sizes(gui,
3359 mwindow->session->cwindow_controls);
3361 // Estimate again from new borders
3362 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3363 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3364 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3366 gui->resize_window(new_w, new_h);
3367 gui->resize_event(new_w, new_h);
3370 void CWindowCanvas::toggle_controls()
3372 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3373 gui->resize_event(gui->get_w(), gui->get_h());
3376 int CWindowCanvas::get_cwindow_controls()
3378 return mwindow->session->cwindow_controls;