rework transportque for shuttle speed codes, add rusage, cleanup
[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 "colorpicker.inc"
31 #include "condition.inc"
32 #include "guicast.h"
33 #include "mutex.inc"
34 #include "thread.h"
35 #include "vframe.inc"
36
37 #define PALLETTE_HISTORY_SIZE 16
38
39
40 class ColorPicker : public BC_DialogThread
41 {
42 public:
43         ColorPicker(int do_alpha = 0, const char *title = 0);
44         ~ColorPicker();
45
46         void start_window(int output, int alpha, int ok_cancel=0);
47         virtual int handle_new_color(int output, int alpha);
48         void update_gui(int output, int alpha);
49         BC_Window* new_gui();
50         virtual void create_objects(ColorWindow *gui) {}
51
52         int orig_color, orig_alpha;
53         int output, alpha;
54         int do_alpha, ok_cancel;
55         const char *title;
56 };
57
58 class ColorWindow : public BC_Window
59 {
60 public:
61         ColorWindow(ColorPicker *thread, int x, int y, int w, int h, const char *title);
62         ~ColorWindow();
63
64         void create_objects();
65         void change_values();
66         int close_event();
67         void update_display();
68         void update_rgb();
69         void update_hsv();
70         void update_yuv();
71         int handle_event();
72         void get_screen_sample();
73         int cursor_motion_event();
74         int button_press_event();
75         int button_release_event();
76
77         struct { float r, g, b; } rgb;
78         struct { float y, u, v; } yuv;
79         struct { float h, s, v; } hsv;
80         float aph;
81         void update_rgb(float r, float g, float b);
82         void update_hsv(float h, float s, float v);
83         void update_yuv(float y, float u, float v);
84         void update_rgb_hex(const char *hex);
85         int rgb888();
86         int alpha8();
87
88         ColorPicker *thread;
89         PaletteWheel *wheel;
90         PaletteWheelValue *wheel_value;
91         PaletteOutput *output;
92         PaletteHue *hue;
93         PaletteSat *sat;
94         PaletteVal *val;
95         PaletteRed *red;
96         PaletteGrn *grn;
97         PaletteBlu *blu;
98         PaletteLum *lum;
99         PaletteCr  *c_r;
100         PaletteCb  *c_b;
101         PaletteAlpha *alpha;
102
103         PaletteHSV *hsv_h, *hsv_s, *hsv_v;
104         PaletteRGB *rgb_r, *rgb_g, *rgb_b;
105         PaletteYUV *yuv_y, *yuv_u, *yuv_v;
106         PaletteAPH *aph_a;
107
108         PaletteHexButton *hex_btn;
109         PaletteHex *hex_box;
110         PaletteGrabButton *grab_btn;
111         PaletteHistory *history;
112
113         VFrame *value_bitmap;
114         int button_grabbed;
115
116         int palette_history[PALLETTE_HISTORY_SIZE];
117         void load_history();
118         void save_history();
119         void update_history(int color);
120         void update_history();
121 };
122
123
124 class PaletteWheel : public BC_SubWindow
125 {
126 public:
127         PaletteWheel(ColorWindow *window, int x, int y);
128         ~PaletteWheel();
129         int button_press_event();
130         int cursor_motion_event();
131         int button_release_event();
132
133         void create_objects();
134         int draw(float hue, float saturation);
135         int get_angle(float x1, float y1, float x2, float y2);
136         float torads(float angle);
137         ColorWindow *window;
138         float oldhue;
139         float oldsaturation;
140         int button_down;
141 };
142
143 class PaletteWheelValue : public BC_SubWindow
144 {
145 public:
146         PaletteWheelValue(ColorWindow *window, int x, int y);
147         ~PaletteWheelValue();
148         void create_objects();
149         int button_press_event();
150         int cursor_motion_event();
151         int button_release_event();
152         int draw(float hue, float saturation, float value);
153         ColorWindow *window;
154         int button_down;
155 // Gradient
156         VFrame *frame;
157 };
158
159 class PaletteOutput : public BC_SubWindow
160 {
161 public:
162         PaletteOutput(ColorWindow *window, int x, int y);
163         ~PaletteOutput();
164         void create_objects();
165         int handle_event();
166         int draw();
167         ColorWindow *window;
168 };
169
170 class PaletteHue : public BC_ISlider
171 {
172 public:
173         PaletteHue(ColorWindow *window, int x, int y);
174         ~PaletteHue();
175         int handle_event();
176         ColorWindow *window;
177 };
178
179 class PaletteSat : public BC_FSlider
180 {
181 public:
182         PaletteSat(ColorWindow *window, int x, int y);
183         ~PaletteSat();
184         int handle_event();
185         ColorWindow *window;
186 };
187
188 class PaletteVal : public BC_FSlider
189 {
190 public:
191         PaletteVal(ColorWindow *window, int x, int y);
192         ~PaletteVal();
193         int handle_event();
194         ColorWindow *window;
195 };
196
197 class PaletteRed : public BC_FSlider
198 {
199 public:
200         PaletteRed(ColorWindow *window, int x, int y);
201         ~PaletteRed();
202         int handle_event();
203         ColorWindow *window;
204 };
205
206 class PaletteGrn : public BC_FSlider
207 {
208 public:
209         PaletteGrn(ColorWindow *window, int x, int y);
210         ~PaletteGrn();
211         int handle_event();
212         ColorWindow *window;
213 };
214
215 class PaletteBlu : public BC_FSlider
216 {
217 public:
218         PaletteBlu(ColorWindow *window, int x, int y);
219         ~PaletteBlu();
220         int handle_event();
221         ColorWindow *window;
222 };
223
224 class PaletteAlpha : public BC_FSlider
225 {
226 public:
227         PaletteAlpha(ColorWindow *window, int x, int y);
228         ~PaletteAlpha();
229         int handle_event();
230         ColorWindow *window;
231 };
232
233 class PaletteLum : public BC_FSlider
234 {
235 public:
236         PaletteLum(ColorWindow *window, int x, int y);
237         ~PaletteLum();
238         int handle_event();
239         ColorWindow *window;
240 };
241
242 class PaletteCr : public BC_FSlider
243 {
244 public:
245         PaletteCr(ColorWindow *window, int x, int y);
246         ~PaletteCr();
247         int handle_event();
248         ColorWindow *window;
249 };
250
251 class PaletteCb : public BC_FSlider
252 {
253 public:
254         PaletteCb(ColorWindow *window, int x, int y);
255         ~PaletteCb();
256         int handle_event();
257         ColorWindow *window;
258 };
259
260 class PaletteNum : public BC_TumbleTextBox
261 {
262 public:
263         ColorWindow *window;
264         float *output;
265
266         PaletteNum(ColorWindow *window, int x, int y,
267                         float &output, float min, float max);
268         ~PaletteNum();
269         void update_output() { *output = atof(get_text()); }
270         static int calculate_h() { return BC_Tumbler::calculate_h(); }
271 };
272
273 class PaletteRGB : public PaletteNum
274 {
275 public:
276         PaletteRGB(ColorWindow *window, int x, int y,
277                         float &output, float min, float max)
278          : PaletteNum(window, x, y, output, min, max) {}
279         int handle_event();
280 };
281
282 class PaletteYUV : public PaletteNum
283 {
284 public:
285         PaletteYUV(ColorWindow *window, int x, int y,
286                         float &output, float min, float max)
287          : PaletteNum(window, x, y, output, min, max) {}
288         int handle_event();
289 };
290
291 class PaletteHSV : public PaletteNum
292 {
293 public:
294         PaletteHSV(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 PaletteAPH : public PaletteNum
301 {
302 public:
303         PaletteAPH(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 PaletteHexButton : public BC_GenericButton
310 {
311 public:
312         PaletteHexButton(ColorWindow *window, int x, int y);
313         ~PaletteHexButton();
314         int handle_event();
315         ColorWindow *window;
316 };
317
318 class PaletteHex : public BC_TextBox
319 {
320 public:
321         PaletteHex(ColorWindow *window, int x, int y, const char *hex);
322         ~PaletteHex();
323         int keypress_event();
324         void update();
325         ColorWindow *window;
326 };
327
328 class PaletteGrabButton : public BC_Button
329 {
330 public:
331         PaletteGrabButton(ColorWindow *window, int x, int y);
332         ~PaletteGrabButton();
333         int handle_event();
334
335         ColorWindow *window;
336         VFrame *vframes[3];
337 };
338
339 class PaletteHistory : public BC_SubWindow
340 {
341 public:
342         PaletteHistory(ColorWindow *window, int x, int y);
343         ~PaletteHistory();
344         void update(int flush=1);
345         int button_press_event();
346         int button_release_event();
347         int cursor_motion_event();
348         int cursor_leave_event();
349         int repeat_event(int64_t duration);
350
351         ColorWindow *window;
352         int button_down;
353 };
354
355 class ColorButton : public BC_Button
356 {
357 public:
358         ColorButton(const char *title,
359                 int x, int y, int w, int h,
360                 int color, int alpha, int ok_cancel);
361         ~ColorButton();
362
363         virtual void set_color(int color);
364         virtual int handle_new_color(int color, int alpha);
365         virtual void handle_done_event(int result);
366
367         void close_picker();
368         void update_gui(int color);
369         int handle_event();
370
371         const char *title;
372         int color, alpha, ok_cancel;
373         int orig_color, orig_alpha;
374
375         VFrame *vframes[3];
376         ColorButtonPicker *color_picker;
377         ColorButtonThread *color_thread;
378 };
379
380 class ColorButtonPicker : public ColorPicker
381 {
382 public:
383         ColorButtonPicker(ColorButton *color_button);
384         ~ColorButtonPicker();
385         int handle_new_color(int color, int alpha);
386         void handle_done_event(int result);
387         void update_gui();
388
389         ColorButton *color_button;
390 };
391
392 class ColorButtonThread : public Thread
393 {
394 public:
395         ColorButtonThread(ColorButton *color_button);
396         ~ColorButtonThread();
397
398         void start();
399         void stop();
400         void run();
401
402         ColorButton *color_button;
403         Condition *update_lock;
404         int done;
405 };
406
407 class ColorBoxButton : public ColorButton
408 {
409 public:
410         ColorBoxButton(const char *title,
411                 int x, int y, int w, int h,
412                 int color, int alpha, int ok_cancel);
413         ~ColorBoxButton();
414         void create_objects();
415
416         virtual int handle_new_color(int color, int alpha);
417         virtual void handle_done_event(int result);
418         void set_color(int color);
419 };
420
421 class ColorCircleButton : public ColorButton
422 {
423 public:
424         ColorCircleButton(const char *title,
425                 int x, int y, int w, int h,
426                 int color, int alpha, int ok_cancel);
427         ~ColorCircleButton();
428         void create_objects();
429
430         virtual int handle_new_color(int color, int alpha);
431         virtual void handle_done_event(int result);
432         void set_color(int color);
433 };
434
435 #endif