4 #include "edlsession.h"
8 #define _(String) gettext(String)
9 #define gettext_noop(String) String
10 #define N_(String) gettext_noop (String)
13 Canvas::Canvas(BC_WindowBase *subwindow,
26 this->subwindow = subwindow;
31 this->output_w = output_w;
32 this->output_h = output_h;
33 this->use_scrollbars = use_scrollbars;
34 this->use_cwindow = use_cwindow;
35 this->use_rwindow = use_rwindow;
36 this->use_vwindow = use_vwindow;
41 if(refresh_frame) delete refresh_frame;
43 if(yscroll) delete yscroll;
44 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 + 1);
69 h = (int)((float)output_h * zoom + 1);
74 h = (int)((float)output_w / aspect_ratio * zoom + 1);
75 w = (int)((float)output_w * zoom + 1);
79 float Canvas::get_x_offset(EDL *edl,
89 if(conformed_w < w_visible)
90 return -(float)(w_visible - conformed_w) / 2;
92 return (float)get_xscroll();
95 return ((float)-canvas->get_w() / zoom_x +
96 edl->calculate_output_w(single_channel)) / 2;
101 int canvas_w = canvas->get_w();
102 int canvas_h = canvas->get_h();
106 if((float)out_w / out_h > conformed_w / conformed_h)
108 out_w = (int)(out_h * conformed_w / conformed_h + 0.5);
112 return -(canvas_w - out_w) / 2 / zoom_x;
118 float Canvas::get_y_offset(EDL *edl,
128 if(conformed_h < h_visible)
129 return -(float)(h_visible - conformed_h) / 2;
131 return (float)get_yscroll();
134 return ((float)-canvas->get_h() / zoom_y +
135 edl->calculate_output_h(single_channel)) / 2;
140 int canvas_w = canvas->get_w();
141 int canvas_h = canvas->get_h();
145 if((float)out_w / out_h <= conformed_w / conformed_h)
147 out_h = (int)((float)out_w / (conformed_w / conformed_h) + 0.5);
150 //printf("Canvas::get_y_offset 1 %d %d %f\n", out_h, canvas_h, -((float)canvas_h - out_h) / 2);
152 return -((float)canvas_h - out_h) / 2 / zoom_y;
158 // This may not be used anymore
159 void Canvas::check_boundaries(EDL *edl, int &x, int &y, float &zoom)
161 if(x + w_visible > w_needed) x = w_needed - w_visible;
162 if(y + h_visible > h_needed) y = h_needed - h_visible;
168 void Canvas::update_scrollbars()
172 if(xscroll) xscroll->update_length(w_needed, get_xscroll(), w_visible);
173 if(yscroll) yscroll->update_length(h_needed, get_yscroll(), h_visible);
177 void Canvas::get_zooms(EDL *edl,
184 edl->calculate_conformed_dimensions(single_channel,
190 zoom_x = get_zoom() *
192 edl->calculate_output_w(single_channel);
193 zoom_y = get_zoom() *
195 edl->calculate_output_h(single_channel);
200 int canvas_w = canvas->get_w();
201 int canvas_h = canvas->get_h();
206 if((float)out_w / out_h > conformed_w / conformed_h)
208 out_w = (int)((float)out_h * conformed_w / conformed_h + 0.5);
212 out_h = (int)((float)out_w / (conformed_w / conformed_h) + 0.5);
215 zoom_x = (float)out_w / edl->calculate_output_w(single_channel);
216 zoom_y = (float)out_h / edl->calculate_output_h(single_channel);
217 //printf("get zooms 2 %d %d %f %f\n", canvas_w, canvas_h, conformed_w, conformed_h);
221 // Convert a coordinate on the canvas to a coordinate on the output
222 void Canvas::canvas_to_output(EDL *edl, int single_channel, float &x, float &y)
224 float zoom_x, zoom_y, conformed_w, conformed_h;
225 get_zooms(edl, single_channel, zoom_x, zoom_y, conformed_w, conformed_h);
227 //printf("Canvas::canvas_to_output y=%f zoom_y=%f y_offset=%f\n",
228 // y, zoom_y, get_y_offset(edl, single_channel, zoom_y, conformed_w, conformed_h));
230 x = (float)x / zoom_x + get_x_offset(edl, single_channel, zoom_x, conformed_w, conformed_h);
231 y = (float)y / zoom_y + get_y_offset(edl, single_channel, zoom_y, conformed_w, conformed_h);
234 void Canvas::output_to_canvas(EDL *edl, int single_channel, float &x, float &y)
236 float zoom_x, zoom_y, conformed_w, conformed_h;
237 get_zooms(edl, single_channel, zoom_x, zoom_y, conformed_w, conformed_h);
239 //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));
241 x = (float)zoom_x * (x - get_x_offset(edl, single_channel, zoom_x, conformed_w, conformed_h));
242 y = (float)zoom_y * (y - get_y_offset(edl, single_channel, zoom_y, conformed_w, conformed_h));
247 void Canvas::get_transfers(EDL *edl,
259 // printf("Canvas::get_transfers %d %d\n", canvas_w,
261 if(canvas_w < 0) canvas_w = canvas->get_w();
262 if(canvas_h < 0) canvas_h = canvas->get_h();
266 float in_x1, in_y1, in_x2, in_y2;
267 float out_x1, out_y1, out_x2, out_y2;
268 float zoom_x, zoom_y, conformed_w, conformed_h;
270 get_zooms(edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
280 canvas_to_output(edl, 0, in_x1, in_y1);
281 canvas_to_output(edl, 0, in_x2, in_y2);
283 // printf("Canvas::get_transfers 1 %.0f %.0f %.0f %.0f -> %.0f %.0f %.0f %.0f\n",
284 // in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
288 out_x1 += -in_x1 * zoom_x;
294 out_y1 += -in_y1 * zoom_y;
298 int output_w = get_output_w(edl);
299 int output_h = get_output_h(edl);
303 out_x2 -= (in_x2 - output_w) * zoom_x;
309 out_y2 -= (in_y2 - output_h) * zoom_y;
312 // printf("Canvas::get_transfers 2 %.0f %.0f %.0f %.0f -> %.0f %.0f %.0f %.0f\n",
313 // in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
317 in_w = (int)(in_x2 - in_x1);
318 in_h = (int)(in_y2 - in_y1);
321 out_w = (int)(out_x2 - out_x1);
322 out_h = (int)(out_y2 - out_y1);
325 // if(!scrollbars_exist())
327 // out_x = canvas_w / 2 - out_w / 2;
328 // out_y = canvas_h / 2 - out_h / 2;
331 // printf("Canvas::get_transfers 2 %d %d %d %d -> %d %d %d %d\n",in_x,
349 if((float)out_w / out_h > edl->get_aspect_ratio())
351 out_w = (int)(out_h * edl->get_aspect_ratio() + 0.5);
352 out_x = canvas_w / 2 - out_w / 2;
356 out_h = (int)(out_w / edl->get_aspect_ratio() + 0.5);
357 out_y = canvas_h / 2 - out_h / 2;
361 in_w = get_output_w(edl);
362 in_h = get_output_h(edl);
368 in_w = this->output_w;
369 in_h = this->output_h;
377 out_x = MAX(0, out_x);
378 out_y = MAX(0, out_y);
379 out_w = MAX(0, out_w);
380 out_h = MAX(0, out_h);
383 int Canvas::scrollbars_exist()
385 return(use_scrollbars && (xscroll || yscroll));
388 int Canvas::get_output_w(EDL *edl)
391 return edl->calculate_output_w(0);
393 return edl->session->output_w;
396 int Canvas::get_output_h(EDL *edl)
401 return edl->calculate_output_h(0);
403 return edl->session->output_h;
409 void Canvas::get_scrollbars(EDL *edl,
415 int need_xscroll = 0;
416 int need_yscroll = 0;
418 float zoom_x, zoom_y, conformed_w, conformed_h;
422 w_needed = edl->calculate_output_w(0);
423 h_needed = edl->calculate_output_h(0);
424 w_visible = w_needed;
425 h_visible = h_needed;
427 //printf("Canvas::get_scrollbars 1 %d %d\n", get_xscroll(), get_yscroll());
431 w_needed = edl->calculate_output_w(0);
432 h_needed = edl->calculate_output_h(0);
433 get_zooms(edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
434 //printf("Canvas::get_scrollbars 2 %d %d\n", get_xscroll(), get_yscroll());
438 w_visible = (int)(canvas_w / zoom_x);
439 h_visible = (int)(canvas_h / zoom_y);
442 // if(w_needed > w_visible)
448 canvas_h -= BC_ScrollBar::get_span(SCROLL_HORIZ);
455 // if(h_needed > h_visible)
461 canvas_w -= BC_ScrollBar::get_span(SCROLL_VERT);
468 //printf("Canvas::get_scrollbars %d %d %d %d %d %d\n", canvas_w, canvas_h, w_needed, h_needed, w_visible, h_visible);
469 //printf("Canvas::get_scrollbars 3 %d %d\n", get_xscroll(), get_yscroll());
471 w_visible = (int)(canvas_w / zoom_x);
472 h_visible = (int)(canvas_h / zoom_y);
478 subwindow->add_subwindow(xscroll = new CanvasXScroll(edl,
487 xscroll->reposition_window(canvas_x, canvas_y + canvas_h, canvas_w);
489 if(xscroll->get_length() != w_needed ||
490 xscroll->get_handlelength() != w_visible)
491 xscroll->update_length(w_needed, get_xscroll(), w_visible);
495 if(xscroll) delete xscroll;
498 //printf("Canvas::get_scrollbars 4 %d %d\n", get_xscroll(), get_yscroll());
503 subwindow->add_subwindow(yscroll = new CanvasYScroll(edl,
512 yscroll->reposition_window(canvas_x + canvas_w, canvas_y, canvas_h);
514 if(yscroll->get_length() != edl->calculate_output_h(0) ||
515 yscroll->get_handlelength() != h_visible)
516 yscroll->update_length(h_needed, get_yscroll(), h_visible);
520 if(yscroll) delete yscroll;
523 //printf("Canvas::get_scrollbars 5 %d %d\n", get_xscroll(), get_yscroll());
526 void Canvas::reposition_window(EDL *edl, int x, int y, int w, int h)
532 int view_x = x, view_y = y, view_w = w, view_h = h;
533 //printf("Canvas::reposition_window 1\n");
534 get_scrollbars(edl, view_x, view_y, view_w, view_h);
535 //printf("Canvas::reposition_window %d %d %d %d\n", view_x, view_y, view_w, view_h);
536 canvas->reposition_window(view_x, view_y, view_w, view_h);
538 //printf("Canvas::reposition_window 2\n");
541 void Canvas::set_cursor(int cursor)
543 canvas->set_cursor(cursor);
546 int Canvas::get_cursor_x()
548 return canvas->get_cursor_x();
551 int Canvas::get_cursor_y()
553 return canvas->get_cursor_y();
556 int Canvas::get_buttonpress()
558 return canvas->get_buttonpress();
562 int Canvas::create_objects(EDL *edl)
564 int view_x = x, view_y = y, view_w = w, view_h = h;
565 get_scrollbars(edl, view_x, view_y, view_w, view_h);
567 subwindow->add_subwindow(canvas = new CanvasOutput(edl,
574 subwindow->add_subwindow(canvas_menu = new CanvasPopup(this));
575 canvas_menu->create_objects();
580 int Canvas::button_press_event()
584 if(canvas->get_buttonpress() == 3)
586 canvas_menu->activate_menu();
596 CanvasOutput::CanvasOutput(EDL *edl,
602 : BC_SubWindow(x, y, w, h, BLACK)
604 this->canvas = canvas;
608 CanvasOutput::~CanvasOutput()
612 int CanvasOutput::handle_event()
617 int CanvasOutput::cursor_leave_event()
620 if(cursor_inside) result = canvas->cursor_leave_event();
625 int CanvasOutput::cursor_enter_event()
628 if(is_event_win() && BC_WindowBase::cursor_inside())
631 result = canvas->cursor_enter_event();
636 int CanvasOutput::button_press_event()
638 if(is_event_win() && BC_WindowBase::cursor_inside())
640 return canvas->button_press_event();
645 int CanvasOutput::button_release_event()
647 return canvas->button_release_event();
650 int CanvasOutput::cursor_motion_event()
652 return canvas->cursor_motion_event();
657 CanvasXScroll::CanvasXScroll(EDL *edl,
673 this->canvas = canvas;
676 CanvasXScroll::~CanvasXScroll()
680 int CanvasXScroll::handle_event()
682 //printf("CanvasXScroll::handle_event %d %d %d\n", get_length(), get_value(), get_handlelength());
683 canvas->update_zoom(get_value(), canvas->get_yscroll(), canvas->get_zoom());
684 canvas->draw_refresh();
693 CanvasYScroll::CanvasYScroll(EDL *edl,
709 this->canvas = canvas;
712 CanvasYScroll::~CanvasYScroll()
716 int CanvasYScroll::handle_event()
718 //printf("CanvasYScroll::handle_event %d %d\n", get_value(), get_length());
719 canvas->update_zoom(canvas->get_xscroll(), get_value(), canvas->get_zoom());
720 canvas->draw_refresh();
727 CanvasPopup::CanvasPopup(Canvas *canvas)
734 this->canvas = canvas;
737 CanvasPopup::~CanvasPopup()
741 void CanvasPopup::create_objects()
743 add_item(new CanvasPopupSize(canvas, _("Zoom 25%"), 0.25));
744 add_item(new CanvasPopupSize(canvas, _("Zoom 50%"), 0.5));
745 add_item(new CanvasPopupSize(canvas, _("Zoom 100%"), 1.0));
746 add_item(new CanvasPopupSize(canvas, _("Zoom 200%"), 2.0));
747 if(canvas->use_cwindow)
749 add_item(new CanvasPopupResetCamera(canvas));
750 add_item(new CanvasPopupResetProjector(canvas));
752 if(canvas->use_rwindow)
754 add_item(new CanvasPopupResetTranslation(canvas));
756 if(canvas->use_vwindow)
758 add_item(new CanvasPopupRemoveSource(canvas));
764 CanvasPopupSize::CanvasPopupSize(Canvas *canvas, char *text, float percentage)
767 this->canvas = canvas;
768 this->percentage = percentage;
770 CanvasPopupSize::~CanvasPopupSize()
773 int CanvasPopupSize::handle_event()
775 canvas->zoom_resize_window(percentage);
781 CanvasPopupResetCamera::CanvasPopupResetCamera(Canvas *canvas)
782 : BC_MenuItem(_("Reset camera"))
784 this->canvas = canvas;
786 int CanvasPopupResetCamera::handle_event()
788 canvas->reset_camera();
794 CanvasPopupResetProjector::CanvasPopupResetProjector(Canvas *canvas)
795 : BC_MenuItem(_("Reset projector"))
797 this->canvas = canvas;
799 int CanvasPopupResetProjector::handle_event()
801 canvas->reset_projector();
807 CanvasPopupResetTranslation::CanvasPopupResetTranslation(Canvas *canvas)
808 : BC_MenuItem(_("Reset translation"))
810 this->canvas = canvas;
812 int CanvasPopupResetTranslation::handle_event()
814 canvas->reset_translation();
821 CanvasPopupRemoveSource::CanvasPopupRemoveSource(Canvas *canvas)
822 : BC_MenuItem(_("Close source"))
824 this->canvas = canvas;
826 int CanvasPopupRemoveSource::handle_event()
828 canvas->close_source();