+GWindowColorThread::GWindowColorThread(GWindowGUI *gui, GWindowColorButton *color_button)
+ : ColorPicker(0, color_button->auto_toggle->caption)
+{
+ this->gui = gui;
+ this->color_button = color_button;
+ this->color = 0;
+ color_update = new GWindowColorUpdate(this);
+}
+
+GWindowColorThread::~GWindowColorThread()
+{
+ delete color_update;
+}
+
+void GWindowColorThread::start(int color)
+{
+ start_window(color, 0, 1);
+ color_update->start();
+}
+
+void GWindowColorThread::handle_done_event(int result)
+{
+ color_update->stop();
+ int ref = color_button->auto_toggle->info->ref;
+ gui->lock_window("GWindowColorThread::handle_done_event");
+ if( !result ) {
+ GWindowGUI::auto_colors[ref] = color;
+ color_button->auto_toggle->update_gui(color);
+ gui->save_defaults();
+ }
+ else {
+ color = GWindowGUI::auto_colors[ref];
+ color_button->update_gui(color);
+ }
+ gui->unlock_window();
+ MWindowGUI *mwindow_gui = gui->mwindow->gui;
+ mwindow_gui->lock_window("GWindowColorUpdate::run");
+ mwindow_gui->draw_overlays(1);
+ mwindow_gui->unlock_window();
+}
+
+int GWindowColorThread::handle_new_color(int color, int alpha)
+{
+ this->color = color;
+ color_update->update_lock->unlock();
+ return 1;
+}
+
+void GWindowColorThread::update_gui()
+{
+ gui->lock_window("GWindowColorThread::update_gui");
+ color_button->update_gui(color);
+ gui->unlock_window();
+}
+
+GWindowColorUpdate::GWindowColorUpdate(GWindowColorThread *color_thread)
+ : Thread(1, 0, 0)
+{
+ this->color_thread = color_thread;
+ this->update_lock = new Condition(0,"GWindowColorUpdate::update_lock");
+ done = 1;
+}
+
+GWindowColorUpdate::~GWindowColorUpdate()
+{
+ stop();
+ delete update_lock;
+}
+
+void GWindowColorUpdate::start()
+{
+ if( done ) {
+ done = 0;
+ Thread::start();
+ }
+}
+
+void GWindowColorUpdate::stop()
+{
+ if( !done ) {
+ done = 1;
+ update_lock->unlock();
+ join();
+ }
+}
+
+void GWindowColorUpdate::run()
+{
+ while( !done ) {
+ update_lock->lock("GWindowColorUpdate::run");
+ if( done ) break;
+ color_thread->update_gui();
+ }
+}
+
+
+int GWindowColorButton::handle_event()
+{
+ GWindowGUI *gui = auto_toggle->gui;
+ gui->start_color_thread(this);
+ return 1;
+}
+
+void GWindowGUI::create_objects()
+{
+ int x = 10, y = 10;
+ lock_window("GWindowGUI::create_objects");
+
+ for( int i=0; i<(int)(sizeof(toggle_order)/sizeof(toggle_order[0])); ++i ) {
+ toggleinfo *tp = &toggle_order[i];
+ int ref = tp->ref;
+ if( ref < 0 ) {
+ BC_Bar *bar = new BC_Bar(x,y,get_w()-x-10);
+ add_tool(bar);
+ toggles[i] = 0;
+ y += bar->get_h() + 5;
+ continue;
+ }
+ const char *label = toggle_text(tp);
+ int color = tp->isauto > 0 ? auto_colors[tp->ref] : WHITE;
+ GWindowToggle *toggle = new GWindowToggle(this, x, y, label, color, tp);
+ add_tool(toggles[i] = toggle);
+ if( tp->isauto > 0 ) {
+ VFrame *vframe = 0;
+ switch( ref ) {
+ case AUTOMATION_MODE: vframe = mwindow->theme->modekeyframe_data; break;
+ case AUTOMATION_PAN: vframe = mwindow->theme->pankeyframe_data; break;
+ case AUTOMATION_MASK: vframe = mwindow->theme->maskkeyframe_data; break;
+ }
+ if( !vframe ) {
+ int wh = toggle->get_h() - 4;
+ GWindowColorButton *color_button =
+ new GWindowColorButton(toggle, get_w()-wh-10, y+2, wh);
+ add_tool(color_button);
+ color_button->set_color(color);
+ color_button->draw_face();
+ }
+ else
+ draw_vframe(vframe, get_w()-vframe->get_w()-10, y);
+ }
+ else if( tp->isauto < 0 ) {
+ const char *accel = 0;
+ switch( ref ) {
+ case NONAUTOTOGGLES_CAMERA_XYZ:
+ camera_xyz = toggle;
+ accel = _("Shift-F1");
+ break;
+ case NONAUTOTOGGLES_PROJECTOR_XYZ:
+ projector_xyz = toggle;
+ accel = _("Shift-F2");
+ break;
+ }
+ if( accel ) {
+ int x1 = get_w() - BC_Title::calculate_w(this, accel) - 10;
+ add_subwindow(new BC_Title(x1, y, accel));
+ }
+ }