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
27 #include "bctextbox.h"
28 #include "bcsubwindow.h"
30 #include "colorpicker.inc"
31 #include "condition.inc"
37 #define PALLETTE_HISTORY_SIZE 16
38 #define COLOR_PICKER_W xS(540)
39 #define COLOR_PICKER_H yS(330)
42 class ColorPicker : public BC_DialogThread
45 ColorPicker(int do_alpha = 0, const char *title = 0);
47 void start_window(int color, int alpha, int ok_cancel=0);
48 virtual void update_gui(int color, int alpha);
49 virtual int handle_new_color(int color, int alpha);
53 int ok_cancel, do_alpha;
60 ColorGUI(BC_WindowBase *window);
63 void add_tool(BC_WindowBase *sub_wdw);
64 void start_selection(int color, int alpha, int ok_cancel);
65 void create_objects();
68 void update_display();
73 void get_screen_sample();
74 int cursor_motion_gui();
75 int button_press_gui();
76 int button_release_gui();
78 virtual void update_gui(int color, int alpha);
79 virtual int handle_new_color(int color, int alpha);
80 virtual void create_objects(ColorGUI *gui) {}
82 static int calculate_w() { return COLOR_PICKER_W; }
83 static int calculate_h() { return COLOR_PICKER_H; }
86 struct { float r, g, b; } rgb;
87 struct { float y, u, v; } yuv;
88 struct { float h, s, v; } hsv;
90 void update_rgb(float r, float g, float b);
91 void update_hsv(float h, float s, float v);
92 void update_yuv(float y, float u, float v);
93 void update_rgb_hex(const char *hex);
97 BC_WindowBase *window;
99 PaletteWheelValue *wheel_value;
100 PaletteOutput *poutput;
110 PaletteAlpha *palpha;
112 PaletteHSV *hsv_h, *hsv_s, *hsv_v;
113 PaletteRGB *rgb_r, *rgb_g, *rgb_b;
114 PaletteYUV *yuv_y, *yuv_u, *yuv_v;
117 PaletteHexButton *hex_btn;
119 PaletteGrabButton *grab_btn;
120 PaletteHistory *history;
122 VFrame *value_bitmap;
125 int orig_color, orig_alpha;
127 int do_alpha, ok_cancel;
130 int palette_history[PALLETTE_HISTORY_SIZE];
133 void update_history(int color);
134 void update_history();
137 class ColorWindow : public BC_Window, public ColorGUI
140 ColorWindow(ColorPicker *thread, int x, int y, int w, int h, const char *title);
143 void update_gui(int color, int alpha);
144 int handle_new_color(int color, int alpha);
146 int close_event() { return close_gui(); }
147 int cursor_motion_event() { return cursor_motion_gui(); }
148 int button_press_event() { return button_press_gui(); }
149 int button_release_event() { return button_release_gui(); }
155 class PaletteWheel : public BC_SubWindow
158 PaletteWheel(ColorGUI *gui, int x, int y);
160 int button_press_event();
161 int cursor_motion_event();
162 int button_release_event();
164 void create_objects();
165 int draw(float hue, float saturation);
166 int get_angle(float x1, float y1, float x2, float y2);
167 float torads(float angle);
174 class PaletteWheelValue : public BC_SubWindow
177 PaletteWheelValue(ColorGUI *gui, int x, int y);
178 ~PaletteWheelValue();
179 void create_objects();
180 int button_press_event();
181 int cursor_motion_event();
182 int button_release_event();
183 int draw(float hue, float saturation, float value);
190 class PaletteOutput : public BC_SubWindow
193 PaletteOutput(ColorGUI *gui, int x, int y);
195 void create_objects();
201 class PaletteHue : public BC_ISlider
204 PaletteHue(ColorGUI *gui, int x, int y);
210 class PaletteSat : public BC_FSlider
213 PaletteSat(ColorGUI *gui, int x, int y);
219 class PaletteVal : public BC_FSlider
222 PaletteVal(ColorGUI *gui, int x, int y);
228 class PaletteRed : public BC_FSlider
231 PaletteRed(ColorGUI *gui, int x, int y);
237 class PaletteGrn : public BC_FSlider
240 PaletteGrn(ColorGUI *gui, int x, int y);
246 class PaletteBlu : public BC_FSlider
249 PaletteBlu(ColorGUI *gui, int x, int y);
255 class PaletteAlpha : public BC_FSlider
258 PaletteAlpha(ColorGUI *gui, int x, int y);
264 class PaletteLum : public BC_FSlider
267 PaletteLum(ColorGUI *gui, int x, int y);
273 class PaletteCr : public BC_FSlider
276 PaletteCr(ColorGUI *gui, int x, int y);
282 class PaletteCb : public BC_FSlider
285 PaletteCb(ColorGUI *gui, int x, int y);
291 class PaletteNum : public BC_TumbleTextBox
297 PaletteNum(ColorGUI *gui, int x, int y,
298 float &output, float min, float max);
300 void update_output() { *output = atof(get_text()); }
301 static int calculate_h() { return BC_Tumbler::calculate_h(); }
304 class PaletteRGB : public PaletteNum
307 PaletteRGB(ColorGUI *gui, int x, int y,
308 float &output, float min, float max)
309 : PaletteNum(gui, x, y, output, min, max) {}
313 class PaletteYUV : public PaletteNum
316 PaletteYUV(ColorGUI *gui, int x, int y,
317 float &output, float min, float max)
318 : PaletteNum(gui, x, y, output, min, max) {}
322 class PaletteHSV : public PaletteNum
325 PaletteHSV(ColorGUI *gui, int x, int y,
326 float &output, float min, float max)
327 : PaletteNum(gui, x, y, output, min, max) {}
331 class PaletteAPH : public PaletteNum
334 PaletteAPH(ColorGUI *gui, int x, int y,
335 float &output, float min, float max)
336 : PaletteNum(gui, x, y, output, min, max) {}
340 class PaletteHexButton : public BC_GenericButton
343 PaletteHexButton(ColorGUI *gui, int x, int y);
349 class PaletteHex : public BC_TextBox
352 PaletteHex(ColorGUI *gui, int x, int y, const char *hex);
354 int keypress_event();
359 class PaletteGrabButton : public BC_Button
362 PaletteGrabButton(ColorGUI *gui, int x, int y);
363 ~PaletteGrabButton();
370 class PaletteHistory : public BC_SubWindow
373 PaletteHistory(ColorGUI *gui, int x, int y);
375 void update(int flush=1);
376 int button_press_event();
377 int button_release_event();
378 int cursor_motion_event();
379 int cursor_leave_event();
380 int repeat_event(int64_t duration);
386 class ColorButton : public BC_Button
389 ColorButton(const char *title,
390 int x, int y, int w, int h,
391 int color, int alpha, int ok_cancel);
394 virtual void set_color(int color);
395 virtual int handle_new_color(int color, int alpha);
396 virtual void handle_done_event(int result);
399 void update_gui(int color, int alpha);
400 void update_gui(int color);
404 int color, alpha, ok_cancel;
405 int orig_color, orig_alpha;
408 ColorButtonPicker *color_picker;
409 ColorButtonThread *color_thread;
412 class ColorButtonPicker : public ColorPicker
415 ColorButtonPicker(ColorButton *color_button);
416 ~ColorButtonPicker();
417 void update(int color, int alpha);
418 int handle_new_color(int color, int alpha);
419 void handle_done_event(int result);
421 void update_gui(int color, int alpha);
423 ColorButton *color_button;
426 class ColorButtonThread : public Thread
429 ColorButtonThread(ColorButton *color_button);
430 ~ColorButtonThread();
436 ColorButton *color_button;
437 Condition *update_lock;
441 class ColorBoxButton : public ColorButton
444 ColorBoxButton(const char *title,
445 int x, int y, int w, int h,
446 int color, int alpha, int ok_cancel);
448 void create_objects();
450 virtual int handle_new_color(int color, int alpha);
451 virtual void handle_done_event(int result);
452 void set_color(int color);
455 class ColorCircleButton : public ColorButton
458 ColorCircleButton(const char *title,
459 int x, int y, int w, int h,
460 int color, int alpha, int ok_cancel);
461 ~ColorCircleButton();
462 void create_objects();
464 virtual int handle_new_color(int color, int alpha);
465 virtual void handle_done_event(int result);
466 void set_color(int color);