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,
633 this->mwindow = mwindow;
634 this->cwindow = cwindow;
637 void CWindowEditing::set_inpoint()
639 mwindow->set_inpoint(0);
642 void CWindowEditing::set_outpoint()
644 mwindow->set_outpoint(0);
651 CWindowMeters::CWindowMeters(MWindow *mwindow, CWindowGUI *gui, int x, int y, int h)
652 : MeterPanel(mwindow,
657 mwindow->edl->session->audio_channels,
658 mwindow->edl->session->cwindow_meter)
660 this->mwindow = mwindow;
664 CWindowMeters::~CWindowMeters()
668 int CWindowMeters::change_status_event()
670 mwindow->edl->session->cwindow_meter = use_meters;
671 mwindow->theme->get_cwindow_sizes(gui, mwindow->session->cwindow_controls);
672 gui->resize_event(gui->get_w(), gui->get_h());
679 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y)
682 (double)mwindow->edl->session->cwindow_zoom,
690 this->mwindow = mwindow;
694 CWindowZoom::~CWindowZoom()
698 int CWindowZoom::handle_event()
700 if(!strcasecmp(AUTO_ZOOM, get_text()))
702 gui->zoom_canvas(1, get_value(), 0);
706 gui->zoom_canvas(0, get_value(), 0);
714 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
715 : BC_PercentageSlider(x,
724 this->mwindow = mwindow;
725 this->cwindow = cwindow;
726 set_precision(0.00001);
727 set_pagination(1.0, 10.0);
730 CWindowSlider::~CWindowSlider()
734 int CWindowSlider::handle_event()
737 cwindow->playback_engine->interrupt_playback(1);
738 lock_window("CWindowSlider::handle_event 1");
740 mwindow->gui->lock_window("CWindowSlider::handle_event 2");
741 mwindow->select_point((double)get_value());
742 mwindow->gui->unlock_window();
746 void CWindowSlider::set_position()
748 double new_length = mwindow->edl->tracks->total_playable_length();
749 if(mwindow->edl->local_session->preview_end <= 0 ||
750 mwindow->edl->local_session->preview_end > new_length)
751 mwindow->edl->local_session->preview_end = new_length;
752 if(mwindow->edl->local_session->preview_start >
753 mwindow->edl->local_session->preview_end)
754 mwindow->edl->local_session->preview_start = 0;
758 update(mwindow->theme->cslider_w,
759 mwindow->edl->local_session->get_selectionstart(1),
760 mwindow->edl->local_session->preview_start,
761 mwindow->edl->local_session->preview_end);
765 int CWindowSlider::increase_value()
768 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
769 lock_window("CWindowSlider::increase_value");
773 int CWindowSlider::decrease_value()
776 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
777 lock_window("CWindowSlider::decrease_value");
782 // CWindowDestination::CWindowDestination(MWindow *mwindow, CWindowGUI *cwindow, int x, int y)
783 // : BC_PopupTextBox(cwindow,
784 // &cwindow->destinations,
785 // cwindow->destinations.values[cwindow->cwindow->destination]->get_text(),
791 // this->mwindow = mwindow;
792 // this->cwindow = cwindow;
795 // CWindowDestination::~CWindowDestination()
799 // int CWindowDestination::handle_event()
805 CWindowTransport::CWindowTransport(MWindow *mwindow,
809 : PlayTransport(mwindow,
817 EDL* CWindowTransport::get_edl()
822 void CWindowTransport::goto_start()
824 gui->unlock_window();
825 handle_transport(REWIND, 1);
827 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
828 mwindow->goto_start();
829 mwindow->gui->unlock_window();
831 gui->lock_window("CWindowTransport::goto_start 2");
834 void CWindowTransport::goto_end()
836 gui->unlock_window();
837 handle_transport(GOTO_END, 1);
839 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
841 mwindow->gui->unlock_window();
843 gui->lock_window("CWindowTransport::goto_end 2");
848 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
851 mwindow->theme->ccanvas_x,
852 mwindow->theme->ccanvas_y,
853 mwindow->theme->ccanvas_w,
854 mwindow->theme->ccanvas_h,
857 mwindow->edl->session->cwindow_scrollbars,
860 this->mwindow = mwindow;
864 void CWindowCanvas::status_event()
869 int CWindowCanvas::get_fullscreen()
871 return mwindow->session->cwindow_fullscreen;
874 void CWindowCanvas::set_fullscreen(int value)
876 mwindow->session->cwindow_fullscreen = value;
880 void CWindowCanvas::update_zoom(int x, int y, float zoom)
882 use_scrollbars = mwindow->edl->session->cwindow_scrollbars;
884 mwindow->edl->session->cwindow_xscroll = x;
885 mwindow->edl->session->cwindow_yscroll = y;
886 mwindow->edl->session->cwindow_zoom = zoom;
889 void CWindowCanvas::zoom_auto()
891 gui->zoom_canvas(1, 1.0, 1);
894 int CWindowCanvas::get_xscroll()
896 return mwindow->edl->session->cwindow_xscroll;
899 int CWindowCanvas::get_yscroll()
901 return mwindow->edl->session->cwindow_yscroll;
905 float CWindowCanvas::get_zoom()
907 return mwindow->edl->session->cwindow_zoom;
910 void CWindowCanvas::draw_refresh()
912 if(get_canvas() && !get_canvas()->get_video_on())
917 float in_x1, in_y1, in_x2, in_y2;
918 float out_x1, out_y1, out_x2, out_y2;
919 get_transfers(mwindow->edl,
929 get_canvas()->clear_box(0,
931 get_canvas()->get_w(),
932 get_canvas()->get_h());
934 // printf("CWindowCanvas::draw_refresh %f %f %f %f -> %f %f %f %f\n",
935 // in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
938 if(out_x2 > out_x1 &&
943 // Can't use OpenGL here because it is called asynchronously of the
944 // playback operation.
945 get_canvas()->draw_vframe(refresh_frame,
948 (int)(out_x2 - out_x1),
949 (int)(out_y2 - out_y1),
952 (int)(in_x2 - in_x1),
953 (int)(in_y2 - in_y1),
959 get_canvas()->flash();
961 //printf("CWindowCanvas::draw_refresh 10\n");
964 #define CROPHANDLE_W 10
965 #define CROPHANDLE_H 10
967 void CWindowCanvas::draw_crophandle(int x, int y)
969 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
974 #define FIRST_CONTROL_W 20
975 #define FIRST_CONTROL_H 20
977 #define BC_INFINITY 65536
979 #define SQR(x) ((x) * (x))
982 int CWindowCanvas::do_mask(int &redraw,
988 // Retrieve points from top recordable track
989 //printf("CWindowCanvas::do_mask 1\n");
990 Track *track = gui->cwindow->calculate_affected_track();
991 //printf("CWindowCanvas::do_mask 2\n");
994 //printf("CWindowCanvas::do_mask 3\n");
996 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
997 int64_t position = track->to_units(
998 mwindow->edl->local_session->get_selectionstart(1),
1000 ArrayList<MaskPoint*> points;
1001 mask_autos->get_points(&points, mwindow->edl->session->cwindow_mask,
1004 //printf("CWindowCanvas::do_mask 4\n");
1006 // Projector zooms relative to the center of the track output.
1007 float half_track_w = (float)track->track_w / 2;
1008 float half_track_h = (float)track->track_h / 2;
1009 // Translate mask to projection
1010 float projector_x, projector_y, projector_z;
1011 track->automation->get_projector(&projector_x,
1018 // Get position of cursor relative to mask
1019 float mask_cursor_x = get_cursor_x();
1020 float mask_cursor_y = get_cursor_y();
1021 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1023 projector_x += mwindow->edl->session->output_w / 2;
1024 projector_y += mwindow->edl->session->output_h / 2;
1026 mask_cursor_x -= projector_x;
1027 mask_cursor_y -= projector_y;
1028 mask_cursor_x = mask_cursor_x / projector_z + half_track_w;
1029 mask_cursor_y = mask_cursor_y / projector_z + half_track_h;
1031 // Fix cursor origin
1034 gui->x_origin = mask_cursor_x;
1035 gui->y_origin = mask_cursor_y;
1039 // Points of closest line
1040 int shortest_point1 = -1;
1041 int shortest_point2 = -1;
1043 int shortest_point = -1;
1044 // Distance to closest line
1045 float shortest_line_distance = BC_INFINITY;
1046 // Distance to closest point
1047 float shortest_point_distance = BC_INFINITY;
1048 int selected_point = -1;
1049 int selected_control_point = -1;
1050 float selected_control_point_distance = BC_INFINITY;
1051 ArrayList<int> x_points;
1052 ArrayList<int> y_points;
1058 get_canvas()->set_color(WHITE);
1059 get_canvas()->set_inverse();
1061 //printf("CWindowCanvas::do_mask 1 %d\n", points.total);
1063 // Never draw closed polygon and a closed
1064 // polygon is harder to add points to.
1065 for(int i = 0; i < points.total && !result; i++)
1067 MaskPoint *point1 = points.values[i];
1068 MaskPoint *point2 = (i >= points.total - 1) ?
1070 points.values[i + 1];
1071 float x0, x1, x2, x3;
1072 float y0, y1, y2, y3;
1073 float old_x, old_y, x, y;
1074 int segments = (int)(sqrt(SQR(point1->x - point2->x) + SQR(point1->y - point2->y)));
1076 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1077 //point1->x, point1->y, point2->x, point2->y, projector_z);
1078 for(int j = 0; j <= segments && !result; j++)
1080 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1083 x1 = point1->x + point1->control_x2;
1084 y1 = point1->y + point1->control_y2;
1085 x2 = point2->x + point2->control_x1;
1086 y2 = point2->y + point2->control_y1;
1090 float t = (float)j / segments;
1091 float tpow2 = t * t;
1092 float tpow3 = t * t * t;
1094 float invtpow2 = invt * invt;
1095 float invtpow3 = invt * invt * invt;
1098 + 3 * t * invtpow2 * x1
1099 + 3 * tpow2 * invt * x2
1102 + 3 * t * invtpow2 * y1
1103 + 3 * tpow2 * invt * y2
1106 x = (x - half_track_w) * projector_z + projector_x;
1107 y = (y - half_track_h) * projector_z + projector_y;
1110 // Test new point addition
1113 float line_distance =
1114 sqrt(SQR(x - mask_cursor_x) + SQR(y - mask_cursor_y));
1116 //printf("CWindowCanvas::do_mask 1 x=%f mask_cursor_x=%f y=%f mask_cursor_y=%f %f %f %d, %d\n",
1117 //x, mask_cursor_x, y, mask_cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1118 if(line_distance < shortest_line_distance ||
1119 shortest_point1 < 0)
1121 shortest_line_distance = line_distance;
1122 shortest_point1 = i;
1123 shortest_point2 = (i >= points.total - 1) ? 0 : (i + 1);
1124 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n", line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1128 float point_distance1 =
1129 sqrt(SQR(point1->x - mask_cursor_x) + SQR(point1->y - mask_cursor_y));
1130 float point_distance2 =
1131 sqrt(SQR(point2->x - mask_cursor_x) + SQR(point2->y - mask_cursor_y));
1133 if(point_distance1 < shortest_point_distance ||
1136 shortest_point_distance = point_distance1;
1140 if(point_distance2 < shortest_point_distance ||
1143 shortest_point_distance = point_distance2;
1144 shortest_point = (i >= points.total - 1) ? 0 : (i + 1);
1148 output_to_canvas(mwindow->edl, 0, x, y);
1151 #define TEST_BOX(cursor_x, cursor_y, target_x, target_y) \
1152 (cursor_x >= target_x - CONTROL_W / 2 && \
1153 cursor_x < target_x + CONTROL_W / 2 && \
1154 cursor_y >= target_y - CONTROL_H / 2 && \
1155 cursor_y < target_y + CONTROL_H / 2)
1157 // Test existing point selection
1160 float canvas_x = (x0 - half_track_w) * projector_z + projector_x;
1161 float canvas_y = (y0 - half_track_h) * projector_z + projector_y;
1162 int cursor_x = get_cursor_x();
1163 int cursor_y = get_cursor_y();
1166 if(gui->shift_down())
1168 float control_x = (x1 - half_track_w) * projector_z + projector_x;
1169 float control_y = (y1 - half_track_h) * projector_z + projector_y;
1170 output_to_canvas(mwindow->edl, 0, control_x, control_y);
1173 sqrt(SQR(control_x - cursor_x) + SQR(control_y - cursor_y));
1175 if(distance < selected_control_point_distance)
1178 selected_control_point = 1;
1179 selected_control_point_distance = distance;
1184 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1185 if(!gui->ctrl_down())
1187 if(TEST_BOX(cursor_x, cursor_y, canvas_x, canvas_y))
1194 selected_point = shortest_point;
1198 // Test second point
1199 canvas_x = (x3 - half_track_w) * projector_z + projector_x;
1200 canvas_y = (y3 - half_track_h) * projector_z + projector_y;
1201 if(gui->shift_down())
1203 float control_x = (x2 - half_track_w) * projector_z + projector_x;
1204 float control_y = (y2 - half_track_h) * projector_z + projector_y;
1205 output_to_canvas(mwindow->edl, 0, control_x, control_y);
1208 sqrt(SQR(control_x - cursor_x) + SQR(control_y - cursor_y));
1210 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1211 if(distance < selected_control_point_distance)
1213 selected_point = (i < points.total - 1 ? i + 1 : 0);
1214 selected_control_point = 0;
1215 selected_control_point_distance = distance;
1219 if(i < points.total - 1)
1221 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1222 if(!gui->ctrl_down())
1224 if(TEST_BOX(cursor_x, cursor_y, canvas_x, canvas_y))
1226 selected_point = (i < points.total - 1 ? i + 1 : 0);
1231 selected_point = shortest_point;
1240 // Draw joining line
1243 x_points.append((int)x);
1244 y_points.append((int)y);
1255 // Draw second anchor
1256 if(i < points.total - 1)
1258 if(i == gui->affected_point - 1)
1259 get_canvas()->draw_disc((int)x - CONTROL_W / 2,
1260 (int)y - CONTROL_W / 2,
1264 get_canvas()->draw_circle((int)x - CONTROL_W / 2,
1265 (int)y - CONTROL_W / 2,
1268 // char string[BCTEXTLEN];
1269 // sprintf(string, "%d", (i < points.total - 1 ? i + 1 : 0));
1270 // canvas->draw_text((int)x + CONTROL_W, (int)y + CONTROL_W, string);
1273 // Draw second control point. Discard x2 and y2 after this.
1274 x2 = (x2 - half_track_w) * projector_z + projector_x;
1275 y2 = (y2 - half_track_h) * projector_z + projector_y;
1276 output_to_canvas(mwindow->edl, 0, x2, y2);
1277 get_canvas()->draw_line((int)x, (int)y, (int)x2, (int)y2);
1278 get_canvas()->draw_rectangle((int)x2 - CONTROL_W / 2,
1279 (int)y2 - CONTROL_H / 2,
1289 // Draw first anchor
1292 get_canvas()->draw_disc((int)x - FIRST_CONTROL_W / 2,
1293 (int)y - FIRST_CONTROL_H / 2,
1298 // Draw first control point. Discard x1 and y1 after this.
1301 x1 = (x1 - half_track_w) * projector_z + projector_x;
1302 y1 = (y1 - half_track_h) * projector_z + projector_y;
1303 output_to_canvas(mwindow->edl, 0, x1, y1);
1304 get_canvas()->draw_line((int)x, (int)y, (int)x1, (int)y1);
1305 get_canvas()->draw_rectangle((int)x1 - CONTROL_W / 2,
1306 (int)y1 - CONTROL_H / 2,
1310 x_points.append((int)x);
1311 y_points.append((int)y);
1314 //printf("CWindowCanvas::do_mask 1\n");
1320 //printf("CWindowCanvas::do_mask 1\n");
1324 get_canvas()->draw_polygon(&x_points, &y_points);
1325 get_canvas()->set_opaque();
1327 //printf("CWindowCanvas::do_mask 1\n");
1336 if(button_press && !result)
1338 gui->affected_track = gui->cwindow->calculate_affected_track();
1339 // Get current keyframe
1340 if(gui->affected_track)
1341 gui->affected_keyframe =
1342 gui->cwindow->calculate_affected_auto(
1343 gui->affected_track->automation->autos[AUTOMATION_MASK],
1346 MaskAuto *keyframe = (MaskAuto*)gui->affected_keyframe;
1347 SubMask *mask = keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1350 // Translate entire keyframe
1351 if(gui->alt_down() && mask->points.total)
1353 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1354 gui->affected_point = 0;
1357 // Existing point or control point was selected
1358 if(selected_point >= 0)
1360 gui->affected_point = selected_point;
1362 if(selected_control_point == 0)
1363 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1365 if(selected_control_point == 1)
1366 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1368 gui->current_operation = mwindow->edl->session->cwindow_operation;
1371 // No existing point or control point was selected so create a new one
1372 if(!gui->shift_down() && !gui->alt_down())
1374 // Create the template
1375 MaskPoint *point = new MaskPoint;
1376 point->x = mask_cursor_x;
1377 point->y = mask_cursor_y;
1378 point->control_x1 = 0;
1379 point->control_y1 = 0;
1380 point->control_x2 = 0;
1381 point->control_y2 = 0;
1384 if(shortest_point2 < shortest_point1)
1386 shortest_point2 ^= shortest_point1;
1387 shortest_point1 ^= shortest_point2;
1388 shortest_point2 ^= shortest_point1;
1393 // printf("CWindowGUI::do_mask 40\n");
1394 // mwindow->edl->dump();
1395 // printf("CWindowGUI::do_mask 50\n");
1399 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1400 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1401 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1403 // Append to end of list
1404 if(labs(shortest_point1 - shortest_point2) > 1)
1406 // Need to apply the new point to every keyframe
1407 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto;
1410 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1411 MaskPoint *new_point = new MaskPoint;
1412 submask->points.append(new_point);
1413 *new_point = *point;
1414 if(current == (MaskAuto*)mask_autos->default_auto)
1415 current = (MaskAuto*)mask_autos->first;
1417 current = (MaskAuto*)NEXT;
1420 gui->affected_point = mask->points.total - 1;
1424 // Insert between 2 points, shifting back point 2
1425 if(shortest_point1 >= 0 && shortest_point2 >= 0)
1427 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto;
1430 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1431 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1433 if(submask->points.total >= shortest_point2)
1435 MaskPoint *new_point = new MaskPoint;
1436 submask->points.append(0);
1437 for(int i = submask->points.total - 1;
1438 i > shortest_point2;
1440 submask->points.values[i] = submask->points.values[i - 1];
1441 submask->points.values[shortest_point2] = new_point;
1443 *new_point = *point;
1446 if(current == (MaskAuto*)mask_autos->default_auto)
1447 current = (MaskAuto*)mask_autos->first;
1449 current = (MaskAuto*)NEXT;
1453 gui->affected_point = shortest_point2;
1458 // printf("CWindowGUI::do_mask 20\n");
1459 // mwindow->edl->dump();
1460 // printf("CWindowGUI::do_mask 30\n");
1465 // Create the first point.
1468 //printf("CWindowCanvas::do_mask 1\n");
1469 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto;
1472 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1473 MaskPoint *new_point = new MaskPoint;
1474 submask->points.append(new_point);
1475 *new_point = *point;
1476 if(current == (MaskAuto*)mask_autos->default_auto)
1477 current = (MaskAuto*)mask_autos->first;
1479 current = (MaskAuto*)NEXT;
1482 //printf("CWindowCanvas::do_mask 2\n");
1483 // Create a second point if none existed before
1484 if(mask->points.total < 2)
1486 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto;
1489 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1490 MaskPoint *new_point = new MaskPoint;
1491 submask->points.append(new_point);
1492 *new_point = *point;
1493 if(current == (MaskAuto*)mask_autos->default_auto)
1494 current = (MaskAuto*)mask_autos->first;
1496 current = (MaskAuto*)NEXT;
1499 gui->affected_point = mask->points.total - 1;
1500 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.total);
1505 gui->current_operation = mwindow->edl->session->cwindow_operation;
1506 // Delete the template
1508 //printf("CWindowGUI::do_mask 1\n");
1509 mwindow->undo->update_undo(_("mask point"), LOAD_AUTOMATION);
1510 //printf("CWindowGUI::do_mask 10\n");
1519 if(button_press && result)
1521 MaskAuto *keyframe = (MaskAuto*)gui->affected_keyframe;
1522 SubMask *mask = keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1523 MaskPoint *point = mask->points.values[gui->affected_point];
1524 gui->center_x = point->x;
1525 gui->center_y = point->y;
1526 gui->control_in_x = point->control_x1;
1527 gui->control_in_y = point->control_y1;
1528 gui->control_out_x = point->control_x2;
1529 gui->control_out_y = point->control_y2;
1532 //printf("CWindowCanvas::do_mask 8\n");
1535 MaskAuto *keyframe = (MaskAuto*)gui->affected_keyframe;
1536 SubMask *mask = keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1537 if(gui->affected_point < mask->points.total)
1539 MaskPoint *point = mask->points.values[gui->affected_point];
1540 // float cursor_x = get_cursor_x();
1541 // float cursor_y = get_cursor_y();
1542 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
1543 float cursor_x = mask_cursor_x;
1544 float cursor_y = mask_cursor_y;
1545 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask->points.total, gui->affected_point);
1547 float last_x = point->x;
1548 float last_y = point->y;
1549 float last_control_x1 = point->control_x1;
1550 float last_control_y1 = point->control_y1;
1551 float last_control_x2 = point->control_x2;
1552 float last_control_y2 = point->control_y2;
1555 switch(gui->current_operation)
1558 point->x = cursor_x - gui->x_origin + gui->center_x;
1559 point->y = cursor_y - gui->y_origin + gui->center_y;
1562 case CWINDOW_MASK_CONTROL_IN:
1563 point->control_x1 = cursor_x - gui->x_origin + gui->control_in_x;
1564 point->control_y1 = cursor_y - gui->y_origin + gui->control_in_y;
1567 case CWINDOW_MASK_CONTROL_OUT:
1568 point->control_x2 = cursor_x - gui->x_origin + gui->control_out_x;
1569 point->control_y2 = cursor_y - gui->y_origin + gui->control_out_y;
1572 case CWINDOW_MASK_TRANSLATE:
1573 for(int i = 0; i < mask->points.total; i++)
1575 mask->points.values[i]->x += cursor_x - gui->x_origin;
1576 mask->points.values[i]->y += cursor_y - gui->y_origin;
1578 gui->x_origin = cursor_x;
1579 gui->y_origin = cursor_y;
1584 if( !EQUIV(last_x, point->x) ||
1585 !EQUIV(last_y, point->y) ||
1586 !EQUIV(last_control_x1, point->control_x1) ||
1587 !EQUIV(last_control_y1, point->control_y1) ||
1588 !EQUIV(last_control_x2, point->control_x2) ||
1589 !EQUIV(last_control_y2, point->control_y2))
1597 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
1599 points.remove_all_objects();
1600 //printf("CWindowCanvas::do_mask 20\n");
1605 int CWindowCanvas::do_eyedrop(int &rerender, int button_press)
1608 float cursor_x = get_cursor_x();
1609 float cursor_y = get_cursor_y();
1614 gui->current_operation = CWINDOW_EYEDROP;
1617 if(gui->current_operation == CWINDOW_EYEDROP)
1619 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
1621 // Get color out of frame.
1622 // Doesn't work during playback because that bypasses the refresh frame.
1625 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
1626 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
1628 // Decompression coefficients straight out of jpeglib
1629 #define V_TO_R 1.40200
1630 #define V_TO_G -0.71414
1632 #define U_TO_G -0.34414
1633 #define U_TO_B 1.77200
1635 #define GET_COLOR(type, components, max, do_yuv) \
1637 type *row = (type*)(refresh_frame->get_rows()[(int)cursor_y]) + \
1638 (int)cursor_x * components; \
1639 float red = (float)*row++ / max; \
1640 float green = (float)*row++ / max; \
1641 float blue = (float)*row++ / max; \
1644 mwindow->edl->local_session->red = red + V_TO_R * (blue - 0.5); \
1645 mwindow->edl->local_session->green = red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
1646 mwindow->edl->local_session->blue = red + U_TO_B * (green - 0.5); \
1650 mwindow->edl->local_session->red = red; \
1651 mwindow->edl->local_session->green = green; \
1652 mwindow->edl->local_session->blue = blue; \
1656 switch(refresh_frame->get_color_model())
1659 GET_COLOR(unsigned char, 3, 0xff, 1);
1662 GET_COLOR(unsigned char, 4, 0xff, 1);
1665 GET_COLOR(uint16_t, 3, 0xffff, 1);
1667 case BC_YUVA16161616:
1668 GET_COLOR(uint16_t, 4, 0xffff, 1);
1671 GET_COLOR(unsigned char, 3, 0xff, 0);
1674 GET_COLOR(unsigned char, 4, 0xff, 0);
1677 GET_COLOR(float, 3, 1.0, 0);
1680 GET_COLOR(float, 4, 1.0, 0);
1686 mwindow->edl->local_session->red = 0;
1687 mwindow->edl->local_session->green = 0;
1688 mwindow->edl->local_session->blue = 0;
1697 // Can't rerender since the color value is from the output of any effect it
1705 void CWindowCanvas::draw_overlays()
1707 if(mwindow->edl->session->safe_regions)
1709 draw_safe_regions();
1712 if(mwindow->edl->session->cwindow_scrollbars)
1714 // Always draw output rectangle
1715 float x1, y1, x2, y2;
1717 x2 = mwindow->edl->session->output_w;
1719 y2 = mwindow->edl->session->output_h;
1720 output_to_canvas(mwindow->edl, 0, x1, y1);
1721 output_to_canvas(mwindow->edl, 0, x2, y2);
1723 get_canvas()->set_inverse();
1724 get_canvas()->set_color(WHITE);
1726 get_canvas()->draw_rectangle((int)x1,
1731 get_canvas()->set_opaque();
1734 if(mwindow->session->ccanvas_highlighted)
1736 get_canvas()->set_color(WHITE);
1737 get_canvas()->set_inverse();
1738 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
1739 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
1740 get_canvas()->set_opaque();
1743 int temp1 = 0, temp2 = 0;
1744 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
1745 switch(mwindow->edl->session->cwindow_operation)
1747 case CWINDOW_CAMERA:
1751 case CWINDOW_PROJECTOR:
1760 do_mask(temp1, temp2, 0, 0, 1);
1765 void CWindowCanvas::draw_safe_regions()
1767 float action_x1, action_x2, action_y1, action_y2;
1768 float title_x1, title_x2, title_y1, title_y2;
1770 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
1771 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
1772 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
1773 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
1774 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
1775 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
1776 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
1777 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
1779 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
1780 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
1781 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
1782 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
1784 get_canvas()->set_inverse();
1785 get_canvas()->set_color(WHITE);
1787 get_canvas()->draw_rectangle((int)action_x1,
1789 (int)(action_x2 - action_x1),
1790 (int)(action_y2 - action_y1));
1791 get_canvas()->draw_rectangle((int)title_x1,
1793 (int)(title_x2 - title_x1),
1794 (int)(title_y2 - title_y1));
1796 get_canvas()->set_opaque();
1799 void CWindowCanvas::reset_keyframe(int do_camera)
1801 FloatAuto *x_keyframe = 0;
1802 FloatAuto *y_keyframe = 0;
1803 FloatAuto *z_keyframe = 0;
1804 Track *affected_track = 0;
1806 affected_track = gui->cwindow->calculate_affected_track();
1810 gui->cwindow->calculate_affected_autos(&x_keyframe,
1819 x_keyframe->value = 0;
1820 y_keyframe->value = 0;
1821 z_keyframe->value = 1;
1823 mwindow->sync_parameters(CHANGE_PARAMS);
1828 void CWindowCanvas::reset_camera()
1833 void CWindowCanvas::reset_projector()
1838 int CWindowCanvas::test_crop(int button_press, int &redraw)
1841 int handle_selected = -1;
1842 float x1 = mwindow->edl->session->crop_x1;
1843 float y1 = mwindow->edl->session->crop_y1;
1844 float x2 = mwindow->edl->session->crop_x2;
1845 float y2 = mwindow->edl->session->crop_y2;
1846 float cursor_x = get_cursor_x();
1847 float cursor_y = get_cursor_y();
1848 float canvas_x1 = x1;
1849 float canvas_y1 = y1;
1850 float canvas_x2 = x2;
1851 float canvas_y2 = y2;
1852 float canvas_cursor_x = cursor_x;
1853 float canvas_cursor_y = cursor_y;
1855 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
1856 // Use screen normalized coordinates for hot spot tests.
1857 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1858 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1861 if(gui->current_operation == CWINDOW_CROP)
1863 handle_selected = gui->crop_handle;
1866 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
1867 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
1869 handle_selected = 0;
1870 gui->crop_origin_x = x1;
1871 gui->crop_origin_y = y1;
1874 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
1875 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
1877 handle_selected = 1;
1878 gui->crop_origin_x = x2;
1879 gui->crop_origin_y = y1;
1882 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
1883 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
1885 handle_selected = 2;
1886 gui->crop_origin_x = x1;
1887 gui->crop_origin_y = y2;
1890 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
1891 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
1893 handle_selected = 3;
1894 gui->crop_origin_x = x2;
1895 gui->crop_origin_y = y2;
1900 gui->crop_origin_x = cursor_x;
1901 gui->crop_origin_y = cursor_y;
1904 // printf("test crop %d %d\n",
1905 // gui->current_operation,
1906 // handle_selected);
1913 gui->crop_translate = 1;
1914 gui->crop_origin_x1 = x1;
1915 gui->crop_origin_y1 = y1;
1916 gui->crop_origin_x2 = x2;
1917 gui->crop_origin_y2 = y2;
1920 gui->crop_translate = 0;
1922 gui->current_operation = CWINDOW_CROP;
1923 gui->crop_handle = handle_selected;
1924 gui->x_origin = cursor_x;
1925 gui->y_origin = cursor_y;
1928 if(handle_selected < 0 && !gui->crop_translate)
1932 mwindow->edl->session->crop_x1 = (int)x1;
1933 mwindow->edl->session->crop_y1 = (int)y1;
1934 mwindow->edl->session->crop_x2 = (int)x2;
1935 mwindow->edl->session->crop_y2 = (int)y2;
1940 // Translate all 4 points
1941 if(gui->current_operation == CWINDOW_CROP && gui->crop_translate)
1943 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
1944 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
1945 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
1946 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
1948 mwindow->edl->session->crop_x1 = (int)x1;
1949 mwindow->edl->session->crop_y1 = (int)y1;
1950 mwindow->edl->session->crop_x2 = (int)x2;
1951 mwindow->edl->session->crop_y2 = (int)y2;
1957 if(gui->current_operation == CWINDOW_CROP)
1959 switch(gui->crop_handle)
1962 x1 = gui->crop_origin_x;
1963 y1 = gui->crop_origin_y;
1964 x2 = gui->crop_origin_x;
1965 y2 = gui->crop_origin_y;
1966 if(cursor_x < gui->x_origin)
1968 if(cursor_y < gui->y_origin)
1974 if(cursor_y >= gui->y_origin)
1981 if(cursor_x >= gui->x_origin)
1983 if(cursor_y < gui->y_origin)
1989 if(cursor_y >= gui->y_origin)
1996 // printf("test crop %d %d %d %d\n",
1997 // mwindow->edl->session->crop_x1,
1998 // mwindow->edl->session->crop_y1,
1999 // mwindow->edl->session->crop_x2,
2000 // mwindow->edl->session->crop_y2);
2003 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2004 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2007 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2008 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2011 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2012 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2015 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2016 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2020 if(!EQUIV(mwindow->edl->session->crop_x1, x1) ||
2021 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2022 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2023 !EQUIV(mwindow->edl->session->crop_y2, y2))
2030 switch (gui->crop_handle)
2032 case 0: gui->crop_handle = 1; break;
2033 case 1: gui->crop_handle = 0; break;
2034 case 2: gui->crop_handle = 3; break;
2035 case 3: gui->crop_handle = 2; break;
2045 switch (gui->crop_handle)
2047 case 0: gui->crop_handle = 2; break;
2048 case 1: gui->crop_handle = 3; break;
2049 case 2: gui->crop_handle = 0; break;
2050 case 3: gui->crop_handle = 1; break;
2055 mwindow->edl->session->crop_x1 = (int)x1;
2056 mwindow->edl->session->crop_y1 = (int)y1;
2057 mwindow->edl->session->crop_x2 = (int)x2;
2058 mwindow->edl->session->crop_y2 = (int)y2;
2064 // Update cursor font
2065 if(handle_selected >= 0)
2067 switch(handle_selected)
2070 set_cursor(UPLEFT_RESIZE);
2073 set_cursor(UPRIGHT_RESIZE);
2076 set_cursor(DOWNLEFT_RESIZE);
2079 set_cursor(DOWNRIGHT_RESIZE);
2086 set_cursor(ARROW_CURSOR);
2088 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2092 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2093 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2094 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2095 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2096 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2097 // mwindow->edl->session->crop_x2,
2098 // mwindow->edl->session->crop_y2,
2099 // mwindow->edl->calculate_output_w(0),
2100 // mwindow->edl->calculate_output_h(0));
2106 void CWindowCanvas::draw_crop()
2108 get_canvas()->set_inverse();
2109 get_canvas()->set_color(WHITE);
2111 float x1 = mwindow->edl->session->crop_x1;
2112 float y1 = mwindow->edl->session->crop_y1;
2113 float x2 = mwindow->edl->session->crop_x2;
2114 float y2 = mwindow->edl->session->crop_y2;
2116 output_to_canvas(mwindow->edl, 0, x1, y1);
2117 output_to_canvas(mwindow->edl, 0, x2, y2);
2119 if(x2 - x1 && y2 - y1)
2120 get_canvas()->draw_rectangle((int)x1,
2125 draw_crophandle((int)x1, (int)y1);
2126 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2127 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2128 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2129 get_canvas()->set_opaque();
2139 void CWindowCanvas::draw_bezier(int do_camera)
2141 Track *track = gui->cwindow->calculate_affected_track();
2148 int64_t position = track->to_units(
2149 mwindow->edl->local_session->get_selectionstart(1),
2152 track->automation->get_projector(¢er_x,
2158 // center_x += track->track_w / 2;
2159 // center_y += track->track_h / 2;
2160 center_x += mwindow->edl->session->output_w / 2;
2161 center_y += mwindow->edl->session->output_h / 2;
2162 float track_x1 = center_x - track->track_w / 2 * center_z;
2163 float track_y1 = center_y - track->track_h / 2 * center_z;
2164 float track_x2 = track_x1 + track->track_w * center_z;
2165 float track_y2 = track_y1 + track->track_h * center_z;
2167 output_to_canvas(mwindow->edl, 0, track_x1, track_y1);
2168 output_to_canvas(mwindow->edl, 0, track_x2, track_y2);
2170 #define DRAW_PROJECTION(offset) \
2171 get_canvas()->draw_rectangle((int)track_x1 + offset, \
2172 (int)track_y1 + offset, \
2173 (int)(track_x2 - track_x1), \
2174 (int)(track_y2 - track_y1)); \
2175 get_canvas()->draw_line((int)track_x1 + offset, \
2176 (int)track_y1 + offset, \
2177 (int)track_x2 + offset, \
2178 (int)track_y2 + offset); \
2179 get_canvas()->draw_line((int)track_x2 + offset, \
2180 (int)track_y1 + offset, \
2181 (int)track_x1 + offset, \
2182 (int)track_y2 + offset); \
2186 get_canvas()->set_color(BLACK);
2189 // canvas->set_inverse();
2191 get_canvas()->set_color(GREEN);
2193 get_canvas()->set_color(RED);
2196 // canvas->set_opaque();
2202 int CWindowCanvas::test_bezier(int button_press,
2210 // Processing drag operation.
2211 // Create keyframe during first cursor motion.
2215 float cursor_x = get_cursor_x();
2216 float cursor_y = get_cursor_y();
2217 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2219 if(gui->current_operation == CWINDOW_CAMERA ||
2220 gui->current_operation == CWINDOW_PROJECTOR)
2222 if(!gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom)
2224 gui->translating_zoom = 1;
2225 gui->reset_affected();
2228 if(!gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom)
2230 gui->translating_zoom = 0;
2231 gui->reset_affected();
2234 // Get target keyframe
2235 float last_center_x;
2236 float last_center_y;
2237 float last_center_z;
2240 if(!gui->affected_x && !gui->affected_y && !gui->affected_z)
2242 FloatAutos *affected_x_autos;
2243 FloatAutos *affected_y_autos;
2244 FloatAutos *affected_z_autos;
2245 if(!gui->affected_track) return 0;
2246 double position = mwindow->edl->local_session->get_selectionstart(1);
2247 int64_t track_position = gui->affected_track->to_units(position, 0);
2249 if(mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA)
2251 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_X];
2252 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Y];
2253 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Z];
2257 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_X];
2258 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Y];
2259 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Z];
2263 if(gui->translating_zoom)
2265 FloatAuto *previous = 0;
2266 FloatAuto *next = 0;
2267 float new_z = affected_z_autos->get_value(
2273 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2274 affected_z_autos, 1, &created, 0);
2277 gui->affected_z->value = new_z;
2278 gui->affected_z->control_in_value = 0;
2279 gui->affected_z->control_out_value = 0;
2280 gui->affected_z->control_in_position = 0;
2281 gui->affected_z->control_out_position = 0;
2287 FloatAuto *previous = 0;
2288 FloatAuto *next = 0;
2289 float new_x = affected_x_autos->get_value(
2296 float new_y = affected_y_autos->get_value(
2302 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2303 affected_x_autos, 1, &created, 0);
2306 gui->affected_x->value = new_x;
2307 gui->affected_x->control_in_value = 0;
2308 gui->affected_x->control_out_value = 0;
2309 gui->affected_x->control_in_position = 0;
2310 gui->affected_x->control_out_position = 0;
2314 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2315 affected_y_autos, 1, &created, 0);
2318 gui->affected_y->value = new_y;
2319 gui->affected_y->control_in_value = 0;
2320 gui->affected_y->control_out_value = 0;
2321 gui->affected_y->control_in_position = 0;
2322 gui->affected_y->control_out_position = 0;
2329 if(gui->translating_zoom)
2331 gui->center_z = gui->affected_z->value;
2335 gui->center_x = gui->affected_x->value;
2336 gui->center_y = gui->affected_y->value;
2344 if(gui->translating_zoom)
2346 last_center_z = gui->affected_z->value;
2350 last_center_x = gui->affected_x->value;
2351 last_center_y = gui->affected_y->value;
2354 if(gui->translating_zoom)
2356 gui->affected_z->value = gui->center_z +
2357 (cursor_y - gui->y_origin) / 128;
2359 if(gui->affected_z->value < 0) gui->affected_z->value = 0;
2360 if(!EQUIV(last_center_z, gui->affected_z->value))
2369 gui->affected_x->value = gui->center_x + cursor_x - gui->x_origin;
2370 gui->affected_y->value = gui->center_y + cursor_y - gui->y_origin;
2371 if(!EQUIV(last_center_x, gui->affected_x->value) ||
2372 !EQUIV(last_center_y, gui->affected_y->value))
2384 // Begin drag operation. Don't create keyframe here.
2386 // Get affected track off of the first recordable video track.
2387 // Calculating based on the alpha channel would require recording what layer
2388 // each output pixel belongs to as they're rendered and stacked. Forget it.
2389 gui->affected_track = gui->cwindow->calculate_affected_track();
2390 gui->reset_affected();
2392 if(gui->affected_track)
2394 gui->current_operation =
2395 mwindow->edl->session->cwindow_operation;
2403 int CWindowCanvas::test_zoom(int &redraw)
2406 float zoom = get_zoom();
2410 if(!mwindow->edl->session->cwindow_scrollbars)
2412 mwindow->edl->session->cwindow_scrollbars = 1;
2414 x = mwindow->edl->session->output_w / 2;
2415 y = mwindow->edl->session->output_h / 2;
2421 canvas_to_output(mwindow->edl,
2426 //printf("CWindowCanvas::test_zoom 1 %f %f\n", x, y);
2428 // Find current zoom in table
2429 int current_index = 0;
2430 for(current_index = 0 ; current_index < total_zooms; current_index++)
2431 if(EQUIV(my_zoom_table[current_index], zoom)) break;
2435 if(get_buttonpress() == 5 ||
2446 CLAMP(current_index, 0, total_zooms - 1);
2447 zoom = my_zoom_table[current_index];
2450 x = x - w / zoom / 2;
2451 y = y - h / zoom / 2;
2456 // check_boundaries(mwindow->edl, x_i, y_i, zoom);
2458 //printf("CWindowCanvas::test_zoom 2 %d %d\n", x_i, y_i);
2463 reposition_window(mwindow->edl,
2464 mwindow->theme->ccanvas_x,
2465 mwindow->theme->ccanvas_y,
2466 mwindow->theme->ccanvas_w,
2467 mwindow->theme->ccanvas_h);
2472 gui->zoom_panel->update(zoom);
2478 void CWindowCanvas::calculate_origin()
2480 gui->x_origin = get_cursor_x();
2481 gui->y_origin = get_cursor_y();
2482 //printf("CWindowCanvas::calculate_origin 1 %f %f\n", gui->x_origin, gui->y_origin);
2483 canvas_to_output(mwindow->edl, 0, gui->x_origin, gui->y_origin);
2484 //printf("CWindowCanvas::calculate_origin 2 %f %f\n", gui->x_origin, gui->y_origin);
2488 int CWindowCanvas::cursor_leave_event()
2490 set_cursor(ARROW_CURSOR);
2494 int CWindowCanvas::cursor_enter_event()
2497 switch(mwindow->edl->session->cwindow_operation)
2499 case CWINDOW_CAMERA:
2500 case CWINDOW_PROJECTOR:
2501 set_cursor(MOVE_CURSOR);
2504 set_cursor(MOVE_CURSOR);
2507 test_crop(0, redraw);
2509 case CWINDOW_PROTECT:
2510 set_cursor(ARROW_CURSOR);
2513 set_cursor(CROSS_CURSOR);
2515 case CWINDOW_EYEDROP:
2516 set_cursor(CROSS_CURSOR);
2522 int CWindowCanvas::cursor_motion_event()
2524 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
2527 switch(gui->current_operation)
2529 case CWINDOW_SCROLL:
2531 float zoom = get_zoom();
2532 float cursor_x = get_cursor_x();
2533 float cursor_y = get_cursor_y();
2535 float zoom_x, zoom_y, conformed_w, conformed_h;
2536 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
2537 cursor_x = (float)cursor_x / zoom_x + gui->x_offset;
2538 cursor_y = (float)cursor_y / zoom_y + gui->y_offset;
2542 int x = (int)(gui->x_origin - cursor_x + gui->x_offset);
2543 int y = (int)(gui->y_origin - cursor_y + gui->y_offset);
2548 update_scrollbars();
2554 case CWINDOW_CAMERA:
2555 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
2558 case CWINDOW_PROJECTOR:
2559 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
2564 //printf("CWindowCanvas::cursor_motion_event 1 %d %d\n", x, y);
2565 result = test_crop(0, redraw);
2569 case CWINDOW_MASK_CONTROL_IN:
2570 case CWINDOW_MASK_CONTROL_OUT:
2571 case CWINDOW_MASK_TRANSLATE:
2572 result = do_mask(redraw,
2579 case CWINDOW_EYEDROP:
2580 result = do_eyedrop(rerender, 0);
2589 switch(mwindow->edl->session->cwindow_operation)
2592 result = test_crop(0, redraw);
2598 // If the window is never unlocked before calling send_command the
2599 // display shouldn't get stuck on the old video frame although it will
2600 // flicker between the old video frame and the new video frame.
2610 mwindow->gui->lock_window("CWindowCanvas::cursor_motion_event 1");
2611 mwindow->gui->canvas->draw_overlays();
2612 mwindow->gui->canvas->flash();
2613 mwindow->gui->unlock_window();
2618 mwindow->restart_brender();
2619 mwindow->sync_parameters(CHANGE_PARAMS);
2620 gui->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2624 if(!redraw) gui->update_tool();
2629 int CWindowCanvas::button_press_event()
2633 int redraw_canvas = 0;
2636 if(Canvas::button_press_event()) return 1;
2638 gui->translating_zoom = gui->shift_down();
2641 //printf("CWindowCanvas::button_press_event 2 %f %f\n", gui->x_origin, gui->y_origin, gui->x_origin, gui->y_origin);
2643 float zoom_x, zoom_y, conformed_w, conformed_h;
2644 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
2645 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
2646 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
2649 if(get_buttonpress() == 2)
2651 gui->current_operation = CWINDOW_SCROLL;
2657 switch(mwindow->edl->session->cwindow_operation)
2659 case CWINDOW_CAMERA:
2660 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
2663 case CWINDOW_PROJECTOR:
2664 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
2668 result = test_zoom(redraw);
2672 result = test_crop(1, redraw);
2676 if(get_buttonpress() == 1)
2677 result = do_mask(redraw, rerender, 1, 0, 0);
2680 case CWINDOW_EYEDROP:
2681 result = do_eyedrop(rerender, 1);
2692 // rerendering can also be caused by press event
2695 mwindow->restart_brender();
2696 mwindow->sync_parameters(CHANGE_PARAMS);
2697 gui->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
2701 if(!redraw) gui->update_tool();
2706 int CWindowCanvas::button_release_event()
2710 switch(gui->current_operation)
2712 case CWINDOW_SCROLL:
2716 case CWINDOW_CAMERA:
2717 mwindow->undo->update_undo(_("camera"), LOAD_AUTOMATION);
2720 case CWINDOW_PROJECTOR:
2721 mwindow->undo->update_undo(_("projector"), LOAD_AUTOMATION);
2725 case CWINDOW_MASK_CONTROL_IN:
2726 case CWINDOW_MASK_CONTROL_OUT:
2727 case CWINDOW_MASK_TRANSLATE:
2728 mwindow->undo->update_undo(_("mask point"), LOAD_AUTOMATION);
2733 gui->current_operation = CWINDOW_NONE;
2737 void CWindowCanvas::zoom_resize_window(float percentage)
2739 int canvas_w, canvas_h;
2740 calculate_sizes(mwindow->edl->get_aspect_ratio(),
2741 mwindow->edl->session->output_w,
2742 mwindow->edl->session->output_h,
2747 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
2748 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
2749 gui->resize_window(new_w, new_h);
2750 gui->resize_event(new_w, new_h);
2753 void CWindowCanvas::toggle_controls()
2755 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
2756 gui->resize_event(gui->get_w(), gui->get_h());
2759 int CWindowCanvas::get_cwindow_controls()
2761 return mwindow->session->cwindow_controls;