4 * Copyright (C) 2008-2017 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "bcsignals.h"
26 #include "edlsession.h"
29 #include "mainsession.h"
30 #include "mwindowgui.h"
33 #include "playback3d.h"
34 #include "videodevice.h"
39 Canvas::Canvas(MWindow *mwindow,
40 BC_WindowBase *subwindow,
53 this->mwindow = mwindow;
54 this->subwindow = subwindow;
59 this->output_w = output_w;
60 this->output_h = output_h;
61 this->use_scrollbars = use_scrollbars;
62 this->canvas_auxwindow = 0;
63 this->scr_w0 = subwindow->get_screen_w(0, 0);
64 this->root_w = subwindow->get_root_w(0);
65 this->root_h = subwindow->get_root_h(0);
66 canvas_lock = new Condition(1, "Canvas::canvas_lock", 1);
71 if(refresh_frame) delete refresh_frame;
73 if(yscroll) delete yscroll;
74 if(xscroll) delete xscroll;
75 delete canvas_subwindow;
76 delete canvas_fullscreen;
89 canvas_fullscreen = 0;
95 BC_WindowBase *Canvas::lock_canvas(const char *loc)
97 canvas_lock->lock(loc);
98 BC_WindowBase *wdw = get_canvas();
99 if( wdw ) wdw->lock_window(loc);
103 void Canvas::unlock_canvas()
105 BC_WindowBase *wdw = get_canvas();
106 if( wdw ) wdw->unlock_window();
107 canvas_lock->unlock();
110 BC_WindowBase* Canvas::get_canvas()
112 if(get_fullscreen() && canvas_fullscreen)
113 return canvas_fullscreen;
114 return canvas_auxwindow ? canvas_auxwindow : canvas_subwindow;
117 void Canvas::use_auxwindow(BC_WindowBase *aux)
119 canvas_auxwindow = aux;
122 void Canvas::use_cwindow()
124 canvas_menu->use_cwindow();
125 fullscreen_menu->use_cwindow();
128 void Canvas::use_rwindow()
130 canvas_menu->use_rwindow();
133 void Canvas::use_vwindow()
135 canvas_menu->use_vwindow();
138 int Canvas::get_fullscreen()
140 return is_fullscreen;
143 void Canvas::set_fullscreen(int value)
145 is_fullscreen = value;
148 // Get dimensions given a zoom
149 void Canvas::calculate_sizes(float aspect_ratio,
156 // Horizontal stretch
157 if((float)output_w / output_h <= aspect_ratio)
159 w = (int)((float)output_h * aspect_ratio * zoom);
160 h = (int)((float)output_h * zoom);
165 h = (int)((float)output_w / aspect_ratio * zoom);
166 w = (int)((float)output_w * zoom);
170 float Canvas::get_x_offset(EDL *edl,
180 // If the projection is smaller than the canvas, this forces it in the center.
181 // if(conformed_w < w_visible)
182 // return -(float)(w_visible - conformed_w) / 2;
184 return (float)get_xscroll();
187 return ((float)-get_canvas()->get_w() / zoom_x +
188 edl->session->output_w) / 2;
193 int canvas_w = get_canvas()->get_w();
194 int canvas_h = get_canvas()->get_h();
198 if((float)out_w / out_h > conformed_w / conformed_h)
200 out_w = (int)(out_h * conformed_w / conformed_h + 0.5);
204 return -(canvas_w - out_w) / 2 / zoom_x;
210 float Canvas::get_y_offset(EDL *edl,
220 // If the projection is smaller than the canvas, this forces it in the center.
221 // if(conformed_h < h_visible)
222 // return -(float)(h_visible - conformed_h) / 2;
224 return (float)get_yscroll();
227 return ((float)-get_canvas()->get_h() / zoom_y +
228 edl->session->output_h) / 2;
233 int canvas_w = get_canvas()->get_w();
234 int canvas_h = get_canvas()->get_h();
238 if((float)out_w / out_h <= conformed_w / conformed_h)
240 out_h = (int)((float)out_w / (conformed_w / conformed_h) + 0.5);
243 //printf("Canvas::get_y_offset 1 %d %d %f\n", out_h, canvas_h, -((float)canvas_h - out_h) / 2);
245 return -((float)canvas_h - out_h) / 2 / zoom_y;
251 // This may not be used anymore
252 void Canvas::check_boundaries(EDL *edl, int &x, int &y, float &zoom)
254 if(x + w_visible > w_needed) x = w_needed - w_visible;
255 if(y + h_visible > h_needed) y = h_needed - h_visible;
261 void Canvas::update_scrollbars(int flush)
265 if(xscroll) xscroll->update_length(w_needed, get_xscroll(), w_visible, flush);
266 if(yscroll) yscroll->update_length(h_needed, get_yscroll(), h_visible, flush);
270 void Canvas::get_zooms(EDL *edl,
277 edl->calculate_conformed_dimensions(single_channel,
283 zoom_x = get_zoom() *
285 edl->session->output_w;
286 zoom_y = get_zoom() *
288 edl->session->output_h;
293 int canvas_w = get_canvas()->get_w();
294 int canvas_h = get_canvas()->get_h();
299 if((float)out_w / out_h > conformed_w / conformed_h)
301 out_w = (int)((float)out_h * conformed_w / conformed_h + 0.5);
305 out_h = (int)((float)out_w / (conformed_w / conformed_h) + 0.5);
308 zoom_x = (float)out_w / edl->session->output_w;
309 zoom_y = (float)out_h / edl->session->output_h;
310 //printf("get zooms 2 %d %d %f %f\n", canvas_w, canvas_h, conformed_w, conformed_h);
314 // Convert a coordinate on the canvas to a coordinate on the output
315 void Canvas::canvas_to_output(EDL *edl, int single_channel, float &x, float &y)
317 float zoom_x, zoom_y, conformed_w, conformed_h;
318 get_zooms(edl, single_channel, zoom_x, zoom_y, conformed_w, conformed_h);
320 //printf("Canvas::canvas_to_output y=%f zoom_y=%f y_offset=%f\n",
321 // y, zoom_y, get_y_offset(edl, single_channel, zoom_y, conformed_w, conformed_h));
323 x = (float)x / zoom_x + get_x_offset(edl, single_channel, zoom_x, conformed_w, conformed_h);
324 y = (float)y / zoom_y + get_y_offset(edl, single_channel, zoom_y, conformed_w, conformed_h);
327 void Canvas::output_to_canvas(EDL *edl, int single_channel, float &x, float &y)
329 float zoom_x, zoom_y, conformed_w, conformed_h;
330 get_zooms(edl, single_channel, zoom_x, zoom_y, conformed_w, conformed_h);
332 //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));
334 x = (float)zoom_x * (x - get_x_offset(edl, single_channel, zoom_x, conformed_w, conformed_h));
335 y = (float)zoom_y * (y - get_y_offset(edl, single_channel, zoom_y, conformed_w, conformed_h));
340 void Canvas::get_transfers(EDL *edl,
341 float &output_x1, float &output_y1, float &output_x2, float &output_y2,
342 float &canvas_x1, float &canvas_y1, float &canvas_x2, float &canvas_y2,
343 int canvas_w, int canvas_h)
345 //printf("Canvas::get_transfers %d canvas_w=%d canvas_h=%d\n",
346 // __LINE__, canvas_w, canvas_h);
347 // automatic canvas size detection
348 if(canvas_w < 0) canvas_w = get_canvas()->get_w();
349 if(canvas_h < 0) canvas_h = get_canvas()->get_h();
351 // Canvas is zoomed to a portion of the output frame
354 float in_x1, in_y1, in_x2, in_y2;
355 float out_x1, out_y1, out_x2, out_y2;
356 float zoom_x, zoom_y, conformed_w, conformed_h;
358 get_zooms(edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
368 canvas_to_output(edl, 0, in_x1, in_y1);
369 canvas_to_output(edl, 0, in_x2, in_y2);
371 //printf("Canvas::get_transfers 1 %.0f %.0f %.0f %.0f -> %.0f %.0f %.0f %.0f\n",
372 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
376 out_x1 += -in_x1 * zoom_x;
382 out_y1 += -in_y1 * zoom_y;
386 int output_w = get_output_w(edl);
387 int output_h = get_output_h(edl);
391 out_x2 -= (in_x2 - output_w) * zoom_x;
397 out_y2 -= (in_y2 - output_h) * zoom_y;
400 // printf("Canvas::get_transfers 2 %.0f %.0f %.0f %.0f -> %.0f %.0f %.0f %.0f\n",
401 // in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
413 // if(!scrollbars_exist())
415 // out_x = canvas_w / 2 - out_w / 2;
416 // out_y = canvas_h / 2 - out_h / 2;
421 // The output frame is normalized to the canvas
423 // Default canvas coords fill the entire canvas
426 canvas_x2 = canvas_w;
427 canvas_y2 = canvas_h;
431 // Use EDL aspect ratio to shrink one of the canvas dimensions
432 float out_w = canvas_x2 - canvas_x1;
433 float out_h = canvas_y2 - canvas_y1;
434 if(out_w / out_h > edl->get_aspect_ratio())
436 out_w = (int)(out_h * edl->get_aspect_ratio() + 0.5);
437 canvas_x1 = canvas_w / 2 - out_w / 2;
441 out_h = (int)(out_w / edl->get_aspect_ratio() + 0.5);
442 canvas_y1 = canvas_h / 2 - out_h / 2;
443 // printf("Canvas::get_transfers %d canvas_h=%d out_h=%f canvas_y1=%f\n",
449 canvas_x2 = canvas_x1 + out_w;
450 canvas_y2 = canvas_y1 + out_h;
452 // Get output frame coords from EDL
455 output_x2 = get_output_w(edl);
456 output_y2 = get_output_h(edl);
459 // No EDL to get aspect ratio or output frame coords from
463 output_x2 = this->output_w;
464 output_y2 = this->output_h;
468 // Clamp to minimum value
469 output_x1 = MAX(0, output_x1);
470 output_y1 = MAX(0, output_y1);
471 output_x2 = MAX(output_x1, output_x2);
472 output_y2 = MAX(output_y1, output_y2);
473 canvas_x1 = MAX(0, canvas_x1);
474 canvas_y1 = MAX(0, canvas_y1);
475 canvas_x2 = MAX(canvas_x1, canvas_x2);
476 canvas_y2 = MAX(canvas_y1, canvas_y2);
477 // printf("Canvas::get_transfers %d %f,%f %f,%f -> %f,%f %f,%f\n",
489 int Canvas::scrollbars_exist()
491 return(use_scrollbars && (xscroll || yscroll));
494 int Canvas::get_output_w(EDL *edl)
496 return !edl ? 0 : edl->session->output_w;
499 int Canvas::get_output_h(EDL *edl)
501 return !edl ? 0 : edl->session->output_h;
506 void Canvas::get_scrollbars(EDL *edl,
512 int need_xscroll = 0;
513 int need_yscroll = 0;
515 float zoom_x, zoom_y, conformed_w, conformed_h;
519 w_needed = edl->session->output_w;
520 h_needed = edl->session->output_h;
521 w_visible = w_needed;
522 h_visible = h_needed;
524 //printf("Canvas::get_scrollbars 1 %d %d\n", get_xscroll(), get_yscroll());
526 if( use_scrollbars ) {
527 w_needed = edl->session->output_w;
528 h_needed = edl->session->output_h;
529 get_zooms(edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
530 //printf("Canvas::get_scrollbars 2 %d %d\n", get_xscroll(), get_yscroll());
532 w_visible = (int)(canvas_w / zoom_x);
533 h_visible = (int)(canvas_h / zoom_y);
534 if( w_needed > w_visible ) {
536 canvas_h -= BC_ScrollBar::get_span(SCROLL_HORIZ);
539 if( h_needed > h_visible ) {
541 canvas_w -= BC_ScrollBar::get_span(SCROLL_VERT);
543 //printf("Canvas::get_scrollbars %d %d %d %d %d %d\n", canvas_w, canvas_h, w_needed, h_needed, w_visible, h_visible);
544 //printf("Canvas::get_scrollbars 3 %d %d\n", get_xscroll(), get_yscroll());
546 w_visible = (int)(canvas_w / zoom_x);
547 h_visible = (int)(canvas_h / zoom_y);
552 xscroll = new CanvasXScroll(edl, this, canvas_x, canvas_y + canvas_h,
553 w_needed, get_xscroll(), w_visible, canvas_w);
554 subwindow->add_subwindow(xscroll);
555 xscroll->show_window(0);
558 xscroll->reposition_window(canvas_x, canvas_y + canvas_h, canvas_w);
560 if( xscroll->get_length() != w_needed ||
561 xscroll->get_handlelength() != w_visible )
562 xscroll->update_length(w_needed, get_xscroll(), w_visible, 0);
565 delete xscroll; xscroll = 0;
567 //printf("Canvas::get_scrollbars 4 %d %d\n", get_xscroll(), get_yscroll());
571 yscroll = new CanvasYScroll(edl, this, canvas_x + canvas_w, canvas_y,
572 h_needed, get_yscroll(), h_visible, canvas_h);
573 subwindow->add_subwindow(yscroll);
574 yscroll->show_window(0);
577 yscroll->reposition_window(canvas_x + canvas_w, canvas_y, canvas_h);
579 if( yscroll->get_length() != edl->session->output_h ||
580 yscroll->get_handlelength() != h_visible )
581 yscroll->update_length(h_needed, get_yscroll(), h_visible, 0);
584 delete yscroll; yscroll = 0;
586 //printf("Canvas::get_scrollbars 5 %d %d\n", get_xscroll(), get_yscroll());
590 void Canvas::update_geometry(EDL *edl, int x, int y, int w, int h)
593 if( this->x != x || this->y != y ||
594 this->w != w || this->h != h ) redraw = 1;
596 int vx = x, vy = y, vw = w, vh = h;
597 get_scrollbars(edl, vx, vy, vw, vh);
598 if( vx != view_x || vy != view_y ||
599 vw != view_w || vh != view_h ) redraw = 1;
601 if( !redraw ) return;
602 reposition_window(edl, x, y, w, h);
605 void Canvas::reposition_window(EDL *edl, int x, int y, int w, int h)
607 this->x = view_x = x; this->y = view_y = y;
608 this->w = view_w = w; this->h = view_h = h;
609 //printf("Canvas::reposition_window 1\n");
610 get_scrollbars(edl, view_x, view_y, view_w, view_h);
611 //printf("Canvas::reposition_window %d %d %d %d\n", view_x, view_y, view_w, view_h);
614 canvas_subwindow->reposition_window(view_x, view_y, view_w, view_h);
616 // Need to clear out the garbage in the back
617 if(canvas_subwindow->get_video_on())
619 canvas_subwindow->set_color(BLACK);
620 canvas_subwindow->draw_box(0, 0,
621 get_canvas()->get_w(), get_canvas()->get_h());
622 canvas_subwindow->flash(0);
628 // must hold window lock
629 int Canvas::refresh(int flush)
631 BC_WindowBase *window = get_canvas();
632 if( !window ) return 0;
633 // relock in lock order to prevent deadlock
634 window->unlock_window();
635 lock_canvas("Canvas::refresh");
637 canvas_lock->unlock();
640 // must not hold locks
641 int Canvas::redraw(int flush)
643 lock_canvas("Canvas::redraw");
649 void Canvas::set_cursor(int cursor)
651 get_canvas()->set_cursor(cursor, 0, 1);
654 int Canvas::get_cursor_x()
656 return get_canvas()->get_cursor_x();
659 int Canvas::get_cursor_y()
661 return get_canvas()->get_cursor_y();
664 int Canvas::get_buttonpress()
666 return get_canvas()->get_buttonpress();
670 void Canvas::create_objects(EDL *edl)
676 get_scrollbars(edl, view_x, view_y, view_w, view_h);
678 subwindow->unlock_window();
680 subwindow->lock_window("Canvas::create_objects");
682 subwindow->add_subwindow(canvas_menu = new CanvasPopup(this));
683 canvas_menu->create_objects();
685 subwindow->add_subwindow(fullscreen_menu = new CanvasFullScreenPopup(this));
686 fullscreen_menu->create_objects();
690 int Canvas::button_press_event()
694 if(get_canvas()->get_buttonpress() == 3)
697 fullscreen_menu->activate_menu();
699 canvas_menu->activate_menu();
706 void Canvas::start_single()
712 void Canvas::stop_single()
718 void Canvas::start_video()
722 get_canvas()->start_video();
727 void Canvas::stop_video()
731 get_canvas()->stop_video();
737 void Canvas::start_fullscreen()
743 void Canvas::stop_fullscreen()
749 void Canvas::create_canvas()
751 canvas_lock->lock("Canvas::create_canvas");
753 BC_WindowBase *wdw = 0;
754 if( !get_fullscreen() ) {
756 if( canvas_fullscreen ) {
757 canvas_fullscreen->lock_window("Canvas::create_canvas 1");
758 video_on = canvas_fullscreen->get_video_on();
759 if( video_on ) canvas_fullscreen->stop_video();
760 canvas_fullscreen->hide_window();
761 canvas_fullscreen->unlock_window();
763 if( !canvas_auxwindow && !canvas_subwindow ) {
764 subwindow->add_subwindow(canvas_subwindow = new CanvasOutput(this,
765 view_x, view_y, view_w, view_h));
768 wdw->lock_window("Canvas::create_canvas 2");
772 wdw = canvas_auxwindow ? canvas_auxwindow : canvas_subwindow;
773 wdw->lock_window("Canvas::create_canvas 3");
774 video_on = wdw->get_video_on();
775 if( video_on ) wdw->stop_video();
777 wdw->get_fullscreen_geometry(x, y, w, h);
778 wdw->unlock_window();
779 if( canvas_fullscreen ) {
780 if( x != canvas_fullscreen->get_x() ||
781 y != canvas_fullscreen->get_y() ||
782 w != canvas_fullscreen->get_w() ||
783 h != canvas_fullscreen->get_h() ) {
784 delete canvas_fullscreen;
785 canvas_fullscreen = 0;
788 if( !canvas_fullscreen )
789 canvas_fullscreen = new CanvasFullScreen(this, w, h);
790 wdw = canvas_fullscreen;
791 wdw->lock_window("Canvas::create_canvas 4");
794 wdw->reposition_window(x, y);
802 wdw->unlock_window();
803 canvas_lock->unlock();
808 int Canvas::cursor_leave_event_base(BC_WindowBase *caller)
811 if(cursor_inside) result = cursor_leave_event();
816 int Canvas::cursor_enter_event_base(BC_WindowBase *caller)
819 if(caller->is_event_win() && caller->cursor_inside())
822 result = cursor_enter_event();
827 int Canvas::button_press_event_base(BC_WindowBase *caller)
829 if(caller->is_event_win() && caller->cursor_inside())
831 return button_press_event();
836 int Canvas::keypress_event(BC_WindowBase *caller)
838 int key = caller->get_keypress();
841 caller->unlock_window();
846 caller->lock_window("Canvas::keypress_event 1");
849 caller->unlock_window();
852 caller->lock_window("Canvas::keypress_event 2");
860 void Canvas::update_refresh(VideoDevice *device, VFrame *output_frame)
862 int best_color_model = output_frame->get_color_model();
864 device->out_config->driver == PLAYBACK_X11_GL &&
865 output_frame->get_opengl_state() != VFrame::RAM;
867 // OpenGL does YUV->RGB in the compositing step
869 best_color_model = BC_RGB888;
870 else if( BC_CModels::has_alpha(best_color_model) ) {
872 BC_CModels::is_float(best_color_model ) ?
874 BC_CModels::is_yuv(best_color_model ) ?
875 ( BC_CModels::calculate_pixelsize(best_color_model) > 8 ?
876 BC_YUV161616 : BC_YUV888 ) :
877 ( BC_CModels::calculate_pixelsize(best_color_model) > 8 ?
878 BC_RGB161616 : BC_RGB888 ) ;
880 int out_w = output_frame->get_w();
881 int out_h = output_frame->get_h();
883 (refresh_frame->get_w() != out_w ||
884 refresh_frame->get_h() != out_h ||
885 refresh_frame->get_color_model() != best_color_model ) ) {
886 // x11 direct render uses BC_BGR8888, use tranfer_from to remap
887 delete refresh_frame; refresh_frame = 0;
890 if( !refresh_frame ) {
892 new VFrame(out_w, out_h, best_color_model);
897 mwindow->playback_3d->copy_from(this, refresh_frame, output_frame, 0);
898 lock_canvas("Canvas::update_refresh");
901 refresh_frame->transfer_from(output_frame, -1);
904 void Canvas::clear(int flash)
906 BC_WindowBase *cwdw = get_canvas();
908 cwdw->set_bg_color(get_clear_color());
909 cwdw->clear_box(0,0, cwdw->get_w(), cwdw->get_h());
910 if( flash ) cwdw->flash();
914 CanvasOutput::CanvasOutput(Canvas *canvas,
915 int x, int y, int w, int h)
916 : BC_SubWindow(x, y, w, h, BLACK)
918 this->canvas = canvas;
921 CanvasOutput::~CanvasOutput()
925 int CanvasOutput::cursor_leave_event()
927 return canvas->cursor_leave_event_base(canvas->get_canvas());
930 int CanvasOutput::cursor_enter_event()
932 return canvas->cursor_enter_event_base(canvas->get_canvas());
935 int CanvasOutput::button_press_event()
937 return canvas->button_press_event_base(canvas->get_canvas());
940 int CanvasOutput::button_release_event()
942 return canvas->button_release_event();
945 int CanvasOutput::cursor_motion_event()
947 return canvas->cursor_motion_event();
950 int CanvasOutput::keypress_event()
952 return canvas->keypress_event(canvas->get_canvas());
957 CanvasFullScreen::CanvasFullScreen(Canvas *canvas, int w, int h)
958 : BC_FullScreen(canvas->subwindow, w, h, BLACK, 0, 0, 0)
960 this->canvas = canvas;
963 CanvasFullScreen::~CanvasFullScreen()
968 CanvasXScroll::CanvasXScroll(EDL *edl, Canvas *canvas, int x, int y,
969 int length, int position, int handle_length, int pixels)
970 : BC_ScrollBar(x, y, SCROLL_HORIZ, pixels, length, position, handle_length)
972 this->canvas = canvas;
975 CanvasXScroll::~CanvasXScroll()
979 int CanvasXScroll::handle_event()
981 canvas->update_zoom(get_value(), canvas->get_yscroll(), canvas->get_zoom());
982 return canvas->refresh(1);
986 CanvasYScroll::CanvasYScroll(EDL *edl, Canvas *canvas, int x, int y,
987 int length, int position, int handle_length, int pixels)
988 : BC_ScrollBar(x, y, SCROLL_VERT, pixels, length, position, handle_length)
990 this->canvas = canvas;
993 CanvasYScroll::~CanvasYScroll()
997 int CanvasYScroll::handle_event()
999 canvas->update_zoom(canvas->get_xscroll(), get_value(), canvas->get_zoom());
1000 return canvas->refresh(1);
1004 CanvasFullScreenPopup::CanvasFullScreenPopup(Canvas *canvas)
1005 : BC_PopupMenu(0, 0, 0, "", 0)
1007 this->canvas = canvas;
1011 void CanvasFullScreenPopup::create_objects()
1013 add_item(new CanvasSubWindowItem(canvas));
1016 void CanvasFullScreenPopup::use_cwindow()
1018 add_item(new CanvasPopupAuto(canvas));
1021 CanvasSubWindowItem::CanvasSubWindowItem(Canvas *canvas)
1022 : BC_MenuItem(_("Windowed"), "f", 'f')
1024 this->canvas = canvas;
1027 int CanvasSubWindowItem::handle_event()
1029 // It isn't a problem to delete the canvas from in here because the event
1030 // dispatcher is the canvas subwindow.
1031 canvas->subwindow->unlock_window();
1032 canvas->stop_fullscreen();
1033 canvas->subwindow->lock_window("CanvasSubWindowItem::handle_event");
1038 CanvasPopup::CanvasPopup(Canvas *canvas)
1039 : BC_PopupMenu(0, 0, 0, "", 0)
1041 this->canvas = canvas;
1044 CanvasPopup::~CanvasPopup()
1048 CanvasZoomSize::CanvasZoomSize(Canvas *canvas)
1049 : BC_MenuItem(_("Zoom..."))
1051 this->canvas = canvas;
1054 CanvasSizeSubMenu::CanvasSizeSubMenu(CanvasZoomSize *zoom_size)
1056 this->zoom_size = zoom_size;
1059 void CanvasPopup::create_objects()
1061 add_item(new BC_MenuItem("-"));
1062 add_item(new CanvasFullScreenItem(canvas));
1064 CanvasZoomSize *zoom_size = new CanvasZoomSize(canvas);
1065 add_item(zoom_size);
1066 CanvasSizeSubMenu *submenu = new CanvasSizeSubMenu(zoom_size);
1067 zoom_size->add_submenu(submenu);
1069 submenu->add_submenuitem(new CanvasPopupSize(canvas, _("Zoom 25%"), 0.25));
1070 submenu->add_submenuitem(new CanvasPopupSize(canvas, _("Zoom 33%"), 0.33));
1071 submenu->add_submenuitem(new CanvasPopupSize(canvas, _("Zoom 50%"), 0.5));
1072 submenu->add_submenuitem(new CanvasPopupSize(canvas, _("Zoom 75%"), 0.75));
1073 submenu->add_submenuitem(new CanvasPopupSize(canvas, _("Zoom 100%"), 1.0));
1074 submenu->add_submenuitem(new CanvasPopupSize(canvas, _("Zoom 150%"), 1.5));
1075 submenu->add_submenuitem(new CanvasPopupSize(canvas, _("Zoom 200%"), 2.0));
1076 submenu->add_submenuitem(new CanvasPopupSize(canvas, _("Zoom 300%"), 3.0));
1077 submenu->add_submenuitem(new CanvasPopupSize(canvas, _("Zoom 400%"), 4.0));
1080 void CanvasPopup::use_cwindow()
1082 add_item(new CanvasPopupAuto(canvas));
1083 add_item(new CanvasPopupResetCamera(canvas));
1084 add_item(new CanvasPopupResetProjector(canvas));
1085 add_item(new CanvasPopupCameraKeyframe(canvas));
1086 add_item(new CanvasPopupProjectorKeyframe(canvas));
1087 add_item(toggle_controls = new CanvasToggleControls(canvas));
1090 void CanvasPopup::use_rwindow()
1092 add_item(new CanvasPopupResetTranslation(canvas));
1095 void CanvasPopup::use_vwindow()
1097 add_item(new CanvasPopupRemoveSource(canvas));
1101 CanvasPopupAuto::CanvasPopupAuto(Canvas *canvas)
1102 : BC_MenuItem(_("Zoom Auto"))
1104 this->canvas = canvas;
1107 int CanvasPopupAuto::handle_event()
1109 canvas->zoom_auto();
1114 CanvasPopupSize::CanvasPopupSize(Canvas *canvas, char *text, float percentage)
1117 this->canvas = canvas;
1118 this->percentage = percentage;
1120 CanvasPopupSize::~CanvasPopupSize()
1123 int CanvasPopupSize::handle_event()
1125 canvas->zoom_resize_window(percentage);
1130 CanvasPopupResetCamera::CanvasPopupResetCamera(Canvas *canvas)
1131 : BC_MenuItem(_("Reset camera"), _("F11"), KEY_F11)
1133 this->canvas = canvas;
1135 int CanvasPopupResetCamera::handle_event()
1137 canvas->reset_camera();
1141 CanvasPopupResetProjector::CanvasPopupResetProjector(Canvas *canvas)
1142 : BC_MenuItem(_("Reset projector"), _("F12"), KEY_F12)
1144 this->canvas = canvas;
1146 int CanvasPopupResetProjector::handle_event()
1148 canvas->reset_projector();
1153 CanvasPopupCameraKeyframe::CanvasPopupCameraKeyframe(Canvas *canvas)
1154 : BC_MenuItem(_("Camera keyframe"), _("Shift-F11"), KEY_F11)
1156 this->canvas = canvas;
1159 int CanvasPopupCameraKeyframe::handle_event()
1161 canvas->camera_keyframe();
1165 CanvasPopupProjectorKeyframe::CanvasPopupProjectorKeyframe(Canvas *canvas)
1166 : BC_MenuItem(_("Projector keyframe"), _("Shift-F12"), KEY_F12)
1168 this->canvas = canvas;
1171 int CanvasPopupProjectorKeyframe::handle_event()
1173 canvas->projector_keyframe();
1179 CanvasPopupResetTranslation::CanvasPopupResetTranslation(Canvas *canvas)
1180 : BC_MenuItem(_("Reset translation"))
1182 this->canvas = canvas;
1184 int CanvasPopupResetTranslation::handle_event()
1186 canvas->reset_translation();
1192 CanvasToggleControls::CanvasToggleControls(Canvas *canvas)
1193 : BC_MenuItem(calculate_text(canvas->get_cwindow_controls()))
1195 this->canvas = canvas;
1197 int CanvasToggleControls::handle_event()
1199 canvas->toggle_controls();
1200 set_text(calculate_text(canvas->get_cwindow_controls()));
1204 char* CanvasToggleControls::calculate_text(int cwindow_controls)
1206 if(!cwindow_controls)
1207 return _("Show controls");
1209 return _("Hide controls");
1218 CanvasFullScreenItem::CanvasFullScreenItem(Canvas *canvas)
1219 : BC_MenuItem(_("Fullscreen"), "f", 'f')
1221 this->canvas = canvas;
1223 int CanvasFullScreenItem::handle_event()
1225 canvas->subwindow->unlock_window();
1226 canvas->start_fullscreen();
1227 canvas->subwindow->lock_window("CanvasFullScreenItem::handle_event");
1239 CanvasPopupRemoveSource::CanvasPopupRemoveSource(Canvas *canvas)
1240 : BC_MenuItem(_("Close source"))
1242 this->canvas = canvas;
1244 int CanvasPopupRemoveSource::handle_event()
1246 canvas->close_source();