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