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)
716 CWrapper(toggle_label)
722 void CWindowEditing::to_clip()
724 mwindow->to_clip(mwindow->edl, _("composer window: "));
728 CWindowMeters::CWindowMeters(MWindow *mwindow,
733 : MeterPanel(mwindow,
739 mwindow->edl->session->audio_channels,
740 mwindow->edl->session->cwindow_meter,
744 this->mwindow = mwindow;
748 CWindowMeters::~CWindowMeters()
752 int CWindowMeters::change_status_event(int new_status)
754 mwindow->edl->session->cwindow_meter = new_status;
755 gui->update_meters();
762 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
763 : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
764 x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
766 this->mwindow = mwindow;
770 CWindowZoom::~CWindowZoom()
774 void CWindowZoom::update(double value)
776 char string[BCSTRLEN];
777 const char *cp = string;
780 int frac = value >= 1.0f ? 1 :
782 value >= .01f ? 3 : 4;
783 sprintf(string, "x %.*f", frac, value);
787 ZoomPanel::update(cp);
790 int CWindowZoom::handle_event()
792 double value = !strcasecmp(gui->auto_zoom, get_text()) ? 0 : get_value();
793 gui->zoom_canvas(value, 0);
800 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
801 : BC_PercentageSlider(x,
810 this->mwindow = mwindow;
811 this->cwindow = cwindow;
812 set_precision(0.00001);
815 CWindowSlider::~CWindowSlider()
819 int CWindowSlider::handle_event()
821 cwindow->update_position((double)get_value());
825 void CWindowSlider::set_position()
827 double new_length = mwindow->edl->tracks->total_playable_length();
828 // if(mwindow->edl->local_session->preview_end <= 0 ||
829 // mwindow->edl->local_session->preview_end > new_length)
830 // mwindow->edl->local_session->preview_end = new_length;
831 // if(mwindow->edl->local_session->preview_start >
832 // mwindow->edl->local_session->preview_end)
833 // mwindow->edl->local_session->preview_start = 0;
836 update(mwindow->theme->cslider_w,
837 mwindow->edl->local_session->get_selectionstart(1),
840 // mwindow->edl->local_session->preview_start,
841 // mwindow->edl->local_session->preview_end);
845 int CWindowSlider::increase_value()
848 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
849 lock_window("CWindowSlider::increase_value");
853 int CWindowSlider::decrease_value()
856 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
857 lock_window("CWindowSlider::decrease_value");
862 // CWindowDestination::CWindowDestination(MWindow *mwindow, CWindowGUI *cwindow, int x, int y)
863 // : BC_PopupTextBox(cwindow,
864 // &cwindow->destinations,
865 // cwindow->destinations.values[cwindow->cwindow->destination]->get_text(),
871 // this->mwindow = mwindow;
872 // this->cwindow = cwindow;
875 // CWindowDestination::~CWindowDestination()
879 // int CWindowDestination::handle_event()
890 CWindowTransport::CWindowTransport(MWindow *mwindow,
894 : PlayTransport(mwindow,
902 EDL* CWindowTransport::get_edl()
907 void CWindowTransport::goto_start()
909 gui->unlock_window();
910 handle_transport(REWIND, 1);
912 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
913 mwindow->goto_start();
914 mwindow->gui->unlock_window();
916 gui->lock_window("CWindowTransport::goto_start 2");
919 void CWindowTransport::goto_end()
921 gui->unlock_window();
922 handle_transport(GOTO_END, 1);
924 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
926 mwindow->gui->unlock_window();
928 gui->lock_window("CWindowTransport::goto_end 2");
933 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
936 mwindow->theme->ccanvas_x,
937 mwindow->theme->ccanvas_y,
938 mwindow->theme->ccanvas_w,
939 mwindow->theme->ccanvas_h,
942 mwindow->edl->session->cwindow_scrollbars)
944 this->mwindow = mwindow;
948 void CWindowCanvas::status_event()
953 int CWindowCanvas::get_fullscreen()
955 return mwindow->session->cwindow_fullscreen;
958 void CWindowCanvas::set_fullscreen(int value)
960 mwindow->session->cwindow_fullscreen = value;
964 void CWindowCanvas::update_zoom(int x, int y, float zoom)
966 use_scrollbars = mwindow->edl->session->cwindow_scrollbars;
968 mwindow->edl->session->cwindow_xscroll = x;
969 mwindow->edl->session->cwindow_yscroll = y;
970 mwindow->edl->session->cwindow_zoom = zoom;
973 void CWindowCanvas::zoom_auto()
975 gui->zoom_canvas(0, 1);
978 int CWindowCanvas::get_xscroll()
980 return mwindow->edl->session->cwindow_xscroll;
983 int CWindowCanvas::get_yscroll()
985 return mwindow->edl->session->cwindow_yscroll;
989 float CWindowCanvas::get_zoom()
991 return mwindow->edl->session->cwindow_zoom;
994 void CWindowCanvas::draw_refresh(int flush)
996 if(get_canvas() && !get_canvas()->get_video_on())
999 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
1001 float in_x1, in_y1, in_x2, in_y2;
1002 float out_x1, out_y1, out_x2, out_y2;
1003 get_transfers(mwindow->edl,
1013 if(!EQUIV(out_x1, 0) ||
1014 !EQUIV(out_y1, 0) ||
1015 !EQUIV(out_x2, get_canvas()->get_w()) ||
1016 !EQUIV(out_y2, get_canvas()->get_h()))
1018 get_canvas()->clear_box(0,
1020 get_canvas()->get_w(),
1021 get_canvas()->get_h());
1024 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1025 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1028 if(out_x2 > out_x1 &&
1033 // Can't use OpenGL here because it is called asynchronously of the
1034 // playback operation.
1035 get_canvas()->draw_vframe(refresh_frame,
1038 (int)(out_x2 - out_x1),
1039 (int)(out_y2 - out_y1),
1042 (int)(in_x2 - in_x1),
1043 (int)(in_y2 - in_y1),
1049 get_canvas()->clear_box(0,
1051 get_canvas()->get_w(),
1052 get_canvas()->get_h());
1056 get_canvas()->flash(flush);
1058 //printf("CWindowCanvas::draw_refresh 10\n");
1061 #define CROPHANDLE_W 10
1062 #define CROPHANDLE_H 10
1064 void CWindowCanvas::draw_crophandle(int x, int y)
1066 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1074 #define CONTROL_W 10
1075 #define CONTROL_H 10
1076 #define FIRST_CONTROL_W 20
1077 #define FIRST_CONTROL_H 20
1079 #define BC_INFINITY 65536
1081 #define RULERHANDLE_W 16
1082 #define RULERHANDLE_H 16
1086 int CWindowCanvas::do_ruler(int draw,
1092 float x1 = mwindow->edl->session->ruler_x1;
1093 float y1 = mwindow->edl->session->ruler_y1;
1094 float x2 = mwindow->edl->session->ruler_x2;
1095 float y2 = mwindow->edl->session->ruler_y2;
1096 float canvas_x1 = x1;
1097 float canvas_y1 = y1;
1098 float canvas_x2 = x2;
1099 float canvas_y2 = y2;
1100 float output_x = get_cursor_x();
1101 float output_y = get_cursor_y();
1102 float canvas_cursor_x = output_x;
1103 float canvas_cursor_y = output_y;
1105 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1106 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1107 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1108 mwindow->session->cwindow_output_x = roundf(output_x);
1109 mwindow->session->cwindow_output_y = roundf(output_y);
1111 if(button_press && get_buttonpress() == 1)
1113 gui->ruler_handle = -1;
1114 gui->ruler_translate = 0;
1117 gui->ruler_translate = 1;
1118 gui->ruler_origin_x = x1;
1119 gui->ruler_origin_y = y1;
1122 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1123 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1124 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1125 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1127 gui->ruler_handle = 0;
1128 gui->ruler_origin_x = x1;
1129 gui->ruler_origin_y = y1;
1132 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1133 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1134 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1135 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1137 gui->ruler_handle = 1;
1138 gui->ruler_origin_x = x2;
1139 gui->ruler_origin_y = y2;
1143 // Start new selection
1144 if(!gui->ruler_translate &&
1145 (gui->ruler_handle < 0 ||
1150 do_ruler(1, 0, 0, 0);
1151 get_canvas()->flash();
1152 gui->ruler_handle = 1;
1153 mwindow->edl->session->ruler_x1 = output_x;
1154 mwindow->edl->session->ruler_y1 = output_y;
1155 mwindow->edl->session->ruler_x2 = output_x;
1156 mwindow->edl->session->ruler_y2 = output_y;
1157 gui->ruler_origin_x = mwindow->edl->session->ruler_x2;
1158 gui->ruler_origin_y = mwindow->edl->session->ruler_y2;
1161 gui->x_origin = output_x;
1162 gui->y_origin = output_y;
1163 gui->current_operation = CWINDOW_RULER;
1164 gui->tool_panel->raise_window();
1170 if(gui->current_operation == CWINDOW_RULER)
1172 if(gui->ruler_translate)
1175 do_ruler(1, 0, 0, 0);
1176 float x_difference = mwindow->edl->session->ruler_x1;
1177 float y_difference = mwindow->edl->session->ruler_y1;
1178 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1179 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1180 x_difference -= mwindow->edl->session->ruler_x1;
1181 y_difference -= mwindow->edl->session->ruler_y1;
1182 mwindow->edl->session->ruler_x2 -= x_difference;
1183 mwindow->edl->session->ruler_y2 -= y_difference;
1185 do_ruler(1, 0, 0, 0);
1186 get_canvas()->flash();
1190 switch(gui->ruler_handle)
1193 do_ruler(1, 0, 0, 0);
1194 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1195 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1196 if(gui->alt_down() || gui->ctrl_down())
1198 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1199 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1203 double distance_value =
1204 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1205 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1206 if(angle_value < 22)
1207 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2;
1209 if(angle_value > 67)
1210 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2;
1212 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 &&
1213 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1215 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1216 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1219 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 && mwindow->edl->session->ruler_y1 > mwindow->edl->session->ruler_y2)
1221 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1222 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1225 if(mwindow->edl->session->ruler_x1 > mwindow->edl->session->ruler_x2 &&
1226 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1228 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1229 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1233 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1234 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1237 do_ruler(1, 0, 0, 0);
1238 get_canvas()->flash();
1243 do_ruler(1, 0, 0, 0);
1244 mwindow->edl->session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1245 mwindow->edl->session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1246 if(gui->alt_down() || gui->ctrl_down())
1248 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1249 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1253 double distance_value =
1254 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1255 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1256 if(angle_value < 22)
1257 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1;
1259 if(angle_value > 67)
1260 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1;
1262 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1263 mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1265 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1266 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1269 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1270 mwindow->edl->session->ruler_y2 > mwindow->edl->session->ruler_y1)
1272 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1273 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1276 if(mwindow->edl->session->ruler_x2 > mwindow->edl->session->ruler_x1 && mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1278 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1279 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1283 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1284 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1287 do_ruler(1, 0, 0, 0);
1288 get_canvas()->flash();
1292 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1296 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1301 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1302 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1303 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1304 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1306 set_cursor(UPRIGHT_ARROW_CURSOR);
1309 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1310 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1311 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1312 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1314 set_cursor(UPRIGHT_ARROW_CURSOR);
1317 set_cursor(CROSS_CURSOR);
1319 // Update current position
1324 // Assume no ruler measurement if 0 length
1325 if(draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)))
1327 get_canvas()->set_inverse();
1328 get_canvas()->set_color(WHITE);
1329 get_canvas()->draw_line((int)canvas_x1,
1333 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1335 roundf(canvas_x1) + RULERHANDLE_W / 2,
1337 get_canvas()->draw_line(roundf(canvas_x1),
1338 roundf(canvas_y1) - RULERHANDLE_H / 2,
1340 roundf(canvas_y1) + RULERHANDLE_H / 2);
1341 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1343 roundf(canvas_x2) + RULERHANDLE_W / 2,
1345 get_canvas()->draw_line(roundf(canvas_x2),
1346 roundf(canvas_y2) - RULERHANDLE_H / 2,
1348 roundf(canvas_y2) + RULERHANDLE_H / 2);
1349 get_canvas()->set_opaque();
1356 static inline double line_dist(float cx,float cy, float tx,float ty)
1358 double dx = tx-cx, dy = ty-cy;
1359 return sqrt(dx*dx + dy*dy);
1362 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1364 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1365 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1369 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1370 int button_press, int cursor_motion, int draw)
1372 // Retrieve points from top recordable track
1373 //printf("CWindowCanvas::do_mask 1\n");
1374 Track *track = gui->cwindow->calculate_affected_track();
1375 //printf("CWindowCanvas::do_mask 2\n");
1377 if(!track) return 0;
1378 //printf("CWindowCanvas::do_mask 3\n");
1380 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1381 int64_t position = track->to_units(
1382 mwindow->edl->local_session->get_selectionstart(1),
1384 ArrayList<MaskPoint*> points;
1386 // Determine the points based on whether
1387 // new keyframes will be generated or drawing is performed.
1388 // If keyframe generation occurs, use the interpolated mask.
1389 // If no keyframe generation occurs, use the previous mask.
1390 int use_interpolated = 0;
1391 if(button_press || cursor_motion) {
1392 #ifdef USE_KEYFRAME_SPANNING
1393 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1394 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1397 mask_autos->get_prev_auto(track->to_units(selection_start, 0),
1398 PLAY_FORWARD, first, 1);
1400 mask_autos->get_prev_auto(track->to_units(selection_end, 0),
1401 PLAY_FORWARD, last, 1);
1403 if(last == first && (!mwindow->edl->session->auto_keyframes))
1404 use_interpolated = 0;
1406 // If keyframe spanning occurs, use the interpolated points.
1407 // If new keyframe is generated, use the interpolated points.
1408 use_interpolated = 1;
1411 if(mwindow->edl->session->auto_keyframes)
1412 use_interpolated = 1;
1416 use_interpolated = 1;
1418 if(use_interpolated) {
1419 // Interpolate the points to get exactly what is being rendered at this position.
1420 mask_autos->get_points(&points,
1421 mwindow->edl->session->cwindow_mask,
1426 // Use the prev mask
1428 mask_autos->get_prev_auto(position,
1432 ((MaskAuto*)prev)->get_points(&points,
1433 mwindow->edl->session->cwindow_mask);
1436 // Projector zooms relative to the center of the track output.
1437 float half_track_w = (float)track->track_w / 2;
1438 float half_track_h = (float)track->track_h / 2;
1439 // Translate mask to projection
1440 float projector_x, projector_y, projector_z;
1441 track->automation->get_projector(
1442 &projector_x, &projector_y, &projector_z,
1443 position, PLAY_FORWARD);
1446 // Get position of cursor relative to mask
1447 float cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
1448 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1449 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1451 projector_x += mwindow->edl->session->output_w / 2;
1452 projector_y += mwindow->edl->session->output_h / 2;
1453 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1454 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1456 // Fix cursor origin
1458 gui->x_origin = mask_cursor_x;
1459 gui->y_origin = mask_cursor_y;
1463 // Points of closest line
1464 int shortest_point1 = -1;
1465 int shortest_point2 = -1;
1467 int shortest_point = -1;
1468 // Distance to closest line
1469 float shortest_line_distance = BC_INFINITY;
1470 // Distance to closest point
1471 float shortest_point_distance = BC_INFINITY;
1472 int selected_point = -1;
1473 int selected_control_point = -1;
1474 float selected_control_point_distance = BC_INFINITY;
1475 ArrayList<int> x_points;
1476 ArrayList<int> y_points;
1478 if(!cursor_motion) {
1480 get_canvas()->set_color(WHITE);
1481 get_canvas()->set_inverse();
1483 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1485 // Never draw closed polygon and a closed
1486 // polygon is harder to add points to.
1487 for(int i = 0; i < points.size() && !result; i++) {
1488 MaskPoint *point1 = points.get(i);
1489 MaskPoint *point2 = (i >= points.size() - 1) ?
1490 points.get(0) : points.get(i + 1);
1492 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1493 if(point_distance1 < shortest_point_distance || shortest_point < 0) {
1494 shortest_point_distance = point_distance1;
1498 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1499 if(point_distance2 < shortest_point_distance || shortest_point < 0) {
1500 shortest_point_distance = point_distance2;
1501 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1505 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1507 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1508 //point1->x, point1->y, point2->x, point2->y, projector_z);
1509 for(int j = 0; j <= segments && !result; j++) {
1510 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1511 float x0 = point1->x, y0 = point1->y;
1512 float x1 = point1->x + point1->control_x2;
1513 float y1 = point1->y + point1->control_y2;
1514 float x2 = point2->x + point2->control_x1;
1515 float y2 = point2->y + point2->control_y1;
1516 float x3 = point2->x, y3 = point2->y;
1517 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1518 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1519 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1520 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1521 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1522 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1523 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1524 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1526 float t = (float)j / segments;
1527 float tpow2 = t * t;
1528 float tpow3 = t * t * t;
1530 float invtpow2 = invt * invt;
1531 float invtpow3 = invt * invt * invt;
1533 float x = ( invtpow3 * x0
1534 + 3 * t * invtpow2 * x1
1535 + 3 * tpow2 * invt * x2
1537 float y = ( invtpow3 * y0
1538 + 3 * t * invtpow2 * y1
1539 + 3 * tpow2 * invt * y2
1541 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1542 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1543 // Test new point addition
1545 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1547 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1548 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1549 if(line_distance < shortest_line_distance ||
1550 shortest_point1 < 0) {
1551 shortest_line_distance = line_distance;
1552 shortest_point1 = i;
1553 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1554 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1555 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1558 // Test existing point selection
1560 if(gui->ctrl_down()) {
1561 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1563 if(distance < selected_control_point_distance) {
1565 selected_control_point = 1;
1566 selected_control_point_distance = distance;
1570 if(!gui->shift_down()) {
1571 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1572 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
1577 selected_point = shortest_point;
1580 // Test second point
1581 if(gui->ctrl_down()) {
1582 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1584 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1585 if(distance < selected_control_point_distance) {
1586 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1587 selected_control_point = 0;
1588 selected_control_point_distance = distance;
1591 else if(i < points.size() - 1) {
1592 if(!gui->shift_down()) {
1593 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1594 if(test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3)) {
1595 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1599 selected_point = shortest_point;
1604 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1608 if(draw) { // Draw joining line
1609 x_points.append((int)canvas_x);
1610 y_points.append((int)canvas_y);
1614 if(draw) { // Draw second anchor
1615 if(i < points.size() - 1) {
1616 if(i == gui->affected_point - 1)
1617 get_canvas()->draw_disc(
1618 (int)canvas_x - CONTROL_W / 2,
1619 (int)canvas_y - CONTROL_W / 2,
1620 CONTROL_W, CONTROL_H);
1622 get_canvas()->draw_circle(
1623 (int)canvas_x - CONTROL_W / 2,
1624 (int)canvas_y - CONTROL_W / 2,
1625 CONTROL_W, CONTROL_H);
1626 // char string[BCTEXTLEN];
1627 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1628 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1630 // Draw second control point.
1631 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1632 get_canvas()->draw_line(
1633 (int)canvas_x, (int)canvas_y,
1634 (int)canvas_x2, (int)canvas_y2);
1635 get_canvas()->draw_rectangle(
1636 (int)canvas_x2 - CONTROL_W / 2,
1637 (int)canvas_y2 - CONTROL_H / 2,
1638 CONTROL_W, CONTROL_H);
1643 // Draw first anchor
1644 if(i == 0 && draw) {
1645 char mask_label[BCSTRLEN];
1646 sprintf(mask_label, "%d",
1647 mwindow->edl->session->cwindow_mask);
1648 get_canvas()->draw_text(
1649 (int)canvas_x - FIRST_CONTROL_W,
1650 (int)canvas_y - FIRST_CONTROL_H,
1653 get_canvas()->draw_disc(
1654 (int)canvas_x - FIRST_CONTROL_W / 2,
1655 (int)canvas_y - FIRST_CONTROL_H / 2,
1656 FIRST_CONTROL_W, FIRST_CONTROL_H);
1659 // Draw first control point.
1661 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1662 get_canvas()->draw_line(
1663 (int)canvas_x, (int)canvas_y,
1664 (int)canvas_x1, (int)canvas_y1);
1665 get_canvas()->draw_rectangle(
1666 (int)canvas_x1 - CONTROL_W / 2,
1667 (int)canvas_y1 - CONTROL_H / 2,
1668 CONTROL_W, CONTROL_H);
1670 x_points.append((int)canvas_x);
1671 y_points.append((int)canvas_y);
1674 //printf("CWindowCanvas::do_mask 1\n");
1678 //printf("CWindowCanvas::do_mask 1\n");
1681 get_canvas()->draw_polygon(&x_points, &y_points);
1682 get_canvas()->set_opaque();
1684 //printf("CWindowCanvas::do_mask 1\n");
1687 if(button_press && !result) {
1688 gui->affected_track = gui->cwindow->calculate_affected_track();
1690 // Get keyframe outside the EDL to edit. This must be rendered
1691 // instead of the EDL keyframes when it exists. Then it must be
1692 // applied to the EDL keyframes on buttonrelease.
1693 if(gui->affected_track) {
1694 #ifdef USE_KEYFRAME_SPANNING
1695 // Make copy of current parameters in local keyframe
1696 gui->mask_keyframe =
1697 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1700 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1703 gui->mask_keyframe =
1704 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1709 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1712 // Translate entire keyframe
1713 if(gui->alt_down() && mask->points.size()) {
1714 mwindow->undo->update_undo_before(_("mask translate"), 0);
1715 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1716 gui->affected_point = 0;
1719 // Existing point or control point was selected
1720 if(selected_point >= 0) {
1721 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1722 gui->affected_point = selected_point;
1724 if(selected_control_point == 0)
1725 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1727 if(selected_control_point == 1)
1728 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1730 gui->current_operation = mwindow->edl->session->cwindow_operation;
1732 else // No existing point or control point was selected so create a new one
1733 if(!gui->ctrl_down() && !gui->alt_down()) {
1734 mwindow->undo->update_undo_before(_("mask point"), 0);
1735 // Create the template
1736 MaskPoint *point = new MaskPoint;
1737 point->x = mask_cursor_x;
1738 point->y = mask_cursor_y;
1739 point->control_x1 = 0;
1740 point->control_y1 = 0;
1741 point->control_x2 = 0;
1742 point->control_y2 = 0;
1745 if(shortest_point2 < shortest_point1) {
1746 shortest_point2 ^= shortest_point1;
1747 shortest_point1 ^= shortest_point2;
1748 shortest_point2 ^= shortest_point1;
1753 // printf("CWindowGUI::do_mask 40\n");
1754 // mwindow->edl->dump();
1755 // printf("CWindowGUI::do_mask 50\n");
1759 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1760 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1761 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1763 // Append to end of list
1764 if( shortest_point1 == shortest_point2 ||
1765 labs(shortest_point1 - shortest_point2) > 1) {
1766 #ifdef USE_KEYFRAME_SPANNING
1768 MaskPoint *new_point = new MaskPoint;
1769 points.append(new_point);
1770 *new_point = *point;
1771 gui->affected_point = points.size() - 1;
1775 // Need to apply the new point to every keyframe
1776 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1777 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1778 MaskPoint *new_point = new MaskPoint;
1779 submask->points.append(new_point);
1780 *new_point = *point;
1781 if(current == (MaskAuto*)mask_autos->default_auto)
1782 current = (MaskAuto*)mask_autos->first;
1784 current = (MaskAuto*)NEXT;
1786 gui->affected_point = mask->points.size() - 1;
1792 // Insert between 2 points, shifting back point 2
1793 if(shortest_point1 >= 0 && shortest_point2 >= 0) {
1795 #ifdef USE_KEYFRAME_SPANNING
1796 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1798 if(points.size() >= shortest_point2) {
1799 MaskPoint *new_point = new MaskPoint;
1801 for(int i = points.size() - 1;
1802 i > shortest_point2;
1804 points.values[i] = points.values[i - 1];
1805 points.values[shortest_point2] = new_point;
1807 *new_point = *point;
1812 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1813 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1814 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1816 if(submask->points.size() >= shortest_point2) {
1817 MaskPoint *new_point = new MaskPoint;
1818 submask->points.append(0);
1819 for(int i = submask->points.size() - 1;
1820 i > shortest_point2;
1822 submask->points.values[i] = submask->points.values[i - 1];
1823 submask->points.values[shortest_point2] = new_point;
1825 *new_point = *point;
1828 if(current == (MaskAuto*)mask_autos->default_auto)
1829 current = (MaskAuto*)mask_autos->first;
1831 current = (MaskAuto*)NEXT;
1835 gui->affected_point = shortest_point2;
1840 // printf("CWindowGUI::do_mask 20\n");
1841 // mwindow->edl->dump();
1842 // printf("CWindowGUI::do_mask 30\n");
1845 //printf("CWindowCanvas::do_mask 1\n");
1846 // Create the first point.
1847 #ifdef USE_KEYFRAME_SPANNING
1848 MaskPoint *new_point = new MaskPoint;
1849 points.append(new_point);
1850 *new_point = *point;
1851 gui->affected_point = points.size() - 1;
1853 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1854 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1855 MaskPoint *new_point = new MaskPoint;
1856 submask->points.append(new_point);
1857 *new_point = *point;
1858 if(current == (MaskAuto*)mask_autos->default_auto)
1859 current = (MaskAuto*)mask_autos->first;
1861 current = (MaskAuto*)NEXT;
1863 gui->affected_point = points.size() - 1;
1866 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
1869 gui->current_operation = mwindow->edl->session->cwindow_operation;
1870 // Delete the template
1879 if(button_press && result) {
1880 #ifdef USE_KEYFRAME_SPANNING
1881 MaskPoint *point = points.values[gui->affected_point];
1882 gui->center_x = point->x;
1883 gui->center_y = point->y;
1884 gui->control_in_x = point->control_x1;
1885 gui->control_in_y = point->control_y1;
1886 gui->control_out_x = point->control_x2;
1887 gui->control_out_y = point->control_y2;
1888 gui->tool_panel->raise_window();
1890 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1891 MaskPoint *point = mask->points.values[gui->affected_point];
1892 gui->center_x = point->x;
1893 gui->center_y = point->y;
1894 gui->control_in_x = point->control_x1;
1895 gui->control_in_y = point->control_y1;
1896 gui->control_out_x = point->control_x2;
1897 gui->control_out_y = point->control_y2;
1898 gui->tool_panel->raise_window();
1902 //printf("CWindowCanvas::do_mask 8\n");
1905 #ifdef USE_KEYFRAME_SPANNING
1906 // Must update the reference keyframes for every cursor motion
1907 gui->mask_keyframe =
1908 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1911 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1914 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1916 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1917 if( gui->affected_point >= 0 && gui->affected_point < mask->points.size() &&
1918 gui->current_operation != CWINDOW_NONE) {
1919 // mwindow->undo->update_undo_before(_("mask point"), this);
1920 #ifdef USE_KEYFRAME_SPANNING
1921 MaskPoint *point = points.get(gui->affected_point);
1923 MaskPoint *point = mask->points.get(gui->affected_point);
1925 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
1926 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask->points.size(), gui->affected_point);
1928 float last_x = point->x;
1929 float last_y = point->y;
1930 float last_control_x1 = point->control_x1;
1931 float last_control_y1 = point->control_y1;
1932 float last_control_x2 = point->control_x2;
1933 float last_control_y2 = point->control_y2;
1935 switch(gui->current_operation) {
1937 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1938 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
1939 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
1942 case CWINDOW_MASK_CONTROL_IN:
1943 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
1944 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
1947 case CWINDOW_MASK_CONTROL_OUT:
1948 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
1949 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
1952 case CWINDOW_MASK_TRANSLATE:
1953 #ifdef USE_KEYFRAME_SPANNING
1954 for(int i = 0; i < points.size(); i++) {
1955 points.values[i]->x += mask_cursor_x - gui->x_origin;
1956 points.values[i]->y += mask_cursor_y - gui->y_origin;
1959 for(int i = 0; i < mask->points.size(); i++) {
1960 mask->points.values[i]->x += mask_cursor_x - gui->x_origin;
1961 mask->points.values[i]->y += mask_cursor_y - gui->y_origin;
1964 gui->x_origin = mask_cursor_x;
1965 gui->y_origin = mask_cursor_y;
1969 if( !EQUIV(last_x, point->x) ||
1970 !EQUIV(last_y, point->y) ||
1971 !EQUIV(last_control_x1, point->control_x1) ||
1972 !EQUIV(last_control_y1, point->control_y1) ||
1973 !EQUIV(last_control_x2, point->control_x2) ||
1974 !EQUIV(last_control_y2, point->control_y2)) {
1980 if(gui->current_operation == CWINDOW_NONE) {
1981 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
1983 for(int i = 0; i < points.size() && !over_point; i++) {
1984 MaskPoint *point = points.get(i);
1985 float x0 = point->x;
1986 float y0 = point->y;
1987 float x1 = point->x + point->control_x1;
1988 float y1 = point->y + point->control_y1;
1989 float x2 = point->x + point->control_x2;
1990 float y2 = point->y + point->control_y2;
1991 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1992 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1994 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1995 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
1999 if(!over_point && gui->ctrl_down()) {
2000 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
2001 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
2002 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2003 if(test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1)) {
2007 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2008 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2009 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2010 if(test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2)) {
2017 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2022 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2025 #ifdef USE_KEYFRAME_SPANNING
2026 // Must commit change after operation.
2027 if(rerender && track) {
2028 // Swap EDL keyframe with original.
2029 // Apply new values to keyframe span
2030 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2031 temp_keyframe.copy_data(gui->mask_keyframe);
2032 // Apply interpolated points back to keyframe
2033 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2034 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2035 mask_autos->update_parameter(&temp_keyframe);
2039 points.remove_all_objects();
2040 //printf("CWindowCanvas::do_mask 20\n");
2044 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2047 int radius = mwindow->edl->session->eyedrop_radius;
2055 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2060 row1 = gui->eyedrop_y - radius;
2061 row2 = gui->eyedrop_y + radius;
2062 column1 = gui->eyedrop_x - radius;
2063 column2 = gui->eyedrop_x + radius;
2065 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2066 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2067 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2068 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2070 if(row2 <= row1) row2 = row1 + 1;
2071 if(column2 <= column1) column2 = column1 + 1;
2078 output_to_canvas(mwindow->edl, 0, x1, y1);
2079 output_to_canvas(mwindow->edl, 0, x2, y2);
2080 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2082 if(x2 - x1 >= 1 && y2 - y1 >= 1)
2084 get_canvas()->set_inverse();
2085 get_canvas()->set_color(WHITE);
2087 get_canvas()->draw_rectangle((int)x1,
2092 get_canvas()->set_opaque();
2093 get_canvas()->flash();
2101 gui->current_operation = CWINDOW_EYEDROP;
2102 gui->tool_panel->raise_window();
2105 if(gui->current_operation == CWINDOW_EYEDROP)
2107 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2109 // Get color out of frame.
2110 // Doesn't work during playback because that bypasses the refresh frame.
2111 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2113 float cursor_x = get_cursor_x();
2114 float cursor_y = get_cursor_y();
2115 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2116 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2117 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2119 row1 = cursor_y - radius;
2120 row2 = cursor_y + radius;
2121 column1 = cursor_x - radius;
2122 column2 = cursor_x + radius;
2123 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2124 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2125 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2126 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2127 if(row2 <= row1) row2 = row1 + 1;
2128 if(column2 <= column1) column2 = column1 + 1;
2132 if(gui->eyedrop_visible)
2135 do_eyedrop(temp, 0, 1);
2136 gui->eyedrop_visible = 0;
2139 gui->eyedrop_x = cursor_x;
2140 gui->eyedrop_y = cursor_y;
2145 do_eyedrop(temp, 0, 1);
2146 gui->eyedrop_visible = 1;
2149 // Decompression coefficients straight out of jpeglib
2150 #define V_TO_R 1.40200
2151 #define V_TO_G -0.71414
2153 #define U_TO_G -0.34414
2154 #define U_TO_B 1.77200
2156 #define GET_COLOR(type, components, max, do_yuv) \
2158 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2160 float red = (float)*row++ / max; \
2161 float green = (float)*row++ / max; \
2162 float blue = (float)*row++ / max; \
2165 mwindow->edl->local_session->red += red + V_TO_R * (blue - 0.5); \
2166 mwindow->edl->local_session->green += red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
2167 mwindow->edl->local_session->blue += red + U_TO_B * (green - 0.5); \
2171 mwindow->edl->local_session->red += red; \
2172 mwindow->edl->local_session->green += green; \
2173 mwindow->edl->local_session->blue += blue; \
2179 mwindow->edl->local_session->red = 0;
2180 mwindow->edl->local_session->green = 0;
2181 mwindow->edl->local_session->blue = 0;
2182 for(int i = row1; i < row2; i++)
2184 for(int j = column1; j < column2; j++)
2186 switch(refresh_frame->get_color_model())
2189 GET_COLOR(unsigned char, 3, 0xff, 1);
2192 GET_COLOR(unsigned char, 4, 0xff, 1);
2195 GET_COLOR(uint16_t, 3, 0xffff, 1);
2197 case BC_YUVA16161616:
2198 GET_COLOR(uint16_t, 4, 0xffff, 1);
2201 GET_COLOR(unsigned char, 3, 0xff, 0);
2204 GET_COLOR(unsigned char, 4, 0xff, 0);
2207 GET_COLOR(float, 3, 1.0, 0);
2210 GET_COLOR(float, 4, 1.0, 0);
2216 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2217 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2218 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2223 mwindow->edl->local_session->red = 0;
2224 mwindow->edl->local_session->green = 0;
2225 mwindow->edl->local_session->blue = 0;
2226 gui->eyedrop_visible = 0;
2235 // Can't rerender since the color value is from the output of any effect it
2238 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2244 void CWindowCanvas::draw_overlays()
2246 if(mwindow->edl->session->safe_regions)
2248 draw_safe_regions();
2251 if(mwindow->edl->session->cwindow_scrollbars)
2253 // Always draw output rectangle
2254 float x1, y1, x2, y2;
2256 x2 = mwindow->edl->session->output_w;
2258 y2 = mwindow->edl->session->output_h;
2259 output_to_canvas(mwindow->edl, 0, x1, y1);
2260 output_to_canvas(mwindow->edl, 0, x2, y2);
2262 get_canvas()->set_inverse();
2263 get_canvas()->set_color(WHITE);
2265 get_canvas()->draw_rectangle((int)x1,
2270 get_canvas()->set_opaque();
2273 if(gui->highlighted)
2275 get_canvas()->set_color(WHITE);
2276 get_canvas()->set_inverse();
2277 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2278 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2279 get_canvas()->set_opaque();
2282 int temp1 = 0, temp2 = 0;
2283 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2284 switch(mwindow->edl->session->cwindow_operation)
2286 case CWINDOW_CAMERA:
2290 case CWINDOW_PROJECTOR:
2299 do_mask(temp1, temp2, 0, 0, 1);
2303 do_ruler(1, 0, 0, 0);
2306 case CWINDOW_EYEDROP:
2307 if(gui->eyedrop_visible)
2310 do_eyedrop(rerender, 0, 1);
2311 gui->eyedrop_visible = 1;
2317 void CWindowCanvas::draw_safe_regions()
2319 float action_x1, action_x2, action_y1, action_y2;
2320 float title_x1, title_x2, title_y1, title_y2;
2322 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2323 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2324 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2325 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2326 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2327 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2328 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2329 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2331 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2332 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2333 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2334 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2336 get_canvas()->set_inverse();
2337 get_canvas()->set_color(WHITE);
2339 get_canvas()->draw_rectangle((int)action_x1,
2341 (int)(action_x2 - action_x1),
2342 (int)(action_y2 - action_y1));
2343 get_canvas()->draw_rectangle((int)title_x1,
2345 (int)(title_x2 - title_x1),
2346 (int)(title_y2 - title_y1));
2348 get_canvas()->set_opaque();
2351 void CWindowCanvas::reset_keyframe(int do_camera)
2353 FloatAuto *x_keyframe = 0;
2354 FloatAuto *y_keyframe = 0;
2355 FloatAuto *z_keyframe = 0;
2356 Track *affected_track = 0;
2358 affected_track = gui->cwindow->calculate_affected_track();
2362 gui->cwindow->calculate_affected_autos(&x_keyframe,
2371 x_keyframe->set_value(0);
2372 y_keyframe->set_value(0);
2373 z_keyframe->set_value(1);
2375 mwindow->sync_parameters(CHANGE_PARAMS);
2380 void CWindowCanvas::reset_camera()
2385 void CWindowCanvas::reset_projector()
2390 int CWindowCanvas::test_crop(int button_press, int &redraw)
2393 int handle_selected = -1;
2394 float x1 = mwindow->edl->session->crop_x1;
2395 float y1 = mwindow->edl->session->crop_y1;
2396 float x2 = mwindow->edl->session->crop_x2;
2397 float y2 = mwindow->edl->session->crop_y2;
2398 float cursor_x = get_cursor_x();
2399 float cursor_y = get_cursor_y();
2400 float canvas_x1 = x1;
2401 float canvas_y1 = y1;
2402 float canvas_x2 = x2;
2403 float canvas_y2 = y2;
2404 float canvas_cursor_x = cursor_x;
2405 float canvas_cursor_y = cursor_y;
2407 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2408 // Use screen normalized coordinates for hot spot tests.
2409 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2410 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2413 if(gui->current_operation == CWINDOW_CROP)
2415 handle_selected = gui->crop_handle;
2418 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2419 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2421 handle_selected = 0;
2422 gui->crop_origin_x = x1;
2423 gui->crop_origin_y = y1;
2426 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2427 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2429 handle_selected = 1;
2430 gui->crop_origin_x = x2;
2431 gui->crop_origin_y = y1;
2434 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2435 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2437 handle_selected = 2;
2438 gui->crop_origin_x = x1;
2439 gui->crop_origin_y = y2;
2442 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2443 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2445 handle_selected = 3;
2446 gui->crop_origin_x = x2;
2447 gui->crop_origin_y = y2;
2452 gui->crop_origin_x = cursor_x;
2453 gui->crop_origin_y = cursor_y;
2456 // printf("test crop %d %d\n",
2457 // gui->current_operation,
2458 // handle_selected);
2465 gui->crop_translate = 1;
2466 gui->crop_origin_x1 = x1;
2467 gui->crop_origin_y1 = y1;
2468 gui->crop_origin_x2 = x2;
2469 gui->crop_origin_y2 = y2;
2472 gui->crop_translate = 0;
2474 gui->current_operation = CWINDOW_CROP;
2475 gui->crop_handle = handle_selected;
2476 gui->x_origin = cursor_x;
2477 gui->y_origin = cursor_y;
2478 gui->tool_panel->raise_window();
2481 if(handle_selected < 0 && !gui->crop_translate)
2485 mwindow->edl->session->crop_x1 = (int)x1;
2486 mwindow->edl->session->crop_y1 = (int)y1;
2487 mwindow->edl->session->crop_x2 = (int)x2;
2488 mwindow->edl->session->crop_y2 = (int)y2;
2493 // Translate all 4 points
2494 if(gui->current_operation == CWINDOW_CROP && gui->crop_translate)
2496 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2497 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2498 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2499 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2501 mwindow->edl->session->crop_x1 = (int)x1;
2502 mwindow->edl->session->crop_y1 = (int)y1;
2503 mwindow->edl->session->crop_x2 = (int)x2;
2504 mwindow->edl->session->crop_y2 = (int)y2;
2510 if(gui->current_operation == CWINDOW_CROP)
2512 switch(gui->crop_handle)
2515 x1 = gui->crop_origin_x;
2516 y1 = gui->crop_origin_y;
2517 x2 = gui->crop_origin_x;
2518 y2 = gui->crop_origin_y;
2519 if(cursor_x < gui->x_origin)
2521 if(cursor_y < gui->y_origin)
2527 if(cursor_y >= gui->y_origin)
2534 if(cursor_x >= gui->x_origin)
2536 if(cursor_y < gui->y_origin)
2542 if(cursor_y >= gui->y_origin)
2549 // printf("test crop %d %d %d %d\n",
2550 // mwindow->edl->session->crop_x1,
2551 // mwindow->edl->session->crop_y1,
2552 // mwindow->edl->session->crop_x2,
2553 // mwindow->edl->session->crop_y2);
2556 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2557 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2560 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2561 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2564 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2565 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2568 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2569 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2573 if(!EQUIV(mwindow->edl->session->crop_x1, x1) ||
2574 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2575 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2576 !EQUIV(mwindow->edl->session->crop_y2, y2))
2583 switch (gui->crop_handle)
2585 case 0: gui->crop_handle = 1; break;
2586 case 1: gui->crop_handle = 0; break;
2587 case 2: gui->crop_handle = 3; break;
2588 case 3: gui->crop_handle = 2; break;
2598 switch (gui->crop_handle)
2600 case 0: gui->crop_handle = 2; break;
2601 case 1: gui->crop_handle = 3; break;
2602 case 2: gui->crop_handle = 0; break;
2603 case 3: gui->crop_handle = 1; break;
2608 mwindow->edl->session->crop_x1 = (int)x1;
2609 mwindow->edl->session->crop_y1 = (int)y1;
2610 mwindow->edl->session->crop_x2 = (int)x2;
2611 mwindow->edl->session->crop_y2 = (int)y2;
2617 // Update cursor font
2618 if(handle_selected >= 0)
2620 switch(handle_selected)
2623 set_cursor(UPLEFT_RESIZE);
2626 set_cursor(UPRIGHT_RESIZE);
2629 set_cursor(DOWNLEFT_RESIZE);
2632 set_cursor(DOWNRIGHT_RESIZE);
2639 set_cursor(ARROW_CURSOR);
2641 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2645 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2646 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2647 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2648 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2649 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2650 // mwindow->edl->session->crop_x2,
2651 // mwindow->edl->session->crop_y2,
2652 // mwindow->edl->calculate_output_w(0),
2653 // mwindow->edl->calculate_output_h(0));
2659 void CWindowCanvas::draw_crop()
2661 get_canvas()->set_inverse();
2662 get_canvas()->set_color(WHITE);
2664 float x1 = mwindow->edl->session->crop_x1;
2665 float y1 = mwindow->edl->session->crop_y1;
2666 float x2 = mwindow->edl->session->crop_x2;
2667 float y2 = mwindow->edl->session->crop_y2;
2669 output_to_canvas(mwindow->edl, 0, x1, y1);
2670 output_to_canvas(mwindow->edl, 0, x2, y2);
2672 if(x2 - x1 && y2 - y1)
2673 get_canvas()->draw_rectangle((int)x1,
2678 draw_crophandle((int)x1, (int)y1);
2679 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2680 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2681 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2682 get_canvas()->set_opaque();
2692 void CWindowCanvas::draw_bezier(int do_camera)
2694 Track *track = gui->cwindow->calculate_affected_track();
2701 int64_t position = track->to_units(
2702 mwindow->edl->local_session->get_selectionstart(1),
2705 track->automation->get_projector(¢er_x,
2711 // center_x += track->track_w / 2;
2712 // center_y += track->track_h / 2;
2713 center_x += mwindow->edl->session->output_w / 2;
2714 center_y += mwindow->edl->session->output_h / 2;
2715 float track_x1 = center_x - track->track_w / 2 * center_z;
2716 float track_y1 = center_y - track->track_h / 2 * center_z;
2717 float track_x2 = track_x1 + track->track_w * center_z;
2718 float track_y2 = track_y1 + track->track_h * center_z;
2720 output_to_canvas(mwindow->edl, 0, track_x1, track_y1);
2721 output_to_canvas(mwindow->edl, 0, track_x2, track_y2);
2723 #define DRAW_PROJECTION(offset) \
2724 get_canvas()->draw_rectangle((int)track_x1 + offset, \
2725 (int)track_y1 + offset, \
2726 (int)(track_x2 - track_x1), \
2727 (int)(track_y2 - track_y1)); \
2728 get_canvas()->draw_line((int)track_x1 + offset, \
2729 (int)track_y1 + offset, \
2730 (int)track_x2 + offset, \
2731 (int)track_y2 + offset); \
2732 get_canvas()->draw_line((int)track_x2 + offset, \
2733 (int)track_y1 + offset, \
2734 (int)track_x1 + offset, \
2735 (int)track_y2 + offset); \
2739 get_canvas()->set_color(BLACK);
2742 // canvas->set_inverse();
2744 get_canvas()->set_color(GREEN);
2746 get_canvas()->set_color(RED);
2749 // canvas->set_opaque();
2753 int CWindowCanvas::test_bezier(int button_press,
2761 // Processing drag operation.
2762 // Create keyframe during first cursor motion.
2766 float cursor_x = get_cursor_x();
2767 float cursor_y = get_cursor_y();
2768 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2770 if(gui->current_operation == CWINDOW_CAMERA ||
2771 gui->current_operation == CWINDOW_PROJECTOR)
2773 if(!gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom)
2775 gui->translating_zoom = 1;
2776 gui->reset_affected();
2779 if(!gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom)
2781 gui->translating_zoom = 0;
2782 gui->reset_affected();
2785 // Get target keyframe
2786 float last_center_x;
2787 float last_center_y;
2788 float last_center_z;
2791 if(!gui->affected_x && !gui->affected_y && !gui->affected_z)
2793 FloatAutos *affected_x_autos;
2794 FloatAutos *affected_y_autos;
2795 FloatAutos *affected_z_autos;
2796 if(!gui->affected_track) return 0;
2797 double position = mwindow->edl->local_session->get_selectionstart(1);
2798 int64_t track_position = gui->affected_track->to_units(position, 0);
2800 if(mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA)
2802 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_X];
2803 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Y];
2804 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Z];
2808 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_X];
2809 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Y];
2810 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Z];
2814 if(gui->translating_zoom)
2816 FloatAuto *previous = 0;
2817 FloatAuto *next = 0;
2818 float new_z = affected_z_autos->get_value(
2824 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2825 affected_z_autos, 1, &created, 0);
2827 gui->affected_z->set_value(new_z);
2833 FloatAuto *previous = 0;
2834 FloatAuto *next = 0;
2835 float new_x = affected_x_autos->get_value(
2842 float new_y = affected_y_autos->get_value(
2848 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2849 affected_x_autos, 1, &created, 0);
2851 gui->affected_x->set_value(new_x);
2855 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2856 affected_y_autos, 1, &created, 0);
2858 gui->affected_y->set_value(new_y);
2865 if(gui->translating_zoom)
2867 gui->center_z = gui->affected_z->get_value();
2871 gui->center_x = gui->affected_x->get_value();
2872 gui->center_y = gui->affected_y->get_value();
2879 if(gui->translating_zoom)
2881 last_center_z = gui->affected_z->get_value();
2882 float z = gui->center_z + (cursor_y - gui->y_origin) / 128;
2884 if(!EQUIV(last_center_z, z))
2890 gui->affected_z->set_value(z);
2894 last_center_x = gui->affected_x->get_value();
2895 last_center_y = gui->affected_y->get_value();
2896 float x = gui->center_x + cursor_x - gui->x_origin;
2897 float y = gui->center_y + cursor_y - gui->y_origin;
2898 gui->affected_x->set_value(x);
2899 gui->affected_y->set_value(y);
2900 if( !EQUIV(last_center_x, x) || !EQUIV(last_center_y, y) )
2906 gui->affected_x->set_value(x);
2907 gui->affected_y->set_value(y);
2914 // Begin drag operation. Don't create keyframe here.
2916 // Get affected track off of the first recordable video track.
2917 // Calculating based on the alpha channel would require recording what layer
2918 // each output pixel belongs to as they're rendered and stacked. Forget it.
2919 gui->affected_track = gui->cwindow->calculate_affected_track();
2920 gui->reset_affected();
2922 if(gui->affected_track)
2924 if(gui->current_operation == CWINDOW_CAMERA)
2925 mwindow->undo->update_undo_before(_("camera"), this);
2927 mwindow->undo->update_undo_before(_("projector"), this);
2929 gui->current_operation =
2930 mwindow->edl->session->cwindow_operation;
2931 gui->tool_panel->raise_window();
2940 int CWindowCanvas::test_zoom(int &redraw)
2946 if( mwindow->edl->session->cwindow_scrollbars ) {
2947 if( *gui->zoom_panel->get_text() != 'x' ) {
2948 // Find current zoom in table
2949 int idx = total_zooms; float old_zoom = get_zoom();
2950 while( --idx >= 0 && !EQUIV(my_zoom_table[idx], old_zoom) );
2952 idx += get_buttonpress() == 5 ||
2953 gui->ctrl_down() || gui->shift_down() ? -1 : +1 ;
2954 CLAMP(idx, 0, total_zooms-1);
2955 zoom = my_zoom_table[idx];
2958 x = get_cursor_x(); y = get_cursor_y();
2960 mwindow->edl->session->cwindow_scrollbars = 0;
2961 gui->zoom_panel->update(0);
2962 zoom = gui->get_auto_zoom();
2965 gui->zoom_panel->ZoomPanel::update(zoom);
2966 float output_x = x, output_y = y;
2967 canvas_to_output(mwindow->edl, 0, output_x, output_y);
2968 x = output_x - x / zoom;
2969 y = output_y - y / zoom;
2973 mwindow->edl->session->cwindow_scrollbars = 1;
2974 x = (mwindow->edl->session->output_w - w) / 2;
2975 y = (mwindow->edl->session->output_h - h) / 2;
2978 update_zoom((int)x, (int)y, zoom);
2980 gui->composite_panel->cpanel_zoom->update(zoom);
2982 reposition_window(mwindow->edl,
2983 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
2984 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
2985 redraw = 1; result = 1;
2991 void CWindowCanvas::calculate_origin()
2993 gui->x_origin = get_cursor_x();
2994 gui->y_origin = get_cursor_y();
2995 //printf("CWindowCanvas::calculate_origin 1 %f %f\n", gui->x_origin, gui->y_origin);
2996 canvas_to_output(mwindow->edl, 0, gui->x_origin, gui->y_origin);
2997 //printf("CWindowCanvas::calculate_origin 2 %f %f\n", gui->x_origin, gui->y_origin);
3001 int CWindowCanvas::cursor_leave_event()
3003 set_cursor(ARROW_CURSOR);
3007 int CWindowCanvas::cursor_enter_event()
3010 switch(mwindow->edl->session->cwindow_operation)
3012 case CWINDOW_CAMERA:
3013 case CWINDOW_PROJECTOR:
3014 set_cursor(MOVE_CURSOR);
3017 set_cursor(MOVE_CURSOR);
3020 test_crop(0, redraw);
3022 case CWINDOW_PROTECT:
3023 set_cursor(ARROW_CURSOR);
3027 set_cursor(CROSS_CURSOR);
3029 case CWINDOW_EYEDROP:
3030 set_cursor(CROSS_CURSOR);
3036 int CWindowCanvas::cursor_motion_event()
3038 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3041 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3042 switch(gui->current_operation)
3044 case CWINDOW_SCROLL:
3046 float zoom = get_zoom();
3047 float cursor_x = get_cursor_x();
3048 float cursor_y = get_cursor_y();
3050 float zoom_x, zoom_y, conformed_w, conformed_h;
3051 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3052 cursor_x = (float)cursor_x / zoom_x + gui->x_offset;
3053 cursor_y = (float)cursor_y / zoom_y + gui->y_offset;
3057 int x = (int)(gui->x_origin - cursor_x + gui->x_offset);
3058 int y = (int)(gui->y_origin - cursor_y + gui->y_offset);
3063 update_scrollbars(0);
3070 result = do_ruler(0, 1, 0, 0);
3073 case CWINDOW_CAMERA:
3074 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3077 case CWINDOW_PROJECTOR:
3078 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3083 result = test_crop(0, redraw);
3084 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3091 case CWINDOW_MASK_CONTROL_IN:
3092 case CWINDOW_MASK_CONTROL_OUT:
3093 case CWINDOW_MASK_TRANSLATE:
3095 result = do_mask(redraw,
3102 case CWINDOW_EYEDROP:
3103 result = do_eyedrop(rerender, 0, 0);
3112 // cursor font changes
3115 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3117 // mwindow->edl->session->cwindow_operation);
3118 switch(mwindow->edl->session->cwindow_operation)
3121 result = test_crop(0, redraw);
3124 result = do_ruler(0, 1, 0, 0);
3127 result = do_mask(redraw,
3137 // If the window is never unlocked before calling send_command the
3138 // display shouldn't get stuck on the old video frame although it will
3139 // flicker between the old video frame and the new video frame.
3149 gui->unlock_window();
3152 mwindow->gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3153 mwindow->gui->draw_overlays(1);
3154 mwindow->gui->unlock_window();
3156 gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3161 gui->unlock_window();
3162 mwindow->restart_brender();
3163 mwindow->sync_parameters(CHANGE_PARAMS);
3164 gui->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
3168 if(!redraw) gui->update_tool();
3169 gui->lock_window("CWindowCanvas::cursor_motion_event 2");
3174 int CWindowCanvas::button_press_event()
3178 int redraw_canvas = 0;
3181 if(Canvas::button_press_event()) return 1;
3183 gui->translating_zoom = gui->shift_down();
3186 //printf("CWindowCanvas::button_press_event 2 %f %f\n", gui->x_origin, gui->y_origin, gui->x_origin, gui->y_origin);
3188 float zoom_x, zoom_y, conformed_w, conformed_h;
3189 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3190 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3191 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3194 if(get_buttonpress() == 2)
3196 gui->current_operation = CWINDOW_SCROLL;
3202 switch(mwindow->edl->session->cwindow_operation)
3205 result = do_ruler(0, 0, 1, 0);
3208 case CWINDOW_CAMERA:
3209 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3212 case CWINDOW_PROJECTOR:
3213 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3217 result = test_zoom(redraw);
3221 result = test_crop(1, redraw);
3225 if(get_buttonpress() == 1)
3226 result = do_mask(redraw, rerender, 1, 0, 0);
3229 case CWINDOW_EYEDROP:
3230 result = do_eyedrop(rerender, 1, 0);
3238 gui->unlock_window();
3241 mwindow->gui->lock_window("CWindowCanvas::button_press_event 1");
3242 mwindow->gui->draw_overlays(1);
3243 mwindow->gui->unlock_window();
3246 gui->lock_window("CWindowCanvas::button_press_event 1");
3249 // rerendering can also be caused by press event
3252 gui->unlock_window();
3254 mwindow->restart_brender();
3255 mwindow->sync_parameters(CHANGE_PARAMS);
3256 gui->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
3260 if(!redraw) gui->update_tool();
3261 gui->lock_window("CWindowCanvas::button_press_event 2");
3266 int CWindowCanvas::button_release_event()
3270 switch(gui->current_operation)
3272 case CWINDOW_SCROLL:
3277 do_ruler(0, 0, 0, 1);
3280 case CWINDOW_CAMERA:
3281 mwindow->undo->update_undo_after(_("camera"), LOAD_AUTOMATION);
3284 case CWINDOW_PROJECTOR:
3285 mwindow->undo->update_undo_after(_("projector"), LOAD_AUTOMATION);
3289 case CWINDOW_MASK_CONTROL_IN:
3290 case CWINDOW_MASK_CONTROL_OUT:
3291 case CWINDOW_MASK_TRANSLATE:
3292 // Finish mask operation
3293 gui->mask_keyframe = 0;
3294 mwindow->undo->update_undo_after(_("mask"), LOAD_AUTOMATION);
3297 result = Canvas::button_release_event();
3301 gui->current_operation = CWINDOW_NONE;
3305 void CWindowCanvas::zoom_resize_window(float percentage)
3307 int canvas_w, canvas_h;
3311 // Get required canvas size
3312 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3313 mwindow->edl->session->output_w,
3314 mwindow->edl->session->output_h,
3319 // Estimate window size from current borders
3320 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3321 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3323 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3324 mwindow->session->cwindow_w = new_w;
3325 mwindow->session->cwindow_h = new_h;
3327 mwindow->theme->get_cwindow_sizes(gui,
3328 mwindow->session->cwindow_controls);
3330 // Estimate again from new borders
3331 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3332 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3333 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3335 gui->resize_window(new_w, new_h);
3336 gui->resize_event(new_w, new_h);
3339 void CWindowCanvas::toggle_controls()
3341 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3342 gui->resize_event(gui->get_w(), gui->get_h());
3345 int CWindowCanvas::get_cwindow_controls()
3347 return mwindow->session->cwindow_controls;