85fa706b2dff8cbddc4821cb03e683deb31a9050
[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 #define COLOR_PICKER_W xS(540)
39 #define COLOR_PICKER_H yS(330)
40
41
42 class ColorPicker : public BC_DialogThread
43 {
44 public:
45         ColorPicker(int do_alpha = 0, const char *title = 0);
46         ~ColorPicker();
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);
50         BC_Window* new_gui();
51
52         int color, alpha;
53         int ok_cancel, do_alpha;
54         const char *title;
55 };
56
57 class ColorGUI
58 {
59 public:
60         ColorGUI(BC_WindowBase *window);
61         ~ColorGUI();
62
63         void add_tool(BC_WindowBase *sub_wdw);
64         void start_selection(int color, int alpha, int ok_cancel);
65         void create_objects();
66         void change_values();
67         int close_gui();
68         void update_display();
69         void update_rgb();
70         void update_hsv();
71         void update_yuv();
72         int handle_gui();
73         void get_screen_sample();
74         int cursor_motion_gui();
75         int button_press_gui();
76         int button_release_gui();
77
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) {}
81
82         static int calculate_w() { return COLOR_PICKER_W; }
83         static int calculate_h() { return COLOR_PICKER_H; }
84
85
86         struct { float r, g, b; } rgb;
87         struct { float y, u, v; } yuv;
88         struct { float h, s, v; } hsv;
89         float aph;
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);
94         int rgb888();
95         int alpha8();
96
97         BC_WindowBase *window;
98         PaletteWheel *wheel;
99         PaletteWheelValue *wheel_value;
100         PaletteOutput *poutput;
101         PaletteHue *hue;
102         PaletteSat *sat;
103         PaletteVal *val;
104         PaletteRed *red;
105         PaletteGrn *grn;
106         PaletteBlu *blu;
107         PaletteLum *lum;
108         PaletteCr  *c_r;
109         PaletteCb  *c_b;
110         PaletteAlpha *palpha;
111
112         PaletteHSV *hsv_h, *hsv_s, *hsv_v;
113         PaletteRGB *rgb_r, *rgb_g, *rgb_b;
114         PaletteYUV *yuv_y, *yuv_u, *yuv_v;
115         PaletteAPH *aph_a;
116
117         PaletteHexButton *hex_btn;
118         PaletteHex *hex_box;
119         PaletteGrabButton *grab_btn;
120         PaletteHistory *history;
121
122         VFrame *value_bitmap;
123         int button_grabbed;
124
125         int orig_color, orig_alpha;
126         int color, alpha;
127         int do_alpha, ok_cancel;
128         const char *title;
129
130         int palette_history[PALLETTE_HISTORY_SIZE];
131         void load_history();
132         void save_history();
133         void update_history(int color);
134         void update_history();
135 };
136
137 class ColorWindow : public BC_Window, public ColorGUI
138 {
139 public:
140         ColorWindow(ColorPicker *thread, int x, int y, int w, int h, const char *title);
141         ~ColorWindow();
142
143         void update_gui(int color, int alpha);
144         int handle_new_color(int color, int alpha);
145
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(); }
150
151         ColorPicker *thread;
152 };
153
154
155 class PaletteWheel : public BC_SubWindow
156 {
157 public:
158         PaletteWheel(ColorGUI *gui, int x, int y);
159         ~PaletteWheel();
160         int button_press_event();
161         int cursor_motion_event();
162         int button_release_event();
163
164         void create_objects();
165         int draw(float hue, float saturation);
166         int get_angle(float x1, float y1, float x2, float y2);
167         float torads(float angle);
168         ColorGUI *gui;
169         float oldhue;
170         float oldsaturation;
171         int button_down;
172 };
173
174 class PaletteWheelValue : public BC_SubWindow
175 {
176 public:
177         PaletteWheelValue(ColorGUI *gui, int x, int y);
178         ~PaletteWheelValue();
179         void create_objects();
180         int button_press_event();
181         int cursor_motion_event();
182         int button_release_event();
183         int draw(float hue, float saturation, float value);
184         ColorGUI *gui;
185         int button_down;
186 // Gradient
187         VFrame *frame;
188 };
189
190 class PaletteOutput : public BC_SubWindow
191 {
192 public:
193         PaletteOutput(ColorGUI *gui, int x, int y);
194         ~PaletteOutput();
195         void create_objects();
196         int handle_event();
197         int draw();
198         ColorGUI *gui;
199 };
200
201 class PaletteHue : public BC_ISlider
202 {
203 public:
204         PaletteHue(ColorGUI *gui, int x, int y);
205         ~PaletteHue();
206         int handle_event();
207         ColorGUI *gui;
208 };
209
210 class PaletteSat : public BC_FSlider
211 {
212 public:
213         PaletteSat(ColorGUI *gui, int x, int y);
214         ~PaletteSat();
215         int handle_event();
216         ColorGUI *gui;
217 };
218
219 class PaletteVal : public BC_FSlider
220 {
221 public:
222         PaletteVal(ColorGUI *gui, int x, int y);
223         ~PaletteVal();
224         int handle_event();
225         ColorGUI *gui;
226 };
227
228 class PaletteRed : public BC_FSlider
229 {
230 public:
231         PaletteRed(ColorGUI *gui, int x, int y);
232         ~PaletteRed();
233         int handle_event();
234         ColorGUI *gui;
235 };
236
237 class PaletteGrn : public BC_FSlider
238 {
239 public:
240         PaletteGrn(ColorGUI *gui, int x, int y);
241         ~PaletteGrn();
242         int handle_event();
243         ColorGUI *gui;
244 };
245
246 class PaletteBlu : public BC_FSlider
247 {
248 public:
249         PaletteBlu(ColorGUI *gui, int x, int y);
250         ~PaletteBlu();
251         int handle_event();
252         ColorGUI *gui;
253 };
254
255 class PaletteAlpha : public BC_FSlider
256 {
257 public:
258         PaletteAlpha(ColorGUI *gui, int x, int y);
259         ~PaletteAlpha();
260         int handle_event();
261         ColorGUI *gui;
262 };
263
264 class PaletteLum : public BC_FSlider
265 {
266 public:
267         PaletteLum(ColorGUI *gui, int x, int y);
268         ~PaletteLum();
269         int handle_event();
270         ColorGUI *gui;
271 };
272
273 class PaletteCr : public BC_FSlider
274 {
275 public:
276         PaletteCr(ColorGUI *gui, int x, int y);
277         ~PaletteCr();
278         int handle_event();
279         ColorGUI *gui;
280 };
281
282 class PaletteCb : public BC_FSlider
283 {
284 public:
285         PaletteCb(ColorGUI *gui, int x, int y);
286         ~PaletteCb();
287         int handle_event();
288         ColorGUI *gui;
289 };
290
291 class PaletteNum : public BC_TumbleTextBox
292 {
293 public:
294         ColorGUI *gui;
295         float *output;
296
297         PaletteNum(ColorGUI *gui, int x, int y,
298                         float &output, float min, float max);
299         ~PaletteNum();
300         void update_output() { *output = atof(get_text()); }
301         static int calculate_h() { return BC_Tumbler::calculate_h(); }
302 };
303
304 class PaletteRGB : public PaletteNum
305 {
306 public:
307         PaletteRGB(ColorGUI *gui, int x, int y,
308                         float &output, float min, float max)
309          : PaletteNum(gui, x, y, output, min, max) {}
310         int handle_event();
311 };
312
313 class PaletteYUV : public PaletteNum
314 {
315 public:
316         PaletteYUV(ColorGUI *gui, int x, int y,
317                         float &output, float min, float max)
318          : PaletteNum(gui, x, y, output, min, max) {}
319         int handle_event();
320 };
321
322 class PaletteHSV : public PaletteNum
323 {
324 public:
325         PaletteHSV(ColorGUI *gui, int x, int y,
326                         float &output, float min, float max)
327          : PaletteNum(gui, x, y, output, min, max) {}
328         int handle_event();
329 };
330
331 class PaletteAPH : public PaletteNum
332 {
333 public:
334         PaletteAPH(ColorGUI *gui, int x, int y,
335                         float &output, float min, float max)
336          : PaletteNum(gui, x, y, output, min, max) {}
337         int handle_event();
338 };
339
340 class PaletteHexButton : public BC_GenericButton
341 {
342 public:
343         PaletteHexButton(ColorGUI *gui, int x, int y);
344         ~PaletteHexButton();
345         int handle_event();
346         ColorGUI *gui;
347 };
348
349 class PaletteHex : public BC_TextBox
350 {
351 public:
352         PaletteHex(ColorGUI *gui, int x, int y, const char *hex);
353         ~PaletteHex();
354         int keypress_event();
355         void update();
356         ColorGUI *gui;
357 };
358
359 class PaletteGrabButton : public BC_Button
360 {
361 public:
362         PaletteGrabButton(ColorGUI *gui, int x, int y);
363         ~PaletteGrabButton();
364         int handle_event();
365
366         ColorGUI *gui;
367         VFrame *vframes[3];
368 };
369
370 class PaletteHistory : public BC_SubWindow
371 {
372 public:
373         PaletteHistory(ColorGUI *gui, int x, int y);
374         ~PaletteHistory();
375         void update(int flush=1);
376         int button_press_event();
377         int button_release_event();
378         int cursor_motion_event();
379         int cursor_leave_event();
380         int repeat_event(int64_t duration);
381
382         ColorGUI *gui;
383         int button_down;
384 };
385
386 class ColorButton : public BC_Button
387 {
388 public:
389         ColorButton(const char *title,
390                 int x, int y, int w, int h,
391                 int color, int alpha, int ok_cancel);
392         ~ColorButton();
393
394         virtual void set_color(int color);
395         virtual int handle_new_color(int color, int alpha);
396         virtual void handle_done_event(int result);
397
398         void close_picker();
399         void update_gui(int color, int alpha);
400         void update_gui(int color);
401         int handle_event();
402
403         const char *title;
404         int color, alpha, ok_cancel;
405         int orig_color, orig_alpha;
406
407         VFrame *vframes[3];
408         ColorButtonPicker *color_picker;
409         ColorButtonThread *color_thread;
410 };
411
412 class ColorButtonPicker : public ColorPicker
413 {
414 public:
415         ColorButtonPicker(ColorButton *color_button);
416         ~ColorButtonPicker();
417         void update(int color, int alpha);
418         int handle_new_color(int color, int alpha);
419         void handle_done_event(int result);
420         void update_gui();
421         void update_gui(int color, int alpha);
422
423         ColorButton *color_button;
424 };
425
426 class ColorButtonThread : public Thread
427 {
428 public:
429         ColorButtonThread(ColorButton *color_button);
430         ~ColorButtonThread();
431
432         void start();
433         void stop();
434         void run();
435
436         ColorButton *color_button;
437         Condition *update_lock;
438         int done;
439 };
440
441 class ColorBoxButton : public ColorButton
442 {
443 public:
444         ColorBoxButton(const char *title,
445                 int x, int y, int w, int h,
446                 int color, int alpha, int ok_cancel);
447         ~ColorBoxButton();
448         void create_objects();
449
450         virtual int handle_new_color(int color, int alpha);
451         virtual void handle_done_event(int result);
452         void set_color(int color);
453 };
454
455 class ColorCircleButton : public ColorButton
456 {
457 public:
458         ColorCircleButton(const char *title,
459                 int x, int y, int w, int h,
460                 int color, int alpha, int ok_cancel);
461         ~ColorCircleButton();
462         void create_objects();
463
464         virtual int handle_new_color(int color, int alpha);
465         virtual void handle_done_event(int result);
466         void set_color(int color);
467 };
468
469 #endif