Fltk Color Choosers

#include <FL/Fl_Color_Chooser.H>

int fl_color_chooser(const char*, double& r, double& g, double& b);
int fl_color_chooser(const char*, uchar& r, uchar& g, uchar& b);

The double version takes r,g,b values in the range 0.0 to 1.0. The uchar version takes r,g,b values in the range 0 to 255.

fl_color_chooser() pops up a window to let the user pick an arbitrary rgb color. They can pick the hue and saturation in the "hue box" on the left (hold down Ctrl to just change the saturation), and the brighness using the vertical slider. Or they can type the 8-bit numbers into the rgb Fl_Value_Input fields, or drag the mouse across them to adjust them. The pull-down menu lets the user set the input fields to show rgb, hsv, or 8-bit rgb (0 to 255).

This returns non-zero if the user picks ok, and updates the r,g,b values. If the user picks cancel or closes the window this returns zero and leaves r,g,b unchanged.

If you use the color chooser on an 8-bit screen, it will allocate all the available X colors, leaving you no space to exactly represent the color the user picks! You can however use fl_rectf() to fill a region with a simulated color using dithering.

class Fl_Color_Chooser : public Fl_Group

A widget for selecting an rgb color. You can place any number of these into a panel of your own design. This widget contains the hue box, value slider, and rgb input fields from the above diagram (it does not have the color chips or the Cancel or OK buttons). The callback is done every time the user changes the rgb value. It is not done if they move the hue control in a way that produces the same rgb value, such as when saturation or value is zero.

Fl_Color_Chooser::Fl_Color_Chooser(int,int,int,int,const char* = 0);

double Fl_Color_Chooser::hue() const;

double Fl_Color_Chooser::saturation() const;

double Fl_Color_Chooser::value() const;

double Fl_Color_Chooser::r() const;
double Fl_Color_Chooser::g() const;
double Fl_Color_Chooser::b() const;

int Fl_Color_Chooser::rgb(double, double, double);

int Fl_Color_Chooser::hsv(double,double,double);

static void Fl_Color_Chooser::hsv2rgb(double, double, double, double&, double&, double&);
static void Fl_Color_Chooser::rgb2hsv(double, double, double, double&, double&, double&);

#include <FL/fl_show_colormap.H>
int fl_show_colormap(int oldcol);

fl_show_colormap() pops up a panel of the 256 colors you can access with fl_color() and lets the user pick one of them. It returns the new color index, or the old one if the user types Esc or clicks outside the window.