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
40 class ColorPicker : public BC_DialogThread
43 ColorPicker(int do_alpha = 0, const char *title = 0);
46 void start_window(int output, int alpha, int ok_cancel=0);
47 virtual int handle_new_color(int output, int alpha);
48 void update_gui(int output, int alpha);
50 virtual void create_objects(ColorWindow *gui) {}
52 int orig_color, orig_alpha;
54 int do_alpha, ok_cancel;
58 class ColorWindow : public BC_Window
61 ColorWindow(ColorPicker *thread, int x, int y, int w, int h, const char *title);
64 void create_objects();
67 void update_display();
72 void get_screen_sample();
73 int cursor_motion_event();
74 int button_press_event();
75 int button_release_event();
77 struct { float r, g, b; } rgb;
78 struct { float y, u, v; } yuv;
79 struct { float h, s, v; } hsv;
81 void update_rgb(float r, float g, float b);
82 void update_hsv(float h, float s, float v);
83 void update_yuv(float y, float u, float v);
84 void update_rgb_hex(const char *hex);
90 PaletteWheelValue *wheel_value;
91 PaletteOutput *output;
103 PaletteHSV *hsv_h, *hsv_s, *hsv_v;
104 PaletteRGB *rgb_r, *rgb_g, *rgb_b;
105 PaletteYUV *yuv_y, *yuv_u, *yuv_v;
108 PaletteHexButton *hex_btn;
110 PaletteGrabButton *grab_btn;
111 PaletteHistory *history;
113 VFrame *value_bitmap;
116 int palette_history[PALLETTE_HISTORY_SIZE];
119 void update_history(int color);
120 void update_history();
124 class PaletteWheel : public BC_SubWindow
127 PaletteWheel(ColorWindow *window, int x, int y);
129 int button_press_event();
130 int cursor_motion_event();
131 int button_release_event();
133 void create_objects();
134 int draw(float hue, float saturation);
135 int get_angle(float x1, float y1, float x2, float y2);
136 float torads(float angle);
143 class PaletteWheelValue : public BC_SubWindow
146 PaletteWheelValue(ColorWindow *window, int x, int y);
147 ~PaletteWheelValue();
148 void create_objects();
149 int button_press_event();
150 int cursor_motion_event();
151 int button_release_event();
152 int draw(float hue, float saturation, float value);
159 class PaletteOutput : public BC_SubWindow
162 PaletteOutput(ColorWindow *window, int x, int y);
164 void create_objects();
170 class PaletteHue : public BC_ISlider
173 PaletteHue(ColorWindow *window, int x, int y);
179 class PaletteSat : public BC_FSlider
182 PaletteSat(ColorWindow *window, int x, int y);
188 class PaletteVal : public BC_FSlider
191 PaletteVal(ColorWindow *window, int x, int y);
197 class PaletteRed : public BC_FSlider
200 PaletteRed(ColorWindow *window, int x, int y);
206 class PaletteGrn : public BC_FSlider
209 PaletteGrn(ColorWindow *window, int x, int y);
215 class PaletteBlu : public BC_FSlider
218 PaletteBlu(ColorWindow *window, int x, int y);
224 class PaletteAlpha : public BC_FSlider
227 PaletteAlpha(ColorWindow *window, int x, int y);
233 class PaletteLum : public BC_FSlider
236 PaletteLum(ColorWindow *window, int x, int y);
242 class PaletteCr : public BC_FSlider
245 PaletteCr(ColorWindow *window, int x, int y);
251 class PaletteCb : public BC_FSlider
254 PaletteCb(ColorWindow *window, int x, int y);
260 class PaletteNum : public BC_TumbleTextBox
266 PaletteNum(ColorWindow *window, int x, int y,
267 float &output, float min, float max);
269 void update_output() { *output = atof(get_text()); }
270 static int calculate_h() { return BC_Tumbler::calculate_h(); }
273 class PaletteRGB : public PaletteNum
276 PaletteRGB(ColorWindow *window, int x, int y,
277 float &output, float min, float max)
278 : PaletteNum(window, x, y, output, min, max) {}
282 class PaletteYUV : public PaletteNum
285 PaletteYUV(ColorWindow *window, int x, int y,
286 float &output, float min, float max)
287 : PaletteNum(window, x, y, output, min, max) {}
291 class PaletteHSV : public PaletteNum
294 PaletteHSV(ColorWindow *window, int x, int y,
295 float &output, float min, float max)
296 : PaletteNum(window, x, y, output, min, max) {}
300 class PaletteAPH : public PaletteNum
303 PaletteAPH(ColorWindow *window, int x, int y,
304 float &output, float min, float max)
305 : PaletteNum(window, x, y, output, min, max) {}
309 class PaletteHexButton : public BC_GenericButton
312 PaletteHexButton(ColorWindow *window, int x, int y);
318 class PaletteHex : public BC_TextBox
321 PaletteHex(ColorWindow *window, int x, int y, const char *hex);
323 int keypress_event();
328 class PaletteGrabButton : public BC_Button
331 PaletteGrabButton(ColorWindow *window, int x, int y);
332 ~PaletteGrabButton();
339 class PaletteHistory : public BC_SubWindow
342 PaletteHistory(ColorWindow *window, int x, int y);
344 void update(int flush=1);
345 int button_press_event();
346 int button_release_event();
347 int cursor_motion_event();
348 int cursor_leave_event();
349 int repeat_event(int64_t duration);
355 class ColorButton : public BC_Button
358 ColorButton(const char *title,
359 int x, int y, int w, int h,
360 int color, int alpha, int ok_cancel);
363 virtual void set_color(int color);
364 virtual int handle_new_color(int color, int alpha);
365 virtual void handle_done_event(int result);
368 void update_gui(int color, int alpha);
369 void update_gui(int color);
373 int color, alpha, ok_cancel;
374 int orig_color, orig_alpha;
377 ColorButtonPicker *color_picker;
378 ColorButtonThread *color_thread;
381 class ColorButtonPicker : public ColorPicker
384 ColorButtonPicker(ColorButton *color_button);
385 ~ColorButtonPicker();
386 void update(int color, int alpha);
387 int handle_new_color(int color, int alpha);
388 void handle_done_event(int result);
390 void update_gui(int color, int alpha);
392 ColorButton *color_button;
395 class ColorButtonThread : public Thread
398 ColorButtonThread(ColorButton *color_button);
399 ~ColorButtonThread();
405 ColorButton *color_button;
406 Condition *update_lock;
410 class ColorBoxButton : public ColorButton
413 ColorBoxButton(const char *title,
414 int x, int y, int w, int h,
415 int color, int alpha, int ok_cancel);
417 void create_objects();
419 virtual int handle_new_color(int color, int alpha);
420 virtual void handle_done_event(int result);
421 void set_color(int color);
424 class ColorCircleButton : public ColorButton
427 ColorCircleButton(const char *title,
428 int x, int y, int w, int h,
429 int color, int alpha, int ok_cancel);
430 ~ColorCircleButton();
431 void create_objects();
433 virtual int handle_new_color(int color, int alpha);
434 virtual void handle_done_event(int result);
435 void set_color(int color);