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(); }
154 class ColorOK : public BC_OKButton
157 ColorOK(ColorGUI *gui, BC_WindowBase *window);
160 BC_WindowBase *window;
164 class ColorCancel : public BC_CancelButton
167 ColorCancel(ColorGUI *gui, BC_WindowBase *window);
170 BC_WindowBase *window;
174 class PaletteWheel : public BC_SubWindow
177 PaletteWheel(ColorGUI *gui, int x, int y);
179 int button_press_event();
180 int cursor_motion_event();
181 int button_release_event();
183 void create_objects();
184 int draw(float hue, float saturation);
185 int get_angle(float x1, float y1, float x2, float y2);
186 float torads(float angle);
193 class PaletteWheelValue : public BC_SubWindow
196 PaletteWheelValue(ColorGUI *gui, int x, int y);
197 ~PaletteWheelValue();
198 void create_objects();
199 int button_press_event();
200 int cursor_motion_event();
201 int button_release_event();
202 int draw(float hue, float saturation, float value);
209 class PaletteOutput : public BC_SubWindow
212 PaletteOutput(ColorGUI *gui, int x, int y);
214 void create_objects();
220 class PaletteHue : public BC_ISlider
223 PaletteHue(ColorGUI *gui, int x, int y);
229 class PaletteSat : public BC_FSlider
232 PaletteSat(ColorGUI *gui, int x, int y);
238 class PaletteVal : public BC_FSlider
241 PaletteVal(ColorGUI *gui, int x, int y);
247 class PaletteRed : public BC_FSlider
250 PaletteRed(ColorGUI *gui, int x, int y);
256 class PaletteGrn : public BC_FSlider
259 PaletteGrn(ColorGUI *gui, int x, int y);
265 class PaletteBlu : public BC_FSlider
268 PaletteBlu(ColorGUI *gui, int x, int y);
274 class PaletteAlpha : public BC_FSlider
277 PaletteAlpha(ColorGUI *gui, int x, int y);
283 class PaletteLum : public BC_FSlider
286 PaletteLum(ColorGUI *gui, int x, int y);
292 class PaletteCr : public BC_FSlider
295 PaletteCr(ColorGUI *gui, int x, int y);
301 class PaletteCb : public BC_FSlider
304 PaletteCb(ColorGUI *gui, int x, int y);
310 class PaletteNum : public BC_TumbleTextBox
316 PaletteNum(ColorGUI *gui, int x, int y,
317 float &output, float min, float max);
319 void update_output() { *output = atof(get_text()); }
320 static int calculate_h() { return BC_Tumbler::calculate_h(); }
323 class PaletteRGB : public PaletteNum
326 PaletteRGB(ColorGUI *gui, int x, int y,
327 float &output, float min, float max)
328 : PaletteNum(gui, x, y, output, min, max) {}
332 class PaletteYUV : public PaletteNum
335 PaletteYUV(ColorGUI *gui, int x, int y,
336 float &output, float min, float max)
337 : PaletteNum(gui, x, y, output, min, max) {}
341 class PaletteHSV : public PaletteNum
344 PaletteHSV(ColorGUI *gui, int x, int y,
345 float &output, float min, float max)
346 : PaletteNum(gui, x, y, output, min, max) {}
350 class PaletteAPH : public PaletteNum
353 PaletteAPH(ColorGUI *gui, int x, int y,
354 float &output, float min, float max)
355 : PaletteNum(gui, x, y, output, min, max) {}
359 class PaletteHexButton : public BC_GenericButton
362 PaletteHexButton(ColorGUI *gui, int x, int y);
368 class PaletteHex : public BC_TextBox
371 PaletteHex(ColorGUI *gui, int x, int y, const char *hex);
373 int keypress_event();
378 class PaletteGrabButton : public BC_Button
381 PaletteGrabButton(ColorGUI *gui, int x, int y);
382 ~PaletteGrabButton();
389 class PaletteHistory : public BC_SubWindow
392 PaletteHistory(ColorGUI *gui, int x, int y);
394 void update(int flush=1);
395 int button_press_event();
396 int button_release_event();
397 int cursor_motion_event();
398 int cursor_leave_event();
399 int repeat_event(int64_t duration);
405 class ColorButton : public BC_Button
408 ColorButton(const char *title,
409 int x, int y, int w, int h,
410 int color, int alpha, int ok_cancel);
413 virtual void set_color(int color);
414 virtual int handle_new_color(int color, int alpha);
415 virtual void handle_done_event(int result);
418 void update_gui(int color, int alpha);
419 void update_gui(int color);
423 int color, alpha, ok_cancel;
424 int orig_color, orig_alpha;
427 ColorButtonPicker *color_picker;
428 ColorButtonThread *color_thread;
431 class ColorButtonPicker : public ColorPicker
434 ColorButtonPicker(ColorButton *color_button);
435 ~ColorButtonPicker();
436 void update(int color, int alpha);
437 int handle_new_color(int color, int alpha);
438 void handle_done_event(int result);
440 void update_gui(int color, int alpha);
442 ColorButton *color_button;
445 class ColorButtonThread : public Thread
448 ColorButtonThread(ColorButton *color_button);
449 ~ColorButtonThread();
455 ColorButton *color_button;
456 Condition *update_lock;
460 class ColorBoxButton : public ColorButton
463 ColorBoxButton(const char *title,
464 int x, int y, int w, int h,
465 int color, int alpha, int ok_cancel);
467 void create_objects();
469 virtual int handle_new_color(int color, int alpha);
470 virtual void handle_done_event(int result);
471 void set_color(int color);
474 class ColorCircleButton : public ColorButton
477 ColorCircleButton(const char *title,
478 int x, int y, int w, int h,
479 int color, int alpha, int ok_cancel);
480 ~ColorCircleButton();
481 void create_objects();
483 virtual int handle_new_color(int color, int alpha);
484 virtual void handle_done_event(int result);
485 void set_color(int color);