vicon drag tweaks, proxy drag fix, vicon mouseover, binfolder around sort fix, draw_r...
[goodguy/history.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         {
349                 case 'w':
350                 case 'W':
351                         close_event();
352                         result = 1;
353                         break;
354                 case 'z':
355                         mwindow->undo_entry(this);
356                         break;
357                 case 'Z':
358                         mwindow->redo_entry(this);
359                         break;
360                 case 'f':
361                         unlock_window();
362                         if(mwindow->session->vwindow_fullscreen)
363                                 canvas->stop_fullscreen();
364                         else
365                                 canvas->start_fullscreen();
366                         lock_window("VWindowGUI::keypress_event 1");
367                         break;
368                 case ESC:
369                         unlock_window();
370                         if(mwindow->session->vwindow_fullscreen)
371                                 canvas->stop_fullscreen();
372                         lock_window("VWindowGUI::keypress_event 2");
373                         break;
374         }
375         if(!result) result = transport->keypress_event();
376         return result;
377 }
378
379 void VWindowGUI::stop_transport(const char *lock_msg)
380 {
381         if( !transport->is_stopped() ) {
382                 if( lock_msg ) unlock_window();
383                 transport->handle_transport(STOP, 1, 0, 0);
384                 if( lock_msg ) lock_window(lock_msg);
385         }
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
489 void VWindowGUI::update_meters()
490 {
491         if(mwindow->edl->session->vwindow_meter != meters->visible)
492         {
493                 meters->set_meters(meters->meter_count,
494                         mwindow->edl->session->vwindow_meter);
495                 mwindow->theme->get_vwindow_sizes(this);
496                 resize_event(get_w(), get_h());
497         }
498 }
499
500
501
502 VWindowMeters::VWindowMeters(MWindow *mwindow,
503         VWindowGUI *gui,
504         int x,
505         int y,
506         int h)
507  : MeterPanel(mwindow,
508                 gui,
509                 x,
510                 y,
511                 -1,
512                 h,
513                 mwindow->edl->session->audio_channels,
514                 mwindow->edl->session->vwindow_meter,
515                 0,
516                 0)
517 {
518         this->mwindow = mwindow;
519         this->gui = gui;
520 }
521
522 VWindowMeters::~VWindowMeters()
523 {
524 }
525
526 int VWindowMeters::change_status_event(int new_status)
527 {
528         mwindow->edl->session->vwindow_meter = new_status;
529         gui->update_meters();
530         return 1;
531 }
532
533
534 VWindowEditing::VWindowEditing(MWindow *mwindow, VWindow *vwindow)
535  : EditPanel(mwindow, vwindow->gui, VWINDOW_ID,
536                 mwindow->theme->vedit_x, mwindow->theme->vedit_y,
537                 EDITING_ARROW,
538                 0, // use_editing_mode
539                 0, // use_keyframe
540                 1, // use_splice
541                 1, // use_overwrite
542                 0, // use_lift
543                 0, // use_extract
544                 1, // use_copy
545                 0, // use_paste
546                 0, // use_undo
547                 0, // use_fit
548                 0, // locklabels
549                 1, // use_labels
550                 1, // use_toclip
551                 1, // use_meters
552                 0, // use_cut
553                 0, // use_commerical
554                 0, // use_goto
555                 1) // use_clk2play
556 {
557         this->mwindow = mwindow;
558         this->vwindow = vwindow;
559 }
560
561 VWindowEditing::~VWindowEditing()
562 {
563 }
564
565 void VWindowEditing::copy_selection()
566 {
567         vwindow->copy(subwindow->shift_down());
568 }
569
570 void VWindowEditing::splice_selection()
571 {
572         if(vwindow->get_edl())
573         {
574                 mwindow->gui->lock_window("VWindowEditing::splice_selection");
575                 mwindow->splice(vwindow->get_edl(), subwindow->shift_down());
576                 mwindow->gui->unlock_window();
577         }
578 }
579
580 void VWindowEditing::overwrite_selection()
581 {
582         if(vwindow->get_edl())
583         {
584                 mwindow->gui->lock_window("VWindowEditing::overwrite_selection");
585                 mwindow->overwrite(vwindow->get_edl(), subwindow->shift_down());
586                 mwindow->gui->unlock_window();
587         }
588 }
589
590 void VWindowEditing::toggle_label()
591 {
592         if(vwindow->get_edl())
593         {
594                 EDL *edl = vwindow->get_edl();
595                 edl->labels->toggle_label(edl->local_session->get_selectionstart(1),
596                         edl->local_session->get_selectionend(1));
597                 vwindow->gui->timebar->update(1);
598         }
599 }
600
601 void VWindowEditing::prev_label()
602 {
603         if(vwindow->get_edl())
604         {
605                 EDL *edl = vwindow->get_edl();
606                 vwindow->gui->unlock_window();
607                 vwindow->playback_engine->interrupt_playback(1);
608                 vwindow->gui->lock_window("VWindowEditing::prev_label");
609
610                 Label *current = edl->labels->prev_label(
611                         edl->local_session->get_selectionstart(1));
612
613
614                 if(!current)
615                 {
616                         edl->local_session->set_selectionstart(0);
617                         edl->local_session->set_selectionend(0);
618                         vwindow->update_position(CHANGE_NONE, 0, 1, 0);
619                         vwindow->gui->timebar->update(1);
620                 }
621                 else
622                 {
623                         edl->local_session->set_selectionstart(current->position);
624                         edl->local_session->set_selectionend(current->position);
625                         vwindow->update_position(CHANGE_NONE, 0, 1, 0);
626                         vwindow->gui->timebar->update(1);
627                 }
628         }
629 }
630
631 void VWindowEditing::next_label()
632 {
633         if(vwindow->get_edl())
634         {
635                 EDL *edl = vwindow->get_edl();
636                 Label *current = edl->labels->next_label(
637                         edl->local_session->get_selectionstart(1));
638                 if(!current)
639                 {
640                         vwindow->gui->unlock_window();
641                         vwindow->playback_engine->interrupt_playback(1);
642                         vwindow->gui->lock_window("VWindowEditing::next_label 1");
643
644                         double position = edl->tracks->total_length();
645                         edl->local_session->set_selectionstart(position);
646                         edl->local_session->set_selectionend(position);
647                         vwindow->update_position(CHANGE_NONE, 0, 1, 0);
648                         vwindow->gui->timebar->update(1);
649                 }
650                 else
651                 {
652                         vwindow->gui->unlock_window();
653                         vwindow->playback_engine->interrupt_playback(1);
654                         vwindow->gui->lock_window("VWindowEditing::next_label 2");
655
656                         edl->local_session->set_selectionstart(current->position);
657                         edl->local_session->set_selectionend(current->position);
658                         vwindow->update_position(CHANGE_NONE, 0, 1, 0);
659                         vwindow->gui->timebar->update(1);
660                 }
661         }
662 }
663
664 double VWindowEditing::get_position()
665 {
666         EDL *edl = vwindow->get_edl();
667         double position = !edl ? 0 : edl->local_session->get_selectionstart(1);
668         return position;
669 }
670
671 void VWindowEditing::set_position(double position)
672 {
673         EDL *edl = vwindow->get_edl();
674         if( !edl ) return;
675         if( get_position() != position ) {
676                 if( position < 0 ) position = 0;
677                 edl->local_session->set_selectionstart(position);
678                 edl->local_session->set_selectionend(position);
679                 vwindow->update_position(CHANGE_NONE, 0, 1);
680         }
681 }
682
683 void VWindowEditing::set_inpoint()
684 {
685         vwindow->set_inpoint();
686 }
687
688 void VWindowEditing::set_outpoint()
689 {
690         vwindow->set_outpoint();
691 }
692
693 void VWindowEditing::unset_inoutpoint()
694 {
695         vwindow->unset_inoutpoint();
696 }
697
698
699 void VWindowEditing::to_clip()
700 {
701         EDL *edl = vwindow->get_edl();
702         if( !edl ) return;
703         mwindow->to_clip(edl, _("viewer window: "), subwindow->shift_down());
704 }
705
706 VWindowSource::VWindowSource(MWindow *mwindow, VWindowGUI *vwindow, int x, int y)
707  : BC_PopupTextBox(vwindow,
708         &vwindow->sources,
709         "",
710         x,
711         y,
712         200,
713         200)
714 {
715         this->mwindow = mwindow;
716         this->vwindow = vwindow;
717 }
718
719 VWindowSource::~VWindowSource()
720 {
721 }
722
723 int VWindowSource::handle_event()
724 {
725         return 1;
726 }
727
728
729 VWindowTransport::VWindowTransport(MWindow *mwindow,
730         VWindowGUI *gui,
731         int x,
732         int y)
733  : PlayTransport(mwindow,
734         gui,
735         x,
736         y)
737 {
738         this->gui = gui;
739 }
740
741 EDL* VWindowTransport::get_edl()
742 {
743         return gui->vwindow->get_edl();
744 }
745
746
747 void VWindowTransport::goto_start()
748 {
749         gui->unlock_window();
750         handle_transport(REWIND, 1);
751         gui->lock_window("VWindowTransport::goto_start");
752         gui->vwindow->goto_start();
753 }
754
755 void VWindowTransport::goto_end()
756 {
757         gui->unlock_window();
758         handle_transport(GOTO_END, 1);
759         gui->lock_window("VWindowTransport::goto_end");
760         gui->vwindow->goto_end();
761 }
762
763
764
765
766 VWindowCanvas::VWindowCanvas(MWindow *mwindow, VWindowGUI *gui)
767  : Canvas(mwindow,
768         gui,
769         mwindow->theme->vcanvas_x,
770         mwindow->theme->vcanvas_y,
771         mwindow->theme->vcanvas_w,
772         mwindow->theme->vcanvas_h,
773         0, 0, 0)
774 {
775 //printf("VWindowCanvas::VWindowCanvas %d %d\n", __LINE__, mwindow->theme->vcanvas_x);
776         this->mwindow = mwindow;
777         this->gui = gui;
778 }
779
780 void VWindowCanvas::zoom_resize_window(float percentage)
781 {
782         EDL *edl = gui->vwindow->get_edl();
783         if(!edl) edl = mwindow->edl;
784
785         int canvas_w, canvas_h;
786         int new_w, new_h;
787
788 // Get required canvas size
789         calculate_sizes(edl->get_aspect_ratio(),
790                 edl->session->output_w,
791                 edl->session->output_h,
792                 percentage,
793                 canvas_w,
794                 canvas_h);
795
796 // Estimate window size from current borders
797         new_w = canvas_w + (gui->get_w() - mwindow->theme->vcanvas_w);
798         new_h = canvas_h + (gui->get_h() - mwindow->theme->vcanvas_h);
799
800         mwindow->session->vwindow_w = new_w;
801         mwindow->session->vwindow_h = new_h;
802
803         mwindow->theme->get_vwindow_sizes(gui);
804
805 // Estimate again from new borders
806         new_w = canvas_w + (mwindow->session->vwindow_w - mwindow->theme->vcanvas_w);
807         new_h = canvas_h + (mwindow->session->vwindow_h - mwindow->theme->vcanvas_h);
808
809
810         gui->resize_window(new_w, new_h);
811         gui->resize_event(new_w, new_h);
812 }
813
814 void VWindowCanvas::close_source()
815 {
816         gui->unlock_window();
817         gui->vwindow->playback_engine->interrupt_playback(1);
818         gui->lock_window("VWindowCanvas::close_source");
819         gui->vwindow->delete_source(1, 1);
820 }
821
822
823 void VWindowCanvas::draw_refresh(int flush)
824 {
825         EDL *edl = gui->vwindow->get_edl();
826
827         if(!get_canvas()->get_video_on()) get_canvas()->clear_box(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
828         if(!get_canvas()->get_video_on() && refresh_frame && edl)
829         {
830                 float in_x1, in_y1, in_x2, in_y2;
831                 float out_x1, out_y1, out_x2, out_y2;
832                 get_transfers(edl,
833                         in_x1,
834                         in_y1,
835                         in_x2,
836                         in_y2,
837                         out_x1,
838                         out_y1,
839                         out_x2,
840                         out_y2);
841                 get_canvas()->draw_vframe(refresh_frame,
842                                 (int)out_x1,
843                                 (int)out_y1,
844                                 (int)(out_x2 - out_x1),
845                                 (int)(out_y2 - out_y1),
846                                 (int)in_x1,
847                                 (int)in_y1,
848                                 (int)(in_x2 - in_x1),
849                                 (int)(in_y2 - in_y1),
850                                 0);
851         }
852
853         if(!get_canvas()->get_video_on())
854         {
855                 draw_overlays();
856                 get_canvas()->flash(flush);
857         }
858 }
859
860 int VWindowCanvas::need_overlays()
861 {
862         if( gui->highlighted ) return 1;
863         return 0;
864 }
865
866 void VWindowCanvas::draw_overlays()
867 {
868         if( gui->highlighted )
869         {
870                 get_canvas()->set_color(WHITE);
871                 get_canvas()->set_inverse();
872                 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
873                 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
874                 get_canvas()->set_opaque();
875         }
876 }
877
878 int VWindowCanvas::get_fullscreen()
879 {
880         return mwindow->session->vwindow_fullscreen;
881 }
882
883 void VWindowCanvas::set_fullscreen(int value)
884 {
885         mwindow->session->vwindow_fullscreen = value;
886 }
887