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);
89 PaletteWheelValue *wheel_value;
90 PaletteOutput *output;
102 PaletteHSV *hsv_h, *hsv_s, *hsv_v;
103 PaletteRGB *rgb_r, *rgb_g, *rgb_b;
104 PaletteYUV *yuv_y, *yuv_u, *yuv_v;
107 PaletteHexButton *hex_btn;
109 PaletteGrabButton *grab_btn;
110 PaletteHistory *history;
112 VFrame *value_bitmap;
115 int palette_history[PALLETTE_HISTORY_SIZE];
118 void update_history(int color);
119 void update_history();
123 class PaletteWheel : public BC_SubWindow
126 PaletteWheel(ColorWindow *window, int x, int y);
128 int button_press_event();
129 int cursor_motion_event();
130 int button_release_event();
132 void create_objects();
133 int draw(float hue, float saturation);
134 int get_angle(float x1, float y1, float x2, float y2);
135 float torads(float angle);
142 class PaletteWheelValue : public BC_SubWindow
145 PaletteWheelValue(ColorWindow *window, int x, int y);
146 ~PaletteWheelValue();
147 void create_objects();
148 int button_press_event();
149 int cursor_motion_event();
150 int button_release_event();
151 int draw(float hue, float saturation, float value);
158 class PaletteOutput : public BC_SubWindow
161 PaletteOutput(ColorWindow *window, int x, int y);
163 void create_objects();
169 class PaletteHue : public BC_ISlider
172 PaletteHue(ColorWindow *window, int x, int y);
178 class PaletteSat : public BC_FSlider
181 PaletteSat(ColorWindow *window, int x, int y);
187 class PaletteVal : public BC_FSlider
190 PaletteVal(ColorWindow *window, int x, int y);
196 class PaletteRed : public BC_FSlider
199 PaletteRed(ColorWindow *window, int x, int y);
205 class PaletteGrn : public BC_FSlider
208 PaletteGrn(ColorWindow *window, int x, int y);
214 class PaletteBlu : public BC_FSlider
217 PaletteBlu(ColorWindow *window, int x, int y);
223 class PaletteAlpha : public BC_FSlider
226 PaletteAlpha(ColorWindow *window, int x, int y);
232 class PaletteLum : public BC_FSlider
235 PaletteLum(ColorWindow *window, int x, int y);
241 class PaletteCr : public BC_FSlider
244 PaletteCr(ColorWindow *window, int x, int y);
250 class PaletteCb : public BC_FSlider
253 PaletteCb(ColorWindow *window, int x, int y);
259 class PaletteNum : public BC_TumbleTextBox
265 PaletteNum(ColorWindow *window, int x, int y,
266 float &output, float min, float max);
268 void update_output() { *output = atof(get_text()); }
269 static int calculate_h() { return BC_Tumbler::calculate_h(); }
272 class PaletteRGB : public PaletteNum
275 PaletteRGB(ColorWindow *window, int x, int y,
276 float &output, float min, float max)
277 : PaletteNum(window, x, y, output, min, max) {}
281 class PaletteYUV : public PaletteNum
284 PaletteYUV(ColorWindow *window, int x, int y,
285 float &output, float min, float max)
286 : PaletteNum(window, x, y, output, min, max) {}
290 class PaletteHSV : public PaletteNum
293 PaletteHSV(ColorWindow *window, int x, int y,
294 float &output, float min, float max)
295 : PaletteNum(window, x, y, output, min, max) {}
299 class PaletteAPH : public PaletteNum
302 PaletteAPH(ColorWindow *window, int x, int y,
303 float &output, float min, float max)
304 : PaletteNum(window, x, y, output, min, max) {}
308 class PaletteHexButton : public BC_GenericButton
311 PaletteHexButton(ColorWindow *window, int x, int y);
317 class PaletteHex : public BC_TextBox
320 PaletteHex(ColorWindow *window, int x, int y, const char *hex);
322 int keypress_event();
327 class PaletteGrabButton : public BC_Button
330 PaletteGrabButton(ColorWindow *window, int x, int y);
331 ~PaletteGrabButton();
338 class PaletteHistory : public BC_SubWindow
341 PaletteHistory(ColorWindow *window, int x, int y);
343 void update(int flush=1);
344 int button_press_event();
345 int button_release_event();
346 int cursor_motion_event();
347 int cursor_leave_event();
348 int repeat_event(int64_t duration);
354 class ColorButton : public BC_Button
357 ColorButton(const char *title,
358 int x, int y, int w, int h,
359 int color, int alpha, int ok_cancel);
362 virtual void set_color(int color);
363 virtual int handle_new_color(int color, int alpha);
364 virtual void handle_done_event(int result);
367 void update_gui(int color);
371 int color, alpha, ok_cancel;
372 int orig_color, orig_alpha;
375 ColorButtonPicker *color_picker;
376 ColorButtonThread *color_thread;
379 class ColorButtonPicker : public ColorPicker
382 ColorButtonPicker(ColorButton *color_button);
383 ~ColorButtonPicker();
384 int handle_new_color(int color, int alpha);
385 void handle_done_event(int result);
388 ColorButton *color_button;
391 class ColorButtonThread : public Thread
394 ColorButtonThread(ColorButton *color_button);
395 ~ColorButtonThread();
401 ColorButton *color_button;
402 Condition *update_lock;
406 class ColorBoxButton : public ColorButton
409 ColorBoxButton(const char *title,
410 int x, int y, int w, int h,
411 int color, int alpha, int ok_cancel);
413 void create_objects();
415 virtual int handle_new_color(int color, int alpha);
416 virtual void handle_done_event(int result);
417 void set_color(int color);
420 class ColorCircleButton : public ColorButton
423 ColorCircleButton(const char *title,
424 int x, int y, int w, int h,
425 int color, int alpha, int ok_cancel);
426 ~ColorCircleButton();
427 void create_objects();
429 virtual int handle_new_color(int color, int alpha);
430 virtual void handle_done_event(int result);
431 void set_color(int color);