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