1 // generated by Fast Light User Interface Designer (fluid) version 1.0100
2 
3 #include "ColorEditor.h"
4 // Quat - A 3D fractal generation program
5 // Copyright (C) 1997-2000 Dirk Meyer
6 // (email: dirk.meyer@studserv.uni-stuttgart.de)
7 // mail:  Dirk Meyer
8 //        Marbacher Weg 29
9 //        D-71334 Waiblingen
10 //        Germany
11 //
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28 #include <FL/Fl_Color_Chooser.H>
29 #include "ColorPreview.h"
30 #include "ColorClipboard.h"
31 #include "ChildWindow.h"
32 
cb_add_i(Fl_Button *,void *)33 inline void ColorEditor::cb_add_i(Fl_Button*, void*) {
34   CP->add();
35 }
cb_add(Fl_Button * o,void * v)36 void ColorEditor::cb_add(Fl_Button* o, void* v) {
37   ((ColorEditor*)(o->parent()->user_data()))->cb_add_i(o,v);
38 }
39 
cb_del_i(Fl_Button *,void *)40 inline void ColorEditor::cb_del_i(Fl_Button*, void*) {
41   CP->del();
42 }
cb_del(Fl_Button * o,void * v)43 void ColorEditor::cb_del(Fl_Button* o, void* v) {
44   ((ColorEditor*)(o->parent()->user_data()))->cb_del_i(o,v);
45 }
46 
cb_weight_i(Fl_Value_Input * o,void *)47 inline void ColorEditor::cb_weight_i(Fl_Value_Input* o, void*) {
48   CP->weight(CP->current(), o->value());
49 }
cb_weight(Fl_Value_Input * o,void * v)50 void ColorEditor::cb_weight(Fl_Value_Input* o, void* v) {
51   ((ColorEditor*)(o->parent()->user_data()))->cb_weight_i(o,v);
52 }
53 
cb_red1_i(Fl_Value_Input * o,void *)54 inline void ColorEditor::cb_red1_i(Fl_Value_Input* o, void*) {
55   CP->red1(CP->current(), o->value());
56 }
cb_red1(Fl_Value_Input * o,void * v)57 void ColorEditor::cb_red1(Fl_Value_Input* o, void* v) {
58   ((ColorEditor*)(o->parent()->user_data()))->cb_red1_i(o,v);
59 }
60 
cb_green1_i(Fl_Value_Input * o,void *)61 inline void ColorEditor::cb_green1_i(Fl_Value_Input* o, void*) {
62   CP->green1(CP->current(), o->value());
63 }
cb_green1(Fl_Value_Input * o,void * v)64 void ColorEditor::cb_green1(Fl_Value_Input* o, void* v) {
65   ((ColorEditor*)(o->parent()->user_data()))->cb_green1_i(o,v);
66 }
67 
cb_blue1_i(Fl_Value_Input * o,void *)68 inline void ColorEditor::cb_blue1_i(Fl_Value_Input* o, void*) {
69   CP->blue1(CP->current(), o->value());
70 }
cb_blue1(Fl_Value_Input * o,void * v)71 void ColorEditor::cb_blue1(Fl_Value_Input* o, void* v) {
72   ((ColorEditor*)(o->parent()->user_data()))->cb_blue1_i(o,v);
73 }
74 
cb_button_sel1_i(Fl_Button *,void *)75 inline void ColorEditor::cb_button_sel1_i(Fl_Button*, void*) {
76   {
77 	double r = red1->value();
78 	double g = green1->value();
79 	double b = blue1->value();
80 	if (fl_color_chooser("Select Color 1", r, g, b))
81 	{
82 		red1->value(r); green1->value(g); blue1->value(b);
83 		red1->do_callback(); green1->do_callback(); blue1->do_callback();
84 	}
85 };
86 }
cb_button_sel1(Fl_Button * o,void * v)87 void ColorEditor::cb_button_sel1(Fl_Button* o, void* v) {
88   ((ColorEditor*)(o->parent()->user_data()))->cb_button_sel1_i(o,v);
89 }
90 
cb_button_copy1_i(Fl_Button *,void *)91 inline void ColorEditor::cb_button_copy1_i(Fl_Button*, void*) {
92   clip->Set(red1->value(), green1->value(), blue1->value()); clip->redraw();
93 }
cb_button_copy1(Fl_Button * o,void * v)94 void ColorEditor::cb_button_copy1(Fl_Button* o, void* v) {
95   ((ColorEditor*)(o->parent()->user_data()))->cb_button_copy1_i(o,v);
96 }
97 
cb_button_paste1_i(Fl_Button *,void *)98 inline void ColorEditor::cb_button_paste1_i(Fl_Button*, void*) {
99   red1->value(clip->GetRed()); green1->value(clip->GetGreen()); blue1->value(clip->GetBlue());
100 red1->do_callback(); green1->do_callback(); blue1->do_callback();
101 }
cb_button_paste1(Fl_Button * o,void * v)102 void ColorEditor::cb_button_paste1(Fl_Button* o, void* v) {
103   ((ColorEditor*)(o->parent()->user_data()))->cb_button_paste1_i(o,v);
104 }
105 
cb_red2_i(Fl_Value_Input * o,void *)106 inline void ColorEditor::cb_red2_i(Fl_Value_Input* o, void*) {
107   CP->red2(CP->current(), o->value());
108 }
cb_red2(Fl_Value_Input * o,void * v)109 void ColorEditor::cb_red2(Fl_Value_Input* o, void* v) {
110   ((ColorEditor*)(o->parent()->user_data()))->cb_red2_i(o,v);
111 }
112 
cb_green2_i(Fl_Value_Input * o,void *)113 inline void ColorEditor::cb_green2_i(Fl_Value_Input* o, void*) {
114   CP->green2(CP->current(), o->value());
115 }
cb_green2(Fl_Value_Input * o,void * v)116 void ColorEditor::cb_green2(Fl_Value_Input* o, void* v) {
117   ((ColorEditor*)(o->parent()->user_data()))->cb_green2_i(o,v);
118 }
119 
cb_blue2_i(Fl_Value_Input * o,void *)120 inline void ColorEditor::cb_blue2_i(Fl_Value_Input* o, void*) {
121   CP->blue2(CP->current(), o->value());
122 }
cb_blue2(Fl_Value_Input * o,void * v)123 void ColorEditor::cb_blue2(Fl_Value_Input* o, void* v) {
124   ((ColorEditor*)(o->parent()->user_data()))->cb_blue2_i(o,v);
125 }
126 
cb_button_sel2_i(Fl_Button *,void *)127 inline void ColorEditor::cb_button_sel2_i(Fl_Button*, void*) {
128   {
129 	double r = red2->value();
130 	double g = green2->value();
131 	double b = blue2->value();
132 	if (fl_color_chooser("Select Color 2", r, g, b))
133 	{
134 		red2->value(r); green2->value(g); blue2->value(b);
135 		red2->do_callback(); green2->do_callback(); blue2->do_callback();
136 	}
137 };
138 }
cb_button_sel2(Fl_Button * o,void * v)139 void ColorEditor::cb_button_sel2(Fl_Button* o, void* v) {
140   ((ColorEditor*)(o->parent()->user_data()))->cb_button_sel2_i(o,v);
141 }
142 
cb_button_copy2_i(Fl_Button *,void *)143 inline void ColorEditor::cb_button_copy2_i(Fl_Button*, void*) {
144   clip->Set(red2->value(), green2->value(), blue2->value()); clip->redraw();
145 }
cb_button_copy2(Fl_Button * o,void * v)146 void ColorEditor::cb_button_copy2(Fl_Button* o, void* v) {
147   ((ColorEditor*)(o->parent()->user_data()))->cb_button_copy2_i(o,v);
148 }
149 
cb_button_paste2_i(Fl_Button *,void *)150 inline void ColorEditor::cb_button_paste2_i(Fl_Button*, void*) {
151   red2->value(clip->GetRed()); green2->value(clip->GetGreen()); blue2->value(clip->GetBlue());
152 red2->do_callback(); green2->do_callback(); blue2->do_callback();
153 }
cb_button_paste2(Fl_Button * o,void * v)154 void ColorEditor::cb_button_paste2(Fl_Button* o, void* v) {
155   ((ColorEditor*)(o->parent()->user_data()))->cb_button_paste2_i(o,v);
156 }
157 
cb_0_i(Fl_Menu_ * o,void *)158 inline void ColorEditor::cb_0_i(Fl_Menu_* o, void*) {
159   ColorFormula->value(o->text());
160 }
cb_0(Fl_Menu_ * o,void * v)161 void ColorEditor::cb_0(Fl_Menu_* o, void* v) {
162   ((ColorEditor*)(o->parent()->user_data()))->cb_0_i(o,v);
163 }
164 
cb_01_i(Fl_Menu_ * o,void *)165 inline void ColorEditor::cb_01_i(Fl_Menu_* o, void*) {
166   ColorFormula->value(o->text());
167 }
cb_01(Fl_Menu_ * o,void * v)168 void ColorEditor::cb_01(Fl_Menu_* o, void* v) {
169   ((ColorEditor*)(o->parent()->user_data()))->cb_01_i(o,v);
170 }
171 
cb_02_i(Fl_Menu_ * o,void *)172 inline void ColorEditor::cb_02_i(Fl_Menu_* o, void*) {
173   ColorFormula->value(o->text());
174 }
cb_02(Fl_Menu_ * o,void * v)175 void ColorEditor::cb_02(Fl_Menu_* o, void* v) {
176   ((ColorEditor*)(o->parent()->user_data()))->cb_02_i(o,v);
177 }
178 
cb_03_i(Fl_Menu_ * o,void *)179 inline void ColorEditor::cb_03_i(Fl_Menu_* o, void*) {
180   ColorFormula->value(o->text());
181 }
cb_03(Fl_Menu_ * o,void * v)182 void ColorEditor::cb_03(Fl_Menu_* o, void* v) {
183   ((ColorEditor*)(o->parent()->user_data()))->cb_03_i(o,v);
184 }
185 
cb_04_i(Fl_Menu_ * o,void *)186 inline void ColorEditor::cb_04_i(Fl_Menu_* o, void*) {
187   ColorFormula->value(o->text());
188 }
cb_04(Fl_Menu_ * o,void * v)189 void ColorEditor::cb_04(Fl_Menu_* o, void* v) {
190   ((ColorEditor*)(o->parent()->user_data()))->cb_04_i(o,v);
191 }
192 
cb_x_i(Fl_Menu_ * o,void *)193 inline void ColorEditor::cb_x_i(Fl_Menu_* o, void*) {
194   ColorFormula->value(o->text());
195 }
cb_x(Fl_Menu_ * o,void * v)196 void ColorEditor::cb_x(Fl_Menu_* o, void* v) {
197   ((ColorEditor*)(o->parent()->user_data()))->cb_x_i(o,v);
198 }
199 
cb_sin_i(Fl_Menu_ * o,void *)200 inline void ColorEditor::cb_sin_i(Fl_Menu_* o, void*) {
201   ColorFormula->value(o->text());
202 }
cb_sin(Fl_Menu_ * o,void * v)203 void ColorEditor::cb_sin(Fl_Menu_* o, void* v) {
204   ((ColorEditor*)(o->parent()->user_data()))->cb_sin_i(o,v);
205 }
206 
cb_y_i(Fl_Menu_ * o,void *)207 inline void ColorEditor::cb_y_i(Fl_Menu_* o, void*) {
208   ColorFormula->value(o->text());
209 }
cb_y(Fl_Menu_ * o,void * v)210 void ColorEditor::cb_y(Fl_Menu_* o, void* v) {
211   ((ColorEditor*)(o->parent()->user_data()))->cb_y_i(o,v);
212 }
213 
cb_sqrt_i(Fl_Menu_ * o,void *)214 inline void ColorEditor::cb_sqrt_i(Fl_Menu_* o, void*) {
215   ColorFormula->value(o->text());
216 }
cb_sqrt(Fl_Menu_ * o,void * v)217 void ColorEditor::cb_sqrt(Fl_Menu_* o, void* v) {
218   ((ColorEditor*)(o->parent()->user_data()))->cb_sqrt_i(o,v);
219 }
220 
221 Fl_Menu_Item ColorEditor::menu_choice_formula[] = {
222  {" These are only examples.", 0,  0, 0, 1, 0, 0, 12, 72},
223  {" You can also enter your own formula!", 0,  0, 0, 1, 0, 0, 12, 72},
224  {" 0", 0,  (Fl_Callback*)ColorEditor::cb_0, 0, 0, 0, 0, 12, 0},
225  {" 0.36*x-0.5       # linear in x-dir", 0,  (Fl_Callback*)ColorEditor::cb_01, 0, 0, 0, 0, 12, 0},
226  {" 0.48*y-0.5      # linear in y-dir.", 0,  (Fl_Callback*)ColorEditor::cb_02, 0, 0, 0, 0, 12, 0},
227  {" 0.25*z-0.5      # linear in z-dir.", 0,  (Fl_Callback*)ColorEditor::cb_03, 0, 0, 0, 0, 12, 0},
228  {" 0.7*sqrt(x^2+y^2+z^2)     # spherical", 0,  (Fl_Callback*)ColorEditor::cb_04, 0, 0, 0, 0, 12, 0},
229  {" x+y     # diagonal striped", 0,  (Fl_Callback*)ColorEditor::cb_x, 0, 0, 0, 0, 12, 0},
230  {" (sin(7*x)+sin(7*y)+sin(7*z)+3)/6  # big speckles", 0,  (Fl_Callback*)ColorEditor::cb_sin, 0, 0, 0, 0, 12, 0},
231  {" y+0.2*sin(15*x)    # spikes", 0,  (Fl_Callback*)ColorEditor::cb_y, 0, 0, 0, 0, 12, 0},
232  {" sqrt((orbite(5)-x)^2+(orbitj(5)-y)^2+(orbitk(5)-z)^2+(orbitl(5)-orbitl(0))^2\
233 )", 0,  (Fl_Callback*)ColorEditor::cb_sqrt, 0, 0, 0, 0, 12, 0},
234  {0}
235 };
236 
ColorEditor(int X,int Y,int W,int H,const char * label)237 ColorEditor::ColorEditor(int X, int Y, int W, int H, const char *label) : Fl_Group(X,Y,W,H,label) {
238   ChildWindow* w;
239   { ChildWindow* o = win = new ChildWindow(416, 216);
240     w = o;
241     o->user_data((void*)(this));
242     { Fl_Group* o = new Fl_Group(10, 50, 100, 90, "Range");
243       o->tooltip("A color range begins with color 1 and fades smoothly into color 2.");
244       o->box(FL_EMBOSSED_FRAME);
245       o->labelsize(12);
246       o->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
247       o->end();
248     }
249     { Fl_Group* o = new Fl_Group(110, 50, 150, 90, "Color 1");
250       o->tooltip("Start color of the selected color range.");
251       o->box(FL_EMBOSSED_FRAME);
252       o->labelsize(12);
253       o->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
254       o->end();
255     }
256     { Fl_Group* o = new Fl_Group(260, 50, 150, 90, "Color 2");
257       o->tooltip("End color of the selected color range.");
258       o->box(FL_EMBOSSED_FRAME);
259       o->labelsize(12);
260       o->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
261       o->end();
262     }
263     { ColorPreview* o = CP = new ColorPreview(10, 5, 370, 20, "label");
264       o->tooltip("Select the color range to edit.");
265       o->box(FL_UP_BOX);
266       o->labeltype(FL_NO_LABEL);
267       o->labelsize(12);
268     }
269     { ColorClipboard* o = clip = new ColorClipboard(390, 5, 20, 20, "label");
270       o->tooltip("Displays the color currently in clipboard.");
271       o->box(FL_DOWN_BOX);
272       o->labeltype(FL_NO_LABEL);
273       o->labelsize(12);
274       o->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
275     }
276     { Fl_Box* o = new Fl_Box(30, 25, 20, 10, "0");
277       o->box(FL_FLAT_BOX);
278       o->labelsize(10);
279     }
280     { Fl_Box* o = new Fl_Box(340, 25, 20, 10, "1");
281       o->box(FL_FLAT_BOX);
282       o->labelsize(10);
283     }
284     { Fl_Output* o = range = new Fl_Output(180, 25, 40, 15);
285       o->tooltip("Currently selected color range / number of color ranges in palette.");
286       o->textsize(11);
287     }
288     { Fl_Button* o = add = new Fl_Button(20, 70, 40, 20, "Add");
289       o->tooltip("Insert a new color range before the selected one.");
290       o->labelsize(12);
291       o->callback((Fl_Callback*)cb_add);
292     }
293     { Fl_Button* o = del = new Fl_Button(60, 70, 40, 20, "Del");
294       o->tooltip("Delete the selected color range.");
295       o->labelsize(12);
296       o->callback((Fl_Callback*)cb_del);
297       o->deactivate();
298     }
299     { Fl_Value_Input* o = weight = new Fl_Value_Input(20, 110, 80, 20, "Weighting");
300       o->tooltip("Size of the selected color range in the palette.");
301       o->labelsize(12);
302       o->minimum(1e-05);
303       o->maximum(100);
304       o->textsize(12);
305       o->callback((Fl_Callback*)cb_weight);
306       o->align(FL_ALIGN_TOP_LEFT);
307     }
308     { Fl_Value_Input* o = red1 = new Fl_Value_Input(130, 70, 80, 20, "R");
309       o->tooltip("Red");
310       o->labelsize(12);
311       o->textsize(12);
312       o->callback((Fl_Callback*)cb_red1);
313     }
314     { Fl_Value_Input* o = green1 = new Fl_Value_Input(130, 90, 80, 20, "G");
315       o->tooltip("Green");
316       o->labelsize(12);
317       o->textsize(12);
318       o->callback((Fl_Callback*)cb_green1);
319     }
320     { Fl_Value_Input* o = blue1 = new Fl_Value_Input(130, 110, 80, 20, "B");
321       o->tooltip("Blue");
322       o->labelsize(12);
323       o->textsize(12);
324       o->callback((Fl_Callback*)cb_blue1);
325     }
326     { Fl_Button* o = button_sel1 = new Fl_Button(210, 70, 40, 20, "Sel");
327       o->tooltip("Graphically select color 1.");
328       o->labelsize(12);
329       o->callback((Fl_Callback*)cb_button_sel1);
330     }
331     { Fl_Button* o = button_copy1 = new Fl_Button(210, 90, 40, 20, "Copy");
332       o->tooltip("Copy color 1 to clipboard.");
333       o->labelsize(12);
334       o->callback((Fl_Callback*)cb_button_copy1);
335     }
336     { Fl_Button* o = button_paste1 = new Fl_Button(210, 110, 40, 20, "Paste");
337       o->tooltip("Copy clipboard to color 1.");
338       o->labelsize(12);
339       o->callback((Fl_Callback*)cb_button_paste1);
340     }
341     { Fl_Value_Input* o = red2 = new Fl_Value_Input(280, 70, 80, 20, "R");
342       o->tooltip("Red");
343       o->labelsize(12);
344       o->textsize(12);
345       o->callback((Fl_Callback*)cb_red2);
346     }
347     { Fl_Value_Input* o = green2 = new Fl_Value_Input(280, 90, 80, 20, "G");
348       o->tooltip("Green");
349       o->labelsize(12);
350       o->textsize(12);
351       o->callback((Fl_Callback*)cb_green2);
352     }
353     { Fl_Value_Input* o = blue2 = new Fl_Value_Input(280, 110, 80, 20, "B");
354       o->tooltip("Blue");
355       o->labelsize(12);
356       o->textsize(12);
357       o->callback((Fl_Callback*)cb_blue2);
358     }
359     { Fl_Button* o = button_sel2 = new Fl_Button(360, 70, 40, 20, "Sel");
360       o->tooltip("Graphically select color 2.");
361       o->labelsize(12);
362       o->callback((Fl_Callback*)cb_button_sel2);
363     }
364     { Fl_Button* o = button_copy2 = new Fl_Button(360, 90, 40, 20, "Copy");
365       o->tooltip("Copy color 2 to clipboard.");
366       o->labelsize(12);
367       o->callback((Fl_Callback*)cb_button_copy2);
368     }
369     { Fl_Button* o = button_paste2 = new Fl_Button(360, 110, 40, 20, "Paste");
370       o->tooltip("Copy clipboard to color 2.");
371       o->labelsize(12);
372       o->callback((Fl_Callback*)cb_button_paste2);
373     }
374     { Fl_Choice* o = choice_formula = new Fl_Choice(10, 190, 20, 20, "Color Formula");
375       o->tooltip("Click here for example formulas.");
376       o->down_box(FL_DOWN_BOX);
377       o->labelsize(12);
378       o->textsize(12);
379       o->align(FL_ALIGN_TOP_LEFT);
380       o->menu(menu_choice_formula);
381     }
382     { Fl_Input* o = ColorFormula = new Fl_Input(30, 190, 380, 20, "Color Formula");
383       o->tooltip("The result of a color formula is an index into the palette.\nSo you can estab\
384 lish a connection between points\nin space and colors");
385       o->labeltype(FL_NO_LABEL);
386       o->labelsize(12);
387       o->textsize(12);
388       o->align(FL_ALIGN_TOP_LEFT);
389     }
390     o->clear_border();
391     o->end();
392   }
393   CP->SetInputs(add,del,weight,red1,green1,blue1,red2,green2,blue2,range);
394 end(); // VERY IMPORTANT!
395 win->position(X+2, Y+2);
396 // DON'T delete win in destructor (or elsewhere)
397 // it's automatically deleted by Fl_Group
398 }
399 
set(const realpal_cpp & p,const colscheme_cpp & scheme)400 void ColorEditor::set(const realpal_cpp& p, const colscheme_cpp& scheme) {
401   CP->SetPal(p);
402 ColorFormula->value(reinterpret_cast<const char*>(&scheme));
403 
404 return;
405 }
406 
get(realpal_cpp & p,colscheme_cpp & scheme)407 void ColorEditor::get(realpal_cpp& p, colscheme_cpp& scheme) {
408   CP->GetPal(p);
409 strcpy(scheme, ColorFormula->value());
410 return;
411 }
412 
deactiv()413 void ColorEditor::deactiv() {
414   add->deactivate();
415 del->deactivate();
416 weight->deactivate();
417 button_sel1->deactivate();
418 button_copy1->deactivate();
419 button_paste1->deactivate();
420 red1->deactivate();
421 green1->deactivate();
422 blue1->deactivate();
423 button_sel2->deactivate();
424 button_copy2->deactivate();
425 button_paste2->deactivate();
426 red2->deactivate();
427 green2->deactivate();
428 blue2->deactivate();
429 choice_formula->deactivate();
430 ColorFormula->deactivate();
431 }
432