+ this->color = color;
+ int r = (color>>16) & 0xff;
+ int g = (color>>8) & 0xff;
+ int b = (color>>0) & 0xff;
+ for( int i=0; i<3; ++i ) {
+ VFrame *vframe = vframes[i];
+ int ww = vframe->get_w(), hh = vframe->get_h();
+ int cx = (ww+1)/2, cy = hh/2;
+ double cc = (cx*cx + cy*cy) / 4.;
+ uint8_t *bp = vframe->get_data(), *dp = bp;
+ uint8_t *ep = dp + vframe->get_data_size();
+ int rr = r, gg = g, bb = b;
+ int bpl = vframe->get_bytes_per_line();
+ switch( i ) {
+ case BUTTON_UP:
+ break;
+ case BUTTON_UPHI:
+ if( (rr+=48) > 0xff ) rr = 0xff;
+ if( (gg+=48) > 0xff ) gg = 0xff;
+ if( (bb+=48) > 0xff ) bb = 0xff;
+ break;
+ case BUTTON_DOWNHI:
+ if( (rr-=48) < 0x00 ) rr = 0x00;
+ if( (gg-=48) < 0x00 ) gg = 0x00;
+ if( (bb-=48) < 0x00 ) bb = 0x00;
+ break;
+ }
+ while( dp < ep ) {
+ int yy = (dp-bp) / bpl, xx = ((dp-bp) % bpl) >> 2;
+ int dy = cy - yy, dx = cx - xx;
+ double s = dx*dx + dy*dy - cc;
+ double ss = s < 0 ? 1 : s >= cc ? 0 : 1 - s/cc;
+ int aa = ss * 0xff;
+ *dp++ = rr; *dp++ = gg; *dp++ = bb; *dp++ = aa;
+ }
+ }
+ set_images(vframes);
+}
+
+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();
+ }
+}
+