4 #include "edlsession.h"
10 Canvas::Canvas(BC_WindowBase *subwindow,
23 this->subwindow = subwindow;
28 this->output_w = output_w;
29 this->output_h = output_h;
30 this->use_scrollbars = use_scrollbars;
31 this->use_cwindow = use_cwindow;
32 this->use_rwindow = use_rwindow;
33 this->use_vwindow = use_vwindow;
38 if(refresh_frame) delete refresh_frame;
40 if(yscroll) delete yscroll;
41 if(xscroll) delete xscroll;
57 // Get dimensions given a zoom
58 void Canvas::calculate_sizes(float aspect_ratio,
66 if((float)output_w / output_h <= aspect_ratio)
68 w = (int)((float)output_h * aspect_ratio * zoom);
69 h = (int)((float)output_h * zoom);
74 h = (int)((float)output_w / aspect_ratio * zoom);
75 w = (int)((float)output_w * zoom);
79 float Canvas::get_x_offset(EDL *edl,
89 // If the projection is smaller than the canvas, this forces it in the center.
90 // if(conformed_w < w_visible)
91 // return -(float)(w_visible - conformed_w) / 2;
93 return (float)get_xscroll();
96 return ((float)-canvas->get_w() / zoom_x +
97 edl->calculate_output_w(single_channel)) / 2;
102 int canvas_w = canvas->get_w();
103 int canvas_h = canvas->get_h();
107 if((float)out_w / out_h > conformed_w / conformed_h)
109 out_w = (int)(out_h * conformed_w / conformed_h + 0.5);
113 return -(canvas_w - out_w) / 2 / zoom_x;
119 float Canvas::get_y_offset(EDL *edl,
129 // If the projection is smaller than the canvas, this forces it in the center.
130 // if(conformed_h < h_visible)
131 // return -(float)(h_visible - conformed_h) / 2;
133 return (float)get_yscroll();
136 return ((float)-canvas->get_h() / zoom_y +
137 edl->calculate_output_h(single_channel)) / 2;
142 int canvas_w = canvas->get_w();
143 int canvas_h = canvas->get_h();
147 if((float)out_w / out_h <= conformed_w / conformed_h)
149 out_h = (int)((float)out_w / (conformed_w / conformed_h) + 0.5);
152 //printf("Canvas::get_y_offset 1 %d %d %f\n", out_h, canvas_h, -((float)canvas_h - out_h) / 2);
154 return -((float)canvas_h - out_h) / 2 / zoom_y;
160 // This may not be used anymore
161 void Canvas::check_boundaries(EDL *edl, int &x, int &y, float &zoom)
163 if(x + w_visible > w_needed) x = w_needed - w_visible;
164 if(y + h_visible > h_needed) y = h_needed - h_visible;
170 void Canvas::update_scrollbars()
174 if(xscroll) xscroll->update_length(w_needed, get_xscroll(), w_visible);
175 if(yscroll) yscroll->update_length(h_needed, get_yscroll(), h_visible);
179 void Canvas::get_zooms(EDL *edl,
186 edl->calculate_conformed_dimensions(single_channel,
192 zoom_x = get_zoom() *
194 edl->calculate_output_w(single_channel);
195 zoom_y = get_zoom() *
197 edl->calculate_output_h(single_channel);
202 int canvas_w = canvas->get_w();
203 int canvas_h = canvas->get_h();
208 if((float)out_w / out_h > conformed_w / conformed_h)
210 out_w = (int)((float)out_h * conformed_w / conformed_h + 0.5);
214 out_h = (int)((float)out_w / (conformed_w / conformed_h) + 0.5);
217 zoom_x = (float)out_w / edl->calculate_output_w(single_channel);
218 zoom_y = (float)out_h / edl->calculate_output_h(single_channel);
219 //printf("get zooms 2 %d %d %f %f\n", canvas_w, canvas_h, conformed_w, conformed_h);
223 // Convert a coordinate on the canvas to a coordinate on the output
224 void Canvas::canvas_to_output(EDL *edl, int single_channel, float &x, float &y)
226 float zoom_x, zoom_y, conformed_w, conformed_h;
227 get_zooms(edl, single_channel, zoom_x, zoom_y, conformed_w, conformed_h);
229 //printf("Canvas::canvas_to_output y=%f zoom_y=%f y_offset=%f\n",
230 // y, zoom_y, get_y_offset(edl, single_channel, zoom_y, conformed_w, conformed_h));
232 x = (float)x / zoom_x + get_x_offset(edl, single_channel, zoom_x, conformed_w, conformed_h);
233 y = (float)y / zoom_y + get_y_offset(edl, single_channel, zoom_y, conformed_w, conformed_h);
236 void Canvas::output_to_canvas(EDL *edl, int single_channel, float &x, float &y)
238 float zoom_x, zoom_y, conformed_w, conformed_h;
239 get_zooms(edl, single_channel, zoom_x, zoom_y, conformed_w, conformed_h);
241 //printf("Canvas::output_to_canvas x=%f zoom_x=%f x_offset=%f\n", x, zoom_x, get_x_offset(edl, single_channel, zoom_x, conformed_w));
243 x = (float)zoom_x * (x - get_x_offset(edl, single_channel, zoom_x, conformed_w, conformed_h));
244 y = (float)zoom_y * (y - get_y_offset(edl, single_channel, zoom_y, conformed_w, conformed_h));
249 void Canvas::get_transfers(EDL *edl,
261 // printf("Canvas::get_transfers %d %d\n", canvas_w,
263 if(canvas_w < 0) canvas_w = canvas->get_w();
264 if(canvas_h < 0) canvas_h = canvas->get_h();
268 float in_x1, in_y1, in_x2, in_y2;
269 float out_x1, out_y1, out_x2, out_y2;
270 float zoom_x, zoom_y, conformed_w, conformed_h;
272 get_zooms(edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
282 canvas_to_output(edl, 0, in_x1, in_y1);
283 canvas_to_output(edl, 0, in_x2, in_y2);
285 //printf("Canvas::get_transfers 1 %.0f %.0f %.0f %.0f -> %.0f %.0f %.0f %.0f\n",
286 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
290 out_x1 += -in_x1 * zoom_x;
296 out_y1 += -in_y1 * zoom_y;
300 int output_w = get_output_w(edl);
301 int output_h = get_output_h(edl);
305 out_x2 -= (in_x2 - output_w) * zoom_x;
311 out_y2 -= (in_y2 - output_h) * zoom_y;
314 // printf("Canvas::get_transfers 2 %.0f %.0f %.0f %.0f -> %.0f %.0f %.0f %.0f\n",
315 // in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
319 in_w = (int)(in_x2 - in_x1);
320 in_h = (int)(in_y2 - in_y1);
323 out_w = (int)(out_x2 - out_x1);
324 out_h = (int)(out_y2 - out_y1);
327 // if(!scrollbars_exist())
329 // out_x = canvas_w / 2 - out_w / 2;
330 // out_y = canvas_h / 2 - out_h / 2;
333 // printf("Canvas::get_transfers 2 %d %d %d %d -> %d %d %d %d\n",in_x,
351 if((float)out_w / out_h > edl->get_aspect_ratio())
353 out_w = (int)(out_h * edl->get_aspect_ratio() + 0.5);
354 out_x = canvas_w / 2 - out_w / 2;
358 out_h = (int)(out_w / edl->get_aspect_ratio() + 0.5);
359 out_y = canvas_h / 2 - out_h / 2;
363 in_w = get_output_w(edl);
364 in_h = get_output_h(edl);
370 in_w = this->output_w;
371 in_h = this->output_h;
379 out_x = MAX(0, out_x);
380 out_y = MAX(0, out_y);
381 out_w = MAX(0, out_w);
382 out_h = MAX(0, out_h);
385 int Canvas::scrollbars_exist()
387 return(use_scrollbars && (xscroll || yscroll));
390 int Canvas::get_output_w(EDL *edl)
393 return edl->calculate_output_w(0);
395 return edl->session->output_w;
398 int Canvas::get_output_h(EDL *edl)
403 return edl->calculate_output_h(0);
405 return edl->session->output_h;
411 void Canvas::get_scrollbars(EDL *edl,
417 int need_xscroll = 0;
418 int need_yscroll = 0;
420 float zoom_x, zoom_y, conformed_w, conformed_h;
424 w_needed = edl->calculate_output_w(0);
425 h_needed = edl->calculate_output_h(0);
426 w_visible = w_needed;
427 h_visible = h_needed;
429 //printf("Canvas::get_scrollbars 1 %d %d\n", get_xscroll(), get_yscroll());
433 w_needed = edl->calculate_output_w(0);
434 h_needed = edl->calculate_output_h(0);
435 get_zooms(edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
436 //printf("Canvas::get_scrollbars 2 %d %d\n", get_xscroll(), get_yscroll());
440 w_visible = (int)(canvas_w / zoom_x);
441 h_visible = (int)(canvas_h / zoom_y);
444 // if(w_needed > w_visible)
450 canvas_h -= BC_ScrollBar::get_span(SCROLL_HORIZ);
457 // if(h_needed > h_visible)
463 canvas_w -= BC_ScrollBar::get_span(SCROLL_VERT);
470 //printf("Canvas::get_scrollbars %d %d %d %d %d %d\n", canvas_w, canvas_h, w_needed, h_needed, w_visible, h_visible);
471 //printf("Canvas::get_scrollbars 3 %d %d\n", get_xscroll(), get_yscroll());
473 w_visible = (int)(canvas_w / zoom_x);
474 h_visible = (int)(canvas_h / zoom_y);
480 subwindow->add_subwindow(xscroll = new CanvasXScroll(edl,
489 xscroll->reposition_window(canvas_x, canvas_y + canvas_h, canvas_w);
491 if(xscroll->get_length() != w_needed ||
492 xscroll->get_handlelength() != w_visible)
493 xscroll->update_length(w_needed, get_xscroll(), w_visible);
497 if(xscroll) delete xscroll;
500 //printf("Canvas::get_scrollbars 4 %d %d\n", get_xscroll(), get_yscroll());
505 subwindow->add_subwindow(yscroll = new CanvasYScroll(edl,
514 yscroll->reposition_window(canvas_x + canvas_w, canvas_y, canvas_h);
516 if(yscroll->get_length() != edl->calculate_output_h(0) ||
517 yscroll->get_handlelength() != h_visible)
518 yscroll->update_length(h_needed, get_yscroll(), h_visible);
522 if(yscroll) delete yscroll;
525 //printf("Canvas::get_scrollbars 5 %d %d\n", get_xscroll(), get_yscroll());
528 void Canvas::reposition_window(EDL *edl, int x, int y, int w, int h)
534 int view_x = x, view_y = y, view_w = w, view_h = h;
535 //printf("Canvas::reposition_window 1\n");
536 get_scrollbars(edl, view_x, view_y, view_w, view_h);
537 //printf("Canvas::reposition_window %d %d %d %d\n", view_x, view_y, view_w, view_h);
538 canvas->reposition_window(view_x, view_y, view_w, view_h);
540 // Need to clear out the garbage in the back
541 if(canvas->video_is_on())
543 canvas->set_color(BLACK);
544 canvas->draw_box(0, 0, canvas->get_w(), canvas->get_h());
551 //printf("Canvas::reposition_window 2\n");
554 void Canvas::set_cursor(int cursor)
556 canvas->set_cursor(cursor);
559 int Canvas::get_cursor_x()
561 return canvas->get_cursor_x();
564 int Canvas::get_cursor_y()
566 return canvas->get_cursor_y();
569 int Canvas::get_buttonpress()
571 return canvas->get_buttonpress();
575 int Canvas::create_objects(EDL *edl)
577 int view_x = x, view_y = y, view_w = w, view_h = h;
578 get_scrollbars(edl, view_x, view_y, view_w, view_h);
580 subwindow->add_subwindow(canvas = new CanvasOutput(edl,
587 subwindow->add_subwindow(canvas_menu = new CanvasPopup(this));
588 canvas_menu->create_objects();
593 int Canvas::button_press_event()
597 if(canvas->get_buttonpress() == 3)
599 canvas_menu->activate_menu();
606 void Canvas::start_single()
612 void Canvas::stop_single()
618 void Canvas::start_video()
622 canvas->start_video();
627 void Canvas::stop_video()
631 canvas->stop_video();
654 CanvasOutput::CanvasOutput(EDL *edl,
660 : BC_SubWindow(x, y, w, h, 0)
662 this->canvas = canvas;
666 CanvasOutput::~CanvasOutput()
670 int CanvasOutput::handle_event()
675 int CanvasOutput::cursor_leave_event()
678 if(cursor_inside) result = canvas->cursor_leave_event();
683 int CanvasOutput::cursor_enter_event()
686 if(is_event_win() && BC_WindowBase::cursor_inside())
689 result = canvas->cursor_enter_event();
694 int CanvasOutput::button_press_event()
696 if(is_event_win() && BC_WindowBase::cursor_inside())
698 return canvas->button_press_event();
703 int CanvasOutput::button_release_event()
705 return canvas->button_release_event();
708 int CanvasOutput::cursor_motion_event()
710 return canvas->cursor_motion_event();
715 CanvasXScroll::CanvasXScroll(EDL *edl,
731 this->canvas = canvas;
734 CanvasXScroll::~CanvasXScroll()
738 int CanvasXScroll::handle_event()
740 //printf("CanvasXScroll::handle_event %d %d %d\n", get_length(), get_value(), get_handlelength());
741 canvas->update_zoom(get_value(), canvas->get_yscroll(), canvas->get_zoom());
742 canvas->draw_refresh();
751 CanvasYScroll::CanvasYScroll(EDL *edl,
767 this->canvas = canvas;
770 CanvasYScroll::~CanvasYScroll()
774 int CanvasYScroll::handle_event()
776 //printf("CanvasYScroll::handle_event %d %d\n", get_value(), get_length());
777 canvas->update_zoom(canvas->get_xscroll(), get_value(), canvas->get_zoom());
778 canvas->draw_refresh();
785 CanvasPopup::CanvasPopup(Canvas *canvas)
792 this->canvas = canvas;
795 CanvasPopup::~CanvasPopup()
799 void CanvasPopup::create_objects()
801 add_item(new CanvasPopupSize(canvas, _("Zoom 25%"), 0.25));
802 add_item(new CanvasPopupSize(canvas, _("Zoom 50%"), 0.5));
803 add_item(new CanvasPopupSize(canvas, _("Zoom 100%"), 1.0));
804 add_item(new CanvasPopupSize(canvas, _("Zoom 200%"), 2.0));
805 if(canvas->use_cwindow)
807 add_item(new CanvasPopupResetCamera(canvas));
808 add_item(new CanvasPopupResetProjector(canvas));
809 add_item(toggle_controls = new CanvasToggleControls(canvas));
811 if(canvas->use_rwindow)
813 add_item(new CanvasPopupResetTranslation(canvas));
815 if(canvas->use_vwindow)
817 add_item(new CanvasPopupRemoveSource(canvas));
823 CanvasPopupSize::CanvasPopupSize(Canvas *canvas, char *text, float percentage)
826 this->canvas = canvas;
827 this->percentage = percentage;
829 CanvasPopupSize::~CanvasPopupSize()
832 int CanvasPopupSize::handle_event()
834 canvas->zoom_resize_window(percentage);
840 CanvasPopupResetCamera::CanvasPopupResetCamera(Canvas *canvas)
841 : BC_MenuItem(_("Reset camera"))
843 this->canvas = canvas;
845 int CanvasPopupResetCamera::handle_event()
847 canvas->reset_camera();
853 CanvasPopupResetProjector::CanvasPopupResetProjector(Canvas *canvas)
854 : BC_MenuItem(_("Reset projector"))
856 this->canvas = canvas;
858 int CanvasPopupResetProjector::handle_event()
860 canvas->reset_projector();
866 CanvasPopupResetTranslation::CanvasPopupResetTranslation(Canvas *canvas)
867 : BC_MenuItem(_("Reset translation"))
869 this->canvas = canvas;
871 int CanvasPopupResetTranslation::handle_event()
873 canvas->reset_translation();
879 CanvasToggleControls::CanvasToggleControls(Canvas *canvas)
880 : BC_MenuItem(calculate_text(canvas->get_cwindow_controls()))
882 this->canvas = canvas;
884 int CanvasToggleControls::handle_event()
886 canvas->toggle_controls();
887 set_text(calculate_text(canvas->get_cwindow_controls()));
891 char* CanvasToggleControls::calculate_text(int cwindow_controls)
893 if(!cwindow_controls)
894 return _("Show controls");
896 return _("Hide controls");
902 CanvasPopupRemoveSource::CanvasPopupRemoveSource(Canvas *canvas)
903 : BC_MenuItem(_("Close source"))
905 this->canvas = canvas;
907 int CanvasPopupRemoveSource::handle_event()
909 canvas->close_source();