colorpick rework, color popup for titler, color convert fixes
[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 "bcdialog.h"
26 #include "clip.h"
27 #include "condition.inc"
28 #include "guicast.h"
29 #include "mutex.inc"
30 #include "thread.h"
31 #include "vframe.inc"
32
33 class ColorWindow;
34 class PaletteWheel;
35 class PaletteWheelValue;
36 class PaletteOutput;
37 class PaletteHue;
38 class PaletteSat;
39 class PaletteVal;
40 class PaletteRed;
41 class PaletteGrn;
42 class PaletteBlu;
43 class PaletteLum;
44 class PaletteCr;
45 class PaletteCb;
46 class PaletteAlpha;
47 class PalletteHSV;
48 class PalletteRGB;
49 class PalletteYUV;
50 class PalletteAPH;
51
52 class ColorThread : public BC_DialogThread
53 {
54 public:
55         ColorThread(int do_alpha = 0, const char *title = 0);
56         ~ColorThread();
57
58         void start_window(int output, int alpha, int do_okcancel=0);
59         virtual int handle_new_color(int output, int alpha);
60         void update_gui(int output, int alpha);
61         BC_Window* new_gui();
62
63         int output, alpha;
64         int do_alpha, do_okcancel;
65         const char *title;
66 };
67
68 class ColorWindow : public BC_Window
69 {
70 public:
71         ColorWindow(ColorThread *thread, int x, int y, int w, int h, const char *title);
72         ~ColorWindow();
73
74         void create_objects();
75         void change_values();
76         int close_event();
77         void update_display();
78         void update_rgb();
79         void update_hsv();
80         void update_yuv();
81         int handle_event();
82
83         struct { float r, g, b; } rgb;
84         struct { float y, u, v; } yuv;
85         struct { float h, s, v; } hsv;
86         float aph;
87         void update_rgb(float r, float g, float b);
88         void update_hsv(float h, float s, float v);
89         void update_yuv(float y, float u, float v);
90
91         ColorThread *thread;
92
93         PaletteWheel *wheel;
94         PaletteWheelValue *wheel_value;
95         PaletteOutput *output;
96         PaletteHue *hue;
97         PaletteSat *sat;
98         PaletteVal *val;
99         PaletteRed *red;
100         PaletteGrn *grn;
101         PaletteBlu *blu;
102         PaletteLum *lum;
103         PaletteCr  *c_r;
104         PaletteCb  *c_b;
105         PaletteAlpha *alpha;
106
107         PalletteHSV *hsv_h, *hsv_s, *hsv_v;
108         PalletteRGB *rgb_r, *rgb_g, *rgb_b;
109         PalletteYUV *yuv_y, *yuv_u, *yuv_v;
110         PalletteAPH *aph_a;
111
112         VFrame *value_bitmap;
113 };
114
115
116 class PaletteWheel : public BC_SubWindow
117 {
118 public:
119         PaletteWheel(ColorWindow *window, int x, int y);
120         ~PaletteWheel();
121         int button_press_event();
122         int cursor_motion_event();
123         int button_release_event();
124
125         void create_objects();
126         int draw(float hue, float saturation);
127         int get_angle(float x1, float y1, float x2, float y2);
128         float torads(float angle);
129         ColorWindow *window;
130         float oldhue;
131         float oldsaturation;
132         int button_down;
133 };
134
135 class PaletteWheelValue : public BC_SubWindow
136 {
137 public:
138         PaletteWheelValue(ColorWindow *window, int x, int y);
139         ~PaletteWheelValue();
140         void create_objects();
141         int button_press_event();
142         int cursor_motion_event();
143         int button_release_event();
144         int draw(float hue, float saturation, float value);
145         ColorWindow *window;
146         int button_down;
147 // Gradient
148         VFrame *frame;
149 };
150
151 class PaletteOutput : public BC_SubWindow
152 {
153 public:
154         PaletteOutput(ColorWindow *window, int x, int y);
155         ~PaletteOutput();
156         void create_objects();
157         int handle_event();
158         int draw();
159         ColorWindow *window;
160 };
161
162 class PaletteHue : public BC_ISlider
163 {
164 public:
165         PaletteHue(ColorWindow *window, int x, int y);
166         ~PaletteHue();
167         int handle_event();
168         ColorWindow *window;
169 };
170
171 class PaletteSat : public BC_FSlider
172 {
173 public:
174         PaletteSat(ColorWindow *window, int x, int y);
175         ~PaletteSat();
176         int handle_event();
177         ColorWindow *window;
178 };
179
180 class PaletteVal : public BC_FSlider
181 {
182 public:
183         PaletteVal(ColorWindow *window, int x, int y);
184         ~PaletteVal();
185         int handle_event();
186         ColorWindow *window;
187 };
188
189 class PaletteRed : public BC_FSlider
190 {
191 public:
192         PaletteRed(ColorWindow *window, int x, int y);
193         ~PaletteRed();
194         int handle_event();
195         ColorWindow *window;
196 };
197
198 class PaletteGrn : public BC_FSlider
199 {
200 public:
201         PaletteGrn(ColorWindow *window, int x, int y);
202         ~PaletteGrn();
203         int handle_event();
204         ColorWindow *window;
205 };
206
207 class PaletteBlu : public BC_FSlider
208 {
209 public:
210         PaletteBlu(ColorWindow *window, int x, int y);
211         ~PaletteBlu();
212         int handle_event();
213         ColorWindow *window;
214 };
215
216 class PaletteAlpha : public BC_FSlider
217 {
218 public:
219         PaletteAlpha(ColorWindow *window, int x, int y);
220         ~PaletteAlpha();
221         int handle_event();
222         ColorWindow *window;
223 };
224
225 class PaletteLum : public BC_FSlider
226 {
227 public:
228         PaletteLum(ColorWindow *window, int x, int y);
229         ~PaletteLum();
230         int handle_event();
231         ColorWindow *window;
232 };
233
234 class PaletteCr : public BC_FSlider
235 {
236 public:
237         PaletteCr(ColorWindow *window, int x, int y);
238         ~PaletteCr();
239         int handle_event();
240         ColorWindow *window;
241 };
242
243 class PaletteCb : public BC_FSlider
244 {
245 public:
246         PaletteCb(ColorWindow *window, int x, int y);
247         ~PaletteCb();
248         int handle_event();
249         ColorWindow *window;
250 };
251
252 class PalletteNum : public BC_TumbleTextBox
253 {
254 public:
255         ColorWindow *window;
256         float *output;
257
258         PalletteNum(ColorWindow *window, int x, int y,
259                         float &output, float min, float max);
260         ~PalletteNum();
261         void update_output() { *output = atof(get_text()); }
262         static int calculate_h() { return BC_Tumbler::calculate_h(); }
263 };
264
265 class PalletteRGB : public PalletteNum
266 {
267 public:
268         PalletteRGB(ColorWindow *window, int x, int y,
269                         float &output, float min, float max)
270          : PalletteNum(window, x, y, output, min, max) {}
271         int handle_event();
272 };
273
274 class PalletteYUV : public PalletteNum
275 {
276 public:
277         PalletteYUV(ColorWindow *window, int x, int y,
278                         float &output, float min, float max)
279          : PalletteNum(window, x, y, output, min, max) {}
280         int handle_event();
281 };
282
283 class PalletteHSV : public PalletteNum
284 {
285 public:
286         PalletteHSV(ColorWindow *window, int x, int y,
287                         float &output, float min, float max)
288          : PalletteNum(window, x, y, output, min, max) {}
289         int handle_event();
290 };
291
292 class PalletteAPH : public PalletteNum
293 {
294 public:
295         PalletteAPH(ColorWindow *window, int x, int y,
296                         float &output, float min, float max)
297          : PalletteNum(window, x, y, output, min, max) {}
298         int handle_event();
299 };
300
301 #endif