ripple edge drag_handle tweaks, sync_parameter fix, shuttlerc, shortcuts
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / vwindowgui.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2011 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "arender.h"
23 #include "asset.h"
24 #include "assets.h"
25 #include "awindowgui.h"
26 #include "awindow.h"
27 #include "cache.h"
28 #include "canvas.h"
29 #include "clip.h"
30 #include "clipedit.h"
31 #include "edl.h"
32 #include "edlsession.h"
33 #include "filesystem.h"
34 #include "filexml.h"
35 #include "fonts.h"
36 #include "keys.h"
37 #include "labels.h"
38 #include "language.h"
39 #include "localsession.h"
40 #include "mainclock.h"
41 #include "mainmenu.h"
42 #include "mainsession.h"
43 #include "mainundo.h"
44 #include "meterpanel.h"
45 #include "mwindowgui.h"
46 #include "mwindow.h"
47 #include "playtransport.h"
48 #include "preferences.h"
49 #include "renderengine.h"
50 #include "samples.h"
51 #include "theme.h"
52 #include "timebar.h"
53 #include "tracks.h"
54 #include "transportque.h"
55 #include "vframe.h"
56 #include "vplayback.h"
57 #include "vtimebar.h"
58 #include "vwindowgui.h"
59 #include "vwindow.h"
60
61
62
63
64 VWindowGUI::VWindowGUI(MWindow *mwindow, VWindow *vwindow)
65  : BC_Window(_(PROGRAM_NAME ": Viewer"),
66         mwindow->session->vwindow_x,
67         mwindow->session->vwindow_y,
68         mwindow->session->vwindow_w,
69         mwindow->session->vwindow_h,
70         100,
71         100,
72         1,
73         1,
74         0) // Hide it
75 {
76         this->mwindow = mwindow;
77         this->vwindow = vwindow;
78         canvas = 0;
79         transport = 0;
80         edit_panel = 0;
81         meters = 0;
82 //      source = 0;
83         strcpy(loaded_title, "");
84         highlighted = 0;
85 }
86
87 VWindowGUI::~VWindowGUI()
88 {
89         vwindow->playback_engine->interrupt_playback(1);
90         sources.remove_all_objects();
91         labels.remove_all_objects();
92         delete canvas;
93         delete transport;
94         delete edit_panel;
95         delete meters;
96 //      delete source;
97 }
98
99 void VWindowGUI::draw_wave()
100 {
101         TransportCommand command;
102         command.command = NORMAL_FWD;
103         command.get_edl()->copy_all(vwindow->get_edl());
104         command.change_type = CHANGE_ALL;
105         command.realtime = 0;
106         RenderEngine *render_engine = new RenderEngine(0, mwindow->preferences, 0, 0);
107         CICache *cache = new CICache(mwindow->preferences);
108         render_engine->set_acache(cache);
109         render_engine->arm_command(&command);
110
111         double duration = 1.;
112         int w = mwindow->edl->session->output_w;
113         int h = mwindow->edl->session->output_h;
114         VFrame *vframe = new VFrame(w, h, BC_RGB888);
115         vframe->clear_frame();
116         int sample_rate = mwindow->edl->get_sample_rate();
117         int channels = mwindow->edl->session->audio_channels;
118         if( channels > 2 ) channels = 2;
119         int64_t bfrsz = sample_rate * duration;
120         Samples *samples[MAXCHANNELS];
121         int ch = 0;
122         while( ch < channels ) samples[ch++] = new Samples(bfrsz);
123         while( ch < MAXCHANNELS ) samples[ch++] = 0;
124         render_engine->arender->process_buffer(samples, bfrsz, 0);
125
126         static int line_colors[2] = { GREEN, YELLOW };
127         static int base_colors[2] = { RED, PINK };
128         for( int i=channels; --i>=0; ) {
129                 AssetPicon::draw_wave(vframe, samples[i]->get_data(), bfrsz,
130                         base_colors[i], line_colors[i]);
131         }
132
133         for( int i=channels; --i>=0; ) delete samples[i];
134         delete render_engine;
135         delete cache;
136         delete canvas->refresh_frame;
137         canvas->refresh_frame = vframe;
138         canvas->draw_refresh(1);
139 }
140
141 void VWindowGUI::change_source(EDL *edl, const char *title)
142 {
143 //printf("VWindowGUI::change_source %d\n", __LINE__);
144
145         update_sources(title);
146         strcpy(loaded_title, title);
147         char string[BCTEXTLEN];
148         if(title[0])
149                 sprintf(string, _(PROGRAM_NAME ": %s"), title);
150         else
151                 sprintf(string, _(PROGRAM_NAME ": Viewer"));
152
153         lock_window("VWindowGUI::change_source");
154         canvas->clear();
155         if( edl &&
156             !edl->tracks->playable_video_tracks() &&
157             edl->tracks->playable_audio_tracks() )
158                 draw_wave();
159         timebar->update(0);
160         set_title(string);
161         unlock_window();
162 }
163
164
165 // Get source list from master EDL
166 void VWindowGUI::update_sources(const char *title)
167 {
168         lock_window("VWindowGUI::update_sources");
169         sources.remove_all_objects();
170
171         for( int i=0; i<mwindow->edl->clips.size(); ++i ) {
172                 char *clip_title = mwindow->edl->clips.values[i]->local_session->clip_title;
173                 int exists = 0;
174
175                 for( int j=0; !exists && j<sources.size(); ++j ) {
176                         if( !strcasecmp(sources.values[j]->get_text(), clip_title) )
177                                 exists = 1;
178                 }
179
180                 if( !exists )
181                         sources.append(new BC_ListBoxItem(clip_title));
182         }
183
184         FileSystem fs;
185         for( Asset *current=mwindow->edl->assets->first; current; current=NEXT ) {
186                 char clip_title[BCTEXTLEN];
187                 fs.extract_name(clip_title, current->path);
188                 int exists = 0;
189
190                 for( int j=0; !exists && j<sources.size(); ++j ) {
191                         if( !strcasecmp(sources.values[j]->get_text(), clip_title) )
192                                 exists = 1;
193                 }
194
195                 if( !exists )
196                         sources.append(new BC_ListBoxItem(clip_title));
197         }
198
199         unlock_window();
200 }
201
202 void VWindowGUI::create_objects()
203 {
204         lock_window("VWindowGUI::create_objects");
205         in_point = 0;
206         out_point = 0;
207         set_icon(mwindow->theme->get_image("vwindow_icon"));
208
209 //printf("VWindowGUI::create_objects 1\n");
210         mwindow->theme->get_vwindow_sizes(this);
211         mwindow->theme->draw_vwindow_bg(this);
212         flash(0);
213
214         meters = new VWindowMeters(mwindow,
215                 this,
216                 mwindow->theme->vmeter_x,
217                 mwindow->theme->vmeter_y,
218                 mwindow->theme->vmeter_h);
219         meters->create_objects();
220
221 //printf("VWindowGUI::create_objects 1\n");
222 // Requires meters to build
223         edit_panel = new VWindowEditing(mwindow, vwindow);
224         edit_panel->set_meters(meters);
225         edit_panel->create_objects();
226
227 //printf("VWindowGUI::create_objects 1\n");
228         transport = new VWindowTransport(mwindow,
229                 this,
230                 mwindow->theme->vtransport_x,
231                 mwindow->theme->vtransport_y);
232         transport->create_objects();
233
234 //printf("VWindowGUI::create_objects 1\n");
235 //      add_subwindow(fps_title = new BC_Title(mwindow->theme->vedit_x, y, ""));
236     add_subwindow(clock = new MainClock(mwindow,
237                 mwindow->theme->vtime_x,
238                 mwindow->theme->vtime_y,
239                 mwindow->theme->vtime_w));
240
241         canvas = new VWindowCanvas(mwindow, this);
242         canvas->create_objects(mwindow->edl);
243         canvas->use_vwindow();
244
245
246 //printf("VWindowGUI::create_objects 1\n");
247         add_subwindow(timebar = new VTimeBar(mwindow,
248                 this,
249                 mwindow->theme->vtimebar_x,
250                 mwindow->theme->vtimebar_y,
251                 mwindow->theme->vtimebar_w,
252                 mwindow->theme->vtimebar_h));
253         timebar->create_objects();
254 //printf("VWindowGUI::create_objects 2\n");
255
256
257 //printf("VWindowGUI::create_objects 1\n");
258 //      source = new VWindowSource(mwindow,
259 //              this,
260 //              mwindow->theme->vsource_x,
261 //              mwindow->theme->vsource_y);
262 //      source->create_objects();
263         update_sources(_("None"));
264
265 //printf("VWindowGUI::create_objects 2\n");
266         deactivate();
267
268         show_window();
269         unlock_window();
270 }
271
272 int VWindowGUI::resize_event(int w, int h)
273 {
274         mwindow->session->vwindow_x = get_x();
275         mwindow->session->vwindow_y = get_y();
276         mwindow->session->vwindow_w = w;
277         mwindow->session->vwindow_h = h;
278
279         mwindow->theme->get_vwindow_sizes(this);
280         mwindow->theme->draw_vwindow_bg(this);
281         flash(0);
282
283 //printf("VWindowGUI::resize_event %d %d\n", __LINE__, mwindow->theme->vedit_y);
284         edit_panel->reposition_buttons(mwindow->theme->vedit_x,
285                 mwindow->theme->vedit_y);
286
287         timebar->resize_event();
288         transport->reposition_buttons(mwindow->theme->vtransport_x,
289                 mwindow->theme->vtransport_y);
290         clock->reposition_window(mwindow->theme->vtime_x,
291                 mwindow->theme->vtime_y,
292                 mwindow->theme->vtime_w,
293                 clock->get_h());
294         canvas->reposition_window(0,
295                 mwindow->theme->vcanvas_x,
296                 mwindow->theme->vcanvas_y,
297                 mwindow->theme->vcanvas_w,
298                 mwindow->theme->vcanvas_h);
299 //printf("VWindowGUI::resize_event %d %d\n", __LINE__, mwindow->theme->vcanvas_x);
300 //      source->reposition_window(mwindow->theme->vsource_x,
301 //              mwindow->theme->vsource_y);
302         meters->reposition_window(mwindow->theme->vmeter_x,
303                 mwindow->theme->vmeter_y,
304                 -1,
305                 mwindow->theme->vmeter_h);
306
307         BC_WindowBase::resize_event(w, h);
308         return 1;
309 }
310
311
312
313
314
315 int VWindowGUI::translation_event()
316 {
317         mwindow->session->vwindow_x = get_x();
318         mwindow->session->vwindow_y = get_y();
319         return 0;
320 }
321
322 int VWindowGUI::close_event()
323 {
324         hide_window();
325         int i = mwindow->vwindows.size();
326         while( --i >= 0 && mwindow->vwindows.get(i)->gui != this );
327         if( i > 0 ) {
328                 set_done(0);
329                 return 1;
330         }
331
332         mwindow->session->show_vwindow = 0;
333         unlock_window();
334
335         mwindow->gui->lock_window("VWindowGUI::close_event");
336         mwindow->gui->mainmenu->show_vwindow->set_checked(0);
337         mwindow->gui->unlock_window();
338
339         lock_window("VWindowGUI::close_event");
340         mwindow->save_defaults();
341         return 1;
342 }
343
344 int VWindowGUI::keypress_event()
345 {
346         int result = 0;
347         switch( get_keypress() ) {
348         case 'w':
349         case 'W':
350                 close_event();
351                 result = 1;
352                 break;
353         case 'z':
354                 mwindow->undo_entry(this);
355                 break;
356         case 'Z':
357                 mwindow->redo_entry(this);
358                 break;
359         case 'f':
360                 unlock_window();
361                 if(mwindow->session->vwindow_fullscreen)
362                         canvas->stop_fullscreen();
363                 else
364                         canvas->start_fullscreen();
365                 lock_window("VWindowGUI::keypress_event 1");
366                 break;
367         case ESC:
368                 unlock_window();
369                 if(mwindow->session->vwindow_fullscreen)
370                         canvas->stop_fullscreen();
371                 lock_window("VWindowGUI::keypress_event 2");
372                 break;
373         case KEY_F1:
374         case KEY_F2:
375         case KEY_F3:
376         case KEY_F4:
377                 if( ctrl_down() && shift_down() ) {
378                         resend_event(mwindow->gui);
379                         result = 1;
380                         break;
381                 }
382         }
383         if( !result )
384                 result = transport->keypress_event();
385         return result;
386 }
387
388 int VWindowGUI::button_press_event()
389 {
390         if( vwindow->get_edl() != 0 && canvas->get_canvas() &&
391             mwindow->edl->session->vwindow_click2play &&
392             canvas->get_canvas()->get_cursor_over_window() ) {
393                 switch( get_buttonpress() ) {
394                 case LEFT_BUTTON:
395                         if( !vwindow->playback_engine->is_playing_back ) {
396                                 double length = vwindow->get_edl()->tracks->total_playable_length();
397                                 double position = vwindow->playback_engine->get_tracking_position();
398                                 if( position >= length ) transport->goto_start();
399                         }
400                         return transport->forward_play->handle_event();
401                 case MIDDLE_BUTTON:
402                         if( !vwindow->playback_engine->is_playing_back ) {
403                                 double position = vwindow->playback_engine->get_tracking_position();
404                                 if( position <= 0 ) transport->goto_end();
405                         }
406                         return transport->reverse_play->handle_event();
407                 case RIGHT_BUTTON:  // activates popup
408                         break;
409                 case WHEEL_UP:
410                         return transport->frame_forward_play->handle_event();
411                 case WHEEL_DOWN:
412                         return transport->frame_reverse_play->handle_event();
413                 }
414         }
415         if(canvas->get_canvas())
416                 return canvas->button_press_event_base(canvas->get_canvas());
417         return 0;
418 }
419
420 int VWindowGUI::cursor_leave_event()
421 {
422         if(canvas->get_canvas())
423                 return canvas->cursor_leave_event_base(canvas->get_canvas());
424         return 0;
425 }
426
427 int VWindowGUI::cursor_enter_event()
428 {
429         if(canvas->get_canvas())
430                 return canvas->cursor_enter_event_base(canvas->get_canvas());
431         return 0;
432 }
433
434 int VWindowGUI::button_release_event()
435 {
436         if(canvas->get_canvas())
437                 return canvas->button_release_event();
438         return 0;
439 }
440
441 int VWindowGUI::cursor_motion_event()
442 {
443         if(canvas->get_canvas())
444         {
445                 canvas->get_canvas()->unhide_cursor();
446                 return canvas->cursor_motion_event();
447         }
448         return 0;
449 }
450
451
452 void VWindowGUI::drag_motion()
453 {
454 // Window hidden
455         if(get_hidden()) return;
456         if(mwindow->session->current_operation != DRAG_ASSET) return;
457         int need_highlight = cursor_above() && get_cursor_over_window() ? 1 : 0;
458         if( highlighted == need_highlight ) return;
459         highlighted = need_highlight;
460         canvas->draw_refresh();
461 }
462
463 int VWindowGUI::drag_stop()
464 {
465         if( get_hidden() ) return 0;
466
467         if( highlighted &&
468             mwindow->session->current_operation == DRAG_ASSET ) {
469                 highlighted = 0;
470                 canvas->draw_refresh();
471                 unlock_window();
472
473                 Indexable *indexable =
474                         mwindow->session->drag_assets->size() > 0 ?
475                                 (Indexable *)mwindow->session->drag_assets->get(0) :
476                         mwindow->session->drag_clips->size() > 0 ?
477                                 (Indexable *)mwindow->session->drag_clips->get(0) : 0;
478                 if( indexable )
479                         vwindow->change_source(indexable);
480
481                 lock_window("VWindowGUI::drag_stop");
482                 return 1;
483         }
484
485         return 0;
486 }
487
488 void VWindowGUI::stop_transport()
489 {
490         if( !transport->is_stopped() ) {
491                 unlock_window();
492                 transport->handle_transport(STOP, 1);
493                 lock_window("VWindowGUI::panel_stop_transport");
494         }
495 }
496
497 void VWindowGUI::update_meters()
498 {
499         if(mwindow->edl->session->vwindow_meter != meters->visible)
500         {
501                 meters->set_meters(meters->meter_count,
502                         mwindow->edl->session->vwindow_meter);
503                 mwindow->theme->get_vwindow_sizes(this);
504                 resize_event(get_w(), get_h());
505         }
506 }
507
508
509
510 VWindowMeters::VWindowMeters(MWindow *mwindow,
511         VWindowGUI *gui,
512         int x,
513         int y,
514         int h)
515  : MeterPanel(mwindow,
516                 gui,
517                 x,
518                 y,
519                 -1,
520                 h,
521                 mwindow->edl->session->audio_channels,
522                 mwindow->edl->session->vwindow_meter,
523                 0,
524                 0)
525 {
526         this->mwindow = mwindow;
527         this->gui = gui;
528 }
529
530 VWindowMeters::~VWindowMeters()
531 {
532 }
533
534 int VWindowMeters::change_status_event(int new_status)
535 {
536         mwindow->edl->session->vwindow_meter = new_status;
537         gui->update_meters();
538         return 1;
539 }
540
541
542 VWindowEditing::VWindowEditing(MWindow *mwindow, VWindow *vwindow)
543  : EditPanel(mwindow, vwindow->gui, VWINDOW_ID,
544                 mwindow->theme->vedit_x, mwindow->theme->vedit_y,
545                 EDITING_ARROW,
546                 0, // use_editing_mode
547                 0, // use_keyframe
548                 1, // use_splice
549                 1, // use_overwrite
550                 1, // use_copy
551                 0, // use_paste
552                 0, // use_undo
553                 0, // use_fit
554                 0, // locklabels
555                 1, // use_labels
556                 1, // use_toclip
557                 1, // use_meters
558                 0, // use_cut
559                 0, // use_commerical
560                 0, // use_goto
561                 1) // use_clk2play
562 {
563         this->mwindow = mwindow;
564         this->vwindow = vwindow;
565 }
566
567 VWindowEditing::~VWindowEditing()
568 {
569 }
570
571 #define relock_vm(s) \
572  vwindow->gui->unlock_window(); \
573  mwindow->gui->lock_window("VWindowEditing::" s)
574 #define relock_mv(s) \
575  mwindow->gui->unlock_window(); \
576  vwindow->gui->lock_window("VWindowEditing::" s)
577
578 double VWindowEditing::get_position()
579 {
580         EDL *edl = vwindow->get_edl();
581         double position = !edl ? 0 : edl->local_session->get_selectionstart(1);
582         return position;
583 }
584
585 void VWindowEditing::set_position(double position)
586 {
587         EDL *edl = vwindow->get_edl();
588         if( !edl ) return;
589         if( get_position() != position ) {
590                 if( position < 0 ) position = 0;
591                 edl->local_session->set_selectionstart(position);
592                 edl->local_session->set_selectionend(position);
593                 vwindow->update_position();
594         }
595 }
596
597 void VWindowEditing::set_click_to_play(int v)
598 {
599         click2play->update(v);
600         relock_vm("set_click_to_play");
601         mwindow->edl->session->vwindow_click2play = v;
602         mwindow->update_vwindow();
603         relock_mv("set_click_to_play");
604 }
605
606 void VWindowEditing::panel_stop_transport()
607 {
608         vwindow->gui->stop_transport();
609 }
610
611 void VWindowEditing::panel_toggle_label()
612 {
613         if( !vwindow->get_edl() ) return;
614         EDL *edl = vwindow->get_edl();
615         edl->labels->toggle_label(edl->local_session->get_selectionstart(1),
616                 edl->local_session->get_selectionend(1));
617         vwindow->gui->timebar->update(1);
618 }
619
620 void VWindowEditing::panel_next_label(int cut)
621 {
622         if( !vwindow->get_edl() ) return;
623         vwindow->interrupt_playback(1);
624
625         EDL *edl = vwindow->get_edl();
626         Label *current = edl->labels->next_label(
627                 edl->local_session->get_selectionstart(1));
628         double position = current ? current->position :
629                 edl->tracks->total_length();
630         edl->local_session->set_selectionstart(position);
631         edl->local_session->set_selectionend(position);
632         vwindow->update_position();
633         vwindow->gui->timebar->update(1);
634 }
635
636 void VWindowEditing::panel_prev_label(int cut)
637 {
638         if( !vwindow->get_edl() ) return;
639         vwindow->interrupt_playback(1);
640
641         EDL *edl = vwindow->get_edl();
642         Label *current = edl->labels->prev_label(
643                 edl->local_session->get_selectionstart(1));
644         double position = !current ? 0 : current->position;
645         edl->local_session->set_selectionstart(position);
646         edl->local_session->set_selectionend(position);
647         vwindow->update_position();
648         vwindow->gui->timebar->update(1);
649 }
650
651 void VWindowEditing::panel_prev_edit(int cut) {} // not used
652 void VWindowEditing::panel_next_edit(int cut) {} // not used
653
654 void VWindowEditing::panel_copy_selection()
655 {
656         vwindow->copy(vwindow->gui->shift_down());
657 }
658
659 void VWindowEditing::panel_overwrite_selection()
660 {
661         if( !vwindow->get_edl() ) return;
662         relock_vm("overwrite_selection");
663         mwindow->overwrite(vwindow->get_edl(), vwindow->gui->shift_down());
664         relock_mv("overwrite_selection");
665 }
666
667 void VWindowEditing::panel_splice_selection()
668 {
669         if( !vwindow->get_edl() ) return;
670         relock_vm("splice_selection");
671         mwindow->splice(vwindow->get_edl(), vwindow->gui->shift_down());
672         relock_mv("splice_selection");
673 }
674
675 void VWindowEditing::panel_set_inpoint()
676 {
677         vwindow->set_inpoint();
678 }
679
680 void VWindowEditing::panel_set_outpoint()
681 {
682         vwindow->set_outpoint();
683 }
684
685 void VWindowEditing::panel_unset_inoutpoint()
686 {
687         vwindow->unset_inoutpoint();
688 }
689
690 void VWindowEditing::panel_to_clip()
691 {
692         EDL *edl = vwindow->get_edl();
693         if( !edl ) return;
694         mwindow->to_clip(edl, _("viewer window: "), subwindow->shift_down());
695 }
696
697 // not used
698 void VWindowEditing::panel_cut() {}
699 void VWindowEditing::panel_paste() {}
700 void VWindowEditing::panel_fit_selection() {}
701 void VWindowEditing::panel_fit_autos(int all) {}
702 void VWindowEditing::panel_set_editing_mode(int mode) {}
703 void VWindowEditing::panel_set_auto_keyframes(int v) {}
704 void VWindowEditing::panel_set_labels_follow_edits(int v) {}
705
706
707 VWindowSource::VWindowSource(MWindow *mwindow, VWindowGUI *vwindow, int x, int y)
708  : BC_PopupTextBox(vwindow,
709         &vwindow->sources,
710         "",
711         x,
712         y,
713         200,
714         200)
715 {
716         this->mwindow = mwindow;
717         this->vwindow = vwindow;
718 }
719
720 VWindowSource::~VWindowSource()
721 {
722 }
723
724 int VWindowSource::handle_event()
725 {
726         return 1;
727 }
728
729
730 VWindowTransport::VWindowTransport(MWindow *mwindow,
731         VWindowGUI *gui,
732         int x,
733         int y)
734  : PlayTransport(mwindow,
735         gui,
736         x,
737         y)
738 {
739         this->gui = gui;
740 }
741
742 EDL* VWindowTransport::get_edl()
743 {
744         return gui->vwindow->get_edl();
745 }
746
747
748 void VWindowTransport::goto_start()
749 {
750         gui->unlock_window();
751         handle_transport(REWIND, 1);
752         gui->lock_window("VWindowTransport::goto_start");
753         gui->vwindow->goto_start();
754 }
755
756 void VWindowTransport::goto_end()
757 {
758         gui->unlock_window();
759         handle_transport(GOTO_END, 1);
760         gui->lock_window("VWindowTransport::goto_end");
761         gui->vwindow->goto_end();
762 }
763
764
765
766
767 VWindowCanvas::VWindowCanvas(MWindow *mwindow, VWindowGUI *gui)
768  : Canvas(mwindow,
769         gui,
770         mwindow->theme->vcanvas_x,
771         mwindow->theme->vcanvas_y,
772         mwindow->theme->vcanvas_w,
773         mwindow->theme->vcanvas_h,
774         0, 0, 0)
775 {
776 //printf("VWindowCanvas::VWindowCanvas %d %d\n", __LINE__, mwindow->theme->vcanvas_x);
777         this->mwindow = mwindow;
778         this->gui = gui;
779 }
780
781 void VWindowCanvas::zoom_resize_window(float percentage)
782 {
783         EDL *edl = gui->vwindow->get_edl();
784         if(!edl) edl = mwindow->edl;
785
786         int canvas_w, canvas_h;
787         int new_w, new_h;
788
789 // Get required canvas size
790         calculate_sizes(edl->get_aspect_ratio(),
791                 edl->session->output_w,
792                 edl->session->output_h,
793                 percentage,
794                 canvas_w,
795                 canvas_h);
796
797 // Estimate window size from current borders
798         new_w = canvas_w + (gui->get_w() - mwindow->theme->vcanvas_w);
799         new_h = canvas_h + (gui->get_h() - mwindow->theme->vcanvas_h);
800
801         mwindow->session->vwindow_w = new_w;
802         mwindow->session->vwindow_h = new_h;
803
804         mwindow->theme->get_vwindow_sizes(gui);
805
806 // Estimate again from new borders
807         new_w = canvas_w + (mwindow->session->vwindow_w - mwindow->theme->vcanvas_w);
808         new_h = canvas_h + (mwindow->session->vwindow_h - mwindow->theme->vcanvas_h);
809
810
811         gui->resize_window(new_w, new_h);
812         gui->resize_event(new_w, new_h);
813 }
814
815 void VWindowCanvas::close_source()
816 {
817         gui->vwindow->interrupt_playback(1);
818         gui->vwindow->delete_source(1, 1);
819 }
820
821
822 void VWindowCanvas::draw_refresh(int flush)
823 {
824         EDL *edl = gui->vwindow->get_edl();
825
826         if(!get_canvas()->get_video_on()) get_canvas()->clear_box(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
827         if(!get_canvas()->get_video_on() && refresh_frame && edl)
828         {
829                 float in_x1, in_y1, in_x2, in_y2;
830                 float out_x1, out_y1, out_x2, out_y2;
831                 get_transfers(edl,
832                         in_x1, in_y1, in_x2, in_y2,
833                         out_x1, out_y1, out_x2, out_y2);
834 // input scaled from session to refresh frame coordinates
835                 int ow = get_output_w(edl);
836                 int oh = get_output_h(edl);
837                 int rw = refresh_frame->get_w();
838                 int rh = refresh_frame->get_h();
839                 float xs = (float)rw / ow;
840                 float ys = (float)rh / oh;
841                 in_x1 *= xs;  in_x2 *= xs;
842                 in_y1 *= ys;  in_y2 *= ys;
843                 get_canvas()->draw_vframe(refresh_frame,
844                                 (int)out_x1,
845                                 (int)out_y1,
846                                 (int)(out_x2 - out_x1),
847                                 (int)(out_y2 - out_y1),
848                                 (int)in_x1,
849                                 (int)in_y1,
850                                 (int)(in_x2 - in_x1),
851                                 (int)(in_y2 - in_y1),
852                                 0);
853         }
854
855         if(!get_canvas()->get_video_on())
856         {
857                 draw_overlays();
858                 get_canvas()->flash(flush);
859         }
860 }
861
862 int VWindowCanvas::need_overlays()
863 {
864         if( gui->highlighted ) return 1;
865         return 0;
866 }
867
868 void VWindowCanvas::draw_overlays()
869 {
870         if( gui->highlighted )
871         {
872                 get_canvas()->set_color(WHITE);
873                 get_canvas()->set_inverse();
874                 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
875                 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
876                 get_canvas()->set_opaque();
877         }
878 }
879
880 int VWindowCanvas::get_fullscreen()
881 {
882         return mwindow->session->vwindow_fullscreen;
883 }
884
885 void VWindowCanvas::set_fullscreen(int value)
886 {
887         mwindow->session->vwindow_fullscreen = value;
888 }
889