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