a63069324050b12ecac6d3b6f6488f2edb86a09f
[goodguy/history.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 "condition.inc"
31 #include "guicast.h"
32 #include "mutex.inc"
33 #include "thread.h"
34 #include "vframe.inc"
35
36 #define PALLETTE_HISTORY_SIZE 16
37
38 class ColorWindow;
39 class PaletteWheel;
40 class PaletteWheelValue;
41 class PaletteOutput;
42 class PaletteHue;
43 class PaletteSat;
44 class PaletteVal;
45 class PaletteRed;
46 class PaletteGrn;
47 class PaletteBlu;
48 class PaletteLum;
49 class PaletteCr;
50 class PaletteCb;
51 class PaletteAlpha;
52 class PaletteHSV;
53 class PaletteRGB;
54 class PaletteYUV;
55 class PaletteAPH;
56 class PaletteHexButton;
57 class PaletteHex;
58 class PaletteGrabButton;
59 class PaletteHistory;
60
61 class ColorThread : public BC_DialogThread
62 {
63 public:
64         ColorThread(int do_alpha = 0, const char *title = 0);
65         ~ColorThread();
66
67         void start_window(int output, int alpha, int do_okcancel=0);
68         virtual int handle_new_color(int output, int alpha);
69         void update_gui(int output, int alpha);
70         BC_Window* new_gui();
71
72         int output, alpha;
73         int do_alpha, do_okcancel;
74         const char *title;
75 };
76
77 class ColorWindow : public BC_Window
78 {
79 public:
80         ColorWindow(ColorThread *thread, int x, int y, int w, int h, const char *title);
81         ~ColorWindow();
82
83         void create_objects();
84         void change_values();
85         int close_event();
86         void update_display();
87         void update_rgb();
88         void update_hsv();
89         void update_yuv();
90         int handle_event();
91         int button_press_event();
92         int button_release_event();
93
94         struct { float r, g, b; } rgb;
95         struct { float y, u, v; } yuv;
96         struct { float h, s, v; } hsv;
97         float aph;
98         void update_rgb(float r, float g, float b);
99         void update_hsv(float h, float s, float v);
100         void update_yuv(float y, float u, float v);
101         int rgb888();
102
103         ColorThread *thread;
104         PaletteWheel *wheel;
105         PaletteWheelValue *wheel_value;
106         PaletteOutput *output;
107         PaletteHue *hue;
108         PaletteSat *sat;
109         PaletteVal *val;
110         PaletteRed *red;
111         PaletteGrn *grn;
112         PaletteBlu *blu;
113         PaletteLum *lum;
114         PaletteCr  *c_r;
115         PaletteCb  *c_b;
116         PaletteAlpha *alpha;
117
118         PaletteHSV *hsv_h, *hsv_s, *hsv_v;
119         PaletteRGB *rgb_r, *rgb_g, *rgb_b;
120         PaletteYUV *yuv_y, *yuv_u, *yuv_v;
121         PaletteAPH *aph_a;
122
123         PaletteHexButton *hex_btn;
124         PaletteHex *hex_box;
125         PaletteGrabButton *grab_btn;
126         PaletteHistory *history;
127
128         VFrame *value_bitmap;
129         int button_grabbed;
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
139 class PaletteWheel : public BC_SubWindow
140 {
141 public:
142         PaletteWheel(ColorWindow *window, int x, int y);
143         ~PaletteWheel();
144         int button_press_event();
145         int cursor_motion_event();
146         int button_release_event();
147
148         void create_objects();
149         int draw(float hue, float saturation);
150         int get_angle(float x1, float y1, float x2, float y2);
151         float torads(float angle);
152         ColorWindow *window;
153         float oldhue;
154         float oldsaturation;
155         int button_down;
156 };
157
158 class PaletteWheelValue : public BC_SubWindow
159 {
160 public:
161         PaletteWheelValue(ColorWindow *window, int x, int y);
162         ~PaletteWheelValue();
163         void create_objects();
164         int button_press_event();
165         int cursor_motion_event();
166         int button_release_event();
167         int draw(float hue, float saturation, float value);
168         ColorWindow *window;
169         int button_down;
170 // Gradient
171         VFrame *frame;
172 };
173
174 class PaletteOutput : public BC_SubWindow
175 {
176 public:
177         PaletteOutput(ColorWindow *window, int x, int y);
178         ~PaletteOutput();
179         void create_objects();
180         int handle_event();
181         int draw();
182         ColorWindow *window;
183 };
184
185 class PaletteHue : public BC_ISlider
186 {
187 public:
188         PaletteHue(ColorWindow *window, int x, int y);
189         ~PaletteHue();
190         int handle_event();
191         ColorWindow *window;
192 };
193
194 class PaletteSat : public BC_FSlider
195 {
196 public:
197         PaletteSat(ColorWindow *window, int x, int y);
198         ~PaletteSat();
199         int handle_event();
200         ColorWindow *window;
201 };
202
203 class PaletteVal : public BC_FSlider
204 {
205 public:
206         PaletteVal(ColorWindow *window, int x, int y);
207         ~PaletteVal();
208         int handle_event();
209         ColorWindow *window;
210 };
211
212 class PaletteRed : public BC_FSlider
213 {
214 public:
215         PaletteRed(ColorWindow *window, int x, int y);
216         ~PaletteRed();
217         int handle_event();
218         ColorWindow *window;
219 };
220
221 class PaletteGrn : public BC_FSlider
222 {
223 public:
224         PaletteGrn(ColorWindow *window, int x, int y);
225         ~PaletteGrn();
226         int handle_event();
227         ColorWindow *window;
228 };
229
230 class PaletteBlu : public BC_FSlider
231 {
232 public:
233         PaletteBlu(ColorWindow *window, int x, int y);
234         ~PaletteBlu();
235         int handle_event();
236         ColorWindow *window;
237 };
238
239 class PaletteAlpha : public BC_FSlider
240 {
241 public:
242         PaletteAlpha(ColorWindow *window, int x, int y);
243         ~PaletteAlpha();
244         int handle_event();
245         ColorWindow *window;
246 };
247
248 class PaletteLum : public BC_FSlider
249 {
250 public:
251         PaletteLum(ColorWindow *window, int x, int y);
252         ~PaletteLum();
253         int handle_event();
254         ColorWindow *window;
255 };
256
257 class PaletteCr : public BC_FSlider
258 {
259 public:
260         PaletteCr(ColorWindow *window, int x, int y);
261         ~PaletteCr();
262         int handle_event();
263         ColorWindow *window;
264 };
265
266 class PaletteCb : public BC_FSlider
267 {
268 public:
269         PaletteCb(ColorWindow *window, int x, int y);
270         ~PaletteCb();
271         int handle_event();
272         ColorWindow *window;
273 };
274
275 class PaletteNum : public BC_TumbleTextBox
276 {
277 public:
278         ColorWindow *window;
279         float *output;
280
281         PaletteNum(ColorWindow *window, int x, int y,
282                         float &output, float min, float max);
283         ~PaletteNum();
284         void update_output() { *output = atof(get_text()); }
285         static int calculate_h() { return BC_Tumbler::calculate_h(); }
286 };
287
288 class PaletteRGB : public PaletteNum
289 {
290 public:
291         PaletteRGB(ColorWindow *window, int x, int y,
292                         float &output, float min, float max)
293          : PaletteNum(window, x, y, output, min, max) {}
294         int handle_event();
295 };
296
297 class PaletteYUV : public PaletteNum
298 {
299 public:
300         PaletteYUV(ColorWindow *window, int x, int y,
301                         float &output, float min, float max)
302          : PaletteNum(window, x, y, output, min, max) {}
303         int handle_event();
304 };
305
306 class PaletteHSV : public PaletteNum
307 {
308 public:
309         PaletteHSV(ColorWindow *window, int x, int y,
310                         float &output, float min, float max)
311          : PaletteNum(window, x, y, output, min, max) {}
312         int handle_event();
313 };
314
315 class PaletteAPH : public PaletteNum
316 {
317 public:
318         PaletteAPH(ColorWindow *window, int x, int y,
319                         float &output, float min, float max)
320          : PaletteNum(window, x, y, output, min, max) {}
321         int handle_event();
322 };
323
324 class PaletteHexButton : public BC_GenericButton
325 {
326 public:
327         PaletteHexButton(ColorWindow *window, int x, int y);
328         ~PaletteHexButton();
329         int handle_event();
330         ColorWindow *window;
331 };
332
333 class PaletteHex : public BC_TextBox
334 {
335 public:
336         PaletteHex(ColorWindow *window, int x, int y, const char *hex);
337         ~PaletteHex();
338         int handle_event();
339         void update();
340         ColorWindow *window;
341 };
342
343 class PaletteGrabButton : public BC_Button
344 {
345 public:
346         PaletteGrabButton(ColorWindow *window, int x, int y);
347         ~PaletteGrabButton();
348         int handle_event();
349
350         ColorWindow *window;
351         VFrame *vframes[3];
352 };
353
354 class PaletteHistory : public BC_SubWindow
355 {
356 public:
357         PaletteHistory(ColorWindow *window, int x, int y);
358         ~PaletteHistory();
359         void update(int flush=1);
360         int button_press_event();
361         int button_release_event();
362         int cursor_motion_event();
363         int cursor_enter_event();
364         int cursor_leave_event();
365         int repeat_event(int64_t duration);
366
367         ColorWindow *window;
368         int button_down;
369 };
370
371 #endif