#include <fgcolor.h>
A color is normally specified in terms of RGB (red, green and blue) components, but it is also possible to specify HSV (hue, saturation and value) or set a color name (the names are copied from from the X11 color database).
In addition to the RGB value, a FGColor also has a PIXEL_ARGB value and a validity. The PIXEL_ARGB value is used by the underlying window system to refer to a color. It can be thought of as an index into the display hardware's color table.
Predefined X11 colors
A color can be set by passing setNamedColor() an RGB string like "#112233", or a color name, e.g. "blue". The names are taken from X11's rgb.txt database but can also be used under Windows. To get a lighter or darker color use light() and dark() respectively. Colors can also be set using setRgb() and setHsv(). The color components can be accessed in one go with rgb() and hsv(), or individually with red(), green() and blue().
Because many people don't know the HSV color model very well, we'll cover it briefly here.
The RGB model is hardware-oriented. Its representation is close to what most monitors show. In contrast, HSV represents color in a way more suited to the human perception of color. For example, the relationships "stronger than", "darker than" and "the opposite of" are easily expressed in HSV but are much harder to express in RGB.
HSV, like RGB, has three components:
Here are some examples: Pure red is H=0, S=1.0, V=1.0. A dark red, moving slightly towards the magenta, could be H=350 (equivalent to -10), S=1.0, V=180. A grayish light red could have H about 0 (say 350-359 or 0-10), S about 50-100, and S=1.0.
OpenGUI returns a hue value of -1 for achromatic colors. If you pass a too-big hue value, it forces it into range. Hue 360 or 720 is treated as 0; hue 540 is treated as 180.
fgcolor.cpp, and gradient.cpp.
Public Types | |
| enum | ENamedColor { none = 0xFFFFFFFF, aliceblue = 0x00F0F8FF, antiquewhite = 0x00FAEBD7, aqua = 0x0000FFFF, aquamarine = 0x007FFFD4, azure = 0x00F0FFFF, beige = 0x00F5F5DC, bisque = 0x00FFE4C4, black = 0x00000000, blanchedalmond = 0x00FFEBCD, blue = 0x000000FF, blueviolet = 0x008A2BE2, brown = 0x00A52A2A, burlywood = 0x00DEB887, cadetblue = 0x005F9EA0, chartreuse = 0x007FFF00, chocolate = 0x00D2691E, coral = 0x00FF7F50, cornflower = 0x006495ED, cornsilk = 0x00FFF8DC, crimson = 0x00DC143C, cyan = 0x0000FFFF, darkblue = 0x0000008B, darkcyan = 0x00008B8B, darkgoldenrod = 0x00B8860B, darkgray = 0x00A9A9A9, darkgreen = 0x00006400, darkkhaki = 0x00BDB76B, darkmagenta = 0x008B008B, darkolivegreen = 0x00556B2F, darkorange = 0x00FF8C00, darkorchid = 0x009932CC, darkred = 0x008B0000, darksalmon = 0x00E9967A, darkseagreen = 0x008FBC8B, darkslateblue = 0x00483D8B, darkslategray = 0x002F4F4F, darkturquoise = 0x0000CED1, darkviolet = 0x009400D3, deeppink = 0x00FF1493, deepskyblue = 0x0000BFFF, dimgray = 0x00696969, dodgerblue = 0x001E90FF, firebrick = 0x00B22222, floralwhite = 0x00FFFAF0, forestgreen = 0x00228B22, fuchsia = 0x00FF00FF, gainsboro = 0x00DCDCDC, ghostwhite = 0x00F8F8FF, gold = 0x00FFD700, goldenrod = 0x00DAA520, gray = 0x00808080, green = 0x00008000, greenyellow = 0x00ADFF2F, honeydew = 0x00F0FFF0, hotpink = 0x00FF69B4, indianred = 0x00CD5C5C, indigo = 0x004B0082, ivory = 0x00FFFFF0, khaki = 0x00F0E68C, lavender = 0x00E6E6FA, lavenderblush = 0x00FFF0F5, lawngreen = 0x007CFC00, lemonchiffon = 0x00FFFACD, lightblue = 0x00ADD8E6, lightcoral = 0x00F08080, lightcyan = 0x00E0FFFF, lightgoldenrodyellow = 0x00FAFAD2, lightgreen = 0x0090EE90, lightgrey = 0x00D3D3D3, lightpink = 0x00FFB6C1, lightsalmon = 0x00FFA07A, lightseagreen = 0x0020B2AA, lightskyblue = 0x0087CEFA, lightslategray = 0x00778899, lightsteelblue = 0x00B0C4DE, lightyellow = 0x00FFFFE0, lime = 0x0000FF00, limegreen = 0x0032CD32, linen = 0x00FAF0E6, magenta = 0x00FF00FF, maroon = 0x00800000, mediumaquamarine = 0x0066CDAA, mediumblue = 0x000000CD, mediumorchid = 0x00BA55D3, mediumpurple = 0x009370DB, mediumseagreen = 0x003CB371, mediumslateblue = 0x007B68EE, mediumspringgreen = 0x0000FA9A, mediumturquoise = 0x0048D1CC, mediumvioletred = 0x00C71585, midnightblue = 0x00191970, mintcream = 0x00F5FFFA, mistyrose = 0x00FFE4E1, moccasin = 0x00FFE4B5, navajowhite = 0x00FFDEAD, navy = 0x00000080, oldlace = 0x00FDF5E6, olive = 0x00808000, olivedrab = 0x006B8E23, orange = 0x00FFA500, orangered = 0x00FF4500, orchid = 0x00DA70D6, palegoldenrod = 0x00EEE8AA, palegreen = 0x0098FB98, paleturquoise = 0x00AFEEEE, palevioletred = 0x00DB7093, papayawhip = 0x00FFEFD5, peachpuff = 0x00FFDAB9, peru = 0x00CD853F, pink = 0x00FFC0CB, plum = 0x00DDA0DD, powderblue = 0x00B0E0E6, purple = 0x00800080, red = 0x00FF0000, rosybrown = 0x00BC8F8F, royalblue = 0x004169E1, saddlebrown = 0x008B4513, salmon = 0x00FA8072, sandybrown = 0x00F4A460, seagreen = 0x002E8B57, seashell = 0x00FFF5EE, sienna = 0x00A0522D, silver = 0x00C0C0C0, skyblue = 0x0087CEEB, slateblue = 0x006A5ACD, slategray = 0x00708090, snow = 0x00FFFAFA, springgreen = 0x0000FF7F, steelblue = 0x004682B4, tan = 0x00D2B48C, teal = 0x00008080, thistle = 0x00D8BFD8, tomato = 0x00FF6347, turquoise = 0x0040E0D0, violet = 0x00EE82EE, wheat = 0x00F5DEB3, white = 0x00FFFFFF, whitesmoke = 0x00F5F5F5, yellow = 0x00FFFF00, yellowgreen = 0x009ACD32 } |
Public Member Functions | |
| FGColor (PIXEL_ARGB cr) | |
| FGColor (int r, int g, int b) | |
| FGColor (const char *name) | |
| operator PIXEL_ARGB () const | |
| void | Desaturate (void) |
| void | Lighter (float factor=1.5) |
| void | Darker (float factor=2.0) |
| void | Opposite (void) |
| void | SetRed (int red) |
| void | SetGreen (int green) |
| void | SetBlue (int blue) |
| void | SetRGB (int red, int green, int blue) |
| int | GetRed () const |
| int | GetGreen () const |
| int | GetBlue () const |
| void | SetHue (float hue) |
| void | SetLuminance (float luminance) |
| void | SetSaturation (float saturation) |
| void | SetHLS (float hue, float luminance, float saturation) |
| float | GetHue () const |
| float | GetSaturation () const |
| float | GetLuminance () const |
| char * | GetString () const |
| bool | SetString (const char *pcColor) |
| const char * | GetName () const |
Static Public Member Functions | |
| static const char * | GetNameFromIndex (int i) |
| static FGColor | GetColorFromIndex (int i) |
| static int | GetNumNames () |
|
|
For 140 colors names are defined. The same names are used in html, the names and corresponding color values are copied from the Internet Explorer documentation (MSDN January 99: "Platform SDK/Internet/DHTML/Additional References/Color Table"). Because the elements of an enumeration are implicitly converted to integer and a PIXEL_ARGB is only a typedef for an uint, ENamedColor values can be used everywhere a PIXEL_ARGB value or a CColor object is expected. Example: |
|
|
Constructs an object of the class FGColor and initializes it with the passed color cr. At the input is ARGB PIXEL_ARGB (or palette entry index for indexed colors). The use of a default parameter implements in one step the default constructor and the conversion constructor from type PIXEL_ARGB to type FGColor. Because of this, the following code is legal, although no special assignment operator is defined: FGColor black; // intialized to black by default FGColor c1(FGDirectColor(255, 0, 0)); // initialized to red FGColor c2(FGColor::seagreen); // FGColor::ENamedColor is PIXEL_ARGB compatible FGColor c3(80,80,80); // R,G,B PIXEL_ARGB r = FGDirectColor(200, 50, 200); c1 = r; // legal, implicit call of FGColor::FGColor(r) c2 = FGDirectColor(100, 150, 200); // dito, evaluates to FGColor::FGColor(FGDirectColor(100, 150, 250)); |
|
||||||||||||||||
|
Connstruct object from R, G and B components.
|
|
|
Connstruct object aka named color.
|
|
|
Returns a darker (or lighter) color. Returns a darker color if factor is greater than 1.0 Setting factor to 3.0 returns a color that has one-third the brightness. Returns a lighter color if factor is less than 1.0 We recommend using lighter() for this purpose. If factor is 0 or negative, the return value is unspecified. (This function converts the current RGB color to HSV, divides V by factor and converts back to RGB.)
|
|
|
Desaturates color.
|
|
|
Gets the blue portion of the color. The return value lies in the range from 0 to 255.
|
|
|
Gets the color for the index i. |
|
|
Gets the green portion of the color. The return value lies in the range from 0 to 255.
|
|
|
Gets the hue. The return value is interpreted as an angle in the color circle(0.0 - 360.0 Degree). Red is positioned at 0 degree, green at 120 degree and blue at 240 Degree.
|
|
|
Gets the luminance of the color. The return value is normed, its value lies in the range between 0.0 (black) and 1.0 (white).
|
|
|
Gets the user friendly name of the color. When no name is known for the color, a string in the html format "#RRGGBB" will be returned. |
|
|
Gets the user friendly name for the index i. |
|
|
Gets the number of named colors (the number of values enumerated in ENamedColor and ENamedColorIndex). |
|
|
Gets the red portion of the color. The return value lies in the range from 0 to 255.
|
|
|
Gets the saturation of the color. The return value is normed, its value lies in the range between 0.0 (gray, absence of all colors) and 1.0 (pure color).
|
|
|
Gets the RGB color value as text in a hexadecimal representation int the format "RRGGBB". Example: red is returned as "FF0000", green as "00FF00" and blue as "0000FF".
|
|
|
Returns a lighter (or darker) color. Returns a lighter color if factor is greater than 1.0 Setting factor to 1.5 returns a color that is 50% brighter. Returns a darker color if factor is less than 1.0. We recommend using Darker() for this purpose. If factor is 0 or negative, the return value is unspecified. (This function converts the current RGB color to HSV, multiplies V by factor, and converts the result back to RGB.)
|
|
|
Returns PIXEL_ARGB value for this color. |
|
|
Changes the color to the HUE+180deg, i.e. opposite color. By example: yellow to blue |
|
|
Sets the blue portion of the color. Values must be in the range from 0 to 255. |
|
|
Sets the green portion of the color. Values must be in the range from 0 to 255. |
|
||||||||||||||||
|
Combines the methods SetHue, SetLuminance and SetSaturation in one step.
|
|
|
Sets the hue. The parameter is interpreted as an angle in the color circle(0.0 - 360.0 Degree). Red is positioned at 0 degree, green at 120 degree and blue at 240 Degree.
|
|
|
Sets the luminance of the color. The parameter is normed, its value must be in the range between 0.0 (black) and 1.0 (white).
|
|
|
Sets the red portion of the color. Values must be in the range from 0 to 255. |
|
||||||||||||||||
|
Combines the methods SetRed, SetGreen and SetBlue in one step. |
|
|
Sets the saturation of the color. The parameter is normed, its value must be in the range between 0.0 (gray, absence of all color) and 1.0 (pure colors).
|
|
|
Initializes the object with the color, whose RGB color value is scanned from the passed string pcColor. It should contain a string in the hexadecimal format RRGGBB. If no valid color could be scanned from the string, the method returns false, else true. Example: "FF0000" sets the color to red, "00FF00" to green and "0000FF" to blue. |
1.4.0