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 zoom_panel->zoom_text->add_item(new BC_MenuItem(auto_zoom = _(AUTO_ZOOM)));
204 if( !mwindow->edl->session->cwindow_scrollbars )
205 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, mwindow->theme->ccomposite_h);
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(double value, int update_menu)
374 float zoom = !value ? get_auto_zoom() : value;
375 mwindow->edl->session->cwindow_scrollbars = !value ? 0 : 1;
377 float cx = canvas->get_xscroll() + 0.5f*canvas->w_visible;
378 float cy = canvas->get_yscroll() + 0.5f*canvas->h_visible;
379 float output_x = cx, output_y = cy;
380 canvas->output_to_canvas(mwindow->edl, 0, cx, cy);
381 x = output_x - cx / zoom;
382 y = output_y - cy / zoom;
384 canvas->update_zoom((int)x, (int)y, zoom);
387 zoom_panel->update(value);
388 if( mwindow->edl->session->cwindow_operation == CWINDOW_ZOOM )
389 composite_panel->cpanel_zoom->update(zoom);
391 canvas->reposition_window(mwindow->edl,
392 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
393 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
394 canvas->draw_refresh();
399 void CWindowGUI::set_operation(int value)
401 mwindow->edl->session->cwindow_operation = value;
403 composite_panel->set_operation(value);
404 edit_panel->update();
406 tool_panel->start_tool(value);
407 canvas->draw_refresh();
410 void CWindowGUI::update_tool()
412 tool_panel->update_values();
415 int CWindowGUI::close_event()
417 cwindow->hide_window();
422 int CWindowGUI::keypress_event()
426 switch(get_keypress())
444 if(mwindow->session->cwindow_fullscreen)
445 canvas->stop_fullscreen();
447 canvas->start_fullscreen();
448 lock_window("CWindowGUI::keypress_event 1");
452 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
454 mwindow->gui->unlock_window();
455 lock_window("CWindowGUI::keypress_event 2");
459 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
460 mwindow->clear_entry();
461 mwindow->gui->unlock_window();
462 lock_window("CWindowGUI::keypress_event 3");
466 if(mwindow->session->cwindow_fullscreen)
467 canvas->stop_fullscreen();
468 lock_window("CWindowGUI::keypress_event 4");
475 int shift_down = this->shift_down();
477 mwindow->gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
479 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
480 mwindow->prev_edit_handle(shift_down);
481 mwindow->gui->unlock_window();
483 lock_window("CWindowGUI::keypress_event 1");
489 mwindow->gui->lock_window("CWindowGUI::keypress_event 3");
490 mwindow->move_left();
491 mwindow->gui->unlock_window();
493 lock_window("CWindowGUI::keypress_event 2");
503 int shift_down = this->shift_down();
505 mwindow->gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
507 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
508 mwindow->next_edit_handle(shift_down);
509 mwindow->gui->unlock_window();
511 lock_window("CWindowGUI::keypress_event 2");
517 mwindow->gui->lock_window("CWindowGUI::keypress_event 4");
518 mwindow->move_right();
519 mwindow->gui->unlock_window();
521 lock_window("CWindowGUI::keypress_event 3");
528 if(!result) result = transport->keypress_event();
534 void CWindowGUI::reset_affected()
541 void CWindowGUI::keyboard_zoomin()
543 // if(mwindow->edl->session->cwindow_scrollbars)
545 zoom_panel->zoom_tumbler->handle_up_event();
552 void CWindowGUI::keyboard_zoomout()
554 // if(mwindow->edl->session->cwindow_scrollbars)
556 zoom_panel->zoom_tumbler->handle_down_event();
564 void CWindowGUI::drag_motion()
566 if(get_hidden()) return;
568 if(mwindow->session->current_operation != DRAG_ASSET &&
569 mwindow->session->current_operation != DRAG_VTRANSITION &&
570 mwindow->session->current_operation != DRAG_VEFFECT) return;
571 int need_highlight = cursor_above() && get_cursor_over_window();
572 if( highlighted == need_highlight ) return;
573 highlighted = need_highlight;
574 canvas->draw_refresh();
577 int CWindowGUI::drag_stop()
580 if(get_hidden()) return 0;
581 if( !highlighted ) return 0;
582 if( mwindow->session->current_operation != DRAG_ASSET &&
583 mwindow->session->current_operation != DRAG_VTRANSITION &&
584 mwindow->session->current_operation != DRAG_VEFFECT) return 0;
586 canvas->draw_refresh();
589 if(mwindow->session->current_operation == DRAG_ASSET)
591 if(mwindow->session->drag_assets->total ||
592 mwindow->session->drag_clips->total)
594 mwindow->gui->lock_window("CWindowGUI::drag_stop 5");
595 mwindow->undo->update_undo_before(_("insert assets"), 0);
596 mwindow->gui->unlock_window();
599 if(mwindow->session->drag_assets->total)
601 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
603 mwindow->load_assets(mwindow->session->drag_assets,
604 mwindow->edl->local_session->get_selectionstart(),
606 mwindow->session->track_highlighted,
608 mwindow->edl->session->labels_follow_edits,
609 mwindow->edl->session->plugins_follow_edits,
610 mwindow->edl->session->autos_follow_edits,
614 if(mwindow->session->drag_clips->total)
616 mwindow->gui->lock_window("CWindowGUI::drag_stop 2");
618 mwindow->paste_edls(mwindow->session->drag_clips,
620 mwindow->session->track_highlighted,
621 mwindow->edl->local_session->get_selectionstart(),
622 mwindow->edl->session->labels_follow_edits,
623 mwindow->edl->session->plugins_follow_edits,
624 mwindow->edl->session->autos_follow_edits,
628 if(mwindow->session->drag_assets->total ||
629 mwindow->session->drag_clips->total)
631 mwindow->save_backup();
632 mwindow->restart_brender();
633 mwindow->gui->update(1, 1, 1, 1, 0, 1, 0);
634 mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
635 mwindow->gui->unlock_window();
636 mwindow->sync_parameters(LOAD_ALL);
640 if(mwindow->session->current_operation == DRAG_VEFFECT)
642 //printf("CWindowGUI::drag_stop 1\n");
643 Track *affected_track = cwindow->calculate_affected_track();
644 //printf("CWindowGUI::drag_stop 2\n");
646 mwindow->gui->lock_window("CWindowGUI::drag_stop 3");
647 mwindow->insert_effects_cwindow(affected_track);
648 mwindow->session->current_operation = NO_OPERATION;
649 mwindow->gui->unlock_window();
652 if(mwindow->session->current_operation == DRAG_VTRANSITION)
654 Track *affected_track = cwindow->calculate_affected_track();
655 mwindow->gui->lock_window("CWindowGUI::drag_stop 4");
656 mwindow->paste_transition_cwindow(affected_track);
657 mwindow->session->current_operation = NO_OPERATION;
658 mwindow->gui->unlock_window();
664 void CWindowGUI::update_meters()
666 if(mwindow->edl->session->cwindow_meter != meters->visible)
668 meters->set_meters(meters->meter_count, mwindow->edl->session->cwindow_meter);
669 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
670 resize_event(get_w(), get_h());
675 CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
678 mwindow->theme->cedit_x,
679 mwindow->theme->cedit_y,
680 mwindow->edl->session->editing_mode,
699 this->mwindow = mwindow;
700 this->cwindow = cwindow;
703 #define CWrapper(fn) void CWindowEditing::fn() { \
704 mwindow->gui->lock_window("CWrapper::" #fn); \
706 mwindow->gui->unlock_window(); \
709 CWrapper(copy_selection)
710 CWrapper(splice_selection)
711 CWrapper(overwrite_selection)
712 CWrapper(set_inpoint)
713 CWrapper(set_outpoint)
714 CWrapper(clear_inpoint)
715 CWrapper(clear_outpoint)
717 CWrapper(toggle_label)
725 CWindowMeters::CWindowMeters(MWindow *mwindow,
730 : MeterPanel(mwindow,
736 mwindow->edl->session->audio_channels,
737 mwindow->edl->session->cwindow_meter,
741 this->mwindow = mwindow;
745 CWindowMeters::~CWindowMeters()
749 int CWindowMeters::change_status_event(int new_status)
751 mwindow->edl->session->cwindow_meter = new_status;
752 gui->update_meters();
759 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
760 : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
761 x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
763 this->mwindow = mwindow;
767 CWindowZoom::~CWindowZoom()
771 void CWindowZoom::update(double value)
773 char string[BCSTRLEN];
774 const char *cp = string;
777 int frac = value >= 1.0f ? 1 :
779 value >= .01f ? 3 : 4;
780 sprintf(string, "x %.*f", frac, value);
784 ZoomPanel::update(cp);
787 int CWindowZoom::handle_event()
789 double value = !strcasecmp(gui->auto_zoom, get_text()) ? 0 : get_value();
790 gui->zoom_canvas(value, 0);
797 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
798 : BC_PercentageSlider(x,
807 this->mwindow = mwindow;
808 this->cwindow = cwindow;
809 set_precision(0.00001);
812 CWindowSlider::~CWindowSlider()
816 int CWindowSlider::handle_event()
818 cwindow->update_position((double)get_value());
822 void CWindowSlider::set_position()
824 double new_length = mwindow->edl->tracks->total_playable_length();
825 // if(mwindow->edl->local_session->preview_end <= 0 ||
826 // mwindow->edl->local_session->preview_end > new_length)
827 // mwindow->edl->local_session->preview_end = new_length;
828 // if(mwindow->edl->local_session->preview_start >
829 // mwindow->edl->local_session->preview_end)
830 // mwindow->edl->local_session->preview_start = 0;
833 update(mwindow->theme->cslider_w,
834 mwindow->edl->local_session->get_selectionstart(1),
837 // mwindow->edl->local_session->preview_start,
838 // mwindow->edl->local_session->preview_end);
842 int CWindowSlider::increase_value()
845 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
846 lock_window("CWindowSlider::increase_value");
850 int CWindowSlider::decrease_value()
853 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
854 lock_window("CWindowSlider::decrease_value");
859 // CWindowDestination::CWindowDestination(MWindow *mwindow, CWindowGUI *cwindow, int x, int y)
860 // : BC_PopupTextBox(cwindow,
861 // &cwindow->destinations,
862 // cwindow->destinations.values[cwindow->cwindow->destination]->get_text(),
868 // this->mwindow = mwindow;
869 // this->cwindow = cwindow;
872 // CWindowDestination::~CWindowDestination()
876 // int CWindowDestination::handle_event()
887 CWindowTransport::CWindowTransport(MWindow *mwindow,
891 : PlayTransport(mwindow,
899 EDL* CWindowTransport::get_edl()
904 void CWindowTransport::goto_start()
906 gui->unlock_window();
907 handle_transport(REWIND, 1);
909 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
910 mwindow->goto_start();
911 mwindow->gui->unlock_window();
913 gui->lock_window("CWindowTransport::goto_start 2");
916 void CWindowTransport::goto_end()
918 gui->unlock_window();
919 handle_transport(GOTO_END, 1);
921 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
923 mwindow->gui->unlock_window();
925 gui->lock_window("CWindowTransport::goto_end 2");
930 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
933 mwindow->theme->ccanvas_x,
934 mwindow->theme->ccanvas_y,
935 mwindow->theme->ccanvas_w,
936 mwindow->theme->ccanvas_h,
939 mwindow->edl->session->cwindow_scrollbars)
941 this->mwindow = mwindow;
945 void CWindowCanvas::status_event()
950 int CWindowCanvas::get_fullscreen()
952 return mwindow->session->cwindow_fullscreen;
955 void CWindowCanvas::set_fullscreen(int value)
957 mwindow->session->cwindow_fullscreen = value;
961 void CWindowCanvas::update_zoom(int x, int y, float zoom)
963 use_scrollbars = mwindow->edl->session->cwindow_scrollbars;
965 mwindow->edl->session->cwindow_xscroll = x;
966 mwindow->edl->session->cwindow_yscroll = y;
967 mwindow->edl->session->cwindow_zoom = zoom;
970 void CWindowCanvas::zoom_auto()
972 gui->zoom_canvas(0, 1);
975 int CWindowCanvas::get_xscroll()
977 return mwindow->edl->session->cwindow_xscroll;
980 int CWindowCanvas::get_yscroll()
982 return mwindow->edl->session->cwindow_yscroll;
986 float CWindowCanvas::get_zoom()
988 return mwindow->edl->session->cwindow_zoom;
991 void CWindowCanvas::draw_refresh(int flush)
993 if(get_canvas() && !get_canvas()->get_video_on())
996 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
998 float in_x1, in_y1, in_x2, in_y2;
999 float out_x1, out_y1, out_x2, out_y2;
1000 get_transfers(mwindow->edl,
1010 if(!EQUIV(out_x1, 0) ||
1011 !EQUIV(out_y1, 0) ||
1012 !EQUIV(out_x2, get_canvas()->get_w()) ||
1013 !EQUIV(out_y2, get_canvas()->get_h()))
1015 get_canvas()->clear_box(0,
1017 get_canvas()->get_w(),
1018 get_canvas()->get_h());
1021 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1022 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1025 if(out_x2 > out_x1 &&
1030 // Can't use OpenGL here because it is called asynchronously of the
1031 // playback operation.
1032 get_canvas()->draw_vframe(refresh_frame,
1035 (int)(out_x2 - out_x1),
1036 (int)(out_y2 - out_y1),
1039 (int)(in_x2 - in_x1),
1040 (int)(in_y2 - in_y1),
1046 get_canvas()->clear_box(0,
1048 get_canvas()->get_w(),
1049 get_canvas()->get_h());
1053 get_canvas()->flash(flush);
1055 //printf("CWindowCanvas::draw_refresh 10\n");
1058 #define CROPHANDLE_W 10
1059 #define CROPHANDLE_H 10
1061 void CWindowCanvas::draw_crophandle(int x, int y)
1063 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1071 #define CONTROL_W 10
1072 #define CONTROL_H 10
1073 #define FIRST_CONTROL_W 20
1074 #define FIRST_CONTROL_H 20
1076 #define BC_INFINITY 65536
1078 #define RULERHANDLE_W 16
1079 #define RULERHANDLE_H 16
1083 int CWindowCanvas::do_ruler(int draw,
1089 float x1 = mwindow->edl->session->ruler_x1;
1090 float y1 = mwindow->edl->session->ruler_y1;
1091 float x2 = mwindow->edl->session->ruler_x2;
1092 float y2 = mwindow->edl->session->ruler_y2;
1093 float canvas_x1 = x1;
1094 float canvas_y1 = y1;
1095 float canvas_x2 = x2;
1096 float canvas_y2 = y2;
1097 float output_x = get_cursor_x();
1098 float output_y = get_cursor_y();
1099 float canvas_cursor_x = output_x;
1100 float canvas_cursor_y = output_y;
1102 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1103 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1104 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1105 mwindow->session->cwindow_output_x = roundf(output_x);
1106 mwindow->session->cwindow_output_y = roundf(output_y);
1108 if(button_press && get_buttonpress() == 1)
1110 gui->ruler_handle = -1;
1111 gui->ruler_translate = 0;
1114 gui->ruler_translate = 1;
1115 gui->ruler_origin_x = x1;
1116 gui->ruler_origin_y = y1;
1119 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1120 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1121 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1122 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1124 gui->ruler_handle = 0;
1125 gui->ruler_origin_x = x1;
1126 gui->ruler_origin_y = y1;
1129 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1130 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1131 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1132 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1134 gui->ruler_handle = 1;
1135 gui->ruler_origin_x = x2;
1136 gui->ruler_origin_y = y2;
1140 // Start new selection
1141 if(!gui->ruler_translate &&
1142 (gui->ruler_handle < 0 ||
1147 do_ruler(1, 0, 0, 0);
1148 get_canvas()->flash();
1149 gui->ruler_handle = 1;
1150 mwindow->edl->session->ruler_x1 = output_x;
1151 mwindow->edl->session->ruler_y1 = output_y;
1152 mwindow->edl->session->ruler_x2 = output_x;
1153 mwindow->edl->session->ruler_y2 = output_y;
1154 gui->ruler_origin_x = mwindow->edl->session->ruler_x2;
1155 gui->ruler_origin_y = mwindow->edl->session->ruler_y2;
1158 gui->x_origin = output_x;
1159 gui->y_origin = output_y;
1160 gui->current_operation = CWINDOW_RULER;
1161 gui->tool_panel->raise_window();
1167 if(gui->current_operation == CWINDOW_RULER)
1169 if(gui->ruler_translate)
1172 do_ruler(1, 0, 0, 0);
1173 float x_difference = mwindow->edl->session->ruler_x1;
1174 float y_difference = mwindow->edl->session->ruler_y1;
1175 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1176 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1177 x_difference -= mwindow->edl->session->ruler_x1;
1178 y_difference -= mwindow->edl->session->ruler_y1;
1179 mwindow->edl->session->ruler_x2 -= x_difference;
1180 mwindow->edl->session->ruler_y2 -= y_difference;
1182 do_ruler(1, 0, 0, 0);
1183 get_canvas()->flash();
1187 switch(gui->ruler_handle)
1190 do_ruler(1, 0, 0, 0);
1191 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1192 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1193 if(gui->alt_down() || gui->ctrl_down())
1195 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1196 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1200 double distance_value =
1201 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1202 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1203 if(angle_value < 22)
1204 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2;
1206 if(angle_value > 67)
1207 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2;
1209 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 &&
1210 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1212 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1213 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1216 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 && mwindow->edl->session->ruler_y1 > mwindow->edl->session->ruler_y2)
1218 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1219 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1222 if(mwindow->edl->session->ruler_x1 > mwindow->edl->session->ruler_x2 &&
1223 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1225 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1226 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1230 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1231 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1234 do_ruler(1, 0, 0, 0);
1235 get_canvas()->flash();
1240 do_ruler(1, 0, 0, 0);
1241 mwindow->edl->session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1242 mwindow->edl->session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1243 if(gui->alt_down() || gui->ctrl_down())
1245 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1246 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1250 double distance_value =
1251 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1252 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1253 if(angle_value < 22)
1254 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1;
1256 if(angle_value > 67)
1257 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1;
1259 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1260 mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1262 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1263 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1266 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1267 mwindow->edl->session->ruler_y2 > mwindow->edl->session->ruler_y1)
1269 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1270 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1273 if(mwindow->edl->session->ruler_x2 > mwindow->edl->session->ruler_x1 && mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1275 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1276 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1280 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1281 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1284 do_ruler(1, 0, 0, 0);
1285 get_canvas()->flash();
1289 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1293 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1298 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1299 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1300 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1301 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1303 set_cursor(UPRIGHT_ARROW_CURSOR);
1306 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1307 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1308 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1309 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1311 set_cursor(UPRIGHT_ARROW_CURSOR);
1314 set_cursor(CROSS_CURSOR);
1316 // Update current position
1321 // Assume no ruler measurement if 0 length
1322 if(draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)))
1324 get_canvas()->set_inverse();
1325 get_canvas()->set_color(WHITE);
1326 get_canvas()->draw_line((int)canvas_x1,
1330 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1332 roundf(canvas_x1) + RULERHANDLE_W / 2,
1334 get_canvas()->draw_line(roundf(canvas_x1),
1335 roundf(canvas_y1) - RULERHANDLE_H / 2,
1337 roundf(canvas_y1) + RULERHANDLE_H / 2);
1338 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1340 roundf(canvas_x2) + RULERHANDLE_W / 2,
1342 get_canvas()->draw_line(roundf(canvas_x2),
1343 roundf(canvas_y2) - RULERHANDLE_H / 2,
1345 roundf(canvas_y2) + RULERHANDLE_H / 2);
1346 get_canvas()->set_opaque();
1353 static inline double line_dist(float cx,float cy, float tx,float ty)
1355 double dx = tx-cx, dy = ty-cy;
1356 return sqrt(dx*dx + dy*dy);
1359 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1361 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1362 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1366 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1367 int button_press, int cursor_motion, int draw)
1369 // Retrieve points from top recordable track
1370 //printf("CWindowCanvas::do_mask 1\n");
1371 Track *track = gui->cwindow->calculate_affected_track();
1372 //printf("CWindowCanvas::do_mask 2\n");
1374 if(!track) return 0;
1375 //printf("CWindowCanvas::do_mask 3\n");
1377 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1378 int64_t position = track->to_units(
1379 mwindow->edl->local_session->get_selectionstart(1),
1381 ArrayList<MaskPoint*> points;
1383 // Determine the points based on whether
1384 // new keyframes will be generated or drawing is performed.
1385 // If keyframe generation occurs, use the interpolated mask.
1386 // If no keyframe generation occurs, use the previous mask.
1387 int use_interpolated = 0;
1388 if(button_press || cursor_motion) {
1389 #ifdef USE_KEYFRAME_SPANNING
1390 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1391 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1394 mask_autos->get_prev_auto(track->to_units(selection_start, 0),
1395 PLAY_FORWARD, first, 1);
1397 mask_autos->get_prev_auto(track->to_units(selection_end, 0),
1398 PLAY_FORWARD, last, 1);
1400 if(last == first && (!mwindow->edl->session->auto_keyframes))
1401 use_interpolated = 0;
1403 // If keyframe spanning occurs, use the interpolated points.
1404 // If new keyframe is generated, use the interpolated points.
1405 use_interpolated = 1;
1408 if(mwindow->edl->session->auto_keyframes)
1409 use_interpolated = 1;
1413 use_interpolated = 1;
1415 if(use_interpolated) {
1416 // Interpolate the points to get exactly what is being rendered at this position.
1417 mask_autos->get_points(&points,
1418 mwindow->edl->session->cwindow_mask,
1423 // Use the prev mask
1425 mask_autos->get_prev_auto(position,
1429 ((MaskAuto*)prev)->get_points(&points,
1430 mwindow->edl->session->cwindow_mask);
1433 // Projector zooms relative to the center of the track output.
1434 float half_track_w = (float)track->track_w / 2;
1435 float half_track_h = (float)track->track_h / 2;
1436 // Translate mask to projection
1437 float projector_x, projector_y, projector_z;
1438 track->automation->get_projector(
1439 &projector_x, &projector_y, &projector_z,
1440 position, PLAY_FORWARD);
1443 // Get position of cursor relative to mask
1444 float cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
1445 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1446 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1448 projector_x += mwindow->edl->session->output_w / 2;
1449 projector_y += mwindow->edl->session->output_h / 2;
1450 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1451 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1453 // Fix cursor origin
1455 gui->x_origin = mask_cursor_x;
1456 gui->y_origin = mask_cursor_y;
1460 // Points of closest line
1461 int shortest_point1 = -1;
1462 int shortest_point2 = -1;
1464 int shortest_point = -1;
1465 // Distance to closest line
1466 float shortest_line_distance = BC_INFINITY;
1467 // Distance to closest point
1468 float shortest_point_distance = BC_INFINITY;
1469 int selected_point = -1;
1470 int selected_control_point = -1;
1471 float selected_control_point_distance = BC_INFINITY;
1472 ArrayList<int> x_points;
1473 ArrayList<int> y_points;
1475 if(!cursor_motion) {
1477 get_canvas()->set_color(WHITE);
1478 get_canvas()->set_inverse();
1480 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1482 // Never draw closed polygon and a closed
1483 // polygon is harder to add points to.
1484 for(int i = 0; i < points.size() && !result; i++) {
1485 MaskPoint *point1 = points.get(i);
1486 MaskPoint *point2 = (i >= points.size() - 1) ?
1487 points.get(0) : points.get(i + 1);
1489 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1490 if(point_distance1 < shortest_point_distance || shortest_point < 0) {
1491 shortest_point_distance = point_distance1;
1495 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1496 if(point_distance2 < shortest_point_distance || shortest_point < 0) {
1497 shortest_point_distance = point_distance2;
1498 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1502 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1504 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1505 //point1->x, point1->y, point2->x, point2->y, projector_z);
1506 for(int j = 0; j <= segments && !result; j++) {
1507 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1508 float x0 = point1->x, y0 = point1->y;
1509 float x1 = point1->x + point1->control_x2;
1510 float y1 = point1->y + point1->control_y2;
1511 float x2 = point2->x + point2->control_x1;
1512 float y2 = point2->y + point2->control_y1;
1513 float x3 = point2->x, y3 = point2->y;
1514 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1515 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1516 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1517 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1518 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1519 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1520 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1521 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1523 float t = (float)j / segments;
1524 float tpow2 = t * t;
1525 float tpow3 = t * t * t;
1527 float invtpow2 = invt * invt;
1528 float invtpow3 = invt * invt * invt;
1530 float x = ( invtpow3 * x0
1531 + 3 * t * invtpow2 * x1
1532 + 3 * tpow2 * invt * x2
1534 float y = ( invtpow3 * y0
1535 + 3 * t * invtpow2 * y1
1536 + 3 * tpow2 * invt * y2
1538 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1539 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1540 // Test new point addition
1542 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1544 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1545 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1546 if(line_distance < shortest_line_distance ||
1547 shortest_point1 < 0) {
1548 shortest_line_distance = line_distance;
1549 shortest_point1 = i;
1550 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1551 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1552 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1555 // Test existing point selection
1557 if(gui->ctrl_down()) {
1558 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1560 if(distance < selected_control_point_distance) {
1562 selected_control_point = 1;
1563 selected_control_point_distance = distance;
1567 if(!gui->shift_down()) {
1568 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1569 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
1574 selected_point = shortest_point;
1577 // Test second point
1578 if(gui->ctrl_down()) {
1579 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1581 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1582 if(distance < selected_control_point_distance) {
1583 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1584 selected_control_point = 0;
1585 selected_control_point_distance = distance;
1588 else if(i < points.size() - 1) {
1589 if(!gui->shift_down()) {
1590 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1591 if(test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3)) {
1592 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1596 selected_point = shortest_point;
1601 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1605 if(draw) { // Draw joining line
1606 x_points.append((int)canvas_x);
1607 y_points.append((int)canvas_y);
1611 if(draw) { // Draw second anchor
1612 if(i < points.size() - 1) {
1613 if(i == gui->affected_point - 1)
1614 get_canvas()->draw_disc(
1615 (int)canvas_x - CONTROL_W / 2,
1616 (int)canvas_y - CONTROL_W / 2,
1617 CONTROL_W, CONTROL_H);
1619 get_canvas()->draw_circle(
1620 (int)canvas_x - CONTROL_W / 2,
1621 (int)canvas_y - CONTROL_W / 2,
1622 CONTROL_W, CONTROL_H);
1623 // char string[BCTEXTLEN];
1624 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1625 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1627 // Draw second control point.
1628 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1629 get_canvas()->draw_line(
1630 (int)canvas_x, (int)canvas_y,
1631 (int)canvas_x2, (int)canvas_y2);
1632 get_canvas()->draw_rectangle(
1633 (int)canvas_x2 - CONTROL_W / 2,
1634 (int)canvas_y2 - CONTROL_H / 2,
1635 CONTROL_W, CONTROL_H);
1640 // Draw first anchor
1641 if(i == 0 && draw) {
1642 char mask_label[BCSTRLEN];
1643 sprintf(mask_label, "%d",
1644 mwindow->edl->session->cwindow_mask);
1645 get_canvas()->draw_text(
1646 (int)canvas_x - FIRST_CONTROL_W,
1647 (int)canvas_y - FIRST_CONTROL_H,
1650 get_canvas()->draw_disc(
1651 (int)canvas_x - FIRST_CONTROL_W / 2,
1652 (int)canvas_y - FIRST_CONTROL_H / 2,
1653 FIRST_CONTROL_W, FIRST_CONTROL_H);
1656 // Draw first control point.
1658 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1659 get_canvas()->draw_line(
1660 (int)canvas_x, (int)canvas_y,
1661 (int)canvas_x1, (int)canvas_y1);
1662 get_canvas()->draw_rectangle(
1663 (int)canvas_x1 - CONTROL_W / 2,
1664 (int)canvas_y1 - CONTROL_H / 2,
1665 CONTROL_W, CONTROL_H);
1667 x_points.append((int)canvas_x);
1668 y_points.append((int)canvas_y);
1671 //printf("CWindowCanvas::do_mask 1\n");
1675 //printf("CWindowCanvas::do_mask 1\n");
1678 get_canvas()->draw_polygon(&x_points, &y_points);
1679 get_canvas()->set_opaque();
1681 //printf("CWindowCanvas::do_mask 1\n");
1684 if(button_press && !result) {
1685 gui->affected_track = gui->cwindow->calculate_affected_track();
1687 // Get keyframe outside the EDL to edit. This must be rendered
1688 // instead of the EDL keyframes when it exists. Then it must be
1689 // applied to the EDL keyframes on buttonrelease.
1690 if(gui->affected_track) {
1691 #ifdef USE_KEYFRAME_SPANNING
1692 // Make copy of current parameters in local keyframe
1693 gui->mask_keyframe =
1694 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1697 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1700 gui->mask_keyframe =
1701 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1706 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1709 // Translate entire keyframe
1710 if(gui->alt_down() && mask->points.size()) {
1711 mwindow->undo->update_undo_before(_("mask translate"), 0);
1712 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1713 gui->affected_point = 0;
1716 // Existing point or control point was selected
1717 if(selected_point >= 0) {
1718 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1719 gui->affected_point = selected_point;
1721 if(selected_control_point == 0)
1722 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1724 if(selected_control_point == 1)
1725 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1727 gui->current_operation = mwindow->edl->session->cwindow_operation;
1729 else // No existing point or control point was selected so create a new one
1730 if(!gui->ctrl_down() && !gui->alt_down()) {
1731 mwindow->undo->update_undo_before(_("mask point"), 0);
1732 // Create the template
1733 MaskPoint *point = new MaskPoint;
1734 point->x = mask_cursor_x;
1735 point->y = mask_cursor_y;
1736 point->control_x1 = 0;
1737 point->control_y1 = 0;
1738 point->control_x2 = 0;
1739 point->control_y2 = 0;
1742 if(shortest_point2 < shortest_point1) {
1743 shortest_point2 ^= shortest_point1;
1744 shortest_point1 ^= shortest_point2;
1745 shortest_point2 ^= shortest_point1;
1750 // printf("CWindowGUI::do_mask 40\n");
1751 // mwindow->edl->dump();
1752 // printf("CWindowGUI::do_mask 50\n");
1756 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1757 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1758 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1760 // Append to end of list
1761 if( shortest_point1 == shortest_point2 ||
1762 labs(shortest_point1 - shortest_point2) > 1) {
1763 #ifdef USE_KEYFRAME_SPANNING
1765 MaskPoint *new_point = new MaskPoint;
1766 points.append(new_point);
1767 *new_point = *point;
1768 gui->affected_point = points.size() - 1;
1772 // Need to apply the new point to every keyframe
1773 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1774 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1775 MaskPoint *new_point = new MaskPoint;
1776 submask->points.append(new_point);
1777 *new_point = *point;
1778 if(current == (MaskAuto*)mask_autos->default_auto)
1779 current = (MaskAuto*)mask_autos->first;
1781 current = (MaskAuto*)NEXT;
1783 gui->affected_point = mask->points.size() - 1;
1789 // Insert between 2 points, shifting back point 2
1790 if(shortest_point1 >= 0 && shortest_point2 >= 0) {
1792 #ifdef USE_KEYFRAME_SPANNING
1793 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1795 if(points.size() >= shortest_point2) {
1796 MaskPoint *new_point = new MaskPoint;
1798 for(int i = points.size() - 1;
1799 i > shortest_point2;
1801 points.values[i] = points.values[i - 1];
1802 points.values[shortest_point2] = new_point;
1804 *new_point = *point;
1809 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1810 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1811 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1813 if(submask->points.size() >= shortest_point2) {
1814 MaskPoint *new_point = new MaskPoint;
1815 submask->points.append(0);
1816 for(int i = submask->points.size() - 1;
1817 i > shortest_point2;
1819 submask->points.values[i] = submask->points.values[i - 1];
1820 submask->points.values[shortest_point2] = new_point;
1822 *new_point = *point;
1825 if(current == (MaskAuto*)mask_autos->default_auto)
1826 current = (MaskAuto*)mask_autos->first;
1828 current = (MaskAuto*)NEXT;
1832 gui->affected_point = shortest_point2;
1837 // printf("CWindowGUI::do_mask 20\n");
1838 // mwindow->edl->dump();
1839 // printf("CWindowGUI::do_mask 30\n");
1842 //printf("CWindowCanvas::do_mask 1\n");
1843 // Create the first point.
1844 #ifdef USE_KEYFRAME_SPANNING
1845 MaskPoint *new_point = new MaskPoint;
1846 points.append(new_point);
1847 *new_point = *point;
1848 gui->affected_point = points.size() - 1;
1850 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1851 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1852 MaskPoint *new_point = new MaskPoint;
1853 submask->points.append(new_point);
1854 *new_point = *point;
1855 if(current == (MaskAuto*)mask_autos->default_auto)
1856 current = (MaskAuto*)mask_autos->first;
1858 current = (MaskAuto*)NEXT;
1860 gui->affected_point = points.size() - 1;
1863 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
1866 gui->current_operation = mwindow->edl->session->cwindow_operation;
1867 // Delete the template
1876 if(button_press && result) {
1877 #ifdef USE_KEYFRAME_SPANNING
1878 MaskPoint *point = points.values[gui->affected_point];
1879 gui->center_x = point->x;
1880 gui->center_y = point->y;
1881 gui->control_in_x = point->control_x1;
1882 gui->control_in_y = point->control_y1;
1883 gui->control_out_x = point->control_x2;
1884 gui->control_out_y = point->control_y2;
1885 gui->tool_panel->raise_window();
1887 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1888 MaskPoint *point = mask->points.values[gui->affected_point];
1889 gui->center_x = point->x;
1890 gui->center_y = point->y;
1891 gui->control_in_x = point->control_x1;
1892 gui->control_in_y = point->control_y1;
1893 gui->control_out_x = point->control_x2;
1894 gui->control_out_y = point->control_y2;
1895 gui->tool_panel->raise_window();
1899 //printf("CWindowCanvas::do_mask 8\n");
1902 #ifdef USE_KEYFRAME_SPANNING
1903 // Must update the reference keyframes for every cursor motion
1904 gui->mask_keyframe =
1905 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1908 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1911 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1913 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1914 if( gui->affected_point >= 0 && gui->affected_point < mask->points.size() &&
1915 gui->current_operation != CWINDOW_NONE) {
1916 // mwindow->undo->update_undo_before(_("mask point"), this);
1917 #ifdef USE_KEYFRAME_SPANNING
1918 MaskPoint *point = points.get(gui->affected_point);
1920 MaskPoint *point = mask->points.get(gui->affected_point);
1922 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
1923 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask->points.size(), gui->affected_point);
1925 float last_x = point->x;
1926 float last_y = point->y;
1927 float last_control_x1 = point->control_x1;
1928 float last_control_y1 = point->control_y1;
1929 float last_control_x2 = point->control_x2;
1930 float last_control_y2 = point->control_y2;
1932 switch(gui->current_operation) {
1934 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1935 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
1936 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
1939 case CWINDOW_MASK_CONTROL_IN:
1940 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
1941 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
1944 case CWINDOW_MASK_CONTROL_OUT:
1945 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
1946 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
1949 case CWINDOW_MASK_TRANSLATE:
1950 #ifdef USE_KEYFRAME_SPANNING
1951 for(int i = 0; i < points.size(); i++) {
1952 points.values[i]->x += mask_cursor_x - gui->x_origin;
1953 points.values[i]->y += mask_cursor_y - gui->y_origin;
1956 for(int i = 0; i < mask->points.size(); i++) {
1957 mask->points.values[i]->x += mask_cursor_x - gui->x_origin;
1958 mask->points.values[i]->y += mask_cursor_y - gui->y_origin;
1961 gui->x_origin = mask_cursor_x;
1962 gui->y_origin = mask_cursor_y;
1966 if( !EQUIV(last_x, point->x) ||
1967 !EQUIV(last_y, point->y) ||
1968 !EQUIV(last_control_x1, point->control_x1) ||
1969 !EQUIV(last_control_y1, point->control_y1) ||
1970 !EQUIV(last_control_x2, point->control_x2) ||
1971 !EQUIV(last_control_y2, point->control_y2)) {
1977 if(gui->current_operation == CWINDOW_NONE) {
1978 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
1980 for(int i = 0; i < points.size() && !over_point; i++) {
1981 MaskPoint *point = points.get(i);
1982 float x0 = point->x;
1983 float y0 = point->y;
1984 float x1 = point->x + point->control_x1;
1985 float y1 = point->y + point->control_y1;
1986 float x2 = point->x + point->control_x2;
1987 float y2 = point->y + point->control_y2;
1988 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1989 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1991 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1992 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
1996 if(!over_point && gui->ctrl_down()) {
1997 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1998 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1999 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2000 if(test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1)) {
2004 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2005 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2006 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2007 if(test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2)) {
2014 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2019 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2022 #ifdef USE_KEYFRAME_SPANNING
2023 // Must commit change after operation.
2024 if(rerender && track) {
2025 // Swap EDL keyframe with original.
2026 // Apply new values to keyframe span
2027 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2028 temp_keyframe.copy_data(gui->mask_keyframe);
2029 // Apply interpolated points back to keyframe
2030 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2031 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2032 mask_autos->update_parameter(&temp_keyframe);
2036 points.remove_all_objects();
2037 //printf("CWindowCanvas::do_mask 20\n");
2041 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2044 int radius = mwindow->edl->session->eyedrop_radius;
2052 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2057 row1 = gui->eyedrop_y - radius;
2058 row2 = gui->eyedrop_y + radius;
2059 column1 = gui->eyedrop_x - radius;
2060 column2 = gui->eyedrop_x + radius;
2062 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2063 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2064 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2065 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2067 if(row2 <= row1) row2 = row1 + 1;
2068 if(column2 <= column1) column2 = column1 + 1;
2075 output_to_canvas(mwindow->edl, 0, x1, y1);
2076 output_to_canvas(mwindow->edl, 0, x2, y2);
2077 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2079 if(x2 - x1 >= 1 && y2 - y1 >= 1)
2081 get_canvas()->set_inverse();
2082 get_canvas()->set_color(WHITE);
2084 get_canvas()->draw_rectangle((int)x1,
2089 get_canvas()->set_opaque();
2090 get_canvas()->flash();
2098 gui->current_operation = CWINDOW_EYEDROP;
2099 gui->tool_panel->raise_window();
2102 if(gui->current_operation == CWINDOW_EYEDROP)
2104 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2106 // Get color out of frame.
2107 // Doesn't work during playback because that bypasses the refresh frame.
2108 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2110 float cursor_x = get_cursor_x();
2111 float cursor_y = get_cursor_y();
2112 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2113 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2114 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2116 row1 = cursor_y - radius;
2117 row2 = cursor_y + radius;
2118 column1 = cursor_x - radius;
2119 column2 = cursor_x + radius;
2120 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2121 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2122 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2123 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2124 if(row2 <= row1) row2 = row1 + 1;
2125 if(column2 <= column1) column2 = column1 + 1;
2129 if(gui->eyedrop_visible)
2132 do_eyedrop(temp, 0, 1);
2133 gui->eyedrop_visible = 0;
2136 gui->eyedrop_x = cursor_x;
2137 gui->eyedrop_y = cursor_y;
2142 do_eyedrop(temp, 0, 1);
2143 gui->eyedrop_visible = 1;
2146 // Decompression coefficients straight out of jpeglib
2147 #define V_TO_R 1.40200
2148 #define V_TO_G -0.71414
2150 #define U_TO_G -0.34414
2151 #define U_TO_B 1.77200
2153 #define GET_COLOR(type, components, max, do_yuv) \
2155 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2157 float red = (float)*row++ / max; \
2158 float green = (float)*row++ / max; \
2159 float blue = (float)*row++ / max; \
2162 mwindow->edl->local_session->red += red + V_TO_R * (blue - 0.5); \
2163 mwindow->edl->local_session->green += red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
2164 mwindow->edl->local_session->blue += red + U_TO_B * (green - 0.5); \
2168 mwindow->edl->local_session->red += red; \
2169 mwindow->edl->local_session->green += green; \
2170 mwindow->edl->local_session->blue += blue; \
2176 mwindow->edl->local_session->red = 0;
2177 mwindow->edl->local_session->green = 0;
2178 mwindow->edl->local_session->blue = 0;
2179 for(int i = row1; i < row2; i++)
2181 for(int j = column1; j < column2; j++)
2183 switch(refresh_frame->get_color_model())
2186 GET_COLOR(unsigned char, 3, 0xff, 1);
2189 GET_COLOR(unsigned char, 4, 0xff, 1);
2192 GET_COLOR(uint16_t, 3, 0xffff, 1);
2194 case BC_YUVA16161616:
2195 GET_COLOR(uint16_t, 4, 0xffff, 1);
2198 GET_COLOR(unsigned char, 3, 0xff, 0);
2201 GET_COLOR(unsigned char, 4, 0xff, 0);
2204 GET_COLOR(float, 3, 1.0, 0);
2207 GET_COLOR(float, 4, 1.0, 0);
2213 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2214 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2215 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2220 mwindow->edl->local_session->red = 0;
2221 mwindow->edl->local_session->green = 0;
2222 mwindow->edl->local_session->blue = 0;
2223 gui->eyedrop_visible = 0;
2232 // Can't rerender since the color value is from the output of any effect it
2235 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2241 void CWindowCanvas::draw_overlays()
2243 if(mwindow->edl->session->safe_regions)
2245 draw_safe_regions();
2248 if(mwindow->edl->session->cwindow_scrollbars)
2250 // Always draw output rectangle
2251 float x1, y1, x2, y2;
2253 x2 = mwindow->edl->session->output_w;
2255 y2 = mwindow->edl->session->output_h;
2256 output_to_canvas(mwindow->edl, 0, x1, y1);
2257 output_to_canvas(mwindow->edl, 0, x2, y2);
2259 get_canvas()->set_inverse();
2260 get_canvas()->set_color(WHITE);
2262 get_canvas()->draw_rectangle((int)x1,
2267 get_canvas()->set_opaque();
2270 if(gui->highlighted)
2272 get_canvas()->set_color(WHITE);
2273 get_canvas()->set_inverse();
2274 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2275 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2276 get_canvas()->set_opaque();
2279 int temp1 = 0, temp2 = 0;
2280 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2281 switch(mwindow->edl->session->cwindow_operation)
2283 case CWINDOW_CAMERA:
2287 case CWINDOW_PROJECTOR:
2296 do_mask(temp1, temp2, 0, 0, 1);
2300 do_ruler(1, 0, 0, 0);
2303 case CWINDOW_EYEDROP:
2304 if(gui->eyedrop_visible)
2307 do_eyedrop(rerender, 0, 1);
2308 gui->eyedrop_visible = 1;
2314 void CWindowCanvas::draw_safe_regions()
2316 float action_x1, action_x2, action_y1, action_y2;
2317 float title_x1, title_x2, title_y1, title_y2;
2319 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2320 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2321 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2322 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2323 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2324 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2325 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2326 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2328 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2329 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2330 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2331 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2333 get_canvas()->set_inverse();
2334 get_canvas()->set_color(WHITE);
2336 get_canvas()->draw_rectangle((int)action_x1,
2338 (int)(action_x2 - action_x1),
2339 (int)(action_y2 - action_y1));
2340 get_canvas()->draw_rectangle((int)title_x1,
2342 (int)(title_x2 - title_x1),
2343 (int)(title_y2 - title_y1));
2345 get_canvas()->set_opaque();
2348 void CWindowCanvas::reset_keyframe(int do_camera)
2350 FloatAuto *x_keyframe = 0;
2351 FloatAuto *y_keyframe = 0;
2352 FloatAuto *z_keyframe = 0;
2353 Track *affected_track = 0;
2355 affected_track = gui->cwindow->calculate_affected_track();
2359 gui->cwindow->calculate_affected_autos(&x_keyframe,
2368 x_keyframe->set_value(0);
2369 y_keyframe->set_value(0);
2370 z_keyframe->set_value(1);
2372 mwindow->sync_parameters(CHANGE_PARAMS);
2377 void CWindowCanvas::reset_camera()
2382 void CWindowCanvas::reset_projector()
2387 int CWindowCanvas::test_crop(int button_press, int &redraw)
2390 int handle_selected = -1;
2391 float x1 = mwindow->edl->session->crop_x1;
2392 float y1 = mwindow->edl->session->crop_y1;
2393 float x2 = mwindow->edl->session->crop_x2;
2394 float y2 = mwindow->edl->session->crop_y2;
2395 float cursor_x = get_cursor_x();
2396 float cursor_y = get_cursor_y();
2397 float canvas_x1 = x1;
2398 float canvas_y1 = y1;
2399 float canvas_x2 = x2;
2400 float canvas_y2 = y2;
2401 float canvas_cursor_x = cursor_x;
2402 float canvas_cursor_y = cursor_y;
2404 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2405 // Use screen normalized coordinates for hot spot tests.
2406 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2407 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2410 if(gui->current_operation == CWINDOW_CROP)
2412 handle_selected = gui->crop_handle;
2415 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2416 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2418 handle_selected = 0;
2419 gui->crop_origin_x = x1;
2420 gui->crop_origin_y = y1;
2423 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2424 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2426 handle_selected = 1;
2427 gui->crop_origin_x = x2;
2428 gui->crop_origin_y = y1;
2431 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2432 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2434 handle_selected = 2;
2435 gui->crop_origin_x = x1;
2436 gui->crop_origin_y = y2;
2439 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2440 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2442 handle_selected = 3;
2443 gui->crop_origin_x = x2;
2444 gui->crop_origin_y = y2;
2449 gui->crop_origin_x = cursor_x;
2450 gui->crop_origin_y = cursor_y;
2453 // printf("test crop %d %d\n",
2454 // gui->current_operation,
2455 // handle_selected);
2462 gui->crop_translate = 1;
2463 gui->crop_origin_x1 = x1;
2464 gui->crop_origin_y1 = y1;
2465 gui->crop_origin_x2 = x2;
2466 gui->crop_origin_y2 = y2;
2469 gui->crop_translate = 0;
2471 gui->current_operation = CWINDOW_CROP;
2472 gui->crop_handle = handle_selected;
2473 gui->x_origin = cursor_x;
2474 gui->y_origin = cursor_y;
2475 gui->tool_panel->raise_window();
2478 if(handle_selected < 0 && !gui->crop_translate)
2482 mwindow->edl->session->crop_x1 = (int)x1;
2483 mwindow->edl->session->crop_y1 = (int)y1;
2484 mwindow->edl->session->crop_x2 = (int)x2;
2485 mwindow->edl->session->crop_y2 = (int)y2;
2490 // Translate all 4 points
2491 if(gui->current_operation == CWINDOW_CROP && gui->crop_translate)
2493 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2494 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2495 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2496 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2498 mwindow->edl->session->crop_x1 = (int)x1;
2499 mwindow->edl->session->crop_y1 = (int)y1;
2500 mwindow->edl->session->crop_x2 = (int)x2;
2501 mwindow->edl->session->crop_y2 = (int)y2;
2507 if(gui->current_operation == CWINDOW_CROP)
2509 switch(gui->crop_handle)
2512 x1 = gui->crop_origin_x;
2513 y1 = gui->crop_origin_y;
2514 x2 = gui->crop_origin_x;
2515 y2 = gui->crop_origin_y;
2516 if(cursor_x < gui->x_origin)
2518 if(cursor_y < gui->y_origin)
2524 if(cursor_y >= gui->y_origin)
2531 if(cursor_x >= gui->x_origin)
2533 if(cursor_y < gui->y_origin)
2539 if(cursor_y >= gui->y_origin)
2546 // printf("test crop %d %d %d %d\n",
2547 // mwindow->edl->session->crop_x1,
2548 // mwindow->edl->session->crop_y1,
2549 // mwindow->edl->session->crop_x2,
2550 // mwindow->edl->session->crop_y2);
2553 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2554 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2557 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2558 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2561 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2562 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2565 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2566 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2570 if(!EQUIV(mwindow->edl->session->crop_x1, x1) ||
2571 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2572 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2573 !EQUIV(mwindow->edl->session->crop_y2, y2))
2580 switch (gui->crop_handle)
2582 case 0: gui->crop_handle = 1; break;
2583 case 1: gui->crop_handle = 0; break;
2584 case 2: gui->crop_handle = 3; break;
2585 case 3: gui->crop_handle = 2; break;
2595 switch (gui->crop_handle)
2597 case 0: gui->crop_handle = 2; break;
2598 case 1: gui->crop_handle = 3; break;
2599 case 2: gui->crop_handle = 0; break;
2600 case 3: gui->crop_handle = 1; break;
2605 mwindow->edl->session->crop_x1 = (int)x1;
2606 mwindow->edl->session->crop_y1 = (int)y1;
2607 mwindow->edl->session->crop_x2 = (int)x2;
2608 mwindow->edl->session->crop_y2 = (int)y2;
2614 // Update cursor font
2615 if(handle_selected >= 0)
2617 switch(handle_selected)
2620 set_cursor(UPLEFT_RESIZE);
2623 set_cursor(UPRIGHT_RESIZE);
2626 set_cursor(DOWNLEFT_RESIZE);
2629 set_cursor(DOWNRIGHT_RESIZE);
2636 set_cursor(ARROW_CURSOR);
2638 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2642 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2643 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2644 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2645 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2646 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2647 // mwindow->edl->session->crop_x2,
2648 // mwindow->edl->session->crop_y2,
2649 // mwindow->edl->calculate_output_w(0),
2650 // mwindow->edl->calculate_output_h(0));
2656 void CWindowCanvas::draw_crop()
2658 get_canvas()->set_inverse();
2659 get_canvas()->set_color(WHITE);
2661 float x1 = mwindow->edl->session->crop_x1;
2662 float y1 = mwindow->edl->session->crop_y1;
2663 float x2 = mwindow->edl->session->crop_x2;
2664 float y2 = mwindow->edl->session->crop_y2;
2666 output_to_canvas(mwindow->edl, 0, x1, y1);
2667 output_to_canvas(mwindow->edl, 0, x2, y2);
2669 if(x2 - x1 && y2 - y1)
2670 get_canvas()->draw_rectangle((int)x1,
2675 draw_crophandle((int)x1, (int)y1);
2676 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2677 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2678 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2679 get_canvas()->set_opaque();
2689 void CWindowCanvas::draw_bezier(int do_camera)
2691 Track *track = gui->cwindow->calculate_affected_track();
2698 int64_t position = track->to_units(
2699 mwindow->edl->local_session->get_selectionstart(1),
2702 track->automation->get_projector(¢er_x,
2708 // center_x += track->track_w / 2;
2709 // center_y += track->track_h / 2;
2710 center_x += mwindow->edl->session->output_w / 2;
2711 center_y += mwindow->edl->session->output_h / 2;
2712 float track_x1 = center_x - track->track_w / 2 * center_z;
2713 float track_y1 = center_y - track->track_h / 2 * center_z;
2714 float track_x2 = track_x1 + track->track_w * center_z;
2715 float track_y2 = track_y1 + track->track_h * center_z;
2717 output_to_canvas(mwindow->edl, 0, track_x1, track_y1);
2718 output_to_canvas(mwindow->edl, 0, track_x2, track_y2);
2720 #define DRAW_PROJECTION(offset) \
2721 get_canvas()->draw_rectangle((int)track_x1 + offset, \
2722 (int)track_y1 + offset, \
2723 (int)(track_x2 - track_x1), \
2724 (int)(track_y2 - track_y1)); \
2725 get_canvas()->draw_line((int)track_x1 + offset, \
2726 (int)track_y1 + offset, \
2727 (int)track_x2 + offset, \
2728 (int)track_y2 + offset); \
2729 get_canvas()->draw_line((int)track_x2 + offset, \
2730 (int)track_y1 + offset, \
2731 (int)track_x1 + offset, \
2732 (int)track_y2 + offset); \
2736 get_canvas()->set_color(BLACK);
2739 // canvas->set_inverse();
2741 get_canvas()->set_color(GREEN);
2743 get_canvas()->set_color(RED);
2746 // canvas->set_opaque();
2750 int CWindowCanvas::test_bezier(int button_press,
2758 // Processing drag operation.
2759 // Create keyframe during first cursor motion.
2763 float cursor_x = get_cursor_x();
2764 float cursor_y = get_cursor_y();
2765 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2767 if(gui->current_operation == CWINDOW_CAMERA ||
2768 gui->current_operation == CWINDOW_PROJECTOR)
2770 if(!gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom)
2772 gui->translating_zoom = 1;
2773 gui->reset_affected();
2776 if(!gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom)
2778 gui->translating_zoom = 0;
2779 gui->reset_affected();
2782 // Get target keyframe
2783 float last_center_x;
2784 float last_center_y;
2785 float last_center_z;
2788 if(!gui->affected_x && !gui->affected_y && !gui->affected_z)
2790 FloatAutos *affected_x_autos;
2791 FloatAutos *affected_y_autos;
2792 FloatAutos *affected_z_autos;
2793 if(!gui->affected_track) return 0;
2794 double position = mwindow->edl->local_session->get_selectionstart(1);
2795 int64_t track_position = gui->affected_track->to_units(position, 0);
2797 if(mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA)
2799 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_X];
2800 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Y];
2801 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Z];
2805 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_X];
2806 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Y];
2807 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Z];
2811 if(gui->translating_zoom)
2813 FloatAuto *previous = 0;
2814 FloatAuto *next = 0;
2815 float new_z = affected_z_autos->get_value(
2821 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2822 affected_z_autos, 1, &created, 0);
2824 gui->affected_z->set_value(new_z);
2830 FloatAuto *previous = 0;
2831 FloatAuto *next = 0;
2832 float new_x = affected_x_autos->get_value(
2839 float new_y = affected_y_autos->get_value(
2845 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2846 affected_x_autos, 1, &created, 0);
2848 gui->affected_x->set_value(new_x);
2852 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2853 affected_y_autos, 1, &created, 0);
2855 gui->affected_y->set_value(new_y);
2862 if(gui->translating_zoom)
2864 gui->center_z = gui->affected_z->get_value();
2868 gui->center_x = gui->affected_x->get_value();
2869 gui->center_y = gui->affected_y->get_value();
2876 if(gui->translating_zoom)
2878 last_center_z = gui->affected_z->get_value();
2879 float z = gui->center_z + (cursor_y - gui->y_origin) / 128;
2881 if(!EQUIV(last_center_z, z))
2887 gui->affected_z->set_value(z);
2891 last_center_x = gui->affected_x->get_value();
2892 last_center_y = gui->affected_y->get_value();
2893 float x = gui->center_x + cursor_x - gui->x_origin;
2894 float y = gui->center_y + cursor_y - gui->y_origin;
2895 gui->affected_x->set_value(x);
2896 gui->affected_y->set_value(y);
2897 if( !EQUIV(last_center_x, x) || !EQUIV(last_center_y, y) )
2903 gui->affected_x->set_value(x);
2904 gui->affected_y->set_value(y);
2911 // Begin drag operation. Don't create keyframe here.
2913 // Get affected track off of the first recordable video track.
2914 // Calculating based on the alpha channel would require recording what layer
2915 // each output pixel belongs to as they're rendered and stacked. Forget it.
2916 gui->affected_track = gui->cwindow->calculate_affected_track();
2917 gui->reset_affected();
2919 if(gui->affected_track)
2921 if(gui->current_operation == CWINDOW_CAMERA)
2922 mwindow->undo->update_undo_before(_("camera"), this);
2924 mwindow->undo->update_undo_before(_("projector"), this);
2926 gui->current_operation =
2927 mwindow->edl->session->cwindow_operation;
2928 gui->tool_panel->raise_window();
2937 int CWindowCanvas::test_zoom(int &redraw)
2943 if( mwindow->edl->session->cwindow_scrollbars ) {
2944 if( *gui->zoom_panel->get_text() != 'x' ) {
2945 // Find current zoom in table
2946 int idx = total_zooms; float old_zoom = get_zoom();
2947 while( --idx >= 0 && !EQUIV(my_zoom_table[idx], old_zoom) );
2949 idx += get_buttonpress() == 5 ||
2950 gui->ctrl_down() || gui->shift_down() ? -1 : +1 ;
2951 CLAMP(idx, 0, total_zooms-1);
2952 zoom = my_zoom_table[idx];
2955 x = get_cursor_x(); y = get_cursor_y();
2957 mwindow->edl->session->cwindow_scrollbars = 0;
2958 gui->zoom_panel->update(0);
2959 zoom = gui->get_auto_zoom();
2962 gui->zoom_panel->ZoomPanel::update(zoom);
2963 float output_x = x, output_y = y;
2964 canvas_to_output(mwindow->edl, 0, output_x, output_y);
2965 x = output_x - x / zoom;
2966 y = output_y - y / zoom;
2970 mwindow->edl->session->cwindow_scrollbars = 1;
2971 x = (mwindow->edl->session->output_w - w) / 2;
2972 y = (mwindow->edl->session->output_h - h) / 2;
2975 update_zoom((int)x, (int)y, zoom);
2977 gui->composite_panel->cpanel_zoom->update(zoom);
2979 reposition_window(mwindow->edl,
2980 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
2981 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
2982 redraw = 1; result = 1;
2988 void CWindowCanvas::calculate_origin()
2990 gui->x_origin = get_cursor_x();
2991 gui->y_origin = get_cursor_y();
2992 //printf("CWindowCanvas::calculate_origin 1 %f %f\n", gui->x_origin, gui->y_origin);
2993 canvas_to_output(mwindow->edl, 0, gui->x_origin, gui->y_origin);
2994 //printf("CWindowCanvas::calculate_origin 2 %f %f\n", gui->x_origin, gui->y_origin);
2998 int CWindowCanvas::cursor_leave_event()
3000 set_cursor(ARROW_CURSOR);
3004 int CWindowCanvas::cursor_enter_event()
3007 switch(mwindow->edl->session->cwindow_operation)
3009 case CWINDOW_CAMERA:
3010 case CWINDOW_PROJECTOR:
3011 set_cursor(MOVE_CURSOR);
3014 set_cursor(MOVE_CURSOR);
3017 test_crop(0, redraw);
3019 case CWINDOW_PROTECT:
3020 set_cursor(ARROW_CURSOR);
3024 set_cursor(CROSS_CURSOR);
3026 case CWINDOW_EYEDROP:
3027 set_cursor(CROSS_CURSOR);
3033 int CWindowCanvas::cursor_motion_event()
3035 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3038 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3039 switch(gui->current_operation)
3041 case CWINDOW_SCROLL:
3043 float zoom = get_zoom();
3044 float cursor_x = get_cursor_x();
3045 float cursor_y = get_cursor_y();
3047 float zoom_x, zoom_y, conformed_w, conformed_h;
3048 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3049 cursor_x = (float)cursor_x / zoom_x + gui->x_offset;
3050 cursor_y = (float)cursor_y / zoom_y + gui->y_offset;
3054 int x = (int)(gui->x_origin - cursor_x + gui->x_offset);
3055 int y = (int)(gui->y_origin - cursor_y + gui->y_offset);
3060 update_scrollbars(0);
3067 result = do_ruler(0, 1, 0, 0);
3070 case CWINDOW_CAMERA:
3071 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3074 case CWINDOW_PROJECTOR:
3075 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3080 result = test_crop(0, redraw);
3081 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3088 case CWINDOW_MASK_CONTROL_IN:
3089 case CWINDOW_MASK_CONTROL_OUT:
3090 case CWINDOW_MASK_TRANSLATE:
3092 result = do_mask(redraw,
3099 case CWINDOW_EYEDROP:
3100 result = do_eyedrop(rerender, 0, 0);
3109 // cursor font changes
3112 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3114 // mwindow->edl->session->cwindow_operation);
3115 switch(mwindow->edl->session->cwindow_operation)
3118 result = test_crop(0, redraw);
3121 result = do_ruler(0, 1, 0, 0);
3124 result = do_mask(redraw,
3134 // If the window is never unlocked before calling send_command the
3135 // display shouldn't get stuck on the old video frame although it will
3136 // flicker between the old video frame and the new video frame.
3146 gui->unlock_window();
3149 mwindow->gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3150 mwindow->gui->draw_overlays(1);
3151 mwindow->gui->unlock_window();
3153 gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3158 gui->unlock_window();
3159 mwindow->restart_brender();
3160 mwindow->sync_parameters(CHANGE_PARAMS);
3161 gui->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
3165 if(!redraw) gui->update_tool();
3166 gui->lock_window("CWindowCanvas::cursor_motion_event 2");
3171 int CWindowCanvas::button_press_event()
3175 int redraw_canvas = 0;
3178 if(Canvas::button_press_event()) return 1;
3180 gui->translating_zoom = gui->shift_down();
3183 //printf("CWindowCanvas::button_press_event 2 %f %f\n", gui->x_origin, gui->y_origin, gui->x_origin, gui->y_origin);
3185 float zoom_x, zoom_y, conformed_w, conformed_h;
3186 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3187 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3188 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3191 if(get_buttonpress() == 2)
3193 gui->current_operation = CWINDOW_SCROLL;
3199 switch(mwindow->edl->session->cwindow_operation)
3202 result = do_ruler(0, 0, 1, 0);
3205 case CWINDOW_CAMERA:
3206 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3209 case CWINDOW_PROJECTOR:
3210 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3214 result = test_zoom(redraw);
3218 result = test_crop(1, redraw);
3222 if(get_buttonpress() == 1)
3223 result = do_mask(redraw, rerender, 1, 0, 0);
3226 case CWINDOW_EYEDROP:
3227 result = do_eyedrop(rerender, 1, 0);
3235 gui->unlock_window();
3238 mwindow->gui->lock_window("CWindowCanvas::button_press_event 1");
3239 mwindow->gui->draw_overlays(1);
3240 mwindow->gui->unlock_window();
3243 gui->lock_window("CWindowCanvas::button_press_event 1");
3246 // rerendering can also be caused by press event
3249 gui->unlock_window();
3251 mwindow->restart_brender();
3252 mwindow->sync_parameters(CHANGE_PARAMS);
3253 gui->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
3257 if(!redraw) gui->update_tool();
3258 gui->lock_window("CWindowCanvas::button_press_event 2");
3263 int CWindowCanvas::button_release_event()
3267 switch(gui->current_operation)
3269 case CWINDOW_SCROLL:
3274 do_ruler(0, 0, 0, 1);
3277 case CWINDOW_CAMERA:
3278 mwindow->undo->update_undo_after(_("camera"), LOAD_AUTOMATION);
3281 case CWINDOW_PROJECTOR:
3282 mwindow->undo->update_undo_after(_("projector"), LOAD_AUTOMATION);
3286 case CWINDOW_MASK_CONTROL_IN:
3287 case CWINDOW_MASK_CONTROL_OUT:
3288 case CWINDOW_MASK_TRANSLATE:
3289 // Finish mask operation
3290 gui->mask_keyframe = 0;
3291 mwindow->undo->update_undo_after(_("mask"), LOAD_AUTOMATION);
3294 result = Canvas::button_release_event();
3298 gui->current_operation = CWINDOW_NONE;
3302 void CWindowCanvas::zoom_resize_window(float percentage)
3304 int canvas_w, canvas_h;
3308 // Get required canvas size
3309 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3310 mwindow->edl->session->output_w,
3311 mwindow->edl->session->output_h,
3316 // Estimate window size from current borders
3317 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3318 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3320 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3321 mwindow->session->cwindow_w = new_w;
3322 mwindow->session->cwindow_h = new_h;
3324 mwindow->theme->get_cwindow_sizes(gui,
3325 mwindow->session->cwindow_controls);
3327 // Estimate again from new borders
3328 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3329 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3330 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3332 gui->resize_window(new_w, new_h);
3333 gui->resize_event(new_w, new_h);
3336 void CWindowCanvas::toggle_controls()
3338 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3339 gui->resize_event(gui->get_w(), gui->get_h());
3342 int CWindowCanvas::get_cwindow_controls()
3344 return mwindow->session->cwindow_controls;