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