4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "bcsignals.h"
26 #include "condition.h"
28 #include "edlsession.h"
29 #include "gwindowgui.h"
32 #include "localsession.h"
34 #include "mainsession.h"
36 #include "mwindowgui.h"
39 #include "trackcanvas.h"
46 GWindowGUI::GWindowGUI(MWindow *mwindow, int w, int h)
47 : BC_Window(_(PROGRAM_NAME ": Overlays"),
48 mwindow->session->gwindow_x, mwindow->session->gwindow_y,
51 this->mwindow = mwindow;
56 GWindowGUI::~GWindowGUI()
60 const char *GWindowGUI::non_auto_text[NON_AUTOMATION_TOTAL] =
65 N_("Plugin Keyframes"),
68 const char *GWindowGUI::auto_text[AUTOMATION_TOTAL] =
84 int GWindowGUI::auto_colors[AUTOMATION_TOTAL] =
100 void GWindowGUI::load_defaults()
102 BC_Hash *defaults = mwindow->defaults;
103 auto_colors[AUTOMATION_MUTE] = defaults->get("AUTO_COLOR_MUTE", auto_colors[AUTOMATION_MUTE]);
104 auto_colors[AUTOMATION_CAMERA_X] = defaults->get("AUTO_COLOR_CAMERA_X", auto_colors[AUTOMATION_CAMERA_X]);
105 auto_colors[AUTOMATION_CAMERA_Y] = defaults->get("AUTO_COLOR_CAMERA_Y", auto_colors[AUTOMATION_CAMERA_Y]);
106 auto_colors[AUTOMATION_CAMERA_Z] = defaults->get("AUTO_COLOR_CAMERA_Z", auto_colors[AUTOMATION_CAMERA_Z]);
107 auto_colors[AUTOMATION_PROJECTOR_X] = defaults->get("AUTO_COLOR_PROJECTOR_X", auto_colors[AUTOMATION_PROJECTOR_X]);
108 auto_colors[AUTOMATION_PROJECTOR_Y] = defaults->get("AUTO_COLOR_PROJECTOR_Y", auto_colors[AUTOMATION_PROJECTOR_Y]);
109 auto_colors[AUTOMATION_PROJECTOR_Z] = defaults->get("AUTO_COLOR_PROJECTOR_Z", auto_colors[AUTOMATION_PROJECTOR_Z]);
110 auto_colors[AUTOMATION_FADE] = defaults->get("AUTO_COLOR_FADE", auto_colors[AUTOMATION_FADE]);
111 auto_colors[AUTOMATION_SPEED] = defaults->get("AUTO_COLOR_SPEED", auto_colors[AUTOMATION_SPEED]);
114 void GWindowGUI::save_defaults()
116 BC_Hash *defaults = mwindow->defaults;
117 defaults->update("AUTO_COLOR_MUTE", auto_colors[AUTOMATION_MUTE]);
118 defaults->update("AUTO_COLOR_CAMERA_X", auto_colors[AUTOMATION_CAMERA_X]);
119 defaults->update("AUTO_COLOR_CAMERA_Y", auto_colors[AUTOMATION_CAMERA_Y]);
120 defaults->update("AUTO_COLOR_CAMERA_Z", auto_colors[AUTOMATION_CAMERA_Z]);
121 defaults->update("AUTO_COLOR_PROJECTOR_X", auto_colors[AUTOMATION_PROJECTOR_X]);
122 defaults->update("AUTO_COLOR_PROJECTOR_Y", auto_colors[AUTOMATION_PROJECTOR_Y]);
123 defaults->update("AUTO_COLOR_PROJECTOR_Z", auto_colors[AUTOMATION_PROJECTOR_Z]);
124 defaults->update("AUTO_COLOR_FADE", auto_colors[AUTOMATION_FADE]);
125 defaults->update("AUTO_COLOR_SPEED", auto_colors[AUTOMATION_SPEED]);
128 static toggleinfo toggle_order[] =
130 {0, NON_AUTOMATION_ASSETS},
131 {0, NON_AUTOMATION_TITLES},
132 {0, NON_AUTOMATION_TRANSITIONS},
133 {0, NON_AUTOMATION_PLUGIN_AUTOS},
135 {1, AUTOMATION_FADE},
136 {1, AUTOMATION_MUTE},
137 {1, AUTOMATION_SPEED},
138 {1, AUTOMATION_MODE},
140 {1, AUTOMATION_MASK},
142 {1, AUTOMATION_CAMERA_X},
143 {1, AUTOMATION_CAMERA_Y},
144 {1, AUTOMATION_CAMERA_Z},
145 {-1, NONAUTOTOGGLES_CAMERA_XYZ},
147 {1, AUTOMATION_PROJECTOR_X},
148 {1, AUTOMATION_PROJECTOR_Y},
149 {1, AUTOMATION_PROJECTOR_Z},
150 {-1, NONAUTOTOGGLES_PROJECTOR_XYZ},
153 const char *GWindowGUI::toggle_text(toggleinfo *tp)
155 if( tp->isauto > 0 ) return _(auto_text[tp->ref]);
156 if( !tp->isauto ) return _(non_auto_text[tp->ref]);
160 void GWindowGUI::calculate_extents(BC_WindowBase *gui, int *w, int *h)
162 int temp1, temp2, temp3, temp4, temp5, temp6, temp7;
163 int current_w, current_h;
167 for( int i=0; i<(int)(sizeof(toggle_order)/sizeof(toggle_order[0])); ++i ) {
168 toggleinfo *tp = &toggle_order[i];
171 *h += get_resources()->bar_data->get_h() + 5;
174 BC_Toggle::calculate_extents(gui,
175 BC_WindowBase::get_resources()->checkbox_images,
176 0, &temp1, ¤t_w, ¤t_h,
177 &temp2, &temp3, &temp4, &temp5, &temp6, &temp7,
178 toggle_text(tp), MEDIUMFONT);
179 current_w += current_h;
180 *w = MAX(current_w, *w);
188 GWindowColorButton::GWindowColorButton(GWindowToggle *auto_toggle,
189 int x, int y, int w, int color)
190 : ColorCircleButton(auto_toggle->caption, x, y, w, w, color, -1, 1)
192 this->auto_toggle = auto_toggle;
196 GWindowColorButton::~GWindowColorButton()
200 int GWindowColorButton::handle_new_color(int color, int alpha)
203 color_thread->update_lock->unlock();
207 void GWindowColorButton::handle_done_event(int result)
209 ColorCircleButton::handle_done_event(result);
210 int ref = auto_toggle->info->ref;
211 GWindowGUI *gui = auto_toggle->gui;
212 gui->lock_window("GWindowColorThread::handle_done_event");
214 GWindowGUI::auto_colors[ref] = color;
215 auto_toggle->update_gui(color);
216 gui->save_defaults();
219 color = GWindowGUI::auto_colors[ref];
222 gui->unlock_window();
223 MWindowGUI *mwindow_gui = gui->mwindow->gui;
224 mwindow_gui->lock_window("GWindowColorUpdate::run");
225 mwindow_gui->draw_overlays(1);
226 mwindow_gui->unlock_window();
230 void GWindowGUI::create_objects()
233 lock_window("GWindowGUI::create_objects");
235 for( int i=0; i<(int)(sizeof(toggle_order)/sizeof(toggle_order[0])); ++i ) {
236 toggleinfo *tp = &toggle_order[i];
239 BC_Bar *bar = new BC_Bar(x,y,get_w()-x-10);
242 y += bar->get_h() + 5;
245 const char *label = toggle_text(tp);
246 int color = tp->isauto > 0 ? auto_colors[tp->ref] : WHITE;
247 GWindowToggle *toggle = new GWindowToggle(this, x, y, label, color, tp);
248 add_tool(toggles[i] = toggle);
249 if( tp->isauto > 0 ) {
252 case AUTOMATION_MODE: vframe = mwindow->theme->modekeyframe_data; break;
253 case AUTOMATION_PAN: vframe = mwindow->theme->pankeyframe_data; break;
254 case AUTOMATION_MASK: vframe = mwindow->theme->maskkeyframe_data; break;
257 int wh = toggle->get_h() - 4;
258 GWindowColorButton *color_button =
259 new GWindowColorButton(toggle, get_w()-wh-10, y+2, wh, color);
260 add_tool(color_button);
261 color_button->create_objects();
264 draw_vframe(vframe, get_w()-vframe->get_w()-10, y);
266 else if( tp->isauto < 0 ) {
267 const char *accel = 0;
269 case NONAUTOTOGGLES_CAMERA_XYZ:
271 accel = _("Shift-F1");
273 case NONAUTOTOGGLES_PROJECTOR_XYZ:
274 projector_xyz = toggle;
275 accel = _("Shift-F2");
279 int x1 = get_w() - BC_Title::calculate_w(this, accel) - 10;
280 add_subwindow(new BC_Title(x1, y, accel));
283 y += toggles[i]->get_h() + 5;
289 void GWindowGUI::update_mwindow(int toggles, int overlays)
292 mwindow->gui->lock_window("GWindowGUI::update_mwindow");
294 mwindow->gui->mainmenu->update_toggles(0);
296 mwindow->gui->draw_overlays(1);
297 mwindow->gui->unlock_window();
298 lock_window("GWindowGUI::update_mwindow");
301 void GWindowGUI::update_toggles(int use_lock)
304 lock_window("GWindowGUI::update_toggles");
308 for( int i=0; i<(int)(sizeof(toggle_order)/sizeof(toggle_order[0])); ++i ) {
309 if( toggles[i] ) toggles[i]->update();
312 camera_xyz->set_value(check_xyz(AUTOMATION_CAMERA_X) > 0 ? 1 : 0);
313 projector_xyz->set_value(check_xyz(AUTOMATION_PROJECTOR_X) > 0 ? 1 : 0);
315 if(use_lock) unlock_window();
318 void GWindowGUI::toggle_camera_xyz()
320 int v = camera_xyz->get_value() ? 0 : 1;
321 camera_xyz->set_value(v);
322 xyz_check(AUTOMATION_CAMERA_X, v);
324 update_mwindow(1, 1);
327 void GWindowGUI::toggle_projector_xyz()
329 int v = projector_xyz->get_value() ? 0 : 1;
330 projector_xyz->set_value(v);
331 xyz_check(AUTOMATION_PROJECTOR_X, v);
333 update_mwindow(1, 1);
336 int GWindowGUI::translation_event()
338 mwindow->session->gwindow_x = get_x();
339 mwindow->session->gwindow_y = get_y();
343 int GWindowGUI::close_event()
346 mwindow->session->show_gwindow = 0;
349 mwindow->gui->lock_window("GWindowGUI::close_event");
350 mwindow->gui->mainmenu->show_gwindow->set_checked(0);
351 mwindow->gui->unlock_window();
353 lock_window("GWindowGUI::close_event");
354 mwindow->save_defaults();
358 int GWindowGUI::keypress_event()
360 if( ctrl_down() && shift_down() ) {
361 switch(get_keypress()) {
366 if( ctrl_down() && shift_down() ) {
367 resend_event(mwindow->gui);
372 else if( !ctrl_down() && shift_down() ) {
373 switch(get_keypress()) {
378 toggle_projector_xyz();
382 switch(get_keypress()) {
395 int GWindowGUI::check_xyz(int group)
397 // returns 1=all set, -1=all clear, 0=mixed
398 int *autos = mwindow->edl->session->auto_conf->autos;
399 int v = autos[group], ret = v ? 1 : -1;
400 if( autos[group+1] != v || autos[group+2] != v ) ret = 0;
403 void GWindowGUI::xyz_check(int group, int v)
405 int *autos = mwindow->edl->session->auto_conf->autos;
411 int* GWindowGUI::get_main_value(toggleinfo *info)
413 if( info->isauto > 0 )
414 return &mwindow->edl->session->auto_conf->autos[info->ref];
415 if( !info->isauto ) {
416 switch( info->ref ) {
417 case NON_AUTOMATION_ASSETS: return &mwindow->edl->session->show_assets;
418 case NON_AUTOMATION_TITLES: return &mwindow->edl->session->show_titles;
419 case NON_AUTOMATION_TRANSITIONS: return &mwindow->edl->session->auto_conf->transitions;
420 case NON_AUTOMATION_PLUGIN_AUTOS: return &mwindow->edl->session->auto_conf->plugins;
427 GWindowToggle::GWindowToggle(GWindowGUI *gui, int x, int y,
428 const char *text, int color, toggleinfo *info)
429 : BC_CheckBox(x, y, 0, text, MEDIUMFONT, color)
434 this->color_button = 0;
438 GWindowToggle::~GWindowToggle()
443 int GWindowToggle::handle_event()
445 int value = get_value();
458 if( info->isauto >= 0 ) {
459 *gui->get_main_value(info) = value;
460 switch( info->ref ) {
461 case AUTOMATION_CAMERA_X:
462 case AUTOMATION_CAMERA_Y:
463 case AUTOMATION_CAMERA_Z: {
464 int v = gui->check_xyz(AUTOMATION_CAMERA_X);
465 gui->camera_xyz->set_value(v > 0 ? 1 : 0);
467 case AUTOMATION_PROJECTOR_X:
468 case AUTOMATION_PROJECTOR_Y:
469 case AUTOMATION_PROJECTOR_Z: {
470 int v = gui->check_xyz(AUTOMATION_PROJECTOR_X);
471 gui->projector_xyz->set_value(v > 0 ? 1 : 0);
477 switch( info->ref ) {
478 case NONAUTOTOGGLES_CAMERA_XYZ: group = AUTOMATION_CAMERA_X; break;
479 case NONAUTOTOGGLES_PROJECTOR_XYZ: group = AUTOMATION_PROJECTOR_X; break;
482 gui->xyz_check(group, value);
483 gui->update_toggles(0);
486 gui->update_mwindow(1, 0);
488 // Update stuff in MWindow
490 MWindow *mwindow = gui->mwindow;
491 mwindow->gui->lock_window("GWindowToggle::handle_event");
493 mwindow->gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
494 mwindow->gui->draw_overlays(1);
496 if( value && info->isauto > 0 ) {
497 int autogroup_type = -1;
498 switch( info->ref ) {
499 case AUTOMATION_FADE:
500 autogroup_type = mwindow->edl->tracks->recordable_video_tracks() ?
501 AUTOGROUPTYPE_VIDEO_FADE : AUTOGROUPTYPE_AUDIO_FADE ;
503 case AUTOMATION_SPEED:
504 autogroup_type = AUTOGROUPTYPE_SPEED;
506 case AUTOMATION_CAMERA_X:
507 case AUTOMATION_PROJECTOR_X:
508 autogroup_type = AUTOGROUPTYPE_X;
510 case AUTOMATION_CAMERA_Y:
511 case AUTOMATION_PROJECTOR_Y:
512 autogroup_type = AUTOGROUPTYPE_Y;
514 case AUTOMATION_CAMERA_Z:
515 case AUTOMATION_PROJECTOR_Z:
516 autogroup_type = AUTOGROUPTYPE_ZOOM;
519 if( autogroup_type >= 0 ) {
520 mwindow->edl->local_session->zoombar_showautotype = autogroup_type;
521 mwindow->gui->zoombar->update_autozoom();
525 mwindow->gui->unlock_window();
526 lock_window("GWindowToggle::handle_event");
531 void GWindowToggle::update()
533 int *vp = gui->get_main_value(info);
534 if( vp ) set_value(*vp);
537 void GWindowToggle::update_gui(int color)
539 BC_Toggle::color = color;
543 int GWindowToggle::draw_face(int flash, int flush)
545 int ret = BC_Toggle::draw_face(flash, flush);
549 draw_rectangle(text_x-1, text_y-1, text_w+1, text_h+1);
550 if( flash ) this->flash(0);
551 if( flush ) this->flush();
556 void GWindowGUI::set_cool(int reset, int all)
558 for( int i=0; i<(int)(sizeof(toggles)/sizeof(toggles[0])); ++i ) {
559 GWindowToggle* toggle = toggles[i];
560 if( !toggle ) continue;
561 int *vp = get_main_value(toggle->info);
565 toggle->draw_face(1, 0);
568 *vp = toggle->hot_value;
570 toggle->hot_value = *vp;
572 if ( all || toggle->info->isauto > 0 )
581 void GWindowGUI::set_hot(GWindowToggle *toggle)
583 int *vp = get_main_value(toggle->info);
585 set_cool(-1, !toggle->info->isauto ? 1 : 0);
587 toggle->set_value(*vp = 1);