1 #include "automation.h"
10 #include "cwindowgui.h"
12 #include "cwindowtool.h"
13 #include "editpanel.h"
15 #include "edlsession.h"
16 #include "floatauto.h"
17 #include "floatautos.h"
20 #include "localsession.h"
21 #include "mainclock.h"
24 #include "mainsession.h"
26 #include "maskautos.h"
28 #include "meterpanel.h"
29 #include "mwindowgui.h"
32 #include "playback3d.h"
33 #include "playtransport.h"
35 #include "trackcanvas.h"
37 #include "transportque.h"
41 static double my_zoom_table[] =
54 static int total_zooms = sizeof(my_zoom_table) / sizeof(double);
57 CWindowGUI::CWindowGUI(MWindow *mwindow, CWindow *cwindow)
58 : BC_Window(PROGRAM_NAME ": Compositor",
59 mwindow->session->cwindow_x,
60 mwindow->session->cwindow_y,
61 mwindow->session->cwindow_w,
62 mwindow->session->cwindow_h,
68 BC_WindowBase::get_resources()->bg_color,
69 mwindow->edl->session->get_cwindow_display())
71 this->mwindow = mwindow;
72 this->cwindow = cwindow;
77 affected_keyframe = 0;
83 current_operation = CWINDOW_NONE;
91 CWindowGUI::~CWindowGUI()
93 if(tool_panel) delete tool_panel;
95 delete composite_panel;
104 int CWindowGUI::create_objects()
106 set_icon(mwindow->theme->get_image("cwindow_icon"));
108 active = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_active"));
109 inactive = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_inactive"));
111 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
112 mwindow->theme->draw_cwindow_bg(this);
115 // Meters required by composite panel
116 meters = new CWindowMeters(mwindow,
118 mwindow->theme->cmeter_x,
119 mwindow->theme->cmeter_y,
120 mwindow->theme->cmeter_h);
121 meters->create_objects();
124 composite_panel = new CPanel(mwindow,
126 mwindow->theme->ccomposite_x,
127 mwindow->theme->ccomposite_y,
128 mwindow->theme->ccomposite_w,
129 mwindow->theme->ccomposite_h);
130 composite_panel->create_objects();
132 canvas = new CWindowCanvas(mwindow, this);
133 canvas->create_objects(mwindow->edl);
136 add_subwindow(timebar = new CTimeBar(mwindow,
138 mwindow->theme->ctimebar_x,
139 mwindow->theme->ctimebar_y,
140 mwindow->theme->ctimebar_w,
141 mwindow->theme->ctimebar_h));
142 timebar->create_objects();
144 add_subwindow(slider = new CWindowSlider(mwindow,
146 mwindow->theme->cslider_x,
147 mwindow->theme->cslider_y,
148 mwindow->theme->cslider_w));
150 transport = new CWindowTransport(mwindow,
152 mwindow->theme->ctransport_x,
153 mwindow->theme->ctransport_y);
154 transport->create_objects();
155 transport->set_slider(slider);
157 edit_panel = new CWindowEditing(mwindow, cwindow);
158 edit_panel->set_meters(meters);
159 edit_panel->create_objects();
161 // add_subwindow(clock = new MainClock(mwindow,
162 // mwindow->theme->ctime_x,
163 // mwindow->theme->ctime_y));
165 zoom_panel = new CWindowZoom(mwindow,
167 mwindow->theme->czoom_x,
168 mwindow->theme->czoom_y);
169 zoom_panel->create_objects();
170 zoom_panel->zoom_text->add_item(new BC_MenuItem(AUTO_ZOOM));
171 if(!mwindow->edl->session->cwindow_scrollbars) zoom_panel->set_text(AUTO_ZOOM);
173 // destination = new CWindowDestination(mwindow,
175 // mwindow->theme->cdest_x,
176 // mwindow->theme->cdest_y);
177 // destination->create_objects();
179 // Must create after meter panel
180 tool_panel = new CWindowTool(mwindow, this);
181 tool_panel->Thread::start();
183 set_operation(mwindow->edl->session->cwindow_operation);
186 canvas->draw_refresh();
193 int CWindowGUI::translation_event()
195 mwindow->session->cwindow_x = get_x();
196 mwindow->session->cwindow_y = get_y();
200 int CWindowGUI::resize_event(int w, int h)
202 mwindow->session->cwindow_x = get_x();
203 mwindow->session->cwindow_y = get_y();
204 mwindow->session->cwindow_w = w;
205 mwindow->session->cwindow_h = h;
207 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
208 mwindow->theme->draw_cwindow_bg(this);
211 composite_panel->reposition_buttons(mwindow->theme->ccomposite_x,
212 mwindow->theme->ccomposite_y);
214 canvas->reposition_window(mwindow->edl,
215 mwindow->theme->ccanvas_x,
216 mwindow->theme->ccanvas_y,
217 mwindow->theme->ccanvas_w,
218 mwindow->theme->ccanvas_h);
220 timebar->resize_event();
222 slider->reposition_window(mwindow->theme->cslider_x,
223 mwindow->theme->cslider_y,
224 mwindow->theme->cslider_w);
225 // Recalibrate pointer motion range
226 slider->set_position();
228 transport->reposition_buttons(mwindow->theme->ctransport_x,
229 mwindow->theme->ctransport_y);
231 edit_panel->reposition_buttons(mwindow->theme->cedit_x,
232 mwindow->theme->cedit_y);
234 // clock->reposition_window(mwindow->theme->ctime_x,
235 // mwindow->theme->ctime_y);
237 zoom_panel->reposition_window(mwindow->theme->czoom_x,
238 mwindow->theme->czoom_y);
240 // destination->reposition_window(mwindow->theme->cdest_x,
241 // mwindow->theme->cdest_y);
243 meters->reposition_window(mwindow->theme->cmeter_x,
244 mwindow->theme->cmeter_y,
245 mwindow->theme->cmeter_h);
249 BC_WindowBase::resize_event(w, h);
253 int CWindowGUI::button_press_event()
255 if(canvas->get_canvas())
256 return canvas->button_press_event_base(canvas->get_canvas());
260 int CWindowGUI::cursor_leave_event()
262 if(canvas->get_canvas())
263 return canvas->cursor_leave_event_base(canvas->get_canvas());
267 int CWindowGUI::cursor_enter_event()
269 if(canvas->get_canvas())
270 return canvas->cursor_enter_event_base(canvas->get_canvas());
274 int CWindowGUI::button_release_event()
276 if(canvas->get_canvas())
277 return canvas->button_release_event();
281 int CWindowGUI::cursor_motion_event()
283 if(canvas->get_canvas())
285 canvas->get_canvas()->unhide_cursor();
286 return canvas->cursor_motion_event();
297 void CWindowGUI::draw_status()
299 if(canvas->get_canvas() &&
300 canvas->get_canvas()->get_video_on() ||
301 canvas->is_processing)
304 mwindow->theme->cstatus_x,
305 mwindow->theme->cstatus_y);
309 draw_pixmap(inactive,
310 mwindow->theme->cstatus_x,
311 mwindow->theme->cstatus_y);
314 flash(mwindow->theme->cstatus_x,
315 mwindow->theme->cstatus_y,
321 void CWindowGUI::zoom_canvas(int do_auto, double value, int update_menu)
324 mwindow->edl->session->cwindow_scrollbars = 0;
326 mwindow->edl->session->cwindow_scrollbars = 1;
328 float old_zoom = mwindow->edl->session->cwindow_zoom;
329 float new_zoom = value;
330 float x = canvas->w / 2;
331 float y = canvas->h / 2;
332 canvas->canvas_to_output(mwindow->edl,
336 x -= canvas->w_visible / 2 * old_zoom / new_zoom;
337 y -= canvas->h_visible / 2 * old_zoom / new_zoom;
342 zoom_panel->update(AUTO_ZOOM);
346 zoom_panel->update(value);
350 canvas->update_zoom((int)x,
353 canvas->reposition_window(mwindow->edl,
354 mwindow->theme->ccanvas_x,
355 mwindow->theme->ccanvas_y,
356 mwindow->theme->ccanvas_w,
357 mwindow->theme->ccanvas_h);
358 canvas->draw_refresh();
363 // Don't refresh the canvas in a load file operation which is going to
364 // refresh it anyway.
365 void CWindowGUI::set_operation(int value)
367 mwindow->edl->session->cwindow_operation = value;
369 composite_panel->set_operation(value);
370 edit_panel->update();
372 tool_panel->start_tool(value);
373 canvas->draw_refresh();
376 void CWindowGUI::update_tool()
378 tool_panel->update_values();
381 int CWindowGUI::close_event()
383 cwindow->hide_window();
388 int CWindowGUI::keypress_event()
392 switch(get_keypress())
410 if(mwindow->session->cwindow_fullscreen)
411 canvas->stop_fullscreen();
413 canvas->start_fullscreen();
414 lock_window("CWindowGUI::keypress_event 1");
418 if(mwindow->session->cwindow_fullscreen)
419 canvas->stop_fullscreen();
420 lock_window("CWindowGUI::keypress_event 2");
427 int shift_down = this->shift_down();
429 mwindow->gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
431 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
432 mwindow->prev_edit_handle(shift_down);
433 mwindow->gui->unlock_window();
435 lock_window("CWindowGUI::keypress_event 1");
439 mwindow->move_left();
449 int shift_down = this->shift_down();
451 mwindow->gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
453 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
454 mwindow->next_edit_handle(shift_down);
455 mwindow->gui->unlock_window();
457 lock_window("CWindowGUI::keypress_event 2");
460 mwindow->move_right();
466 if(!result) result = transport->keypress_event();
472 void CWindowGUI::reset_affected()
479 void CWindowGUI::keyboard_zoomin()
481 // if(mwindow->edl->session->cwindow_scrollbars)
483 zoom_panel->zoom_tumbler->handle_up_event();
490 void CWindowGUI::keyboard_zoomout()
492 // if(mwindow->edl->session->cwindow_scrollbars)
494 zoom_panel->zoom_tumbler->handle_down_event();
502 void CWindowGUI::drag_motion()
504 if(get_hidden()) return;
506 if(mwindow->session->current_operation == DRAG_ASSET ||
507 mwindow->session->current_operation == DRAG_VTRANSITION ||
508 mwindow->session->current_operation == DRAG_VEFFECT)
510 int old_status = mwindow->session->ccanvas_highlighted;
511 int cursor_x = get_relative_cursor_x();
512 int cursor_y = get_relative_cursor_y();
514 mwindow->session->ccanvas_highlighted = get_cursor_over_window() &&
515 cursor_x >= canvas->x &&
516 cursor_x < canvas->x + canvas->w &&
517 cursor_y >= canvas->y &&
518 cursor_y < canvas->y + canvas->h;
521 if(old_status != mwindow->session->ccanvas_highlighted)
522 canvas->draw_refresh();
526 int CWindowGUI::drag_stop()
529 if(get_hidden()) return 0;
531 if((mwindow->session->current_operation == DRAG_ASSET ||
532 mwindow->session->current_operation == DRAG_VTRANSITION ||
533 mwindow->session->current_operation == DRAG_VEFFECT) &&
534 mwindow->session->ccanvas_highlighted)
537 mwindow->session->ccanvas_highlighted = 0;
538 canvas->draw_refresh();
544 if(mwindow->session->current_operation == DRAG_ASSET)
546 if(mwindow->session->drag_assets->total)
548 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
550 mwindow->load_assets(mwindow->session->drag_assets,
551 mwindow->edl->local_session->get_selectionstart(),
553 mwindow->session->track_highlighted,
555 mwindow->edl->session->labels_follow_edits,
556 mwindow->edl->session->plugins_follow_edits,
560 if(mwindow->session->drag_clips->total)
562 mwindow->gui->lock_window("CWindowGUI::drag_stop 2");
564 mwindow->paste_edls(mwindow->session->drag_clips,
566 mwindow->session->track_highlighted,
567 mwindow->edl->local_session->get_selectionstart(),
568 mwindow->edl->session->labels_follow_edits,
569 mwindow->edl->session->plugins_follow_edits,
573 if(mwindow->session->drag_assets->total ||
574 mwindow->session->drag_clips->total)
576 mwindow->save_backup();
577 mwindow->restart_brender();
578 mwindow->gui->update(1, 1, 1, 1, 0, 1, 0);
579 mwindow->undo->update_undo(_("insert assets"), LOAD_ALL);
580 mwindow->gui->unlock_window();
581 mwindow->sync_parameters(LOAD_ALL);
585 if(mwindow->session->current_operation == DRAG_VEFFECT)
587 //printf("CWindowGUI::drag_stop 1\n");
588 Track *affected_track = cwindow->calculate_affected_track();
589 //printf("CWindowGUI::drag_stop 2\n");
591 mwindow->gui->lock_window("CWindowGUI::drag_stop 3");
592 mwindow->insert_effects_cwindow(affected_track);
593 mwindow->session->current_operation = NO_OPERATION;
594 mwindow->gui->unlock_window();
597 if(mwindow->session->current_operation == DRAG_VTRANSITION)
599 Track *affected_track = cwindow->calculate_affected_track();
600 mwindow->gui->lock_window("CWindowGUI::drag_stop 4");
601 mwindow->paste_transition_cwindow(affected_track);
602 mwindow->session->current_operation = NO_OPERATION;
603 mwindow->gui->unlock_window();
610 CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
613 mwindow->theme->cedit_x,
614 mwindow->theme->cedit_y,
615 mwindow->edl->session->editing_mode,
632 this->mwindow = mwindow;
633 this->cwindow = cwindow;
636 void CWindowEditing::set_inpoint()
638 mwindow->set_inpoint(0);
641 void CWindowEditing::set_outpoint()
643 mwindow->set_outpoint(0);
650 CWindowMeters::CWindowMeters(MWindow *mwindow, CWindowGUI *gui, int x, int y, int h)
651 : MeterPanel(mwindow,
656 mwindow->edl->session->audio_channels,
657 mwindow->edl->session->cwindow_meter)
659 this->mwindow = mwindow;
663 CWindowMeters::~CWindowMeters()
667 int CWindowMeters::change_status_event()
669 mwindow->edl->session->cwindow_meter = use_meters;
670 mwindow->theme->get_cwindow_sizes(gui, mwindow->session->cwindow_controls);
671 gui->resize_event(gui->get_w(), gui->get_h());
678 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y)
681 (double)mwindow->edl->session->cwindow_zoom,
689 this->mwindow = mwindow;
693 CWindowZoom::~CWindowZoom()
697 int CWindowZoom::handle_event()
699 if(!strcasecmp(AUTO_ZOOM, get_text()))
701 gui->zoom_canvas(1, get_value(), 0);
705 gui->zoom_canvas(0, get_value(), 0);
713 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
714 : BC_PercentageSlider(x,
723 this->mwindow = mwindow;
724 this->cwindow = cwindow;
725 set_precision(0.00001);
728 CWindowSlider::~CWindowSlider()
732 int CWindowSlider::handle_event()
735 cwindow->playback_engine->interrupt_playback(1);
736 lock_window("CWindowSlider::handle_event 1");
738 mwindow->gui->lock_window("CWindowSlider::handle_event 2");
739 mwindow->select_point((double)get_value());
740 mwindow->gui->unlock_window();
744 void CWindowSlider::set_position()
746 double new_length = mwindow->edl->tracks->total_playable_length();
747 if(mwindow->edl->local_session->preview_end <= 0 ||
748 mwindow->edl->local_session->preview_end > new_length)
749 mwindow->edl->local_session->preview_end = new_length;
750 if(mwindow->edl->local_session->preview_start >
751 mwindow->edl->local_session->preview_end)
752 mwindow->edl->local_session->preview_start = 0;
756 update(mwindow->theme->cslider_w,
757 mwindow->edl->local_session->get_selectionstart(1),
758 mwindow->edl->local_session->preview_start,
759 mwindow->edl->local_session->preview_end);
763 int CWindowSlider::increase_value()
766 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
767 lock_window("CWindowSlider::increase_value");
771 int CWindowSlider::decrease_value()
774 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
775 lock_window("CWindowSlider::decrease_value");
780 // CWindowDestination::CWindowDestination(MWindow *mwindow, CWindowGUI *cwindow, int x, int y)
781 // : BC_PopupTextBox(cwindow,
782 // &cwindow->destinations,
783 // cwindow->destinations.values[cwindow->cwindow->destination]->get_text(),
789 // this->mwindow = mwindow;
790 // this->cwindow = cwindow;
793 // CWindowDestination::~CWindowDestination()
797 // int CWindowDestination::handle_event()
803 CWindowTransport::CWindowTransport(MWindow *mwindow,
807 : PlayTransport(mwindow,
815 EDL* CWindowTransport::get_edl()
820 void CWindowTransport::goto_start()
822 gui->unlock_window();
823 handle_transport(REWIND, 1);
825 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
826 mwindow->goto_start();
827 mwindow->gui->unlock_window();
829 gui->lock_window("CWindowTransport::goto_start 2");
832 void CWindowTransport::goto_end()
834 gui->unlock_window();
835 handle_transport(GOTO_END, 1);
837 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
839 mwindow->gui->unlock_window();
841 gui->lock_window("CWindowTransport::goto_end 2");
846 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
849 mwindow->theme->ccanvas_x,
850 mwindow->theme->ccanvas_y,
851 mwindow->theme->ccanvas_w,
852 mwindow->theme->ccanvas_h,
855 mwindow->edl->session->cwindow_scrollbars,
858 this->mwindow = mwindow;
862 void CWindowCanvas::status_event()
867 int CWindowCanvas::get_fullscreen()
869 return mwindow->session->cwindow_fullscreen;
872 void CWindowCanvas::set_fullscreen(int value)
874 mwindow->session->cwindow_fullscreen = value;
878 void CWindowCanvas::update_zoom(int x, int y, float zoom)
880 use_scrollbars = mwindow->edl->session->cwindow_scrollbars;
882 mwindow->edl->session->cwindow_xscroll = x;
883 mwindow->edl->session->cwindow_yscroll = y;
884 mwindow->edl->session->cwindow_zoom = zoom;
887 void CWindowCanvas::zoom_auto()
889 gui->zoom_canvas(1, 1.0, 1);
892 int CWindowCanvas::get_xscroll()
894 return mwindow->edl->session->cwindow_xscroll;
897 int CWindowCanvas::get_yscroll()
899 return mwindow->edl->session->cwindow_yscroll;
903 float CWindowCanvas::get_zoom()
905 return mwindow->edl->session->cwindow_zoom;
908 void CWindowCanvas::draw_refresh()
910 if(get_canvas() && !get_canvas()->get_video_on())
915 float in_x1, in_y1, in_x2, in_y2;
916 float out_x1, out_y1, out_x2, out_y2;
917 get_transfers(mwindow->edl,
927 get_canvas()->clear_box(0,
929 get_canvas()->get_w(),
930 get_canvas()->get_h());
932 // printf("CWindowCanvas::draw_refresh %f %f %f %f -> %f %f %f %f\n",
933 // in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
936 if(out_x2 > out_x1 &&
941 // Can't use OpenGL here because it is called asynchronously of the
942 // playback operation.
943 get_canvas()->draw_vframe(refresh_frame,
946 (int)(out_x2 - out_x1),
947 (int)(out_y2 - out_y1),
950 (int)(in_x2 - in_x1),
951 (int)(in_y2 - in_y1),
957 get_canvas()->flash();
959 //printf("CWindowCanvas::draw_refresh 10\n");
962 #define CROPHANDLE_W 10
963 #define CROPHANDLE_H 10
965 void CWindowCanvas::draw_crophandle(int x, int y)
967 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
972 #define FIRST_CONTROL_W 20
973 #define FIRST_CONTROL_H 20
975 #define BC_INFINITY 65536
977 #define SQR(x) ((x) * (x))
980 int CWindowCanvas::do_mask(int &redraw,
986 // Retrieve points from top recordable track
987 //printf("CWindowCanvas::do_mask 1\n");
988 Track *track = gui->cwindow->calculate_affected_track();
989 //printf("CWindowCanvas::do_mask 2\n");
992 //printf("CWindowCanvas::do_mask 3\n");
994 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
995 int64_t position = track->to_units(
996 mwindow->edl->local_session->get_selectionstart(1),
998 ArrayList<MaskPoint*> points;
999 mask_autos->get_points(&points, mwindow->edl->session->cwindow_mask,
1002 //printf("CWindowCanvas::do_mask 4\n");
1004 // Projector zooms relative to the center of the track output.
1005 float half_track_w = (float)track->track_w / 2;
1006 float half_track_h = (float)track->track_h / 2;
1007 // Translate mask to projection
1008 float projector_x, projector_y, projector_z;
1009 track->automation->get_projector(&projector_x,
1016 // Get position of cursor relative to mask
1017 float mask_cursor_x = get_cursor_x();
1018 float mask_cursor_y = get_cursor_y();
1019 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1021 projector_x += mwindow->edl->session->output_w / 2;
1022 projector_y += mwindow->edl->session->output_h / 2;
1024 mask_cursor_x -= projector_x;
1025 mask_cursor_y -= projector_y;
1026 mask_cursor_x = mask_cursor_x / projector_z + half_track_w;
1027 mask_cursor_y = mask_cursor_y / projector_z + half_track_h;
1029 // Fix cursor origin
1032 gui->x_origin = mask_cursor_x;
1033 gui->y_origin = mask_cursor_y;
1037 // Points of closest line
1038 int shortest_point1 = -1;
1039 int shortest_point2 = -1;
1041 int shortest_point = -1;
1042 // Distance to closest line
1043 float shortest_line_distance = BC_INFINITY;
1044 // Distance to closest point
1045 float shortest_point_distance = BC_INFINITY;
1046 int selected_point = -1;
1047 int selected_control_point = -1;
1048 float selected_control_point_distance = BC_INFINITY;
1049 ArrayList<int> x_points;
1050 ArrayList<int> y_points;
1056 get_canvas()->set_color(WHITE);
1057 get_canvas()->set_inverse();
1059 //printf("CWindowCanvas::do_mask 1 %d\n", points.total);
1061 // Never draw closed polygon and a closed
1062 // polygon is harder to add points to.
1063 for(int i = 0; i < points.total && !result; i++)
1065 MaskPoint *point1 = points.values[i];
1066 MaskPoint *point2 = (i >= points.total - 1) ?
1068 points.values[i + 1];
1069 float x0, x1, x2, x3;
1070 float y0, y1, y2, y3;
1071 float old_x, old_y, x, y;
1072 int segments = (int)(sqrt(SQR(point1->x - point2->x) + SQR(point1->y - point2->y)));
1074 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1075 //point1->x, point1->y, point2->x, point2->y, projector_z);
1076 for(int j = 0; j <= segments && !result; j++)
1078 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1081 x1 = point1->x + point1->control_x2;
1082 y1 = point1->y + point1->control_y2;
1083 x2 = point2->x + point2->control_x1;
1084 y2 = point2->y + point2->control_y1;
1088 float t = (float)j / segments;
1089 float tpow2 = t * t;
1090 float tpow3 = t * t * t;
1092 float invtpow2 = invt * invt;
1093 float invtpow3 = invt * invt * invt;
1096 + 3 * t * invtpow2 * x1
1097 + 3 * tpow2 * invt * x2
1100 + 3 * t * invtpow2 * y1
1101 + 3 * tpow2 * invt * y2
1104 x = (x - half_track_w) * projector_z + projector_x;
1105 y = (y - half_track_h) * projector_z + projector_y;
1108 // Test new point addition
1111 float line_distance =
1112 sqrt(SQR(x - mask_cursor_x) + SQR(y - mask_cursor_y));
1114 //printf("CWindowCanvas::do_mask 1 x=%f mask_cursor_x=%f y=%f mask_cursor_y=%f %f %f %d, %d\n",
1115 //x, mask_cursor_x, y, mask_cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1116 if(line_distance < shortest_line_distance ||
1117 shortest_point1 < 0)
1119 shortest_line_distance = line_distance;
1120 shortest_point1 = i;
1121 shortest_point2 = (i >= points.total - 1) ? 0 : (i + 1);
1122 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n", line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1126 float point_distance1 =
1127 sqrt(SQR(point1->x - mask_cursor_x) + SQR(point1->y - mask_cursor_y));
1128 float point_distance2 =
1129 sqrt(SQR(point2->x - mask_cursor_x) + SQR(point2->y - mask_cursor_y));
1131 if(point_distance1 < shortest_point_distance ||
1134 shortest_point_distance = point_distance1;
1138 if(point_distance2 < shortest_point_distance ||
1141 shortest_point_distance = point_distance2;
1142 shortest_point = (i >= points.total - 1) ? 0 : (i + 1);
1146 output_to_canvas(mwindow->edl, 0, x, y);
1149 #define TEST_BOX(cursor_x, cursor_y, target_x, target_y) \
1150 (cursor_x >= target_x - CONTROL_W / 2 && \
1151 cursor_x < target_x + CONTROL_W / 2 && \
1152 cursor_y >= target_y - CONTROL_H / 2 && \
1153 cursor_y < target_y + CONTROL_H / 2)
1155 // Test existing point selection
1158 float canvas_x = (x0 - half_track_w) * projector_z + projector_x;
1159 float canvas_y = (y0 - half_track_h) * projector_z + projector_y;
1160 int cursor_x = get_cursor_x();
1161 int cursor_y = get_cursor_y();
1164 if(gui->shift_down())
1166 float control_x = (x1 - half_track_w) * projector_z + projector_x;
1167 float control_y = (y1 - half_track_h) * projector_z + projector_y;
1168 output_to_canvas(mwindow->edl, 0, control_x, control_y);
1171 sqrt(SQR(control_x - cursor_x) + SQR(control_y - cursor_y));
1173 if(distance < selected_control_point_distance)
1176 selected_control_point = 1;
1177 selected_control_point_distance = distance;
1182 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1183 if(!gui->ctrl_down())
1185 if(TEST_BOX(cursor_x, cursor_y, canvas_x, canvas_y))
1192 selected_point = shortest_point;
1196 // Test second point
1197 canvas_x = (x3 - half_track_w) * projector_z + projector_x;
1198 canvas_y = (y3 - half_track_h) * projector_z + projector_y;
1199 if(gui->shift_down())
1201 float control_x = (x2 - half_track_w) * projector_z + projector_x;
1202 float control_y = (y2 - half_track_h) * projector_z + projector_y;
1203 output_to_canvas(mwindow->edl, 0, control_x, control_y);
1206 sqrt(SQR(control_x - cursor_x) + SQR(control_y - cursor_y));
1208 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1209 if(distance < selected_control_point_distance)
1211 selected_point = (i < points.total - 1 ? i + 1 : 0);
1212 selected_control_point = 0;
1213 selected_control_point_distance = distance;
1217 if(i < points.total - 1)
1219 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1220 if(!gui->ctrl_down())
1222 if(TEST_BOX(cursor_x, cursor_y, canvas_x, canvas_y))
1224 selected_point = (i < points.total - 1 ? i + 1 : 0);
1229 selected_point = shortest_point;
1238 // Draw joining line
1241 x_points.append((int)x);
1242 y_points.append((int)y);
1253 // Draw second anchor
1254 if(i < points.total - 1)
1256 if(i == gui->affected_point - 1)
1257 get_canvas()->draw_disc((int)x - CONTROL_W / 2,
1258 (int)y - CONTROL_W / 2,
1262 get_canvas()->draw_circle((int)x - CONTROL_W / 2,
1263 (int)y - CONTROL_W / 2,
1266 // char string[BCTEXTLEN];
1267 // sprintf(string, "%d", (i < points.total - 1 ? i + 1 : 0));
1268 // canvas->draw_text((int)x + CONTROL_W, (int)y + CONTROL_W, string);
1271 // Draw second control point. Discard x2 and y2 after this.
1272 x2 = (x2 - half_track_w) * projector_z + projector_x;
1273 y2 = (y2 - half_track_h) * projector_z + projector_y;
1274 output_to_canvas(mwindow->edl, 0, x2, y2);
1275 get_canvas()->draw_line((int)x, (int)y, (int)x2, (int)y2);
1276 get_canvas()->draw_rectangle((int)x2 - CONTROL_W / 2,
1277 (int)y2 - CONTROL_H / 2,
1287 // Draw first anchor
1290 get_canvas()->draw_disc((int)x - FIRST_CONTROL_W / 2,
1291 (int)y - FIRST_CONTROL_H / 2,
1296 // Draw first control point. Discard x1 and y1 after this.
1299 x1 = (x1 - half_track_w) * projector_z + projector_x;
1300 y1 = (y1 - half_track_h) * projector_z + projector_y;
1301 output_to_canvas(mwindow->edl, 0, x1, y1);
1302 get_canvas()->draw_line((int)x, (int)y, (int)x1, (int)y1);
1303 get_canvas()->draw_rectangle((int)x1 - CONTROL_W / 2,
1304 (int)y1 - CONTROL_H / 2,
1308 x_points.append((int)x);
1309 y_points.append((int)y);
1312 //printf("CWindowCanvas::do_mask 1\n");
1318 //printf("CWindowCanvas::do_mask 1\n");
1322 get_canvas()->draw_polygon(&x_points, &y_points);
1323 get_canvas()->set_opaque();
1325 //printf("CWindowCanvas::do_mask 1\n");
1334 if(button_press && !result)
1336 gui->affected_track = gui->cwindow->calculate_affected_track();
1337 // Get current keyframe
1338 if(gui->affected_track)
1339 gui->affected_keyframe =
1340 gui->cwindow->calculate_affected_auto(
1341 gui->affected_track->automation->autos[AUTOMATION_MASK],
1344 MaskAuto *keyframe = (MaskAuto*)gui->affected_keyframe;
1345 SubMask *mask = keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1348 // Translate entire keyframe
1349 if(gui->alt_down() && mask->points.total)
1351 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1352 gui->affected_point = 0;
1355 // Existing point or control point was selected
1356 if(selected_point >= 0)
1358 gui->affected_point = selected_point;
1360 if(selected_control_point == 0)
1361 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1363 if(selected_control_point == 1)
1364 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1366 gui->current_operation = mwindow->edl->session->cwindow_operation;
1369 // No existing point or control point was selected so create a new one
1370 if(!gui->shift_down() && !gui->alt_down())
1372 // Create the template
1373 MaskPoint *point = new MaskPoint;
1374 point->x = mask_cursor_x;
1375 point->y = mask_cursor_y;
1376 point->control_x1 = 0;
1377 point->control_y1 = 0;
1378 point->control_x2 = 0;
1379 point->control_y2 = 0;
1382 if(shortest_point2 < shortest_point1)
1384 shortest_point2 ^= shortest_point1;
1385 shortest_point1 ^= shortest_point2;
1386 shortest_point2 ^= shortest_point1;
1391 // printf("CWindowGUI::do_mask 40\n");
1392 // mwindow->edl->dump();
1393 // printf("CWindowGUI::do_mask 50\n");
1397 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1398 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1399 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1401 // Append to end of list
1402 if(labs(shortest_point1 - shortest_point2) > 1)
1404 // Need to apply the new point to every keyframe
1405 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto;
1408 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1409 MaskPoint *new_point = new MaskPoint;
1410 submask->points.append(new_point);
1411 *new_point = *point;
1412 if(current == (MaskAuto*)mask_autos->default_auto)
1413 current = (MaskAuto*)mask_autos->first;
1415 current = (MaskAuto*)NEXT;
1418 gui->affected_point = mask->points.total - 1;
1422 // Insert between 2 points, shifting back point 2
1423 if(shortest_point1 >= 0 && shortest_point2 >= 0)
1425 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto;
1428 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1429 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1431 if(submask->points.total >= shortest_point2)
1433 MaskPoint *new_point = new MaskPoint;
1434 submask->points.append(0);
1435 for(int i = submask->points.total - 1;
1436 i > shortest_point2;
1438 submask->points.values[i] = submask->points.values[i - 1];
1439 submask->points.values[shortest_point2] = new_point;
1441 *new_point = *point;
1444 if(current == (MaskAuto*)mask_autos->default_auto)
1445 current = (MaskAuto*)mask_autos->first;
1447 current = (MaskAuto*)NEXT;
1451 gui->affected_point = shortest_point2;
1456 // printf("CWindowGUI::do_mask 20\n");
1457 // mwindow->edl->dump();
1458 // printf("CWindowGUI::do_mask 30\n");
1463 // Create the first point.
1466 //printf("CWindowCanvas::do_mask 1\n");
1467 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto;
1470 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1471 MaskPoint *new_point = new MaskPoint;
1472 submask->points.append(new_point);
1473 *new_point = *point;
1474 if(current == (MaskAuto*)mask_autos->default_auto)
1475 current = (MaskAuto*)mask_autos->first;
1477 current = (MaskAuto*)NEXT;
1480 //printf("CWindowCanvas::do_mask 2\n");
1481 // Create a second point if none existed before
1482 if(mask->points.total < 2)
1484 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto;
1487 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1488 MaskPoint *new_point = new MaskPoint;
1489 submask->points.append(new_point);
1490 *new_point = *point;
1491 if(current == (MaskAuto*)mask_autos->default_auto)
1492 current = (MaskAuto*)mask_autos->first;
1494 current = (MaskAuto*)NEXT;
1497 gui->affected_point = mask->points.total - 1;
1498 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.total);
1503 gui->current_operation = mwindow->edl->session->cwindow_operation;
1504 // Delete the template
1506 //printf("CWindowGUI::do_mask 1\n");
1507 mwindow->undo->update_undo(_("mask point"), LOAD_AUTOMATION);
1508 //printf("CWindowGUI::do_mask 10\n");
1517 if(button_press && result)
1519 MaskAuto *keyframe = (MaskAuto*)gui->affected_keyframe;
1520 SubMask *mask = keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1521 MaskPoint *point = mask->points.values[gui->affected_point];
1522 gui->center_x = point->x;
1523 gui->center_y = point->y;
1524 gui->control_in_x = point->control_x1;
1525 gui->control_in_y = point->control_y1;
1526 gui->control_out_x = point->control_x2;
1527 gui->control_out_y = point->control_y2;
1530 //printf("CWindowCanvas::do_mask 8\n");
1533 MaskAuto *keyframe = (MaskAuto*)gui->affected_keyframe;
1534 SubMask *mask = keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1535 if(gui->affected_point < mask->points.total)
1537 MaskPoint *point = mask->points.values[gui->affected_point];
1538 // float cursor_x = get_cursor_x();
1539 // float cursor_y = get_cursor_y();
1540 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
1541 float cursor_x = mask_cursor_x;
1542 float cursor_y = mask_cursor_y;
1543 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask->points.total, gui->affected_point);
1545 float last_x = point->x;
1546 float last_y = point->y;
1547 float last_control_x1 = point->control_x1;
1548 float last_control_y1 = point->control_y1;
1549 float last_control_x2 = point->control_x2;
1550 float last_control_y2 = point->control_y2;
1553 switch(gui->current_operation)
1556 point->x = cursor_x - gui->x_origin + gui->center_x;
1557 point->y = cursor_y - gui->y_origin + gui->center_y;
1560 case CWINDOW_MASK_CONTROL_IN:
1561 point->control_x1 = cursor_x - gui->x_origin + gui->control_in_x;
1562 point->control_y1 = cursor_y - gui->y_origin + gui->control_in_y;
1565 case CWINDOW_MASK_CONTROL_OUT:
1566 point->control_x2 = cursor_x - gui->x_origin + gui->control_out_x;
1567 point->control_y2 = cursor_y - gui->y_origin + gui->control_out_y;
1570 case CWINDOW_MASK_TRANSLATE:
1571 for(int i = 0; i < mask->points.total; i++)
1573 mask->points.values[i]->x += cursor_x - gui->x_origin;
1574 mask->points.values[i]->y += cursor_y - gui->y_origin;
1576 gui->x_origin = cursor_x;
1577 gui->y_origin = cursor_y;
1582 if( !EQUIV(last_x, point->x) ||
1583 !EQUIV(last_y, point->y) ||
1584 !EQUIV(last_control_x1, point->control_x1) ||
1585 !EQUIV(last_control_y1, point->control_y1) ||
1586 !EQUIV(last_control_x2, point->control_x2) ||
1587 !EQUIV(last_control_y2, point->control_y2))
1595 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
1597 points.remove_all_objects();
1598 //printf("CWindowCanvas::do_mask 20\n");
1603 int CWindowCanvas::do_eyedrop(int &rerender, int button_press)
1606 float cursor_x = get_cursor_x();
1607 float cursor_y = get_cursor_y();
1612 gui->current_operation = CWINDOW_EYEDROP;
1615 if(gui->current_operation == CWINDOW_EYEDROP)
1617 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
1619 // Get color out of frame.
1620 // Doesn't work during playback because that bypasses the refresh frame.
1623 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
1624 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
1626 // Decompression coefficients straight out of jpeglib
1627 #define V_TO_R 1.40200
1628 #define V_TO_G -0.71414
1630 #define U_TO_G -0.34414
1631 #define U_TO_B 1.77200
1633 #define GET_COLOR(type, components, max, do_yuv) \
1635 type *row = (type*)(refresh_frame->get_rows()[(int)cursor_y]) + \
1636 (int)cursor_x * components; \
1637 float red = (float)*row++ / max; \
1638 float green = (float)*row++ / max; \
1639 float blue = (float)*row++ / max; \
1642 mwindow->edl->local_session->red = red + V_TO_R * (blue - 0.5); \
1643 mwindow->edl->local_session->green = red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
1644 mwindow->edl->local_session->blue = red + U_TO_B * (green - 0.5); \
1648 mwindow->edl->local_session->red = red; \
1649 mwindow->edl->local_session->green = green; \
1650 mwindow->edl->local_session->blue = blue; \
1654 switch(refresh_frame->get_color_model())
1657 GET_COLOR(unsigned char, 3, 0xff, 1);
1660 GET_COLOR(unsigned char, 4, 0xff, 1);
1663 GET_COLOR(uint16_t, 3, 0xffff, 1);
1665 case BC_YUVA16161616:
1666 GET_COLOR(uint16_t, 4, 0xffff, 1);
1669 GET_COLOR(unsigned char, 3, 0xff, 0);
1672 GET_COLOR(unsigned char, 4, 0xff, 0);
1675 GET_COLOR(float, 3, 1.0, 0);
1678 GET_COLOR(float, 4, 1.0, 0);
1684 mwindow->edl->local_session->red = 0;
1685 mwindow->edl->local_session->green = 0;
1686 mwindow->edl->local_session->blue = 0;
1695 // Can't rerender since the color value is from the output of any effect it
1703 void CWindowCanvas::draw_overlays()
1705 if(mwindow->edl->session->safe_regions)
1707 draw_safe_regions();
1710 if(mwindow->edl->session->cwindow_scrollbars)
1712 // Always draw output rectangle
1713 float x1, y1, x2, y2;
1715 x2 = mwindow->edl->session->output_w;
1717 y2 = mwindow->edl->session->output_h;
1718 output_to_canvas(mwindow->edl, 0, x1, y1);
1719 output_to_canvas(mwindow->edl, 0, x2, y2);
1721 get_canvas()->set_inverse();
1722 get_canvas()->set_color(WHITE);
1724 get_canvas()->draw_rectangle((int)x1,
1729 get_canvas()->set_opaque();
1732 if(mwindow->session->ccanvas_highlighted)
1734 get_canvas()->set_color(WHITE);
1735 get_canvas()->set_inverse();
1736 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
1737 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
1738 get_canvas()->set_opaque();
1741 int temp1 = 0, temp2 = 0;
1742 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
1743 switch(mwindow->edl->session->cwindow_operation)
1745 case CWINDOW_CAMERA:
1749 case CWINDOW_PROJECTOR:
1758 do_mask(temp1, temp2, 0, 0, 1);
1763 void CWindowCanvas::draw_safe_regions()
1765 float action_x1, action_x2, action_y1, action_y2;
1766 float title_x1, title_x2, title_y1, title_y2;
1768 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
1769 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
1770 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
1771 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
1772 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
1773 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
1774 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
1775 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
1777 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
1778 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
1779 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
1780 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
1782 get_canvas()->set_inverse();
1783 get_canvas()->set_color(WHITE);
1785 get_canvas()->draw_rectangle((int)action_x1,
1787 (int)(action_x2 - action_x1),
1788 (int)(action_y2 - action_y1));
1789 get_canvas()->draw_rectangle((int)title_x1,
1791 (int)(title_x2 - title_x1),
1792 (int)(title_y2 - title_y1));
1794 get_canvas()->set_opaque();
1797 void CWindowCanvas::reset_keyframe(int do_camera)
1799 FloatAuto *x_keyframe = 0;
1800 FloatAuto *y_keyframe = 0;
1801 FloatAuto *z_keyframe = 0;
1802 Track *affected_track = 0;
1804 affected_track = gui->cwindow->calculate_affected_track();
1808 gui->cwindow->calculate_affected_autos(&x_keyframe,
1817 x_keyframe->value = 0;
1818 y_keyframe->value = 0;
1819 z_keyframe->value = 1;
1821 mwindow->sync_parameters(CHANGE_PARAMS);
1826 void CWindowCanvas::reset_camera()
1831 void CWindowCanvas::reset_projector()
1836 int CWindowCanvas::test_crop(int button_press, int &redraw)
1839 int handle_selected = -1;
1840 float x1 = mwindow->edl->session->crop_x1;
1841 float y1 = mwindow->edl->session->crop_y1;
1842 float x2 = mwindow->edl->session->crop_x2;
1843 float y2 = mwindow->edl->session->crop_y2;
1844 float cursor_x = get_cursor_x();
1845 float cursor_y = get_cursor_y();
1846 float canvas_x1 = x1;
1847 float canvas_y1 = y1;
1848 float canvas_x2 = x2;
1849 float canvas_y2 = y2;
1850 float canvas_cursor_x = cursor_x;
1851 float canvas_cursor_y = cursor_y;
1853 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
1854 // Use screen normalized coordinates for hot spot tests.
1855 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1856 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1859 if(gui->current_operation == CWINDOW_CROP)
1861 handle_selected = gui->crop_handle;
1864 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
1865 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
1867 handle_selected = 0;
1868 gui->crop_origin_x = x1;
1869 gui->crop_origin_y = y1;
1872 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
1873 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
1875 handle_selected = 1;
1876 gui->crop_origin_x = x2;
1877 gui->crop_origin_y = y1;
1880 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
1881 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
1883 handle_selected = 2;
1884 gui->crop_origin_x = x1;
1885 gui->crop_origin_y = y2;
1888 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
1889 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
1891 handle_selected = 3;
1892 gui->crop_origin_x = x2;
1893 gui->crop_origin_y = y2;
1898 gui->crop_origin_x = cursor_x;
1899 gui->crop_origin_y = cursor_y;
1902 // printf("test crop %d %d\n",
1903 // gui->current_operation,
1904 // handle_selected);
1911 gui->crop_translate = 1;
1912 gui->crop_origin_x1 = x1;
1913 gui->crop_origin_y1 = y1;
1914 gui->crop_origin_x2 = x2;
1915 gui->crop_origin_y2 = y2;
1918 gui->crop_translate = 0;
1920 gui->current_operation = CWINDOW_CROP;
1921 gui->crop_handle = handle_selected;
1922 gui->x_origin = cursor_x;
1923 gui->y_origin = cursor_y;
1926 if(handle_selected < 0 && !gui->crop_translate)
1930 mwindow->edl->session->crop_x1 = (int)x1;
1931 mwindow->edl->session->crop_y1 = (int)y1;
1932 mwindow->edl->session->crop_x2 = (int)x2;
1933 mwindow->edl->session->crop_y2 = (int)y2;
1938 // Translate all 4 points
1939 if(gui->current_operation == CWINDOW_CROP && gui->crop_translate)
1941 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
1942 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
1943 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
1944 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
1946 mwindow->edl->session->crop_x1 = (int)x1;
1947 mwindow->edl->session->crop_y1 = (int)y1;
1948 mwindow->edl->session->crop_x2 = (int)x2;
1949 mwindow->edl->session->crop_y2 = (int)y2;
1955 if(gui->current_operation == CWINDOW_CROP)
1957 switch(gui->crop_handle)
1960 x1 = gui->crop_origin_x;
1961 y1 = gui->crop_origin_y;
1962 x2 = gui->crop_origin_x;
1963 y2 = gui->crop_origin_y;
1964 if(cursor_x < gui->x_origin)
1966 if(cursor_y < gui->y_origin)
1972 if(cursor_y >= gui->y_origin)
1979 if(cursor_x >= gui->x_origin)
1981 if(cursor_y < gui->y_origin)
1987 if(cursor_y >= gui->y_origin)
1994 // printf("test crop %d %d %d %d\n",
1995 // mwindow->edl->session->crop_x1,
1996 // mwindow->edl->session->crop_y1,
1997 // mwindow->edl->session->crop_x2,
1998 // mwindow->edl->session->crop_y2);
2001 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2002 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2005 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2006 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2009 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2010 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2013 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2014 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2018 if(!EQUIV(mwindow->edl->session->crop_x1, x1) ||
2019 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2020 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2021 !EQUIV(mwindow->edl->session->crop_y2, y2))
2028 switch (gui->crop_handle)
2030 case 0: gui->crop_handle = 1; break;
2031 case 1: gui->crop_handle = 0; break;
2032 case 2: gui->crop_handle = 3; break;
2033 case 3: gui->crop_handle = 2; break;
2043 switch (gui->crop_handle)
2045 case 0: gui->crop_handle = 2; break;
2046 case 1: gui->crop_handle = 3; break;
2047 case 2: gui->crop_handle = 0; break;
2048 case 3: gui->crop_handle = 1; break;
2053 mwindow->edl->session->crop_x1 = (int)x1;
2054 mwindow->edl->session->crop_y1 = (int)y1;
2055 mwindow->edl->session->crop_x2 = (int)x2;
2056 mwindow->edl->session->crop_y2 = (int)y2;
2062 // Update cursor font
2063 if(handle_selected >= 0)
2065 switch(handle_selected)
2068 set_cursor(UPLEFT_RESIZE);
2071 set_cursor(UPRIGHT_RESIZE);
2074 set_cursor(DOWNLEFT_RESIZE);
2077 set_cursor(DOWNRIGHT_RESIZE);
2084 set_cursor(ARROW_CURSOR);
2086 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2090 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2091 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2092 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2093 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2094 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2095 // mwindow->edl->session->crop_x2,
2096 // mwindow->edl->session->crop_y2,
2097 // mwindow->edl->calculate_output_w(0),
2098 // mwindow->edl->calculate_output_h(0));
2104 void CWindowCanvas::draw_crop()
2106 get_canvas()->set_inverse();
2107 get_canvas()->set_color(WHITE);
2109 float x1 = mwindow->edl->session->crop_x1;
2110 float y1 = mwindow->edl->session->crop_y1;
2111 float x2 = mwindow->edl->session->crop_x2;
2112 float y2 = mwindow->edl->session->crop_y2;
2114 output_to_canvas(mwindow->edl, 0, x1, y1);
2115 output_to_canvas(mwindow->edl, 0, x2, y2);
2117 if(x2 - x1 && y2 - y1)
2118 get_canvas()->draw_rectangle((int)x1,
2123 draw_crophandle((int)x1, (int)y1);
2124 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2125 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2126 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2127 get_canvas()->set_opaque();
2137 void CWindowCanvas::draw_bezier(int do_camera)
2139 Track *track = gui->cwindow->calculate_affected_track();
2146 int64_t position = track->to_units(
2147 mwindow->edl->local_session->get_selectionstart(1),
2150 track->automation->get_projector(¢er_x,
2156 // center_x += track->track_w / 2;
2157 // center_y += track->track_h / 2;
2158 center_x += mwindow->edl->session->output_w / 2;
2159 center_y += mwindow->edl->session->output_h / 2;
2160 float track_x1 = center_x - track->track_w / 2 * center_z;
2161 float track_y1 = center_y - track->track_h / 2 * center_z;
2162 float track_x2 = track_x1 + track->track_w * center_z;
2163 float track_y2 = track_y1 + track->track_h * center_z;
2165 output_to_canvas(mwindow->edl, 0, track_x1, track_y1);
2166 output_to_canvas(mwindow->edl, 0, track_x2, track_y2);
2168 #define DRAW_PROJECTION(offset) \
2169 get_canvas()->draw_rectangle((int)track_x1 + offset, \
2170 (int)track_y1 + offset, \
2171 (int)(track_x2 - track_x1), \
2172 (int)(track_y2 - track_y1)); \
2173 get_canvas()->draw_line((int)track_x1 + offset, \
2174 (int)track_y1 + offset, \
2175 (int)track_x2 + offset, \
2176 (int)track_y2 + offset); \
2177 get_canvas()->draw_line((int)track_x2 + offset, \
2178 (int)track_y1 + offset, \
2179 (int)track_x1 + offset, \
2180 (int)track_y2 + offset); \
2184 get_canvas()->set_color(BLACK);
2187 // canvas->set_inverse();
2189 get_canvas()->set_color(GREEN);
2191 get_canvas()->set_color(RED);
2194 // canvas->set_opaque();
2200 int CWindowCanvas::test_bezier(int button_press,
2208 // Processing drag operation.
2209 // Create keyframe during first cursor motion.
2213 float cursor_x = get_cursor_x();
2214 float cursor_y = get_cursor_y();
2215 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2217 if(gui->current_operation == CWINDOW_CAMERA ||
2218 gui->current_operation == CWINDOW_PROJECTOR)
2220 if(!gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom)
2222 gui->translating_zoom = 1;
2223 gui->reset_affected();
2226 if(!gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom)
2228 gui->translating_zoom = 0;
2229 gui->reset_affected();
2232 // Get target keyframe
2233 float last_center_x;
2234 float last_center_y;
2235 float last_center_z;
2238 if(!gui->affected_x && !gui->affected_y && !gui->affected_z)
2240 FloatAutos *affected_x_autos;
2241 FloatAutos *affected_y_autos;
2242 FloatAutos *affected_z_autos;
2243 if(!gui->affected_track) return 0;
2244 double position = mwindow->edl->local_session->get_selectionstart(1);
2245 int64_t track_position = gui->affected_track->to_units(position, 0);
2247 if(mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA)
2249 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_X];
2250 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Y];
2251 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Z];
2255 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_X];
2256 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Y];
2257 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Z];
2261 if(gui->translating_zoom)
2263 FloatAuto *previous = 0;
2264 FloatAuto *next = 0;
2265 float new_z = affected_z_autos->get_value(
2271 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2272 affected_z_autos, 1, &created, 0);
2275 gui->affected_z->value = new_z;
2276 gui->affected_z->control_in_value = 0;
2277 gui->affected_z->control_out_value = 0;
2278 gui->affected_z->control_in_position = 0;
2279 gui->affected_z->control_out_position = 0;
2285 FloatAuto *previous = 0;
2286 FloatAuto *next = 0;
2287 float new_x = affected_x_autos->get_value(
2294 float new_y = affected_y_autos->get_value(
2300 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2301 affected_x_autos, 1, &created, 0);
2304 gui->affected_x->value = new_x;
2305 gui->affected_x->control_in_value = 0;
2306 gui->affected_x->control_out_value = 0;
2307 gui->affected_x->control_in_position = 0;
2308 gui->affected_x->control_out_position = 0;
2312 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2313 affected_y_autos, 1, &created, 0);
2316 gui->affected_y->value = new_y;
2317 gui->affected_y->control_in_value = 0;
2318 gui->affected_y->control_out_value = 0;
2319 gui->affected_y->control_in_position = 0;
2320 gui->affected_y->control_out_position = 0;
2327 if(gui->translating_zoom)
2329 gui->center_z = gui->affected_z->value;
2333 gui->center_x = gui->affected_x->value;
2334 gui->center_y = gui->affected_y->value;
2342 if(gui->translating_zoom)
2344 last_center_z = gui->affected_z->value;
2348 last_center_x = gui->affected_x->value;
2349 last_center_y = gui->affected_y->value;
2352 if(gui->translating_zoom)
2354 gui->affected_z->value = gui->center_z +
2355 (cursor_y - gui->y_origin) / 128;
2357 if(gui->affected_z->value < 0) gui->affected_z->value = 0;
2358 if(!EQUIV(last_center_z, gui->affected_z->value))
2367 gui->affected_x->value = gui->center_x + cursor_x - gui->x_origin;
2368 gui->affected_y->value = gui->center_y + cursor_y - gui->y_origin;
2369 if(!EQUIV(last_center_x, gui->affected_x->value) ||
2370 !EQUIV(last_center_y, gui->affected_y->value))
2382 // Begin drag operation. Don't create keyframe here.
2384 // Get affected track off of the first recordable video track.
2385 // Calculating based on the alpha channel would require recording what layer
2386 // each output pixel belongs to as they're rendered and stacked. Forget it.
2387 gui->affected_track = gui->cwindow->calculate_affected_track();
2388 gui->reset_affected();
2390 if(gui->affected_track)
2392 gui->current_operation =
2393 mwindow->edl->session->cwindow_operation;
2401 int CWindowCanvas::test_zoom(int &redraw)
2404 float zoom = get_zoom();
2408 if(!mwindow->edl->session->cwindow_scrollbars)
2410 mwindow->edl->session->cwindow_scrollbars = 1;
2412 x = mwindow->edl->session->output_w / 2;
2413 y = mwindow->edl->session->output_h / 2;
2419 canvas_to_output(mwindow->edl,
2424 //printf("CWindowCanvas::test_zoom 1 %f %f\n", x, y);
2426 // Find current zoom in table
2427 int current_index = 0;
2428 for(current_index = 0 ; current_index < total_zooms; current_index++)
2429 if(EQUIV(my_zoom_table[current_index], zoom)) break;
2433 if(get_buttonpress() == 5 ||
2444 CLAMP(current_index, 0, total_zooms - 1);
2445 zoom = my_zoom_table[current_index];
2448 x = x - w / zoom / 2;
2449 y = y - h / zoom / 2;
2454 // check_boundaries(mwindow->edl, x_i, y_i, zoom);
2456 //printf("CWindowCanvas::test_zoom 2 %d %d\n", x_i, y_i);
2461 reposition_window(mwindow->edl,
2462 mwindow->theme->ccanvas_x,
2463 mwindow->theme->ccanvas_y,
2464 mwindow->theme->ccanvas_w,
2465 mwindow->theme->ccanvas_h);
2470 gui->zoom_panel->update(zoom);
2476 void CWindowCanvas::calculate_origin()
2478 gui->x_origin = get_cursor_x();
2479 gui->y_origin = get_cursor_y();
2480 //printf("CWindowCanvas::calculate_origin 1 %f %f\n", gui->x_origin, gui->y_origin);
2481 canvas_to_output(mwindow->edl, 0, gui->x_origin, gui->y_origin);
2482 //printf("CWindowCanvas::calculate_origin 2 %f %f\n", gui->x_origin, gui->y_origin);
2486 int CWindowCanvas::cursor_leave_event()
2488 set_cursor(ARROW_CURSOR);
2492 int CWindowCanvas::cursor_enter_event()
2495 switch(mwindow->edl->session->cwindow_operation)
2497 case CWINDOW_CAMERA:
2498 case CWINDOW_PROJECTOR:
2499 set_cursor(MOVE_CURSOR);
2502 set_cursor(MOVE_CURSOR);
2505 test_crop(0, redraw);
2507 case CWINDOW_PROTECT:
2508 set_cursor(ARROW_CURSOR);
2511 set_cursor(CROSS_CURSOR);
2513 case CWINDOW_EYEDROP:
2514 set_cursor(CROSS_CURSOR);
2520 int CWindowCanvas::cursor_motion_event()
2522 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
2525 switch(gui->current_operation)
2527 case CWINDOW_SCROLL:
2529 float zoom = get_zoom();
2530 float cursor_x = get_cursor_x();
2531 float cursor_y = get_cursor_y();
2533 float zoom_x, zoom_y, conformed_w, conformed_h;
2534 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
2535 cursor_x = (float)cursor_x / zoom_x + gui->x_offset;
2536 cursor_y = (float)cursor_y / zoom_y + gui->y_offset;
2540 int x = (int)(gui->x_origin - cursor_x + gui->x_offset);
2541 int y = (int)(gui->y_origin - cursor_y + gui->y_offset);
2546 update_scrollbars();
2552 case CWINDOW_CAMERA:
2553 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
2556 case CWINDOW_PROJECTOR:
2557 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
2562 //printf("CWindowCanvas::cursor_motion_event 1 %d %d\n", x, y);
2563 result = test_crop(0, redraw);
2567 case CWINDOW_MASK_CONTROL_IN:
2568 case CWINDOW_MASK_CONTROL_OUT:
2569 case CWINDOW_MASK_TRANSLATE:
2570 result = do_mask(redraw,
2577 case CWINDOW_EYEDROP:
2578 result = do_eyedrop(rerender, 0);
2587 switch(mwindow->edl->session->cwindow_operation)
2590 result = test_crop(0, redraw);
2596 // If the window is never unlocked before calling send_command the
2597 // display shouldn't get stuck on the old video frame although it will
2598 // flicker between the old video frame and the new video frame.
2608 mwindow->gui->lock_window("CWindowCanvas::cursor_motion_event 1");
2609 mwindow->gui->canvas->draw_overlays();
2610 mwindow->gui->canvas->flash();
2611 mwindow->gui->unlock_window();
2616 mwindow->restart_brender();
2617 mwindow->sync_parameters(CHANGE_PARAMS);
2618 gui->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2622 if(!redraw) gui->update_tool();
2627 int CWindowCanvas::button_press_event()
2631 int redraw_canvas = 0;
2634 if(Canvas::button_press_event()) return 1;
2636 gui->translating_zoom = gui->shift_down();
2639 //printf("CWindowCanvas::button_press_event 2 %f %f\n", gui->x_origin, gui->y_origin, gui->x_origin, gui->y_origin);
2641 float zoom_x, zoom_y, conformed_w, conformed_h;
2642 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
2643 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
2644 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
2647 if(get_buttonpress() == 2)
2649 gui->current_operation = CWINDOW_SCROLL;
2655 switch(mwindow->edl->session->cwindow_operation)
2657 case CWINDOW_CAMERA:
2658 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
2661 case CWINDOW_PROJECTOR:
2662 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
2666 result = test_zoom(redraw);
2670 result = test_crop(1, redraw);
2674 if(get_buttonpress() == 1)
2675 result = do_mask(redraw, rerender, 1, 0, 0);
2678 case CWINDOW_EYEDROP:
2679 result = do_eyedrop(rerender, 1);
2690 // rerendering can also be caused by press event
2693 mwindow->restart_brender();
2694 mwindow->sync_parameters(CHANGE_PARAMS);
2695 gui->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2699 if(!redraw) gui->update_tool();
2704 int CWindowCanvas::button_release_event()
2708 switch(gui->current_operation)
2710 case CWINDOW_SCROLL:
2714 case CWINDOW_CAMERA:
2715 mwindow->undo->update_undo(_("camera"), LOAD_AUTOMATION);
2718 case CWINDOW_PROJECTOR:
2719 mwindow->undo->update_undo(_("projector"), LOAD_AUTOMATION);
2723 case CWINDOW_MASK_CONTROL_IN:
2724 case CWINDOW_MASK_CONTROL_OUT:
2725 case CWINDOW_MASK_TRANSLATE:
2726 mwindow->undo->update_undo(_("mask point"), LOAD_AUTOMATION);
2731 gui->current_operation = CWINDOW_NONE;
2735 void CWindowCanvas::zoom_resize_window(float percentage)
2737 int canvas_w, canvas_h;
2738 calculate_sizes(mwindow->edl->get_aspect_ratio(),
2739 mwindow->edl->session->output_w,
2740 mwindow->edl->session->output_h,
2745 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
2746 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
2747 gui->resize_window(new_w, new_h);
2748 gui->resize_event(new_w, new_h);
2751 void CWindowCanvas::toggle_controls()
2753 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
2754 gui->resize_event(gui->get_w(), gui->get_h());
2757 int CWindowCanvas::get_cwindow_controls()
2759 return mwindow->session->cwindow_controls;