00001 #include "awindowgui.h"
00002 #include "awindow.h"
00003 #include "bcsignals.h"
00004 #include "cwindowgui.h"
00005 #include "cwindow.h"
00006 #include "defaults.h"
00007 #include "editpopup.h"
00008 #include "edl.h"
00009 #include "edlsession.h"
00010 #include "filesystem.h"
00011 #include "keyframepopup.h"
00012 #include "keys.h"
00013 #include "language.h"
00014 #include "localsession.h"
00015 #include "mainclock.h"
00016 #include "maincursor.h"
00017 #include "mainmenu.h"
00018 #include "mainsession.h"
00019 #include "mainundo.h"
00020 #include "mbuttons.h"
00021 #include "mtimebar.h"
00022 #include "mwindowgui.h"
00023 #include "mwindow.h"
00024 #include "patchbay.h"
00025 #include "pluginpopup.h"
00026 #include "samplescroll.h"
00027 #include "statusbar.h"
00028 #include "theme.h"
00029 #include "trackcanvas.h"
00030 #include "trackscroll.h"
00031 #include "tracks.h"
00032 #include "transitionpopup.h"
00033 #include "vwindowgui.h"
00034 #include "vwindow.h"
00035 #include "zoombar.h"
00036
00037
00038 MWindowGUI::MWindowGUI(MWindow *mwindow)
00039 : BC_Window(PROGRAM_NAME ": Program",
00040 mwindow->session->mwindow_x,
00041 mwindow->session->mwindow_y,
00042 mwindow->session->mwindow_w,
00043 mwindow->session->mwindow_h,
00044 100,
00045 100,
00046 1,
00047 1,
00048 1)
00049 {
00050 this->mwindow = mwindow;
00051 samplescroll = 0;
00052 trackscroll = 0;
00053 cursor = 0;
00054 canvas = 0;
00055 }
00056
00057
00058 MWindowGUI::~MWindowGUI()
00059 {
00060 delete mbuttons;
00061 delete statusbar;
00062 delete zoombar;
00063 if(samplescroll) delete samplescroll;
00064 if(trackscroll) delete trackscroll;
00065 delete cursor;
00066 delete patchbay;
00067 delete timebar;
00068 delete mainclock;
00069 delete edit_menu;
00070 delete plugin_menu;
00071 delete keyframe_menu;
00072 delete transition_menu;
00073 }
00074
00075 void MWindowGUI::get_scrollbars()
00076 {
00077
00078 int64_t h_needed = mwindow->edl->get_tracks_height(mwindow->theme);
00079 int64_t w_needed = mwindow->edl->get_tracks_width();
00080 int need_xscroll = 0;
00081 int need_yscroll = 0;
00082 view_w = mwindow->theme->mcanvas_w;
00083 view_h = mwindow->theme->mcanvas_h;
00084
00085
00086
00087 need_xscroll = need_yscroll = 1;
00088 view_h = mwindow->theme->mcanvas_h;
00089 view_w = mwindow->theme->mcanvas_w;
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 if(canvas && (view_w != canvas->get_w() || view_h != canvas->get_h()))
00112 {
00113 canvas->reposition_window(mwindow->theme->mcanvas_x,
00114 mwindow->theme->mcanvas_y,
00115 view_w,
00116 view_h);
00117 }
00118
00119
00120 if(need_xscroll)
00121 {
00122 if(!samplescroll)
00123 add_subwindow(samplescroll = new SampleScroll(mwindow,
00124 this,
00125 mwindow->theme->mhscroll_x,
00126 mwindow->theme->mhscroll_y,
00127 mwindow->theme->mhscroll_w));
00128 else
00129 samplescroll->resize_event();
00130
00131 samplescroll->set_position();
00132 }
00133 else
00134 {
00135 if(samplescroll) delete samplescroll;
00136 samplescroll = 0;
00137 mwindow->edl->local_session->view_start = 0;
00138 }
00139
00140
00141 if(need_yscroll)
00142 {
00143
00144 if(!trackscroll)
00145 add_subwindow(trackscroll = new TrackScroll(mwindow,
00146 this,
00147 mwindow->theme->mvscroll_x,
00148 mwindow->theme->mvscroll_y,
00149 mwindow->theme->mvscroll_h));
00150 else
00151 trackscroll->resize_event();
00152
00153
00154
00155 trackscroll->update_length(mwindow->edl->get_tracks_height(mwindow->theme),
00156 mwindow->edl->local_session->track_start,
00157 view_h);
00158
00159 }
00160 else
00161 {
00162 if(trackscroll) delete trackscroll;
00163 trackscroll = 0;
00164 mwindow->edl->local_session->track_start = 0;
00165 }
00166
00167 }
00168
00169 int MWindowGUI::create_objects()
00170 {
00171 SET_TRACE
00172 set_icon(mwindow->theme->get_image("mwindow_icon"));
00173
00174 SET_TRACE
00175
00176 cursor = 0;
00177 add_subwindow(mainmenu = new MainMenu(mwindow, this));
00178 SET_TRACE
00179
00180 mwindow->theme->get_mwindow_sizes(this, get_w(), get_h());
00181 mwindow->theme->draw_mwindow_bg(this);
00182 mainmenu->create_objects();
00183 SET_TRACE
00184
00185 add_subwindow(mbuttons = new MButtons(mwindow, this));
00186 mbuttons->create_objects();
00187 SET_TRACE
00188
00189 add_subwindow(timebar = new MTimeBar(mwindow,
00190 this,
00191 mwindow->theme->mtimebar_x,
00192 mwindow->theme->mtimebar_y,
00193 mwindow->theme->mtimebar_w,
00194 mwindow->theme->mtimebar_h));
00195 timebar->create_objects();
00196 SET_TRACE
00197
00198 add_subwindow(patchbay = new PatchBay(mwindow, this));
00199 patchbay->create_objects();
00200 SET_TRACE
00201
00202 get_scrollbars();
00203
00204 SET_TRACE
00205 mwindow->gui->add_subwindow(canvas = new TrackCanvas(mwindow, this));
00206 canvas->create_objects();
00207 SET_TRACE
00208
00209 add_subwindow(zoombar = new ZoomBar(mwindow, this));
00210 zoombar->create_objects();
00211 SET_TRACE
00212
00213 add_subwindow(statusbar = new StatusBar(mwindow, this));
00214 statusbar->create_objects();
00215 SET_TRACE
00216
00217 add_subwindow(mainclock = new MainClock(mwindow,
00218 mwindow->theme->mclock_x,
00219 mwindow->theme->mclock_y,
00220 mwindow->theme->mclock_w));
00221 mainclock->set_frame_offset( (double)
00222 (mwindow->edl->session->get_frame_offset() /
00223 mwindow->edl->session->frame_rate));
00224 mainclock->update(0);
00225
00226 SET_TRACE
00227
00228 cursor = new MainCursor(mwindow, this);
00229 cursor->create_objects();
00230 SET_TRACE
00231
00232 add_subwindow(edit_menu = new EditPopup(mwindow, this));
00233 edit_menu->create_objects();
00234 SET_TRACE
00235
00236 add_subwindow(plugin_menu = new PluginPopup(mwindow, this));
00237 plugin_menu->create_objects();
00238 SET_TRACE
00239
00240 add_subwindow(keyframe_menu = new KeyframePopup(mwindow, this));
00241 keyframe_menu->create_objects();
00242
00243 add_subwindow(transition_menu = new TransitionPopup(mwindow, this));
00244 transition_menu->create_objects();
00245 SET_TRACE
00246
00247 canvas->activate();
00248 SET_TRACE
00249 return 0;
00250 }
00251
00252 void MWindowGUI::update_title(char *path)
00253 {
00254 FileSystem fs;
00255 char filename[BCTEXTLEN], string[BCTEXTLEN];
00256 fs.extract_name(filename, path);
00257 sprintf(string, PROGRAM_NAME ": %s", filename);
00258 set_title(string);
00259
00260 flush();
00261 }
00262
00263 void MWindowGUI::redraw_time_dependancies()
00264 {
00265 zoombar->redraw_time_dependancies();
00266 timebar->update();
00267 mainclock->update(mwindow->edl->local_session->get_selectionstart(1));
00268 }
00269
00270 int MWindowGUI::focus_in_event()
00271 {
00272 cursor->focus_in_event();
00273 return 1;
00274 }
00275
00276 int MWindowGUI::focus_out_event()
00277 {
00278 cursor->focus_out_event();
00279 return 1;
00280 }
00281
00282
00283 int MWindowGUI::resize_event(int w, int h)
00284 {
00285 mwindow->session->mwindow_w = w;
00286 mwindow->session->mwindow_h = h;
00287 mwindow->theme->get_mwindow_sizes(this, w, h);
00288 mwindow->theme->draw_mwindow_bg(this);
00289 flash();
00290 mainmenu->reposition_window(0, 0, w, mainmenu->get_h());
00291 mbuttons->resize_event();
00292 statusbar->resize_event();
00293 timebar->resize_event();
00294 patchbay->resize_event();
00295 zoombar->resize_event();
00296 get_scrollbars();
00297 canvas->resize_event();
00298 return 0;
00299 }
00300
00301
00302 void MWindowGUI::update(int scrollbars,
00303 int canvas,
00304 int timebar,
00305 int zoombar,
00306 int patchbay,
00307 int clock,
00308 int buttonbar)
00309 {
00310
00311 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
00312
00313 if(scrollbars) this->get_scrollbars();
00314
00315 if(timebar) this->timebar->update();
00316
00317 if(zoombar) this->zoombar->update();
00318
00319 if(patchbay) this->patchbay->update();
00320
00321 if(clock) this->mainclock->update(
00322 mwindow->edl->local_session->get_selectionstart(1));
00323
00324 if(canvas)
00325 {
00326 this->canvas->draw(canvas == 2);
00327 this->cursor->show();
00328 this->canvas->flash();
00329 this->canvas->activate();
00330 }
00331
00332 if(buttonbar) mbuttons->update();
00333
00334 }
00335
00336 int MWindowGUI::visible(int64_t x1, int64_t x2, int64_t view_x1, int64_t view_x2)
00337 {
00338 return (x1 >= view_x1 && x1 < view_x2) ||
00339 (x2 > view_x1 && x2 <= view_x2) ||
00340 (x1 <= view_x1 && x2 >= view_x2);
00341 }
00342
00343
00344 int MWindowGUI::show_message(char *message, int color)
00345 {
00346
00347 if(color < 0) color = mwindow->theme->message_normal;
00348 statusbar->status_text->set_color(color);
00349 statusbar->status_text->update(message);
00350 return 0;
00351 }
00352
00353
00354 int MWindowGUI::drag_motion()
00355 {
00356 if(get_hidden()) return 0;
00357
00358 canvas->drag_motion();
00359 return 0;
00360 }
00361
00362 int MWindowGUI::drag_stop()
00363 {
00364 if(get_hidden()) return 0;
00365
00366 int result = canvas->drag_stop();
00367 return result;
00368 }
00369
00370 void MWindowGUI::default_positions()
00371 {
00372
00373 mwindow->vwindow->gui->lock_window("MWindowGUI::default_positions");
00374 mwindow->cwindow->gui->lock_window("MWindowGUI::default_positions");
00375 mwindow->awindow->gui->lock_window("MWindowGUI::default_positions");
00376
00377
00378
00379
00380
00381 reposition_window(mwindow->session->mwindow_x,
00382 mwindow->session->mwindow_y,
00383 mwindow->session->mwindow_w,
00384 mwindow->session->mwindow_h);
00385 mwindow->vwindow->gui->reposition_window(mwindow->session->vwindow_x,
00386 mwindow->session->vwindow_y,
00387 mwindow->session->vwindow_w,
00388 mwindow->session->vwindow_h);
00389 mwindow->cwindow->gui->reposition_window(mwindow->session->cwindow_x,
00390 mwindow->session->cwindow_y,
00391 mwindow->session->cwindow_w,
00392 mwindow->session->cwindow_h);
00393 mwindow->awindow->gui->reposition_window(mwindow->session->awindow_x,
00394 mwindow->session->awindow_y,
00395 mwindow->session->awindow_w,
00396 mwindow->session->awindow_h);
00397
00398
00399 resize_event(mwindow->session->mwindow_w,
00400 mwindow->session->mwindow_h);
00401
00402 mwindow->vwindow->gui->resize_event(mwindow->session->vwindow_w,
00403 mwindow->session->vwindow_h);
00404
00405 mwindow->cwindow->gui->resize_event(mwindow->session->cwindow_w,
00406 mwindow->session->cwindow_h);
00407
00408 mwindow->awindow->gui->resize_event(mwindow->session->awindow_w,
00409 mwindow->session->awindow_h);
00410
00411
00412
00413 flush();
00414 mwindow->vwindow->gui->flush();
00415 mwindow->cwindow->gui->flush();
00416 mwindow->awindow->gui->flush();
00417
00418 mwindow->vwindow->gui->unlock_window();
00419 mwindow->cwindow->gui->unlock_window();
00420 mwindow->awindow->gui->unlock_window();
00421
00422 }
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440 int MWindowGUI::repeat_event(int64_t duration)
00441 {
00442
00443
00444 return cursor->repeat_event(duration);
00445 }
00446
00447
00448 int MWindowGUI::translation_event()
00449 {
00450
00451 mwindow->session->mwindow_x = get_x();
00452 mwindow->session->mwindow_y = get_y();
00453 return 0;
00454 }
00455
00456
00457 int MWindowGUI::save_defaults(Defaults *defaults)
00458 {
00459 defaults->update("MWINDOWWIDTH", get_w());
00460 defaults->update("MWINDOWHEIGHT", get_h());
00461 mainmenu->save_defaults(defaults);
00462 BC_WindowBase::save_defaults(defaults);
00463 }
00464
00465 int MWindowGUI::keypress_event()
00466 {
00467
00468 int result = 0;
00469 result = mbuttons->keypress_event();
00470
00471 if(!result)
00472 {
00473 switch(get_keypress())
00474 {
00475 case LEFT:
00476 if(!ctrl_down())
00477 {
00478 mwindow->move_left();
00479 result = 1;
00480 }
00481 break;
00482 case RIGHT:
00483 if(!ctrl_down())
00484 {
00485 mwindow->move_right();
00486 result = 1;
00487 }
00488 break;
00489
00490 case UP:
00491 if(ctrl_down())
00492 {
00493 mwindow->expand_y();
00494 result = 1;
00495 }
00496 else
00497 if(alt_down())
00498 {
00499 mwindow->expand_autos();
00500 result = 1;
00501 }
00502 else
00503 {
00504 mwindow->expand_sample();
00505 result = 1;
00506 }
00507 break;
00508
00509 case DOWN:
00510 if(ctrl_down())
00511 {
00512 mwindow->zoom_in_y();
00513 result = 1;
00514 }
00515 else
00516 if(alt_down())
00517 {
00518 mwindow->shrink_autos();
00519 result = 1;
00520 }
00521 else
00522 {
00523 mwindow->zoom_in_sample();
00524 result = 1;
00525 }
00526 break;
00527
00528 case PGUP:
00529 if(!ctrl_down())
00530 {
00531 mwindow->move_up();
00532 result = 1;
00533 }
00534 else
00535 {
00536 mwindow->expand_t();
00537 result = 1;
00538 }
00539 break;
00540
00541 case PGDN:
00542 if(!ctrl_down())
00543 {
00544 mwindow->move_down();
00545 result = 1;
00546 }
00547 else
00548 {
00549 mwindow->zoom_in_t();
00550 result = 1;
00551 }
00552 break;
00553
00554 case TAB:
00555 case LEFTTAB:
00556 int cursor_x = canvas->get_relative_cursor_x();
00557 int cursor_y = canvas->get_relative_cursor_y();
00558
00559 if(get_keypress() == TAB)
00560 {
00561
00562 for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
00563 {
00564 int64_t track_x, track_y, track_w, track_h;
00565 canvas->track_dimensions(track, track_x, track_y, track_w, track_h);
00566
00567 if(cursor_y >= track_y &&
00568 cursor_y < track_y + track_h)
00569 {
00570 if (track->record)
00571 track->record = 0;
00572 else
00573 track->record = 1;
00574 result = 1;
00575 break;
00576 }
00577 }
00578 }
00579 else
00580 {
00581 Track *this_track = 0;
00582 for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
00583 {
00584 int64_t track_x, track_y, track_w, track_h;
00585 canvas->track_dimensions(track, track_x, track_y, track_w, track_h);
00586
00587 if(cursor_y >= track_y &&
00588 cursor_y < track_y + track_h)
00589 {
00590
00591 this_track = track;
00592 break;
00593 }
00594 }
00595
00596 int total_selected = mwindow->edl->tracks->total_of(Tracks::RECORD);
00597
00598
00599 if(total_selected == 0)
00600 {
00601 mwindow->edl->tracks->select_all(Tracks::RECORD,
00602 1);
00603 }
00604 else
00605 if(total_selected == 1)
00606 {
00607
00608 if(this_track && this_track->record)
00609 {
00610 mwindow->edl->tracks->select_all(Tracks::RECORD,
00611 1);
00612 }
00613
00614 else
00615 {
00616 mwindow->edl->tracks->select_all(Tracks::RECORD,
00617 0);
00618 if (this_track)
00619 this_track->record = 1;
00620
00621 }
00622 }
00623 else
00624 if(total_selected > 1)
00625 {
00626 mwindow->edl->tracks->select_all(Tracks::RECORD,
00627 0);
00628 if (this_track)
00629 this_track->record = 1;
00630 }
00631
00632 }
00633
00634 update (0,
00635 1,
00636 0,
00637 0,
00638 1,
00639 0,
00640 1);
00641 unlock_window();
00642 mwindow->cwindow->update(0, 1, 1);
00643 lock_window("TrackCanvas::keypress_event");
00644
00645 result = 1;
00646 break;
00647 }
00648
00649
00650 if(result)
00651 cursor_motion_event();
00652 }
00653
00654 return result;
00655 }
00656
00657
00658 int MWindowGUI::close_event()
00659 {
00660 mainmenu->quit();
00661 }
00662
00663 int MWindowGUI::menu_h()
00664 {
00665 return mainmenu->get_h();
00666 }