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;
54 // Get dimensions given a zoom
55 void Canvas::calculate_sizes(float aspect_ratio,
63 if((float)output_w / output_h <= aspect_ratio)
65 w = (int)((float)output_h * aspect_ratio * zoom + 1);
66 h = (int)((float)output_h * zoom + 1);
71 h = (int)((float)output_w / aspect_ratio * zoom + 1);
72 w = (int)((float)output_w * zoom + 1);
76 float Canvas::get_x_offset(EDL *edl,
86 if(conformed_w < w_visible)
87 return -(float)(w_visible - conformed_w) / 2;
89 return (float)get_xscroll();
92 return ((float)-canvas->get_w() / zoom_x +
93 edl->calculate_output_w(single_channel)) / 2;
98 int canvas_w = canvas->get_w();
99 int canvas_h = canvas->get_h();
103 if((float)out_w / out_h > conformed_w / conformed_h)
105 out_w = (int)(out_h * conformed_w / conformed_h + 0.5);
109 return -(canvas_w - out_w) / 2 / zoom_x;
115 float Canvas::get_y_offset(EDL *edl,
125 if(conformed_h < h_visible)
126 return -(float)(h_visible - conformed_h) / 2;
128 return (float)get_yscroll();
131 return ((float)-canvas->get_h() / zoom_y +
132 edl->calculate_output_h(single_channel)) / 2;
137 int canvas_w = canvas->get_w();
138 int canvas_h = canvas->get_h();
142 if((float)out_w / out_h <= conformed_w / conformed_h)
144 out_h = (int)((float)out_w / (conformed_w / conformed_h) + 0.5);
147 //printf("Canvas::get_y_offset 1 %d %d %f\n", out_h, canvas_h, -((float)canvas_h - out_h) / 2);
149 return -((float)canvas_h - out_h) / 2 / zoom_y;
155 // This may not be used anymore
156 void Canvas::check_boundaries(EDL *edl, int &x, int &y, float &zoom)
158 if(x + w_visible > w_needed) x = w_needed - w_visible;
159 if(y + h_visible > h_needed) y = h_needed - h_visible;
165 void Canvas::update_scrollbars()
169 if(xscroll) xscroll->update_length(w_needed, get_xscroll(), w_visible);
170 if(yscroll) yscroll->update_length(h_needed, get_yscroll(), h_visible);
174 void Canvas::get_zooms(EDL *edl,
181 edl->calculate_conformed_dimensions(single_channel,
187 zoom_x = get_zoom() *
189 edl->calculate_output_w(single_channel);
190 zoom_y = get_zoom() *
192 edl->calculate_output_h(single_channel);
197 int canvas_w = canvas->get_w();
198 int canvas_h = canvas->get_h();
203 if((float)out_w / out_h > conformed_w / conformed_h)
205 out_w = (int)((float)out_h * conformed_w / conformed_h + 0.5);
209 out_h = (int)((float)out_w / (conformed_w / conformed_h) + 0.5);
212 zoom_x = (float)out_w / edl->calculate_output_w(single_channel);
213 zoom_y = (float)out_h / edl->calculate_output_h(single_channel);
214 //printf("get zooms 2 %d %d %f %f\n", canvas_w, canvas_h, conformed_w, conformed_h);
218 // Convert a coordinate on the canvas to a coordinate on the output
219 void Canvas::canvas_to_output(EDL *edl, int single_channel, float &x, float &y)
221 float zoom_x, zoom_y, conformed_w, conformed_h;
222 get_zooms(edl, single_channel, zoom_x, zoom_y, conformed_w, conformed_h);
224 //printf("Canvas::canvas_to_output y=%f zoom_y=%f y_offset=%f\n",
225 // y, zoom_y, get_y_offset(edl, single_channel, zoom_y, conformed_w, conformed_h));
227 x = (float)x / zoom_x + get_x_offset(edl, single_channel, zoom_x, conformed_w, conformed_h);
228 y = (float)y / zoom_y + get_y_offset(edl, single_channel, zoom_y, conformed_w, conformed_h);
231 void Canvas::output_to_canvas(EDL *edl, int single_channel, float &x, float &y)
233 float zoom_x, zoom_y, conformed_w, conformed_h;
234 get_zooms(edl, single_channel, zoom_x, zoom_y, conformed_w, conformed_h);
236 //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));
238 x = (float)zoom_x * (x - get_x_offset(edl, single_channel, zoom_x, conformed_w, conformed_h));
239 y = (float)zoom_y * (y - get_y_offset(edl, single_channel, zoom_y, conformed_w, conformed_h));
244 void Canvas::get_transfers(EDL *edl,
256 // printf("Canvas::get_transfers %d %d\n", canvas_w,
258 if(canvas_w < 0) canvas_w = canvas->get_w();
259 if(canvas_h < 0) canvas_h = canvas->get_h();
263 float in_x1, in_y1, in_x2, in_y2;
264 float out_x1, out_y1, out_x2, out_y2;
265 float zoom_x, zoom_y, conformed_w, conformed_h;
267 get_zooms(edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
277 canvas_to_output(edl, 0, in_x1, in_y1);
278 canvas_to_output(edl, 0, in_x2, in_y2);
280 // printf("Canvas::get_transfers 1 %.0f %.0f %.0f %.0f -> %.0f %.0f %.0f %.0f\n",
281 // in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
285 out_x1 += -in_x1 * zoom_x;
291 out_y1 += -in_y1 * zoom_y;
295 int output_w = get_output_w(edl);
296 int output_h = get_output_h(edl);
300 out_x2 -= (in_x2 - output_w) * zoom_x;
306 out_y2 -= (in_y2 - output_h) * zoom_y;
309 // printf("Canvas::get_transfers 2 %.0f %.0f %.0f %.0f -> %.0f %.0f %.0f %.0f\n",
310 // in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
314 in_w = (int)(in_x2 - in_x1);
315 in_h = (int)(in_y2 - in_y1);
318 out_w = (int)(out_x2 - out_x1);
319 out_h = (int)(out_y2 - out_y1);
322 // if(!scrollbars_exist())
324 // out_x = canvas_w / 2 - out_w / 2;
325 // out_y = canvas_h / 2 - out_h / 2;
328 // printf("Canvas::get_transfers 2 %d %d %d %d -> %d %d %d %d\n",in_x,
346 if((float)out_w / out_h > edl->get_aspect_ratio())
348 out_w = (int)(out_h * edl->get_aspect_ratio() + 0.5);
349 out_x = canvas_w / 2 - out_w / 2;
353 out_h = (int)(out_w / edl->get_aspect_ratio() + 0.5);
354 out_y = canvas_h / 2 - out_h / 2;
358 in_w = get_output_w(edl);
359 in_h = get_output_h(edl);
365 in_w = this->output_w;
366 in_h = this->output_h;
374 out_x = MAX(0, out_x);
375 out_y = MAX(0, out_y);
376 out_w = MAX(0, out_w);
377 out_h = MAX(0, out_h);
380 int Canvas::scrollbars_exist()
382 return(use_scrollbars && (xscroll || yscroll));
385 int Canvas::get_output_w(EDL *edl)
388 return edl->calculate_output_w(0);
390 return edl->session->output_w;
393 int Canvas::get_output_h(EDL *edl)
398 return edl->calculate_output_h(0);
400 return edl->session->output_h;
406 void Canvas::get_scrollbars(EDL *edl,
412 int need_xscroll = 0;
413 int need_yscroll = 0;
415 float zoom_x, zoom_y, conformed_w, conformed_h;
419 w_needed = edl->calculate_output_w(0);
420 h_needed = edl->calculate_output_h(0);
421 w_visible = w_needed;
422 h_visible = h_needed;
424 //printf("Canvas::get_scrollbars 1 %d %d\n", get_xscroll(), get_yscroll());
428 w_needed = edl->calculate_output_w(0);
429 h_needed = edl->calculate_output_h(0);
430 get_zooms(edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
431 //printf("Canvas::get_scrollbars 2 %d %d\n", get_xscroll(), get_yscroll());
435 w_visible = (int)(canvas_w / zoom_x);
436 h_visible = (int)(canvas_h / zoom_y);
439 // if(w_needed > w_visible)
445 canvas_h -= BC_ScrollBar::get_span(SCROLL_HORIZ);
452 // if(h_needed > h_visible)
458 canvas_w -= BC_ScrollBar::get_span(SCROLL_VERT);
465 //printf("Canvas::get_scrollbars %d %d %d %d %d %d\n", canvas_w, canvas_h, w_needed, h_needed, w_visible, h_visible);
466 //printf("Canvas::get_scrollbars 3 %d %d\n", get_xscroll(), get_yscroll());
468 w_visible = (int)(canvas_w / zoom_x);
469 h_visible = (int)(canvas_h / zoom_y);
475 subwindow->add_subwindow(xscroll = new CanvasXScroll(edl,
484 xscroll->reposition_window(canvas_x, canvas_y + canvas_h, canvas_w);
486 if(xscroll->get_length() != w_needed ||
487 xscroll->get_handlelength() != w_visible)
488 xscroll->update_length(w_needed, get_xscroll(), w_visible);
492 if(xscroll) delete xscroll;
495 //printf("Canvas::get_scrollbars 4 %d %d\n", get_xscroll(), get_yscroll());
500 subwindow->add_subwindow(yscroll = new CanvasYScroll(edl,
509 yscroll->reposition_window(canvas_x + canvas_w, canvas_y, canvas_h);
511 if(yscroll->get_length() != edl->calculate_output_h(0) ||
512 yscroll->get_handlelength() != h_visible)
513 yscroll->update_length(h_needed, get_yscroll(), h_visible);
517 if(yscroll) delete yscroll;
520 //printf("Canvas::get_scrollbars 5 %d %d\n", get_xscroll(), get_yscroll());
523 void Canvas::reposition_window(EDL *edl, int x, int y, int w, int h)
529 int view_x = x, view_y = y, view_w = w, view_h = h;
530 //printf("Canvas::reposition_window 1\n");
531 get_scrollbars(edl, view_x, view_y, view_w, view_h);
532 //printf("Canvas::reposition_window %d %d %d %d\n", view_x, view_y, view_w, view_h);
533 canvas->reposition_window(view_x, view_y, view_w, view_h);
535 //printf("Canvas::reposition_window 2\n");
538 void Canvas::set_cursor(int cursor)
540 canvas->set_cursor(cursor);
543 int Canvas::get_cursor_x()
545 return canvas->get_cursor_x();
548 int Canvas::get_cursor_y()
550 return canvas->get_cursor_y();
553 int Canvas::get_buttonpress()
555 return canvas->get_buttonpress();
559 int Canvas::create_objects(EDL *edl)
561 int view_x = x, view_y = y, view_w = w, view_h = h;
562 get_scrollbars(edl, view_x, view_y, view_w, view_h);
564 subwindow->add_subwindow(canvas = new CanvasOutput(edl,
571 subwindow->add_subwindow(canvas_menu = new CanvasPopup(this));
572 canvas_menu->create_objects();
577 int Canvas::button_press_event()
581 if(canvas->get_buttonpress() == 3)
583 canvas_menu->activate_menu();
593 CanvasOutput::CanvasOutput(EDL *edl,
599 : BC_SubWindow(x, y, w, h, BLACK)
601 this->canvas = canvas;
605 CanvasOutput::~CanvasOutput()
609 int CanvasOutput::handle_event()
614 int CanvasOutput::cursor_leave_event()
617 if(cursor_inside) result = canvas->cursor_leave_event();
622 int CanvasOutput::cursor_enter_event()
625 if(is_event_win() && BC_WindowBase::cursor_inside())
628 result = canvas->cursor_enter_event();
633 int CanvasOutput::button_press_event()
635 if(is_event_win() && BC_WindowBase::cursor_inside())
637 return canvas->button_press_event();
642 int CanvasOutput::button_release_event()
644 return canvas->button_release_event();
647 int CanvasOutput::cursor_motion_event()
649 return canvas->cursor_motion_event();
654 CanvasXScroll::CanvasXScroll(EDL *edl,
670 this->canvas = canvas;
673 CanvasXScroll::~CanvasXScroll()
677 int CanvasXScroll::handle_event()
679 //printf("CanvasXScroll::handle_event %d %d %d\n", get_length(), get_value(), get_handlelength());
680 canvas->update_zoom(get_value(), canvas->get_yscroll(), canvas->get_zoom());
681 canvas->draw_refresh();
690 CanvasYScroll::CanvasYScroll(EDL *edl,
706 this->canvas = canvas;
709 CanvasYScroll::~CanvasYScroll()
713 int CanvasYScroll::handle_event()
715 //printf("CanvasYScroll::handle_event %d %d\n", get_value(), get_length());
716 canvas->update_zoom(canvas->get_xscroll(), get_value(), canvas->get_zoom());
717 canvas->draw_refresh();
724 CanvasPopup::CanvasPopup(Canvas *canvas)
731 this->canvas = canvas;
734 CanvasPopup::~CanvasPopup()
738 void CanvasPopup::create_objects()
740 add_item(new CanvasPopupSize(canvas, _("Zoom 25%"), 0.25));
741 add_item(new CanvasPopupSize(canvas, _("Zoom 50%"), 0.5));
742 add_item(new CanvasPopupSize(canvas, _("Zoom 100%"), 1.0));
743 add_item(new CanvasPopupSize(canvas, _("Zoom 200%"), 2.0));
744 if(canvas->use_cwindow)
746 add_item(new CanvasPopupResetCamera(canvas));
747 add_item(new CanvasPopupResetProjector(canvas));
749 if(canvas->use_rwindow)
751 add_item(new CanvasPopupResetTranslation(canvas));
753 if(canvas->use_vwindow)
755 add_item(new CanvasPopupRemoveSource(canvas));
761 CanvasPopupSize::CanvasPopupSize(Canvas *canvas, char *text, float percentage)
764 this->canvas = canvas;
765 this->percentage = percentage;
767 CanvasPopupSize::~CanvasPopupSize()
770 int CanvasPopupSize::handle_event()
772 canvas->zoom_resize_window(percentage);
778 CanvasPopupResetCamera::CanvasPopupResetCamera(Canvas *canvas)
779 : BC_MenuItem(_("Reset camera"))
781 this->canvas = canvas;
783 int CanvasPopupResetCamera::handle_event()
785 canvas->reset_camera();
791 CanvasPopupResetProjector::CanvasPopupResetProjector(Canvas *canvas)
792 : BC_MenuItem(_("Reset projector"))
794 this->canvas = canvas;
796 int CanvasPopupResetProjector::handle_event()
798 canvas->reset_projector();
804 CanvasPopupResetTranslation::CanvasPopupResetTranslation(Canvas *canvas)
805 : BC_MenuItem(_("Reset translation"))
807 this->canvas = canvas;
809 int CanvasPopupResetTranslation::handle_event()
811 canvas->reset_translation();
818 CanvasPopupRemoveSource::CanvasPopupRemoveSource(Canvas *canvas)
819 : BC_MenuItem(_("Close source"))
821 this->canvas = canvas;
823 int CanvasPopupRemoveSource::handle_event()
825 canvas->close_source();