r665: Merged the official release 2.0.
[cinelerra_cv.git] / cinelerra / mwindowgui.C
blobb136691713fc93223bd45fc916314de01d708e8f
1 #include "awindowgui.h"
2 #include "awindow.h"
3 #include "bcsignals.h"
4 #include "cwindowgui.h"
5 #include "cwindow.h"
6 #include "defaults.h"
7 #include "editpopup.h"
8 #include "edl.h"
9 #include "edlsession.h"
10 #include "filesystem.h"
11 #include "keyframepopup.h"
12 #include "keys.h"
13 #include "language.h"
14 #include "localsession.h"
15 #include "mainclock.h"
16 #include "maincursor.h"
17 #include "mainmenu.h"
18 #include "mainsession.h"
19 #include "mainundo.h"
20 #include "mbuttons.h"
21 #include "mtimebar.h"
22 #include "mwindowgui.h"
23 #include "mwindow.h"
24 #include "patchbay.h"
25 #include "pluginpopup.h"
26 #include "samplescroll.h"
27 #include "statusbar.h"
28 #include "theme.h"
29 #include "trackcanvas.h"
30 #include "trackscroll.h"
31 #include "tracks.h"
32 #include "transitionpopup.h"
33 #include "vwindowgui.h"
34 #include "vwindow.h"
35 #include "zoombar.h"
37 // the main window uses its own private colormap for video
38 MWindowGUI::MWindowGUI(MWindow *mwindow)
39  : BC_Window(PROGRAM_NAME ": Program", 
40                 mwindow->session->mwindow_x, 
41                 mwindow->session->mwindow_y, 
42                 mwindow->session->mwindow_w, 
43                 mwindow->session->mwindow_h, 
44                 100,
45                 100,
46                 1,
47                 1,
48                 1)
50         this->mwindow = mwindow;
51         samplescroll = 0;
52         trackscroll = 0;
53         cursor = 0;
54         canvas = 0;
58 MWindowGUI::~MWindowGUI()
60         delete mbuttons;
61         delete statusbar;
62         delete zoombar;
63         if(samplescroll) delete samplescroll;
64         if(trackscroll) delete trackscroll;
65         delete cursor;
66         delete patchbay;
67         delete timebar;
68         delete mainclock;
69         delete edit_menu;
70         delete plugin_menu;
71         delete keyframe_menu;
72         delete transition_menu;
75 void MWindowGUI::get_scrollbars()
77 //printf("MWindowGUI::get_scrollbars 1\n");
78         int64_t h_needed = mwindow->edl->get_tracks_height(mwindow->theme);
79         int64_t w_needed = mwindow->edl->get_tracks_width();
80         int need_xscroll = 0;
81         int need_yscroll = 0;
82         view_w = mwindow->theme->mcanvas_w;
83         view_h = mwindow->theme->mcanvas_h;
84 //printf("MWindowGUI::get_scrollbars 1\n");
86 // Scrollbars are constitutive
87         need_xscroll = need_yscroll = 1;
88         view_h = mwindow->theme->mcanvas_h;
89         view_w = mwindow->theme->mcanvas_w;
91 //      for(int i = 0; i < 2; i++)
92 //      {
93 //              if(w_needed > view_w)
94 //              {
95 //                      need_xscroll = 1;
96 //                      view_h = mwindow->theme->mcanvas_h - SCROLL_SPAN;
97 //              }
98 //              else
99 //                      need_xscroll = 0;
100 // 
101 //              if(h_needed > view_h)
102 //              {
103 //                      need_yscroll = 1;
104 //                      view_w = mwindow->theme->mcanvas_w - SCROLL_SPAN;
105 //              }
106 //              else
107 //                      need_yscroll = 0;
108 //      }
109 //printf("MWindowGUI::get_scrollbars 1\n");
111         if(canvas && (view_w != canvas->get_w() || view_h != canvas->get_h()))
112         {
113                 canvas->reposition_window(mwindow->theme->mcanvas_x,
114                         mwindow->theme->mcanvas_y,
115                         view_w,
116                         view_h);
117         }
118 //printf("MWindowGUI::get_scrollbars 1\n");
120         if(need_xscroll)
121         {
122                 if(!samplescroll)
123                         add_subwindow(samplescroll = new SampleScroll(mwindow, 
124                                 this, 
125                                 mwindow->theme->mhscroll_x, 
126                                 mwindow->theme->mhscroll_y, 
127                                 mwindow->theme->mhscroll_w));
128                 else
129                         samplescroll->resize_event();
131                 samplescroll->set_position();
132         }
133         else
134         {
135                 if(samplescroll) delete samplescroll;
136                 samplescroll = 0;
137                 mwindow->edl->local_session->view_start = 0;
138         }
139 //printf("MWindowGUI::get_scrollbars 1\n");
141         if(need_yscroll)
142         {
143 //printf("MWindowGUI::get_scrollbars 1.1 %p %p\n", this, canvas);
144                 if(!trackscroll)
145                         add_subwindow(trackscroll = new TrackScroll(mwindow, 
146                                 this,
147                                 mwindow->theme->mvscroll_x,
148                                 mwindow->theme->mvscroll_y,
149                                 mwindow->theme->mvscroll_h));
150                 else
151                         trackscroll->resize_event();
154 //printf("MWindowGUI::get_scrollbars 1.2\n");
155                 trackscroll->update_length(mwindow->edl->get_tracks_height(mwindow->theme),
156                         mwindow->edl->local_session->track_start,
157                         view_h);
158 //printf("MWindowGUI::get_scrollbars 1.3\n");
159         }
160         else
161         {
162                 if(trackscroll) delete trackscroll;
163                 trackscroll = 0;
164                 mwindow->edl->local_session->track_start = 0;
165         }
166 //printf("get_scrollbars 2 %d %d\n", need_xscroll, w_needed);
169 int MWindowGUI::create_objects()
171 SET_TRACE
172         set_icon(mwindow->theme->get_image("mwindow_icon"));
173         
174 SET_TRACE
176         cursor = 0;
177         add_subwindow(mainmenu = new MainMenu(mwindow, this));
178 SET_TRACE
180         mwindow->theme->get_mwindow_sizes(this, get_w(), get_h());
181         mwindow->theme->draw_mwindow_bg(this);
182         mainmenu->create_objects();
183 SET_TRACE
185         add_subwindow(mbuttons = new MButtons(mwindow, this));
186         mbuttons->create_objects();
187 SET_TRACE
189         add_subwindow(timebar = new MTimeBar(mwindow, 
190                 this,
191                 mwindow->theme->mtimebar_x,
192                 mwindow->theme->mtimebar_y,
193                 mwindow->theme->mtimebar_w,
194                 mwindow->theme->mtimebar_h));
195         timebar->create_objects();
196 SET_TRACE
198         add_subwindow(patchbay = new PatchBay(mwindow, this));
199         patchbay->create_objects();
200 SET_TRACE
202         get_scrollbars();
204 SET_TRACE
205         mwindow->gui->add_subwindow(canvas = new TrackCanvas(mwindow, this));
206         canvas->create_objects();
207 SET_TRACE
209         add_subwindow(zoombar = new ZoomBar(mwindow, this));
210         zoombar->create_objects();
211 SET_TRACE
213         add_subwindow(statusbar = new StatusBar(mwindow, this));
214         statusbar->create_objects();
215 SET_TRACE
217         add_subwindow(mainclock = new MainClock(mwindow, 
218                 mwindow->theme->mclock_x,
219                 mwindow->theme->mclock_y,
220                 mwindow->theme->mclock_w));
221         mainclock->set_frame_offset( (double) 
222                 (mwindow->edl->session->get_frame_offset() /
223                 mwindow->edl->session->frame_rate));
224         mainclock->update(0);
226 SET_TRACE
228         cursor = new MainCursor(mwindow, this);
229         cursor->create_objects();
230 SET_TRACE
232         add_subwindow(edit_menu = new EditPopup(mwindow, this));
233         edit_menu->create_objects();
234 SET_TRACE
236         add_subwindow(plugin_menu = new PluginPopup(mwindow, this));
237         plugin_menu->create_objects();
238 SET_TRACE
240         add_subwindow(keyframe_menu = new KeyframePopup(mwindow, this));
241         keyframe_menu->create_objects();
243         add_subwindow(transition_menu = new TransitionPopup(mwindow, this));
244         transition_menu->create_objects();
245 SET_TRACE
247         canvas->activate();
248 SET_TRACE
249         return 0;
252 void MWindowGUI::update_title(char *path)
254         FileSystem fs;
255         char filename[BCTEXTLEN], string[BCTEXTLEN];
256         fs.extract_name(filename, path);
257         sprintf(string, PROGRAM_NAME ": %s", filename);
258         set_title(string);
259 //printf("MWindowGUI::update_title %s\n", string);
260         flush();
263 void MWindowGUI::redraw_time_dependancies() 
265         zoombar->redraw_time_dependancies();
266         timebar->update();
267         mainclock->update(mwindow->edl->local_session->get_selectionstart(1));
270 int MWindowGUI::focus_in_event()
272         cursor->focus_in_event();
273         return 1;
276 int MWindowGUI::focus_out_event()
278         cursor->focus_out_event();
279         return 1;
283 int MWindowGUI::resize_event(int w, int h)
285         mwindow->session->mwindow_w = w;
286         mwindow->session->mwindow_h = h;
287         mwindow->theme->get_mwindow_sizes(this, w, h);
288         mwindow->theme->draw_mwindow_bg(this);
289         flash();
290         mainmenu->reposition_window(0, 0, w, mainmenu->get_h());
291         mbuttons->resize_event();
292         statusbar->resize_event();
293         timebar->resize_event();
294         patchbay->resize_event();
295         zoombar->resize_event();
296         get_scrollbars();
297         canvas->resize_event();
298         return 0;
302 void MWindowGUI::update(int scrollbars,
303         int canvas,
304         int timebar,
305         int zoombar,
306         int patchbay, 
307         int clock,
308         int buttonbar)
310 //TRACE("MWindowGUI::update 1");
311         mwindow->edl->tracks->update_y_pixels(mwindow->theme);
312 //TRACE("MWindowGUI::update 1");
313         if(scrollbars) this->get_scrollbars();
314 //TRACE("MWindowGUI::update 1");
315         if(timebar) this->timebar->update();
316 //TRACE("MWindowGUI::update 1");
317         if(zoombar) this->zoombar->update();
318 //TRACE("MWindowGUI::update 1");
319         if(patchbay) this->patchbay->update();
320 //TRACE("MWindowGUI::update 1");
321         if(clock) this->mainclock->update(
322                 mwindow->edl->local_session->get_selectionstart(1));
323 //TRACE("MWindowGUI::update 1");
324         if(canvas)
325         {
326                 this->canvas->draw(canvas == 2);
327                 this->cursor->show();
328                 this->canvas->flash();
329                 this->canvas->activate();
330         }
331 //TRACE("MWindowGUI::update 1");
332         if(buttonbar) mbuttons->update();
333 //TRACE("MWindowGUI::update 100");
336 int MWindowGUI::visible(int64_t x1, int64_t x2, int64_t view_x1, int64_t view_x2)
338         return (x1 >= view_x1 && x1 < view_x2) ||
339                 (x2 > view_x1 && x2 <= view_x2) ||
340                 (x1 <= view_x1 && x2 >= view_x2);
344 int MWindowGUI::show_message(char *message, int color)
346 //printf("MWindowGUI::show_message %s %d\n", message, color);
347         if(color < 0) color = mwindow->theme->message_normal;
348         statusbar->status_text->set_color(color);
349         statusbar->status_text->update(message);
350         return 0;
353 // Drag motion called from other window
354 int MWindowGUI::drag_motion()
356         if(get_hidden()) return 0;
358         canvas->drag_motion();
359         return 0;
362 int MWindowGUI::drag_stop()
364         if(get_hidden()) return 0;
366         int result = canvas->drag_stop();
367         return result;
370 void MWindowGUI::default_positions()
372 //printf("MWindowGUI::default_positions 1\n");
373         mwindow->vwindow->gui->lock_window("MWindowGUI::default_positions");
374         mwindow->cwindow->gui->lock_window("MWindowGUI::default_positions");
375         mwindow->awindow->gui->lock_window("MWindowGUI::default_positions");
377 // printf("MWindowGUI::default_positions 1 %d %d %d %d\n", mwindow->session->vwindow_x, 
378 // mwindow->session->vwindow_y,
379 // mwindow->session->vwindow_w, 
380 // mwindow->session->vwindow_h);
381         reposition_window(mwindow->session->mwindow_x, 
382                 mwindow->session->mwindow_y,
383                 mwindow->session->mwindow_w, 
384                 mwindow->session->mwindow_h);
385         mwindow->vwindow->gui->reposition_window(mwindow->session->vwindow_x, 
386                 mwindow->session->vwindow_y,
387                 mwindow->session->vwindow_w, 
388                 mwindow->session->vwindow_h);
389         mwindow->cwindow->gui->reposition_window(mwindow->session->cwindow_x, 
390                 mwindow->session->cwindow_y,
391                 mwindow->session->cwindow_w, 
392                 mwindow->session->cwindow_h);
393         mwindow->awindow->gui->reposition_window(mwindow->session->awindow_x, 
394                 mwindow->session->awindow_y,
395                 mwindow->session->awindow_w, 
396                 mwindow->session->awindow_h);
397 //printf("MWindowGUI::default_positions 1\n");
399         resize_event(mwindow->session->mwindow_w, 
400                 mwindow->session->mwindow_h);
401 //printf("MWindowGUI::default_positions 1\n");
402         mwindow->vwindow->gui->resize_event(mwindow->session->vwindow_w, 
403                 mwindow->session->vwindow_h);
404 //printf("MWindowGUI::default_positions 1\n");
405         mwindow->cwindow->gui->resize_event(mwindow->session->cwindow_w, 
406                 mwindow->session->cwindow_h);
407 //printf("MWindowGUI::default_positions 1\n");
408         mwindow->awindow->gui->resize_event(mwindow->session->awindow_w, 
409                 mwindow->session->awindow_h);
411 //printf("MWindowGUI::default_positions 1\n");
413         flush();
414         mwindow->vwindow->gui->flush();
415         mwindow->cwindow->gui->flush();
416         mwindow->awindow->gui->flush();
418         mwindow->vwindow->gui->unlock_window();
419         mwindow->cwindow->gui->unlock_window();
420         mwindow->awindow->gui->unlock_window();
421 //printf("MWindowGUI::default_positions 2\n");
440 int MWindowGUI::repeat_event(int64_t duration)
442 // if(duration == 100)
443 // mwindow->sync_parameters(CHANGE_ALL);
444         return cursor->repeat_event(duration);
448 int MWindowGUI::translation_event()
450 //printf("MWindowGUI::translation_event 1 %d %d\n", get_x(), get_y());
451         mwindow->session->mwindow_x = get_x();
452         mwindow->session->mwindow_y = get_y();
453         return 0;
457 int MWindowGUI::save_defaults(Defaults *defaults)
459         defaults->update("MWINDOWWIDTH", get_w());
460         defaults->update("MWINDOWHEIGHT", get_h());
461         mainmenu->save_defaults(defaults);
462         BC_WindowBase::save_defaults(defaults);
465 int MWindowGUI::keypress_event()
467 //printf("MWindowGUI::keypress_event 1 %d\n", get_keypress());
468         int result = 0;
469         result = mbuttons->keypress_event();
471         if(!result)
472         {
473                 switch(get_keypress())
474                 {
475                         case LEFT:
476                                 if(!ctrl_down()) 
477                                 { 
478                                         mwindow->move_left(); 
479                                         result = 1; 
480                                 }
481                                 break;
482                         case RIGHT:
483                                 if(!ctrl_down()) 
484                                 { 
485                                         mwindow->move_right(); 
486                                         result = 1; 
487                                 }
488                                 break;
490                         case UP:
491                                 if(ctrl_down())
492                                 {
493                                         mwindow->expand_y();
494                                         result = 1;
495                                 }
496                                 else
497                                 if(alt_down())
498                                 {
499                                         mwindow->expand_autos();
500                                         result = 1;
501                                 }
502                                 else
503                                 {
504                                         mwindow->expand_sample();
505                                         result = 1;
506                                 }
507                                 break;
509                         case DOWN:
510                                 if(ctrl_down())
511                                 {
512                                         mwindow->zoom_in_y();
513                                         result = 1;
514                                 }
515                                 else
516                                 if(alt_down())
517                                 {
518                                         mwindow->shrink_autos();
519                                         result = 1;
520                                 }
521                                 else
522                                 {
523                                         mwindow->zoom_in_sample();
524                                         result = 1;
525                                 }
526                                 break;
528                         case PGUP:
529                                 if(!ctrl_down())
530                                 {
531                                         mwindow->move_up();
532                                         result = 1;
533                                 }
534                                 else
535                                 {
536                                         mwindow->expand_t();
537                                         result = 1;
538                                 }
539                                 break;
541                         case PGDN:
542                                 if(!ctrl_down())
543                                 {
544                                         mwindow->move_down();
545                                         result = 1;
546                                 }
547                                 else
548                                 {
549                                         mwindow->zoom_in_t();
550                                         result = 1;
551                                 }
552                                 break;
554                         case TAB:
555                         case LEFTTAB:
556                                 int cursor_x = canvas->get_relative_cursor_x();
557                                 int cursor_y = canvas->get_relative_cursor_y();
559                                 if(get_keypress() == TAB)
560                                 {
561 // Switch the record button
562                                         for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
563                                         {
564                                                 int64_t track_x, track_y, track_w, track_h;
565                                                 canvas->track_dimensions(track, track_x, track_y, track_w, track_h);
567                                                 if(cursor_y >= track_y && 
568                                                         cursor_y < track_y + track_h)
569                                                 {
570                                                         if (track->record)
571                                                                 track->record = 0;
572                                                         else
573                                                                 track->record = 1;
574                                                         result = 1; 
575                                                         break;
576                                                 }
577                                         }
578                                 } 
579                                 else 
580                                 {
581                                         Track *this_track = 0;
582                                         for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
583                                         {
584                                                 int64_t track_x, track_y, track_w, track_h;
585                                                 canvas->track_dimensions(track, track_x, track_y, track_w, track_h);
587                                                 if(cursor_y >= track_y && 
588                                                         cursor_y < track_y + track_h)
589                                                 {
590                                                         // This is our track
591                                                         this_track = track;
592                                                         break;
593                                                 }
594                                         }
596                                         int total_selected = mwindow->edl->tracks->total_of(Tracks::RECORD);
598         // nothing previously selected
599                                         if(total_selected == 0)
600                                         {
601                                                 mwindow->edl->tracks->select_all(Tracks::RECORD,
602                                                         1);
603                                         }
604                                         else
605                                         if(total_selected == 1)
606                                         {
607         // this patch was previously the only one on
608                                                 if(this_track && this_track->record)
609                                                 {
610                                                         mwindow->edl->tracks->select_all(Tracks::RECORD,
611                                                                 1);
612                                                 }
613         // another patch was previously the only one on
614                                                 else
615                                                 {
616                                                         mwindow->edl->tracks->select_all(Tracks::RECORD,
617                                                                 0);
618                                                         if (this_track) 
619                                                                 this_track->record = 1;
621                                                 }
622                                         }
623                                         else
624                                         if(total_selected > 1)
625                                         {
626                                                 mwindow->edl->tracks->select_all(Tracks::RECORD,
627                                                         0);
628                                                 if (this_track) 
629                                                         this_track->record = 1;
630                                         }
632                                 }
634                                 update (0,
635                                                 1,
636                                                 0,
637                                                 0,
638                                                 1,
639                                                 0,
640                                                 1);
641                                 unlock_window();
642                                 mwindow->cwindow->update(0, 1, 1);
643                                 lock_window("TrackCanvas::keypress_event");
645                                 result = 1;
646                                 break;
647                 }
649 // since things under cursor have changed...
650                 if(result) 
651                         cursor_motion_event(); 
652         }
654         return result;
658 int MWindowGUI::close_event() 
660         mainmenu->quit(); 
663 int MWindowGUI::menu_h()
665         return mainmenu->get_h();