a5d203d29fc47fa31506cb9030e30a6c9eb0b1c4
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / colorpicker.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #ifndef COLORPICKER_H
23 #define COLORPICKER_H
24
25 #include "bcbutton.h"
26 #include "bcdialog.h"
27 #include "bctextbox.h"
28 #include "bcsubwindow.h"
29 #include "clip.h"
30 #include "colorpicker.inc"
31 #include "condition.inc"
32 #include "guicast.h"
33 #include "mutex.inc"
34 #include "thread.h"
35 #include "vframe.inc"
36
37 #define PALLETTE_HISTORY_SIZE 16
38
39
40 class ColorPicker : public BC_DialogThread
41 {
42 public:
43         ColorPicker(int do_alpha = 0, const char *title = 0);
44         ~ColorPicker();
45
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);
49         BC_Window* new_gui();
50         virtual void create_objects(ColorWindow *gui) {}
51
52         int orig_color, orig_alpha;
53         int output, alpha;
54         int do_alpha, ok_cancel;
55         const char *title;
56 };
57
58 class ColorWindow : public BC_Window
59 {
60 public:
61         ColorWindow(ColorPicker *thread, int x, int y, int w, int h, const char *title);
62         ~ColorWindow();
63
64         void create_objects();
65         void change_values();
66         int close_event();
67         void update_display();
68         void update_rgb();
69         void update_hsv();
70         void update_yuv();
71         int handle_event();
72         void get_screen_sample();
73         int cursor_motion_event();
74         int button_press_event();
75         int button_release_event();
76
77         struct { float r, g, b; } rgb;
78         struct { float y, u, v; } yuv;
79         struct { float h, s, v; } hsv;
80         float aph;
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);
85         int rgb888();
86
87         ColorPicker *thread;
88         PaletteWheel *wheel;
89         PaletteWheelValue *wheel_value;
90         PaletteOutput *output;
91         PaletteHue *hue;
92         PaletteSat *sat;
93         PaletteVal *val;
94         PaletteRed *red;
95         PaletteGrn *grn;
96         PaletteBlu *blu;
97         PaletteLum *lum;
98         PaletteCr  *c_r;
99         PaletteCb  *c_b;
100         PaletteAlpha *alpha;
101
102         PaletteHSV *hsv_h, *hsv_s, *hsv_v;
103         PaletteRGB *rgb_r, *rgb_g, *rgb_b;
104         PaletteYUV *yuv_y, *yuv_u, *yuv_v;
105         PaletteAPH *aph_a;
106
107         PaletteHexButton *hex_btn;
108         PaletteHex *hex_box;
109         PaletteGrabButton *grab_btn;
110         PaletteHistory *history;
111
112         VFrame *value_bitmap;
113         int button_grabbed;
114
115         int palette_history[PALLETTE_HISTORY_SIZE];
116         void load_history();
117         void save_history();
118         void update_history(int color);
119         void update_history();
120 };
121
122
123 class PaletteWheel : public BC_SubWindow
124 {
125 public:
126         PaletteWheel(ColorWindow *window, int x, int y);
127         ~PaletteWheel();
128         int button_press_event();
129         int cursor_motion_event();
130         int button_release_event();
131
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);
136         ColorWindow *window;
137         float oldhue;
138         float oldsaturation;
139         int button_down;
140 };
141
142 class PaletteWheelValue : public BC_SubWindow
143 {
144 public:
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);
152         ColorWindow *window;
153         int button_down;
154 // Gradient
155         VFrame *frame;
156 };
157
158 class PaletteOutput : public BC_SubWindow
159 {
160 public:
161         PaletteOutput(ColorWindow *window, int x, int y);
162         ~PaletteOutput();
163         void create_objects();
164         int handle_event();
165         int draw();
166         ColorWindow *window;
167 };
168
169 class PaletteHue : public BC_ISlider
170 {
171 public:
172         PaletteHue(ColorWindow *window, int x, int y);
173         ~PaletteHue();
174         int handle_event();
175         ColorWindow *window;
176 };
177
178 class PaletteSat : public BC_FSlider
179 {
180 public:
181         PaletteSat(ColorWindow *window, int x, int y);
182         ~PaletteSat();
183         int handle_event();
184         ColorWindow *window;
185 };
186
187 class PaletteVal : public BC_FSlider
188 {
189 public:
190         PaletteVal(ColorWindow *window, int x, int y);
191         ~PaletteVal();
192         int handle_event();
193         ColorWindow *window;
194 };
195
196 class PaletteRed : public BC_FSlider
197 {
198 public:
199         PaletteRed(ColorWindow *window, int x, int y);
200         ~PaletteRed();
201         int handle_event();
202         ColorWindow *window;
203 };
204
205 class PaletteGrn : public BC_FSlider
206 {
207 public:
208         PaletteGrn(ColorWindow *window, int x, int y);
209         ~PaletteGrn();
210         int handle_event();
211         ColorWindow *window;
212 };
213
214 class PaletteBlu : public BC_FSlider
215 {
216 public:
217         PaletteBlu(ColorWindow *window, int x, int y);
218         ~PaletteBlu();
219         int handle_event();
220         ColorWindow *window;
221 };
222
223 class PaletteAlpha : public BC_FSlider
224 {
225 public:
226         PaletteAlpha(ColorWindow *window, int x, int y);
227         ~PaletteAlpha();
228         int handle_event();
229         ColorWindow *window;
230 };
231
232 class PaletteLum : public BC_FSlider
233 {
234 public:
235         PaletteLum(ColorWindow *window, int x, int y);
236         ~PaletteLum();
237         int handle_event();
238         ColorWindow *window;
239 };
240
241 class PaletteCr : public BC_FSlider
242 {
243 public:
244         PaletteCr(ColorWindow *window, int x, int y);
245         ~PaletteCr();
246         int handle_event();
247         ColorWindow *window;
248 };
249
250 class PaletteCb : public BC_FSlider
251 {
252 public:
253         PaletteCb(ColorWindow *window, int x, int y);
254         ~PaletteCb();
255         int handle_event();
256         ColorWindow *window;
257 };
258
259 class PaletteNum : public BC_TumbleTextBox
260 {
261 public:
262         ColorWindow *window;
263         float *output;
264
265         PaletteNum(ColorWindow *window, int x, int y,
266                         float &output, float min, float max);
267         ~PaletteNum();
268         void update_output() { *output = atof(get_text()); }
269         static int calculate_h() { return BC_Tumbler::calculate_h(); }
270 };
271
272 class PaletteRGB : public PaletteNum
273 {
274 public:
275         PaletteRGB(ColorWindow *window, int x, int y,
276                         float &output, float min, float max)
277          : PaletteNum(window, x, y, output, min, max) {}
278         int handle_event();
279 };
280
281 class PaletteYUV : public PaletteNum
282 {
283 public:
284         PaletteYUV(ColorWindow *window, int x, int y,
285                         float &output, float min, float max)
286          : PaletteNum(window, x, y, output, min, max) {}
287         int handle_event();
288 };
289
290 class PaletteHSV : public PaletteNum
291 {
292 public:
293         PaletteHSV(ColorWindow *window, int x, int y,
294                         float &output, float min, float max)
295          : PaletteNum(window, x, y, output, min, max) {}
296         int handle_event();
297 };
298
299 class PaletteAPH : public PaletteNum
300 {
301 public:
302         PaletteAPH(ColorWindow *window, int x, int y,
303                         float &output, float min, float max)
304          : PaletteNum(window, x, y, output, min, max) {}
305         int handle_event();
306 };
307
308 class PaletteHexButton : public BC_GenericButton
309 {
310 public:
311         PaletteHexButton(ColorWindow *window, int x, int y);
312         ~PaletteHexButton();
313         int handle_event();
314         ColorWindow *window;
315 };
316
317 class PaletteHex : public BC_TextBox
318 {
319 public:
320         PaletteHex(ColorWindow *window, int x, int y, const char *hex);
321         ~PaletteHex();
322         int keypress_event();
323         void update();
324         ColorWindow *window;
325 };
326
327 class PaletteGrabButton : public BC_Button
328 {
329 public:
330         PaletteGrabButton(ColorWindow *window, int x, int y);
331         ~PaletteGrabButton();
332         int handle_event();
333
334         ColorWindow *window;
335         VFrame *vframes[3];
336 };
337
338 class PaletteHistory : public BC_SubWindow
339 {
340 public:
341         PaletteHistory(ColorWindow *window, int x, int y);
342         ~PaletteHistory();
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);
349
350         ColorWindow *window;
351         int button_down;
352 };
353
354 class ColorButton : public BC_Button
355 {
356 public:
357         ColorButton(const char *title,
358                 int x, int y, int w, int h,
359                 int color, int alpha, int ok_cancel);
360         ~ColorButton();
361
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);
365
366         void close_picker();
367         void update_gui(int color);
368         int handle_event();
369
370         const char *title;
371         int color, alpha, ok_cancel;
372         int orig_color, orig_alpha;
373
374         VFrame *vframes[3];
375         ColorButtonPicker *color_picker;
376         ColorButtonThread *color_thread;
377 };
378
379 class ColorButtonPicker : public ColorPicker
380 {
381 public:
382         ColorButtonPicker(ColorButton *color_button);
383         ~ColorButtonPicker();
384         int handle_new_color(int color, int alpha);
385         void handle_done_event(int result);
386         void update_gui();
387
388         ColorButton *color_button;
389 };
390
391 class ColorButtonThread : public Thread
392 {
393 public:
394         ColorButtonThread(ColorButton *color_button);
395         ~ColorButtonThread();
396
397         void start();
398         void stop();
399         void run();
400
401         ColorButton *color_button;
402         Condition *update_lock;
403         int done;
404 };
405
406 class ColorBoxButton : public ColorButton
407 {
408 public:
409         ColorBoxButton(const char *title,
410                 int x, int y, int w, int h,
411                 int color, int alpha, int ok_cancel);
412         ~ColorBoxButton();
413         void create_objects();
414
415         virtual int handle_new_color(int color, int alpha);
416         virtual void handle_done_event(int result);
417         void set_color(int color);
418 };
419
420 class ColorCircleButton : public ColorButton
421 {
422 public:
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();
428
429         virtual int handle_new_color(int color, int alpha);
430         virtual void handle_done_event(int result);
431         void set_color(int color);
432 };
433
434 #endif