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,
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;
114 CWindowGUI::~CWindowGUI()
116 if(tool_panel) delete tool_panel;
118 delete composite_panel;
127 void CWindowGUI::create_objects()
129 lock_window("CWindowGUI::create_objects");
130 set_icon(mwindow->theme->get_image("cwindow_icon"));
132 active = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_active"));
133 inactive = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_inactive"));
135 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
136 mwindow->theme->draw_cwindow_bg(this);
139 // Meters required by composite panel
140 meters = new CWindowMeters(mwindow,
142 mwindow->theme->cmeter_x,
143 mwindow->theme->cmeter_y,
144 mwindow->theme->cmeter_h);
145 meters->create_objects();
148 composite_panel = new CPanel(mwindow,
150 mwindow->theme->ccomposite_x,
151 mwindow->theme->ccomposite_y,
152 mwindow->theme->ccomposite_w,
153 mwindow->theme->ccomposite_h);
154 composite_panel->create_objects();
156 canvas = new CWindowCanvas(mwindow, this);
158 canvas->create_objects(mwindow->edl);
159 canvas->use_cwindow();
162 add_subwindow(timebar = new CTimeBar(mwindow,
164 mwindow->theme->ctimebar_x,
165 mwindow->theme->ctimebar_y,
166 mwindow->theme->ctimebar_w,
167 mwindow->theme->ctimebar_h));
168 timebar->create_objects();
171 transport = new CWindowTransport(mwindow,
173 mwindow->theme->ctransport_x,
174 mwindow->theme->ctransport_y);
175 transport->create_objects();
177 edit_panel = new CWindowEditing(mwindow, cwindow);
178 edit_panel->set_meters(meters);
179 edit_panel->create_objects();
181 // add_subwindow(clock = new MainClock(mwindow,
182 // mwindow->theme->ctime_x,
183 // mwindow->theme->ctime_y));
185 zoom_panel = new CWindowZoom(mwindow,
187 mwindow->theme->czoom_x,
188 mwindow->theme->czoom_y,
189 mwindow->theme->czoom_w);
190 zoom_panel->create_objects();
191 zoom_panel->zoom_text->add_item(new BC_MenuItem(AUTO_ZOOM));
192 if(!mwindow->edl->session->cwindow_scrollbars) zoom_panel->set_text(AUTO_ZOOM);
194 // destination = new CWindowDestination(mwindow,
196 // mwindow->theme->cdest_x,
197 // mwindow->theme->cdest_y);
198 // destination->create_objects();
200 // Must create after meter panel
201 tool_panel = new CWindowTool(mwindow, this);
202 tool_panel->Thread::start();
205 set_operation(mwindow->edl->session->cwindow_operation);
209 canvas->draw_refresh(0);
216 int CWindowGUI::translation_event()
218 mwindow->session->cwindow_x = get_x();
219 mwindow->session->cwindow_y = get_y();
223 int CWindowGUI::resize_event(int w, int h)
225 mwindow->session->cwindow_x = get_x();
226 mwindow->session->cwindow_y = get_y();
227 mwindow->session->cwindow_w = w;
228 mwindow->session->cwindow_h = h;
230 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
231 mwindow->theme->draw_cwindow_bg(this);
234 composite_panel->reposition_buttons(mwindow->theme->ccomposite_x,
235 mwindow->theme->ccomposite_y);
237 canvas->reposition_window(mwindow->edl,
238 mwindow->theme->ccanvas_x,
239 mwindow->theme->ccanvas_y,
240 mwindow->theme->ccanvas_w,
241 mwindow->theme->ccanvas_h);
243 timebar->resize_event();
245 transport->reposition_buttons(mwindow->theme->ctransport_x,
246 mwindow->theme->ctransport_y);
248 edit_panel->reposition_buttons(mwindow->theme->cedit_x,
249 mwindow->theme->cedit_y);
251 // clock->reposition_window(mwindow->theme->ctime_x,
252 // mwindow->theme->ctime_y);
254 zoom_panel->reposition_window(mwindow->theme->czoom_x,
255 mwindow->theme->czoom_y);
257 // destination->reposition_window(mwindow->theme->cdest_x,
258 // mwindow->theme->cdest_y);
260 meters->reposition_window(mwindow->theme->cmeter_x,
261 mwindow->theme->cmeter_y,
263 mwindow->theme->cmeter_h);
267 BC_WindowBase::resize_event(w, h);
271 int CWindowGUI::button_press_event()
273 if(canvas->get_canvas())
274 return canvas->button_press_event_base(canvas->get_canvas());
278 int CWindowGUI::cursor_leave_event()
280 if(canvas->get_canvas())
281 return canvas->cursor_leave_event_base(canvas->get_canvas());
285 int CWindowGUI::cursor_enter_event()
287 if(canvas->get_canvas())
288 return canvas->cursor_enter_event_base(canvas->get_canvas());
292 int CWindowGUI::button_release_event()
294 if(canvas->get_canvas())
295 return canvas->button_release_event();
299 int CWindowGUI::cursor_motion_event()
301 if(canvas->get_canvas())
303 canvas->get_canvas()->unhide_cursor();
304 return canvas->cursor_motion_event();
315 void CWindowGUI::draw_status(int flush)
317 if( (canvas->get_canvas() && canvas->get_canvas()->get_video_on()) ||
318 canvas->is_processing )
321 mwindow->theme->cstatus_x,
322 mwindow->theme->cstatus_y);
326 draw_pixmap(inactive,
327 mwindow->theme->cstatus_x,
328 mwindow->theme->cstatus_y);
332 // printf("CWindowGUI::draw_status %d %d %d\n", __LINE__, mwindow->theme->cstatus_x,
333 // mwindow->theme->cstatus_y);
334 flash(mwindow->theme->cstatus_x,
335 mwindow->theme->cstatus_y,
342 void CWindowGUI::zoom_canvas(int do_auto, double value, int update_menu)
345 mwindow->edl->session->cwindow_scrollbars = 0;
347 mwindow->edl->session->cwindow_scrollbars = 1;
349 float old_zoom = mwindow->edl->session->cwindow_zoom;
350 float new_zoom = value;
351 float x = canvas->w / 2;
352 float y = canvas->h / 2;
353 canvas->canvas_to_output(mwindow->edl,
357 x -= canvas->w_visible / 2 * old_zoom / new_zoom;
358 y -= canvas->h_visible / 2 * old_zoom / new_zoom;
363 zoom_panel->update(AUTO_ZOOM);
367 zoom_panel->update(value);
371 canvas->update_zoom((int)x,
374 canvas->reposition_window(mwindow->edl,
375 mwindow->theme->ccanvas_x,
376 mwindow->theme->ccanvas_y,
377 mwindow->theme->ccanvas_w,
378 mwindow->theme->ccanvas_h);
379 canvas->draw_refresh();
384 void CWindowGUI::set_operation(int value)
386 mwindow->edl->session->cwindow_operation = value;
388 composite_panel->set_operation(value);
389 edit_panel->update();
391 tool_panel->start_tool(value);
392 canvas->draw_refresh();
395 void CWindowGUI::update_tool()
397 tool_panel->update_values();
400 int CWindowGUI::close_event()
402 cwindow->hide_window();
407 int CWindowGUI::keypress_event()
411 switch(get_keypress())
429 if(mwindow->session->cwindow_fullscreen)
430 canvas->stop_fullscreen();
432 canvas->start_fullscreen();
433 lock_window("CWindowGUI::keypress_event 1");
437 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
439 mwindow->gui->unlock_window();
440 lock_window("CWindowGUI::keypress_event 2");
444 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
445 mwindow->clear_entry();
446 mwindow->gui->unlock_window();
447 lock_window("CWindowGUI::keypress_event 3");
451 if(mwindow->session->cwindow_fullscreen)
452 canvas->stop_fullscreen();
453 lock_window("CWindowGUI::keypress_event 4");
460 int shift_down = this->shift_down();
462 mwindow->gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
464 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
465 mwindow->prev_edit_handle(shift_down);
466 mwindow->gui->unlock_window();
468 lock_window("CWindowGUI::keypress_event 1");
474 mwindow->gui->lock_window("CWindowGUI::keypress_event 3");
475 mwindow->move_left();
476 mwindow->gui->unlock_window();
478 lock_window("CWindowGUI::keypress_event 2");
488 int shift_down = this->shift_down();
490 mwindow->gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
492 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
493 mwindow->next_edit_handle(shift_down);
494 mwindow->gui->unlock_window();
496 lock_window("CWindowGUI::keypress_event 2");
502 mwindow->gui->lock_window("CWindowGUI::keypress_event 4");
503 mwindow->move_right();
504 mwindow->gui->unlock_window();
506 lock_window("CWindowGUI::keypress_event 3");
513 if(!result) result = transport->keypress_event();
519 void CWindowGUI::reset_affected()
526 void CWindowGUI::keyboard_zoomin()
528 // if(mwindow->edl->session->cwindow_scrollbars)
530 zoom_panel->zoom_tumbler->handle_up_event();
537 void CWindowGUI::keyboard_zoomout()
539 // if(mwindow->edl->session->cwindow_scrollbars)
541 zoom_panel->zoom_tumbler->handle_down_event();
549 void CWindowGUI::drag_motion()
551 if(get_hidden()) return;
553 if(mwindow->session->current_operation == DRAG_ASSET ||
554 mwindow->session->current_operation == DRAG_VTRANSITION ||
555 mwindow->session->current_operation == DRAG_VEFFECT)
557 int old_status = mwindow->session->ccanvas_highlighted;
558 int cursor_x = get_relative_cursor_x();
559 int cursor_y = get_relative_cursor_y();
561 mwindow->session->ccanvas_highlighted = get_cursor_over_window() &&
562 cursor_x >= canvas->x &&
563 cursor_x < canvas->x + canvas->w &&
564 cursor_y >= canvas->y &&
565 cursor_y < canvas->y + canvas->h;
568 if(old_status != mwindow->session->ccanvas_highlighted)
569 canvas->draw_refresh();
573 int CWindowGUI::drag_stop()
576 if(get_hidden()) return 0;
578 if((mwindow->session->current_operation == DRAG_ASSET ||
579 mwindow->session->current_operation == DRAG_VTRANSITION ||
580 mwindow->session->current_operation == DRAG_VEFFECT) &&
581 mwindow->session->ccanvas_highlighted)
584 mwindow->session->ccanvas_highlighted = 0;
585 canvas->draw_refresh();
591 if(mwindow->session->current_operation == DRAG_ASSET)
593 if(mwindow->session->drag_assets->total ||
594 mwindow->session->drag_clips->total)
596 mwindow->gui->lock_window("CWindowGUI::drag_stop 5");
597 mwindow->undo->update_undo_before(_("insert assets"), 0);
598 mwindow->gui->unlock_window();
601 if(mwindow->session->drag_assets->total)
603 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
605 mwindow->load_assets(mwindow->session->drag_assets,
606 mwindow->edl->local_session->get_selectionstart(),
608 mwindow->session->track_highlighted,
610 mwindow->edl->session->labels_follow_edits,
611 mwindow->edl->session->plugins_follow_edits,
612 mwindow->edl->session->autos_follow_edits);
615 if(mwindow->session->drag_clips->total)
617 mwindow->gui->lock_window("CWindowGUI::drag_stop 2");
619 mwindow->paste_edls(mwindow->session->drag_clips,
621 mwindow->session->track_highlighted,
622 mwindow->edl->local_session->get_selectionstart(),
623 mwindow->edl->session->labels_follow_edits,
624 mwindow->edl->session->plugins_follow_edits,
625 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,
698 this->mwindow = mwindow;
699 this->cwindow = cwindow;
702 #define CWrapper(fn) void CWindowEditing::fn() { \
703 mwindow->gui->lock_window("CWrapper::" #fn); \
705 mwindow->gui->unlock_window(); \
708 CWrapper(copy_selection)
709 CWrapper(splice_selection)
710 CWrapper(overwrite_selection)
711 CWrapper(set_inpoint)
712 CWrapper(set_outpoint)
713 CWrapper(clear_inpoint)
714 CWrapper(clear_outpoint)
716 CWrapper(toggle_label)
724 CWindowMeters::CWindowMeters(MWindow *mwindow,
729 : MeterPanel(mwindow,
735 mwindow->edl->session->audio_channels,
736 mwindow->edl->session->cwindow_meter,
740 this->mwindow = mwindow;
744 CWindowMeters::~CWindowMeters()
748 int CWindowMeters::change_status_event(int new_status)
750 mwindow->edl->session->cwindow_meter = new_status;
751 gui->update_meters();
758 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
761 (double)mwindow->edl->session->cwindow_zoom,
769 this->mwindow = mwindow;
773 CWindowZoom::~CWindowZoom()
777 int CWindowZoom::handle_event()
779 if(!strcasecmp(AUTO_ZOOM, get_text()))
781 gui->zoom_canvas(1, get_value(), 0);
785 gui->zoom_canvas(0, get_value(), 0);
796 CWindowTransport::CWindowTransport(MWindow *mwindow,
800 : PlayTransport(mwindow,
808 EDL* CWindowTransport::get_edl()
813 void CWindowTransport::goto_start()
815 gui->unlock_window();
816 handle_transport(REWIND, 1);
818 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
819 mwindow->goto_start();
820 mwindow->gui->unlock_window();
822 gui->lock_window("CWindowTransport::goto_start 2");
825 void CWindowTransport::goto_end()
827 gui->unlock_window();
828 handle_transport(GOTO_END, 1);
830 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
832 mwindow->gui->unlock_window();
834 gui->lock_window("CWindowTransport::goto_end 2");
839 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
842 mwindow->theme->ccanvas_x,
843 mwindow->theme->ccanvas_y,
844 mwindow->theme->ccanvas_w,
845 mwindow->theme->ccanvas_h,
848 mwindow->edl->session->cwindow_scrollbars)
850 this->mwindow = mwindow;
854 void CWindowCanvas::status_event()
859 int CWindowCanvas::get_fullscreen()
861 return mwindow->session->cwindow_fullscreen;
864 void CWindowCanvas::set_fullscreen(int value)
866 mwindow->session->cwindow_fullscreen = value;
870 void CWindowCanvas::update_zoom(int x, int y, float zoom)
872 use_scrollbars = mwindow->edl->session->cwindow_scrollbars;
874 mwindow->edl->session->cwindow_xscroll = x;
875 mwindow->edl->session->cwindow_yscroll = y;
876 mwindow->edl->session->cwindow_zoom = zoom;
879 void CWindowCanvas::zoom_auto()
881 gui->zoom_canvas(1, 1.0, 1);
884 int CWindowCanvas::get_xscroll()
886 return mwindow->edl->session->cwindow_xscroll;
889 int CWindowCanvas::get_yscroll()
891 return mwindow->edl->session->cwindow_yscroll;
895 float CWindowCanvas::get_zoom()
897 return mwindow->edl->session->cwindow_zoom;
900 void CWindowCanvas::draw_refresh(int flush)
902 if(get_canvas() && !get_canvas()->get_video_on())
905 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
907 float in_x1, in_y1, in_x2, in_y2;
908 float out_x1, out_y1, out_x2, out_y2;
909 get_transfers(mwindow->edl,
919 if(!EQUIV(out_x1, 0) ||
921 !EQUIV(out_x2, get_canvas()->get_w()) ||
922 !EQUIV(out_y2, get_canvas()->get_h()))
924 get_canvas()->clear_box(0,
926 get_canvas()->get_w(),
927 get_canvas()->get_h());
930 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
931 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
934 if(out_x2 > out_x1 &&
939 // Can't use OpenGL here because it is called asynchronously of the
940 // playback operation.
941 get_canvas()->draw_vframe(refresh_frame,
944 (int)(out_x2 - out_x1),
945 (int)(out_y2 - out_y1),
948 (int)(in_x2 - in_x1),
949 (int)(in_y2 - in_y1),
955 get_canvas()->clear_box(0,
957 get_canvas()->get_w(),
958 get_canvas()->get_h());
962 get_canvas()->flash(flush);
964 //printf("CWindowCanvas::draw_refresh 10\n");
967 #define CROPHANDLE_W 10
968 #define CROPHANDLE_H 10
970 void CWindowCanvas::draw_crophandle(int x, int y)
972 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
982 #define FIRST_CONTROL_W 20
983 #define FIRST_CONTROL_H 20
985 #define BC_INFINITY 65536
987 #define RULERHANDLE_W 16
988 #define RULERHANDLE_H 16
992 int CWindowCanvas::do_ruler(int draw,
998 float x1 = mwindow->edl->session->ruler_x1;
999 float y1 = mwindow->edl->session->ruler_y1;
1000 float x2 = mwindow->edl->session->ruler_x2;
1001 float y2 = mwindow->edl->session->ruler_y2;
1002 float canvas_x1 = x1;
1003 float canvas_y1 = y1;
1004 float canvas_x2 = x2;
1005 float canvas_y2 = y2;
1006 float output_x = get_cursor_x();
1007 float output_y = get_cursor_y();
1008 float canvas_cursor_x = output_x;
1009 float canvas_cursor_y = output_y;
1011 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1012 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1013 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1014 mwindow->session->cwindow_output_x = (int)output_x;
1015 mwindow->session->cwindow_output_y = (int)output_y;
1017 if(button_press && get_buttonpress() == 1)
1019 gui->ruler_handle = -1;
1020 gui->ruler_translate = 0;
1023 gui->ruler_translate = 1;
1024 gui->ruler_origin_x = x1;
1025 gui->ruler_origin_y = y1;
1028 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1029 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1030 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1031 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1033 gui->ruler_handle = 0;
1034 gui->ruler_origin_x = x1;
1035 gui->ruler_origin_y = y1;
1038 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1039 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1040 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1041 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1043 gui->ruler_handle = 1;
1044 gui->ruler_origin_x = x2;
1045 gui->ruler_origin_y = y2;
1049 // Start new selection
1050 if(!gui->ruler_translate &&
1051 (gui->ruler_handle < 0 ||
1052 (EQUIV(x2 - x1, 0.0) &&
1053 EQUIV(y2 - y1, 0.0))))
1056 do_ruler(1, 0, 0, 0);
1057 get_canvas()->flash();
1058 gui->ruler_handle = 1;
1059 mwindow->edl->session->ruler_x1 = output_x;
1060 mwindow->edl->session->ruler_y1 = output_y;
1061 mwindow->edl->session->ruler_x2 = output_x;
1062 mwindow->edl->session->ruler_y2 = output_y;
1063 gui->ruler_origin_x = mwindow->edl->session->ruler_x2;
1064 gui->ruler_origin_y = mwindow->edl->session->ruler_y2;
1067 gui->x_origin = output_x;
1068 gui->y_origin = output_y;
1069 gui->current_operation = CWINDOW_RULER;
1070 gui->tool_panel->raise_window();
1076 if(gui->current_operation == CWINDOW_RULER)
1078 if(gui->ruler_translate)
1081 do_ruler(1, 0, 0, 0);
1082 float x_difference = mwindow->edl->session->ruler_x1;
1083 float y_difference = mwindow->edl->session->ruler_y1;
1084 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1085 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1086 x_difference -= mwindow->edl->session->ruler_x1;
1087 y_difference -= mwindow->edl->session->ruler_y1;
1088 mwindow->edl->session->ruler_x2 -= x_difference;
1089 mwindow->edl->session->ruler_y2 -= y_difference;
1091 do_ruler(1, 0, 0, 0);
1092 get_canvas()->flash();
1095 switch(gui->ruler_handle)
1098 do_ruler(1, 0, 0, 0);
1099 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1100 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1101 if(gui->alt_down() || gui->ctrl_down())
1103 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1104 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1108 double distance_value =
1109 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1110 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1111 if(angle_value < 22)
1112 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2;
1114 if(angle_value > 67)
1115 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2;
1117 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 &&
1118 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1120 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1121 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1124 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 && mwindow->edl->session->ruler_y1 > mwindow->edl->session->ruler_y2)
1126 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1127 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1130 if(mwindow->edl->session->ruler_x1 > mwindow->edl->session->ruler_x2 &&
1131 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1133 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1134 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1138 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1139 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1142 do_ruler(1, 0, 0, 0);
1143 get_canvas()->flash();
1148 do_ruler(1, 0, 0, 0);
1149 mwindow->edl->session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1150 mwindow->edl->session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1151 if(gui->alt_down() || gui->ctrl_down())
1153 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1154 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1158 double distance_value =
1159 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1160 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1161 if(angle_value < 22)
1162 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1;
1164 if(angle_value > 67)
1165 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1;
1167 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1168 mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1170 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1171 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1174 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1175 mwindow->edl->session->ruler_y2 > mwindow->edl->session->ruler_y1)
1177 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1178 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1181 if(mwindow->edl->session->ruler_x2 > mwindow->edl->session->ruler_x1 && mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1183 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1184 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1188 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1189 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1192 do_ruler(1, 0, 0, 0);
1193 get_canvas()->flash();
1197 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1201 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1206 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1207 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1208 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1209 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1211 set_cursor(UPRIGHT_ARROW_CURSOR);
1214 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1215 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1216 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1217 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1219 set_cursor(UPRIGHT_ARROW_CURSOR);
1222 set_cursor(CROSS_CURSOR);
1224 // Update current position
1229 // Assume no ruler measurement if 0 length
1230 if(draw && (x2 - x1 || y2 - y1))
1232 get_canvas()->set_inverse();
1233 get_canvas()->set_color(WHITE);
1234 get_canvas()->draw_line((int)canvas_x1,
1238 get_canvas()->draw_line((int)canvas_x1 - RULERHANDLE_W / 2,
1240 (int)canvas_x1 + RULERHANDLE_W / 2,
1242 get_canvas()->draw_line((int)canvas_x1,
1243 (int)canvas_y1 - RULERHANDLE_H / 2,
1245 (int)canvas_y1 + RULERHANDLE_H / 2);
1246 get_canvas()->draw_line((int)canvas_x2 - RULERHANDLE_W / 2,
1248 (int)canvas_x2 + RULERHANDLE_W / 2,
1250 get_canvas()->draw_line((int)canvas_x2,
1251 (int)canvas_y2 - RULERHANDLE_H / 2,
1253 (int)canvas_y2 + RULERHANDLE_H / 2);
1254 get_canvas()->set_opaque();
1261 int CWindowCanvas::do_mask(int &redraw,
1267 // Retrieve points from top recordable track
1268 //printf("CWindowCanvas::do_mask 1\n");
1269 Track *track = gui->cwindow->calculate_affected_track();
1270 //printf("CWindowCanvas::do_mask 2\n");
1272 if(!track) return 0;
1273 //printf("CWindowCanvas::do_mask 3\n");
1275 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1276 int64_t position = track->to_units(
1277 mwindow->edl->local_session->get_selectionstart(1),
1279 ArrayList<MaskPoint*> points;
1281 // Determine the points based on whether
1282 // new keyframes will be generated or drawing is performed.
1283 // If keyframe generation occurs, use the interpolated mask.
1284 // If no keyframe generation occurs, use the previous mask.
1285 int use_interpolated = 0;
1286 if(button_press || cursor_motion)
1288 #ifdef USE_KEYFRAME_SPANNING
1289 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1290 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1293 mask_autos->get_prev_auto(track->to_units(selection_start, 0),
1298 mask_autos->get_prev_auto(track->to_units(selection_end, 0),
1303 if(last == first && (!mwindow->edl->session->auto_keyframes))
1304 use_interpolated = 0;
1306 // If keyframe spanning occurs, use the interpolated points.
1307 // If new keyframe is generated, use the interpolated points.
1308 use_interpolated = 1;
1311 if(mwindow->edl->session->auto_keyframes)
1312 use_interpolated = 1;
1316 use_interpolated = 1;
1318 if(use_interpolated)
1320 // Interpolate the points to get exactly what is being rendered at this position.
1321 mask_autos->get_points(&points,
1322 mwindow->edl->session->cwindow_mask,
1327 // Use the prev mask
1330 mask_autos->get_prev_auto(position,
1334 ((MaskAuto*)prev)->get_points(&points,
1335 mwindow->edl->session->cwindow_mask);
1338 // Projector zooms relative to the center of the track output.
1339 float half_track_w = (float)track->track_w / 2;
1340 float half_track_h = (float)track->track_h / 2;
1341 // Translate mask to projection
1342 float projector_x, projector_y, projector_z;
1343 track->automation->get_projector(&projector_x,
1350 // Get position of cursor relative to mask
1351 float mask_cursor_x = get_cursor_x();
1352 float mask_cursor_y = get_cursor_y();
1353 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1355 projector_x += mwindow->edl->session->output_w / 2;
1356 projector_y += mwindow->edl->session->output_h / 2;
1358 mask_cursor_x -= projector_x;
1359 mask_cursor_y -= projector_y;
1360 mask_cursor_x = mask_cursor_x / projector_z + half_track_w;
1361 mask_cursor_y = mask_cursor_y / projector_z + half_track_h;
1363 // Fix cursor origin
1366 gui->x_origin = mask_cursor_x;
1367 gui->y_origin = mask_cursor_y;
1371 // Points of closest line
1372 int shortest_point1 = -1;
1373 int shortest_point2 = -1;
1375 int shortest_point = -1;
1376 // Distance to closest line
1377 float shortest_line_distance = BC_INFINITY;
1378 // Distance to closest point
1379 float shortest_point_distance = BC_INFINITY;
1380 int selected_point = -1;
1381 int selected_control_point = -1;
1382 float selected_control_point_distance = BC_INFINITY;
1383 ArrayList<int> x_points;
1384 ArrayList<int> y_points;
1390 get_canvas()->set_color(WHITE);
1391 get_canvas()->set_inverse();
1393 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1395 // Never draw closed polygon and a closed
1396 // polygon is harder to add points to.
1397 for(int i = 0; i < points.size() && !result; i++)
1399 MaskPoint *point1 = points.get(i);
1400 MaskPoint *point2 = (i >= points.size() - 1) ?
1403 float x0, x1, x2, x3;
1404 float y0, y1, y2, y3;
1406 int segments = (int)(sqrt(SQR(point1->x - point2->x) + SQR(point1->y - point2->y)));
1408 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1409 //point1->x, point1->y, point2->x, point2->y, projector_z);
1410 for(int j = 0; j <= segments && !result; j++)
1412 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1415 x1 = point1->x + point1->control_x2;
1416 y1 = point1->y + point1->control_y2;
1417 x2 = point2->x + point2->control_x1;
1418 y2 = point2->y + point2->control_y1;
1422 float t = (float)j / segments;
1423 float tpow2 = t * t;
1424 float tpow3 = t * t * t;
1426 float invtpow2 = invt * invt;
1427 float invtpow3 = invt * invt * invt;
1430 + 3 * t * invtpow2 * x1
1431 + 3 * tpow2 * invt * x2
1434 + 3 * t * invtpow2 * y1
1435 + 3 * tpow2 * invt * y2
1438 x = (x - half_track_w) * projector_z + projector_x;
1439 y = (y - half_track_h) * projector_z + projector_y;
1442 // Test new point addition
1445 float line_distance =
1446 sqrt(SQR(x - mask_cursor_x) + SQR(y - mask_cursor_y));
1448 //printf("CWindowCanvas::do_mask 1 x=%f mask_cursor_x=%f y=%f mask_cursor_y=%f %f %f %d, %d\n",
1449 //x, mask_cursor_x, y, mask_cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1450 if(line_distance < shortest_line_distance ||
1451 shortest_point1 < 0)
1453 shortest_line_distance = line_distance;
1454 shortest_point1 = i;
1455 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1456 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n", line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1460 float point_distance1 =
1461 sqrt(SQR(point1->x - mask_cursor_x) + SQR(point1->y - mask_cursor_y));
1462 float point_distance2 =
1463 sqrt(SQR(point2->x - mask_cursor_x) + SQR(point2->y - mask_cursor_y));
1465 if(point_distance1 < shortest_point_distance ||
1468 shortest_point_distance = point_distance1;
1472 if(point_distance2 < shortest_point_distance ||
1475 shortest_point_distance = point_distance2;
1476 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1480 output_to_canvas(mwindow->edl, 0, x, y);
1483 #define TEST_BOX(cursor_x, cursor_y, target_x, target_y) \
1484 (cursor_x >= target_x - CONTROL_W / 2 && \
1485 cursor_x < target_x + CONTROL_W / 2 && \
1486 cursor_y >= target_y - CONTROL_H / 2 && \
1487 cursor_y < target_y + CONTROL_H / 2)
1489 // Test existing point selection
1492 float canvas_x = (x0 - half_track_w) * projector_z + projector_x;
1493 float canvas_y = (y0 - half_track_h) * projector_z + projector_y;
1494 int cursor_x = get_cursor_x();
1495 int cursor_y = get_cursor_y();
1498 if(gui->shift_down())
1500 float control_x = (x1 - half_track_w) * projector_z + projector_x;
1501 float control_y = (y1 - half_track_h) * projector_z + projector_y;
1502 output_to_canvas(mwindow->edl, 0, control_x, control_y);
1505 sqrt(SQR(control_x - cursor_x) + SQR(control_y - cursor_y));
1507 if(distance < selected_control_point_distance)
1510 selected_control_point = 1;
1511 selected_control_point_distance = distance;
1516 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1517 if(!gui->ctrl_down())
1519 if(TEST_BOX(cursor_x, cursor_y, canvas_x, canvas_y))
1526 selected_point = shortest_point;
1530 // Test second point
1531 canvas_x = (x3 - half_track_w) * projector_z + projector_x;
1532 canvas_y = (y3 - half_track_h) * projector_z + projector_y;
1533 if(gui->shift_down())
1535 float control_x = (x2 - half_track_w) * projector_z + projector_x;
1536 float control_y = (y2 - half_track_h) * projector_z + projector_y;
1537 output_to_canvas(mwindow->edl, 0, control_x, control_y);
1540 sqrt(SQR(control_x - cursor_x) + SQR(control_y - cursor_y));
1542 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1543 if(distance < selected_control_point_distance)
1545 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1546 selected_control_point = 0;
1547 selected_control_point_distance = distance;
1551 if(i < points.size() - 1)
1553 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1554 if(!gui->ctrl_down())
1556 if(TEST_BOX(cursor_x, cursor_y, canvas_x, canvas_y))
1558 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1563 selected_point = shortest_point;
1572 // Draw joining line
1575 x_points.append((int)x);
1576 y_points.append((int)y);
1587 // Draw second anchor
1588 if(i < points.size() - 1)
1590 if(i == gui->affected_point - 1)
1591 get_canvas()->draw_disc((int)x - CONTROL_W / 2,
1592 (int)y - CONTROL_W / 2,
1596 get_canvas()->draw_circle((int)x - CONTROL_W / 2,
1597 (int)y - CONTROL_W / 2,
1600 // char string[BCTEXTLEN];
1601 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1602 // canvas->draw_text((int)x + CONTROL_W, (int)y + CONTROL_W, string);
1605 // Draw second control point. Discard x2 and y2 after this.
1606 x2 = (x2 - half_track_w) * projector_z + projector_x;
1607 y2 = (y2 - half_track_h) * projector_z + projector_y;
1608 output_to_canvas(mwindow->edl, 0, x2, y2);
1609 get_canvas()->draw_line((int)x, (int)y, (int)x2, (int)y2);
1610 get_canvas()->draw_rectangle((int)x2 - CONTROL_W / 2,
1611 (int)y2 - CONTROL_H / 2,
1621 // Draw first anchor
1624 get_canvas()->draw_disc((int)x - FIRST_CONTROL_W / 2,
1625 (int)y - FIRST_CONTROL_H / 2,
1630 // Draw first control point. Discard x1 and y1 after this.
1633 x1 = (x1 - half_track_w) * projector_z + projector_x;
1634 y1 = (y1 - half_track_h) * projector_z + projector_y;
1635 output_to_canvas(mwindow->edl, 0, x1, y1);
1636 get_canvas()->draw_line((int)x, (int)y, (int)x1, (int)y1);
1637 get_canvas()->draw_rectangle((int)x1 - CONTROL_W / 2,
1638 (int)y1 - CONTROL_H / 2,
1642 x_points.append((int)x);
1643 y_points.append((int)y);
1646 //printf("CWindowCanvas::do_mask 1\n");
1650 //printf("CWindowCanvas::do_mask 1\n");
1654 get_canvas()->draw_polygon(&x_points, &y_points);
1655 get_canvas()->set_opaque();
1657 //printf("CWindowCanvas::do_mask 1\n");
1666 if(button_press && !result)
1668 gui->affected_track = gui->cwindow->calculate_affected_track();
1670 // Get keyframe outside the EDL to edit. This must be rendered
1671 // instead of the EDL keyframes when it exists. Then it must be
1672 // applied to the EDL keyframes on buttonrelease.
1673 if(gui->affected_track)
1675 #ifdef USE_KEYFRAME_SPANNING
1676 // Make copy of current parameters in local keyframe
1677 gui->mask_keyframe =
1678 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1681 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1684 gui->mask_keyframe =
1685 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1690 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1693 // Translate entire keyframe
1694 if(gui->alt_down() && mask->points.size())
1696 mwindow->undo->update_undo_before(_("mask translate"), 0);
1697 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1698 gui->affected_point = 0;
1701 // Existing point or control point was selected
1702 if(selected_point >= 0)
1704 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1705 gui->affected_point = selected_point;
1707 if(selected_control_point == 0)
1708 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1710 if(selected_control_point == 1)
1711 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1713 gui->current_operation = mwindow->edl->session->cwindow_operation;
1716 // No existing point or control point was selected so create a new one
1717 if(!gui->shift_down() && !gui->alt_down())
1719 mwindow->undo->update_undo_before(_("mask point"), 0);
1720 // Create the template
1721 MaskPoint *point = new MaskPoint;
1722 point->x = mask_cursor_x;
1723 point->y = mask_cursor_y;
1724 point->control_x1 = 0;
1725 point->control_y1 = 0;
1726 point->control_x2 = 0;
1727 point->control_y2 = 0;
1730 if(shortest_point2 < shortest_point1)
1732 shortest_point2 ^= shortest_point1;
1733 shortest_point1 ^= shortest_point2;
1734 shortest_point2 ^= shortest_point1;
1739 // printf("CWindowGUI::do_mask 40\n");
1740 // mwindow->edl->dump();
1741 // printf("CWindowGUI::do_mask 50\n");
1745 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1746 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1747 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1749 // Append to end of list
1750 if(labs(shortest_point1 - shortest_point2) > 1)
1752 #ifdef USE_KEYFRAME_SPANNING
1754 MaskPoint *new_point = new MaskPoint;
1755 points.append(new_point);
1756 *new_point = *point;
1757 gui->affected_point = points.size() - 1;
1761 // Need to apply the new point to every keyframe
1762 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto;
1765 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1766 MaskPoint *new_point = new MaskPoint;
1767 submask->points.append(new_point);
1768 *new_point = *point;
1769 if(current == (MaskAuto*)mask_autos->default_auto)
1770 current = (MaskAuto*)mask_autos->first;
1772 current = (MaskAuto*)NEXT;
1774 gui->affected_point = mask->points.size() - 1;
1780 // Insert between 2 points, shifting back point 2
1781 if(shortest_point1 >= 0 && shortest_point2 >= 0)
1784 #ifdef USE_KEYFRAME_SPANNING
1785 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1787 if(points.size() >= shortest_point2)
1789 MaskPoint *new_point = new MaskPoint;
1791 for(int i = points.size() - 1;
1792 i > shortest_point2;
1794 points.values[i] = points.values[i - 1];
1795 points.values[shortest_point2] = new_point;
1797 *new_point = *point;
1802 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto;
1805 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1806 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1808 if(submask->points.size() >= shortest_point2)
1810 MaskPoint *new_point = new MaskPoint;
1811 submask->points.append(0);
1812 for(int i = submask->points.size() - 1;
1813 i > shortest_point2;
1815 submask->points.values[i] = submask->points.values[i - 1];
1816 submask->points.values[shortest_point2] = new_point;
1818 *new_point = *point;
1821 if(current == (MaskAuto*)mask_autos->default_auto)
1822 current = (MaskAuto*)mask_autos->first;
1824 current = (MaskAuto*)NEXT;
1829 gui->affected_point = shortest_point2;
1834 // printf("CWindowGUI::do_mask 20\n");
1835 // mwindow->edl->dump();
1836 // printf("CWindowGUI::do_mask 30\n");
1843 //printf("CWindowCanvas::do_mask 1\n");
1844 // Create the first point.
1845 #ifdef USE_KEYFRAME_SPANNING
1846 MaskPoint *new_point = new MaskPoint;
1847 points.append(new_point);
1848 *new_point = *point;
1850 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto;
1853 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1854 MaskPoint *new_point = new MaskPoint;
1855 submask->points.append(new_point);
1856 *new_point = *point;
1857 if(current == (MaskAuto*)mask_autos->default_auto)
1858 current = (MaskAuto*)mask_autos->first;
1860 current = (MaskAuto*)NEXT;
1864 //printf("CWindowCanvas::do_mask 2\n");
1865 // Create a second point if none existed before
1866 #ifdef USE_KEYFRAME_SPANNING
1867 if(points.size() < 2)
1870 MaskPoint *new_point = new MaskPoint;
1871 points.append(new_point);
1872 *new_point = *point;
1875 gui->affected_point = points.size() - 1;
1877 if(mask->points.size() < 2)
1880 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto;
1883 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1884 MaskPoint *new_point = new MaskPoint;
1885 submask->points.append(new_point);
1886 *new_point = *point;
1887 if(current == (MaskAuto*)mask_autos->default_auto)
1888 current = (MaskAuto*)mask_autos->first;
1890 current = (MaskAuto*)NEXT;
1894 gui->affected_point = mask->points.size() - 1;
1897 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
1902 gui->current_operation = mwindow->edl->session->cwindow_operation;
1903 // Delete the template
1913 if(button_press && result)
1915 #ifdef USE_KEYFRAME_SPANNING
1916 MaskPoint *point = points.values[gui->affected_point];
1917 gui->center_x = point->x;
1918 gui->center_y = point->y;
1919 gui->control_in_x = point->control_x1;
1920 gui->control_in_y = point->control_y1;
1921 gui->control_out_x = point->control_x2;
1922 gui->control_out_y = point->control_y2;
1923 gui->tool_panel->raise_window();
1925 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1926 MaskPoint *point = mask->points.values[gui->affected_point];
1927 gui->center_x = point->x;
1928 gui->center_y = point->y;
1929 gui->control_in_x = point->control_x1;
1930 gui->control_in_y = point->control_y1;
1931 gui->control_out_x = point->control_x2;
1932 gui->control_out_y = point->control_y2;
1933 gui->tool_panel->raise_window();
1937 //printf("CWindowCanvas::do_mask 8\n");
1941 #ifdef USE_KEYFRAME_SPANNING
1942 // Must update the reference keyframes for every cursor motion
1943 gui->mask_keyframe =
1944 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1947 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1950 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1952 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1953 if(gui->affected_point < mask->points.size() &&
1954 gui->current_operation != CWINDOW_NONE)
1956 // mwindow->undo->update_undo_before(_("mask point"), this);
1957 #ifdef USE_KEYFRAME_SPANNING
1958 MaskPoint *point = points.get(gui->affected_point);
1960 MaskPoint *point = mask->points.get(gui->affected_point);
1962 // float cursor_x = get_cursor_x();
1963 // float cursor_y = get_cursor_y();
1964 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
1965 float cursor_x = mask_cursor_x;
1966 float cursor_y = mask_cursor_y;
1967 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask->points.size(), gui->affected_point);
1969 float last_x = point->x;
1970 float last_y = point->y;
1971 float last_control_x1 = point->control_x1;
1972 float last_control_y1 = point->control_y1;
1973 float last_control_x2 = point->control_x2;
1974 float last_control_y2 = point->control_y2;
1977 switch(gui->current_operation)
1980 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1981 point->x = cursor_x - gui->x_origin + gui->center_x;
1982 point->y = cursor_y - gui->y_origin + gui->center_y;
1985 case CWINDOW_MASK_CONTROL_IN:
1986 point->control_x1 = cursor_x - gui->x_origin + gui->control_in_x;
1987 point->control_y1 = cursor_y - gui->y_origin + gui->control_in_y;
1990 case CWINDOW_MASK_CONTROL_OUT:
1991 point->control_x2 = cursor_x - gui->x_origin + gui->control_out_x;
1992 point->control_y2 = cursor_y - gui->y_origin + gui->control_out_y;
1995 case CWINDOW_MASK_TRANSLATE:
1996 #ifdef USE_KEYFRAME_SPANNING
1997 for(int i = 0; i < points.size(); i++)
1999 points.values[i]->x += cursor_x - gui->x_origin;
2000 points.values[i]->y += cursor_y - gui->y_origin;
2003 for(int i = 0; i < mask->points.size(); i++)
2005 mask->points.values[i]->x += cursor_x - gui->x_origin;
2006 mask->points.values[i]->y += cursor_y - gui->y_origin;
2009 gui->x_origin = cursor_x;
2010 gui->y_origin = cursor_y;
2015 if( !EQUIV(last_x, point->x) ||
2016 !EQUIV(last_y, point->y) ||
2017 !EQUIV(last_control_x1, point->control_x1) ||
2018 !EQUIV(last_control_y1, point->control_y1) ||
2019 !EQUIV(last_control_x2, point->control_x2) ||
2020 !EQUIV(last_control_y2, point->control_y2))
2027 if(gui->current_operation == CWINDOW_NONE)
2029 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
2031 for(int i = 0; i < points.size() && !over_point; i++)
2033 MaskPoint *point = points.get(i);
2034 float x0 = point->x;
2035 float y0 = point->y;
2036 float x1 = point->x + point->control_x1;
2037 float y1 = point->y + point->control_y1;
2038 float x2 = point->x + point->control_x2;
2039 float y2 = point->y + point->control_y2;
2040 float canvas_x = (x0 - half_track_w) * projector_z + projector_x;
2041 float canvas_y = (y0 - half_track_h) * projector_z + projector_y;
2042 int cursor_x = get_cursor_x();
2043 int cursor_y = get_cursor_y();
2045 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
2046 if(TEST_BOX(cursor_x, cursor_y, canvas_x, canvas_y))
2052 if(!over_point && gui->shift_down())
2054 canvas_x = (x1 - half_track_w) * projector_z + projector_x;
2055 canvas_y = (y1 - half_track_h) * projector_z + projector_y;
2056 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
2057 if(TEST_BOX(cursor_x, cursor_y, canvas_x, canvas_y))
2063 canvas_x = (x2 - half_track_w) * projector_z + projector_x;
2064 canvas_y = (y2 - half_track_h) * projector_z + projector_y;
2065 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
2066 if(TEST_BOX(cursor_x, cursor_y, canvas_x, canvas_y))
2076 set_cursor(ARROW_CURSOR);
2080 set_cursor(CROSS_CURSOR);
2086 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2089 #ifdef USE_KEYFRAME_SPANNING
2090 // Must commit change after operation.
2091 if(rerender && track)
2093 // Swap EDL keyframe with original.
2094 // Apply new values to keyframe span
2095 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2096 temp_keyframe.copy_data(gui->mask_keyframe);
2097 // Apply interpolated points back to keyframe
2098 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2099 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2100 mask_autos->update_parameter(&temp_keyframe);
2104 points.remove_all_objects();
2105 //printf("CWindowCanvas::do_mask 20\n");
2110 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2113 int radius = mwindow->edl->session->eyedrop_radius;
2121 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2126 row1 = gui->eyedrop_y - radius;
2127 row2 = gui->eyedrop_y + radius;
2128 column1 = gui->eyedrop_x - radius;
2129 column2 = gui->eyedrop_x + radius;
2131 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2132 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2133 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2134 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2136 if(row2 <= row1) row2 = row1 + 1;
2137 if(column2 <= column1) column2 = column1 + 1;
2144 output_to_canvas(mwindow->edl, 0, x1, y1);
2145 output_to_canvas(mwindow->edl, 0, x2, y2);
2146 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2148 if(x2 - x1 >= 1 && y2 - y1 >= 1)
2150 get_canvas()->set_inverse();
2151 get_canvas()->set_color(WHITE);
2153 get_canvas()->draw_rectangle((int)x1,
2158 get_canvas()->set_opaque();
2159 get_canvas()->flash();
2167 gui->current_operation = CWINDOW_EYEDROP;
2168 gui->tool_panel->raise_window();
2171 if(gui->current_operation == CWINDOW_EYEDROP)
2173 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2175 // Get color out of frame.
2176 // Doesn't work during playback because that bypasses the refresh frame.
2177 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2179 float cursor_x = get_cursor_x();
2180 float cursor_y = get_cursor_y();
2181 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2182 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2183 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2185 row1 = cursor_y - radius;
2186 row2 = cursor_y + radius;
2187 column1 = cursor_x - radius;
2188 column2 = cursor_x + radius;
2189 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2190 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2191 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2192 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2193 if(row2 <= row1) row2 = row1 + 1;
2194 if(column2 <= column1) column2 = column1 + 1;
2198 if(gui->eyedrop_visible)
2201 do_eyedrop(temp, 0, 1);
2202 gui->eyedrop_visible = 0;
2205 gui->eyedrop_x = cursor_x;
2206 gui->eyedrop_y = cursor_y;
2211 do_eyedrop(temp, 0, 1);
2212 gui->eyedrop_visible = 1;
2215 // Decompression coefficients straight out of jpeglib
2216 #define V_TO_R 1.40200
2217 #define V_TO_G -0.71414
2219 #define U_TO_G -0.34414
2220 #define U_TO_B 1.77200
2222 #define GET_COLOR(type, components, max, do_yuv) \
2224 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2226 float red = (float)*row++ / max; \
2227 float green = (float)*row++ / max; \
2228 float blue = (float)*row++ / max; \
2231 mwindow->edl->local_session->red += red + V_TO_R * (blue - 0.5); \
2232 mwindow->edl->local_session->green += red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
2233 mwindow->edl->local_session->blue += red + U_TO_B * (green - 0.5); \
2237 mwindow->edl->local_session->red += red; \
2238 mwindow->edl->local_session->green += green; \
2239 mwindow->edl->local_session->blue += blue; \
2245 mwindow->edl->local_session->red = 0;
2246 mwindow->edl->local_session->green = 0;
2247 mwindow->edl->local_session->blue = 0;
2248 for(int i = row1; i < row2; i++)
2250 for(int j = column1; j < column2; j++)
2252 switch(refresh_frame->get_color_model())
2255 GET_COLOR(unsigned char, 3, 0xff, 1);
2258 GET_COLOR(unsigned char, 4, 0xff, 1);
2261 GET_COLOR(uint16_t, 3, 0xffff, 1);
2263 case BC_YUVA16161616:
2264 GET_COLOR(uint16_t, 4, 0xffff, 1);
2267 GET_COLOR(unsigned char, 3, 0xff, 0);
2270 GET_COLOR(unsigned char, 4, 0xff, 0);
2273 GET_COLOR(float, 3, 1.0, 0);
2276 GET_COLOR(float, 4, 1.0, 0);
2282 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2283 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2284 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2289 mwindow->edl->local_session->red = 0;
2290 mwindow->edl->local_session->green = 0;
2291 mwindow->edl->local_session->blue = 0;
2292 gui->eyedrop_visible = 0;
2301 // Can't rerender since the color value is from the output of any effect it
2304 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2310 void CWindowCanvas::draw_overlays()
2312 if(mwindow->edl->session->safe_regions)
2314 draw_safe_regions();
2317 if(mwindow->edl->session->cwindow_scrollbars)
2319 // Always draw output rectangle
2320 float x1, y1, x2, y2;
2322 x2 = mwindow->edl->session->output_w;
2324 y2 = mwindow->edl->session->output_h;
2325 output_to_canvas(mwindow->edl, 0, x1, y1);
2326 output_to_canvas(mwindow->edl, 0, x2, y2);
2328 get_canvas()->set_inverse();
2329 get_canvas()->set_color(WHITE);
2331 get_canvas()->draw_rectangle((int)x1,
2336 get_canvas()->set_opaque();
2339 if(mwindow->session->ccanvas_highlighted)
2341 get_canvas()->set_color(WHITE);
2342 get_canvas()->set_inverse();
2343 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2344 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2345 get_canvas()->set_opaque();
2348 int temp1 = 0, temp2 = 0;
2349 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2350 switch(mwindow->edl->session->cwindow_operation)
2352 case CWINDOW_CAMERA:
2356 case CWINDOW_PROJECTOR:
2365 do_mask(temp1, temp2, 0, 0, 1);
2369 do_ruler(1, 0, 0, 0);
2372 case CWINDOW_EYEDROP:
2373 if(gui->eyedrop_visible)
2376 do_eyedrop(rerender, 0, 1);
2377 gui->eyedrop_visible = 1;
2383 void CWindowCanvas::draw_safe_regions()
2385 float action_x1, action_x2, action_y1, action_y2;
2386 float title_x1, title_x2, title_y1, title_y2;
2388 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2389 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2390 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2391 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2392 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2393 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2394 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2395 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2397 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2398 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2399 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2400 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2402 get_canvas()->set_inverse();
2403 get_canvas()->set_color(WHITE);
2405 get_canvas()->draw_rectangle((int)action_x1,
2407 (int)(action_x2 - action_x1),
2408 (int)(action_y2 - action_y1));
2409 get_canvas()->draw_rectangle((int)title_x1,
2411 (int)(title_x2 - title_x1),
2412 (int)(title_y2 - title_y1));
2414 get_canvas()->set_opaque();
2417 void CWindowCanvas::reset_keyframe(int do_camera)
2419 FloatAuto *x_keyframe = 0;
2420 FloatAuto *y_keyframe = 0;
2421 FloatAuto *z_keyframe = 0;
2422 Track *affected_track = 0;
2424 affected_track = gui->cwindow->calculate_affected_track();
2428 gui->cwindow->calculate_affected_autos(&x_keyframe,
2437 x_keyframe->value = 0;
2438 y_keyframe->value = 0;
2439 z_keyframe->value = 1;
2441 mwindow->sync_parameters(CHANGE_PARAMS);
2446 void CWindowCanvas::reset_camera()
2451 void CWindowCanvas::reset_projector()
2456 int CWindowCanvas::test_crop(int button_press, int &redraw)
2459 int handle_selected = -1;
2460 float x1 = mwindow->edl->session->crop_x1;
2461 float y1 = mwindow->edl->session->crop_y1;
2462 float x2 = mwindow->edl->session->crop_x2;
2463 float y2 = mwindow->edl->session->crop_y2;
2464 float cursor_x = get_cursor_x();
2465 float cursor_y = get_cursor_y();
2466 float canvas_x1 = x1;
2467 float canvas_y1 = y1;
2468 float canvas_x2 = x2;
2469 float canvas_y2 = y2;
2470 float canvas_cursor_x = cursor_x;
2471 float canvas_cursor_y = cursor_y;
2473 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2474 // Use screen normalized coordinates for hot spot tests.
2475 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2476 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2479 if(gui->current_operation == CWINDOW_CROP)
2481 handle_selected = gui->crop_handle;
2484 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2485 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2487 handle_selected = 0;
2488 gui->crop_origin_x = x1;
2489 gui->crop_origin_y = y1;
2492 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2493 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2495 handle_selected = 1;
2496 gui->crop_origin_x = x2;
2497 gui->crop_origin_y = y1;
2500 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2501 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2503 handle_selected = 2;
2504 gui->crop_origin_x = x1;
2505 gui->crop_origin_y = y2;
2508 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2509 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2511 handle_selected = 3;
2512 gui->crop_origin_x = x2;
2513 gui->crop_origin_y = y2;
2518 gui->crop_origin_x = cursor_x;
2519 gui->crop_origin_y = cursor_y;
2522 // printf("test crop %d %d\n",
2523 // gui->current_operation,
2524 // handle_selected);
2531 gui->crop_translate = 1;
2532 gui->crop_origin_x1 = x1;
2533 gui->crop_origin_y1 = y1;
2534 gui->crop_origin_x2 = x2;
2535 gui->crop_origin_y2 = y2;
2538 gui->crop_translate = 0;
2540 gui->current_operation = CWINDOW_CROP;
2541 gui->crop_handle = handle_selected;
2542 gui->x_origin = cursor_x;
2543 gui->y_origin = cursor_y;
2544 gui->tool_panel->raise_window();
2547 if(handle_selected < 0 && !gui->crop_translate)
2551 mwindow->edl->session->crop_x1 = (int)x1;
2552 mwindow->edl->session->crop_y1 = (int)y1;
2553 mwindow->edl->session->crop_x2 = (int)x2;
2554 mwindow->edl->session->crop_y2 = (int)y2;
2559 // Translate all 4 points
2560 if(gui->current_operation == CWINDOW_CROP && gui->crop_translate)
2562 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2563 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2564 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2565 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2567 mwindow->edl->session->crop_x1 = (int)x1;
2568 mwindow->edl->session->crop_y1 = (int)y1;
2569 mwindow->edl->session->crop_x2 = (int)x2;
2570 mwindow->edl->session->crop_y2 = (int)y2;
2576 if(gui->current_operation == CWINDOW_CROP)
2578 switch(gui->crop_handle)
2581 x1 = gui->crop_origin_x;
2582 y1 = gui->crop_origin_y;
2583 x2 = gui->crop_origin_x;
2584 y2 = gui->crop_origin_y;
2585 if(cursor_x < gui->x_origin)
2587 if(cursor_y < gui->y_origin)
2593 if(cursor_y >= gui->y_origin)
2600 if(cursor_x >= gui->x_origin)
2602 if(cursor_y < gui->y_origin)
2608 if(cursor_y >= gui->y_origin)
2615 // printf("test crop %d %d %d %d\n",
2616 // mwindow->edl->session->crop_x1,
2617 // mwindow->edl->session->crop_y1,
2618 // mwindow->edl->session->crop_x2,
2619 // mwindow->edl->session->crop_y2);
2622 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2623 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2626 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2627 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2630 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2631 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2634 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2635 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2639 if(!EQUIV(mwindow->edl->session->crop_x1, x1) ||
2640 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2641 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2642 !EQUIV(mwindow->edl->session->crop_y2, y2))
2649 switch (gui->crop_handle)
2651 case 0: gui->crop_handle = 1; break;
2652 case 1: gui->crop_handle = 0; break;
2653 case 2: gui->crop_handle = 3; break;
2654 case 3: gui->crop_handle = 2; break;
2664 switch (gui->crop_handle)
2666 case 0: gui->crop_handle = 2; break;
2667 case 1: gui->crop_handle = 3; break;
2668 case 2: gui->crop_handle = 0; break;
2669 case 3: gui->crop_handle = 1; break;
2674 mwindow->edl->session->crop_x1 = (int)x1;
2675 mwindow->edl->session->crop_y1 = (int)y1;
2676 mwindow->edl->session->crop_x2 = (int)x2;
2677 mwindow->edl->session->crop_y2 = (int)y2;
2683 // Update cursor font
2684 if(handle_selected >= 0)
2686 switch(handle_selected)
2689 set_cursor(UPLEFT_RESIZE);
2692 set_cursor(UPRIGHT_RESIZE);
2695 set_cursor(DOWNLEFT_RESIZE);
2698 set_cursor(DOWNRIGHT_RESIZE);
2705 set_cursor(ARROW_CURSOR);
2707 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2711 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2712 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2713 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2714 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2715 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2716 // mwindow->edl->session->crop_x2,
2717 // mwindow->edl->session->crop_y2,
2718 // mwindow->edl->calculate_output_w(0),
2719 // mwindow->edl->calculate_output_h(0));
2725 void CWindowCanvas::draw_crop()
2727 get_canvas()->set_inverse();
2728 get_canvas()->set_color(WHITE);
2730 float x1 = mwindow->edl->session->crop_x1;
2731 float y1 = mwindow->edl->session->crop_y1;
2732 float x2 = mwindow->edl->session->crop_x2;
2733 float y2 = mwindow->edl->session->crop_y2;
2735 output_to_canvas(mwindow->edl, 0, x1, y1);
2736 output_to_canvas(mwindow->edl, 0, x2, y2);
2738 if(x2 - x1 && y2 - y1)
2739 get_canvas()->draw_rectangle((int)x1,
2744 draw_crophandle((int)x1, (int)y1);
2745 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2746 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2747 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2748 get_canvas()->set_opaque();
2758 void CWindowCanvas::draw_bezier(int do_camera)
2760 Track *track = gui->cwindow->calculate_affected_track();
2767 int64_t position = track->to_units(
2768 mwindow->edl->local_session->get_selectionstart(1),
2771 track->automation->get_projector(¢er_x,
2777 // center_x += track->track_w / 2;
2778 // center_y += track->track_h / 2;
2779 center_x += mwindow->edl->session->output_w / 2;
2780 center_y += mwindow->edl->session->output_h / 2;
2781 float track_x1 = center_x - track->track_w / 2 * center_z;
2782 float track_y1 = center_y - track->track_h / 2 * center_z;
2783 float track_x2 = track_x1 + track->track_w * center_z;
2784 float track_y2 = track_y1 + track->track_h * center_z;
2786 output_to_canvas(mwindow->edl, 0, track_x1, track_y1);
2787 output_to_canvas(mwindow->edl, 0, track_x2, track_y2);
2789 #define DRAW_PROJECTION(offset) \
2790 get_canvas()->draw_rectangle((int)track_x1 + offset, \
2791 (int)track_y1 + offset, \
2792 (int)(track_x2 - track_x1), \
2793 (int)(track_y2 - track_y1)); \
2794 get_canvas()->draw_line((int)track_x1 + offset, \
2795 (int)track_y1 + offset, \
2796 (int)track_x2 + offset, \
2797 (int)track_y2 + offset); \
2798 get_canvas()->draw_line((int)track_x2 + offset, \
2799 (int)track_y1 + offset, \
2800 (int)track_x1 + offset, \
2801 (int)track_y2 + offset); \
2805 get_canvas()->set_color(BLACK);
2808 // canvas->set_inverse();
2810 get_canvas()->set_color(GREEN);
2812 get_canvas()->set_color(RED);
2815 // canvas->set_opaque();
2821 int CWindowCanvas::test_bezier(int button_press,
2829 // Processing drag operation.
2830 // Create keyframe during first cursor motion.
2834 float cursor_x = get_cursor_x();
2835 float cursor_y = get_cursor_y();
2836 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2838 if(gui->current_operation == CWINDOW_CAMERA ||
2839 gui->current_operation == CWINDOW_PROJECTOR)
2841 if(!gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom)
2843 gui->translating_zoom = 1;
2844 gui->reset_affected();
2847 if(!gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom)
2849 gui->translating_zoom = 0;
2850 gui->reset_affected();
2853 // Get target keyframe
2854 float last_center_x;
2855 float last_center_y;
2856 float last_center_z;
2859 if(!gui->affected_x && !gui->affected_y && !gui->affected_z)
2861 FloatAutos *affected_x_autos;
2862 FloatAutos *affected_y_autos;
2863 FloatAutos *affected_z_autos;
2864 if(!gui->affected_track) return 0;
2865 double position = mwindow->edl->local_session->get_selectionstart(1);
2866 int64_t track_position = gui->affected_track->to_units(position, 0);
2868 if(mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA)
2870 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_X];
2871 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Y];
2872 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Z];
2876 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_X];
2877 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Y];
2878 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Z];
2882 if(gui->translating_zoom)
2884 FloatAuto *previous = 0;
2885 FloatAuto *next = 0;
2886 float new_z = affected_z_autos->get_value(
2892 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2893 affected_z_autos, 1, &created, 0);
2896 gui->affected_z->value = new_z;
2897 gui->affected_z->control_in_value = 0;
2898 gui->affected_z->control_out_value = 0;
2899 // gui->affected_z->control_in_position = 0;
2900 // gui->affected_z->control_out_position = 0;
2906 FloatAuto *previous = 0;
2907 FloatAuto *next = 0;
2908 float new_x = affected_x_autos->get_value(
2915 float new_y = affected_y_autos->get_value(
2921 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2922 affected_x_autos, 1, &created, 0);
2925 gui->affected_x->value = new_x;
2926 gui->affected_x->control_in_value = 0;
2927 gui->affected_x->control_out_value = 0;
2928 // gui->affected_x->control_in_position = 0;
2929 // gui->affected_x->control_out_position = 0;
2933 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2934 affected_y_autos, 1, &created, 0);
2937 gui->affected_y->value = new_y;
2938 gui->affected_y->control_in_value = 0;
2939 gui->affected_y->control_out_value = 0;
2940 // gui->affected_y->control_in_position = 0;
2941 // gui->affected_y->control_out_position = 0;
2948 if(gui->translating_zoom)
2950 gui->center_z = gui->affected_z->value;
2954 gui->center_x = gui->affected_x->value;
2955 gui->center_y = gui->affected_y->value;
2963 if(gui->translating_zoom)
2965 last_center_z = gui->affected_z->value;
2969 last_center_x = gui->affected_x->value;
2970 last_center_y = gui->affected_y->value;
2973 if(gui->translating_zoom)
2975 gui->affected_z->value = gui->center_z +
2976 (cursor_y - gui->y_origin) / 128;
2978 if(gui->affected_z->value < 0) gui->affected_z->value = 0;
2979 if(!EQUIV(last_center_z, gui->affected_z->value))
2988 gui->affected_x->value = gui->center_x + cursor_x - gui->x_origin;
2989 gui->affected_y->value = gui->center_y + cursor_y - gui->y_origin;
2990 if(!EQUIV(last_center_x, gui->affected_x->value) ||
2991 !EQUIV(last_center_y, gui->affected_y->value))
3003 // Begin drag operation. Don't create keyframe here.
3005 // Get affected track off of the first recordable video track.
3006 // Calculating based on the alpha channel would require recording what layer
3007 // each output pixel belongs to as they're rendered and stacked. Forget it.
3008 gui->affected_track = gui->cwindow->calculate_affected_track();
3009 gui->reset_affected();
3011 if(gui->affected_track)
3013 if(gui->current_operation == CWINDOW_CAMERA)
3014 mwindow->undo->update_undo_before(_("camera"), this);
3016 mwindow->undo->update_undo_before(_("projector"), this);
3018 gui->current_operation =
3019 mwindow->edl->session->cwindow_operation;
3020 gui->tool_panel->raise_window();
3028 int CWindowCanvas::test_zoom(int &redraw)
3031 float zoom = get_zoom();
3035 if(!mwindow->edl->session->cwindow_scrollbars)
3037 mwindow->edl->session->cwindow_scrollbars = 1;
3039 x = mwindow->edl->session->output_w / 2;
3040 y = mwindow->edl->session->output_h / 2;
3041 x = x - w / zoom / 2;
3042 y = y - h / zoom / 2;
3046 // Cursor position relative to canvas
3049 // cursor position relative to output
3052 canvas_to_output(mwindow->edl,
3057 //printf("CWindowCanvas::test_zoom 1 %f %f\n", x, y);
3059 // Find current zoom in table
3060 int current_index = 0;
3061 for(current_index = 0 ; current_index < total_zooms; current_index++)
3062 if(EQUIV(my_zoom_table[current_index], zoom)) break;
3066 if(get_buttonpress() == 5 ||
3078 CLAMP(current_index, 0, total_zooms - 1);
3079 zoom = my_zoom_table[current_index];
3081 x = output_x - x / zoom;
3082 y = output_y - y / zoom;
3091 // check_boundaries(mwindow->edl, x_i, y_i, zoom);
3093 //printf("CWindowCanvas::test_zoom 2 %d %d\n", x_i, y_i);
3098 reposition_window(mwindow->edl,
3099 mwindow->theme->ccanvas_x,
3100 mwindow->theme->ccanvas_y,
3101 mwindow->theme->ccanvas_w,
3102 mwindow->theme->ccanvas_h);
3107 gui->zoom_panel->update(zoom);
3113 void CWindowCanvas::calculate_origin()
3115 gui->x_origin = get_cursor_x();
3116 gui->y_origin = get_cursor_y();
3117 //printf("CWindowCanvas::calculate_origin 1 %f %f\n", gui->x_origin, gui->y_origin);
3118 canvas_to_output(mwindow->edl, 0, gui->x_origin, gui->y_origin);
3119 //printf("CWindowCanvas::calculate_origin 2 %f %f\n", gui->x_origin, gui->y_origin);
3123 int CWindowCanvas::cursor_leave_event()
3125 set_cursor(ARROW_CURSOR);
3129 int CWindowCanvas::cursor_enter_event()
3132 switch(mwindow->edl->session->cwindow_operation)
3134 case CWINDOW_CAMERA:
3135 case CWINDOW_PROJECTOR:
3136 set_cursor(MOVE_CURSOR);
3139 set_cursor(MOVE_CURSOR);
3142 test_crop(0, redraw);
3144 case CWINDOW_PROTECT:
3145 set_cursor(ARROW_CURSOR);
3149 set_cursor(CROSS_CURSOR);
3151 case CWINDOW_EYEDROP:
3152 set_cursor(CROSS_CURSOR);
3158 int CWindowCanvas::cursor_motion_event()
3160 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3163 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3164 switch(gui->current_operation)
3166 case CWINDOW_SCROLL:
3168 float zoom = get_zoom();
3169 float cursor_x = get_cursor_x();
3170 float cursor_y = get_cursor_y();
3172 float zoom_x, zoom_y, conformed_w, conformed_h;
3173 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3174 cursor_x = (float)cursor_x / zoom_x + gui->x_offset;
3175 cursor_y = (float)cursor_y / zoom_y + gui->y_offset;
3179 int x = (int)(gui->x_origin - cursor_x + gui->x_offset);
3180 int y = (int)(gui->y_origin - cursor_y + gui->y_offset);
3185 update_scrollbars(0);
3192 result = do_ruler(0, 1, 0, 0);
3195 case CWINDOW_CAMERA:
3196 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3199 case CWINDOW_PROJECTOR:
3200 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3205 result = test_crop(0, redraw);
3206 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3213 case CWINDOW_MASK_CONTROL_IN:
3214 case CWINDOW_MASK_CONTROL_OUT:
3215 case CWINDOW_MASK_TRANSLATE:
3217 result = do_mask(redraw,
3224 case CWINDOW_EYEDROP:
3225 result = do_eyedrop(rerender, 0, 0);
3234 // cursor font changes
3237 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3239 // mwindow->edl->session->cwindow_operation);
3240 switch(mwindow->edl->session->cwindow_operation)
3243 result = test_crop(0, redraw);
3246 result = do_ruler(0, 1, 0, 0);
3249 result = do_mask(redraw,
3259 // If the window is never unlocked before calling send_command the
3260 // display shouldn't get stuck on the old video frame although it will
3261 // flicker between the old video frame and the new video frame.
3271 gui->unlock_window();
3274 mwindow->gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3275 mwindow->gui->draw_overlays(1);
3276 mwindow->gui->unlock_window();
3278 gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3283 gui->unlock_window();
3284 mwindow->restart_brender();
3285 mwindow->sync_parameters(CHANGE_PARAMS);
3286 gui->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
3290 if(!redraw) gui->update_tool();
3291 gui->lock_window("CWindowCanvas::cursor_motion_event 2");
3296 int CWindowCanvas::button_press_event()
3300 int redraw_canvas = 0;
3303 if(Canvas::button_press_event()) return 1;
3305 gui->translating_zoom = gui->shift_down();
3308 //printf("CWindowCanvas::button_press_event 2 %f %f\n", gui->x_origin, gui->y_origin, gui->x_origin, gui->y_origin);
3310 float zoom_x, zoom_y, conformed_w, conformed_h;
3311 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3312 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3313 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3316 if(get_buttonpress() == 2)
3318 gui->current_operation = CWINDOW_SCROLL;
3324 switch(mwindow->edl->session->cwindow_operation)
3327 result = do_ruler(0, 0, 1, 0);
3330 case CWINDOW_CAMERA:
3331 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3334 case CWINDOW_PROJECTOR:
3335 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3339 result = test_zoom(redraw);
3343 result = test_crop(1, redraw);
3347 if(get_buttonpress() == 1)
3348 result = do_mask(redraw, rerender, 1, 0, 0);
3351 case CWINDOW_EYEDROP:
3352 result = do_eyedrop(rerender, 1, 0);
3360 gui->unlock_window();
3363 mwindow->gui->lock_window("CWindowCanvas::button_press_event 1");
3364 mwindow->gui->draw_overlays(1);
3365 mwindow->gui->unlock_window();
3368 gui->lock_window("CWindowCanvas::button_press_event 1");
3371 // rerendering can also be caused by press event
3374 gui->unlock_window();
3376 mwindow->restart_brender();
3377 mwindow->sync_parameters(CHANGE_PARAMS);
3378 gui->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
3382 if(!redraw) gui->update_tool();
3383 gui->lock_window("CWindowCanvas::button_press_event 2");
3388 int CWindowCanvas::button_release_event()
3392 switch(gui->current_operation)
3394 case CWINDOW_SCROLL:
3399 do_ruler(0, 0, 0, 1);
3402 case CWINDOW_CAMERA:
3403 mwindow->undo->update_undo_after(_("camera"), LOAD_AUTOMATION);
3406 case CWINDOW_PROJECTOR:
3407 mwindow->undo->update_undo_after(_("projector"), LOAD_AUTOMATION);
3411 case CWINDOW_MASK_CONTROL_IN:
3412 case CWINDOW_MASK_CONTROL_OUT:
3413 case CWINDOW_MASK_TRANSLATE:
3414 // Finish mask operation
3415 gui->mask_keyframe = 0;
3416 mwindow->undo->update_undo_after(_("mask"), LOAD_AUTOMATION);
3421 gui->current_operation = CWINDOW_NONE;
3425 void CWindowCanvas::zoom_resize_window(float percentage)
3427 int canvas_w, canvas_h;
3431 // Get required canvas size
3432 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3433 mwindow->edl->session->output_w,
3434 mwindow->edl->session->output_h,
3439 // Estimate window size from current borders
3440 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3441 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3443 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3444 mwindow->session->cwindow_w = new_w;
3445 mwindow->session->cwindow_h = new_h;
3447 mwindow->theme->get_cwindow_sizes(gui,
3448 mwindow->session->cwindow_controls);
3450 // Estimate again from new borders
3451 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3452 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3453 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3455 gui->resize_window(new_w, new_h);
3456 gui->resize_event(new_w, new_h);
3459 void CWindowCanvas::toggle_controls()
3461 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3462 gui->resize_event(gui->get_w(), gui->get_h());
3465 int CWindowCanvas::get_cwindow_controls()
3467 return mwindow->session->cwindow_controls;