titler fixes, auto paste bug, resize popup hang, focus policy fix, chk lang
[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         void update_rgb_hex(const char *hex);
102         int rgb888();
103
104         ColorThread *thread;
105         PaletteWheel *wheel;
106         PaletteWheelValue *wheel_value;
107         PaletteOutput *output;
108         PaletteHue *hue;
109         PaletteSat *sat;
110         PaletteVal *val;
111         PaletteRed *red;
112         PaletteGrn *grn;
113         PaletteBlu *blu;
114         PaletteLum *lum;
115         PaletteCr  *c_r;
116         PaletteCb  *c_b;
117         PaletteAlpha *alpha;
118
119         PaletteHSV *hsv_h, *hsv_s, *hsv_v;
120         PaletteRGB *rgb_r, *rgb_g, *rgb_b;
121         PaletteYUV *yuv_y, *yuv_u, *yuv_v;
122         PaletteAPH *aph_a;
123
124         PaletteHexButton *hex_btn;
125         PaletteHex *hex_box;
126         PaletteGrabButton *grab_btn;
127         PaletteHistory *history;
128
129         VFrame *value_bitmap;
130         int button_grabbed;
131
132         int palette_history[PALLETTE_HISTORY_SIZE];
133         void load_history();
134         void save_history();
135         void update_history(int color);
136         void update_history();
137 };
138
139
140 class PaletteWheel : public BC_SubWindow
141 {
142 public:
143         PaletteWheel(ColorWindow *window, int x, int y);
144         ~PaletteWheel();
145         int button_press_event();
146         int cursor_motion_event();
147         int button_release_event();
148
149         void create_objects();
150         int draw(float hue, float saturation);
151         int get_angle(float x1, float y1, float x2, float y2);
152         float torads(float angle);
153         ColorWindow *window;
154         float oldhue;
155         float oldsaturation;
156         int button_down;
157 };
158
159 class PaletteWheelValue : public BC_SubWindow
160 {
161 public:
162         PaletteWheelValue(ColorWindow *window, int x, int y);
163         ~PaletteWheelValue();
164         void create_objects();
165         int button_press_event();
166         int cursor_motion_event();
167         int button_release_event();
168         int draw(float hue, float saturation, float value);
169         ColorWindow *window;
170         int button_down;
171 // Gradient
172         VFrame *frame;
173 };
174
175 class PaletteOutput : public BC_SubWindow
176 {
177 public:
178         PaletteOutput(ColorWindow *window, int x, int y);
179         ~PaletteOutput();
180         void create_objects();
181         int handle_event();
182         int draw();
183         ColorWindow *window;
184 };
185
186 class PaletteHue : public BC_ISlider
187 {
188 public:
189         PaletteHue(ColorWindow *window, int x, int y);
190         ~PaletteHue();
191         int handle_event();
192         ColorWindow *window;
193 };
194
195 class PaletteSat : public BC_FSlider
196 {
197 public:
198         PaletteSat(ColorWindow *window, int x, int y);
199         ~PaletteSat();
200         int handle_event();
201         ColorWindow *window;
202 };
203
204 class PaletteVal : public BC_FSlider
205 {
206 public:
207         PaletteVal(ColorWindow *window, int x, int y);
208         ~PaletteVal();
209         int handle_event();
210         ColorWindow *window;
211 };
212
213 class PaletteRed : public BC_FSlider
214 {
215 public:
216         PaletteRed(ColorWindow *window, int x, int y);
217         ~PaletteRed();
218         int handle_event();
219         ColorWindow *window;
220 };
221
222 class PaletteGrn : public BC_FSlider
223 {
224 public:
225         PaletteGrn(ColorWindow *window, int x, int y);
226         ~PaletteGrn();
227         int handle_event();
228         ColorWindow *window;
229 };
230
231 class PaletteBlu : public BC_FSlider
232 {
233 public:
234         PaletteBlu(ColorWindow *window, int x, int y);
235         ~PaletteBlu();
236         int handle_event();
237         ColorWindow *window;
238 };
239
240 class PaletteAlpha : public BC_FSlider
241 {
242 public:
243         PaletteAlpha(ColorWindow *window, int x, int y);
244         ~PaletteAlpha();
245         int handle_event();
246         ColorWindow *window;
247 };
248
249 class PaletteLum : public BC_FSlider
250 {
251 public:
252         PaletteLum(ColorWindow *window, int x, int y);
253         ~PaletteLum();
254         int handle_event();
255         ColorWindow *window;
256 };
257
258 class PaletteCr : public BC_FSlider
259 {
260 public:
261         PaletteCr(ColorWindow *window, int x, int y);
262         ~PaletteCr();
263         int handle_event();
264         ColorWindow *window;
265 };
266
267 class PaletteCb : public BC_FSlider
268 {
269 public:
270         PaletteCb(ColorWindow *window, int x, int y);
271         ~PaletteCb();
272         int handle_event();
273         ColorWindow *window;
274 };
275
276 class PaletteNum : public BC_TumbleTextBox
277 {
278 public:
279         ColorWindow *window;
280         float *output;
281
282         PaletteNum(ColorWindow *window, int x, int y,
283                         float &output, float min, float max);
284         ~PaletteNum();
285         void update_output() { *output = atof(get_text()); }
286         static int calculate_h() { return BC_Tumbler::calculate_h(); }
287 };
288
289 class PaletteRGB : public PaletteNum
290 {
291 public:
292         PaletteRGB(ColorWindow *window, int x, int y,
293                         float &output, float min, float max)
294          : PaletteNum(window, x, y, output, min, max) {}
295         int handle_event();
296 };
297
298 class PaletteYUV : public PaletteNum
299 {
300 public:
301         PaletteYUV(ColorWindow *window, int x, int y,
302                         float &output, float min, float max)
303          : PaletteNum(window, x, y, output, min, max) {}
304         int handle_event();
305 };
306
307 class PaletteHSV : public PaletteNum
308 {
309 public:
310         PaletteHSV(ColorWindow *window, int x, int y,
311                         float &output, float min, float max)
312          : PaletteNum(window, x, y, output, min, max) {}
313         int handle_event();
314 };
315
316 class PaletteAPH : public PaletteNum
317 {
318 public:
319         PaletteAPH(ColorWindow *window, int x, int y,
320                         float &output, float min, float max)
321          : PaletteNum(window, x, y, output, min, max) {}
322         int handle_event();
323 };
324
325 class PaletteHexButton : public BC_GenericButton
326 {
327 public:
328         PaletteHexButton(ColorWindow *window, int x, int y);
329         ~PaletteHexButton();
330         int handle_event();
331         ColorWindow *window;
332 };
333
334 class PaletteHex : public BC_TextBox
335 {
336 public:
337         PaletteHex(ColorWindow *window, int x, int y, const char *hex);
338         ~PaletteHex();
339         int keypress_event();
340         void update();
341         ColorWindow *window;
342 };
343
344 class PaletteGrabButton : public BC_Button
345 {
346 public:
347         PaletteGrabButton(ColorWindow *window, int x, int y);
348         ~PaletteGrabButton();
349         int handle_event();
350
351         ColorWindow *window;
352         VFrame *vframes[3];
353 };
354
355 class PaletteHistory : public BC_SubWindow
356 {
357 public:
358         PaletteHistory(ColorWindow *window, int x, int y);
359         ~PaletteHistory();
360         void update(int flush=1);
361         int button_press_event();
362         int button_release_event();
363         int cursor_motion_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