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