X-Git-Url: http://git.cinelerra-gg.org/git/?a=blobdiff_plain;f=cinelerra-5.1%2Fcinelerra%2Fcolorpicker.C;h=ad559a790d5df2658d4875cfa67b7e07520d4fef;hb=83c58d6d78f6bf0d1d1fd4cfba8654906fe6ec29;hp=1b40fcf0c38f8d00bca6f4b35972422918d71c3c;hpb=7fd85fb66168f6b518c5f2d73e04036e87faa0e1;p=goodguy%2Fcinelerra.git diff --git a/cinelerra-5.1/cinelerra/colorpicker.C b/cinelerra-5.1/cinelerra/colorpicker.C index 1b40fcf0..ad559a79 100644 --- a/cinelerra-5.1/cinelerra/colorpicker.C +++ b/cinelerra-5.1/cinelerra/colorpicker.C @@ -42,9 +42,9 @@ ColorPicker::ColorPicker(int do_alpha, const char *title) { this->title = title; this->do_alpha = do_alpha; - this->do_okcancel = 0; - this->output = BLACK; - this->alpha = 255; + this->ok_cancel = 0; + this->output = this->orig_color = BLACK; + this->alpha = this->orig_alpha = 255; } ColorPicker::~ColorPicker() @@ -52,7 +52,7 @@ ColorPicker::~ColorPicker() close_window(); } -void ColorPicker::start_window(int output, int alpha, int do_okcancel) +void ColorPicker::start_window(int output, int alpha, int ok_cancel) { if( running() ) { ColorWindow *gui = (ColorWindow *)get_gui(); @@ -63,9 +63,11 @@ void ColorPicker::start_window(int output, int alpha, int do_okcancel) } return; } + this->orig_color = output; + this->orig_alpha = alpha; this->output = output; this->alpha = alpha; - this->do_okcancel = do_okcancel; + this->ok_cancel = ok_cancel; start(); } @@ -75,10 +77,10 @@ BC_Window* ColorPicker::new_gui() strcpy(window_title, _(PROGRAM_NAME ": ")); strcat(window_title, title ? title : _("Color Picker")); BC_DisplayInfo display_info; - int x = display_info.get_abs_cursor_x() + 25; - int y = display_info.get_abs_cursor_y() - 100; - int w = 540, h = 330; - if( do_okcancel ) + int x = display_info.get_abs_cursor_x() + xS(25); + int y = display_info.get_abs_cursor_y() - yS(100); + int w = xS(540), h = yS(330); + if( ok_cancel ) h += bmax(BC_OKButton::calculate_h(),BC_CancelButton::calculate_h()); int root_w = display_info.get_root_w(), root_h = display_info.get_root_h(); if( x+w > root_w ) x = root_w - w; @@ -94,7 +96,7 @@ void ColorPicker::update_gui(int output, int alpha) { ColorWindow *gui = (ColorWindow *)get_gui(); if( !gui ) return; - gui->lock_window(); + gui->lock_window("ColorPicker::update_gui"); this->output = output; this->alpha = alpha; gui->change_values(); @@ -105,7 +107,7 @@ void ColorPicker::update_gui(int output, int alpha) int ColorPicker::handle_new_color(int output, int alpha) { printf("ColorPicker::handle_new_color undefined.\n"); - return 0; + return 1; } @@ -146,7 +148,9 @@ ColorWindow::~ColorWindow() void ColorWindow::create_objects() { - int x0 = 10, y0 = 10; + int xs5 = xS(5), xs10 = xS(10), xs15 = xS(15); + int ys10 = yS(10), ys15 = yS(15), ys25 = yS(25), ys40 = yS(40); + int x0 = xs10, y0 = ys10; lock_window("ColorWindow::create_objects"); change_values(); @@ -154,75 +158,76 @@ void ColorWindow::create_objects() add_tool(wheel = new PaletteWheel(this, x, y)); wheel->create_objects(); - x += 180; add_tool(wheel_value = new PaletteWheelValue(this, x, y)); + x += xS(180); add_tool(wheel_value = new PaletteWheelValue(this, x, y)); wheel_value->create_objects(); x = x0; - y += 180; add_tool(output = new PaletteOutput(this, x, y)); + y += yS(180); add_tool(output = new PaletteOutput(this, x, y)); output->create_objects(); - y += output->get_h() + 20; + y += output->get_h() + yS(20); load_history(); int x1 = x; add_tool(hex_btn = new PaletteHexButton(this, x1, y)); char hex[BCSTRLEN]; sprintf(hex,"%06x",thread->output); - x1 += hex_btn->get_w() + 5; + x1 += hex_btn->get_w() + xs5; add_tool(hex_box = new PaletteHex(this, x1, y, hex)); - x1 += hex_box->get_w() + 15; + x1 += hex_box->get_w() + xs15; add_tool(grab_btn = new PaletteGrabButton(this, x1, y)); - y += hex_box->get_h() + 15; - add_tool(history = new PaletteHistory(this, 10, y)); + y += hex_box->get_h() + ys15; + add_tool(history = new PaletteHistory(this, xs10, y)); - x += 240; + x += xS(240); add_tool(new BC_Title(x, y =y0, C_("H:"), SMALLFONT)); - add_tool(new BC_Title(x, y+=25, C_("S:"), SMALLFONT)); - add_tool(new BC_Title(x, y+=25, D_("colorpicker_value#V:"), SMALLFONT)); - add_tool(new BC_Title(x, y+=40, C_("R:"), SMALLFONT)); - add_tool(new BC_Title(x, y+=25, C_("G:"), SMALLFONT)); - add_tool(new BC_Title(x, y+=25, C_("B:"), SMALLFONT)); - add_tool(new BC_Title(x, y+=40, C_("Y:"), SMALLFONT)); - add_tool(new BC_Title(x, y+=25, C_("U:"), SMALLFONT)); - add_tool(new BC_Title(x, y+=25, D_("colorpicker_Cr#V:"), SMALLFONT)); + add_tool(new BC_Title(x, y+=ys25, C_("S:"), SMALLFONT)); + add_tool(new BC_Title(x, y+=ys25, D_("colorpicker_value#V:"), SMALLFONT)); + add_tool(new BC_Title(x, y+=ys40, C_("R:"), SMALLFONT)); + add_tool(new BC_Title(x, y+=ys25, C_("G:"), SMALLFONT)); + add_tool(new BC_Title(x, y+=ys25, C_("B:"), SMALLFONT)); + add_tool(new BC_Title(x, y+=ys40, C_("Y:"), SMALLFONT)); + add_tool(new BC_Title(x, y+=ys25, C_("U:"), SMALLFONT)); + add_tool(new BC_Title(x, y+=ys25, D_("colorpicker_Cr#V:"), SMALLFONT)); if( thread->do_alpha ) - add_tool(new BC_Title(x, y+=40, C_("A:"), SMALLFONT)); - x += 24; + add_tool(new BC_Title(x, y+=ys40, C_("A:"), SMALLFONT)); + x += xS(24); add_tool(hue = new PaletteHue(this, x, y= y0)); - add_tool(sat = new PaletteSat(this, x, y+=25)); - add_tool(val = new PaletteVal(this, x, y+=25)); - add_tool(red = new PaletteRed(this, x, y+=40)); - add_tool(grn = new PaletteGrn(this, x, y+=25)); - add_tool(blu = new PaletteBlu(this, x, y+=25)); - add_tool(lum = new PaletteLum(this, x, y+=40)); - add_tool(c_r = new PaletteCr (this, x, y+=25)); - add_tool(c_b = new PaletteCb (this, x, y+=25)); + add_tool(sat = new PaletteSat(this, x, y+=ys25)); + add_tool(val = new PaletteVal(this, x, y+=ys25)); + add_tool(red = new PaletteRed(this, x, y+=ys40)); + add_tool(grn = new PaletteGrn(this, x, y+=ys25)); + add_tool(blu = new PaletteBlu(this, x, y+=ys25)); + add_tool(lum = new PaletteLum(this, x, y+=ys40)); + add_tool(c_r = new PaletteCr (this, x, y+=ys25)); + add_tool(c_b = new PaletteCb (this, x, y+=ys25)); if( thread->do_alpha ) - add_tool(alpha = new PaletteAlpha(this, x, y+=40)); + add_tool(alpha = new PaletteAlpha(this, x, y+=ys40)); - x += hue->get_w() + 10; + x += hue->get_w() + xs10; hsv_h = new PaletteHSV(this, x,y= y0, hsv.h, 0, 360); hsv_h->create_objects(); hsv_h->set_tooltip(_("Hue")); - hsv_s = new PaletteHSV(this, x,y+=25, hsv.s, 0, 1); + hsv_s = new PaletteHSV(this, x,y+=ys25, hsv.s, 0, 1); hsv_s->create_objects(); hsv_s->set_tooltip(_("Saturation")); - hsv_v = new PaletteHSV(this, x,y+=25, hsv.v, 0, 1); + hsv_v = new PaletteHSV(this, x,y+=ys25, hsv.v, 0, 1); hsv_v->create_objects(); hsv_v->set_tooltip(_("Value")); - rgb_r = new PaletteRGB(this, x,y+=40, rgb.r, 0, 1); + rgb_r = new PaletteRGB(this, x,y+=ys40, rgb.r, 0, 1); rgb_r->create_objects(); rgb_r->set_tooltip(_("Red")); - rgb_g = new PaletteRGB(this, x,y+=25, rgb.g, 0, 1); + rgb_g = new PaletteRGB(this, x,y+=ys25, rgb.g, 0, 1); rgb_g->create_objects(); rgb_g->set_tooltip(_("Green")); - rgb_b = new PaletteRGB(this, x,y+=25, rgb.b, 0, 1); + rgb_b = new PaletteRGB(this, x,y+=ys25, rgb.b, 0, 1); rgb_b->create_objects(); rgb_b->set_tooltip(_("Blue")); - yuv_y = new PaletteYUV(this, x,y+=40, yuv.y, 0, 1); + yuv_y = new PaletteYUV(this, x,y+=ys40, yuv.y, 0, 1); yuv_y->create_objects(); yuv_y->set_tooltip(_("Luminance")); - yuv_u = new PaletteYUV(this, x,y+=25, yuv.u, 0, 1); + yuv_u = new PaletteYUV(this, x,y+=ys25, yuv.u, 0, 1); yuv_u->create_objects(); yuv_u->set_tooltip(_("Blue Luminance Difference")); - yuv_v = new PaletteYUV(this, x,y+=25, yuv.v, 0, 1); + yuv_v = new PaletteYUV(this, x,y+=ys25, yuv.v, 0, 1); yuv_v->create_objects(); yuv_v->set_tooltip(_("Red Luminance Difference")); if( thread->do_alpha ) { - aph_a = new PaletteAPH(this, x,y+=40, aph, 0, 1); + aph_a = new PaletteAPH(this, x,y+=ys40, aph, 0, 1); aph_a->create_objects(); aph_a->set_tooltip(_("Alpha")); } - if( thread->do_okcancel ) { + if( thread->ok_cancel ) { add_tool(new BC_OKButton(this)); add_tool(new BC_CancelButton(this)); } + thread->create_objects(this); update_display(); update_history(); @@ -244,7 +249,7 @@ void ColorWindow::change_values() int ColorWindow::close_event() { - set_done(thread->do_okcancel ? 1 : 0); + set_done(thread->ok_cancel ? 1 : 0); return 1; } @@ -300,13 +305,17 @@ void ColorWindow::update_display() yuv_v->update(yuv.v); hex_box->update(); - if( thread->do_alpha ) + if( thread->do_alpha ) { + alpha->update(aph); aph_a->update(aph); + } } int ColorWindow::handle_event() { - thread->handle_new_color(rgb888(), (int)(255*aph + 0.5)); + unlock_window(); + thread->handle_new_color(rgb888(), alpha8()); + lock_window("ColorWindow::handle_event"); return 1; } @@ -355,8 +364,12 @@ int ColorWindow::button_release_event() void ColorWindow::update_rgb_hex(const char *hex) { - int color; + unsigned color; if( sscanf(hex,"%x",&color) == 1 ) { + if( thread->do_alpha ) { + aph = ((color>>24) & 0xff) / 255.; + aph_a->update(aph); + } float r = ((color>>16) & 0xff) / 255.; float g = ((color>>8) & 0xff) / 255.; float b = ((color>>0) & 0xff) / 255.; @@ -369,7 +382,7 @@ void ColorWindow::update_rgb_hex(const char *hex) PaletteWheel::PaletteWheel(ColorWindow *window, int x, int y) - : BC_SubWindow(x, y, 170, 170) + : BC_SubWindow(x, y, xS(170), yS(170)) { this->window = window; oldhue = 0; @@ -482,27 +495,15 @@ void PaletteWheel::create_objects() } } } -//printf("PaletteWheel::create_objects 1\n"); draw_vframe(&frame, - 0, - 0, - get_w(), - get_h(), - 0, - 0, - get_w(), - get_h(), - 0); -//printf("PaletteWheel::create_objects 1\n"); + 0, 0, get_w(), get_h(), + 0, 0, get_w(), get_h(), 0); oldhue = window->hsv.h; oldsaturation = window->hsv.s; -//printf("PaletteWheel::create_objects 1\n"); draw(oldhue, oldsaturation); -//printf("PaletteWheel::create_objects 1\n"); flash(); -//printf("PaletteWheel::create_objects 2\n"); } float PaletteWheel::torads(float angle) @@ -552,7 +553,7 @@ int PaletteWheel::draw(float hue, float saturation) set_inverse(); set_color(WHITE); - draw_circle(x - 5, y - 5, 10, 10); + draw_circle(x - xS(5), y - yS(5), xS(10), yS(10)); set_opaque(); return 0; } @@ -566,7 +567,7 @@ int PaletteWheel::get_angle(float x1, float y1, float x2, float y2) } PaletteWheelValue::PaletteWheelValue(ColorWindow *window, int x, int y) - : BC_SubWindow(x, y, 40, 170, BLACK) + : BC_SubWindow(x, y, xS(40), yS(170), BLACK) { this->window = window; button_down = 0; @@ -638,7 +639,6 @@ int PaletteWheelValue::draw(float hue, float saturation, float value) row[j * 3 + 2] = b; } } - draw_3d_border(0, 0, get_w(), get_h(), 1); draw_vframe(frame, 2, 2, get_w() - 4, get_h() - 4, 2, 2, get_w() - 4, get_h() - 4, 0); @@ -651,7 +651,7 @@ int PaletteWheelValue::draw(float hue, float saturation, float value) } PaletteOutput::PaletteOutput(ColorWindow *window, int x, int y) - : BC_SubWindow(x, y, 180, 30, BLACK) + : BC_SubWindow(x, y, xS(180), yS(30), BLACK) { this->window = window; } @@ -680,7 +680,7 @@ int PaletteOutput::draw() } PaletteHue::PaletteHue(ColorWindow *window, int x, int y) - : BC_ISlider(x, y, 0, 150, 200, 0, 359, (int)(window->hsv.h), 0) + : BC_ISlider(x, y, 0, xS(150), xS(200), 0, 359, (int)(window->hsv.h), 0) { this->window = window; } @@ -697,7 +697,7 @@ int PaletteHue::handle_event() } PaletteSat::PaletteSat(ColorWindow *window, int x, int y) - : BC_FSlider(x, y, 0, 150, 200, 0, 1.0, window->hsv.s, 0) + : BC_FSlider(x, y, 0, xS(150), xS(200), 0, 1.0, window->hsv.s, 0) { this->window = window; set_precision(0.01); @@ -716,7 +716,7 @@ int PaletteSat::handle_event() PaletteVal::PaletteVal(ColorWindow *window, int x, int y) - : BC_FSlider(x, y, 0, 150, 200, 0, 1.0, window->hsv.v, 0) + : BC_FSlider(x, y, 0, xS(150), xS(200), 0, 1.0, window->hsv.v, 0) { this->window = window; set_precision(0.01); @@ -735,7 +735,7 @@ int PaletteVal::handle_event() PaletteRed::PaletteRed(ColorWindow *window, int x, int y) - : BC_FSlider(x, y, 0, 150, 200, 0, 1, window->rgb.r, 0) + : BC_FSlider(x, y, 0, xS(150), xS(200), 0, 1, window->rgb.r, 0) { this->window = window; set_precision(0.01); @@ -753,7 +753,7 @@ int PaletteRed::handle_event() } PaletteGrn::PaletteGrn(ColorWindow *window, int x, int y) - : BC_FSlider(x, y, 0, 150, 200, 0, 1, window->rgb.g, 0) + : BC_FSlider(x, y, 0, xS(150), xS(200), 0, 1, window->rgb.g, 0) { this->window = window; set_precision(0.01); @@ -771,7 +771,7 @@ int PaletteGrn::handle_event() } PaletteBlu::PaletteBlu(ColorWindow *window, int x, int y) - : BC_FSlider(x, y, 0, 150, 200, 0, 1, window->rgb.b, 0) + : BC_FSlider(x, y, 0, xS(150), xS(200), 0, 1, window->rgb.b, 0) { this->window = window; set_precision(0.01); @@ -789,7 +789,7 @@ int PaletteBlu::handle_event() } PaletteAlpha::PaletteAlpha(ColorWindow *window, int x, int y) - : BC_FSlider(x, y, 0, 150, 200, 0, 1, window->aph, 0) + : BC_FSlider(x, y, 0, xS(150), xS(200), 0, 1, window->aph, 0) { this->window = window; set_precision(0.01); @@ -801,12 +801,14 @@ PaletteAlpha::~PaletteAlpha() int PaletteAlpha::handle_event() { window->aph = get_value(); + window->aph_a->update(window->aph); + window->hex_box->update(); window->handle_event(); return 1; } PaletteLum::PaletteLum(ColorWindow *window, int x, int y) - : BC_FSlider(x, y, 0, 150, 200, 0, 1, window->yuv.y, 0) + : BC_FSlider(x, y, 0, xS(150), xS(200), 0, 1, window->yuv.y, 0) { this->window = window; set_precision(0.01); @@ -824,7 +826,7 @@ int PaletteLum::handle_event() } PaletteCr::PaletteCr(ColorWindow *window, int x, int y) - : BC_FSlider(x, y, 0, 150, 200, 0, 1, window->yuv.u, 0) + : BC_FSlider(x, y, 0, xS(150), xS(200), 0, 1, window->yuv.u, 0) { this->window = window; set_precision(0.01); @@ -842,7 +844,7 @@ int PaletteCr::handle_event() } PaletteCb::PaletteCb(ColorWindow *window, int x, int y) - : BC_FSlider(x, y, 0, 150, 200, 0, 1, window->yuv.v, 0) + : BC_FSlider(x, y, 0, xS(150), xS(200), 0, 1, window->yuv.v, 0) { this->window = window; set_precision(0.01); @@ -967,10 +969,16 @@ int ColorWindow::rgb888() bclamp(r, 0, 255); bclamp(g, 0, 255); bclamp(b, 0, 255); return (r<<16) | (g<<8) | (b<<0); } +int ColorWindow::alpha8() +{ + int a = 255*aph + 0.5; + bclamp(a, 0, 255); + return a; +} PaletteNum::PaletteNum(ColorWindow *window, int x, int y, float &output, float min, float max) - : BC_TumbleTextBox(window, output, min, max, x, y, 64) + : BC_TumbleTextBox(window, output, min, max, x, y, xS(64)) { this->window = window; this->output = &output; @@ -1016,7 +1024,7 @@ int PaletteAPH::handle_event() } PaletteHexButton::PaletteHexButton(ColorWindow *window, int x, int y) - : BC_GenericButton(x, y, 50, "#") + : BC_GenericButton(x, y, xS(50), "#") { this->window = window; set_tooltip(_("hex rgb color")); @@ -1032,7 +1040,7 @@ int PaletteHexButton::handle_event() } PaletteHex::PaletteHex(ColorWindow *window, int x, int y, const char *hex) - : BC_TextBox(x, y, 100, 1, hex) + : BC_TextBox(x, y, xS(100), 1, hex) { this->window = window; } @@ -1041,7 +1049,10 @@ PaletteHex::~PaletteHex() } void PaletteHex::update() { - char hex[BCSTRLEN]; sprintf(hex,"%06x",window->rgb888()); + char hex[BCSTRLEN], *cp = hex; + if( window->thread->do_alpha ) + cp += sprintf(cp,"%02x", window->alpha8()); + sprintf(cp,"%06x",window->rgb888()); BC_TextBox::update(hex); } @@ -1082,7 +1093,7 @@ int PaletteGrabButton::handle_event() } PaletteHistory::PaletteHistory(ColorWindow *window, int x, int y) - : BC_SubWindow(x,y, 200, 24) + : BC_SubWindow(x,y, xS(200), yS(24)) { this->window = window; button_down = 0; @@ -1155,3 +1166,292 @@ int PaletteHistory::repeat_event(int64_t duration) return result; } + +ColorButton::ColorButton(const char *title, + int x, int y, int w, int h, + int color, int alpha, int ok_cancel) + : BC_Button(x, y, w, vframes) +{ + this->title = title; + this->color = this->orig_color = color; + this->alpha = this->orig_alpha = alpha; + this->ok_cancel = ok_cancel; + + for( int i=0; i<3; ++i ) { + vframes[i] = new VFrame(w, h, BC_RGBA8888); + vframes[i]->clear_frame(); + } + color_picker = 0; + color_thread = 0; +} + +ColorButton::~ColorButton() +{ + delete color_thread; + delete color_picker; + for( int i=0; i<3; ++i ) + delete vframes[i]; +} + +void ColorButton::set_color(int color) +{ + printf("ColorButton::set_color %06x\n", color); +} +void ColorButton::handle_done_event(int result) +{ + color_thread->stop(); +} +int ColorButton::handle_new_color(int color, int alpha) +{ + printf("ColorButton::handle_new_color %02x%06x\n", alpha, color); + return 1; +} + +int ColorButton::handle_event() +{ + unlock_window(); + delete color_picker; + color_picker = new ColorButtonPicker(this); + orig_color = color; orig_alpha = alpha; + color_picker->start_window(color, alpha, ok_cancel); + if( !color_thread ) + color_thread = new ColorButtonThread(this); + color_thread->start(); + lock_window("ColorButtonButton::start_color_thread"); + return 1; +} + +void ColorButton::close_picker() +{ + if( color_thread ) color_thread->stop(); + delete color_thread; color_thread = 0; + delete color_picker; color_picker = 0; +} + +void ColorButton::update_gui(int color, int alpha) +{ + if( color_picker ) + color_picker->update_gui(color, alpha); + update_gui(color | (~alpha<<24)); +} + +void ColorButton::update_gui(int color) +{ + set_color(color); + draw_face(); +} + +ColorButtonPicker::ColorButtonPicker(ColorButton *color_button) + : ColorPicker(color_button->alpha >= 0 ? 1 : 0, color_button->title) +{ + this->color_button = color_button; +} + +ColorButtonPicker::~ColorButtonPicker() +{ +} + +void ColorButtonPicker::handle_done_event(int result) +{ + color_button->color_thread->stop(); + color_button->handle_done_event(result); +} + +void ColorButtonPicker::update(int color, int alpha) +{ + color_button->color = color; + color_button->alpha = alpha; + color_button->color_thread->update_lock->unlock(); +} + +int ColorButtonPicker::handle_new_color(int color, int alpha) +{ + color_button->lock_window("ColorButtonPicker::handle_new_color"); + color_button->update_gui(color, alpha); + color_button->unlock_window(); + return color_button->handle_new_color(color, alpha); +} + +void ColorButtonPicker::update_gui() +{ + color_button->lock_window("ColorButtonPicker::update_gui"); + color_button->update_gui(color_button->color, color_button->alpha); + color_button->unlock_window(); +} + +void ColorButtonPicker::update_gui(int color, int alpha) +{ + ColorPicker::update_gui(color, alpha); + color_button->handle_new_color(color, alpha); +} + +ColorButtonThread::ColorButtonThread(ColorButton *color_button) + : Thread(1, 0, 0) +{ + this->color_button = color_button; + this->update_lock = new Condition(0,"ColorButtonThread::update_lock"); + done = 1; +} + +ColorButtonThread::~ColorButtonThread() +{ + stop(); + delete update_lock; +} + +void ColorButtonThread::start() +{ + if( done ) { + done = 0; + Thread::start(); + } +} + +void ColorButtonThread::stop() +{ + if( !done ) { + done = 1; + update_lock->unlock(); + join(); + } +} + +void ColorButtonThread::run() +{ + ColorButtonPicker *color_picker = color_button->color_picker; + color_picker->update_gui(); + while( !done ) { + update_lock->lock("ColorButtonThread::run"); + if( done ) break; + color_picker->update_gui(); + } +} + + +ColorBoxButton::ColorBoxButton(const char *title, + int x, int y, int w, int h, + int color, int alpha, int ok_cancel) + : ColorButton(title, x, y, w, h, color, alpha, ok_cancel) +{ +} +ColorBoxButton::~ColorBoxButton() +{ +} + +int ColorBoxButton::handle_new_color(int color, int alpha) +{ + return ColorButton::handle_new_color(color, alpha); +} +void ColorBoxButton::handle_done_event(int result) +{ + ColorButton::handle_done_event(result); +} +void ColorBoxButton::create_objects() +{ + update_gui(color, alpha); +} + +void ColorBoxButton::set_color(int color) +{ + this->color = (color & 0xffffff); + this->alpha = (~color>>24) & 0xff; + int r = (color>>16) & 0xff; + int g = (color>> 8) & 0xff; + int b = (color>> 0) & 0xff; + int color_model = vframes[0]->get_color_model(); + int bpp = BC_CModels::calculate_pixelsize(color_model); + for( int i=0; i<3; ++i ) { + VFrame *vframe = vframes[i]; + int ww = vframe->get_w(), hh = vframe->get_h(); + uint8_t **rows = vframe->get_rows(); + int rr = r, gg = g, bb = b; + 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; + } + for( int y=0; y 3 ) rp[3] = 0xff; + rp += bpp; + } + } + } + set_images(vframes); +} + +ColorCircleButton::ColorCircleButton(const char *title, + int x, int y, int w, int h, + int color, int alpha, int ok_cancel) + : ColorButton(title, x, y, w, h, color, alpha, ok_cancel) +{ +} +ColorCircleButton::~ColorCircleButton() +{ +} +int ColorCircleButton::handle_new_color(int color, int alpha) +{ + return ColorButton::handle_new_color(color, alpha); +} +void ColorCircleButton::handle_done_event(int result) +{ + ColorButton::handle_done_event(result); +} +void ColorCircleButton::create_objects() +{ + update_gui(color, alpha); +} + +void ColorCircleButton::set_color(int color) +{ + this->color = (color & 0xffffff); + this->alpha = (~color>>24) & 0xff; + 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); +} +