NAME

Fl::Color - Easily Imported Color-related Functions and Static Values

Synopsis

use Fl qw[:enum]; # Import with all enums!
use Fl qw[:color]; # Import just the stuff in here

Description

This file contains type definitions, general enumerations, and several functions which can be inported with the :color tag.

Colors are either 8-bit indexes into a virtual colormap or 24-bit RGB color values. (See Fl::Draw for the default colormap)

Color indices occupy the lower 8 bits of the value, while RGB colors occupy the upper 24 bits, for a byte organization of RGBI.

Fl_Color => 0xrrggbbii
               | | | |
               | | | +--- index between 0 and 255
               | | +----- blue color component (8 bit)
               | +------- green component (8 bit)
               +--------- red component (8 bit)

Here's a list of built-in colors:

FL_FOREGROUND_COLOR

The default foreground color used for labels and text.

FL_BACKGROUND2_COLOR

The default background color for text, list, and valuator widgets.

FL_INACTIVE_COLOR

The inactive foreground color.

FL_SELECTION_COLOR

The default selection/highlight color.

FL_GRAY0
FL_DARK3
FL_DARK2
FL_DARK1
FL_BACKGROUND_COLOR
FL_LIGHT1
FL_LIGHT2
FL_LIGHT3
FL_BLACK
FL_RED
FL_GREEN
FL_YELLOW
FL_BLUE
FL_MAGENTA
FL_CYAN
FL_DARK_RED
FL_DARK_GREEN
FL_DARK_YELLOW
FL_DARK_BLUE
FL_DARK_MAGENTA
FL_DARK_CYAN
FL_WHITE

The following functions are also imported with the :color tag.

fl_inactive(...)
my $inactive_red = fl_inactive(FL_RED);

Returns the inactive, dimmed version of the given color.

fl_contrast(...)
my $fg = FL_RED;
my $bg = FL_BLACK;
my $color = fl_contrast($fg, $bg);

Returns a color that contrasts with the background color.

This will be the foreground color if it contrasts sufficiently with the background color. Otherwise, returns FL_WHITE or FL_BLACK depending on which color provides the best contrast.

fl_color_average(...)
my $average = fl_color_average(FL_RED, FL_BLUE, .14);

Returns the weighted average color between the two given colors.

The red, green and blue values are averages using the following formula:

color = color1 * weight  + color2 * (1 - weight)

Thus, a weight value of 1.0 will return the first color, while a value of 0.0 will return the second color.

fl_lighter(...)
my $light_red = fl_lighter(FL_RED);

Returns a lighter version of the specified color.

fl_darker(...)
my $dark_red = fl_darker(FL_RED);

Returns a darker version of the specified color.

fl_rgb_color(...)
my $color = fl_rgb_color(100, 200, 180);

Returns the 24-bit color value closest to r, b, g.

my $gray = fl_rgb_color(13);

Returns the 24-bit color value closest to g (grayscale).

fl_gray_ramp(...)
my $gray = fl_gray_ramp(20 / 255);

Returns a gray color value scaled from black to white.

fl_color_cube(...)
my ($r, $g, $b) = (200, 180, 0);
my $color = fl_color_cube($r, $b, $g);

Returns a color out of the color cube.

$r must be in the range 0 to FL_NUM_RED - 1, $g must be in the range 0 to FL_NUM_GREEN - 1, $b must be in the range 0 to FL_NUM_BLUE - 1.

To get the closest color to a 8-bit set of R,G,B values use:

fl_color_cube(R * (FL_NUM_RED - 1) / 255, G * (FL_NUM_GREEN - 1) / 255, B * (FL_NUM_BLUE - 1) / 255);

fl_show_colormap(...)
my $new_color = fl_show_colormap(FL_RED);

Pops up a window to let the user pick a colormap entry. The provided color is highlighted when the grid is shown.

LICENSE

Copyright (C) Sanko Robinson.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

Sanko Robinson <sanko@cpan.org>