4 * Copyright (C) 1997-2014 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 "automation.h"
24 #include "bcsignals.h"
28 #include "cplayback.h"
31 #include "cwindowgui.h"
33 #include "cwindowtool.h"
34 #include "editpanel.h"
36 #include "edlsession.h"
37 #include "floatauto.h"
38 #include "floatautos.h"
41 #include "localsession.h"
42 #include "mainclock.h"
45 #include "mainsession.h"
47 #include "maskautos.h"
49 #include "meterpanel.h"
50 #include "mwindowgui.h"
53 #include "playback3d.h"
54 #include "playtransport.h"
56 #include "trackcanvas.h"
58 #include "transportque.h"
62 static double my_zoom_table[] =
75 static int total_zooms = sizeof(my_zoom_table) / sizeof(double);
78 CWindowGUI::CWindowGUI(MWindow *mwindow, CWindow *cwindow)
79 : BC_Window(_(PROGRAM_NAME ": Compositor"),
80 mwindow->session->cwindow_x,
81 mwindow->session->cwindow_y,
82 mwindow->session->cwindow_w,
83 mwindow->session->cwindow_h,
89 BC_WindowBase::get_resources()->bg_color,
90 mwindow->get_cwindow_display())
92 this->mwindow = mwindow;
93 this->cwindow = cwindow;
95 affected_x = affected_y = affected_z = 0;
97 orig_mask_keyframe = new MaskAuto(0, 0);
99 x_offset = y_offset = 0;
100 x_origin = y_origin = 0;
101 current_operation = CWINDOW_NONE;
105 crop_handle = -1; crop_translate = 0;
106 crop_origin_x = crop_origin_y = 0;
107 crop_origin_x1 = crop_origin_y1 = 0;
108 crop_origin_x2 = crop_origin_y2 = 0;
110 eyedrop_x = eyedrop_y = 0;
111 ruler_origin_x = ruler_origin_y = 0;
112 ruler_handle = -1; ruler_translate = 0;
113 center_x = center_y = center_z = 0;
114 control_in_x = control_in_y = 0;
115 control_out_x = control_out_y = 0;
116 translating_zoom = 0;
120 CWindowGUI::~CWindowGUI()
122 if(tool_panel) delete tool_panel;
124 delete composite_panel;
131 delete orig_mask_keyframe;
134 void CWindowGUI::create_objects()
136 lock_window("CWindowGUI::create_objects");
137 set_icon(mwindow->theme->get_image("cwindow_icon"));
139 active = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_active"));
140 inactive = new BC_Pixmap(this, mwindow->theme->get_image("cwindow_inactive"));
142 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
143 mwindow->theme->draw_cwindow_bg(this);
146 // Meters required by composite panel
147 meters = new CWindowMeters(mwindow,
149 mwindow->theme->cmeter_x,
150 mwindow->theme->cmeter_y,
151 mwindow->theme->cmeter_h);
152 meters->create_objects();
155 composite_panel = new CPanel(mwindow,
157 mwindow->theme->ccomposite_x,
158 mwindow->theme->ccomposite_y,
159 mwindow->theme->ccomposite_w,
160 mwindow->theme->ccomposite_h);
161 composite_panel->create_objects();
163 canvas = new CWindowCanvas(mwindow, this);
165 canvas->create_objects(mwindow->edl);
166 canvas->use_cwindow();
169 add_subwindow(timebar = new CTimeBar(mwindow,
171 mwindow->theme->ctimebar_x,
172 mwindow->theme->ctimebar_y,
173 mwindow->theme->ctimebar_w,
174 mwindow->theme->ctimebar_h));
175 timebar->create_objects();
178 add_subwindow(slider = new CWindowSlider(mwindow,
180 mwindow->theme->cslider_x,
181 mwindow->theme->cslider_y,
182 mwindow->theme->cslider_w));
185 transport = new CWindowTransport(mwindow,
187 mwindow->theme->ctransport_x,
188 mwindow->theme->ctransport_y);
189 transport->create_objects();
191 transport->set_slider(slider);
194 edit_panel = new CWindowEditing(mwindow, cwindow);
195 edit_panel->set_meters(meters);
196 edit_panel->create_objects();
198 // add_subwindow(clock = new MainClock(mwindow,
199 // mwindow->theme->ctime_x,
200 // mwindow->theme->ctime_y));
202 zoom_panel = new CWindowZoom(mwindow,
204 mwindow->theme->czoom_x,
205 mwindow->theme->czoom_y,
206 mwindow->theme->czoom_w);
207 zoom_panel->create_objects();
208 zoom_panel->zoom_text->add_item(new BC_MenuItem(auto_zoom = _(AUTO_ZOOM)));
209 if( !mwindow->edl->session->cwindow_scrollbars )
210 zoom_panel->set_text(auto_zoom);
212 // destination = new CWindowDestination(mwindow,
214 // mwindow->theme->cdest_x,
215 // mwindow->theme->cdest_y);
216 // destination->create_objects();
218 // Must create after meter panel
219 tool_panel = new CWindowTool(mwindow, this);
220 tool_panel->Thread::start();
223 set_operation(mwindow->edl->session->cwindow_operation);
227 canvas->draw_refresh(0);
234 int CWindowGUI::translation_event()
236 mwindow->session->cwindow_x = get_x();
237 mwindow->session->cwindow_y = get_y();
241 int CWindowGUI::resize_event(int w, int h)
243 mwindow->session->cwindow_x = get_x();
244 mwindow->session->cwindow_y = get_y();
245 mwindow->session->cwindow_w = w;
246 mwindow->session->cwindow_h = h;
248 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
249 mwindow->theme->draw_cwindow_bg(this);
252 composite_panel->reposition_buttons(mwindow->theme->ccomposite_x,
253 mwindow->theme->ccomposite_y, mwindow->theme->ccomposite_h);
255 canvas->reposition_window(mwindow->edl,
256 mwindow->theme->ccanvas_x,
257 mwindow->theme->ccanvas_y,
258 mwindow->theme->ccanvas_w,
259 mwindow->theme->ccanvas_h);
261 timebar->resize_event();
264 slider->reposition_window(mwindow->theme->cslider_x,
265 mwindow->theme->cslider_y,
266 mwindow->theme->cslider_w);
267 // Recalibrate pointer motion range
268 slider->set_position();
271 transport->reposition_buttons(mwindow->theme->ctransport_x,
272 mwindow->theme->ctransport_y);
274 edit_panel->reposition_buttons(mwindow->theme->cedit_x,
275 mwindow->theme->cedit_y);
277 // clock->reposition_window(mwindow->theme->ctime_x,
278 // mwindow->theme->ctime_y);
280 zoom_panel->reposition_window(mwindow->theme->czoom_x,
281 mwindow->theme->czoom_y);
283 // destination->reposition_window(mwindow->theme->cdest_x,
284 // mwindow->theme->cdest_y);
286 meters->reposition_window(mwindow->theme->cmeter_x,
287 mwindow->theme->cmeter_y,
289 mwindow->theme->cmeter_h);
293 BC_WindowBase::resize_event(w, h);
297 int CWindowGUI::button_press_event()
299 if( current_operation == CWINDOW_NONE &&
300 mwindow->edl != 0 && canvas->get_canvas() &&
301 canvas->get_canvas()->get_cursor_over_window() ) {
302 switch( get_buttonpress() ) {
304 if( !cwindow->playback_engine->is_playing_back ) {
305 double length = mwindow->edl->tracks->total_playable_length();
306 double position = cwindow->playback_engine->get_tracking_position();
307 if( position >= length ) transport->goto_start();
309 return transport->forward_play->handle_event();
311 if( !cwindow->playback_engine->is_playing_back ) {
312 double position = cwindow->playback_engine->get_tracking_position();
313 if( position <= 0 ) transport->goto_end();
315 return transport->reverse_play->handle_event();
316 case RIGHT_BUTTON: // activates popup
319 return transport->frame_forward_play->handle_event();
321 return transport->frame_reverse_play->handle_event();
324 if(canvas->get_canvas())
325 return canvas->button_press_event_base(canvas->get_canvas());
329 int CWindowGUI::cursor_leave_event()
331 if(canvas->get_canvas())
332 return canvas->cursor_leave_event_base(canvas->get_canvas());
336 int CWindowGUI::cursor_enter_event()
338 if(canvas->get_canvas())
339 return canvas->cursor_enter_event_base(canvas->get_canvas());
343 int CWindowGUI::button_release_event()
345 if(canvas->get_canvas())
346 return canvas->button_release_event();
350 int CWindowGUI::cursor_motion_event()
352 if(canvas->get_canvas())
354 canvas->get_canvas()->unhide_cursor();
355 return canvas->cursor_motion_event();
366 void CWindowGUI::draw_status(int flush)
368 if( (canvas->get_canvas() && canvas->get_canvas()->get_video_on()) ||
369 canvas->is_processing )
372 mwindow->theme->cstatus_x,
373 mwindow->theme->cstatus_y);
377 draw_pixmap(inactive,
378 mwindow->theme->cstatus_x,
379 mwindow->theme->cstatus_y);
383 // printf("CWindowGUI::draw_status %d %d %d\n", __LINE__, mwindow->theme->cstatus_x,
384 // mwindow->theme->cstatus_y);
385 flash(mwindow->theme->cstatus_x,
386 mwindow->theme->cstatus_y,
392 float CWindowGUI::get_auto_zoom()
394 float conformed_w, conformed_h;
395 mwindow->edl->calculate_conformed_dimensions(0, conformed_w, conformed_h);
396 float zoom_x = canvas->w / conformed_w;
397 float zoom_y = canvas->h / conformed_h;
398 return zoom_x < zoom_y ? zoom_x : zoom_y;
401 void CWindowGUI::zoom_canvas(double value, int update_menu)
404 float zoom = !value ? get_auto_zoom() : value;
405 mwindow->edl->session->cwindow_scrollbars = !value ? 0 : 1;
407 float cx = canvas->get_xscroll() + 0.5f*canvas->w_visible;
408 float cy = canvas->get_yscroll() + 0.5f*canvas->h_visible;
409 float output_x = cx, output_y = cy;
410 canvas->output_to_canvas(mwindow->edl, 0, cx, cy);
411 x = output_x - cx / zoom;
412 y = output_y - cy / zoom;
414 canvas->update_zoom((int)(x+0.5), (int)(y+0.5), zoom);
417 zoom_panel->update(value);
418 if( mwindow->edl->session->cwindow_operation == CWINDOW_ZOOM )
419 composite_panel->cpanel_zoom->update(zoom);
421 canvas->reposition_window(mwindow->edl,
422 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
423 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
424 canvas->draw_refresh();
429 void CWindowGUI::set_operation(int value)
431 mwindow->edl->session->cwindow_operation = value;
433 composite_panel->set_operation(value);
434 edit_panel->update();
436 tool_panel->start_tool(value);
437 canvas->draw_refresh();
440 void CWindowGUI::update_tool()
442 tool_panel->update_values();
445 int CWindowGUI::close_event()
447 cwindow->hide_window();
452 int CWindowGUI::keypress_event()
456 switch(get_keypress())
474 if(mwindow->session->cwindow_fullscreen)
475 canvas->stop_fullscreen();
477 canvas->start_fullscreen();
478 lock_window("CWindowGUI::keypress_event 1");
482 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
484 mwindow->gui->unlock_window();
485 lock_window("CWindowGUI::keypress_event 2");
489 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
490 mwindow->clear_entry();
491 mwindow->gui->unlock_window();
492 lock_window("CWindowGUI::keypress_event 3");
496 if(mwindow->session->cwindow_fullscreen)
497 canvas->stop_fullscreen();
498 lock_window("CWindowGUI::keypress_event 4");
502 int alt_down = this->alt_down();
503 int shift_down = this->shift_down();
506 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
508 mwindow->prev_edit_handle(shift_down);
510 mwindow->move_left();
511 mwindow->gui->unlock_window();
512 lock_window("CWindowGUI::keypress_event 2");
518 int alt_down = this->alt_down();
519 int shift_down = this->shift_down();
522 mwindow->gui->lock_window("CWindowGUI::keypress_event 2");
524 mwindow->next_edit_handle(shift_down);
526 mwindow->move_right();
527 mwindow->gui->unlock_window();
528 lock_window("CWindowGUI::keypress_event 2");
534 if(!result) result = transport->keypress_event();
540 void CWindowGUI::reset_affected()
547 void CWindowGUI::keyboard_zoomin()
549 // if(mwindow->edl->session->cwindow_scrollbars)
551 zoom_panel->zoom_tumbler->handle_up_event();
558 void CWindowGUI::keyboard_zoomout()
560 // if(mwindow->edl->session->cwindow_scrollbars)
562 zoom_panel->zoom_tumbler->handle_down_event();
570 void CWindowGUI::drag_motion()
572 if(get_hidden()) return;
574 if(mwindow->session->current_operation != DRAG_ASSET &&
575 mwindow->session->current_operation != DRAG_VTRANSITION &&
576 mwindow->session->current_operation != DRAG_VEFFECT) return;
577 int need_highlight = cursor_above() && get_cursor_over_window();
578 if( highlighted == need_highlight ) return;
579 highlighted = need_highlight;
580 canvas->draw_refresh();
583 int CWindowGUI::drag_stop()
586 if(get_hidden()) return 0;
587 if( !highlighted ) return 0;
588 if( mwindow->session->current_operation != DRAG_ASSET &&
589 mwindow->session->current_operation != DRAG_VTRANSITION &&
590 mwindow->session->current_operation != DRAG_VEFFECT) return 0;
592 canvas->draw_refresh();
595 if(mwindow->session->current_operation == DRAG_ASSET)
597 if(mwindow->session->drag_assets->total ||
598 mwindow->session->drag_clips->total)
600 mwindow->gui->lock_window("CWindowGUI::drag_stop 5");
601 mwindow->undo->update_undo_before(_("insert assets"), 0);
602 mwindow->gui->unlock_window();
605 if(mwindow->session->drag_assets->total)
607 mwindow->gui->lock_window("CWindowGUI::drag_stop 1");
609 mwindow->load_assets(mwindow->session->drag_assets,
610 mwindow->edl->local_session->get_selectionstart(),
612 mwindow->session->track_highlighted,
614 mwindow->edl->session->labels_follow_edits,
615 mwindow->edl->session->plugins_follow_edits,
616 mwindow->edl->session->autos_follow_edits,
620 if(mwindow->session->drag_clips->total)
622 mwindow->gui->lock_window("CWindowGUI::drag_stop 2");
624 mwindow->paste_edls(mwindow->session->drag_clips,
626 mwindow->session->track_highlighted,
627 mwindow->edl->local_session->get_selectionstart(),
628 mwindow->edl->session->labels_follow_edits,
629 mwindow->edl->session->plugins_follow_edits,
630 mwindow->edl->session->autos_follow_edits,
634 if(mwindow->session->drag_assets->total ||
635 mwindow->session->drag_clips->total)
637 mwindow->save_backup();
638 mwindow->restart_brender();
639 mwindow->gui->update(1, 1, 1, 1, 0, 1, 0);
640 mwindow->undo->update_undo_after(_("insert assets"), LOAD_ALL);
641 mwindow->gui->unlock_window();
642 mwindow->sync_parameters(LOAD_ALL);
646 if(mwindow->session->current_operation == DRAG_VEFFECT)
648 //printf("CWindowGUI::drag_stop 1\n");
649 Track *affected_track = cwindow->calculate_affected_track();
650 //printf("CWindowGUI::drag_stop 2\n");
652 mwindow->gui->lock_window("CWindowGUI::drag_stop 3");
653 mwindow->insert_effects_cwindow(affected_track);
654 mwindow->session->current_operation = NO_OPERATION;
655 mwindow->gui->unlock_window();
658 if(mwindow->session->current_operation == DRAG_VTRANSITION)
660 Track *affected_track = cwindow->calculate_affected_track();
661 mwindow->gui->lock_window("CWindowGUI::drag_stop 4");
662 mwindow->paste_transition_cwindow(affected_track);
663 mwindow->session->current_operation = NO_OPERATION;
664 mwindow->gui->unlock_window();
670 void CWindowGUI::update_meters()
672 if(mwindow->edl->session->cwindow_meter != meters->visible)
674 meters->set_meters(meters->meter_count, mwindow->edl->session->cwindow_meter);
675 mwindow->theme->get_cwindow_sizes(this, mwindow->session->cwindow_controls);
676 resize_event(get_w(), get_h());
680 void CWindowGUI::stop_transport(const char *lock_msg)
682 if( lock_msg ) unlock_window();
683 mwindow->stop_transport();
684 if( lock_msg ) lock_window(lock_msg);
688 CWindowEditing::CWindowEditing(MWindow *mwindow, CWindow *cwindow)
691 mwindow->theme->cedit_x,
692 mwindow->theme->cedit_y,
693 mwindow->edl->session->editing_mode,
712 this->mwindow = mwindow;
713 this->cwindow = cwindow;
716 #define CWrapper(fn) void CWindowEditing::fn() { \
717 mwindow->gui->lock_window("CWrapper::" #fn); \
719 mwindow->gui->unlock_window(); \
722 CWrapper(copy_selection)
723 CWrapper(splice_selection)
724 CWrapper(overwrite_selection)
725 CWrapper(set_inpoint)
726 CWrapper(set_outpoint)
727 CWrapper(unset_inoutpoint)
728 CWrapper(toggle_label)
734 void CWindowEditing::to_clip()
736 mwindow->to_clip(mwindow->edl, _("composer window: "));
740 CWindowMeters::CWindowMeters(MWindow *mwindow,
745 : MeterPanel(mwindow,
751 mwindow->edl->session->audio_channels,
752 mwindow->edl->session->cwindow_meter,
756 this->mwindow = mwindow;
760 CWindowMeters::~CWindowMeters()
764 int CWindowMeters::change_status_event(int new_status)
766 mwindow->edl->session->cwindow_meter = new_status;
767 gui->update_meters();
774 CWindowZoom::CWindowZoom(MWindow *mwindow, CWindowGUI *gui, int x, int y, int w)
775 : ZoomPanel(mwindow, gui, (double)mwindow->edl->session->cwindow_zoom,
776 x, y, w, my_zoom_table, total_zooms, ZOOM_PERCENTAGE)
778 this->mwindow = mwindow;
782 CWindowZoom::~CWindowZoom()
786 void CWindowZoom::update(double value)
788 char string[BCSTRLEN];
789 const char *cp = string;
792 int frac = value >= 1.0f ? 1 :
794 value >= .01f ? 3 : 4;
795 sprintf(string, "x %.*f", frac, value);
799 ZoomPanel::update(cp);
802 int CWindowZoom::handle_event()
804 double value = !strcasecmp(gui->auto_zoom, get_text()) ? 0 : get_value();
805 gui->zoom_canvas(value, 0);
812 CWindowSlider::CWindowSlider(MWindow *mwindow, CWindow *cwindow, int x, int y, int pixels)
813 : BC_PercentageSlider(x,
822 this->mwindow = mwindow;
823 this->cwindow = cwindow;
824 set_precision(0.00001);
827 CWindowSlider::~CWindowSlider()
831 int CWindowSlider::handle_event()
833 cwindow->update_position((double)get_value());
837 void CWindowSlider::set_position()
839 double new_length = mwindow->edl->tracks->total_length();
840 // if(mwindow->edl->local_session->preview_end <= 0 ||
841 // mwindow->edl->local_session->preview_end > new_length)
842 // mwindow->edl->local_session->preview_end = new_length;
843 // if(mwindow->edl->local_session->preview_start >
844 // mwindow->edl->local_session->preview_end)
845 // mwindow->edl->local_session->preview_start = 0;
848 update(mwindow->theme->cslider_w,
849 mwindow->edl->local_session->get_selectionstart(1),
852 // mwindow->edl->local_session->preview_start,
853 // mwindow->edl->local_session->preview_end);
857 int CWindowSlider::increase_value()
860 cwindow->gui->transport->handle_transport(SINGLE_FRAME_FWD);
861 lock_window("CWindowSlider::increase_value");
865 int CWindowSlider::decrease_value()
868 cwindow->gui->transport->handle_transport(SINGLE_FRAME_REWIND);
869 lock_window("CWindowSlider::decrease_value");
874 // CWindowDestination::CWindowDestination(MWindow *mwindow, CWindowGUI *cwindow, int x, int y)
875 // : BC_PopupTextBox(cwindow,
876 // &cwindow->destinations,
877 // cwindow->destinations.values[cwindow->cwindow->destination]->get_text(),
883 // this->mwindow = mwindow;
884 // this->cwindow = cwindow;
887 // CWindowDestination::~CWindowDestination()
891 // int CWindowDestination::handle_event()
902 CWindowTransport::CWindowTransport(MWindow *mwindow,
906 : PlayTransport(mwindow,
914 EDL* CWindowTransport::get_edl()
919 void CWindowTransport::goto_start()
921 gui->unlock_window();
922 handle_transport(REWIND, 1);
924 mwindow->gui->lock_window("CWindowTransport::goto_start 1");
925 mwindow->goto_start();
926 mwindow->gui->unlock_window();
928 gui->lock_window("CWindowTransport::goto_start 2");
931 void CWindowTransport::goto_end()
933 gui->unlock_window();
934 handle_transport(GOTO_END, 1);
936 mwindow->gui->lock_window("CWindowTransport::goto_end 1");
938 mwindow->gui->unlock_window();
940 gui->lock_window("CWindowTransport::goto_end 2");
945 CWindowCanvas::CWindowCanvas(MWindow *mwindow, CWindowGUI *gui)
948 mwindow->theme->ccanvas_x,
949 mwindow->theme->ccanvas_y,
950 mwindow->theme->ccanvas_w,
951 mwindow->theme->ccanvas_h,
954 mwindow->edl->session->cwindow_scrollbars)
956 this->mwindow = mwindow;
960 void CWindowCanvas::status_event()
965 int CWindowCanvas::get_fullscreen()
967 return mwindow->session->cwindow_fullscreen;
970 void CWindowCanvas::set_fullscreen(int value)
972 mwindow->session->cwindow_fullscreen = value;
976 void CWindowCanvas::update_zoom(int x, int y, float zoom)
978 use_scrollbars = mwindow->edl->session->cwindow_scrollbars;
980 mwindow->edl->session->cwindow_xscroll = x;
981 mwindow->edl->session->cwindow_yscroll = y;
982 mwindow->edl->session->cwindow_zoom = zoom;
985 void CWindowCanvas::zoom_auto()
987 gui->zoom_canvas(0, 1);
990 int CWindowCanvas::get_xscroll()
992 return mwindow->edl->session->cwindow_xscroll;
995 int CWindowCanvas::get_yscroll()
997 return mwindow->edl->session->cwindow_yscroll;
1001 float CWindowCanvas::get_zoom()
1003 return mwindow->edl->session->cwindow_zoom;
1006 void CWindowCanvas::draw_refresh(int flush)
1008 if(get_canvas() && !get_canvas()->get_video_on())
1011 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
1013 float in_x1, in_y1, in_x2, in_y2;
1014 float out_x1, out_y1, out_x2, out_y2;
1015 get_transfers(mwindow->edl,
1025 if(!EQUIV(out_x1, 0) ||
1026 !EQUIV(out_y1, 0) ||
1027 !EQUIV(out_x2, get_canvas()->get_w()) ||
1028 !EQUIV(out_y2, get_canvas()->get_h()))
1030 get_canvas()->clear_box(0,
1032 get_canvas()->get_w(),
1033 get_canvas()->get_h());
1036 //printf("CWindowCanvas::draw_refresh %.2f %.2f %.2f %.2f -> %.2f %.2f %.2f %.2f\n",
1037 //in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2);
1040 if(out_x2 > out_x1 &&
1045 // Can't use OpenGL here because it is called asynchronously of the
1046 // playback operation.
1047 get_canvas()->draw_vframe(refresh_frame,
1050 (int)(out_x2 - out_x1),
1051 (int)(out_y2 - out_y1),
1054 (int)(in_x2 - in_x1),
1055 (int)(in_y2 - in_y1),
1061 get_canvas()->clear_box(0,
1063 get_canvas()->get_w(),
1064 get_canvas()->get_h());
1068 get_canvas()->flash(flush);
1070 //printf("CWindowCanvas::draw_refresh 10\n");
1073 #define CROPHANDLE_W 10
1074 #define CROPHANDLE_H 10
1076 void CWindowCanvas::draw_crophandle(int x, int y)
1078 get_canvas()->draw_box(x, y, CROPHANDLE_W, CROPHANDLE_H);
1086 #define CONTROL_W 10
1087 #define CONTROL_H 10
1088 #define FIRST_CONTROL_W 20
1089 #define FIRST_CONTROL_H 20
1091 #define BC_INFINITY 65536
1093 #define RULERHANDLE_W 16
1094 #define RULERHANDLE_H 16
1098 int CWindowCanvas::do_ruler(int draw,
1104 float x1 = mwindow->edl->session->ruler_x1;
1105 float y1 = mwindow->edl->session->ruler_y1;
1106 float x2 = mwindow->edl->session->ruler_x2;
1107 float y2 = mwindow->edl->session->ruler_y2;
1108 float canvas_x1 = x1;
1109 float canvas_y1 = y1;
1110 float canvas_x2 = x2;
1111 float canvas_y2 = y2;
1112 float output_x = get_cursor_x();
1113 float output_y = get_cursor_y();
1114 float canvas_cursor_x = output_x;
1115 float canvas_cursor_y = output_y;
1117 canvas_to_output(mwindow->edl, 0, output_x, output_y);
1118 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1119 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1120 mwindow->session->cwindow_output_x = roundf(output_x);
1121 mwindow->session->cwindow_output_y = roundf(output_y);
1123 if(button_press && get_buttonpress() == 1)
1125 gui->ruler_handle = -1;
1126 gui->ruler_translate = 0;
1129 gui->ruler_translate = 1;
1130 gui->ruler_origin_x = x1;
1131 gui->ruler_origin_y = y1;
1134 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1135 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1136 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1137 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1139 gui->ruler_handle = 0;
1140 gui->ruler_origin_x = x1;
1141 gui->ruler_origin_y = y1;
1144 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1145 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1146 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1147 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1149 gui->ruler_handle = 1;
1150 gui->ruler_origin_x = x2;
1151 gui->ruler_origin_y = y2;
1155 // Start new selection
1156 if(!gui->ruler_translate &&
1157 (gui->ruler_handle < 0 ||
1162 do_ruler(1, 0, 0, 0);
1163 get_canvas()->flash();
1164 gui->ruler_handle = 1;
1165 mwindow->edl->session->ruler_x1 = output_x;
1166 mwindow->edl->session->ruler_y1 = output_y;
1167 mwindow->edl->session->ruler_x2 = output_x;
1168 mwindow->edl->session->ruler_y2 = output_y;
1169 gui->ruler_origin_x = mwindow->edl->session->ruler_x2;
1170 gui->ruler_origin_y = mwindow->edl->session->ruler_y2;
1173 gui->x_origin = output_x;
1174 gui->y_origin = output_y;
1175 gui->current_operation = CWINDOW_RULER;
1176 gui->tool_panel->raise_window();
1182 if(gui->current_operation == CWINDOW_RULER)
1184 if(gui->ruler_translate)
1187 do_ruler(1, 0, 0, 0);
1188 float x_difference = mwindow->edl->session->ruler_x1;
1189 float y_difference = mwindow->edl->session->ruler_y1;
1190 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1191 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1192 x_difference -= mwindow->edl->session->ruler_x1;
1193 y_difference -= mwindow->edl->session->ruler_y1;
1194 mwindow->edl->session->ruler_x2 -= x_difference;
1195 mwindow->edl->session->ruler_y2 -= y_difference;
1197 do_ruler(1, 0, 0, 0);
1198 get_canvas()->flash();
1202 switch(gui->ruler_handle)
1205 do_ruler(1, 0, 0, 0);
1206 mwindow->edl->session->ruler_x1 = output_x - gui->x_origin + gui->ruler_origin_x;
1207 mwindow->edl->session->ruler_y1 = output_y - gui->y_origin + gui->ruler_origin_y;
1208 if(gui->alt_down() || gui->ctrl_down())
1210 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1211 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1215 double distance_value =
1216 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1217 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1218 if(angle_value < 22)
1219 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2;
1221 if(angle_value > 67)
1222 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2;
1224 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 &&
1225 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1227 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1228 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1231 if(mwindow->edl->session->ruler_x1 < mwindow->edl->session->ruler_x2 && mwindow->edl->session->ruler_y1 > mwindow->edl->session->ruler_y2)
1233 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 - distance_value / 1.414214;
1234 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1237 if(mwindow->edl->session->ruler_x1 > mwindow->edl->session->ruler_x2 &&
1238 mwindow->edl->session->ruler_y1 < mwindow->edl->session->ruler_y2)
1240 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1241 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 - distance_value / 1.414214;
1245 mwindow->edl->session->ruler_x1 = mwindow->edl->session->ruler_x2 + distance_value / 1.414214;
1246 mwindow->edl->session->ruler_y1 = mwindow->edl->session->ruler_y2 + distance_value / 1.414214;
1249 do_ruler(1, 0, 0, 0);
1250 get_canvas()->flash();
1255 do_ruler(1, 0, 0, 0);
1256 mwindow->edl->session->ruler_x2 = output_x - gui->x_origin + gui->ruler_origin_x;
1257 mwindow->edl->session->ruler_y2 = output_y - gui->y_origin + gui->ruler_origin_y;
1258 if(gui->alt_down() || gui->ctrl_down())
1260 double angle_value = fabs(atan((mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1) /
1261 (mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1)) *
1265 double distance_value =
1266 sqrt(SQR(mwindow->edl->session->ruler_x2 - mwindow->edl->session->ruler_x1) +
1267 SQR(mwindow->edl->session->ruler_y2 - mwindow->edl->session->ruler_y1));
1268 if(angle_value < 22)
1269 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1;
1271 if(angle_value > 67)
1272 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1;
1274 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1275 mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1277 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1278 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1281 if(mwindow->edl->session->ruler_x2 < mwindow->edl->session->ruler_x1 &&
1282 mwindow->edl->session->ruler_y2 > mwindow->edl->session->ruler_y1)
1284 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 - distance_value / 1.414214;
1285 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1288 if(mwindow->edl->session->ruler_x2 > mwindow->edl->session->ruler_x1 && mwindow->edl->session->ruler_y2 < mwindow->edl->session->ruler_y1)
1290 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1291 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 - distance_value / 1.414214;
1295 mwindow->edl->session->ruler_x2 = mwindow->edl->session->ruler_x1 + distance_value / 1.414214;
1296 mwindow->edl->session->ruler_y2 = mwindow->edl->session->ruler_y1 + distance_value / 1.414214;
1299 do_ruler(1, 0, 0, 0);
1300 get_canvas()->flash();
1304 //printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n", gui->ruler_x1, gui->ruler_y1, gui->ruler_x2, gui->ruler_y2);
1308 // printf("CWindowCanvas::do_ruler 2 %f %f %f %f\n",
1313 if(canvas_cursor_x >= canvas_x1 - RULERHANDLE_W / 2 &&
1314 canvas_cursor_x < canvas_x1 + RULERHANDLE_W / 2 &&
1315 canvas_cursor_y >= canvas_y1 - RULERHANDLE_W &&
1316 canvas_cursor_y < canvas_y1 + RULERHANDLE_H / 2)
1318 set_cursor(UPRIGHT_ARROW_CURSOR);
1321 if(canvas_cursor_x >= canvas_x2 - RULERHANDLE_W / 2 &&
1322 canvas_cursor_x < canvas_x2 + RULERHANDLE_W / 2 &&
1323 canvas_cursor_y >= canvas_y2 - RULERHANDLE_W &&
1324 canvas_cursor_y < canvas_y2 + RULERHANDLE_H / 2)
1326 set_cursor(UPRIGHT_ARROW_CURSOR);
1329 set_cursor(CROSS_CURSOR);
1331 // Update current position
1336 // Assume no ruler measurement if 0 length
1337 if(draw && (!EQUIV(x2, x1) || !EQUIV(y2, y1)))
1339 get_canvas()->set_inverse();
1340 get_canvas()->set_color(WHITE);
1341 get_canvas()->draw_line((int)canvas_x1,
1345 get_canvas()->draw_line(roundf(canvas_x1) - RULERHANDLE_W / 2,
1347 roundf(canvas_x1) + RULERHANDLE_W / 2,
1349 get_canvas()->draw_line(roundf(canvas_x1),
1350 roundf(canvas_y1) - RULERHANDLE_H / 2,
1352 roundf(canvas_y1) + RULERHANDLE_H / 2);
1353 get_canvas()->draw_line(roundf(canvas_x2) - RULERHANDLE_W / 2,
1355 roundf(canvas_x2) + RULERHANDLE_W / 2,
1357 get_canvas()->draw_line(roundf(canvas_x2),
1358 roundf(canvas_y2) - RULERHANDLE_H / 2,
1360 roundf(canvas_y2) + RULERHANDLE_H / 2);
1361 get_canvas()->set_opaque();
1368 static inline double line_dist(float cx,float cy, float tx,float ty)
1370 double dx = tx-cx, dy = ty-cy;
1371 return sqrt(dx*dx + dy*dy);
1374 static inline bool test_bbox(int cx, int cy, int tx, int ty)
1376 // printf("test_bbox %d,%d - %d,%d = %f\n",cx,cy,tx,ty,line_dist(cx,cy,tx,ty));
1377 return (llabs(cx-tx) < CONTROL_W/2 && llabs(cy-ty) < CONTROL_H/2);
1381 int CWindowCanvas::do_mask(int &redraw, int &rerender,
1382 int button_press, int cursor_motion, int draw)
1384 // Retrieve points from top recordable track
1385 //printf("CWindowCanvas::do_mask 1\n");
1386 Track *track = gui->cwindow->calculate_affected_track();
1387 //printf("CWindowCanvas::do_mask 2\n");
1389 if(!track) return 0;
1390 //printf("CWindowCanvas::do_mask 3\n");
1392 MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
1393 int64_t position = track->to_units(
1394 mwindow->edl->local_session->get_selectionstart(1),
1396 ArrayList<MaskPoint*> points;
1398 // Determine the points based on whether
1399 // new keyframes will be generated or drawing is performed.
1400 // If keyframe generation occurs, use the interpolated mask.
1401 // If no keyframe generation occurs, use the previous mask.
1402 int use_interpolated = 0;
1403 if(button_press || cursor_motion) {
1404 #ifdef USE_KEYFRAME_SPANNING
1405 double selection_start = mwindow->edl->local_session->get_selectionstart(0);
1406 double selection_end = mwindow->edl->local_session->get_selectionend(0);
1409 mask_autos->get_prev_auto(track->to_units(selection_start, 0),
1410 PLAY_FORWARD, first, 1);
1412 mask_autos->get_prev_auto(track->to_units(selection_end, 0),
1413 PLAY_FORWARD, last, 1);
1415 if(last == first && (!mwindow->edl->session->auto_keyframes))
1416 use_interpolated = 0;
1418 // If keyframe spanning occurs, use the interpolated points.
1419 // If new keyframe is generated, use the interpolated points.
1420 use_interpolated = 1;
1423 if(mwindow->edl->session->auto_keyframes)
1424 use_interpolated = 1;
1428 use_interpolated = 1;
1430 if(use_interpolated) {
1431 // Interpolate the points to get exactly what is being rendered at this position.
1432 mask_autos->get_points(&points,
1433 mwindow->edl->session->cwindow_mask,
1438 // Use the prev mask
1440 mask_autos->get_prev_auto(position,
1444 ((MaskAuto*)prev)->get_points(&points,
1445 mwindow->edl->session->cwindow_mask);
1448 // Projector zooms relative to the center of the track output.
1449 float half_track_w = (float)track->track_w / 2;
1450 float half_track_h = (float)track->track_h / 2;
1451 // Translate mask to projection
1452 float projector_x, projector_y, projector_z;
1453 track->automation->get_projector(
1454 &projector_x, &projector_y, &projector_z,
1455 position, PLAY_FORWARD);
1458 // Get position of cursor relative to mask
1459 float cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
1460 float mask_cursor_x = cursor_x, mask_cursor_y = cursor_y;
1461 canvas_to_output(mwindow->edl, 0, mask_cursor_x, mask_cursor_y);
1463 projector_x += mwindow->edl->session->output_w / 2;
1464 projector_y += mwindow->edl->session->output_h / 2;
1465 mask_cursor_x = (mask_cursor_x - projector_x) / projector_z + half_track_w;
1466 mask_cursor_y = (mask_cursor_y - projector_y) / projector_z + half_track_h;
1468 // Fix cursor origin
1470 gui->x_origin = mask_cursor_x;
1471 gui->y_origin = mask_cursor_y;
1475 // Points of closest line
1476 int shortest_point1 = -1;
1477 int shortest_point2 = -1;
1479 int shortest_point = -1;
1480 // Distance to closest line
1481 float shortest_line_distance = BC_INFINITY;
1482 // Distance to closest point
1483 float shortest_point_distance = BC_INFINITY;
1484 int selected_point = -1;
1485 int selected_control_point = -1;
1486 float selected_control_point_distance = BC_INFINITY;
1487 ArrayList<int> x_points;
1488 ArrayList<int> y_points;
1490 if(!cursor_motion) {
1492 get_canvas()->set_color(WHITE);
1493 get_canvas()->set_inverse();
1495 //printf("CWindowCanvas::do_mask 1 %d\n", points.size());
1497 // Never draw closed polygon and a closed
1498 // polygon is harder to add points to.
1499 for(int i = 0; i < points.size() && !result; i++) {
1500 MaskPoint *point1 = points.get(i);
1501 MaskPoint *point2 = (i >= points.size() - 1) ?
1502 points.get(0) : points.get(i + 1);
1504 float point_distance1 = line_dist(point1->x,point1->y, mask_cursor_x,mask_cursor_y);
1505 if(point_distance1 < shortest_point_distance || shortest_point < 0) {
1506 shortest_point_distance = point_distance1;
1510 float point_distance2 = line_dist(point2->x,point2->y, mask_cursor_x,mask_cursor_y);
1511 if(point_distance2 < shortest_point_distance || shortest_point < 0) {
1512 shortest_point_distance = point_distance2;
1513 shortest_point = (i >= points.size() - 1) ? 0 : (i + 1);
1517 int segments = 1 + line_dist(point1->x,point1->y, point2->x,point2->y);
1519 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f projectorz=%f\n",
1520 //point1->x, point1->y, point2->x, point2->y, projector_z);
1521 for(int j = 0; j <= segments && !result; j++) {
1522 //printf("CWindowCanvas::do_mask 1 %f, %f -> %f, %f\n", x0, y0, x3, y3);
1523 float x0 = point1->x, y0 = point1->y;
1524 float x1 = point1->x + point1->control_x2;
1525 float y1 = point1->y + point1->control_y2;
1526 float x2 = point2->x + point2->control_x1;
1527 float y2 = point2->y + point2->control_y1;
1528 float x3 = point2->x, y3 = point2->y;
1529 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
1530 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
1531 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
1532 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
1533 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
1534 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
1535 float canvas_x3 = (x3 - half_track_w) * projector_z + projector_x;
1536 float canvas_y3 = (y3 - half_track_h) * projector_z + projector_y;
1538 float t = (float)j / segments;
1539 float tpow2 = t * t;
1540 float tpow3 = t * t * t;
1542 float invtpow2 = invt * invt;
1543 float invtpow3 = invt * invt * invt;
1545 float x = ( invtpow3 * x0
1546 + 3 * t * invtpow2 * x1
1547 + 3 * tpow2 * invt * x2
1549 float y = ( invtpow3 * y0
1550 + 3 * t * invtpow2 * y1
1551 + 3 * tpow2 * invt * y2
1553 float canvas_x = (x - half_track_w) * projector_z + projector_x;
1554 float canvas_y = (y - half_track_h) * projector_z + projector_y;
1555 // Test new point addition
1557 float line_distance = line_dist(x,y, mask_cursor_x,mask_cursor_y);
1559 //printf("CWindowCanvas::do_mask 1 x=%f cursor_x=%f y=%f cursor_y=%f %f %f %d, %d\n",
1560 // x, cursor_x, y, cursor_y, line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1561 if(line_distance < shortest_line_distance ||
1562 shortest_point1 < 0) {
1563 shortest_line_distance = line_distance;
1564 shortest_point1 = i;
1565 shortest_point2 = (i >= points.size() - 1) ? 0 : (i + 1);
1566 //printf("CWindowCanvas::do_mask 2 %f %f %d, %d\n",
1567 // line_distance, shortest_line_distance, shortest_point1, shortest_point2);
1570 // Test existing point selection
1572 if(gui->ctrl_down()) {
1573 float distance = line_dist(x1,y1, mask_cursor_x,mask_cursor_y);
1575 if(distance < selected_control_point_distance) {
1577 selected_control_point = 1;
1578 selected_control_point_distance = distance;
1582 if(!gui->shift_down()) {
1583 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
1584 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
1589 selected_point = shortest_point;
1592 // Test second point
1593 if(gui->ctrl_down()) {
1594 float distance = line_dist(x2,y2, mask_cursor_x,mask_cursor_y);
1596 //printf("CWindowCanvas::do_mask %d %f %f\n", i, distance, selected_control_point_distance);
1597 if(distance < selected_control_point_distance) {
1598 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1599 selected_control_point = 0;
1600 selected_control_point_distance = distance;
1603 else if(i < points.size() - 1) {
1604 if(!gui->shift_down()) {
1605 output_to_canvas(mwindow->edl, 0, canvas_x3, canvas_y3);
1606 if(test_bbox(cursor_x, cursor_y, canvas_x3, canvas_y3)) {
1607 selected_point = (i < points.size() - 1 ? i + 1 : 0);
1611 selected_point = shortest_point;
1616 output_to_canvas(mwindow->edl, 0, canvas_x, canvas_y);
1620 if(draw) { // Draw joining line
1621 x_points.append((int)canvas_x);
1622 y_points.append((int)canvas_y);
1626 if(draw) { // Draw second anchor
1627 if(i < points.size() - 1) {
1628 if(i == gui->affected_point - 1)
1629 get_canvas()->draw_disc(
1630 (int)canvas_x - CONTROL_W / 2,
1631 (int)canvas_y - CONTROL_W / 2,
1632 CONTROL_W, CONTROL_H);
1634 get_canvas()->draw_circle(
1635 (int)canvas_x - CONTROL_W / 2,
1636 (int)canvas_y - CONTROL_W / 2,
1637 CONTROL_W, CONTROL_H);
1638 // char string[BCTEXTLEN];
1639 // sprintf(string, "%d", (i < points.size() - 1 ? i + 1 : 0));
1640 // canvas->draw_text((int)canvas_x + CONTROL_W, (int)canvas_y + CONTROL_W, string);
1642 // Draw second control point.
1643 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
1644 get_canvas()->draw_line(
1645 (int)canvas_x, (int)canvas_y,
1646 (int)canvas_x2, (int)canvas_y2);
1647 get_canvas()->draw_rectangle(
1648 (int)canvas_x2 - CONTROL_W / 2,
1649 (int)canvas_y2 - CONTROL_H / 2,
1650 CONTROL_W, CONTROL_H);
1655 // Draw first anchor
1656 if(i == 0 && draw) {
1657 char mask_label[BCSTRLEN];
1658 sprintf(mask_label, "%d",
1659 mwindow->edl->session->cwindow_mask);
1660 get_canvas()->draw_text(
1661 (int)canvas_x - FIRST_CONTROL_W,
1662 (int)canvas_y - FIRST_CONTROL_H,
1665 get_canvas()->draw_disc(
1666 (int)canvas_x - FIRST_CONTROL_W / 2,
1667 (int)canvas_y - FIRST_CONTROL_H / 2,
1668 FIRST_CONTROL_W, FIRST_CONTROL_H);
1671 // Draw first control point.
1673 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
1674 get_canvas()->draw_line(
1675 (int)canvas_x, (int)canvas_y,
1676 (int)canvas_x1, (int)canvas_y1);
1677 get_canvas()->draw_rectangle(
1678 (int)canvas_x1 - CONTROL_W / 2,
1679 (int)canvas_y1 - CONTROL_H / 2,
1680 CONTROL_W, CONTROL_H);
1682 x_points.append((int)canvas_x);
1683 y_points.append((int)canvas_y);
1686 //printf("CWindowCanvas::do_mask 1\n");
1690 //printf("CWindowCanvas::do_mask 1\n");
1693 get_canvas()->draw_polygon(&x_points, &y_points);
1694 get_canvas()->set_opaque();
1696 //printf("CWindowCanvas::do_mask 1\n");
1699 if(button_press && !result) {
1700 gui->affected_track = gui->cwindow->calculate_affected_track();
1702 // Get keyframe outside the EDL to edit. This must be rendered
1703 // instead of the EDL keyframes when it exists. Then it must be
1704 // applied to the EDL keyframes on buttonrelease.
1705 if(gui->affected_track) {
1706 #ifdef USE_KEYFRAME_SPANNING
1707 // Make copy of current parameters in local keyframe
1708 gui->mask_keyframe =
1709 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1712 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1715 gui->mask_keyframe =
1716 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1721 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1724 // Translate entire keyframe
1725 if(gui->alt_down() && mask->points.size()) {
1726 mwindow->undo->update_undo_before(_("mask translate"), 0);
1727 gui->current_operation = CWINDOW_MASK_TRANSLATE;
1728 gui->affected_point = 0;
1731 // Existing point or control point was selected
1732 if(selected_point >= 0) {
1733 mwindow->undo->update_undo_before(_("mask adjust"), 0);
1734 gui->affected_point = selected_point;
1736 if(selected_control_point == 0)
1737 gui->current_operation = CWINDOW_MASK_CONTROL_IN;
1739 if(selected_control_point == 1)
1740 gui->current_operation = CWINDOW_MASK_CONTROL_OUT;
1742 gui->current_operation = mwindow->edl->session->cwindow_operation;
1744 else // No existing point or control point was selected so create a new one
1745 if(!gui->ctrl_down() && !gui->alt_down()) {
1746 mwindow->undo->update_undo_before(_("mask point"), 0);
1747 // Create the template
1748 MaskPoint *point = new MaskPoint;
1749 point->x = mask_cursor_x;
1750 point->y = mask_cursor_y;
1751 point->control_x1 = 0;
1752 point->control_y1 = 0;
1753 point->control_x2 = 0;
1754 point->control_y2 = 0;
1757 if(shortest_point2 < shortest_point1) {
1758 shortest_point2 ^= shortest_point1;
1759 shortest_point1 ^= shortest_point2;
1760 shortest_point2 ^= shortest_point1;
1765 // printf("CWindowGUI::do_mask 40\n");
1766 // mwindow->edl->dump();
1767 // printf("CWindowGUI::do_mask 50\n");
1771 //printf("CWindowCanvas::do_mask 1 %f %f %d %d\n",
1772 // shortest_line_distance, shortest_point_distance, shortest_point1, shortest_point2);
1773 //printf("CWindowCanvas::do_mask %d %d\n", shortest_point1, shortest_point2);
1775 // Append to end of list
1776 if( shortest_point1 == shortest_point2 ||
1777 labs(shortest_point1 - shortest_point2) > 1) {
1778 #ifdef USE_KEYFRAME_SPANNING
1780 MaskPoint *new_point = new MaskPoint;
1781 points.append(new_point);
1782 *new_point = *point;
1783 gui->affected_point = points.size() - 1;
1787 // Need to apply the new point to every keyframe
1788 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1789 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1790 MaskPoint *new_point = new MaskPoint;
1791 submask->points.append(new_point);
1792 *new_point = *point;
1793 if(current == (MaskAuto*)mask_autos->default_auto)
1794 current = (MaskAuto*)mask_autos->first;
1796 current = (MaskAuto*)NEXT;
1798 gui->affected_point = mask->points.size() - 1;
1804 // Insert between 2 points, shifting back point 2
1805 if(shortest_point1 >= 0 && shortest_point2 >= 0) {
1807 #ifdef USE_KEYFRAME_SPANNING
1808 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1810 if(points.size() >= shortest_point2) {
1811 MaskPoint *new_point = new MaskPoint;
1813 for(int i = points.size() - 1;
1814 i > shortest_point2;
1816 points.values[i] = points.values[i - 1];
1817 points.values[shortest_point2] = new_point;
1819 *new_point = *point;
1824 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1825 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1826 // In case the keyframe point count isn't synchronized with the rest of the keyframes,
1828 if(submask->points.size() >= shortest_point2) {
1829 MaskPoint *new_point = new MaskPoint;
1830 submask->points.append(0);
1831 for(int i = submask->points.size() - 1;
1832 i > shortest_point2;
1834 submask->points.values[i] = submask->points.values[i - 1];
1835 submask->points.values[shortest_point2] = new_point;
1837 *new_point = *point;
1840 if(current == (MaskAuto*)mask_autos->default_auto)
1841 current = (MaskAuto*)mask_autos->first;
1843 current = (MaskAuto*)NEXT;
1847 gui->affected_point = shortest_point2;
1852 // printf("CWindowGUI::do_mask 20\n");
1853 // mwindow->edl->dump();
1854 // printf("CWindowGUI::do_mask 30\n");
1857 //printf("CWindowCanvas::do_mask 1\n");
1858 // Create the first point.
1859 #ifdef USE_KEYFRAME_SPANNING
1860 MaskPoint *new_point = new MaskPoint;
1861 points.append(new_point);
1862 *new_point = *point;
1863 gui->affected_point = points.size() - 1;
1865 for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto; current; ) {
1866 SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
1867 MaskPoint *new_point = new MaskPoint;
1868 submask->points.append(new_point);
1869 *new_point = *point;
1870 if(current == (MaskAuto*)mask_autos->default_auto)
1871 current = (MaskAuto*)mask_autos->first;
1873 current = (MaskAuto*)NEXT;
1875 gui->affected_point = points.size() - 1;
1878 //printf("CWindowCanvas::do_mask 3 %d\n", mask->points.size());
1881 gui->current_operation = mwindow->edl->session->cwindow_operation;
1882 // Delete the template
1891 if(button_press && result) {
1892 #ifdef USE_KEYFRAME_SPANNING
1893 MaskPoint *point = points.values[gui->affected_point];
1894 gui->center_x = point->x;
1895 gui->center_y = point->y;
1896 gui->control_in_x = point->control_x1;
1897 gui->control_in_y = point->control_y1;
1898 gui->control_out_x = point->control_x2;
1899 gui->control_out_y = point->control_y2;
1900 gui->tool_panel->raise_window();
1902 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1903 MaskPoint *point = mask->points.values[gui->affected_point];
1904 gui->center_x = point->x;
1905 gui->center_y = point->y;
1906 gui->control_in_x = point->control_x1;
1907 gui->control_in_y = point->control_y1;
1908 gui->control_out_x = point->control_x2;
1909 gui->control_out_y = point->control_y2;
1910 gui->tool_panel->raise_window();
1914 //printf("CWindowCanvas::do_mask 8\n");
1917 #ifdef USE_KEYFRAME_SPANNING
1918 // Must update the reference keyframes for every cursor motion
1919 gui->mask_keyframe =
1920 (MaskAuto*)gui->cwindow->calculate_affected_auto(
1923 gui->orig_mask_keyframe->copy_data(gui->mask_keyframe);
1926 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1928 SubMask *mask = gui->mask_keyframe->get_submask(mwindow->edl->session->cwindow_mask);
1929 if( gui->affected_point >= 0 && gui->affected_point < mask->points.size() &&
1930 gui->current_operation != CWINDOW_NONE) {
1931 // mwindow->undo->update_undo_before(_("mask point"), this);
1932 #ifdef USE_KEYFRAME_SPANNING
1933 MaskPoint *point = points.get(gui->affected_point);
1935 MaskPoint *point = mask->points.get(gui->affected_point);
1937 // canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
1938 //printf("CWindowCanvas::do_mask 9 %d %d\n", mask->points.size(), gui->affected_point);
1940 float last_x = point->x;
1941 float last_y = point->y;
1942 float last_control_x1 = point->control_x1;
1943 float last_control_y1 = point->control_y1;
1944 float last_control_x2 = point->control_x2;
1945 float last_control_y2 = point->control_y2;
1947 switch(gui->current_operation) {
1949 //printf("CWindowCanvas::do_mask %d %d\n", __LINE__, gui->affected_point);
1950 point->x = mask_cursor_x - gui->x_origin + gui->center_x;
1951 point->y = mask_cursor_y - gui->y_origin + gui->center_y;
1954 case CWINDOW_MASK_CONTROL_IN:
1955 point->control_x1 = mask_cursor_x - gui->x_origin + gui->control_in_x;
1956 point->control_y1 = mask_cursor_y - gui->y_origin + gui->control_in_y;
1959 case CWINDOW_MASK_CONTROL_OUT:
1960 point->control_x2 = mask_cursor_x - gui->x_origin + gui->control_out_x;
1961 point->control_y2 = mask_cursor_y - gui->y_origin + gui->control_out_y;
1964 case CWINDOW_MASK_TRANSLATE:
1965 #ifdef USE_KEYFRAME_SPANNING
1966 for(int i = 0; i < points.size(); i++) {
1967 points.values[i]->x += mask_cursor_x - gui->x_origin;
1968 points.values[i]->y += mask_cursor_y - gui->y_origin;
1971 for(int i = 0; i < mask->points.size(); i++) {
1972 mask->points.values[i]->x += mask_cursor_x - gui->x_origin;
1973 mask->points.values[i]->y += mask_cursor_y - gui->y_origin;
1976 gui->x_origin = mask_cursor_x;
1977 gui->y_origin = mask_cursor_y;
1981 if( !EQUIV(last_x, point->x) ||
1982 !EQUIV(last_y, point->y) ||
1983 !EQUIV(last_control_x1, point->control_x1) ||
1984 !EQUIV(last_control_y1, point->control_y1) ||
1985 !EQUIV(last_control_x2, point->control_x2) ||
1986 !EQUIV(last_control_y2, point->control_y2)) {
1992 if(gui->current_operation == CWINDOW_NONE) {
1993 // printf("CWindowCanvas::do_mask %d\n", __LINE__);
1995 for(int i = 0; i < points.size() && !over_point; i++) {
1996 MaskPoint *point = points.get(i);
1997 float x0 = point->x;
1998 float y0 = point->y;
1999 float x1 = point->x + point->control_x1;
2000 float y1 = point->y + point->control_y1;
2001 float x2 = point->x + point->control_x2;
2002 float y2 = point->y + point->control_y2;
2003 float canvas_x0 = (x0 - half_track_w) * projector_z + projector_x;
2004 float canvas_y0 = (y0 - half_track_h) * projector_z + projector_y;
2006 output_to_canvas(mwindow->edl, 0, canvas_x0, canvas_y0);
2007 if(test_bbox(cursor_x, cursor_y, canvas_x0, canvas_y0)) {
2011 if(!over_point && gui->ctrl_down()) {
2012 float canvas_x1 = (x1 - half_track_w) * projector_z + projector_x;
2013 float canvas_y1 = (y1 - half_track_h) * projector_z + projector_y;
2014 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2015 if(test_bbox(cursor_x, cursor_y, canvas_x1, canvas_y1)) {
2019 float canvas_x2 = (x2 - half_track_w) * projector_z + projector_x;
2020 float canvas_y2 = (y2 - half_track_h) * projector_z + projector_y;
2021 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2022 if(test_bbox(cursor_x, cursor_y, canvas_x2, canvas_y2)) {
2029 set_cursor( over_point ? ARROW_CURSOR : CROSS_CURSOR );
2034 //printf("CWindowCanvas::do_mask 2 %d %d %d\n", result, rerender, redraw);
2037 #ifdef USE_KEYFRAME_SPANNING
2038 // Must commit change after operation.
2039 if(rerender && track) {
2040 // Swap EDL keyframe with original.
2041 // Apply new values to keyframe span
2042 MaskAuto temp_keyframe(mwindow->edl, mask_autos);
2043 temp_keyframe.copy_data(gui->mask_keyframe);
2044 // Apply interpolated points back to keyframe
2045 temp_keyframe.set_points(&points, mwindow->edl->session->cwindow_mask);
2046 gui->mask_keyframe->copy_data(gui->orig_mask_keyframe);
2047 mask_autos->update_parameter(&temp_keyframe);
2051 points.remove_all_objects();
2052 //printf("CWindowCanvas::do_mask 20\n");
2056 int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
2059 int radius = mwindow->edl->session->eyedrop_radius;
2067 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2072 row1 = gui->eyedrop_y - radius;
2073 row2 = gui->eyedrop_y + radius;
2074 column1 = gui->eyedrop_x - radius;
2075 column2 = gui->eyedrop_x + radius;
2077 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2078 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2079 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2080 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2082 if(row2 <= row1) row2 = row1 + 1;
2083 if(column2 <= column1) column2 = column1 + 1;
2090 output_to_canvas(mwindow->edl, 0, x1, y1);
2091 output_to_canvas(mwindow->edl, 0, x2, y2);
2092 //printf("CWindowCanvas::do_eyedrop %d %f %f %f %f\n", __LINE__, x1, x2, y1, y2);
2094 if(x2 - x1 >= 1 && y2 - y1 >= 1)
2096 get_canvas()->set_inverse();
2097 get_canvas()->set_color(WHITE);
2099 get_canvas()->draw_rectangle((int)x1,
2104 get_canvas()->set_opaque();
2105 get_canvas()->flash();
2113 gui->current_operation = CWINDOW_EYEDROP;
2114 gui->tool_panel->raise_window();
2117 if(gui->current_operation == CWINDOW_EYEDROP)
2119 mwindow->undo->update_undo_before(_("Eyedrop"), this);
2121 // Get color out of frame.
2122 // Doesn't work during playback because that bypasses the refresh frame.
2123 if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
2125 float cursor_x = get_cursor_x();
2126 float cursor_y = get_cursor_y();
2127 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2128 CLAMP(cursor_x, 0, refresh_frame->get_w() - 1);
2129 CLAMP(cursor_y, 0, refresh_frame->get_h() - 1);
2131 row1 = cursor_y - radius;
2132 row2 = cursor_y + radius;
2133 column1 = cursor_x - radius;
2134 column2 = cursor_x + radius;
2135 CLAMP(row1, 0, refresh_frame->get_h() - 1);
2136 CLAMP(row2, 0, refresh_frame->get_h() - 1);
2137 CLAMP(column1, 0, refresh_frame->get_w() - 1);
2138 CLAMP(column2, 0, refresh_frame->get_w() - 1);
2139 if(row2 <= row1) row2 = row1 + 1;
2140 if(column2 <= column1) column2 = column1 + 1;
2144 if(gui->eyedrop_visible)
2147 do_eyedrop(temp, 0, 1);
2148 gui->eyedrop_visible = 0;
2151 gui->eyedrop_x = cursor_x;
2152 gui->eyedrop_y = cursor_y;
2157 do_eyedrop(temp, 0, 1);
2158 gui->eyedrop_visible = 1;
2161 // Decompression coefficients straight out of jpeglib
2162 #define V_TO_R 1.40200
2163 #define V_TO_G -0.71414
2165 #define U_TO_G -0.34414
2166 #define U_TO_B 1.77200
2168 #define GET_COLOR(type, components, max, do_yuv) \
2170 type *row = (type*)(refresh_frame->get_rows()[i]) + \
2172 float red = (float)*row++ / max; \
2173 float green = (float)*row++ / max; \
2174 float blue = (float)*row++ / max; \
2177 float r = red + V_TO_R * (blue - 0.5); \
2178 float g = red + U_TO_G * (green - 0.5) + V_TO_G * (blue - 0.5); \
2179 float b = red + U_TO_B * (green - 0.5); \
2180 mwindow->edl->local_session->red += r; \
2181 mwindow->edl->local_session->green += g; \
2182 mwindow->edl->local_session->blue += b; \
2183 if(r > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = r; \
2184 if(g > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = g; \
2185 if(b > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = b; \
2189 mwindow->edl->local_session->red += red; \
2190 mwindow->edl->local_session->green += green; \
2191 mwindow->edl->local_session->blue += blue; \
2192 if(red > mwindow->edl->local_session->red_max) mwindow->edl->local_session->red_max = red; \
2193 if(green > mwindow->edl->local_session->green_max) mwindow->edl->local_session->green_max = green; \
2194 if(blue > mwindow->edl->local_session->blue_max) mwindow->edl->local_session->blue_max = blue; \
2200 mwindow->edl->local_session->red = 0;
2201 mwindow->edl->local_session->green = 0;
2202 mwindow->edl->local_session->blue = 0;
2203 mwindow->edl->local_session->red_max = 0;
2204 mwindow->edl->local_session->green_max = 0;
2205 mwindow->edl->local_session->blue_max = 0;
2206 for(int i = row1; i < row2; i++)
2208 for(int j = column1; j < column2; j++)
2210 switch(refresh_frame->get_color_model())
2213 GET_COLOR(unsigned char, 3, 0xff, 1);
2216 GET_COLOR(unsigned char, 4, 0xff, 1);
2219 GET_COLOR(uint16_t, 3, 0xffff, 1);
2221 case BC_YUVA16161616:
2222 GET_COLOR(uint16_t, 4, 0xffff, 1);
2225 GET_COLOR(unsigned char, 3, 0xff, 0);
2228 GET_COLOR(unsigned char, 4, 0xff, 0);
2231 GET_COLOR(float, 3, 1.0, 0);
2234 GET_COLOR(float, 4, 1.0, 0);
2240 mwindow->edl->local_session->red /= (row2 - row1) * (column2 - column1);
2241 mwindow->edl->local_session->green /= (row2 - row1) * (column2 - column1);
2242 mwindow->edl->local_session->blue /= (row2 - row1) * (column2 - column1);
2247 mwindow->edl->local_session->red = 0;
2248 mwindow->edl->local_session->green = 0;
2249 mwindow->edl->local_session->blue = 0;
2250 gui->eyedrop_visible = 0;
2259 // Can't rerender since the color value is from the output of any effect it
2262 mwindow->undo->update_undo_after(_("Eyedrop"), LOAD_SESSION);
2268 void CWindowCanvas::draw_overlays()
2270 if(mwindow->edl->session->safe_regions)
2272 draw_safe_regions();
2275 if(mwindow->edl->session->cwindow_scrollbars)
2277 // Always draw output rectangle
2278 float x1, y1, x2, y2;
2280 x2 = mwindow->edl->session->output_w;
2282 y2 = mwindow->edl->session->output_h;
2283 output_to_canvas(mwindow->edl, 0, x1, y1);
2284 output_to_canvas(mwindow->edl, 0, x2, y2);
2286 get_canvas()->set_inverse();
2287 get_canvas()->set_color(WHITE);
2289 get_canvas()->draw_rectangle((int)x1,
2294 get_canvas()->set_opaque();
2297 if(gui->highlighted)
2299 get_canvas()->set_color(WHITE);
2300 get_canvas()->set_inverse();
2301 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
2302 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
2303 get_canvas()->set_opaque();
2306 int temp1 = 0, temp2 = 0;
2307 //printf("CWindowCanvas::draw_overlays 1 %d\n", mwindow->edl->session->cwindow_operation);
2308 switch(mwindow->edl->session->cwindow_operation)
2310 case CWINDOW_CAMERA:
2314 case CWINDOW_PROJECTOR:
2323 do_mask(temp1, temp2, 0, 0, 1);
2327 do_ruler(1, 0, 0, 0);
2330 case CWINDOW_EYEDROP:
2331 if(gui->eyedrop_visible)
2334 do_eyedrop(rerender, 0, 1);
2335 gui->eyedrop_visible = 1;
2341 void CWindowCanvas::draw_safe_regions()
2343 float action_x1, action_x2, action_y1, action_y2;
2344 float title_x1, title_x2, title_y1, title_y2;
2346 action_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.9;
2347 action_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.9;
2348 action_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.9;
2349 action_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.9;
2350 title_x1 = mwindow->edl->session->output_w / 2 - mwindow->edl->session->output_w / 2 * 0.8;
2351 title_x2 = mwindow->edl->session->output_w / 2 + mwindow->edl->session->output_w / 2 * 0.8;
2352 title_y1 = mwindow->edl->session->output_h / 2 - mwindow->edl->session->output_h / 2 * 0.8;
2353 title_y2 = mwindow->edl->session->output_h / 2 + mwindow->edl->session->output_h / 2 * 0.8;
2355 output_to_canvas(mwindow->edl, 0, action_x1, action_y1);
2356 output_to_canvas(mwindow->edl, 0, action_x2, action_y2);
2357 output_to_canvas(mwindow->edl, 0, title_x1, title_y1);
2358 output_to_canvas(mwindow->edl, 0, title_x2, title_y2);
2360 get_canvas()->set_inverse();
2361 get_canvas()->set_color(WHITE);
2363 get_canvas()->draw_rectangle((int)action_x1,
2365 (int)(action_x2 - action_x1),
2366 (int)(action_y2 - action_y1));
2367 get_canvas()->draw_rectangle((int)title_x1,
2369 (int)(title_x2 - title_x1),
2370 (int)(title_y2 - title_y1));
2372 get_canvas()->set_opaque();
2375 void CWindowCanvas::reset_keyframe(int do_camera)
2377 FloatAuto *x_keyframe = 0;
2378 FloatAuto *y_keyframe = 0;
2379 FloatAuto *z_keyframe = 0;
2380 Track *affected_track = 0;
2382 affected_track = gui->cwindow->calculate_affected_track();
2386 gui->cwindow->calculate_affected_autos(&x_keyframe,
2395 x_keyframe->set_value(0);
2396 y_keyframe->set_value(0);
2397 z_keyframe->set_value(1);
2399 mwindow->sync_parameters(CHANGE_PARAMS);
2404 void CWindowCanvas::reset_camera()
2409 void CWindowCanvas::reset_projector()
2414 int CWindowCanvas::test_crop(int button_press, int &redraw)
2417 int handle_selected = -1;
2418 float x1 = mwindow->edl->session->crop_x1;
2419 float y1 = mwindow->edl->session->crop_y1;
2420 float x2 = mwindow->edl->session->crop_x2;
2421 float y2 = mwindow->edl->session->crop_y2;
2422 float cursor_x = get_cursor_x();
2423 float cursor_y = get_cursor_y();
2424 float canvas_x1 = x1;
2425 float canvas_y1 = y1;
2426 float canvas_x2 = x2;
2427 float canvas_y2 = y2;
2428 float canvas_cursor_x = cursor_x;
2429 float canvas_cursor_y = cursor_y;
2431 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2432 // Use screen normalized coordinates for hot spot tests.
2433 output_to_canvas(mwindow->edl, 0, canvas_x1, canvas_y1);
2434 output_to_canvas(mwindow->edl, 0, canvas_x2, canvas_y2);
2437 if(gui->current_operation == CWINDOW_CROP)
2439 handle_selected = gui->crop_handle;
2442 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2443 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2445 handle_selected = 0;
2446 gui->crop_origin_x = x1;
2447 gui->crop_origin_y = y1;
2450 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2451 canvas_cursor_y >= canvas_y1 && canvas_cursor_y < canvas_y1 + CROPHANDLE_H)
2453 handle_selected = 1;
2454 gui->crop_origin_x = x2;
2455 gui->crop_origin_y = y1;
2458 if(canvas_cursor_x >= canvas_x1 && canvas_cursor_x < canvas_x1 + CROPHANDLE_W &&
2459 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2461 handle_selected = 2;
2462 gui->crop_origin_x = x1;
2463 gui->crop_origin_y = y2;
2466 if(canvas_cursor_x >= canvas_x2 - CROPHANDLE_W && canvas_cursor_x < canvas_x2 &&
2467 canvas_cursor_y >= canvas_y2 - CROPHANDLE_H && canvas_cursor_y < canvas_y2)
2469 handle_selected = 3;
2470 gui->crop_origin_x = x2;
2471 gui->crop_origin_y = y2;
2476 gui->crop_origin_x = cursor_x;
2477 gui->crop_origin_y = cursor_y;
2480 // printf("test crop %d %d\n",
2481 // gui->current_operation,
2482 // handle_selected);
2489 gui->crop_translate = 1;
2490 gui->crop_origin_x1 = x1;
2491 gui->crop_origin_y1 = y1;
2492 gui->crop_origin_x2 = x2;
2493 gui->crop_origin_y2 = y2;
2496 gui->crop_translate = 0;
2498 gui->current_operation = CWINDOW_CROP;
2499 gui->crop_handle = handle_selected;
2500 gui->x_origin = cursor_x;
2501 gui->y_origin = cursor_y;
2502 gui->tool_panel->raise_window();
2505 if(handle_selected < 0 && !gui->crop_translate)
2509 mwindow->edl->session->crop_x1 = (int)x1;
2510 mwindow->edl->session->crop_y1 = (int)y1;
2511 mwindow->edl->session->crop_x2 = (int)x2;
2512 mwindow->edl->session->crop_y2 = (int)y2;
2517 // Translate all 4 points
2518 if(gui->current_operation == CWINDOW_CROP && gui->crop_translate)
2520 x1 = cursor_x - gui->x_origin + gui->crop_origin_x1;
2521 y1 = cursor_y - gui->y_origin + gui->crop_origin_y1;
2522 x2 = cursor_x - gui->x_origin + gui->crop_origin_x2;
2523 y2 = cursor_y - gui->y_origin + gui->crop_origin_y2;
2525 mwindow->edl->session->crop_x1 = (int)x1;
2526 mwindow->edl->session->crop_y1 = (int)y1;
2527 mwindow->edl->session->crop_x2 = (int)x2;
2528 mwindow->edl->session->crop_y2 = (int)y2;
2534 if(gui->current_operation == CWINDOW_CROP)
2536 switch(gui->crop_handle)
2539 x1 = gui->crop_origin_x;
2540 y1 = gui->crop_origin_y;
2541 x2 = gui->crop_origin_x;
2542 y2 = gui->crop_origin_y;
2543 if(cursor_x < gui->x_origin)
2545 if(cursor_y < gui->y_origin)
2551 if(cursor_y >= gui->y_origin)
2558 if(cursor_x >= gui->x_origin)
2560 if(cursor_y < gui->y_origin)
2566 if(cursor_y >= gui->y_origin)
2573 // printf("test crop %d %d %d %d\n",
2574 // mwindow->edl->session->crop_x1,
2575 // mwindow->edl->session->crop_y1,
2576 // mwindow->edl->session->crop_x2,
2577 // mwindow->edl->session->crop_y2);
2580 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2581 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2584 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2585 y1 = cursor_y - gui->y_origin + gui->crop_origin_y;
2588 x1 = cursor_x - gui->x_origin + gui->crop_origin_x;
2589 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2592 x2 = cursor_x - gui->x_origin + gui->crop_origin_x;
2593 y2 = cursor_y - gui->y_origin + gui->crop_origin_y;
2597 if(!EQUIV(mwindow->edl->session->crop_x1, x1) ||
2598 !EQUIV(mwindow->edl->session->crop_x2, x2) ||
2599 !EQUIV(mwindow->edl->session->crop_y1, y1) ||
2600 !EQUIV(mwindow->edl->session->crop_y2, y2))
2607 switch (gui->crop_handle)
2609 case 0: gui->crop_handle = 1; break;
2610 case 1: gui->crop_handle = 0; break;
2611 case 2: gui->crop_handle = 3; break;
2612 case 3: gui->crop_handle = 2; break;
2622 switch (gui->crop_handle)
2624 case 0: gui->crop_handle = 2; break;
2625 case 1: gui->crop_handle = 3; break;
2626 case 2: gui->crop_handle = 0; break;
2627 case 3: gui->crop_handle = 1; break;
2632 mwindow->edl->session->crop_x1 = (int)x1;
2633 mwindow->edl->session->crop_y1 = (int)y1;
2634 mwindow->edl->session->crop_x2 = (int)x2;
2635 mwindow->edl->session->crop_y2 = (int)y2;
2641 // Update cursor font
2642 if(handle_selected >= 0)
2644 switch(handle_selected)
2647 set_cursor(UPLEFT_RESIZE);
2650 set_cursor(UPRIGHT_RESIZE);
2653 set_cursor(DOWNLEFT_RESIZE);
2656 set_cursor(DOWNRIGHT_RESIZE);
2663 set_cursor(ARROW_CURSOR);
2665 #define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
2669 CLAMP(mwindow->edl->session->crop_x1, 0, mwindow->edl->session->output_w);
2670 CLAMP(mwindow->edl->session->crop_x2, 0, mwindow->edl->session->output_w);
2671 CLAMP(mwindow->edl->session->crop_y1, 0, mwindow->edl->session->output_h);
2672 CLAMP(mwindow->edl->session->crop_y2, 0, mwindow->edl->session->output_h);
2673 // printf("CWindowCanvas::test_crop %d %d %d %d\n",
2674 // mwindow->edl->session->crop_x2,
2675 // mwindow->edl->session->crop_y2,
2676 // mwindow->edl->calculate_output_w(0),
2677 // mwindow->edl->calculate_output_h(0));
2683 void CWindowCanvas::draw_crop()
2685 get_canvas()->set_inverse();
2686 get_canvas()->set_color(WHITE);
2688 float x1 = mwindow->edl->session->crop_x1;
2689 float y1 = mwindow->edl->session->crop_y1;
2690 float x2 = mwindow->edl->session->crop_x2;
2691 float y2 = mwindow->edl->session->crop_y2;
2693 output_to_canvas(mwindow->edl, 0, x1, y1);
2694 output_to_canvas(mwindow->edl, 0, x2, y2);
2696 if(x2 - x1 && y2 - y1)
2697 get_canvas()->draw_rectangle((int)x1,
2702 draw_crophandle((int)x1, (int)y1);
2703 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y1);
2704 draw_crophandle((int)x1, (int)y2 - CROPHANDLE_H);
2705 draw_crophandle((int)x2 - CROPHANDLE_W, (int)y2 - CROPHANDLE_H);
2706 get_canvas()->set_opaque();
2716 void CWindowCanvas::draw_bezier(int do_camera)
2718 Track *track = gui->cwindow->calculate_affected_track();
2725 int64_t position = track->to_units(
2726 mwindow->edl->local_session->get_selectionstart(1),
2729 track->automation->get_projector(¢er_x,
2735 // center_x += track->track_w / 2;
2736 // center_y += track->track_h / 2;
2737 center_x += mwindow->edl->session->output_w / 2;
2738 center_y += mwindow->edl->session->output_h / 2;
2739 float track_x1 = center_x - track->track_w / 2 * center_z;
2740 float track_y1 = center_y - track->track_h / 2 * center_z;
2741 float track_x2 = track_x1 + track->track_w * center_z;
2742 float track_y2 = track_y1 + track->track_h * center_z;
2744 output_to_canvas(mwindow->edl, 0, track_x1, track_y1);
2745 output_to_canvas(mwindow->edl, 0, track_x2, track_y2);
2747 #define DRAW_PROJECTION(offset) \
2748 get_canvas()->draw_rectangle((int)track_x1 + offset, \
2749 (int)track_y1 + offset, \
2750 (int)(track_x2 - track_x1), \
2751 (int)(track_y2 - track_y1)); \
2752 get_canvas()->draw_line((int)track_x1 + offset, \
2753 (int)track_y1 + offset, \
2754 (int)track_x2 + offset, \
2755 (int)track_y2 + offset); \
2756 get_canvas()->draw_line((int)track_x2 + offset, \
2757 (int)track_y1 + offset, \
2758 (int)track_x1 + offset, \
2759 (int)track_y2 + offset); \
2763 get_canvas()->set_color(BLACK);
2766 // canvas->set_inverse();
2768 get_canvas()->set_color(GREEN);
2770 get_canvas()->set_color(RED);
2773 // canvas->set_opaque();
2777 int CWindowCanvas::test_bezier(int button_press,
2785 // Processing drag operation.
2786 // Create keyframe during first cursor motion.
2790 float cursor_x = get_cursor_x();
2791 float cursor_y = get_cursor_y();
2792 canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y);
2794 if(gui->current_operation == CWINDOW_CAMERA ||
2795 gui->current_operation == CWINDOW_PROJECTOR)
2797 if(!gui->ctrl_down() && gui->shift_down() && !gui->translating_zoom)
2799 gui->translating_zoom = 1;
2800 gui->reset_affected();
2803 if(!gui->ctrl_down() && !gui->shift_down() && gui->translating_zoom)
2805 gui->translating_zoom = 0;
2806 gui->reset_affected();
2809 // Get target keyframe
2810 float last_center_x;
2811 float last_center_y;
2812 float last_center_z;
2815 if(!gui->affected_x && !gui->affected_y && !gui->affected_z)
2817 FloatAutos *affected_x_autos;
2818 FloatAutos *affected_y_autos;
2819 FloatAutos *affected_z_autos;
2820 if(!gui->affected_track) return 0;
2821 double position = mwindow->edl->local_session->get_selectionstart(1);
2822 int64_t track_position = gui->affected_track->to_units(position, 0);
2824 if(mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA)
2826 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_X];
2827 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Y];
2828 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_CAMERA_Z];
2832 affected_x_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_X];
2833 affected_y_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Y];
2834 affected_z_autos = (FloatAutos*)gui->affected_track->automation->autos[AUTOMATION_PROJECTOR_Z];
2838 if(gui->translating_zoom)
2840 FloatAuto *previous = 0;
2841 FloatAuto *next = 0;
2842 float new_z = affected_z_autos->get_value(
2848 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2849 affected_z_autos, 1, &created, 0);
2851 gui->affected_z->set_value(new_z);
2857 FloatAuto *previous = 0;
2858 FloatAuto *next = 0;
2859 float new_x = affected_x_autos->get_value(
2866 float new_y = affected_y_autos->get_value(
2872 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2873 affected_x_autos, 1, &created, 0);
2875 gui->affected_x->set_value(new_x);
2879 (FloatAuto*)gui->cwindow->calculate_affected_auto(
2880 affected_y_autos, 1, &created, 0);
2882 gui->affected_y->set_value(new_y);
2889 if(gui->translating_zoom)
2891 gui->center_z = gui->affected_z->get_value();
2895 gui->center_x = gui->affected_x->get_value();
2896 gui->center_y = gui->affected_y->get_value();
2903 if(gui->translating_zoom)
2905 last_center_z = gui->affected_z->get_value();
2906 float z = gui->center_z + (cursor_y - gui->y_origin) / 128;
2908 if(!EQUIV(last_center_z, z))
2914 gui->affected_z->set_value(z);
2918 last_center_x = gui->affected_x->get_value();
2919 last_center_y = gui->affected_y->get_value();
2920 float x = gui->center_x + cursor_x - gui->x_origin;
2921 float y = gui->center_y + cursor_y - gui->y_origin;
2922 gui->affected_x->set_value(x);
2923 gui->affected_y->set_value(y);
2924 if( !EQUIV(last_center_x, x) || !EQUIV(last_center_y, y) )
2930 gui->affected_x->set_value(x);
2931 gui->affected_y->set_value(y);
2938 // Begin drag operation. Don't create keyframe here.
2940 // Get affected track off of the first recordable video track.
2941 // Calculating based on the alpha channel would require recording what layer
2942 // each output pixel belongs to as they're rendered and stacked. Forget it.
2943 gui->affected_track = gui->cwindow->calculate_affected_track();
2944 gui->reset_affected();
2946 if(gui->affected_track)
2948 if(gui->current_operation == CWINDOW_CAMERA)
2949 mwindow->undo->update_undo_before(_("camera"), this);
2951 mwindow->undo->update_undo_before(_("projector"), this);
2953 gui->current_operation =
2954 mwindow->edl->session->cwindow_operation;
2955 gui->tool_panel->raise_window();
2964 int CWindowCanvas::test_zoom(int &redraw)
2970 if( mwindow->edl->session->cwindow_scrollbars ) {
2971 if( *gui->zoom_panel->get_text() != 'x' ) {
2972 // Find current zoom in table
2973 int idx = total_zooms; float old_zoom = get_zoom();
2974 while( --idx >= 0 && !EQUIV(my_zoom_table[idx], old_zoom) );
2976 idx += get_buttonpress() == 5 ||
2977 gui->ctrl_down() || gui->shift_down() ? -1 : +1 ;
2978 CLAMP(idx, 0, total_zooms-1);
2979 zoom = my_zoom_table[idx];
2982 x = get_cursor_x(); y = get_cursor_y();
2984 mwindow->edl->session->cwindow_scrollbars = 0;
2985 gui->zoom_panel->update(0);
2986 zoom = gui->get_auto_zoom();
2989 gui->zoom_panel->ZoomPanel::update(zoom);
2990 float output_x = x, output_y = y;
2991 canvas_to_output(mwindow->edl, 0, output_x, output_y);
2992 x = output_x - x / zoom;
2993 y = output_y - y / zoom;
2997 mwindow->edl->session->cwindow_scrollbars = 1;
2998 x = (mwindow->edl->session->output_w - w) / 2;
2999 y = (mwindow->edl->session->output_h - h) / 2;
3002 update_zoom((int)x, (int)y, zoom);
3004 gui->composite_panel->cpanel_zoom->update(zoom);
3006 reposition_window(mwindow->edl,
3007 mwindow->theme->ccanvas_x, mwindow->theme->ccanvas_y,
3008 mwindow->theme->ccanvas_w, mwindow->theme->ccanvas_h);
3009 redraw = 1; result = 1;
3015 void CWindowCanvas::calculate_origin()
3017 gui->x_origin = get_cursor_x();
3018 gui->y_origin = get_cursor_y();
3019 //printf("CWindowCanvas::calculate_origin 1 %f %f\n", gui->x_origin, gui->y_origin);
3020 canvas_to_output(mwindow->edl, 0, gui->x_origin, gui->y_origin);
3021 //printf("CWindowCanvas::calculate_origin 2 %f %f\n", gui->x_origin, gui->y_origin);
3025 int CWindowCanvas::cursor_leave_event()
3027 set_cursor(ARROW_CURSOR);
3031 int CWindowCanvas::cursor_enter_event()
3034 switch(mwindow->edl->session->cwindow_operation)
3036 case CWINDOW_CAMERA:
3037 case CWINDOW_PROJECTOR:
3038 set_cursor(MOVE_CURSOR);
3041 set_cursor(MOVE_CURSOR);
3044 test_crop(0, redraw);
3046 case CWINDOW_PROTECT:
3047 set_cursor(ARROW_CURSOR);
3051 set_cursor(CROSS_CURSOR);
3053 case CWINDOW_EYEDROP:
3054 set_cursor(CROSS_CURSOR);
3060 int CWindowCanvas::cursor_motion_event()
3062 int redraw = 0, result = 0, rerender = 0, redraw_canvas = 0;
3065 //printf("CWindowCanvas::cursor_motion_event %d current_operation=%d\n", __LINE__, gui->current_operation);
3066 switch(gui->current_operation)
3068 case CWINDOW_SCROLL:
3070 float zoom = get_zoom();
3071 float cursor_x = get_cursor_x();
3072 float cursor_y = get_cursor_y();
3074 float zoom_x, zoom_y, conformed_w, conformed_h;
3075 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3076 cursor_x = (float)cursor_x / zoom_x + gui->x_offset;
3077 cursor_y = (float)cursor_y / zoom_y + gui->y_offset;
3081 int x = (int)(gui->x_origin - cursor_x + gui->x_offset);
3082 int y = (int)(gui->y_origin - cursor_y + gui->y_offset);
3087 update_scrollbars(0);
3094 result = do_ruler(0, 1, 0, 0);
3097 case CWINDOW_CAMERA:
3098 result = test_bezier(0, redraw, redraw_canvas, rerender, 1);
3101 case CWINDOW_PROJECTOR:
3102 result = test_bezier(0, redraw, redraw_canvas, rerender, 0);
3107 result = test_crop(0, redraw);
3108 // printf("CWindowCanvas::cursor_motion_event %d result=%d redraw=%d\n",
3115 case CWINDOW_MASK_CONTROL_IN:
3116 case CWINDOW_MASK_CONTROL_OUT:
3117 case CWINDOW_MASK_TRANSLATE:
3119 result = do_mask(redraw,
3126 case CWINDOW_EYEDROP:
3127 result = do_eyedrop(rerender, 0, 0);
3136 // cursor font changes
3139 // printf("CWindowCanvas::cursor_motion_event %d cwindow_operation=%d\n",
3141 // mwindow->edl->session->cwindow_operation);
3142 switch(mwindow->edl->session->cwindow_operation)
3145 result = test_crop(0, redraw);
3148 result = do_ruler(0, 1, 0, 0);
3151 result = do_mask(redraw,
3161 // If the window is never unlocked before calling send_command the
3162 // display shouldn't get stuck on the old video frame although it will
3163 // flicker between the old video frame and the new video frame.
3173 gui->unlock_window();
3176 mwindow->gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3177 mwindow->gui->draw_overlays(1);
3178 mwindow->gui->unlock_window();
3180 gui->lock_window("CWindowCanvas::cursor_motion_event 1");
3185 gui->unlock_window();
3186 mwindow->restart_brender();
3187 mwindow->sync_parameters(CHANGE_PARAMS);
3188 mwindow->cwindow->refresh_frame(CHANGE_NONE);
3189 if(!redraw) gui->update_tool();
3190 gui->lock_window("CWindowCanvas::cursor_motion_event 2");
3195 int CWindowCanvas::button_press_event()
3199 int redraw_canvas = 0;
3202 if(Canvas::button_press_event()) return 1;
3204 gui->translating_zoom = gui->shift_down();
3207 //printf("CWindowCanvas::button_press_event 2 %f %f\n", gui->x_origin, gui->y_origin, gui->x_origin, gui->y_origin);
3209 float zoom_x, zoom_y, conformed_w, conformed_h;
3210 get_zooms(mwindow->edl, 0, zoom_x, zoom_y, conformed_w, conformed_h);
3211 gui->x_offset = get_x_offset(mwindow->edl, 0, zoom_x, conformed_w, conformed_h);
3212 gui->y_offset = get_y_offset(mwindow->edl, 0, zoom_y, conformed_w, conformed_h);
3215 if( mwindow->edl->session->cwindow_operation != CWINDOW_PROTECT &&
3216 get_buttonpress() == 2 )
3218 gui->current_operation = CWINDOW_SCROLL;
3224 switch(mwindow->edl->session->cwindow_operation)
3227 result = do_ruler(0, 0, 1, 0);
3230 case CWINDOW_CAMERA:
3231 result = test_bezier(1, redraw, redraw_canvas, rerender, 1);
3234 case CWINDOW_PROJECTOR:
3235 result = test_bezier(1, redraw, redraw_canvas, rerender, 0);
3239 result = test_zoom(redraw);
3243 result = test_crop(1, redraw);
3247 if(get_buttonpress() == 1)
3248 result = do_mask(redraw, rerender, 1, 0, 0);
3251 case CWINDOW_EYEDROP:
3252 result = do_eyedrop(rerender, 1, 0);
3260 gui->unlock_window();
3263 mwindow->gui->lock_window("CWindowCanvas::button_press_event 1");
3264 mwindow->gui->draw_overlays(1);
3265 mwindow->gui->unlock_window();
3268 gui->lock_window("CWindowCanvas::button_press_event 1");
3271 // rerendering can also be caused by press event
3274 gui->unlock_window();
3276 mwindow->restart_brender();
3277 mwindow->sync_parameters(CHANGE_PARAMS);
3278 mwindow->cwindow->refresh_frame(CHANGE_NONE);
3279 if(!redraw) gui->update_tool();
3280 gui->lock_window("CWindowCanvas::button_press_event 2");
3285 int CWindowCanvas::button_release_event()
3289 switch(gui->current_operation)
3291 case CWINDOW_SCROLL:
3296 do_ruler(0, 0, 0, 1);
3299 case CWINDOW_CAMERA:
3300 mwindow->undo->update_undo_after(_("camera"), LOAD_AUTOMATION);
3303 case CWINDOW_PROJECTOR:
3304 mwindow->undo->update_undo_after(_("projector"), LOAD_AUTOMATION);
3308 case CWINDOW_MASK_CONTROL_IN:
3309 case CWINDOW_MASK_CONTROL_OUT:
3310 case CWINDOW_MASK_TRANSLATE:
3311 // Finish mask operation
3312 gui->mask_keyframe = 0;
3313 mwindow->undo->update_undo_after(_("mask"), LOAD_AUTOMATION);
3316 result = Canvas::button_release_event();
3320 gui->current_operation = CWINDOW_NONE;
3324 void CWindowCanvas::zoom_resize_window(float percentage)
3326 int canvas_w, canvas_h;
3330 // Get required canvas size
3331 calculate_sizes(mwindow->edl->get_aspect_ratio(),
3332 mwindow->edl->session->output_w,
3333 mwindow->edl->session->output_h,
3338 // Estimate window size from current borders
3339 new_w = canvas_w + (gui->get_w() - mwindow->theme->ccanvas_w);
3340 new_h = canvas_h + (gui->get_h() - mwindow->theme->ccanvas_h);
3342 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3343 mwindow->session->cwindow_w = new_w;
3344 mwindow->session->cwindow_h = new_h;
3346 mwindow->theme->get_cwindow_sizes(gui,
3347 mwindow->session->cwindow_controls);
3349 // Estimate again from new borders
3350 new_w = canvas_w + (mwindow->session->cwindow_w - mwindow->theme->ccanvas_w);
3351 new_h = canvas_h + (mwindow->session->cwindow_h - mwindow->theme->ccanvas_h);
3352 //printf("CWindowCanvas::zoom_resize_window %d %d %d\n", __LINE__, new_w, new_h);
3354 gui->resize_window(new_w, new_h);
3355 gui->resize_event(new_w, new_h);
3358 void CWindowCanvas::toggle_controls()
3360 mwindow->session->cwindow_controls = !mwindow->session->cwindow_controls;
3361 gui->resize_event(gui->get_w(), gui->get_h());
3364 int CWindowCanvas::get_cwindow_controls()
3366 return mwindow->session->cwindow_controls;