r499: This commit was manufactured by cvs2svn to create tag 'r1_2_1-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / mwindowgui.C
blob2197e69bf4a8523a833a1fb1c2c39657e1e17236
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 - BC_ScrollBar::get_span(SCROLL_VERT);
89         view_w = mwindow->theme->mcanvas_w - BC_ScrollBar::get_span(SCROLL_HORIZ);
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                                 view_w));
126                 else
127                         samplescroll->resize_event();
129                 samplescroll->set_position();
130         }
131         else
132         {
133                 if(samplescroll) delete samplescroll;
134                 samplescroll = 0;
135                 mwindow->edl->local_session->view_start = 0;
136         }
137 //printf("MWindowGUI::get_scrollbars 1\n");
139         if(need_yscroll)
140         {
141 //printf("MWindowGUI::get_scrollbars 1.1 %p %p\n", this, canvas);
142                 if(!trackscroll)
143                         add_subwindow(trackscroll = new TrackScroll(mwindow, 
144                                 this,
145                                 view_h));
146                 else
147                         trackscroll->resize_event();
150 //printf("MWindowGUI::get_scrollbars 1.2\n");
151                 trackscroll->update_length(mwindow->edl->get_tracks_height(mwindow->theme),
152                         mwindow->edl->local_session->track_start,
153                         view_h);
154 //printf("MWindowGUI::get_scrollbars 1.3\n");
155         }
156         else
157         {
158                 if(trackscroll) delete trackscroll;
159                 trackscroll = 0;
160                 mwindow->edl->local_session->track_start = 0;
161         }
162 //printf("get_scrollbars 2 %d %d\n", need_xscroll, w_needed);
165 int MWindowGUI::create_objects()
167 //set_repeat(100);
169 //printf("MWindowGUI::create_objects 1\n");
170         set_icon(mwindow->theme->mwindow_icon);
171         
172 //printf("MWindowGUI::create_objects 1\n");
174         cursor = 0;
175         add_subwindow(mainmenu = new MainMenu(mwindow, this));
176 //printf("MWindowGUI::create_objects 1\n");
178         mwindow->theme->get_mwindow_sizes(this, get_w(), get_h());
179         mwindow->theme->draw_mwindow_bg(this);
180         mainmenu->create_objects();
181 //printf("MWindowGUI::create_objects 1\n");
183         add_subwindow(mbuttons = new MButtons(mwindow, this));
184         mbuttons->create_objects();
185 //printf("MWindowGUI::create_objects 1\n");
187         add_subwindow(mwindow->timebar = timebar = new MTimeBar(mwindow, 
188                 this,
189                 mwindow->theme->mtimebar_x,
190                 mwindow->theme->mtimebar_y,
191                 mwindow->theme->mtimebar_w,
192                 mwindow->theme->mtimebar_h));
193         timebar->create_objects();
194 //printf("MWindowGUI::create_objects 2\n");
196         add_subwindow(mwindow->patches = patchbay = new PatchBay(mwindow, this));
197         patchbay->create_objects();
198 //printf("MWindowGUI::create_objects 1\n");
200         get_scrollbars();
202 //printf("MWindowGUI::create_objects 1\n");
203         mwindow->gui->add_subwindow(canvas = new TrackCanvas(mwindow, this));
204         canvas->create_objects();
205 //printf("MWindowGUI::create_objects 1\n");
207         add_subwindow(zoombar = new ZoomBar(mwindow, this));
208         zoombar->create_objects();
209 //printf("MWindowGUI::create_objects 1\n");
211         add_subwindow(statusbar = new StatusBar(mwindow, this));
212         statusbar->create_objects();
213 //printf("MWindowGUI::create_objects 1\n");
215         add_subwindow(mainclock = new MainClock(mwindow, 
216                 mwindow->theme->mclock_x,
217                 mwindow->theme->mclock_y,
218                 mwindow->theme->mclock_w));
219         mainclock->set_frame_offset( (double) 
220                 (mwindow->edl->session->get_frame_offset() /
221                 mwindow->edl->session->frame_rate));
222         mainclock->update(0);
224 //printf("MWindowGUI::create_objects 1\n");
226         cursor = new MainCursor(mwindow, this);
227         cursor->create_objects();
228 //printf("MWindowGUI::create_objects 1\n");
230         add_subwindow(edit_menu = new EditPopup(mwindow, this));
231         edit_menu->create_objects();
232 //printf("MWindowGUI::create_objects 1\n");
234         add_subwindow(plugin_menu = new PluginPopup(mwindow, this));
235         plugin_menu->create_objects();
236 //printf("MWindowGUI::create_objects 1\n");
238         add_subwindow(keyframe_menu = new KeyframePopup(mwindow, this));
239         keyframe_menu->create_objects();
241         add_subwindow(transition_menu = new TransitionPopup(mwindow, this));
242         transition_menu->create_objects();
243 //printf("MWindowGUI::create_objects 1\n");
245         canvas->activate();
246 //printf("MWindowGUI::create_objects 1\n");
247         return 0;
250 void MWindowGUI::update_title(char *path)
252         FileSystem fs;
253         char filename[BCTEXTLEN], string[BCTEXTLEN];
254         fs.extract_name(filename, path);
255         sprintf(string, PROGRAM_NAME ": %s", filename);
256         set_title(string);
257 //printf("MWindowGUI::update_title %s\n", string);
258         flush();
261 void MWindowGUI::redraw_time_dependancies() 
263         zoombar->redraw_time_dependancies();
264         timebar->update();
265         mainclock->update(mwindow->edl->local_session->selectionstart);
268 int MWindowGUI::focus_in_event()
270         cursor->focus_in_event();
271         return 1;
274 int MWindowGUI::focus_out_event()
276         cursor->focus_out_event();
277         return 1;
281 int MWindowGUI::resize_event(int w, int h)
283         mwindow->session->mwindow_w = w;
284         mwindow->session->mwindow_h = h;
285         mwindow->theme->get_mwindow_sizes(this, w, h);
286         mwindow->theme->draw_mwindow_bg(this);
287         flash();
288         mainmenu->reposition_window(0, 0, w, mainmenu->get_h());
289         mbuttons->resize_event();
290         statusbar->resize_event();
291         timebar->resize_event();
292         patchbay->resize_event();
293         zoombar->resize_event();
294         get_scrollbars();
295         canvas->resize_event();
296         return 0;
300 void MWindowGUI::update(int scrollbars,
301         int canvas,
302         int timebar,
303         int zoombar,
304         int patchbay, 
305         int clock,
306         int buttonbar)
308 //TRACE("MWindowGUI::update 1");
309         mwindow->edl->tracks->update_y_pixels(mwindow->theme);
310 //TRACE("MWindowGUI::update 1");
311         if(scrollbars) this->get_scrollbars();
312 //TRACE("MWindowGUI::update 1");
313         if(timebar) this->timebar->update();
314 //TRACE("MWindowGUI::update 1");
315         if(zoombar) this->zoombar->update();
316 //TRACE("MWindowGUI::update 1");
317         if(patchbay) this->patchbay->update();
318 //TRACE("MWindowGUI::update 1");
319         if(clock) this->mainclock->update(mwindow->edl->local_session->selectionstart);
320 //TRACE("MWindowGUI::update 1");
321         if(canvas)
322         {
323                 this->canvas->draw(canvas == 2);
324                 this->cursor->show();
325                 this->canvas->flash();
326                 this->canvas->activate();
327         }
328 //TRACE("MWindowGUI::update 1");
329         if(buttonbar) mbuttons->update();
330 //TRACE("MWindowGUI::update 100");
333 int MWindowGUI::visible(int64_t x1, int64_t x2, int64_t view_x1, int64_t view_x2)
335         return (x1 >= view_x1 && x1 < view_x2) ||
336                 (x2 > view_x1 && x2 <= view_x2) ||
337                 (x1 <= view_x1 && x2 >= view_x2);
341 int MWindowGUI::show_message(char *message, int color)
343 //printf("MWindowGUI::show_message %s %d\n", message, color);
344         statusbar->status_text->set_color(color);
345         statusbar->status_text->update(message);
346         return 0;
349 // Drag motion called from other window
350 int MWindowGUI::drag_motion()
352         if(get_hidden()) return 0;
354         canvas->drag_motion();
355         return 0;
358 int MWindowGUI::drag_stop()
360         if(get_hidden()) return 0;
362         int result = canvas->drag_stop();
363         return result;
366 void MWindowGUI::default_positions()
368 //printf("MWindowGUI::default_positions 1\n");
369         mwindow->vwindow->gui->lock_window("MWindowGUI::default_positions");
370         mwindow->cwindow->gui->lock_window("MWindowGUI::default_positions");
371         mwindow->awindow->gui->lock_window("MWindowGUI::default_positions");
373 // printf("MWindowGUI::default_positions 1 %d %d %d %d\n", mwindow->session->vwindow_x, 
374 // mwindow->session->vwindow_y,
375 // mwindow->session->vwindow_w, 
376 // mwindow->session->vwindow_h);
377         reposition_window(mwindow->session->mwindow_x, 
378                 mwindow->session->mwindow_y,
379                 mwindow->session->mwindow_w, 
380                 mwindow->session->mwindow_h);
381         mwindow->vwindow->gui->reposition_window(mwindow->session->vwindow_x, 
382                 mwindow->session->vwindow_y,
383                 mwindow->session->vwindow_w, 
384                 mwindow->session->vwindow_h);
385         mwindow->cwindow->gui->reposition_window(mwindow->session->cwindow_x, 
386                 mwindow->session->cwindow_y,
387                 mwindow->session->cwindow_w, 
388                 mwindow->session->cwindow_h);
389         mwindow->awindow->gui->reposition_window(mwindow->session->awindow_x, 
390                 mwindow->session->awindow_y,
391                 mwindow->session->awindow_w, 
392                 mwindow->session->awindow_h);
393 //printf("MWindowGUI::default_positions 1\n");
395         resize_event(mwindow->session->mwindow_w, 
396                 mwindow->session->mwindow_h);
397 //printf("MWindowGUI::default_positions 1\n");
398         mwindow->vwindow->gui->resize_event(mwindow->session->vwindow_w, 
399                 mwindow->session->vwindow_h);
400 //printf("MWindowGUI::default_positions 1\n");
401         mwindow->cwindow->gui->resize_event(mwindow->session->cwindow_w, 
402                 mwindow->session->cwindow_h);
403 //printf("MWindowGUI::default_positions 1\n");
404         mwindow->awindow->gui->resize_event(mwindow->session->awindow_w, 
405                 mwindow->session->awindow_h);
407 //printf("MWindowGUI::default_positions 1\n");
409         flush();
410         mwindow->vwindow->gui->flush();
411         mwindow->cwindow->gui->flush();
412         mwindow->awindow->gui->flush();
414         mwindow->vwindow->gui->unlock_window();
415         mwindow->cwindow->gui->unlock_window();
416         mwindow->awindow->gui->unlock_window();
417 //printf("MWindowGUI::default_positions 2\n");
436 int MWindowGUI::repeat_event(int64_t duration)
438 // if(duration == 100)
439 // mwindow->sync_parameters(CHANGE_ALL);
440         return cursor->repeat_event(duration);
444 int MWindowGUI::translation_event()
446 //printf("MWindowGUI::translation_event 1 %d %d\n", get_x(), get_y());
447         mwindow->session->mwindow_x = get_x();
448         mwindow->session->mwindow_y = get_y();
449         return 0;
453 int MWindowGUI::save_defaults(Defaults *defaults)
455         defaults->update("MWINDOWWIDTH", get_w());
456         defaults->update("MWINDOWHEIGHT", get_h());
457         mainmenu->save_defaults(defaults);
458         BC_WindowBase::save_defaults(defaults);
461 int MWindowGUI::keypress_event()
463 //printf("MWindowGUI::keypress_event 1 %d\n", get_keypress());
464         int result = 0;
465         result = mbuttons->keypress_event();
466         return result;
470 int MWindowGUI::close_event() 
472         mainmenu->quit(); 
475 int MWindowGUI::menu_h()
477         return mainmenu->get_h();