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