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"
31 #include "localsession.h"
33 #include "mainsession.h"
35 #include "mwindowgui.h"
38 #include "trackcanvas.h"
45 GWindowGUI::GWindowGUI(MWindow *mwindow, int w, int h)
46 : BC_Window(_(PROGRAM_NAME ": Overlays"),
47 mwindow->session->gwindow_x, mwindow->session->gwindow_y,
50 this->mwindow = mwindow;
54 GWindowGUI::~GWindowGUI()
59 void GWindowGUI::start_color_thread(GWindowColorButton *color_button)
63 color_thread = new GWindowColorThread(color_button);
64 int color = auto_colors[color_button->auto_toggle->info->ref];
65 color_thread->start(color);
66 lock_window("GWindowGUI::start_color_thread");
69 const char *GWindowGUI::other_text[NON_AUTOMATION_TOTAL] =
77 const char *GWindowGUI::auto_text[AUTOMATION_TOTAL] =
93 int GWindowGUI::auto_colors[AUTOMATION_TOTAL] =
109 void GWindowGUI::load_defaults()
111 BC_Hash *defaults = mwindow->defaults;
112 auto_colors[AUTOMATION_MUTE] = defaults->get("AUTO_COLOR_MUTE", auto_colors[AUTOMATION_MUTE]);
113 auto_colors[AUTOMATION_CAMERA_X] = defaults->get("AUTO_COLOR_CAMERA_X", auto_colors[AUTOMATION_CAMERA_X]);
114 auto_colors[AUTOMATION_CAMERA_Y] = defaults->get("AUTO_COLOR_CAMERA_Y", auto_colors[AUTOMATION_CAMERA_Y]);
115 auto_colors[AUTOMATION_CAMERA_Z] = defaults->get("AUTO_COLOR_CAMERA_Z", auto_colors[AUTOMATION_CAMERA_Z]);
116 auto_colors[AUTOMATION_PROJECTOR_X] = defaults->get("AUTO_COLOR_PROJECTOR_X", auto_colors[AUTOMATION_PROJECTOR_X]);
117 auto_colors[AUTOMATION_PROJECTOR_Y] = defaults->get("AUTO_COLOR_PROJECTOR_Y", auto_colors[AUTOMATION_PROJECTOR_Y]);
118 auto_colors[AUTOMATION_PROJECTOR_Z] = defaults->get("AUTO_COLOR_PROJECTOR_Z", auto_colors[AUTOMATION_PROJECTOR_Z]);
119 auto_colors[AUTOMATION_FADE] = defaults->get("AUTO_COLOR_FADE", auto_colors[AUTOMATION_FADE]);
120 auto_colors[AUTOMATION_SPEED] = defaults->get("AUTO_COLOR_SPEED", auto_colors[AUTOMATION_SPEED]);
123 void GWindowGUI::save_defaults()
125 BC_Hash *defaults = mwindow->defaults;
126 defaults->update("AUTO_COLOR_MUTE", auto_colors[AUTOMATION_MUTE]);
127 defaults->update("AUTO_COLOR_CAMERA_X", auto_colors[AUTOMATION_CAMERA_X]);
128 defaults->update("AUTO_COLOR_CAMERA_Y", auto_colors[AUTOMATION_CAMERA_Y]);
129 defaults->update("AUTO_COLOR_CAMERA_Z", auto_colors[AUTOMATION_CAMERA_Z]);
130 defaults->update("AUTO_COLOR_PROJECTOR_X", auto_colors[AUTOMATION_PROJECTOR_X]);
131 defaults->update("AUTO_COLOR_PROJECTOR_Y", auto_colors[AUTOMATION_PROJECTOR_Y]);
132 defaults->update("AUTO_COLOR_PROJECTOR_Z", auto_colors[AUTOMATION_PROJECTOR_Z]);
133 defaults->update("AUTO_COLOR_FADE", auto_colors[AUTOMATION_FADE]);
134 defaults->update("AUTO_COLOR_SPEED", auto_colors[AUTOMATION_SPEED]);
137 static toggleinfo toggle_order[] =
139 {0, NON_AUTOMATION_ASSETS},
140 {0, NON_AUTOMATION_TITLES},
141 {0, NON_AUTOMATION_TRANSITIONS},
142 {0, NON_AUTOMATION_PLUGIN_AUTOS},
144 {1, AUTOMATION_FADE},
145 {1, AUTOMATION_MUTE},
146 {1, AUTOMATION_SPEED},
147 {1, AUTOMATION_CAMERA_X},
148 {1, AUTOMATION_CAMERA_Y},
149 {1, AUTOMATION_CAMERA_Z},
150 {1, AUTOMATION_PROJECTOR_X},
151 {1, AUTOMATION_PROJECTOR_Y},
152 {1, AUTOMATION_PROJECTOR_Z},
154 {1, AUTOMATION_MODE},
156 {1, AUTOMATION_MASK},
159 void GWindowGUI::calculate_extents(BC_WindowBase *gui, int *w, int *h)
161 int temp1, temp2, temp3, temp4, temp5, temp6, temp7;
162 int current_w, current_h;
166 for( int i=0; i<(int)(sizeof(toggle_order)/sizeof(toggle_order[0])); ++i ) {
167 toggleinfo *tp = &toggle_order[i];
168 int isauto = tp->isauto, ref = tp->ref;
170 *h += get_resources()->bar_data->get_h() + 5;
173 BC_Toggle::calculate_extents(gui,
174 BC_WindowBase::get_resources()->checkbox_images,
175 0, &temp1, ¤t_w, ¤t_h,
176 &temp2, &temp3, &temp4, &temp5, &temp6, &temp7,
177 _(isauto ? auto_text[ref] : other_text[ref]),
179 current_w += current_h;
180 *w = MAX(current_w, *w);
188 GWindowColorButton::GWindowColorButton(GWindowToggle *auto_toggle, int x, int y, int w)
189 : BC_Button(x, y, w, vframes)
191 this->auto_toggle = auto_toggle;
193 for( int i=0; i<3; ++i )
194 vframes[i] = new VFrame(w, w, BC_RGBA8888, -1);
197 GWindowColorButton::~GWindowColorButton()
199 for( int i=0; i<3; ++i )
203 void GWindowColorButton::set_color(int color)
206 int r = (color>>16) & 0xff;
207 int g = (color>>8) & 0xff;
208 int b = (color>>0) & 0xff;
209 for( int i=0; i<3; ++i ) {
210 VFrame *vframe = vframes[i];
211 int ww = vframe->get_w(), hh = vframe->get_h();
212 int cx = (ww+1)/2, cy = hh/2;
213 double cc = (cx*cx + cy*cy) / 4.;
214 uint8_t *bp = vframe->get_data(), *dp = bp;
215 uint8_t *ep = dp + vframe->get_data_size();
216 int rr = r, gg = g, bb = b;
217 int bpl = vframe->get_bytes_per_line();
222 if( (rr+=48) > 0xff ) rr = 0xff;
223 if( (gg+=48) > 0xff ) gg = 0xff;
224 if( (bb+=48) > 0xff ) bb = 0xff;
227 if( (rr-=48) < 0x00 ) rr = 0x00;
228 if( (gg-=48) < 0x00 ) gg = 0x00;
229 if( (bb-=48) < 0x00 ) bb = 0x00;
233 int yy = (dp-bp) / bpl, xx = ((dp-bp) % bpl) >> 2;
234 int dy = cy - yy, dx = cx - xx;
235 double s = dx*dx + dy*dy - cc;
236 double ss = s < 0 ? 1 : s >= cc ? 0 : 1 - s/cc;
238 *dp++ = rr; *dp++ = gg; *dp++ = bb; *dp++ = aa;
244 void GWindowColorButton::update_gui(int color)
250 GWindowColorThread::GWindowColorThread(GWindowColorButton *color_button)
251 : ColorThread(0, color_button->auto_toggle->caption)
254 this->color_button = color_button;
255 color_update = new GWindowColorUpdate(this);
258 GWindowColorThread::~GWindowColorThread()
263 void GWindowColorThread::start(int color)
265 start_window(color, 0, 1);
266 color_update->start();
269 void GWindowColorThread::handle_done_event(int result)
271 color_update->stop();
272 GWindowGUI *gui = color_button->auto_toggle->gui;
273 int ref = color_button->auto_toggle->info->ref;
274 gui->lock_window("GWindowColorThread::handle_done_event");
276 GWindowGUI::auto_colors[ref] = color;
277 color_button->auto_toggle->update_gui(color);
278 gui->save_defaults();
281 color = GWindowGUI::auto_colors[ref];
282 color_button->update_gui(color);
284 gui->unlock_window();
285 MWindowGUI *mwindow_gui = color_button->auto_toggle->gui->mwindow->gui;
286 mwindow_gui->lock_window("GWindowColorUpdate::run");
287 mwindow_gui->draw_overlays(1);
288 mwindow_gui->unlock_window();
291 int GWindowColorThread::handle_new_color(int color, int alpha)
294 color_update->update_lock->unlock();
298 void GWindowColorThread::update_gui()
300 color_button->update_gui(color);
303 GWindowColorUpdate::GWindowColorUpdate(GWindowColorThread *color_thread)
306 this->color_thread = color_thread;
307 this->update_lock = new Condition(0,"GWindowColorUpdate::update_lock");
311 GWindowColorUpdate::~GWindowColorUpdate()
317 void GWindowColorUpdate::start()
325 void GWindowColorUpdate::stop()
329 update_lock->unlock();
334 void GWindowColorUpdate::run()
337 update_lock->lock("GWindowColorUpdate::run");
339 color_thread->update_gui();
344 int GWindowColorButton::handle_event()
346 GWindowGUI *gui = auto_toggle->gui;
347 gui->start_color_thread(this);
351 void GWindowGUI::create_objects()
354 lock_window("GWindowGUI::create_objects 1");
356 for( int i=0; i<(int)(sizeof(toggle_order)/sizeof(toggle_order[0])); ++i ) {
357 toggleinfo *tp = &toggle_order[i];
360 BC_Bar *bar = new BC_Bar(x,y,get_w()-x-10);
363 y += bar->get_h() + 5;
368 case AUTOMATION_MODE: vframe = mwindow->theme->modekeyframe_data; break;
369 case AUTOMATION_PAN: vframe = mwindow->theme->pankeyframe_data; break;
370 case AUTOMATION_MASK: vframe = mwindow->theme->maskkeyframe_data; break;
372 const char *label = _(tp->isauto ? auto_text[tp->ref] : other_text[tp->ref]);
373 int color = !tp->isauto ? -1 : auto_colors[tp->ref];
374 GWindowToggle *toggle = new GWindowToggle(mwindow, this, x, y, label, color, tp);
375 add_tool(toggles[i] = toggle);
377 draw_vframe(vframe, get_w()-vframe->get_w()-10, y);
378 else if( tp->isauto ) {
379 int wh = toggle->get_h() - 4;
380 GWindowColorButton *color_button =
381 new GWindowColorButton(toggle, get_w()-wh-10, y+2, wh);
382 add_tool(color_button);
383 color_button->set_color(color);
384 color_button->draw_face();
386 y += toggles[i]->get_h() + 5;
391 void GWindowGUI::update_mwindow()
394 mwindow->gui->mainmenu->update_toggles(1);
395 lock_window("GWindowGUI::update_mwindow");
398 void GWindowGUI::update_toggles(int use_lock)
400 if(use_lock) lock_window("GWindowGUI::update_toggles");
402 for( int i=0; i<(int)(sizeof(toggle_order)/sizeof(toggle_order[0])); ++i ) {
403 if( toggles[i] ) toggles[i]->update();
406 if(use_lock) unlock_window();
409 int GWindowGUI::translation_event()
411 mwindow->session->gwindow_x = get_x();
412 mwindow->session->gwindow_y = get_y();
416 int GWindowGUI::close_event()
419 mwindow->session->show_gwindow = 0;
422 mwindow->gui->lock_window("GWindowGUI::close_event");
423 mwindow->gui->mainmenu->show_gwindow->set_checked(0);
424 mwindow->gui->unlock_window();
426 lock_window("GWindowGUI::close_event");
427 mwindow->save_defaults();
431 int GWindowGUI::keypress_event()
433 switch(get_keypress()) {
447 GWindowToggle::GWindowToggle(MWindow *mwindow, GWindowGUI *gui, int x, int y,
448 const char *text, int color, toggleinfo *info)
449 : BC_CheckBox(x, y, *get_main_value(mwindow, info), text, MEDIUMFONT, color)
451 this->mwindow = mwindow;
455 this->color_button = 0;
458 GWindowToggle::~GWindowToggle()
463 int GWindowToggle::handle_event()
465 int value = get_value();
466 *get_main_value(mwindow, info) = value;
467 gui->update_mwindow();
470 // Update stuff in MWindow
472 mwindow->gui->lock_window("GWindowToggle::handle_event");
474 int autogroup_type = -1;
475 switch( info->ref ) {
476 case AUTOMATION_FADE:
477 autogroup_type = mwindow->edl->tracks->recordable_video_tracks() ?
478 AUTOGROUPTYPE_VIDEO_FADE : AUTOGROUPTYPE_AUDIO_FADE ;
480 case AUTOMATION_SPEED:
481 autogroup_type = AUTOGROUPTYPE_SPEED;
483 case AUTOMATION_CAMERA_X:
484 case AUTOMATION_PROJECTOR_X:
485 autogroup_type = AUTOGROUPTYPE_X;
487 case AUTOMATION_CAMERA_Y:
488 case AUTOMATION_PROJECTOR_Y:
489 autogroup_type = AUTOGROUPTYPE_Y;
491 case AUTOMATION_CAMERA_Z:
492 case AUTOMATION_PROJECTOR_Z:
493 autogroup_type = AUTOGROUPTYPE_ZOOM;
496 if( value && autogroup_type >= 0 ) {
497 mwindow->edl->local_session->zoombar_showautotype = autogroup_type;
498 mwindow->gui->zoombar->update_autozoom();
500 mwindow->gui->draw_overlays(1);
503 switch( info->ref ) {
504 case NON_AUTOMATION_ASSETS:
505 case NON_AUTOMATION_TITLES:
506 mwindow->gui->update(1, 1, 0, 0, 1, 0, 0);
509 case NON_AUTOMATION_TRANSITIONS:
510 case NON_AUTOMATION_PLUGIN_AUTOS:
511 mwindow->gui->draw_overlays(1);
516 mwindow->gui->unlock_window();
517 lock_window("GWindowToggle::handle_event");
522 int* GWindowToggle::get_main_value(MWindow *mwindow, toggleinfo *info)
525 return &mwindow->edl->session->auto_conf->autos[info->ref];
527 switch( info->ref ) {
528 case NON_AUTOMATION_ASSETS: return &mwindow->edl->session->show_assets;
529 case NON_AUTOMATION_TITLES: return &mwindow->edl->session->show_titles;
530 case NON_AUTOMATION_TRANSITIONS: return &mwindow->edl->session->auto_conf->transitions;
531 case NON_AUTOMATION_PLUGIN_AUTOS: return &mwindow->edl->session->auto_conf->plugins;
536 void GWindowToggle::update()
538 int *vp = get_main_value(mwindow, info);
543 void GWindowToggle::update_gui(int color)
545 BC_Toggle::color = color;