+void GWindowColorButton::update_gui(int color)
+{
+ set_color(color);
+ draw_face();
+}
+
+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;
+}