00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __COLOR_H
00025 #define __COLOR_H
00026
00027 #ifdef FG_NAMESPACE
00028 namespace fgl
00029 {
00030 #endif
00031
00035 typedef unsigned PIXEL_ARGB;
00036
00098 class FGColor
00099 {
00100 public:
00101
00115 enum ENamedColor
00116 {
00117 none = 0xFFFFFFFF,
00118 aliceblue = 0x00F0F8FF,
00119 antiquewhite = 0x00FAEBD7,
00120 aqua = 0x0000FFFF,
00121 aquamarine = 0x007FFFD4,
00122 azure = 0x00F0FFFF,
00123 beige = 0x00F5F5DC,
00124 bisque = 0x00FFE4C4,
00125 black = 0x00000000,
00126 blanchedalmond = 0x00FFEBCD,
00127 blue = 0x000000FF,
00128 blueviolet = 0x008A2BE2,
00129 brown = 0x00A52A2A,
00130 burlywood = 0x00DEB887,
00131 cadetblue = 0x005F9EA0,
00132 chartreuse = 0x007FFF00,
00133 chocolate = 0x00D2691E,
00134 coral = 0x00FF7F50,
00135 cornflower = 0x006495ED,
00136 cornsilk = 0x00FFF8DC,
00137 crimson = 0x00DC143C,
00138 cyan = 0x0000FFFF,
00139 darkblue = 0x0000008B,
00140 darkcyan = 0x00008B8B,
00141 darkgoldenrod = 0x00B8860B,
00142 darkgray = 0x00A9A9A9,
00143 darkgreen = 0x00006400,
00144 darkkhaki = 0x00BDB76B,
00145 darkmagenta = 0x008B008B,
00146 darkolivegreen = 0x00556B2F,
00147 darkorange = 0x00FF8C00,
00148 darkorchid = 0x009932CC,
00149 darkred = 0x008B0000,
00150 darksalmon = 0x00E9967A,
00151 darkseagreen = 0x008FBC8B,
00152 darkslateblue = 0x00483D8B,
00153 darkslategray = 0x002F4F4F,
00154 darkturquoise = 0x0000CED1,
00155 darkviolet = 0x009400D3,
00156 deeppink = 0x00FF1493,
00157 deepskyblue = 0x0000BFFF,
00158 dimgray = 0x00696969,
00159 dodgerblue = 0x001E90FF,
00160 firebrick = 0x00B22222,
00161 floralwhite = 0x00FFFAF0,
00162 forestgreen = 0x00228B22,
00163 fuchsia = 0x00FF00FF,
00164 gainsboro = 0x00DCDCDC,
00165 ghostwhite = 0x00F8F8FF,
00166 gold = 0x00FFD700,
00167 goldenrod = 0x00DAA520,
00168 gray = 0x00808080,
00169 green = 0x00008000,
00170 greenyellow = 0x00ADFF2F,
00171 honeydew = 0x00F0FFF0,
00172 hotpink = 0x00FF69B4,
00173 indianred = 0x00CD5C5C,
00174 indigo = 0x004B0082,
00175 ivory = 0x00FFFFF0,
00176 khaki = 0x00F0E68C,
00177 lavender = 0x00E6E6FA,
00178 lavenderblush = 0x00FFF0F5,
00179 lawngreen = 0x007CFC00,
00180 lemonchiffon = 0x00FFFACD,
00181 lightblue = 0x00ADD8E6,
00182 lightcoral = 0x00F08080,
00183 lightcyan = 0x00E0FFFF,
00184 lightgoldenrodyellow = 0x00FAFAD2,
00185 lightgreen = 0x0090EE90,
00186 lightgrey = 0x00D3D3D3,
00187 lightpink = 0x00FFB6C1,
00188 lightsalmon = 0x00FFA07A,
00189 lightseagreen = 0x0020B2AA,
00190 lightskyblue = 0x0087CEFA,
00191 lightslategray = 0x00778899,
00192 lightsteelblue = 0x00B0C4DE,
00193 lightyellow = 0x00FFFFE0,
00194 lime = 0x0000FF00,
00195 limegreen = 0x0032CD32,
00196 linen = 0x00FAF0E6,
00197 magenta = 0x00FF00FF,
00198 maroon = 0x00800000,
00199 mediumaquamarine = 0x0066CDAA,
00200 mediumblue = 0x000000CD,
00201 mediumorchid = 0x00BA55D3,
00202 mediumpurple = 0x009370DB,
00203 mediumseagreen = 0x003CB371,
00204 mediumslateblue = 0x007B68EE,
00205 mediumspringgreen = 0x0000FA9A,
00206 mediumturquoise = 0x0048D1CC,
00207 mediumvioletred = 0x00C71585,
00208 midnightblue = 0x00191970,
00209 mintcream = 0x00F5FFFA,
00210 mistyrose = 0x00FFE4E1,
00211 moccasin = 0x00FFE4B5,
00212 navajowhite = 0x00FFDEAD,
00213 navy = 0x00000080,
00214 oldlace = 0x00FDF5E6,
00215 olive = 0x00808000,
00216 olivedrab = 0x006B8E23,
00217 orange = 0x00FFA500,
00218 orangered = 0x00FF4500,
00219 orchid = 0x00DA70D6,
00220 palegoldenrod = 0x00EEE8AA,
00221 palegreen = 0x0098FB98,
00222 paleturquoise = 0x00AFEEEE,
00223 palevioletred = 0x00DB7093,
00224 papayawhip = 0x00FFEFD5,
00225 peachpuff = 0x00FFDAB9,
00226 peru = 0x00CD853F,
00227 pink = 0x00FFC0CB,
00228 plum = 0x00DDA0DD,
00229 powderblue = 0x00B0E0E6,
00230 purple = 0x00800080,
00231 red = 0x00FF0000,
00232 rosybrown = 0x00BC8F8F,
00233 royalblue = 0x004169E1,
00234 saddlebrown = 0x008B4513,
00235 salmon = 0x00FA8072,
00236 sandybrown = 0x00F4A460,
00237 seagreen = 0x002E8B57,
00238 seashell = 0x00FFF5EE,
00239 sienna = 0x00A0522D,
00240 silver = 0x00C0C0C0,
00241 skyblue = 0x0087CEEB,
00242 slateblue = 0x006A5ACD,
00243 slategray = 0x00708090,
00244 snow = 0x00FFFAFA,
00245 springgreen = 0x0000FF7F,
00246 steelblue = 0x004682B4,
00247 tan = 0x00D2B48C,
00248 teal = 0x00008080,
00249 thistle = 0x00D8BFD8,
00250 tomato = 0x00FF6347,
00251 turquoise = 0x0040E0D0,
00252 violet = 0x00EE82EE,
00253 wheat = 0x00F5DEB3,
00254 white = 0x00FFFFFF,
00255 whitesmoke = 0x00F5F5F5,
00256 yellow = 0x00FFFF00,
00257 yellowgreen = 0x009ACD32
00258 };
00259
00279 FGColor(PIXEL_ARGB cr);
00281 FGColor(int r, int g, int b);
00286 FGColor(const char* name);
00287 FGColor();
00288 ~FGColor();
00289
00293 operator PIXEL_ARGB() const
00294 {
00295 return m_pixel;
00296 }
00298 void Desaturate(void);
00314 void Lighter(float factor=1.5);
00331 void Darker(float factor=2.0);
00332
00337 void Opposite(void);
00338
00339
00340
00341 void SetRed(int red);
00342 void SetGreen(int green);
00343 void SetBlue(int blue);
00344 void SetRGB(int red, int green, int blue);
00346 int GetRed() const
00347 {
00348 return m_red;
00349 }
00351 int GetGreen() const
00352 {
00353 return m_green;
00354 }
00356 int GetBlue() const
00357 {
00358 return m_blue;
00359 }
00360
00361
00362
00363
00364 void SetHue(float hue);
00365 void SetLuminance(float luminance);
00366 void SetSaturation(float saturation);
00367
00368 void SetHLS(float hue, float luminance, float saturation);
00373 float GetHue() const
00374 {
00375 return m_hue;
00376 }
00381 float GetSaturation() const
00382 {
00383 return m_saturation;
00384 }
00389 float GetLuminance() const
00390 {
00391 return m_luminance;
00392 }
00393
00394 char* GetString() const;
00395 bool SetString(const char* pcColor);
00396
00397 const char* GetName() const;
00398
00399 static const char* GetNameFromIndex(int i);
00400 static FGColor GetColorFromIndex(int i);
00405 static int GetNumNames() { return numNamedColors; }
00406
00407 private:
00408
00409
00410
00411 void RecomputeRGB(void);
00412 void RecomputeHLS(void);
00413 void RecomputeValue(void);
00414 static unsigned char ToRGB1(float rm1, float rm2, float rh);
00415
00416
00417
00418 PIXEL_ARGB m_pixel;
00419
00420 unsigned char m_blue;
00421 unsigned char m_green;
00422 unsigned char m_red;
00423 unsigned char m_alpha;
00424
00425 float m_hue;
00426 float m_saturation;
00427 float m_luminance;
00428
00429 enum ENamedColorIndex
00430 {
00431 i_aliceblue, i_antiquewhite, i_aqua, i_aquamarine, i_azure, i_beige, i_bisque, i_black,
00432 i_blanchedalmond, i_blue, i_blueviolet, i_brown, i_burlywood, i_cadetblue, i_chartreuse,
00433 i_chocolate, i_coral, i_cornflower, i_cornsilk, i_crimson, i_cyan, i_darkblue, i_darkcyan,
00434 i_darkgoldenrod, i_darkgray, i_darkgreen, i_darkkhaki, i_darkmagenta, i_darkolivegreen,
00435 i_darkorange, i_darkorchid, i_darkred, i_darksalmon, i_darkseagreen, i_darkslateblue,
00436 i_darkslategray, i_darkturquoise, i_darkviolet, i_deeppink, i_deepskyblue, i_dimgray,
00437 i_dodgerblue, i_firebrick, i_floralwhite, i_forestgreen, i_fuchsia, i_gainsboro,
00438 i_ghostwhite, i_gold, i_goldenrod, i_gray, i_green, i_greenyellow, i_honeydew, i_hotpink,
00439 i_indianred, i_indigo, i_ivory, i_khaki, i_lavender, i_lavenderblush, i_lawngreen,
00440 i_lemonchiffon, i_lightblue, i_lightcoral, i_lightcyan, i_lightgoldenrodyellow,
00441 i_lightgreen, i_lightgrey, i_lightpink, i_lightsalmon, i_lightseagreen, i_lightskyblue,
00442 i_lightslategray, i_lightsteelblue, i_lightyellow, i_lime, i_limegreen, i_linen,
00443 i_magenta, i_maroon, i_mediumaquamarine, i_mediumblue, i_mediumorchid, i_mediumpurple,
00444 i_mediumseagreen, i_mediumslateblue, i_mediumspringgreen, i_mediumturquoise,
00445 i_mediumvioletred, i_midnightblue, i_mintcream, i_mistyrose, i_moccasin, i_navajowhite,
00446 i_navy, i_oldlace, i_olive, i_olivedrab, i_orange, i_orangered, i_orchid, i_palegoldenrod,
00447 i_palegreen, i_paleturquoise, i_palevioletred, i_papayawhip, i_peachpuff, i_peru, i_pink,
00448 i_plum, i_powderblue, i_purple, i_red, i_rosybrown, i_royalblue, i_saddlebrown, i_salmon,
00449 i_sandybrown, i_seagreen, i_seashell, i_sienna, i_silver, i_skyblue, i_slateblue,
00450 i_slategray, i_snow, i_springgreen, i_steelblue, i_tan, i_teal, i_thistle, i_tomato,
00451 i_turquoise, i_violet, i_wheat, i_white, i_whitesmoke, i_yellow, i_yellowgreen,
00452 numNamedColors
00453 };
00454
00455
00456 struct FGNamedColor
00457 {
00458 PIXEL_ARGB color;
00459 char* name;
00460 };
00461 static const FGNamedColor m_namedColor[numNamedColors];
00462 };
00463
00469 class FG2Colors
00470 {
00471 FGColor color0;
00472 FGColor color180;
00473 public:
00475 FG2Colors(FGColor& base)
00476 {
00477 color0 = color180 = base;
00478 color180.SetHue(color180.GetHue()+180);
00479 }
00481 FGColor GetColor0(void) { return color0; }
00483 FGColor GetColor1(void) { return color180; }
00484 };
00485
00491 class FG3Colors
00492 {
00493 FGColor color0;
00494 FGColor color120;
00495 FGColor color240;
00496 public:
00498 FG3Colors(FGColor& base)
00499 {
00500 color0 = color120 = color240 = base;
00501 color120.SetHue(color120.GetHue()+120);
00502 color240.SetHue(color240.GetHue()+240);
00503 }
00505 FGColor GetColor0(void) { return color0; }
00507 FGColor GetColor1(void) { return color120; }
00509 FGColor GetColor2(void) { return color240; }
00510 };
00511
00516 class FG4Colors
00517 {
00518 FGColor color0;
00519 FGColor color90;
00520 FGColor color180;
00521 FGColor color270;
00522 public:
00524 FG4Colors(FGColor& base)
00525 {
00526 color0 = color90 = color180 = color270 = base;
00527 color90.SetHue(color90.GetHue()+90);
00528 color180.SetHue(color180.GetHue()+180);
00529 color270.SetHue(color270.GetHue()+270);
00530 }
00532 FGColor GetColor0(void) { return color0; }
00534 FGColor GetColor1(void) { return color90; }
00536 FGColor GetColor2(void) { return color180; }
00538 FGColor GetColor3(void) { return color270; }
00539 };
00540
00545 class FGRelatedColors
00546 {
00547 FGColor colorminus30;
00548 FGColor colorminus15;
00549 FGColor color15;
00550 FGColor color30;
00551 public:
00554 FGRelatedColors(FGColor& base)
00555 {
00556 colorminus30 = colorminus15 = color15 = color30 = base;
00557 colorminus30.SetHue(colorminus30.GetHue()-30);
00558 colorminus15.SetHue(colorminus15.GetHue()-15);
00559 color15.SetHue(color15.GetHue()+15);
00560 color30.SetHue(color30.GetHue()+30);
00561 }
00563 FGColor GetColor0(void) { return colorminus30; }
00565 FGColor GetColor1(void) { return colorminus15; }
00567 FGColor GetColor2(void) { return color15; }
00569 FGColor GetColor3(void) { return color30; }
00570 };
00571
00572
00573 #ifdef FG_NAMESPACE
00574 }
00575 #endif
00576
00577 #endif
00578