r807: Minor fix...
[cinelerra_cv/mob.git] / cinelerra / mwindowgui.C
blob8527251cab4f56db452dd8f85b41e2ffc229029a
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                                         if (alt_down())
479                                                 mwindow->prev_edit_handle();
480                                         else
481                                                 mwindow->move_left(); 
482                                         result = 1; 
483                                 }
484                                 break;
485                         case RIGHT:
486                                 if(!ctrl_down()) 
487                                 { 
488                                         if (alt_down())
489                                                 mwindow->next_edit_handle();
490                                         else
491                                                 mwindow->move_right(); 
492                                         result = 1; 
493                                 }
494                                 break;
496                         case UP:
497                                 if(ctrl_down())
498                                 {
499                                         mwindow->expand_y();
500                                         result = 1;
501                                 }
502                                 else
503                                 if(alt_down())
504                                 {
505                                         mwindow->expand_autos();
506                                         result = 1;
507                                 }
508                                 else
509                                 {
510                                         mwindow->expand_sample();
511                                         result = 1;
512                                 }
513                                 break;
515                         case DOWN:
516                                 if(ctrl_down())
517                                 {
518                                         mwindow->zoom_in_y();
519                                         result = 1;
520                                 }
521                                 else
522                                 if(alt_down())
523                                 {
524                                         mwindow->shrink_autos();
525                                         result = 1;
526                                 }
527                                 else
528                                 {
529                                         mwindow->zoom_in_sample();
530                                         result = 1;
531                                 }
532                                 break;
534                         case PGUP:
535                                 if(!ctrl_down())
536                                 {
537                                         mwindow->move_up();
538                                         result = 1;
539                                 }
540                                 else
541                                 {
542                                         mwindow->expand_t();
543                                         result = 1;
544                                 }
545                                 break;
547                         case PGDN:
548                                 if(!ctrl_down())
549                                 {
550                                         mwindow->move_down();
551                                         result = 1;
552                                 }
553                                 else
554                                 {
555                                         mwindow->zoom_in_t();
556                                         result = 1;
557                                 }
558                                 break;
560                         case TAB:
561                         case LEFTTAB:
562                                 int cursor_x = canvas->get_relative_cursor_x();
563                                 int cursor_y = canvas->get_relative_cursor_y();
565                                 if(get_keypress() == TAB)
566                                 {
567 // Switch the record button
568                                         for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
569                                         {
570                                                 int64_t track_x, track_y, track_w, track_h;
571                                                 canvas->track_dimensions(track, track_x, track_y, track_w, track_h);
573                                                 if(cursor_y >= track_y && 
574                                                         cursor_y < track_y + track_h)
575                                                 {
576                                                         if (track->record)
577                                                                 track->record = 0;
578                                                         else
579                                                                 track->record = 1;
580                                                         result = 1; 
581                                                         break;
582                                                 }
583                                         }
584                                 } 
585                                 else 
586                                 {
587                                         Track *this_track = 0;
588                                         for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
589                                         {
590                                                 int64_t track_x, track_y, track_w, track_h;
591                                                 canvas->track_dimensions(track, track_x, track_y, track_w, track_h);
593                                                 if(cursor_y >= track_y && 
594                                                         cursor_y < track_y + track_h)
595                                                 {
596                                                         // This is our track
597                                                         this_track = track;
598                                                         break;
599                                                 }
600                                         }
602                                         int total_selected = mwindow->edl->tracks->total_of(Tracks::RECORD);
604         // nothing previously selected
605                                         if(total_selected == 0)
606                                         {
607                                                 mwindow->edl->tracks->select_all(Tracks::RECORD,
608                                                         1);
609                                         }
610                                         else
611                                         if(total_selected == 1)
612                                         {
613         // this patch was previously the only one on
614                                                 if(this_track && this_track->record)
615                                                 {
616                                                         mwindow->edl->tracks->select_all(Tracks::RECORD,
617                                                                 1);
618                                                 }
619         // another patch was previously the only one on
620                                                 else
621                                                 {
622                                                         mwindow->edl->tracks->select_all(Tracks::RECORD,
623                                                                 0);
624                                                         if (this_track) 
625                                                                 this_track->record = 1;
627                                                 }
628                                         }
629                                         else
630                                         if(total_selected > 1)
631                                         {
632                                                 mwindow->edl->tracks->select_all(Tracks::RECORD,
633                                                         0);
634                                                 if (this_track) 
635                                                         this_track->record = 1;
636                                         }
638                                 }
640                                 update (0,
641                                                 1,
642                                                 0,
643                                                 0,
644                                                 1,
645                                                 0,
646                                                 1);
647                                 unlock_window();
648                                 mwindow->cwindow->update(0, 1, 1);
649                                 lock_window("TrackCanvas::keypress_event");
651                                 result = 1;
652                                 break;
653                 }
655 // since things under cursor have changed...
656                 if(result) 
657                         cursor_motion_event(); 
658         }
660         return result;
664 int MWindowGUI::close_event() 
666         mainmenu->quit(); 
669 int MWindowGUI::menu_h()
671         return mainmenu->get_h();