2 // "$Id: Fl_Color_Chooser.H 7981 2010-12-08 23:53:04Z greg.ercolano $"
4 // Color chooser header file for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2010 by Bill Spitzak and others.
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
29 Fl_Color_Chooser widget . */
31 // The color chooser object and the color chooser popup. The popup
32 // is just a window containing a single color chooser and some boxes
33 // to indicate the current and cancelled color.
35 #ifndef Fl_Color_Chooser_H
36 #define Fl_Color_Chooser_H
38 #include <FL/Fl_Group.H>
39 #include <FL/Fl_Box.H>
40 #include <FL/Fl_Return_Button.H>
41 #include <FL/Fl_Choice.H>
42 #include <FL/Fl_Value_Input.H>
46 /** For internal use only */
47 class FL_EXPORT Flcc_HueBox : public Fl_Widget {
54 Flcc_HueBox(int X, int Y, int W, int H) : Fl_Widget(X,Y,W,H) {
58 /** For internal use only */
59 class FL_EXPORT Flcc_ValueBox : public Fl_Widget {
66 Flcc_ValueBox(int X, int Y, int W, int H) : Fl_Widget(X,Y,W,H) {
70 /** For internal use only */
71 class FL_EXPORT Flcc_Value_Input : public Fl_Value_Input {
74 Flcc_Value_Input(int X, int Y, int W, int H) : Fl_Value_Input(X,Y,W,H) {}
79 /** \addtogroup group_comdlg
83 \class Fl_Color_Chooser
84 \brief The Fl_Color_Chooser widget provides a standard RGB color chooser.
86 \image html fl_color_chooser.jpg
87 \image latex fl_color_chooser.jpg "fl_color_chooser()" width=5cm
89 You can place any number of the widgets into a panel of your own design.
90 The diagram shows the widget as part of a color chooser dialog created by
91 the fl_color_chooser() function. The Fl_Color_Chooser widget contains the
92 hue box, value slider, and rgb input fields from the above diagram (it
93 does not have the color chips or the Cancel or OK buttons).
94 The callback is done every time the user changes the rgb value. It is not
95 done if they move the hue control in a way that produces the \e same rgb
96 value, such as when saturation or value is zero.
98 The fl_color_chooser() function pops up a window to let the user pick an
99 arbitrary RGB color. They can pick the hue and saturation in the "hue box"
100 on the left (hold down CTRL to just change the saturation), and the
101 brightness using the vertical slider. Or they can type the 8-bit numbers
102 into the RGB Fl_Value_Input fields, or drag the mouse across them to adjust
103 them. The pull-down menu lets the user set the input fields to show RGB,
104 HSV, or 8-bit RGB (0 to 255).
106 fl_color_chooser() returns non-zero if the user picks ok, and updates the
107 RGB values. If the user picks cancel or closes the window this returns
108 zero and leaves RGB unchanged.
110 If you use the color chooser on an 8-bit screen, it will allocate all the
111 available colors, leaving you no space to exactly represent the color the
112 user picks! You can however use fl_rectf() to fill a region with a simulated
113 color using dithering.
116 class FL_EXPORT Fl_Color_Chooser : public Fl_Group {
118 Flcc_ValueBox valuebox;
120 Flcc_Value_Input rvalue;
121 Flcc_Value_Input gvalue;
122 Flcc_Value_Input bvalue;
124 double hue_, saturation_, value_;
126 void set_valuators();
127 static void rgb_cb(Fl_Widget*, void*);
128 static void mode_cb(Fl_Widget*, void*);
132 Returns which Fl_Color_Chooser variant is currently active
133 \return color modes are rgb(0), byte(1), hex(2), or hsv(3)
135 int mode() {return choice.value();}
138 Set which Fl_Color_Chooser variant is currently active
139 \param[in] newMode color modes are rgb(0), byte(1), hex(2), or hsv(3)
141 void mode(int newMode);
144 Returns the current hue.
145 0 <= hue < 6. Zero is red, one is yellow, two is green, etc.
146 <em>This value is convenient for the internal calculations - some other
147 systems consider hue to run from zero to one, or from 0 to 360.</em>
149 double hue() const {return hue_;}
152 Returns the saturation.
153 0 <= saturation <= 1.
155 double saturation() const {return saturation_;}
158 Returns the value/brightness.
161 double value() const {return value_;}
164 Returns the current red value.
167 double r() const {return r_;}
170 Returns the current green value.
173 double g() const {return g_;}
176 Returns the current blue value.
179 double b() const {return b_;}
181 int hsv(double H, double S, double V);
183 int rgb(double R, double G, double B);
185 static void hsv2rgb(double H, double S, double V, double& R, double& G, double& B);
187 static void rgb2hsv(double R, double G, double B, double& H, double& S, double& V);
189 Fl_Color_Chooser(int X, int Y, int W, int H, const char *L = 0);
192 FL_EXPORT int fl_color_chooser(const char* name, double& r, double& g, double& b, int m=-1);
193 FL_EXPORT int fl_color_chooser(const char* name, uchar& r, uchar& g, uchar& b, int m=-1);
198 // End of "$Id: Fl_Color_Chooser.H 7981 2010-12-08 23:53:04Z greg.ercolano $".