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