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