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,
363 void CWindowGUI::zoom_canvas(int do_auto, double value, int update_menu)
366 mwindow->edl->session->cwindow_scrollbars = 0;
368 mwindow->edl->session->cwindow_scrollbars = 1;
370 float old_zoom = mwindow->edl->session->cwindow_zoom;
371 float new_zoom = value;
372 float x = canvas->w / 2.0;
373 float y = canvas->h / 2.0;
374 canvas->canvas_to_output(mwindow->edl,
378 x -= canvas->w_visible / 2 * old_zoom / new_zoom;
379 y -= canvas->h_visible / 2 * old_zoom / new_zoom;
384 zoom_panel->update(auto_zoom);
388 zoom_panel->update(value);
392 canvas->update_zoom((int)x,
395 canvas->reposition_window(mwindow->edl,
396 mwindow->theme->ccanvas_x,
397 mwindow->theme->ccanvas_y,
398 mwindow->theme->ccanvas_w,
399 mwindow->theme->ccanvas_h);
400 canvas->draw_refresh();
405 void CWindowGUI::set_operation(int value)
407 mwindow->edl->session->cwindow_operation = value;
409 composite_panel->set_operation(value);
410 edit_panel->update();
412 tool_panel->start_tool(value);
413 canvas->draw_refresh();
416 void CWindowGUI::update_tool()
418 tool_panel->update_values();
421 int CWindowGUI::close_event()
423 cwindow->hide_window();
428 int CWindowGUI::keypress_event()
432 switch(get_keypress())
450 if(mwindow->session->cwindow_fullscreen)
451 canvas->stop_fullscreen();
453 canvas->start_fullscreen();
454 lock_window("CWindowGUI::keypress_event 1");
458 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
460 mwindow->gui->unlock_window();
461 lock_window("CWindowGUI::keypress_event 2");
465 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
466 mwindow->clear_entry();
467 mwindow->gui->unlock_window();
468 lock_window("CWindowGUI::keypress_event 3");
472 if(mwindow->session->cwindow_fullscreen)
473 canvas->stop_fullscreen();
474 lock_window("CWindowGUI::keypress_event 4");
481 int shift_down = this->shift_down();
483 mwindow->gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
485 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
486 mwindow->prev_edit_handle(shift_down);
487 mwindow->gui->unlock_window();
489 lock_window("CWindowGUI::keypress_event 1");
495 mwindow->gui->lock_window("CWindowGUI::keypress_event 3");
496 mwindow->move_left();
497 mwindow->gui->unlock_window();
499 lock_window("CWindowGUI::keypress_event 2");
509 int shift_down = this->shift_down();
511 mwindow->gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
513 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
514 mwindow->next_edit_handle(shift_down);
515 mwindow->gui->unlock_window();
517 lock_window("CWindowGUI::keypress_event 2");
523 mwindow->gui->lock_window("CWindowGUI::keypress_event 4");
524 mwindow->move_right();
525 mwindow->gui->unlock_window();
527 lock_window("CWindowGUI::keypress_event 3");
534 if(!result) result = transport->keypress_event();
540 void CWindowGUI::reset_affected()
547 void CWindowGUI::keyboard_zoomin()
549 // if(mwindow->edl->session->cwindow_scrollbars)
551 zoom_panel->zoom_tumbler->handle_up_event();
558 void CWindowGUI::keyboard_zoomout()
560 // if(mwindow->edl->session->cwindow_scrollbars)
562 zoom_panel->zoom_tumbler->handle_down_event();
570 void CWindowGUI::drag_motion()
572 if(get_hidden()) return;
574 if(mwindow->session->current_operation != DRAG_ASSET &&
575 mwindow->session->current_operation != DRAG_VTRANSITION &&
576 mwindow->session->current_operation != DRAG_VEFFECT) return;
577 int need_highlight = cursor_above() && get_cursor_over_window();
578 if( highlighted == need_highlight ) return;
579 highlighted = need_highlight;
580 canvas->draw_refresh();
583 int CWindowGUI::drag_stop()
586 if(get_hidden()) return 0;
587 if( !highlighted ) return 0;
588 if( mwindow->session->current_operation != DRAG_ASSET &&
589 mwindow->session->current_operation != DRAG_VTRANSITION &&
590 mwindow->session->current_operation != DRAG_VEFFECT) return 0;
592 canvas->draw_refresh();
595 if(mwindow->session->current_operation == DRAG_ASSET)
597 if(mwindow->session->drag_assets->total ||
598 mwindow->session->drag_clips->total)
600 mwindow->gui->lock_window("CWindowGUI::drag_stop 5");
601 mwindow->undo->update_undo_before(_("insert assets"), 0);
602 mwindow->gui->unlock_window();
605 if(mwindow->session->drag_assets->total)
607 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
609 mwindow->load_assets(mwindow->session->drag_assets,
610 mwindow->edl->local_session->get_selectionstart(),
612 mwindow->session->track_highlighted,
614 mwindow->edl->session->labels_follow_edits,
615 mwindow->edl->session->plugins_follow_edits,
616 mwindow->edl->session->autos_follow_edits,
620 if(mwindow->session->drag_clips->total)
622 mwindow->gui->lock_window("CWindowGUI::drag_stop 2");
624 mwindow->paste_edls(mwindow->session->drag_clips,
626 mwindow->session->track_highlighted,
627 mwindow->edl->local_session->get_selectionstart(),
628 mwindow->edl->session->labels_follow_edits,
629 mwindow->edl->session->plugins_follow_edits,
630 mwindow->edl->session->autos_follow_edits,
634 if(mwindow->session->drag_assets->total ||
635 mwindow->session->drag_clips->total)
637 mwindow->save_backup();
638 mwindow->restart_brender();
639 mwindow->gui->update(1, 1, 1, 1, 0, 1, 0);
640 mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
641 mwindow->gui->unlock_window();
642 mwindow->sync_parameters(LOAD_ALL);
646 if(mwindow->session->current_operation == DRAG_VEFFECT)
648 //printf("CWindowGUI::drag_stop 1\n");
649 Track *affected_track = cwindow->calculate_affected_track();
650 //printf("CWindowGUI::drag_stop 2\n");
652 mwindow->gui->lock_window("CWindowGUI::drag_stop 3");
653 mwindow->insert_effects_cwindow(affected_track);
654 mwindow->session->current_operation = NO_OPERATION;
655 mwindow->gui->unlock_window();
658 if(mwindow->session->current_operation == DRAG_VTRANSITION)
660 Track *affected_track = cwindow->calculate_affected_track();
661 mwindow->gui->lock_window("CWindowGUI::drag_stop 4");
662 mwindow->paste_transition_cwindow(affected_track);
663 mwindow->session->current_operation = NO_OPERATION;
664 mwindow->gui->unlock_window();
670 void CWindowGUI::update_meters()
672 if(mwindow->edl->session->cwindow_meter != meters->visible)
674 meters->set_meters(meters->meter_count, mwindow->edl->session->cwindow_meter);
675 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
676 resize_event(get_w(), get_h());
681 CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
684 mwindow->theme->cedit_x,
685 mwindow->theme->cedit_y,
686 mwindow->edl->session->editing_mode,
705 this->mwindow = mwindow;
706 this->cwindow = cwindow;
709 #define CWrapper(fn) void CWindowEditing::fn() { \
710 mwindow->gui->lock_window("CWrapper::" #fn); \
712 mwindow->gui->unlock_window(); \
715 CWrapper(copy_selection)
716 CWrapper(splice_selection)
717 CWrapper(overwrite_selection)
718 CWrapper(set_inpoint)
719 CWrapper(set_outpoint)
720 CWrapper(clear_inpoint)
721 CWrapper(clear_outpoint)
723 CWrapper(toggle_label)
731 CWindowMeters::CWindowMeters(MWindow *mwindow,
736 : MeterPanel(mwindow,
742 mwindow->edl->session->audio_channels,
743 mwindow->edl->session->cwindow_meter,
747 this->mwindow = mwindow;
751 CWindowMeters::~CWindowMeters()
755 int CWindowMeters::change_status_event(int new_status)
757 mwindow->edl->session->cwindow_meter = new_status;
758 gui->update_meters();
765 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
768 (double)mwindow->edl->session->cwindow_zoom,
776 this->mwindow = mwindow;
780 CWindowZoom::~CWindowZoom()
784 int CWindowZoom::handle_event()
786 if(!strcasecmp(gui->auto_zoom, get_text()))
788 gui->zoom_canvas(1, get_value(), 0);
792 gui->zoom_canvas(0, get_value(), 0);
801 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
802 : BC_PercentageSlider(x,
811 this->mwindow = mwindow;
812 this->cwindow = cwindow;
813 set_precision(0.00001);
816 CWindowSlider::~CWindowSlider()
820 int CWindowSlider::handle_event()
822 cwindow->update_position((double)get_value());
826 void CWindowSlider::set_position()
828 double new_length = mwindow->edl->tracks->total_playable_length();
829 // if(mwindow->edl->local_session->preview_end <= 0 ||
830 // mwindow->edl->local_session->preview_end > new_length)
831 // mwindow->edl->local_session->preview_end = new_length;
832 // if(mwindow->edl->local_session->preview_start >
833 // mwindow->edl->local_session->preview_end)
834 // mwindow->edl->local_session->preview_start = 0;
837 update(mwindow->theme->cslider_w,
838 mwindow->edl->local_session->get_selectionstart(1),
841 // mwindow->edl->local_session->preview_start,
842 // mwindow->edl->local_session->preview_end);
846 int CWindowSlider::increase_value()
849 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
850 lock_window("CWindowSlider::increase_value");
854 int CWindowSlider::decrease_value()
857 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
858 lock_window("CWindowSlider::decrease_value");
863 // CWindowDestination::CWindowDestination(MWindow *mwindow, CWindowGUI *cwindow, int x, int y)
864 // : BC_PopupTextBox(cwindow,
865 // &cwindow->destinations,
866 // cwindow->destinations.values[cwindow->cwindow->destination]->get_text(),
872 // this->mwindow = mwindow;
873 // this->cwindow = cwindow;
876 // CWindowDestination::~CWindowDestination()
880 // int CWindowDestination::handle_event()
891 CWindowTransport::CWindowTransport(MWindow *mwindow,
895 : PlayTransport(mwindow,
903 EDL* CWindowTransport::get_edl()
908 void CWindowTransport::goto_start()
910 gui->unlock_window();
911 handle_transport(REWIND, 1);
913 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
914 mwindow->goto_start();
915 mwindow->gui->unlock_window();
917 gui->lock_window("CWindowTransport::goto_start 2");
920 void CWindowTransport::goto_end()
922 gui->unlock_window();
923 handle_transport(GOTO_END, 1);
925 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
927 mwindow->gui->unlock_window();
929 gui->lock_window("CWindowTransport::goto_end 2");
934 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
937 mwindow->theme->ccanvas_x,
938 mwindow->theme->ccanvas_y,
939 mwindow->theme->ccanvas_w,
940 mwindow->theme->ccanvas_h,
943 mwindow->edl->session->cwindow_scrollbars)
945 this->mwindow = mwindow;
949 void CWindowCanvas::status_event()
954 int CWindowCanvas::get_fullscreen()
956 return mwindow->session->cwindow_fullscreen;
959 void CWindowCanvas::set_fullscreen(int value)
961 mwindow->session->cwindow_fullscreen = value;
965 void CWindowCanvas::update_zoom(int x, int y, float zoom)
967 use_scrollbars = mwindow->edl->session->cwindow_scrollbars;
969 mwindow->edl->session->cwindow_xscroll = x;
970 mwindow->edl->session->cwindow_yscroll = y;
971 mwindow->edl->session->cwindow_zoom = zoom;
974 void CWindowCanvas::zoom_auto()
976 gui->zoom_canvas(1, 1.0, 1);
979 int CWindowCanvas::get_xscroll()
981 return mwindow->edl->session->cwindow_xscroll;
984 int CWindowCanvas::get_yscroll()
986 return mwindow->edl->session->cwindow_yscroll;
990 float CWindowCanvas::get_zoom()
992 return mwindow->edl->session->cwindow_zoom;
995 void CWindowCanvas::draw_refresh(int flush)
997 if(get_canvas() && !get_canvas()->get_video_on())
1000 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
1002 float in_x1, in_y1, in_x2, in_y2;
1003 float out_x1, out_y1, out_x2, out_y2;
1004 get_transfers(mwindow->edl,
1014 if(!EQUIV(out_x1, 0) ||
1015 !EQUIV(out_y1, 0) ||
1016 !EQUIV(out_x2, get_canvas()->get_w()) ||
1017 !EQUIV(out_y2, get_canvas()->get_h()))
1019 get_canvas()->clear_box(0,
1021 get_canvas()->get_w(),
1022 get_canvas()->get_h());
1025 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1026 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1029 if(out_x2 > out_x1 &&
1034 // Can't use OpenGL here because it is called asynchronously of the
1035 // playback operation.
1036 get_canvas()->draw_vframe(refresh_frame,
1039 (int)(out_x2 - out_x1),
1040 (int)(out_y2 - out_y1),
1043 (int)(in_x2 - in_x1),
1044 (int)(in_y2 - in_y1),
1050 get_canvas()->clear_box(0,
1052 get_canvas()->get_w(),
1053 get_canvas()->get_h());
1057 get_canvas()->flash(flush);
1059 //printf("CWindowCanvas::draw_refresh 10\n");
1062 #define CROPHANDLE_W 10
1063 #define CROPHANDLE_H 10
1065 void CWindowCanvas::draw_crophandle(int x, int y)
1067 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1075 #define CONTROL_W 10
1076 #define CONTROL_H 10
1077 #define FIRST_CONTROL_W 20
1078 #define FIRST_CONTROL_H 20
1080 #define BC_INFINITY 65536
1082 #define RULERHANDLE_W 16
1083 #define RULERHANDLE_H 16
1087 int CWindowCanvas::do_ruler(int draw,
1093 float x1 = mwindow->edl->session->ruler_x1;
1094 float y1 = mwindow->edl->session->ruler_y1;
1095 float x2 = mwindow->edl->session->ruler_x2;
1096 float y2 = mwindow->edl->session->ruler_y2;
1097 float canvas_x1 = x1;
1098 float canvas_y1 = y1;
1099 float canvas_x2 = x2;
1100 float canvas_y2 = y2;
1101 float output_x = get_cursor_x();
1102 float output_y = get_cursor_y();
1103 float canvas_cursor_x = output_x;
1104 float canvas_cursor_y = output_y;
1106 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1107 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1108 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1109 mwindow->session->cwindow_output_x = roundf(output_x);
1110 mwindow->session->cwindow_output_y = roundf(output_y);
1112 if(button_press && get_buttonpress() == 1)
1114 gui->ruler_handle = -1;
1115 gui->ruler_translate = 0;
1118 gui->ruler_translate = 1;
1119 gui->ruler_origin_x = x1;
1120 gui->ruler_origin_y = y1;
1123 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1124 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1125 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1126 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1128 gui->ruler_handle = 0;
1129 gui->ruler_origin_x = x1;
1130 gui->ruler_origin_y = y1;
1133 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1134 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1135 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1136 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1138 gui->ruler_handle = 1;
1139 gui->ruler_origin_x = x2;
1140 gui->ruler_origin_y = y2;
1144 // Start new selection
1145 if(!gui->ruler_translate &&
1146 (gui->ruler_handle < 0 ||
1151 do_ruler(1, 0, 0, 0);
1152 get_canvas()->flash();
1153 gui->ruler_handle = 1;
1154 mwindow->edl->session->ruler_x1 = output_x;
1155 mwindow->edl->session->ruler_y1 = output_y;
1156 mwindow->edl->session->ruler_x2 = output_x;
1157 mwindow->edl->session->ruler_y2 = output_y;
1158 gui->ruler_origin_x = mwindow->edl->session->ruler_x2;
1159 gui->ruler_origin_y = mwindow->edl->session->ruler_y2;
1162 gui->x_origin = output_x;
1163 gui->y_origin = output_y;
1164 gui->current_operation = CWINDOW_RULER;
1165 gui->tool_panel->raise_window();
1171 if(gui->current_operation == CWINDOW_RULER)
1173 if(gui->ruler_translate)
1176 do_ruler(1, 0, 0, 0);
1177 float x_difference = mwindow->edl->session->ruler_x1;
1178 float y_difference = mwindow->edl->session->ruler_y1;
1179 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1180 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1181 x_difference -= mwindow->edl->session->ruler_x1;
1182 y_difference -= mwindow->edl->session->ruler_y1;
1183 mwindow->edl->session->ruler_x2 -= x_difference;
1184 mwindow->edl->session->ruler_y2 -= y_difference;
1186 do_ruler(1, 0, 0, 0);
1187 get_canvas()->flash();
1191 switch(gui->ruler_handle)
1194 do_ruler(1, 0, 0, 0);
1195 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1196 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1197 if(gui->alt_down() || gui->ctrl_down())
1199 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1200 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1204 double distance_value =
1205 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1206 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1207 if(angle_value < 22)
1208 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2;
1210 if(angle_value > 67)
1211 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2;
1213 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 &&
1214 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1216 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1217 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1220 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 && 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;
1226 if(mwindow->edl->session->ruler_x1 > mwindow->edl->session->ruler_x2 &&
1227 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1229 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1230 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1234 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1235 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1238 do_ruler(1, 0, 0, 0);
1239 get_canvas()->flash();
1244 do_ruler(1, 0, 0, 0);
1245 mwindow->edl->session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1246 mwindow->edl->session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1247 if(gui->alt_down() || gui->ctrl_down())
1249 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1250 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1254 double distance_value =
1255 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1256 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1257 if(angle_value < 22)
1258 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1;
1260 if(angle_value > 67)
1261 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1;
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 &&
1271 mwindow->edl->session->ruler_y2 > mwindow->edl->session->ruler_y1)
1273 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1274 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1277 if(mwindow->edl->session->ruler_x2 > mwindow->edl->session->ruler_x1 && mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1279 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1280 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1284 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1285 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1288 do_ruler(1, 0, 0, 0);
1289 get_canvas()->flash();
1293 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1297 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1302 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1303 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1304 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1305 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1307 set_cursor(UPRIGHT_ARROW_CURSOR);
1310 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1311 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1312 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1313 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1315 set_cursor(UPRIGHT_ARROW_CURSOR);
1318 set_cursor(CROSS_CURSOR);
1320 // Update current position
1325 // Assume no ruler measurement if 0 length
1326 if(draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)))
1328 get_canvas()->set_inverse();
1329 get_canvas()->set_color(WHITE);
1330 get_canvas()->draw_line((int)canvas_x1,
1334 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1336 roundf(canvas_x1) + RULERHANDLE_W / 2,
1338 get_canvas()->draw_line(roundf(canvas_x1),
1339 roundf(canvas_y1) - RULERHANDLE_H / 2,
1341 roundf(canvas_y1) + RULERHANDLE_H / 2);
1342 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1344 roundf(canvas_x2) + RULERHANDLE_W / 2,
1346 get_canvas()->draw_line(roundf(canvas_x2),
1347 roundf(canvas_y2) - RULERHANDLE_H / 2,
1349 roundf(canvas_y2) + RULERHANDLE_H / 2);
1350 get_canvas()->set_opaque();
1357 static inline double line_dist(float cx,float cy, float tx,float ty)
1359 double dx = tx-cx, dy = ty-cy;
1360 return sqrt(dx*dx + dy*dy);
1363 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1365 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1366 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1370 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1371 int button_press, int cursor_motion, int draw)
1373 // Retrieve points from top recordable track
1374 //printf("CWindowCanvas::do_mask 1\n");
1375 Track *track = gui->cwindow->calculate_affected_track();
1376 //printf("CWindowCanvas::do_mask 2\n");
1378 if(!track) return 0;
1379 //printf("CWindowCanvas::do_mask 3\n");
1381 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1382 int64_t position = track->to_units(
1383 mwindow->edl->local_session->get_selectionstart(1),
1385 ArrayList<MaskPoint*> points;
1387 // Determine the points based on whether
1388 // new keyframes will be generated or drawing is performed.
1389 // If keyframe generation occurs, use the interpolated mask.
1390 // If no keyframe generation occurs, use the previous mask.
1391 int use_interpolated = 0;
1392 if(button_press || cursor_motion) {
1393 #ifdef USE_KEYFRAME_SPANNING
1394 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1395 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1398 mask_autos->get_prev_auto(track->to_units(selection_start, 0),
1399 PLAY_FORWARD, first, 1);
1401 mask_autos->get_prev_auto(track->to_units(selection_end, 0),
1402 PLAY_FORWARD, last, 1);
1404 if(last == first && (!mwindow->edl->session->auto_keyframes))
1405 use_interpolated = 0;
1407 // If keyframe spanning occurs, use the interpolated points.
1408 // If new keyframe is generated, use the interpolated points.
1409 use_interpolated = 1;
1412 if(mwindow->edl->session->auto_keyframes)
1413 use_interpolated = 1;
1417 use_interpolated = 1;
1419 if(use_interpolated) {
1420 // Interpolate the points to get exactly what is being rendered at this position.
1421 mask_autos->get_points(&points,
1422 mwindow->edl->session->cwindow_mask,
1427 // Use the prev mask
1429 mask_autos->get_prev_auto(position,
1433 ((MaskAuto*)prev)->get_points(&points,
1434 mwindow->edl->session->cwindow_mask);
1437 // Projector zooms relative to the center of the track output.
1438 float half_track_w = (float)track->track_w / 2;
1439 float half_track_h = (float)track->track_h / 2;
1440 // Translate mask to projection
1441 float projector_x, projector_y, projector_z;
1442 track->automation->get_projector(
1443 &projector_x, &projector_y, &projector_z,
1444 position, PLAY_FORWARD);
1447 // Get position of cursor relative to mask
1448 float cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
1449 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1450 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1452 projector_x += mwindow->edl->session->output_w / 2;
1453 projector_y += mwindow->edl->session->output_h / 2;
1454 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1455 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1457 // Fix cursor origin
1459 gui->x_origin = mask_cursor_x;
1460 gui->y_origin = mask_cursor_y;
1464 // Points of closest line
1465 int shortest_point1 = -1;
1466 int shortest_point2 = -1;
1468 int shortest_point = -1;
1469 // Distance to closest line
1470 float shortest_line_distance = BC_INFINITY;
1471 // Distance to closest point
1472 float shortest_point_distance = BC_INFINITY;
1473 int selected_point = -1;
1474 int selected_control_point = -1;
1475 float selected_control_point_distance = BC_INFINITY;
1476 ArrayList<int> x_points;
1477 ArrayList<int> y_points;
1479 if(!cursor_motion) {
1481 get_canvas()->set_color(WHITE);
1482 get_canvas()->set_inverse();
1484 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1486 // Never draw closed polygon and a closed
1487 // polygon is harder to add points to.
1488 for(int i = 0; i < points.size() && !result; i++) {
1489 MaskPoint *point1 = points.get(i);
1490 MaskPoint *point2 = (i >= points.size() - 1) ?
1491 points.get(0) : points.get(i + 1);
1493 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1494 if(point_distance1 < shortest_point_distance || shortest_point < 0) {
1495 shortest_point_distance = point_distance1;
1499 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1500 if(point_distance2 < shortest_point_distance || shortest_point < 0) {
1501 shortest_point_distance = point_distance2;
1502 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1506 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1508 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1509 //point1->x, point1->y, point2->x, point2->y, projector_z);
1510 for(int j = 0; j <= segments && !result; j++) {
1511 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1512 float x0 = point1->x, y0 = point1->y;
1513 float x1 = point1->x + point1->control_x2;
1514 float y1 = point1->y + point1->control_y2;
1515 float x2 = point2->x + point2->control_x1;
1516 float y2 = point2->y + point2->control_y1;
1517 float x3 = point2->x, y3 = point2->y;
1518 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1519 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1520 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1521 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1522 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1523 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1524 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1525 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1527 float t = (float)j / segments;
1528 float tpow2 = t * t;
1529 float tpow3 = t * t * t;
1531 float invtpow2 = invt * invt;
1532 float invtpow3 = invt * invt * invt;
1534 float x = ( invtpow3 * x0
1535 + 3 * t * invtpow2 * x1
1536 + 3 * tpow2 * invt * x2
1538 float y = ( invtpow3 * y0
1539 + 3 * t * invtpow2 * y1
1540 + 3 * tpow2 * invt * y2
1542 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1543 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1544 // Test new point addition
1546 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1548 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1549 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1550 if(line_distance < shortest_line_distance ||
1551 shortest_point1 < 0) {
1552 shortest_line_distance = line_distance;
1553 shortest_point1 = i;
1554 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1555 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1556 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1559 // Test existing point selection
1561 if(gui->ctrl_down()) {
1562 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1564 if(distance < selected_control_point_distance) {
1566 selected_control_point = 1;
1567 selected_control_point_distance = distance;
1571 if(!gui->shift_down()) {
1572 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1573 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
1578 selected_point = shortest_point;
1581 // Test second point
1582 if(gui->ctrl_down()) {
1583 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1585 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1586 if(distance < selected_control_point_distance) {
1587 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1588 selected_control_point = 0;
1589 selected_control_point_distance = distance;
1592 else if(i < points.size() - 1) {
1593 if(!gui->shift_down()) {
1594 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1595 if(test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3)) {
1596 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1600 selected_point = shortest_point;
1605 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1609 if(draw) { // Draw joining line
1610 x_points.append((int)canvas_x);
1611 y_points.append((int)canvas_y);
1615 if(draw) { // Draw second anchor
1616 if(i < points.size() - 1) {
1617 if(i == gui->affected_point - 1)
1618 get_canvas()->draw_disc(
1619 (int)canvas_x - CONTROL_W / 2,
1620 (int)canvas_y - CONTROL_W / 2,
1621 CONTROL_W, CONTROL_H);
1623 get_canvas()->draw_circle(
1624 (int)canvas_x - CONTROL_W / 2,
1625 (int)canvas_y - CONTROL_W / 2,
1626 CONTROL_W, CONTROL_H);
1627 // char string[BCTEXTLEN];
1628 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1629 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1631 // Draw second control point.
1632 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1633 get_canvas()->draw_line(
1634 (int)canvas_x, (int)canvas_y,
1635 (int)canvas_x2, (int)canvas_y2);
1636 get_canvas()->draw_rectangle(
1637 (int)canvas_x2 - CONTROL_W / 2,
1638 (int)canvas_y2 - CONTROL_H / 2,
1639 CONTROL_W, CONTROL_H);
1644 // Draw first anchor
1645 if(i == 0 && draw) {
1646 char mask_label[BCSTRLEN];
1647 sprintf(mask_label, "%d",
1648 mwindow->edl->session->cwindow_mask);
1649 get_canvas()->draw_text(
1650 (int)canvas_x - FIRST_CONTROL_W,
1651 (int)canvas_y - FIRST_CONTROL_H,
1654 get_canvas()->draw_disc(
1655 (int)canvas_x - FIRST_CONTROL_W / 2,
1656 (int)canvas_y - FIRST_CONTROL_H / 2,
1657 FIRST_CONTROL_W, FIRST_CONTROL_H);
1660 // Draw first control point.
1662 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1663 get_canvas()->draw_line(
1664 (int)canvas_x, (int)canvas_y,
1665 (int)canvas_x1, (int)canvas_y1);
1666 get_canvas()->draw_rectangle(
1667 (int)canvas_x1 - CONTROL_W / 2,
1668 (int)canvas_y1 - CONTROL_H / 2,
1669 CONTROL_W, CONTROL_H);
1671 x_points.append((int)canvas_x);
1672 y_points.append((int)canvas_y);
1675 //printf("CWindowCanvas::do_mask 1\n");
1679 //printf("CWindowCanvas::do_mask 1\n");
1682 get_canvas()->draw_polygon(&x_points, &y_points);
1683 get_canvas()->set_opaque();
1685 //printf("CWindowCanvas::do_mask 1\n");
1688 if(button_press && !result) {
1689 gui->affected_track = gui->cwindow->calculate_affected_track();
1691 // Get keyframe outside the EDL to edit. This must be rendered
1692 // instead of the EDL keyframes when it exists. Then it must be
1693 // applied to the EDL keyframes on buttonrelease.
1694 if(gui->affected_track) {
1695 #ifdef USE_KEYFRAME_SPANNING
1696 // Make copy of current parameters in local keyframe
1697 gui->mask_keyframe =
1698 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1701 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1704 gui->mask_keyframe =
1705 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1710 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1713 // Translate entire keyframe
1714 if(gui->alt_down() && mask->points.size()) {
1715 mwindow->undo->update_undo_before(_("mask translate"), 0);
1716 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1717 gui->affected_point = 0;
1720 // Existing point or control point was selected
1721 if(selected_point >= 0) {
1722 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1723 gui->affected_point = selected_point;
1725 if(selected_control_point == 0)
1726 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1728 if(selected_control_point == 1)
1729 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1731 gui->current_operation = mwindow->edl->session->cwindow_operation;
1733 else // No existing point or control point was selected so create a new one
1734 if(!gui->ctrl_down() && !gui->alt_down()) {
1735 mwindow->undo->update_undo_before(_("mask point"), 0);
1736 // Create the template
1737 MaskPoint *point = new MaskPoint;
1738 point->x = mask_cursor_x;
1739 point->y = mask_cursor_y;
1740 point->control_x1 = 0;
1741 point->control_y1 = 0;
1742 point->control_x2 = 0;
1743 point->control_y2 = 0;
1746 if(shortest_point2 < shortest_point1) {
1747 shortest_point2 ^= shortest_point1;
1748 shortest_point1 ^= shortest_point2;
1749 shortest_point2 ^= shortest_point1;
1754 // printf("CWindowGUI::do_mask 40\n");
1755 // mwindow->edl->dump();
1756 // printf("CWindowGUI::do_mask 50\n");
1760 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1761 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1762 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1764 // Append to end of list
1765 if( shortest_point1 == shortest_point2 ||
1766 labs(shortest_point1 - shortest_point2) > 1) {
1767 #ifdef USE_KEYFRAME_SPANNING
1769 MaskPoint *new_point = new MaskPoint;
1770 points.append(new_point);
1771 *new_point = *point;
1772 gui->affected_point = points.size() - 1;
1776 // Need to apply the new point to every keyframe
1777 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1778 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1779 MaskPoint *new_point = new MaskPoint;
1780 submask->points.append(new_point);
1781 *new_point = *point;
1782 if(current == (MaskAuto*)mask_autos->default_auto)
1783 current = (MaskAuto*)mask_autos->first;
1785 current = (MaskAuto*)NEXT;
1787 gui->affected_point = mask->points.size() - 1;
1793 // Insert between 2 points, shifting back point 2
1794 if(shortest_point1 >= 0 && shortest_point2 >= 0) {
1796 #ifdef USE_KEYFRAME_SPANNING
1797 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1799 if(points.size() >= shortest_point2) {
1800 MaskPoint *new_point = new MaskPoint;
1802 for(int i = points.size() - 1;
1803 i > shortest_point2;
1805 points.values[i] = points.values[i - 1];
1806 points.values[shortest_point2] = new_point;
1808 *new_point = *point;
1813 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1814 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1815 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1817 if(submask->points.size() >= shortest_point2) {
1818 MaskPoint *new_point = new MaskPoint;
1819 submask->points.append(0);
1820 for(int i = submask->points.size() - 1;
1821 i > shortest_point2;
1823 submask->points.values[i] = submask->points.values[i - 1];
1824 submask->points.values[shortest_point2] = new_point;
1826 *new_point = *point;
1829 if(current == (MaskAuto*)mask_autos->default_auto)
1830 current = (MaskAuto*)mask_autos->first;
1832 current = (MaskAuto*)NEXT;
1836 gui->affected_point = shortest_point2;
1841 // printf("CWindowGUI::do_mask 20\n");
1842 // mwindow->edl->dump();
1843 // printf("CWindowGUI::do_mask 30\n");
1846 //printf("CWindowCanvas::do_mask 1\n");
1847 // Create the first point.
1848 #ifdef USE_KEYFRAME_SPANNING
1849 MaskPoint *new_point = new MaskPoint;
1850 points.append(new_point);
1851 *new_point = *point;
1852 gui->affected_point = points.size() - 1;
1854 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1855 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1856 MaskPoint *new_point = new MaskPoint;
1857 submask->points.append(new_point);
1858 *new_point = *point;
1859 if(current == (MaskAuto*)mask_autos->default_auto)
1860 current = (MaskAuto*)mask_autos->first;
1862 current = (MaskAuto*)NEXT;
1864 gui->affected_point = points.size() - 1;
1867 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
1870 gui->current_operation = mwindow->edl->session->cwindow_operation;
1871 // Delete the template
1880 if(button_press && result) {
1881 #ifdef USE_KEYFRAME_SPANNING
1882 MaskPoint *point = points.values[gui->affected_point];
1883 gui->center_x = point->x;
1884 gui->center_y = point->y;
1885 gui->control_in_x = point->control_x1;
1886 gui->control_in_y = point->control_y1;
1887 gui->control_out_x = point->control_x2;
1888 gui->control_out_y = point->control_y2;
1889 gui->tool_panel->raise_window();
1891 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1892 MaskPoint *point = mask->points.values[gui->affected_point];
1893 gui->center_x = point->x;
1894 gui->center_y = point->y;
1895 gui->control_in_x = point->control_x1;
1896 gui->control_in_y = point->control_y1;
1897 gui->control_out_x = point->control_x2;
1898 gui->control_out_y = point->control_y2;
1899 gui->tool_panel->raise_window();
1903 //printf("CWindowCanvas::do_mask 8\n");
1906 #ifdef USE_KEYFRAME_SPANNING
1907 // Must update the reference keyframes for every cursor motion
1908 gui->mask_keyframe =
1909 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1912 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1915 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1917 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1918 if( gui->affected_point >= 0 && gui->affected_point < mask->points.size() &&
1919 gui->current_operation != CWINDOW_NONE) {
1920 // mwindow->undo->update_undo_before(_("mask point"), this);
1921 #ifdef USE_KEYFRAME_SPANNING
1922 MaskPoint *point = points.get(gui->affected_point);
1924 MaskPoint *point = mask->points.get(gui->affected_point);
1926 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
1927 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask->points.size(), gui->affected_point);
1929 float last_x = point->x;
1930 float last_y = point->y;
1931 float last_control_x1 = point->control_x1;
1932 float last_control_y1 = point->control_y1;
1933 float last_control_x2 = point->control_x2;
1934 float last_control_y2 = point->control_y2;
1936 switch(gui->current_operation) {
1938 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1939 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
1940 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
1943 case CWINDOW_MASK_CONTROL_IN:
1944 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
1945 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
1948 case CWINDOW_MASK_CONTROL_OUT:
1949 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
1950 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
1953 case CWINDOW_MASK_TRANSLATE:
1954 #ifdef USE_KEYFRAME_SPANNING
1955 for(int i = 0; i < points.size(); i++) {
1956 points.values[i]->x += mask_cursor_x - gui->x_origin;
1957 points.values[i]->y += mask_cursor_y - gui->y_origin;
1960 for(int i = 0; i < mask->points.size(); i++) {
1961 mask->points.values[i]->x += mask_cursor_x - gui->x_origin;
1962 mask->points.values[i]->y += mask_cursor_y - gui->y_origin;
1965 gui->x_origin = mask_cursor_x;
1966 gui->y_origin = mask_cursor_y;
1970 if( !EQUIV(last_x, point->x) ||
1971 !EQUIV(last_y, point->y) ||
1972 !EQUIV(last_control_x1, point->control_x1) ||
1973 !EQUIV(last_control_y1, point->control_y1) ||
1974 !EQUIV(last_control_x2, point->control_x2) ||
1975 !EQUIV(last_control_y2, point->control_y2)) {
1981 if(gui->current_operation == CWINDOW_NONE) {
1982 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
1984 for(int i = 0; i < points.size() && !over_point; i++) {
1985 MaskPoint *point = points.get(i);
1986 float x0 = point->x;
1987 float y0 = point->y;
1988 float x1 = point->x + point->control_x1;
1989 float y1 = point->y + point->control_y1;
1990 float x2 = point->x + point->control_x2;
1991 float y2 = point->y + point->control_y2;
1992 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1993 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1995 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1996 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
2000 if(!over_point && gui->ctrl_down()) {
2001 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
2002 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
2003 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2004 if(test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1)) {
2008 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2009 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2010 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2011 if(test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2)) {
2018 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2023 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2026 #ifdef USE_KEYFRAME_SPANNING
2027 // Must commit change after operation.
2028 if(rerender && track) {
2029 // Swap EDL keyframe with original.
2030 // Apply new values to keyframe span
2031 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2032 temp_keyframe.copy_data(gui->mask_keyframe);
2033 // Apply interpolated points back to keyframe
2034 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2035 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2036 mask_autos->update_parameter(&temp_keyframe);
2040 points.remove_all_objects();
2041 //printf("CWindowCanvas::do_mask 20\n");
2045 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2048 int radius = mwindow->edl->session->eyedrop_radius;
2056 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2061 row1 = gui->eyedrop_y - radius;
2062 row2 = gui->eyedrop_y + radius;
2063 column1 = gui->eyedrop_x - radius;
2064 column2 = gui->eyedrop_x + radius;
2066 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2067 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2068 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2069 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2071 if(row2 <= row1) row2 = row1 + 1;
2072 if(column2 <= column1) column2 = column1 + 1;
2079 output_to_canvas(mwindow->edl, 0, x1, y1);
2080 output_to_canvas(mwindow->edl, 0, x2, y2);
2081 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2083 if(x2 - x1 >= 1 && y2 - y1 >= 1)
2085 get_canvas()->set_inverse();
2086 get_canvas()->set_color(WHITE);
2088 get_canvas()->draw_rectangle((int)x1,
2093 get_canvas()->set_opaque();
2094 get_canvas()->flash();
2102 gui->current_operation = CWINDOW_EYEDROP;
2103 gui->tool_panel->raise_window();
2106 if(gui->current_operation == CWINDOW_EYEDROP)
2108 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2110 // Get color out of frame.
2111 // Doesn't work during playback because that bypasses the refresh frame.
2112 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2114 float cursor_x = get_cursor_x();
2115 float cursor_y = get_cursor_y();
2116 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2117 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2118 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2120 row1 = cursor_y - radius;
2121 row2 = cursor_y + radius;
2122 column1 = cursor_x - radius;
2123 column2 = cursor_x + radius;
2124 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2125 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2126 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2127 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2128 if(row2 <= row1) row2 = row1 + 1;
2129 if(column2 <= column1) column2 = column1 + 1;
2133 if(gui->eyedrop_visible)
2136 do_eyedrop(temp, 0, 1);
2137 gui->eyedrop_visible = 0;
2140 gui->eyedrop_x = cursor_x;
2141 gui->eyedrop_y = cursor_y;
2146 do_eyedrop(temp, 0, 1);
2147 gui->eyedrop_visible = 1;
2150 // Decompression coefficients straight out of jpeglib
2151 #define V_TO_R 1.40200
2152 #define V_TO_G -0.71414
2154 #define U_TO_G -0.34414
2155 #define U_TO_B 1.77200
2157 #define GET_COLOR(type, components, max, do_yuv) \
2159 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2161 float red = (float)*row++ / max; \
2162 float green = (float)*row++ / max; \
2163 float blue = (float)*row++ / max; \
2166 mwindow->edl->local_session->red += red + V_TO_R * (blue - 0.5); \
2167 mwindow->edl->local_session->green += red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
2168 mwindow->edl->local_session->blue += red + U_TO_B * (green - 0.5); \
2172 mwindow->edl->local_session->red += red; \
2173 mwindow->edl->local_session->green += green; \
2174 mwindow->edl->local_session->blue += blue; \
2180 mwindow->edl->local_session->red = 0;
2181 mwindow->edl->local_session->green = 0;
2182 mwindow->edl->local_session->blue = 0;
2183 for(int i = row1; i < row2; i++)
2185 for(int j = column1; j < column2; j++)
2187 switch(refresh_frame->get_color_model())
2190 GET_COLOR(unsigned char, 3, 0xff, 1);
2193 GET_COLOR(unsigned char, 4, 0xff, 1);
2196 GET_COLOR(uint16_t, 3, 0xffff, 1);
2198 case BC_YUVA16161616:
2199 GET_COLOR(uint16_t, 4, 0xffff, 1);
2202 GET_COLOR(unsigned char, 3, 0xff, 0);
2205 GET_COLOR(unsigned char, 4, 0xff, 0);
2208 GET_COLOR(float, 3, 1.0, 0);
2211 GET_COLOR(float, 4, 1.0, 0);
2217 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2218 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2219 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2224 mwindow->edl->local_session->red = 0;
2225 mwindow->edl->local_session->green = 0;
2226 mwindow->edl->local_session->blue = 0;
2227 gui->eyedrop_visible = 0;
2236 // Can't rerender since the color value is from the output of any effect it
2239 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2245 void CWindowCanvas::draw_overlays()
2247 if(mwindow->edl->session->safe_regions)
2249 draw_safe_regions();
2252 if(mwindow->edl->session->cwindow_scrollbars)
2254 // Always draw output rectangle
2255 float x1, y1, x2, y2;
2257 x2 = mwindow->edl->session->output_w;
2259 y2 = mwindow->edl->session->output_h;
2260 output_to_canvas(mwindow->edl, 0, x1, y1);
2261 output_to_canvas(mwindow->edl, 0, x2, y2);
2263 get_canvas()->set_inverse();
2264 get_canvas()->set_color(WHITE);
2266 get_canvas()->draw_rectangle((int)x1,
2271 get_canvas()->set_opaque();
2274 if(gui->highlighted)
2276 get_canvas()->set_color(WHITE);
2277 get_canvas()->set_inverse();
2278 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2279 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2280 get_canvas()->set_opaque();
2283 int temp1 = 0, temp2 = 0;
2284 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2285 switch(mwindow->edl->session->cwindow_operation)
2287 case CWINDOW_CAMERA:
2291 case CWINDOW_PROJECTOR:
2300 do_mask(temp1, temp2, 0, 0, 1);
2304 do_ruler(1, 0, 0, 0);
2307 case CWINDOW_EYEDROP:
2308 if(gui->eyedrop_visible)
2311 do_eyedrop(rerender, 0, 1);
2312 gui->eyedrop_visible = 1;
2318 void CWindowCanvas::draw_safe_regions()
2320 float action_x1, action_x2, action_y1, action_y2;
2321 float title_x1, title_x2, title_y1, title_y2;
2323 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2324 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2325 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2326 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2327 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2328 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2329 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2330 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2332 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2333 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2334 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2335 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2337 get_canvas()->set_inverse();
2338 get_canvas()->set_color(WHITE);
2340 get_canvas()->draw_rectangle((int)action_x1,
2342 (int)(action_x2 - action_x1),
2343 (int)(action_y2 - action_y1));
2344 get_canvas()->draw_rectangle((int)title_x1,
2346 (int)(title_x2 - title_x1),
2347 (int)(title_y2 - title_y1));
2349 get_canvas()->set_opaque();
2352 void CWindowCanvas::reset_keyframe(int do_camera)
2354 FloatAuto *x_keyframe = 0;
2355 FloatAuto *y_keyframe = 0;
2356 FloatAuto *z_keyframe = 0;
2357 Track *affected_track = 0;
2359 affected_track = gui->cwindow->calculate_affected_track();
2363 gui->cwindow->calculate_affected_autos(&x_keyframe,
2372 x_keyframe->set_value(0);
2373 y_keyframe->set_value(0);
2374 z_keyframe->set_value(1);
2376 mwindow->sync_parameters(CHANGE_PARAMS);
2381 void CWindowCanvas::reset_camera()
2386 void CWindowCanvas::reset_projector()
2391 int CWindowCanvas::test_crop(int button_press, int &redraw)
2394 int handle_selected = -1;
2395 float x1 = mwindow->edl->session->crop_x1;
2396 float y1 = mwindow->edl->session->crop_y1;
2397 float x2 = mwindow->edl->session->crop_x2;
2398 float y2 = mwindow->edl->session->crop_y2;
2399 float cursor_x = get_cursor_x();
2400 float cursor_y = get_cursor_y();
2401 float canvas_x1 = x1;
2402 float canvas_y1 = y1;
2403 float canvas_x2 = x2;
2404 float canvas_y2 = y2;
2405 float canvas_cursor_x = cursor_x;
2406 float canvas_cursor_y = cursor_y;
2408 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2409 // Use screen normalized coordinates for hot spot tests.
2410 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2411 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2414 if(gui->current_operation == CWINDOW_CROP)
2416 handle_selected = gui->crop_handle;
2419 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2420 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2422 handle_selected = 0;
2423 gui->crop_origin_x = x1;
2424 gui->crop_origin_y = y1;
2427 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2428 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2430 handle_selected = 1;
2431 gui->crop_origin_x = x2;
2432 gui->crop_origin_y = y1;
2435 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2436 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2438 handle_selected = 2;
2439 gui->crop_origin_x = x1;
2440 gui->crop_origin_y = y2;
2443 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2444 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2446 handle_selected = 3;
2447 gui->crop_origin_x = x2;
2448 gui->crop_origin_y = y2;
2453 gui->crop_origin_x = cursor_x;
2454 gui->crop_origin_y = cursor_y;
2457 // printf("test crop %d %d\n",
2458 // gui->current_operation,
2459 // handle_selected);
2466 gui->crop_translate = 1;
2467 gui->crop_origin_x1 = x1;
2468 gui->crop_origin_y1 = y1;
2469 gui->crop_origin_x2 = x2;
2470 gui->crop_origin_y2 = y2;
2473 gui->crop_translate = 0;
2475 gui->current_operation = CWINDOW_CROP;
2476 gui->crop_handle = handle_selected;
2477 gui->x_origin = cursor_x;
2478 gui->y_origin = cursor_y;
2479 gui->tool_panel->raise_window();
2482 if(handle_selected < 0 && !gui->crop_translate)
2486 mwindow->edl->session->crop_x1 = (int)x1;
2487 mwindow->edl->session->crop_y1 = (int)y1;
2488 mwindow->edl->session->crop_x2 = (int)x2;
2489 mwindow->edl->session->crop_y2 = (int)y2;
2494 // Translate all 4 points
2495 if(gui->current_operation == CWINDOW_CROP && gui->crop_translate)
2497 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2498 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2499 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2500 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2502 mwindow->edl->session->crop_x1 = (int)x1;
2503 mwindow->edl->session->crop_y1 = (int)y1;
2504 mwindow->edl->session->crop_x2 = (int)x2;
2505 mwindow->edl->session->crop_y2 = (int)y2;
2511 if(gui->current_operation == CWINDOW_CROP)
2513 switch(gui->crop_handle)
2516 x1 = gui->crop_origin_x;
2517 y1 = gui->crop_origin_y;
2518 x2 = gui->crop_origin_x;
2519 y2 = gui->crop_origin_y;
2520 if(cursor_x < gui->x_origin)
2522 if(cursor_y < gui->y_origin)
2528 if(cursor_y >= gui->y_origin)
2535 if(cursor_x >= gui->x_origin)
2537 if(cursor_y < gui->y_origin)
2543 if(cursor_y >= gui->y_origin)
2550 // printf("test crop %d %d %d %d\n",
2551 // mwindow->edl->session->crop_x1,
2552 // mwindow->edl->session->crop_y1,
2553 // mwindow->edl->session->crop_x2,
2554 // mwindow->edl->session->crop_y2);
2557 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2558 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2561 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2562 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2565 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2566 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2569 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2570 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2574 if(!EQUIV(mwindow->edl->session->crop_x1, x1) ||
2575 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2576 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2577 !EQUIV(mwindow->edl->session->crop_y2, y2))
2584 switch (gui->crop_handle)
2586 case 0: gui->crop_handle = 1; break;
2587 case 1: gui->crop_handle = 0; break;
2588 case 2: gui->crop_handle = 3; break;
2589 case 3: gui->crop_handle = 2; break;
2599 switch (gui->crop_handle)
2601 case 0: gui->crop_handle = 2; break;
2602 case 1: gui->crop_handle = 3; break;
2603 case 2: gui->crop_handle = 0; break;
2604 case 3: gui->crop_handle = 1; break;
2609 mwindow->edl->session->crop_x1 = (int)x1;
2610 mwindow->edl->session->crop_y1 = (int)y1;
2611 mwindow->edl->session->crop_x2 = (int)x2;
2612 mwindow->edl->session->crop_y2 = (int)y2;
2618 // Update cursor font
2619 if(handle_selected >= 0)
2621 switch(handle_selected)
2624 set_cursor(UPLEFT_RESIZE);
2627 set_cursor(UPRIGHT_RESIZE);
2630 set_cursor(DOWNLEFT_RESIZE);
2633 set_cursor(DOWNRIGHT_RESIZE);
2640 set_cursor(ARROW_CURSOR);
2642 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2646 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2647 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2648 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2649 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2650 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2651 // mwindow->edl->session->crop_x2,
2652 // mwindow->edl->session->crop_y2,
2653 // mwindow->edl->calculate_output_w(0),
2654 // mwindow->edl->calculate_output_h(0));
2660 void CWindowCanvas::draw_crop()
2662 get_canvas()->set_inverse();
2663 get_canvas()->set_color(WHITE);
2665 float x1 = mwindow->edl->session->crop_x1;
2666 float y1 = mwindow->edl->session->crop_y1;
2667 float x2 = mwindow->edl->session->crop_x2;
2668 float y2 = mwindow->edl->session->crop_y2;
2670 output_to_canvas(mwindow->edl, 0, x1, y1);
2671 output_to_canvas(mwindow->edl, 0, x2, y2);
2673 if(x2 - x1 && y2 - y1)
2674 get_canvas()->draw_rectangle((int)x1,
2679 draw_crophandle((int)x1, (int)y1);
2680 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2681 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2682 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2683 get_canvas()->set_opaque();
2693 void CWindowCanvas::draw_bezier(int do_camera)
2695 Track *track = gui->cwindow->calculate_affected_track();
2702 int64_t position = track->to_units(
2703 mwindow->edl->local_session->get_selectionstart(1),
2706 track->automation->get_projector(¢er_x,
2712 // center_x += track->track_w / 2;
2713 // center_y += track->track_h / 2;
2714 center_x += mwindow->edl->session->output_w / 2;
2715 center_y += mwindow->edl->session->output_h / 2;
2716 float track_x1 = center_x - track->track_w / 2 * center_z;
2717 float track_y1 = center_y - track->track_h / 2 * center_z;
2718 float track_x2 = track_x1 + track->track_w * center_z;
2719 float track_y2 = track_y1 + track->track_h * center_z;
2721 output_to_canvas(mwindow->edl, 0, track_x1, track_y1);
2722 output_to_canvas(mwindow->edl, 0, track_x2, track_y2);
2724 #define DRAW_PROJECTION(offset) \
2725 get_canvas()->draw_rectangle((int)track_x1 + offset, \
2726 (int)track_y1 + offset, \
2727 (int)(track_x2 - track_x1), \
2728 (int)(track_y2 - track_y1)); \
2729 get_canvas()->draw_line((int)track_x1 + offset, \
2730 (int)track_y1 + offset, \
2731 (int)track_x2 + offset, \
2732 (int)track_y2 + offset); \
2733 get_canvas()->draw_line((int)track_x2 + offset, \
2734 (int)track_y1 + offset, \
2735 (int)track_x1 + offset, \
2736 (int)track_y2 + offset); \
2740 get_canvas()->set_color(BLACK);
2743 // canvas->set_inverse();
2745 get_canvas()->set_color(GREEN);
2747 get_canvas()->set_color(RED);
2750 // canvas->set_opaque();
2754 int CWindowCanvas::test_bezier(int button_press,
2762 // Processing drag operation.
2763 // Create keyframe during first cursor motion.
2767 float cursor_x = get_cursor_x();
2768 float cursor_y = get_cursor_y();
2769 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2771 if(gui->current_operation == CWINDOW_CAMERA ||
2772 gui->current_operation == CWINDOW_PROJECTOR)
2774 if(!gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom)
2776 gui->translating_zoom = 1;
2777 gui->reset_affected();
2780 if(!gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom)
2782 gui->translating_zoom = 0;
2783 gui->reset_affected();
2786 // Get target keyframe
2787 float last_center_x;
2788 float last_center_y;
2789 float last_center_z;
2792 if(!gui->affected_x && !gui->affected_y && !gui->affected_z)
2794 FloatAutos *affected_x_autos;
2795 FloatAutos *affected_y_autos;
2796 FloatAutos *affected_z_autos;
2797 if(!gui->affected_track) return 0;
2798 double position = mwindow->edl->local_session->get_selectionstart(1);
2799 int64_t track_position = gui->affected_track->to_units(position, 0);
2801 if(mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA)
2803 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_X];
2804 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Y];
2805 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Z];
2809 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_X];
2810 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Y];
2811 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Z];
2815 if(gui->translating_zoom)
2817 FloatAuto *previous = 0;
2818 FloatAuto *next = 0;
2819 float new_z = affected_z_autos->get_value(
2825 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2826 affected_z_autos, 1, &created, 0);
2828 gui->affected_z->set_value(new_z);
2834 FloatAuto *previous = 0;
2835 FloatAuto *next = 0;
2836 float new_x = affected_x_autos->get_value(
2843 float new_y = affected_y_autos->get_value(
2849 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2850 affected_x_autos, 1, &created, 0);
2852 gui->affected_x->set_value(new_x);
2856 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2857 affected_y_autos, 1, &created, 0);
2859 gui->affected_y->set_value(new_y);
2866 if(gui->translating_zoom)
2868 gui->center_z = gui->affected_z->get_value();
2872 gui->center_x = gui->affected_x->get_value();
2873 gui->center_y = gui->affected_y->get_value();
2880 if(gui->translating_zoom)
2882 last_center_z = gui->affected_z->get_value();
2883 float z = gui->center_z + (cursor_y - gui->y_origin) / 128;
2885 if(!EQUIV(last_center_z, z))
2891 gui->affected_z->set_value(z);
2895 last_center_x = gui->affected_x->get_value();
2896 last_center_y = gui->affected_y->get_value();
2897 float x = gui->center_x + cursor_x - gui->x_origin;
2898 float y = gui->center_y + cursor_y - gui->y_origin;
2899 gui->affected_x->set_value(x);
2900 gui->affected_y->set_value(y);
2901 if( !EQUIV(last_center_x, x) || !EQUIV(last_center_y, y) )
2907 gui->affected_x->set_value(x);
2908 gui->affected_y->set_value(y);
2915 // Begin drag operation. Don't create keyframe here.
2917 // Get affected track off of the first recordable video track.
2918 // Calculating based on the alpha channel would require recording what layer
2919 // each output pixel belongs to as they're rendered and stacked. Forget it.
2920 gui->affected_track = gui->cwindow->calculate_affected_track();
2921 gui->reset_affected();
2923 if(gui->affected_track)
2925 if(gui->current_operation == CWINDOW_CAMERA)
2926 mwindow->undo->update_undo_before(_("camera"), this);
2928 mwindow->undo->update_undo_before(_("projector"), this);
2930 gui->current_operation =
2931 mwindow->edl->session->cwindow_operation;
2932 gui->tool_panel->raise_window();
2941 int CWindowCanvas::test_zoom(int &redraw)
2944 float zoom = get_zoom();
2948 if(!mwindow->edl->session->cwindow_scrollbars)
2950 mwindow->edl->session->cwindow_scrollbars = 1;
2952 x = mwindow->edl->session->output_w / 2;
2953 y = mwindow->edl->session->output_h / 2;
2954 x = x - w / zoom / 2;
2955 y = y - h / zoom / 2;
2959 // Cursor position relative to canvas
2962 // cursor position relative to output
2965 canvas_to_output(mwindow->edl,
2970 //printf("CWindowCanvas::test_zoom 1 %f %f\n", x, y);
2972 // Find current zoom in table
2973 int current_index = 0;
2974 for(current_index = 0 ; current_index < total_zooms; current_index++)
2975 if(EQUIV(my_zoom_table[current_index], zoom)) break;
2979 if(get_buttonpress() == 5 ||
2991 CLAMP(current_index, 0, total_zooms - 1);
2992 zoom = my_zoom_table[current_index];
2994 x = output_x - x / zoom;
2995 y = output_y - y / zoom;
3004 // check_boundaries(mwindow->edl, x_i, y_i, zoom);
3006 //printf("CWindowCanvas::test_zoom 2 %d %d\n", x_i, y_i);
3011 reposition_window(mwindow->edl,
3012 mwindow->theme->ccanvas_x,
3013 mwindow->theme->ccanvas_y,
3014 mwindow->theme->ccanvas_w,
3015 mwindow->theme->ccanvas_h);
3020 gui->zoom_panel->update(zoom);
3026 void CWindowCanvas::calculate_origin()
3028 gui->x_origin = get_cursor_x();
3029 gui->y_origin = get_cursor_y();
3030 //printf("CWindowCanvas::calculate_origin 1 %f %f\n", gui->x_origin, gui->y_origin);
3031 canvas_to_output(mwindow->edl, 0, gui->x_origin, gui->y_origin);
3032 //printf("CWindowCanvas::calculate_origin 2 %f %f\n", gui->x_origin, gui->y_origin);
3036 int CWindowCanvas::cursor_leave_event()
3038 set_cursor(ARROW_CURSOR);
3042 int CWindowCanvas::cursor_enter_event()
3045 switch(mwindow->edl->session->cwindow_operation)
3047 case CWINDOW_CAMERA:
3048 case CWINDOW_PROJECTOR:
3049 set_cursor(MOVE_CURSOR);
3052 set_cursor(MOVE_CURSOR);
3055 test_crop(0, redraw);
3057 case CWINDOW_PROTECT:
3058 set_cursor(ARROW_CURSOR);
3062 set_cursor(CROSS_CURSOR);
3064 case CWINDOW_EYEDROP:
3065 set_cursor(CROSS_CURSOR);
3071 int CWindowCanvas::cursor_motion_event()
3073 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3076 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3077 switch(gui->current_operation)
3079 case CWINDOW_SCROLL:
3081 float zoom = get_zoom();
3082 float cursor_x = get_cursor_x();
3083 float cursor_y = get_cursor_y();
3085 float zoom_x, zoom_y, conformed_w, conformed_h;
3086 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3087 cursor_x = (float)cursor_x / zoom_x + gui->x_offset;
3088 cursor_y = (float)cursor_y / zoom_y + gui->y_offset;
3092 int x = (int)(gui->x_origin - cursor_x + gui->x_offset);
3093 int y = (int)(gui->y_origin - cursor_y + gui->y_offset);
3098 update_scrollbars(0);
3105 result = do_ruler(0, 1, 0, 0);
3108 case CWINDOW_CAMERA:
3109 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3112 case CWINDOW_PROJECTOR:
3113 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3118 result = test_crop(0, redraw);
3119 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3126 case CWINDOW_MASK_CONTROL_IN:
3127 case CWINDOW_MASK_CONTROL_OUT:
3128 case CWINDOW_MASK_TRANSLATE:
3130 result = do_mask(redraw,
3137 case CWINDOW_EYEDROP:
3138 result = do_eyedrop(rerender, 0, 0);
3147 // cursor font changes
3150 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3152 // mwindow->edl->session->cwindow_operation);
3153 switch(mwindow->edl->session->cwindow_operation)
3156 result = test_crop(0, redraw);
3159 result = do_ruler(0, 1, 0, 0);
3162 result = do_mask(redraw,
3172 // If the window is never unlocked before calling send_command the
3173 // display shouldn't get stuck on the old video frame although it will
3174 // flicker between the old video frame and the new video frame.
3184 gui->unlock_window();
3187 mwindow->gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3188 mwindow->gui->draw_overlays(1);
3189 mwindow->gui->unlock_window();
3191 gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3196 gui->unlock_window();
3197 mwindow->restart_brender();
3198 mwindow->sync_parameters(CHANGE_PARAMS);
3199 gui->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
3203 if(!redraw) gui->update_tool();
3204 gui->lock_window("CWindowCanvas::cursor_motion_event 2");
3209 int CWindowCanvas::button_press_event()
3213 int redraw_canvas = 0;
3216 if(Canvas::button_press_event()) return 1;
3218 gui->translating_zoom = gui->shift_down();
3221 //printf("CWindowCanvas::button_press_event 2 %f %f\n", gui->x_origin, gui->y_origin, gui->x_origin, gui->y_origin);
3223 float zoom_x, zoom_y, conformed_w, conformed_h;
3224 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3225 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3226 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3229 if(get_buttonpress() == 2)
3231 gui->current_operation = CWINDOW_SCROLL;
3237 switch(mwindow->edl->session->cwindow_operation)
3240 result = do_ruler(0, 0, 1, 0);
3243 case CWINDOW_CAMERA:
3244 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3247 case CWINDOW_PROJECTOR:
3248 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3252 result = test_zoom(redraw);
3256 result = test_crop(1, redraw);
3260 if(get_buttonpress() == 1)
3261 result = do_mask(redraw, rerender, 1, 0, 0);
3264 case CWINDOW_EYEDROP:
3265 result = do_eyedrop(rerender, 1, 0);
3273 gui->unlock_window();
3276 mwindow->gui->lock_window("CWindowCanvas::button_press_event 1");
3277 mwindow->gui->draw_overlays(1);
3278 mwindow->gui->unlock_window();
3281 gui->lock_window("CWindowCanvas::button_press_event 1");
3284 // rerendering can also be caused by press event
3287 gui->unlock_window();
3289 mwindow->restart_brender();
3290 mwindow->sync_parameters(CHANGE_PARAMS);
3291 gui->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
3295 if(!redraw) gui->update_tool();
3296 gui->lock_window("CWindowCanvas::button_press_event 2");
3301 int CWindowCanvas::button_release_event()
3305 switch(gui->current_operation)
3307 case CWINDOW_SCROLL:
3312 do_ruler(0, 0, 0, 1);
3315 case CWINDOW_CAMERA:
3316 mwindow->undo->update_undo_after(_("camera"), LOAD_AUTOMATION);
3319 case CWINDOW_PROJECTOR:
3320 mwindow->undo->update_undo_after(_("projector"), LOAD_AUTOMATION);
3324 case CWINDOW_MASK_CONTROL_IN:
3325 case CWINDOW_MASK_CONTROL_OUT:
3326 case CWINDOW_MASK_TRANSLATE:
3327 // Finish mask operation
3328 gui->mask_keyframe = 0;
3329 mwindow->undo->update_undo_after(_("mask"), LOAD_AUTOMATION);
3332 result = Canvas::button_release_event();
3336 gui->current_operation = CWINDOW_NONE;
3340 void CWindowCanvas::zoom_resize_window(float percentage)
3342 int canvas_w, canvas_h;
3346 // Get required canvas size
3347 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3348 mwindow->edl->session->output_w,
3349 mwindow->edl->session->output_h,
3354 // Estimate window size from current borders
3355 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3356 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3358 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3359 mwindow->session->cwindow_w = new_w;
3360 mwindow->session->cwindow_h = new_h;
3362 mwindow->theme->get_cwindow_sizes(gui,
3363 mwindow->session->cwindow_controls);
3365 // Estimate again from new borders
3366 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3367 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3368 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3370 gui->resize_window(new_w, new_h);
3371 gui->resize_event(new_w, new_h);
3374 void CWindowCanvas::toggle_controls()
3376 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3377 gui->resize_event(gui->get_w(), gui->get_h());
3380 int CWindowCanvas::get_cwindow_controls()
3382 return mwindow->session->cwindow_controls;