1 #include "awindowgui.h"
4 #include "cwindowgui.h"
9 #include "edlsession.h"
10 #include "filesystem.h"
11 #include "keyframepopup.h"
14 #include "localsession.h"
15 #include "mainclock.h"
16 #include "maincursor.h"
18 #include "mainsession.h"
22 #include "mwindowgui.h"
25 #include "pluginpopup.h"
26 #include "samplescroll.h"
27 #include "statusbar.h"
29 #include "trackcanvas.h"
30 #include "trackscroll.h"
32 #include "transitionpopup.h"
33 #include "vwindowgui.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,
50 this->mwindow = mwindow;
58 MWindowGUI::~MWindowGUI()
63 if(samplescroll) delete samplescroll;
64 if(trackscroll) delete trackscroll;
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();
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++)
93 // if(w_needed > view_w)
96 // view_h = mwindow->theme->mcanvas_h - SCROLL_SPAN;
101 // if(h_needed > view_h)
104 // view_w = mwindow->theme->mcanvas_w - SCROLL_SPAN;
109 //printf("MWindowGUI::get_scrollbars 1\n");
111 if(canvas && (view_w != canvas->get_w() || view_h != canvas->get_h()))
113 canvas->reposition_window(mwindow->theme->mcanvas_x,
114 mwindow->theme->mcanvas_y,
118 //printf("MWindowGUI::get_scrollbars 1\n");
123 add_subwindow(samplescroll = new SampleScroll(mwindow,
125 mwindow->theme->mhscroll_x,
126 mwindow->theme->mhscroll_y,
127 mwindow->theme->mhscroll_w));
129 samplescroll->resize_event();
131 samplescroll->set_position();
135 if(samplescroll) delete samplescroll;
137 mwindow->edl->local_session->view_start = 0;
139 //printf("MWindowGUI::get_scrollbars 1\n");
143 //printf("MWindowGUI::get_scrollbars 1.1 %p %p\n", this, canvas);
145 add_subwindow(trackscroll = new TrackScroll(mwindow,
147 mwindow->theme->mvscroll_x,
148 mwindow->theme->mvscroll_y,
149 mwindow->theme->mvscroll_h));
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,
158 //printf("MWindowGUI::get_scrollbars 1.3\n");
162 if(trackscroll) delete trackscroll;
164 mwindow->edl->local_session->track_start = 0;
166 //printf("get_scrollbars 2 %d %d\n", need_xscroll, w_needed);
169 int MWindowGUI::create_objects()
172 set_icon(mwindow->theme->get_image("mwindow_icon"));
177 add_subwindow(mainmenu = new MainMenu(mwindow, this));
180 mwindow->theme->get_mwindow_sizes(this, get_w(), get_h());
181 mwindow->theme->draw_mwindow_bg(this);
182 mainmenu->create_objects();
185 add_subwindow(mbuttons = new MButtons(mwindow, this));
186 mbuttons->create_objects();
189 add_subwindow(timebar = new MTimeBar(mwindow,
191 mwindow->theme->mtimebar_x,
192 mwindow->theme->mtimebar_y,
193 mwindow->theme->mtimebar_w,
194 mwindow->theme->mtimebar_h));
195 timebar->create_objects();
198 add_subwindow(patchbay = new PatchBay(mwindow, this));
199 patchbay->create_objects();
205 mwindow->gui->add_subwindow(canvas = new TrackCanvas(mwindow, this));
206 canvas->create_objects();
209 add_subwindow(zoombar = new ZoomBar(mwindow, this));
210 zoombar->create_objects();
213 add_subwindow(statusbar = new StatusBar(mwindow, this));
214 statusbar->create_objects();
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);
228 cursor = new MainCursor(mwindow, this);
229 cursor->create_objects();
232 add_subwindow(edit_menu = new EditPopup(mwindow, this));
233 edit_menu->create_objects();
236 add_subwindow(plugin_menu = new PluginPopup(mwindow, this));
237 plugin_menu->create_objects();
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();
252 void MWindowGUI::update_title(char *path)
255 char filename[BCTEXTLEN], string[BCTEXTLEN];
256 fs.extract_name(filename, path);
257 sprintf(string, PROGRAM_NAME ": %s", filename);
259 //printf("MWindowGUI::update_title %s\n", string);
263 void MWindowGUI::redraw_time_dependancies()
265 zoombar->redraw_time_dependancies();
267 mainclock->update(mwindow->edl->local_session->get_selectionstart(1));
270 int MWindowGUI::focus_in_event()
272 cursor->focus_in_event();
276 int MWindowGUI::focus_out_event()
278 cursor->focus_out_event();
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);
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();
297 canvas->resize_event();
302 void MWindowGUI::update(int scrollbars,
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");
326 this->canvas->draw(canvas == 2);
327 this->cursor->show();
328 this->canvas->flash();
329 this->canvas->activate();
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);
353 // Drag motion called from other window
354 int MWindowGUI::drag_motion()
356 if(get_hidden()) return 0;
358 canvas->drag_motion();
362 int MWindowGUI::drag_stop()
364 if(get_hidden()) return 0;
366 int result = canvas->drag_stop();
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");
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();
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());
469 result = mbuttons->keypress_event();
473 switch(get_keypress())
478 mwindow->move_left();
485 mwindow->move_right();
499 mwindow->expand_autos();
504 mwindow->expand_sample();
512 mwindow->zoom_in_y();
518 mwindow->shrink_autos();
523 mwindow->zoom_in_sample();
544 mwindow->move_down();
549 mwindow->zoom_in_t();
556 int cursor_x = canvas->get_relative_cursor_x();
557 int cursor_y = canvas->get_relative_cursor_y();
559 if(get_keypress() == TAB)
561 // Switch the record button
562 for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
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)
581 Track *this_track = 0;
582 for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
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)
596 int total_selected = mwindow->edl->tracks->total_of(Tracks::RECORD);
598 // nothing previously selected
599 if(total_selected == 0)
601 mwindow->edl->tracks->select_all(Tracks::RECORD,
605 if(total_selected == 1)
607 // this patch was previously the only one on
608 if(this_track && this_track->record)
610 mwindow->edl->tracks->select_all(Tracks::RECORD,
613 // another patch was previously the only one on
616 mwindow->edl->tracks->select_all(Tracks::RECORD,
619 this_track->record = 1;
624 if(total_selected > 1)
626 mwindow->edl->tracks->select_all(Tracks::RECORD,
629 this_track->record = 1;
642 mwindow->cwindow->update(0, 1, 1);
643 lock_window("TrackCanvas::keypress_event");
649 // since things under cursor have changed...
651 cursor_motion_event();
658 int MWindowGUI::close_event()
663 int MWindowGUI::menu_h()
665 return mainmenu->get_h();