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 create_objects(ColorWindow *window) {}
49 virtual void update_gui(int color, int alpha);
50 virtual int handle_new_color(int color, int alpha);
54 int ok_cancel, do_alpha;
61 ColorGUI(BC_WindowBase *window);
64 void add_tool(BC_WindowBase *sub_wdw);
65 void start_selection(int color, int alpha, int ok_cancel);
66 void create_objects();
69 void update_display();
74 void get_screen_sample();
75 int cursor_motion_gui();
76 int button_press_gui();
77 int button_release_gui();
79 virtual void update_gui(int color, int alpha);
80 virtual int handle_new_color(int color, int alpha);
81 virtual void create_objects(ColorGUI *gui) {}
83 static int calculate_w() { return COLOR_PICKER_W; }
84 static int calculate_h() { return COLOR_PICKER_H; }
87 struct { float r, g, b; } rgb;
88 struct { float y, u, v; } yuv;
89 struct { float h, s, v; } hsv;
91 void update_rgb(float r, float g, float b);
92 void update_hsv(float h, float s, float v);
93 void update_yuv(float y, float u, float v);
94 void update_rgb_hex(const char *hex);
98 BC_WindowBase *window;
100 PaletteWheelValue *wheel_value;
101 PaletteOutput *poutput;
111 PaletteAlpha *palpha;
113 PaletteHSV *hsv_h, *hsv_s, *hsv_v;
114 PaletteRGB *rgb_r, *rgb_g, *rgb_b;
115 PaletteYUV *yuv_y, *yuv_u, *yuv_v;
118 PaletteHexButton *hex_btn;
120 PaletteGrabButton *grab_btn;
121 PaletteHistory *history;
123 VFrame *value_bitmap;
126 int orig_color, orig_alpha;
128 int do_alpha, ok_cancel;
131 int palette_history[PALLETTE_HISTORY_SIZE];
134 void update_history(int color);
135 void update_history();
138 class ColorWindow : public BC_Window, public ColorGUI
141 ColorWindow(ColorPicker *thread, int x, int y, int w, int h, const char *title);
144 void update_gui(int color, int alpha);
145 int handle_new_color(int color, int alpha);
146 void create_objects();
148 int close_event() { return close_gui(); }
149 int cursor_motion_event() { return cursor_motion_gui(); }
150 int button_press_event() { return button_press_gui(); }
151 int button_release_event() { return button_release_gui(); }
156 class ColorOK : public BC_OKButton
159 ColorOK(ColorGUI *gui, BC_WindowBase *window);
162 BC_WindowBase *window;
166 class ColorCancel : public BC_CancelButton
169 ColorCancel(ColorGUI *gui, BC_WindowBase *window);
172 BC_WindowBase *window;
176 class PaletteWheel : public BC_SubWindow
179 PaletteWheel(ColorGUI *gui, int x, int y);
181 int button_press_event();
182 int cursor_motion_event();
183 int button_release_event();
185 void create_objects();
186 int draw(float hue, float saturation);
187 int get_angle(float x1, float y1, float x2, float y2);
188 float torads(float angle);
195 class PaletteWheelValue : public BC_SubWindow
198 PaletteWheelValue(ColorGUI *gui, int x, int y);
199 ~PaletteWheelValue();
200 void create_objects();
201 int button_press_event();
202 int cursor_motion_event();
203 int button_release_event();
204 int draw(float hue, float saturation, float value);
211 class PaletteOutput : public BC_SubWindow
214 PaletteOutput(ColorGUI *gui, int x, int y);
216 void create_objects();
222 class PaletteHue : public BC_ISlider
225 PaletteHue(ColorGUI *gui, int x, int y);
231 class PaletteSat : public BC_FSlider
234 PaletteSat(ColorGUI *gui, int x, int y);
240 class PaletteVal : public BC_FSlider
243 PaletteVal(ColorGUI *gui, int x, int y);
249 class PaletteRed : public BC_FSlider
252 PaletteRed(ColorGUI *gui, int x, int y);
258 class PaletteGrn : public BC_FSlider
261 PaletteGrn(ColorGUI *gui, int x, int y);
267 class PaletteBlu : public BC_FSlider
270 PaletteBlu(ColorGUI *gui, int x, int y);
276 class PaletteAlpha : public BC_FSlider
279 PaletteAlpha(ColorGUI *gui, int x, int y);
285 class PaletteLum : public BC_FSlider
288 PaletteLum(ColorGUI *gui, int x, int y);
294 class PaletteCr : public BC_FSlider
297 PaletteCr(ColorGUI *gui, int x, int y);
303 class PaletteCb : public BC_FSlider
306 PaletteCb(ColorGUI *gui, int x, int y);
312 class PaletteNum : public BC_TumbleTextBox
318 PaletteNum(ColorGUI *gui, int x, int y,
319 float &output, float min, float max);
321 void update_output() { *output = atof(get_text()); }
322 static int calculate_h() { return BC_Tumbler::calculate_h(); }
325 class PaletteRGB : public PaletteNum
328 PaletteRGB(ColorGUI *gui, int x, int y,
329 float &output, float min, float max)
330 : PaletteNum(gui, x, y, output, min, max) {}
334 class PaletteYUV : public PaletteNum
337 PaletteYUV(ColorGUI *gui, int x, int y,
338 float &output, float min, float max)
339 : PaletteNum(gui, x, y, output, min, max) {}
343 class PaletteHSV : public PaletteNum
346 PaletteHSV(ColorGUI *gui, int x, int y,
347 float &output, float min, float max)
348 : PaletteNum(gui, x, y, output, min, max) {}
352 class PaletteAPH : public PaletteNum
355 PaletteAPH(ColorGUI *gui, int x, int y,
356 float &output, float min, float max)
357 : PaletteNum(gui, x, y, output, min, max) {}
361 class PaletteHexButton : public BC_GenericButton
364 PaletteHexButton(ColorGUI *gui, int x, int y);
370 class PaletteHex : public BC_TextBox
373 PaletteHex(ColorGUI *gui, int x, int y, const char *hex);
375 int keypress_event();
380 class PaletteGrabButton : public BC_Button
383 PaletteGrabButton(ColorGUI *gui, int x, int y);
384 ~PaletteGrabButton();
391 class PaletteHistory : public BC_SubWindow
394 PaletteHistory(ColorGUI *gui, int x, int y);
396 void update(int flush=1);
397 int button_press_event();
398 int button_release_event();
399 int cursor_motion_event();
400 int cursor_leave_event();
401 int repeat_event(int64_t duration);
407 class ColorButton : public BC_Button
410 ColorButton(const char *title,
411 int x, int y, int w, int h,
412 int color, int alpha, int ok_cancel);
415 virtual void set_color(int color);
416 virtual int handle_new_color(int color, int alpha);
417 virtual void handle_done_event(int result);
420 void update_gui(int color, int alpha);
421 void update_gui(int color);
425 int color, alpha, ok_cancel;
426 int orig_color, orig_alpha;
429 ColorButtonPicker *color_picker;
430 ColorButtonThread *color_thread;
433 class ColorButtonPicker : public ColorPicker
436 ColorButtonPicker(ColorButton *color_button);
437 ~ColorButtonPicker();
438 void update(int color, int alpha);
439 int handle_new_color(int color, int alpha);
440 void handle_done_event(int result);
442 void update_gui(int color, int alpha);
444 ColorButton *color_button;
447 class ColorButtonThread : public Thread
450 ColorButtonThread(ColorButton *color_button);
451 ~ColorButtonThread();
457 ColorButton *color_button;
458 Condition *update_lock;
462 class ColorBoxButton : public ColorButton
465 ColorBoxButton(const char *title,
466 int x, int y, int w, int h,
467 int color, int alpha, int ok_cancel);
469 void create_objects();
471 virtual int handle_new_color(int color, int alpha);
472 virtual void handle_done_event(int result);
473 void set_color(int color);
476 class ColorCircleButton : public ColorButton
479 ColorCircleButton(const char *title,
480 int x, int y, int w, int h,
481 int color, int alpha, int ok_cancel);
482 ~ColorCircleButton();
483 void create_objects();
485 virtual int handle_new_color(int color, int alpha);
486 virtual void handle_done_event(int result);
487 void set_color(int color);