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