4458eb764c80ba1bf608fd1e25f80f5284a1c9c4
[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 "asset.h"
23 #include "assets.h"
24 #include "awindowgui.h"
25 #include "awindow.h"
26 #include "canvas.h"
27 #include "clip.h"
28 #include "clipedit.h"
29 #include "edl.h"
30 #include "edlsession.h"
31 #include "filesystem.h"
32 #include "filexml.h"
33 #include "fonts.h"
34 #include "keys.h"
35 #include "labels.h"
36 #include "language.h"
37 #include "localsession.h"
38 #include "mainclock.h"
39 #include "mainmenu.h"
40 #include "mainsession.h"
41 #include "mainundo.h"
42 #include "meterpanel.h"
43 #include "mwindowgui.h"
44 #include "mwindow.h"
45 #include "playtransport.h"
46 #include "preferences.h"
47 #include "theme.h"
48 #include "timebar.h"
49 #include "tracks.h"
50 #include "vframe.h"
51 #include "vplayback.h"
52 #include "vtimebar.h"
53 #include "vwindowgui.h"
54 #include "vwindow.h"
55
56
57
58
59 VWindowGUI::VWindowGUI(MWindow *mwindow, VWindow *vwindow)
60  : BC_Window(_(PROGRAM_NAME ": Viewer"),
61         mwindow->session->vwindow_x,
62         mwindow->session->vwindow_y,
63         mwindow->session->vwindow_w,
64         mwindow->session->vwindow_h,
65         100,
66         100,
67         1,
68         1,
69         0) // Hide it
70 {
71         this->mwindow = mwindow;
72         this->vwindow = vwindow;
73         canvas = 0;
74         transport = 0;
75         edit_panel = 0;
76         meters = 0;
77 //      source = 0;
78         strcpy(loaded_title, "");
79         highlighted = 0;
80 }
81
82 VWindowGUI::~VWindowGUI()
83 {
84         vwindow->playback_engine->interrupt_playback(1);
85         sources.remove_all_objects();
86         labels.remove_all_objects();
87         delete canvas;
88         delete transport;
89         delete edit_panel;
90         delete meters;
91 //      delete source;
92 }
93
94 void VWindowGUI::change_source(EDL *edl, const char *title)
95 {
96 //printf("VWindowGUI::change_source %d\n", __LINE__);
97
98         update_sources(title);
99         strcpy(loaded_title, title);
100         char string[BCTEXTLEN];
101         if(title[0])
102                 sprintf(string, _(PROGRAM_NAME ": %s"), title);
103         else
104                 sprintf(string, _(PROGRAM_NAME ": Viewer"));
105
106         lock_window("VWindowGUI::change_source");
107         canvas->clear();
108         timebar->update(0);
109         set_title(string);
110         unlock_window();
111 }
112
113
114 // Get source list from master EDL
115 void VWindowGUI::update_sources(const char *title)
116 {
117         lock_window("VWindowGUI::update_sources");
118
119 //printf("VWindowGUI::update_sources 1\n");
120         sources.remove_all_objects();
121 //printf("VWindowGUI::update_sources 2\n");
122
123
124
125         for(int i = 0;
126                 i < mwindow->edl->clips.total;
127                 i++)
128         {
129                 char *clip_title = mwindow->edl->clips.values[i]->local_session->clip_title;
130                 int exists = 0;
131
132                 for(int j = 0; j < sources.total; j++)
133                 {
134                         if(!strcasecmp(sources.values[j]->get_text(), clip_title))
135                         {
136                                 exists = 1;
137                         }
138                 }
139
140                 if(!exists)
141                 {
142                         sources.append(new BC_ListBoxItem(clip_title));
143                 }
144         }
145 //printf("VWindowGUI::update_sources 3\n");
146
147         FileSystem fs;
148         for(Asset *current = mwindow->edl->assets->first;
149                 current;
150                 current = NEXT)
151         {
152                 char clip_title[BCTEXTLEN];
153                 fs.extract_name(clip_title, current->path);
154                 int exists = 0;
155
156                 for(int j = 0; j < sources.total; j++)
157                 {
158                         if(!strcasecmp(sources.values[j]->get_text(), clip_title))
159                         {
160                                 exists = 1;
161                         }
162                 }
163
164                 if(!exists)
165                 {
166                         sources.append(new BC_ListBoxItem(clip_title));
167                 }
168         }
169
170 //printf("VWindowGUI::update_sources 4\n");
171
172 //      source->update_list(&sources);
173 //      source->update(title);
174         unlock_window();
175 }
176
177 void VWindowGUI::create_objects()
178 {
179         in_point = 0;
180         out_point = 0;
181         lock_window("VWindowGUI::create_objects");
182         set_icon(mwindow->theme->get_image("vwindow_icon"));
183
184 //printf("VWindowGUI::create_objects 1\n");
185         mwindow->theme->get_vwindow_sizes(this);
186         mwindow->theme->draw_vwindow_bg(this);
187         flash(0);
188
189         meters = new VWindowMeters(mwindow,
190                 this,
191                 mwindow->theme->vmeter_x,
192                 mwindow->theme->vmeter_y,
193                 mwindow->theme->vmeter_h);
194         meters->create_objects();
195
196 //printf("VWindowGUI::create_objects 1\n");
197 // Requires meters to build
198         edit_panel = new VWindowEditing(mwindow, vwindow);
199         edit_panel->set_meters(meters);
200         edit_panel->create_objects();
201
202 //printf("VWindowGUI::create_objects 1\n");
203         transport = new VWindowTransport(mwindow,
204                 this,
205                 mwindow->theme->vtransport_x,
206                 mwindow->theme->vtransport_y);
207         transport->create_objects();
208
209 //printf("VWindowGUI::create_objects 1\n");
210 //      add_subwindow(fps_title = new BC_Title(mwindow->theme->vedit_x, y, ""));
211     add_subwindow(clock = new MainClock(mwindow,
212                 mwindow->theme->vtime_x,
213                 mwindow->theme->vtime_y,
214                 mwindow->theme->vtime_w));
215
216         canvas = new VWindowCanvas(mwindow, this);
217         canvas->create_objects(mwindow->edl);
218         canvas->use_vwindow();
219
220
221 //printf("VWindowGUI::create_objects 1\n");
222         add_subwindow(timebar = new VTimeBar(mwindow,
223                 this,
224                 mwindow->theme->vtimebar_x,
225                 mwindow->theme->vtimebar_y,
226                 mwindow->theme->vtimebar_w,
227                 mwindow->theme->vtimebar_h));
228         timebar->create_objects();
229 //printf("VWindowGUI::create_objects 2\n");
230
231
232 //printf("VWindowGUI::create_objects 1\n");
233 //      source = new VWindowSource(mwindow,
234 //              this,
235 //              mwindow->theme->vsource_x,
236 //              mwindow->theme->vsource_y);
237 //      source->create_objects();
238         update_sources(_("None"));
239
240 //printf("VWindowGUI::create_objects 2\n");
241         deactivate();
242
243         show_window();
244         unlock_window();
245 }
246
247 int VWindowGUI::resize_event(int w, int h)
248 {
249         mwindow->session->vwindow_x = get_x();
250         mwindow->session->vwindow_y = get_y();
251         mwindow->session->vwindow_w = w;
252         mwindow->session->vwindow_h = h;
253
254         mwindow->theme->get_vwindow_sizes(this);
255         mwindow->theme->draw_vwindow_bg(this);
256         flash(0);
257
258 //printf("VWindowGUI::resize_event %d %d\n", __LINE__, mwindow->theme->vedit_y);
259         edit_panel->reposition_buttons(mwindow->theme->vedit_x,
260                 mwindow->theme->vedit_y);
261
262         timebar->resize_event();
263         transport->reposition_buttons(mwindow->theme->vtransport_x,
264                 mwindow->theme->vtransport_y);
265         clock->reposition_window(mwindow->theme->vtime_x,
266                 mwindow->theme->vtime_y,
267                 mwindow->theme->vtime_w,
268                 clock->get_h());
269         canvas->reposition_window(0,
270                 mwindow->theme->vcanvas_x,
271                 mwindow->theme->vcanvas_y,
272                 mwindow->theme->vcanvas_w,
273                 mwindow->theme->vcanvas_h);
274 //printf("VWindowGUI::resize_event %d %d\n", __LINE__, mwindow->theme->vcanvas_x);
275 //      source->reposition_window(mwindow->theme->vsource_x,
276 //              mwindow->theme->vsource_y);
277         meters->reposition_window(mwindow->theme->vmeter_x,
278                 mwindow->theme->vmeter_y,
279                 -1,
280                 mwindow->theme->vmeter_h);
281
282         BC_WindowBase::resize_event(w, h);
283         return 1;
284 }
285
286
287
288
289
290 int VWindowGUI::translation_event()
291 {
292         mwindow->session->vwindow_x = get_x();
293         mwindow->session->vwindow_y = get_y();
294         return 0;
295 }
296
297 int VWindowGUI::close_event()
298 {
299         hide_window();
300         int i = mwindow->vwindows.size();
301         while( --i >= 0 && mwindow->vwindows.get(i)->gui != this );
302         if( i > 0 ) {
303                 set_done(0);
304                 return 1;
305         }
306
307         mwindow->session->show_vwindow = 0;
308         unlock_window();
309
310         mwindow->gui->lock_window("VWindowGUI::close_event");
311         mwindow->gui->mainmenu->show_vwindow->set_checked(0);
312         mwindow->gui->unlock_window();
313
314         lock_window("VWindowGUI::close_event");
315         mwindow->save_defaults();
316         return 1;
317 }
318
319 int VWindowGUI::keypress_event()
320 {
321         int result = 0;
322         switch(get_keypress())
323         {
324                 case 'w':
325                 case 'W':
326                         close_event();
327                         result = 1;
328                         break;
329                 case 'z':
330                         mwindow->undo_entry(this);
331                         break;
332                 case 'Z':
333                         mwindow->redo_entry(this);
334                         break;
335                 case 'f':
336                         unlock_window();
337                         if(mwindow->session->vwindow_fullscreen)
338                                 canvas->stop_fullscreen();
339                         else
340                                 canvas->start_fullscreen();
341                         lock_window("VWindowGUI::keypress_event 1");
342                         break;
343                 case ESC:
344                         unlock_window();
345                         if(mwindow->session->vwindow_fullscreen)
346                                 canvas->stop_fullscreen();
347                         lock_window("VWindowGUI::keypress_event 2");
348                         break;
349         }
350         if(!result) result = transport->keypress_event();
351
352         return result;
353 }
354
355 void VWindowGUI::stop_transport(const char *lock_msg)
356 {
357         if( !transport->is_stopped() ) {
358                 if( lock_msg ) unlock_window();
359                 transport->handle_transport(STOP, 1, 0, 0);
360                 if( lock_msg ) lock_window(lock_msg);
361         }
362 }
363
364 int VWindowGUI::button_press_event()
365 {
366         if( get_buttonpress() == LEFT_BUTTON && canvas->get_canvas() &&
367             canvas->get_canvas()->get_cursor_over_window() ) {
368                 PlaybackEngine *playback_engine = vwindow->playback_engine;
369                 if( !playback_engine->is_playing_back && vwindow->get_edl() != 0 ) {
370                         double length = vwindow->get_edl()->tracks->total_playable_length();
371                         double position = playback_engine->get_tracking_position();
372                         if( position >= length ) transport->goto_start();
373                 }
374                 return transport->forward_play->handle_event();
375         }
376         if(canvas->get_canvas())
377                 return canvas->button_press_event_base(canvas->get_canvas());
378         return 0;
379 }
380
381 int VWindowGUI::cursor_leave_event()
382 {
383         if(canvas->get_canvas())
384                 return canvas->cursor_leave_event_base(canvas->get_canvas());
385         return 0;
386 }
387
388 int VWindowGUI::cursor_enter_event()
389 {
390         if(canvas->get_canvas())
391                 return canvas->cursor_enter_event_base(canvas->get_canvas());
392         return 0;
393 }
394
395 int VWindowGUI::button_release_event()
396 {
397         if(canvas->get_canvas())
398                 return canvas->button_release_event();
399         return 0;
400 }
401
402 int VWindowGUI::cursor_motion_event()
403 {
404         if(canvas->get_canvas())
405         {
406                 canvas->get_canvas()->unhide_cursor();
407                 return canvas->cursor_motion_event();
408         }
409         return 0;
410 }
411
412
413 void VWindowGUI::drag_motion()
414 {
415 // Window hidden
416         if(get_hidden()) return;
417         if(mwindow->session->current_operation != DRAG_ASSET) return;
418         int need_highlight = cursor_above() && get_cursor_over_window() ? 1 : 0;
419         if( highlighted == need_highlight ) return;
420         highlighted = need_highlight;
421         canvas->draw_refresh();
422 }
423
424 int VWindowGUI::drag_stop()
425 {
426         if(get_hidden()) return 0;
427
428         if(highlighted &&
429                 mwindow->session->current_operation == DRAG_ASSET)
430         {
431                 highlighted = 0;
432                 canvas->draw_refresh();
433                 unlock_window();
434
435                 Indexable *indexable = mwindow->session->drag_assets->size() ?
436                         mwindow->session->drag_assets->get(0) :
437                         0;
438                 EDL *edl = mwindow->session->drag_clips->size() ?
439                         mwindow->session->drag_clips->get(0) :
440                         0;
441                 if(indexable)
442                         vwindow->change_source(indexable);
443                 else
444                 if(edl)
445                         vwindow->change_source(edl);
446                 lock_window("VWindowGUI::drag_stop");
447                 return 1;
448         }
449
450         return 0;
451 }
452
453
454 void VWindowGUI::update_meters()
455 {
456         if(mwindow->edl->session->vwindow_meter != meters->visible)
457         {
458                 meters->set_meters(meters->meter_count,
459                         mwindow->edl->session->vwindow_meter);
460                 mwindow->theme->get_vwindow_sizes(this);
461                 resize_event(get_w(), get_h());
462         }
463 }
464
465
466
467 VWindowMeters::VWindowMeters(MWindow *mwindow,
468         VWindowGUI *gui,
469         int x,
470         int y,
471         int h)
472  : MeterPanel(mwindow,
473                 gui,
474                 x,
475                 y,
476                 -1,
477                 h,
478                 mwindow->edl->session->audio_channels,
479                 mwindow->edl->session->vwindow_meter,
480                 0,
481                 0)
482 {
483         this->mwindow = mwindow;
484         this->gui = gui;
485 }
486
487 VWindowMeters::~VWindowMeters()
488 {
489 }
490
491 int VWindowMeters::change_status_event(int new_status)
492 {
493         mwindow->edl->session->vwindow_meter = new_status;
494         gui->update_meters();
495         return 1;
496 }
497
498
499
500
501
502
503
504 VWindowEditing::VWindowEditing(MWindow *mwindow, VWindow *vwindow)
505  : EditPanel(mwindow,
506                 vwindow->gui,
507                 mwindow->theme->vedit_x,
508                 mwindow->theme->vedit_y,
509                 EDITING_ARROW,
510                 0,
511                 0,
512                 1,
513                 1,
514                 0,
515                 0,
516                 1,
517                 0,
518                 0,
519                 0,
520                 0, // locklabels
521                 1,
522                 1,
523                 1,
524                 0,
525                 0,
526                 0)
527 {
528         this->mwindow = mwindow;
529         this->vwindow = vwindow;
530 }
531
532 VWindowEditing::~VWindowEditing()
533 {
534 }
535
536 void VWindowEditing::copy_selection()
537 {
538         vwindow->copy();
539 }
540
541 void VWindowEditing::splice_selection()
542 {
543         if(vwindow->get_edl())
544         {
545                 mwindow->gui->lock_window("VWindowEditing::splice_selection");
546                 mwindow->splice(vwindow->get_edl());
547                 mwindow->gui->unlock_window();
548         }
549 }
550
551 void VWindowEditing::overwrite_selection()
552 {
553         if(vwindow->get_edl())
554         {
555                 mwindow->gui->lock_window("VWindowEditing::overwrite_selection");
556                 mwindow->overwrite(vwindow->get_edl());
557                 mwindow->gui->unlock_window();
558         }
559 }
560
561 void VWindowEditing::toggle_label()
562 {
563         if(vwindow->get_edl())
564         {
565                 EDL *edl = vwindow->get_edl();
566                 edl->labels->toggle_label(edl->local_session->get_selectionstart(1),
567                         edl->local_session->get_selectionend(1));
568                 vwindow->gui->timebar->update(1);
569         }
570 }
571
572 void VWindowEditing::prev_label()
573 {
574         if(vwindow->get_edl())
575         {
576                 EDL *edl = vwindow->get_edl();
577                 vwindow->gui->unlock_window();
578                 vwindow->playback_engine->interrupt_playback(1);
579                 vwindow->gui->lock_window("VWindowEditing::prev_label");
580
581                 Label *current = edl->labels->prev_label(
582                         edl->local_session->get_selectionstart(1));
583
584
585                 if(!current)
586                 {
587                         edl->local_session->set_selectionstart(0);
588                         edl->local_session->set_selectionend(0);
589                         vwindow->update_position(CHANGE_NONE, 0, 1, 0);
590                         vwindow->gui->timebar->update(1);
591                 }
592                 else
593                 {
594                         edl->local_session->set_selectionstart(current->position);
595                         edl->local_session->set_selectionend(current->position);
596                         vwindow->update_position(CHANGE_NONE, 0, 1, 0);
597                         vwindow->gui->timebar->update(1);
598                 }
599         }
600 }
601
602 void VWindowEditing::next_label()
603 {
604         if(vwindow->get_edl())
605         {
606                 EDL *edl = vwindow->get_edl();
607                 Label *current = edl->labels->next_label(
608                         edl->local_session->get_selectionstart(1));
609                 if(!current)
610                 {
611                         vwindow->gui->unlock_window();
612                         vwindow->playback_engine->interrupt_playback(1);
613                         vwindow->gui->lock_window("VWindowEditing::next_label 1");
614
615                         double position = edl->tracks->total_length();
616                         edl->local_session->set_selectionstart(position);
617                         edl->local_session->set_selectionend(position);
618                         vwindow->update_position(CHANGE_NONE, 0, 1, 0);
619                         vwindow->gui->timebar->update(1);
620                 }
621                 else
622                 {
623                         vwindow->gui->unlock_window();
624                         vwindow->playback_engine->interrupt_playback(1);
625                         vwindow->gui->lock_window("VWindowEditing::next_label 2");
626
627                         edl->local_session->set_selectionstart(current->position);
628                         edl->local_session->set_selectionend(current->position);
629                         vwindow->update_position(CHANGE_NONE, 0, 1, 0);
630                         vwindow->gui->timebar->update(1);
631                 }
632         }
633 }
634
635 double VWindowEditing::get_position()
636 {
637         EDL *edl = vwindow->get_edl();
638         double position = !edl ? 0 : edl->local_session->get_selectionstart(1);
639         return position;
640 }
641
642 void VWindowEditing::set_position(double position)
643 {
644         EDL *edl = vwindow->get_edl();
645         if( !edl ) return;
646         if( get_position() != position ) {
647                 if( position < 0 ) position = 0;
648                 edl->local_session->set_selectionstart(position);
649                 edl->local_session->set_selectionend(position);
650                 vwindow->update_position(CHANGE_NONE, 0, 1);
651         }
652 }
653
654 void VWindowEditing::set_inpoint()
655 {
656         vwindow->set_inpoint();
657 }
658
659 void VWindowEditing::set_outpoint()
660 {
661         vwindow->set_outpoint();
662 }
663
664 void VWindowEditing::unset_inoutpoint()
665 {
666         vwindow->unset_inoutpoint();
667 }
668
669
670 void VWindowEditing::to_clip()
671 {
672         EDL *edl = vwindow->get_edl();
673         if( !edl ) return;
674         mwindow->to_clip(edl, _("viewer window: "));
675 }
676
677 VWindowSource::VWindowSource(MWindow *mwindow, VWindowGUI *vwindow, int x, int y)
678  : BC_PopupTextBox(vwindow,
679         &vwindow->sources,
680         "",
681         x,
682         y,
683         200,
684         200)
685 {
686         this->mwindow = mwindow;
687         this->vwindow = vwindow;
688 }
689
690 VWindowSource::~VWindowSource()
691 {
692 }
693
694 int VWindowSource::handle_event()
695 {
696         return 1;
697 }
698
699
700 VWindowTransport::VWindowTransport(MWindow *mwindow,
701         VWindowGUI *gui,
702         int x,
703         int y)
704  : PlayTransport(mwindow,
705         gui,
706         x,
707         y)
708 {
709         this->gui = gui;
710 }
711
712 EDL* VWindowTransport::get_edl()
713 {
714         return gui->vwindow->get_edl();
715 }
716
717
718 void VWindowTransport::goto_start()
719 {
720         gui->unlock_window();
721         handle_transport(REWIND, 1);
722         gui->lock_window("VWindowTransport::goto_start");
723         gui->vwindow->goto_start();
724 }
725
726 void VWindowTransport::goto_end()
727 {
728         gui->unlock_window();
729         handle_transport(GOTO_END, 1);
730         gui->lock_window("VWindowTransport::goto_end");
731         gui->vwindow->goto_end();
732 }
733
734
735
736
737 VWindowCanvas::VWindowCanvas(MWindow *mwindow, VWindowGUI *gui)
738  : Canvas(mwindow,
739         gui,
740         mwindow->theme->vcanvas_x,
741         mwindow->theme->vcanvas_y,
742         mwindow->theme->vcanvas_w,
743         mwindow->theme->vcanvas_h,
744         0, 0, 0)
745 {
746 //printf("VWindowCanvas::VWindowCanvas %d %d\n", __LINE__, mwindow->theme->vcanvas_x);
747         this->mwindow = mwindow;
748         this->gui = gui;
749 }
750
751 void VWindowCanvas::zoom_resize_window(float percentage)
752 {
753         EDL *edl = gui->vwindow->get_edl();
754         if(!edl) edl = mwindow->edl;
755
756         int canvas_w, canvas_h;
757         int new_w, new_h;
758
759 // Get required canvas size
760         calculate_sizes(edl->get_aspect_ratio(),
761                 edl->session->output_w,
762                 edl->session->output_h,
763                 percentage,
764                 canvas_w,
765                 canvas_h);
766
767 // Estimate window size from current borders
768         new_w = canvas_w + (gui->get_w() - mwindow->theme->vcanvas_w);
769         new_h = canvas_h + (gui->get_h() - mwindow->theme->vcanvas_h);
770
771         mwindow->session->vwindow_w = new_w;
772         mwindow->session->vwindow_h = new_h;
773
774         mwindow->theme->get_vwindow_sizes(gui);
775
776 // Estimate again from new borders
777         new_w = canvas_w + (mwindow->session->vwindow_w - mwindow->theme->vcanvas_w);
778         new_h = canvas_h + (mwindow->session->vwindow_h - mwindow->theme->vcanvas_h);
779
780
781         gui->resize_window(new_w, new_h);
782         gui->resize_event(new_w, new_h);
783 }
784
785 void VWindowCanvas::close_source()
786 {
787         gui->unlock_window();
788         gui->vwindow->playback_engine->interrupt_playback(1);
789         gui->lock_window("VWindowCanvas::close_source");
790         gui->vwindow->delete_source(1, 1);
791 }
792
793
794 void VWindowCanvas::draw_refresh(int flush)
795 {
796         EDL *edl = gui->vwindow->get_edl();
797
798         if(!get_canvas()->get_video_on()) get_canvas()->clear_box(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
799         if(!get_canvas()->get_video_on() && refresh_frame && edl)
800         {
801                 float in_x1, in_y1, in_x2, in_y2;
802                 float out_x1, out_y1, out_x2, out_y2;
803                 get_transfers(edl,
804                         in_x1,
805                         in_y1,
806                         in_x2,
807                         in_y2,
808                         out_x1,
809                         out_y1,
810                         out_x2,
811                         out_y2);
812                 get_canvas()->draw_vframe(refresh_frame,
813                                 (int)out_x1,
814                                 (int)out_y1,
815                                 (int)(out_x2 - out_x1),
816                                 (int)(out_y2 - out_y1),
817                                 (int)in_x1,
818                                 (int)in_y1,
819                                 (int)(in_x2 - in_x1),
820                                 (int)(in_y2 - in_y1),
821                                 0);
822         }
823
824         if(!get_canvas()->get_video_on())
825         {
826                 draw_overlays();
827                 get_canvas()->flash(flush);
828         }
829 }
830
831 void VWindowCanvas::draw_overlays()
832 {
833         if( gui->highlighted )
834         {
835                 get_canvas()->set_color(WHITE);
836                 get_canvas()->set_inverse();
837                 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
838                 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
839                 get_canvas()->set_opaque();
840         }
841 }
842
843 int VWindowCanvas::get_fullscreen()
844 {
845         return mwindow->session->vwindow_fullscreen;
846 }
847
848 void VWindowCanvas::set_fullscreen(int value)
849 {
850         mwindow->session->vwindow_fullscreen = value;
851 }
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889 #if 0
890 void VWindowGUI::update_points()
891 {
892         EDL *edl = vwindow->get_edl();
893
894 //printf("VWindowGUI::update_points 1\n");
895         if(!edl) return;
896
897 //printf("VWindowGUI::update_points 2\n");
898         long pixel = (long)((double)edl->local_session->in_point /
899                 edl->tracks->total_length() *
900                 (mwindow->theme->vtimebar_w -
901                         2 *
902                         mwindow->theme->in_point[0]->get_w())) +
903                 mwindow->theme->in_point[0]->get_w();
904
905 //printf("VWindowGUI::update_points 3 %d\n", edl->local_session->in_point);
906         if(in_point)
907         {
908 //printf("VWindowGUI::update_points 3.1\n");
909                 if(edl->local_session->in_point >= 0)
910                 {
911 //printf("VWindowGUI::update_points 4\n");
912                         if(edl->local_session->in_point != in_point->position ||
913                                 in_point->pixel != pixel)
914                         {
915                                 in_point->pixel = pixel;
916                                 in_point->reposition();
917                         }
918
919 //printf("VWindowGUI::update_points 5\n");
920                         in_point->position = edl->local_session->in_point;
921
922 //printf("VWindowGUI::update_points 6\n");
923                         if(edl->equivalent(in_point->position, edl->local_session->get_selectionstart(1)) ||
924                                 edl->equivalent(in_point->position, edl->local_session->get_selectionend(1)))
925                                 in_point->update(1);
926                         else
927                                 in_point->update(0);
928 //printf("VWindowGUI::update_points 7\n");
929                 }
930                 else
931                 {
932                         delete in_point;
933                         in_point = 0;
934                 }
935         }
936         else
937         if(edl->local_session->in_point >= 0)
938         {
939 //printf("VWindowGUI::update_points 8 %p\n", mwindow->theme->in_point);
940                 add_subwindow(in_point =
941                         new VWindowInPoint(mwindow,
942                                 0,
943                                 this,
944                                 pixel,
945                                 edl->local_session->in_point));
946 //printf("VWindowGUI::update_points 9\n");
947         }
948 //printf("VWindowGUI::update_points 10\n");
949
950         pixel = (long)((double)edl->local_session->out_point /
951                 (edl->tracks->total_length() + 0.5) *
952                 (mwindow->theme->vtimebar_w -
953                         2 *
954                         mwindow->theme->in_point[0]->get_w())) +
955                 mwindow->theme->in_point[0]->get_w() *
956                 2;
957
958         if(out_point)
959         {
960                 if(edl->local_session->out_point >= 0 && pixel >= 0 && pixel <= mwindow->theme->vtimebar_w)
961                 {
962                         if(edl->local_session->out_point != out_point->position ||
963                                 out_point->pixel != pixel)
964                         {
965                                 out_point->pixel = pixel;
966                                 out_point->reposition();
967                         }
968                         out_point->position = edl->local_session->out_point;
969
970                         if(edl->equivalent(out_point->position, edl->local_session->get_selectionstart(1)) ||
971                                 edl->equivalent(out_point->position, edl->local_session->get_selectionend(1)))
972                                 out_point->update(1);
973                         else
974                                 out_point->update(0);
975                 }
976                 else
977                 {
978                         delete out_point;
979                         out_point = 0;
980                 }
981         }
982         else
983         if(edl->local_session->out_point >= 0 && pixel >= 0 && pixel <= mwindow->theme->vtimebar_w)
984         {
985                 add_subwindow(out_point =
986                         new VWindowOutPoint(mwindow,
987                                 0,
988                                 this,
989                                 pixel,
990                                 edl->local_session->out_point));
991         }
992 }
993
994
995 void VWindowGUI::update_labels()
996 {
997         EDL *edl = vwindow->get_edl();
998         int output = 0;
999
1000         for(Label *current = edl->labels->first;
1001                 current;
1002                 current = NEXT)
1003         {
1004                 long pixel = (long)((current->position - edl->local_session->view_start) / edl->local_session->zoom_sample);
1005
1006                 if(pixel >= 0 && pixel < mwindow->theme->vtimebar_w)
1007                 {
1008 // Create new label
1009                         if(output >= labels.total)
1010                         {
1011                                 LabelGUI *new_label;
1012                                 add_subwindow(new_label = new LabelGUI(mwindow, this, pixel, 0, current->position));
1013                                 labels.append(new_label);
1014                         }
1015                         else
1016 // Reposition old label
1017                         if(labels.values[output]->pixel != pixel)
1018                         {
1019                                 labels.values[output]->pixel = pixel;
1020                                 labels.values[output]->position = current->position;
1021                                 labels.values[output]->reposition();
1022                         }
1023
1024                         if(mwindow->edl->local_session->get_selectionstart(1) <= current->position &&
1025                                 mwindow->edl->local_session->get_selectionend(1) >= current->position)
1026                                 labels.values[output]->update(1);
1027                         else
1028                         if(labels.values[output]->get_value())
1029                                 labels.values[output]->update(0);
1030                         output++;
1031                 }
1032         }
1033
1034 // Delete excess labels
1035         while(labels.total > output)
1036         {
1037                 labels.remove_object();
1038         }
1039 }
1040
1041
1042
1043 VWindowInPoint::VWindowInPoint(MWindow *mwindow,
1044                 TimeBar *timebar,
1045                 VWindowGUI *gui,
1046                 long pixel,
1047                 double position)
1048  : InPointGUI(mwindow,
1049                 timebar,
1050                 pixel,
1051                 position)
1052 {
1053         this->gui = gui;
1054 }
1055
1056 int VWindowInPoint::handle_event()
1057 {
1058         EDL *edl = gui->vwindow->get_edl();
1059
1060         if(edl)
1061         {
1062                 double position = edl->align_to_frame(this->position, 0);
1063
1064                 edl->local_session->set_selectionstart(position);
1065                 edl->local_session->set_selectionend(position);
1066                 gui->timebar->update(1);
1067
1068 // Que the VWindow
1069                 mwindow->vwindow->update_position(CHANGE_NONE, 0, 1, 0);
1070         }
1071         return 1;
1072 }
1073
1074
1075
1076 VWindowOutPoint::VWindowOutPoint(MWindow *mwindow,
1077                 TimeBar *timebar,
1078                 VWindowGUI *gui,
1079                 long pixel,
1080                 double position)
1081  : OutPointGUI(mwindow,
1082                 timebar,
1083                 pixel,
1084                 position)
1085 {
1086         this->gui = gui;
1087 }
1088
1089 int VWindowOutPoint::handle_event()
1090 {
1091         EDL *edl = gui->vwindow->get_edl();
1092
1093         if(edl)
1094         {
1095                 double position = edl->align_to_frame(this->position, 0);
1096
1097                 edl->local_session->set_selectionstart(position);
1098                 edl->local_session->set_selectionend(position);
1099                 gui->timebar->update(1);
1100
1101 // Que the VWindow
1102                 mwindow->vwindow->update_position(CHANGE_NONE, 0, 1, 0);
1103         }
1104
1105         return 1;
1106 }
1107
1108
1109
1110 #endif
1111