cposer/viewer btn1/2/3 fwd/rev/frm playback, misc fixes, leaks, cleanup
[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         if( result && !vwindow->playback_engine->is_playing_back )
352                 timebar->update(1);
353         return result;
354 }
355
356 void VWindowGUI::stop_transport(const char *lock_msg)
357 {
358         if( !transport->is_stopped() ) {
359                 if( lock_msg ) unlock_window();
360                 transport->handle_transport(STOP, 1, 0, 0);
361                 if( lock_msg ) lock_window(lock_msg);
362         }
363 }
364
365 int VWindowGUI::button_press_event()
366 {
367         if( vwindow->get_edl() != 0 && canvas->get_canvas() &&
368             canvas->get_canvas()->get_cursor_over_window() ) {
369                 switch( get_buttonpress() ) {
370                 case LEFT_BUTTON:
371                         if( !vwindow->playback_engine->is_playing_back ) {
372                                 double length = vwindow->get_edl()->tracks->total_playable_length();
373                                 double position = vwindow->playback_engine->get_tracking_position();
374                                 if( position >= length ) transport->goto_start();
375                         }
376                         return transport->forward_play->handle_event();
377                 case MIDDLE_BUTTON:
378                         if( !vwindow->playback_engine->is_playing_back ) {
379                                 double position = vwindow->playback_engine->get_tracking_position();
380                                 if( position <= 0 ) transport->goto_end();
381                         }
382                         return transport->reverse_play->handle_event();
383                 case RIGHT_BUTTON:  // activates popup
384                         break;
385                 case WHEEL_UP:
386                         return transport->frame_forward_play->handle_event();
387                 case WHEEL_DOWN:
388                         return transport->frame_reverse_play->handle_event();
389                 }
390         }
391         if(canvas->get_canvas())
392                 return canvas->button_press_event_base(canvas->get_canvas());
393         return 0;
394 }
395
396 int VWindowGUI::cursor_leave_event()
397 {
398         if(canvas->get_canvas())
399                 return canvas->cursor_leave_event_base(canvas->get_canvas());
400         return 0;
401 }
402
403 int VWindowGUI::cursor_enter_event()
404 {
405         if(canvas->get_canvas())
406                 return canvas->cursor_enter_event_base(canvas->get_canvas());
407         return 0;
408 }
409
410 int VWindowGUI::button_release_event()
411 {
412         if(canvas->get_canvas())
413                 return canvas->button_release_event();
414         return 0;
415 }
416
417 int VWindowGUI::cursor_motion_event()
418 {
419         if(canvas->get_canvas())
420         {
421                 canvas->get_canvas()->unhide_cursor();
422                 return canvas->cursor_motion_event();
423         }
424         return 0;
425 }
426
427
428 void VWindowGUI::drag_motion()
429 {
430 // Window hidden
431         if(get_hidden()) return;
432         if(mwindow->session->current_operation != DRAG_ASSET) return;
433         int need_highlight = cursor_above() && get_cursor_over_window() ? 1 : 0;
434         if( highlighted == need_highlight ) return;
435         highlighted = need_highlight;
436         canvas->draw_refresh();
437 }
438
439 int VWindowGUI::drag_stop()
440 {
441         if(get_hidden()) return 0;
442
443         if(highlighted &&
444                 mwindow->session->current_operation == DRAG_ASSET)
445         {
446                 highlighted = 0;
447                 canvas->draw_refresh();
448                 unlock_window();
449
450                 Indexable *indexable = mwindow->session->drag_assets->size() ?
451                         mwindow->session->drag_assets->get(0) :
452                         0;
453                 EDL *edl = mwindow->session->drag_clips->size() ?
454                         mwindow->session->drag_clips->get(0) :
455                         0;
456                 if(indexable)
457                         vwindow->change_source(indexable);
458                 else
459                 if(edl)
460                         vwindow->change_source(edl);
461                 lock_window("VWindowGUI::drag_stop");
462                 return 1;
463         }
464
465         return 0;
466 }
467
468
469 void VWindowGUI::update_meters()
470 {
471         if(mwindow->edl->session->vwindow_meter != meters->visible)
472         {
473                 meters->set_meters(meters->meter_count,
474                         mwindow->edl->session->vwindow_meter);
475                 mwindow->theme->get_vwindow_sizes(this);
476                 resize_event(get_w(), get_h());
477         }
478 }
479
480
481
482 VWindowMeters::VWindowMeters(MWindow *mwindow,
483         VWindowGUI *gui,
484         int x,
485         int y,
486         int h)
487  : MeterPanel(mwindow,
488                 gui,
489                 x,
490                 y,
491                 -1,
492                 h,
493                 mwindow->edl->session->audio_channels,
494                 mwindow->edl->session->vwindow_meter,
495                 0,
496                 0)
497 {
498         this->mwindow = mwindow;
499         this->gui = gui;
500 }
501
502 VWindowMeters::~VWindowMeters()
503 {
504 }
505
506 int VWindowMeters::change_status_event(int new_status)
507 {
508         mwindow->edl->session->vwindow_meter = new_status;
509         gui->update_meters();
510         return 1;
511 }
512
513
514
515
516
517
518
519 VWindowEditing::VWindowEditing(MWindow *mwindow, VWindow *vwindow)
520  : EditPanel(mwindow,
521                 vwindow->gui,
522                 mwindow->theme->vedit_x,
523                 mwindow->theme->vedit_y,
524                 EDITING_ARROW,
525                 0,
526                 0,
527                 1,
528                 1,
529                 0,
530                 0,
531                 1,
532                 0,
533                 0,
534                 0,
535                 0, // locklabels
536                 1,
537                 1,
538                 1,
539                 0,
540                 0,
541                 0)
542 {
543         this->mwindow = mwindow;
544         this->vwindow = vwindow;
545 }
546
547 VWindowEditing::~VWindowEditing()
548 {
549 }
550
551 void VWindowEditing::copy_selection()
552 {
553         vwindow->copy();
554 }
555
556 void VWindowEditing::splice_selection()
557 {
558         if(vwindow->get_edl())
559         {
560                 mwindow->gui->lock_window("VWindowEditing::splice_selection");
561                 mwindow->splice(vwindow->get_edl());
562                 mwindow->gui->unlock_window();
563         }
564 }
565
566 void VWindowEditing::overwrite_selection()
567 {
568         if(vwindow->get_edl())
569         {
570                 mwindow->gui->lock_window("VWindowEditing::overwrite_selection");
571                 mwindow->overwrite(vwindow->get_edl());
572                 mwindow->gui->unlock_window();
573         }
574 }
575
576 void VWindowEditing::toggle_label()
577 {
578         if(vwindow->get_edl())
579         {
580                 EDL *edl = vwindow->get_edl();
581                 edl->labels->toggle_label(edl->local_session->get_selectionstart(1),
582                         edl->local_session->get_selectionend(1));
583                 vwindow->gui->timebar->update(1);
584         }
585 }
586
587 void VWindowEditing::prev_label()
588 {
589         if(vwindow->get_edl())
590         {
591                 EDL *edl = vwindow->get_edl();
592                 vwindow->gui->unlock_window();
593                 vwindow->playback_engine->interrupt_playback(1);
594                 vwindow->gui->lock_window("VWindowEditing::prev_label");
595
596                 Label *current = edl->labels->prev_label(
597                         edl->local_session->get_selectionstart(1));
598
599
600                 if(!current)
601                 {
602                         edl->local_session->set_selectionstart(0);
603                         edl->local_session->set_selectionend(0);
604                         vwindow->update_position(CHANGE_NONE, 0, 1, 0);
605                         vwindow->gui->timebar->update(1);
606                 }
607                 else
608                 {
609                         edl->local_session->set_selectionstart(current->position);
610                         edl->local_session->set_selectionend(current->position);
611                         vwindow->update_position(CHANGE_NONE, 0, 1, 0);
612                         vwindow->gui->timebar->update(1);
613                 }
614         }
615 }
616
617 void VWindowEditing::next_label()
618 {
619         if(vwindow->get_edl())
620         {
621                 EDL *edl = vwindow->get_edl();
622                 Label *current = edl->labels->next_label(
623                         edl->local_session->get_selectionstart(1));
624                 if(!current)
625                 {
626                         vwindow->gui->unlock_window();
627                         vwindow->playback_engine->interrupt_playback(1);
628                         vwindow->gui->lock_window("VWindowEditing::next_label 1");
629
630                         double position = edl->tracks->total_length();
631                         edl->local_session->set_selectionstart(position);
632                         edl->local_session->set_selectionend(position);
633                         vwindow->update_position(CHANGE_NONE, 0, 1, 0);
634                         vwindow->gui->timebar->update(1);
635                 }
636                 else
637                 {
638                         vwindow->gui->unlock_window();
639                         vwindow->playback_engine->interrupt_playback(1);
640                         vwindow->gui->lock_window("VWindowEditing::next_label 2");
641
642                         edl->local_session->set_selectionstart(current->position);
643                         edl->local_session->set_selectionend(current->position);
644                         vwindow->update_position(CHANGE_NONE, 0, 1, 0);
645                         vwindow->gui->timebar->update(1);
646                 }
647         }
648 }
649
650 double VWindowEditing::get_position()
651 {
652         EDL *edl = vwindow->get_edl();
653         double position = !edl ? 0 : edl->local_session->get_selectionstart(1);
654         return position;
655 }
656
657 void VWindowEditing::set_position(double position)
658 {
659         EDL *edl = vwindow->get_edl();
660         if( !edl ) return;
661         if( get_position() != position ) {
662                 if( position < 0 ) position = 0;
663                 edl->local_session->set_selectionstart(position);
664                 edl->local_session->set_selectionend(position);
665                 vwindow->update_position(CHANGE_NONE, 0, 1);
666         }
667 }
668
669 void VWindowEditing::set_inpoint()
670 {
671         vwindow->set_inpoint();
672 }
673
674 void VWindowEditing::set_outpoint()
675 {
676         vwindow->set_outpoint();
677 }
678
679 void VWindowEditing::unset_inoutpoint()
680 {
681         vwindow->unset_inoutpoint();
682 }
683
684
685 void VWindowEditing::to_clip()
686 {
687         EDL *edl = vwindow->get_edl();
688         if( !edl ) return;
689         mwindow->to_clip(edl, _("viewer window: "));
690 }
691
692 VWindowSource::VWindowSource(MWindow *mwindow, VWindowGUI *vwindow, int x, int y)
693  : BC_PopupTextBox(vwindow,
694         &vwindow->sources,
695         "",
696         x,
697         y,
698         200,
699         200)
700 {
701         this->mwindow = mwindow;
702         this->vwindow = vwindow;
703 }
704
705 VWindowSource::~VWindowSource()
706 {
707 }
708
709 int VWindowSource::handle_event()
710 {
711         return 1;
712 }
713
714
715 VWindowTransport::VWindowTransport(MWindow *mwindow,
716         VWindowGUI *gui,
717         int x,
718         int y)
719  : PlayTransport(mwindow,
720         gui,
721         x,
722         y)
723 {
724         this->gui = gui;
725 }
726
727 EDL* VWindowTransport::get_edl()
728 {
729         return gui->vwindow->get_edl();
730 }
731
732
733 void VWindowTransport::goto_start()
734 {
735         gui->unlock_window();
736         handle_transport(REWIND, 1);
737         gui->lock_window("VWindowTransport::goto_start");
738         gui->vwindow->goto_start();
739 }
740
741 void VWindowTransport::goto_end()
742 {
743         gui->unlock_window();
744         handle_transport(GOTO_END, 1);
745         gui->lock_window("VWindowTransport::goto_end");
746         gui->vwindow->goto_end();
747 }
748
749
750
751
752 VWindowCanvas::VWindowCanvas(MWindow *mwindow, VWindowGUI *gui)
753  : Canvas(mwindow,
754         gui,
755         mwindow->theme->vcanvas_x,
756         mwindow->theme->vcanvas_y,
757         mwindow->theme->vcanvas_w,
758         mwindow->theme->vcanvas_h,
759         0, 0, 0)
760 {
761 //printf("VWindowCanvas::VWindowCanvas %d %d\n", __LINE__, mwindow->theme->vcanvas_x);
762         this->mwindow = mwindow;
763         this->gui = gui;
764 }
765
766 void VWindowCanvas::zoom_resize_window(float percentage)
767 {
768         EDL *edl = gui->vwindow->get_edl();
769         if(!edl) edl = mwindow->edl;
770
771         int canvas_w, canvas_h;
772         int new_w, new_h;
773
774 // Get required canvas size
775         calculate_sizes(edl->get_aspect_ratio(),
776                 edl->session->output_w,
777                 edl->session->output_h,
778                 percentage,
779                 canvas_w,
780                 canvas_h);
781
782 // Estimate window size from current borders
783         new_w = canvas_w + (gui->get_w() - mwindow->theme->vcanvas_w);
784         new_h = canvas_h + (gui->get_h() - mwindow->theme->vcanvas_h);
785
786         mwindow->session->vwindow_w = new_w;
787         mwindow->session->vwindow_h = new_h;
788
789         mwindow->theme->get_vwindow_sizes(gui);
790
791 // Estimate again from new borders
792         new_w = canvas_w + (mwindow->session->vwindow_w - mwindow->theme->vcanvas_w);
793         new_h = canvas_h + (mwindow->session->vwindow_h - mwindow->theme->vcanvas_h);
794
795
796         gui->resize_window(new_w, new_h);
797         gui->resize_event(new_w, new_h);
798 }
799
800 void VWindowCanvas::close_source()
801 {
802         gui->unlock_window();
803         gui->vwindow->playback_engine->interrupt_playback(1);
804         gui->lock_window("VWindowCanvas::close_source");
805         gui->vwindow->delete_source(1, 1);
806 }
807
808
809 void VWindowCanvas::draw_refresh(int flush)
810 {
811         EDL *edl = gui->vwindow->get_edl();
812
813         if(!get_canvas()->get_video_on()) get_canvas()->clear_box(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
814         if(!get_canvas()->get_video_on() && refresh_frame && edl)
815         {
816                 float in_x1, in_y1, in_x2, in_y2;
817                 float out_x1, out_y1, out_x2, out_y2;
818                 get_transfers(edl,
819                         in_x1,
820                         in_y1,
821                         in_x2,
822                         in_y2,
823                         out_x1,
824                         out_y1,
825                         out_x2,
826                         out_y2);
827                 get_canvas()->draw_vframe(refresh_frame,
828                                 (int)out_x1,
829                                 (int)out_y1,
830                                 (int)(out_x2 - out_x1),
831                                 (int)(out_y2 - out_y1),
832                                 (int)in_x1,
833                                 (int)in_y1,
834                                 (int)(in_x2 - in_x1),
835                                 (int)(in_y2 - in_y1),
836                                 0);
837         }
838
839         if(!get_canvas()->get_video_on())
840         {
841                 draw_overlays();
842                 get_canvas()->flash(flush);
843         }
844 }
845
846 void VWindowCanvas::draw_overlays()
847 {
848         if( gui->highlighted )
849         {
850                 get_canvas()->set_color(WHITE);
851                 get_canvas()->set_inverse();
852                 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
853                 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
854                 get_canvas()->set_opaque();
855         }
856 }
857
858 int VWindowCanvas::get_fullscreen()
859 {
860         return mwindow->session->vwindow_fullscreen;
861 }
862
863 void VWindowCanvas::set_fullscreen(int value)
864 {
865         mwindow->session->vwindow_fullscreen = value;
866 }
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904 #if 0
905 void VWindowGUI::update_points()
906 {
907         EDL *edl = vwindow->get_edl();
908
909 //printf("VWindowGUI::update_points 1\n");
910         if(!edl) return;
911
912 //printf("VWindowGUI::update_points 2\n");
913         long pixel = (long)((double)edl->local_session->in_point /
914                 edl->tracks->total_length() *
915                 (mwindow->theme->vtimebar_w -
916                         2 *
917                         mwindow->theme->in_point[0]->get_w())) +
918                 mwindow->theme->in_point[0]->get_w();
919
920 //printf("VWindowGUI::update_points 3 %d\n", edl->local_session->in_point);
921         if(in_point)
922         {
923 //printf("VWindowGUI::update_points 3.1\n");
924                 if(edl->local_session->in_point >= 0)
925                 {
926 //printf("VWindowGUI::update_points 4\n");
927                         if(edl->local_session->in_point != in_point->position ||
928                                 in_point->pixel != pixel)
929                         {
930                                 in_point->pixel = pixel;
931                                 in_point->reposition();
932                         }
933
934 //printf("VWindowGUI::update_points 5\n");
935                         in_point->position = edl->local_session->in_point;
936
937 //printf("VWindowGUI::update_points 6\n");
938                         if(edl->equivalent(in_point->position, edl->local_session->get_selectionstart(1)) ||
939                                 edl->equivalent(in_point->position, edl->local_session->get_selectionend(1)))
940                                 in_point->update(1);
941                         else
942                                 in_point->update(0);
943 //printf("VWindowGUI::update_points 7\n");
944                 }
945                 else
946                 {
947                         delete in_point;
948                         in_point = 0;
949                 }
950         }
951         else
952         if(edl->local_session->in_point >= 0)
953         {
954 //printf("VWindowGUI::update_points 8 %p\n", mwindow->theme->in_point);
955                 add_subwindow(in_point =
956                         new VWindowInPoint(mwindow,
957                                 0,
958                                 this,
959                                 pixel,
960                                 edl->local_session->in_point));
961 //printf("VWindowGUI::update_points 9\n");
962         }
963 //printf("VWindowGUI::update_points 10\n");
964
965         pixel = (long)((double)edl->local_session->out_point /
966                 (edl->tracks->total_length() + 0.5) *
967                 (mwindow->theme->vtimebar_w -
968                         2 *
969                         mwindow->theme->in_point[0]->get_w())) +
970                 mwindow->theme->in_point[0]->get_w() *
971                 2;
972
973         if(out_point)
974         {
975                 if(edl->local_session->out_point >= 0 && pixel >= 0 && pixel <= mwindow->theme->vtimebar_w)
976                 {
977                         if(edl->local_session->out_point != out_point->position ||
978                                 out_point->pixel != pixel)
979                         {
980                                 out_point->pixel = pixel;
981                                 out_point->reposition();
982                         }
983                         out_point->position = edl->local_session->out_point;
984
985                         if(edl->equivalent(out_point->position, edl->local_session->get_selectionstart(1)) ||
986                                 edl->equivalent(out_point->position, edl->local_session->get_selectionend(1)))
987                                 out_point->update(1);
988                         else
989                                 out_point->update(0);
990                 }
991                 else
992                 {
993                         delete out_point;
994                         out_point = 0;
995                 }
996         }
997         else
998         if(edl->local_session->out_point >= 0 && pixel >= 0 && pixel <= mwindow->theme->vtimebar_w)
999         {
1000                 add_subwindow(out_point =
1001                         new VWindowOutPoint(mwindow,
1002                                 0,
1003                                 this,
1004                                 pixel,
1005                                 edl->local_session->out_point));
1006         }
1007 }
1008
1009
1010 void VWindowGUI::update_labels()
1011 {
1012         EDL *edl = vwindow->get_edl();
1013         int output = 0;
1014
1015         for(Label *current = edl->labels->first;
1016                 current;
1017                 current = NEXT)
1018         {
1019                 long pixel = (long)((current->position - edl->local_session->view_start) / edl->local_session->zoom_sample);
1020
1021                 if(pixel >= 0 && pixel < mwindow->theme->vtimebar_w)
1022                 {
1023 // Create new label
1024                         if(output >= labels.total)
1025                         {
1026                                 LabelGUI *new_label;
1027                                 add_subwindow(new_label = new LabelGUI(mwindow, this, pixel, 0, current->position));
1028                                 labels.append(new_label);
1029                         }
1030                         else
1031 // Reposition old label
1032                         if(labels.values[output]->pixel != pixel)
1033                         {
1034                                 labels.values[output]->pixel = pixel;
1035                                 labels.values[output]->position = current->position;
1036                                 labels.values[output]->reposition();
1037                         }
1038
1039                         if(mwindow->edl->local_session->get_selectionstart(1) <= current->position &&
1040                                 mwindow->edl->local_session->get_selectionend(1) >= current->position)
1041                                 labels.values[output]->update(1);
1042                         else
1043                         if(labels.values[output]->get_value())
1044                                 labels.values[output]->update(0);
1045                         output++;
1046                 }
1047         }
1048
1049 // Delete excess labels
1050         while(labels.total > output)
1051         {
1052                 labels.remove_object();
1053         }
1054 }
1055
1056
1057
1058 VWindowInPoint::VWindowInPoint(MWindow *mwindow,
1059                 TimeBar *timebar,
1060                 VWindowGUI *gui,
1061                 long pixel,
1062                 double position)
1063  : InPointGUI(mwindow,
1064                 timebar,
1065                 pixel,
1066                 position)
1067 {
1068         this->gui = gui;
1069 }
1070
1071 int VWindowInPoint::handle_event()
1072 {
1073         EDL *edl = gui->vwindow->get_edl();
1074
1075         if(edl)
1076         {
1077                 double position = edl->align_to_frame(this->position, 0);
1078
1079                 edl->local_session->set_selectionstart(position);
1080                 edl->local_session->set_selectionend(position);
1081                 gui->timebar->update(1);
1082
1083 // Que the VWindow
1084                 mwindow->vwindow->update_position(CHANGE_NONE, 0, 1, 0);
1085         }
1086         return 1;
1087 }
1088
1089
1090
1091 VWindowOutPoint::VWindowOutPoint(MWindow *mwindow,
1092                 TimeBar *timebar,
1093                 VWindowGUI *gui,
1094                 long pixel,
1095                 double position)
1096  : OutPointGUI(mwindow,
1097                 timebar,
1098                 pixel,
1099                 position)
1100 {
1101         this->gui = gui;
1102 }
1103
1104 int VWindowOutPoint::handle_event()
1105 {
1106         EDL *edl = gui->vwindow->get_edl();
1107
1108         if(edl)
1109         {
1110                 double position = edl->align_to_frame(this->position, 0);
1111
1112                 edl->local_session->set_selectionstart(position);
1113                 edl->local_session->set_selectionend(position);
1114                 gui->timebar->update(1);
1115
1116 // Que the VWindow
1117                 mwindow->vwindow->update_position(CHANGE_NONE, 0, 1, 0);
1118         }
1119
1120         return 1;
1121 }
1122
1123
1124
1125 #endif
1126