Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages | Examples

fgcolor.h

00001 /*
00002 OpenGUI - Drawing & Windowing library
00003 
00004 Copyright (C) 1996,2005  Marian Krivos
00005 
00006 This library is free software; you can redistribute it and/or
00007 modify it under the terms of the GNU Library General Public
00008 License as published by the Free Software Foundation; either
00009 version 2 of the License, or (at your option) any later version.
00010 
00011 This library is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 Library General Public License for more details.
00015 
00016 You should have received a copy of the GNU Library General Public
00017 License along with this library; if not, write to the Free
00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 nezmar@atlas.sk
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 // Named Colors, could be used as PIXEL_ARGB
00116   {
00117     none                 = 0xFFFFFFFF,   // no color
00118     aliceblue            = 0x00F0F8FF,   // RGB(0xF0, 0xF8, 0xFF)
00119     antiquewhite         = 0x00FAEBD7,   // RGB(0xFA, 0xEB, 0xD7)
00120     aqua                 = 0x0000FFFF,   // RGB(0x00, 0xFF, 0xFF)
00121     aquamarine           = 0x007FFFD4,   // RGB(0x7F, 0xFF, 0xD4)
00122     azure                = 0x00F0FFFF,   // RGB(0xF0, 0xFF, 0xFF)
00123     beige                = 0x00F5F5DC,   // RGB(0xF5, 0xF5, 0xDC)
00124     bisque               = 0x00FFE4C4,   // RGB(0xFF, 0xE4, 0xC4)
00125     black                = 0x00000000,   // RGB(0x00, 0x00, 0x00)
00126     blanchedalmond       = 0x00FFEBCD,   // RGB(0xFF, 0xEB, 0xCD)
00127     blue                 = 0x000000FF,   // RGB(0x00, 0x00, 0xFF)
00128     blueviolet           = 0x008A2BE2,   // RGB(0x8A, 0x2B, 0xE2)
00129     brown                = 0x00A52A2A,   // RGB(0xA5, 0x2A, 0x2A)
00130     burlywood            = 0x00DEB887,   // RGB(0xDE, 0xB8, 0x87)
00131     cadetblue            = 0x005F9EA0,   // RGB(0x5F, 0x9E, 0xA0)
00132     chartreuse           = 0x007FFF00,   // RGB(0x7F, 0xFF, 0x00)
00133     chocolate            = 0x00D2691E,   // RGB(0xD2, 0x69, 0x1E)
00134     coral                = 0x00FF7F50,   // RGB(0xFF, 0x7F, 0x50)
00135     cornflower           = 0x006495ED,   // RGB(0x64, 0x95, 0xED)
00136     cornsilk             = 0x00FFF8DC,   // RGB(0xFF, 0xF8, 0xDC)
00137     crimson              = 0x00DC143C,   // RGB(0xDC, 0x14, 0x3C)
00138     cyan                 = 0x0000FFFF,   // RGB(0x00, 0xFF, 0xFF)
00139     darkblue             = 0x0000008B,   // RGB(0x00, 0x00, 0x8B)
00140     darkcyan             = 0x00008B8B,   // RGB(0x00, 0x8B, 0x8B)
00141     darkgoldenrod        = 0x00B8860B,   // RGB(0xB8, 0x86, 0x0B)
00142     darkgray             = 0x00A9A9A9,   // RGB(0xA9, 0xA9, 0xA9)
00143     darkgreen            = 0x00006400,   // RGB(0x00, 0x64, 0x00)
00144     darkkhaki            = 0x00BDB76B,   // RGB(0xBD, 0xB7, 0x6B)
00145     darkmagenta          = 0x008B008B,   // RGB(0x8B, 0x00, 0x8B)
00146     darkolivegreen       = 0x00556B2F,   // RGB(0x55, 0x6B, 0x2F)
00147     darkorange           = 0x00FF8C00,   // RGB(0xFF, 0x8C, 0x00)
00148     darkorchid           = 0x009932CC,   // RGB(0x99, 0x32, 0xCC)
00149     darkred              = 0x008B0000,   // RGB(0x8B, 0x00, 0x00)
00150     darksalmon           = 0x00E9967A,   // RGB(0xE9, 0x96, 0x7A)
00151     darkseagreen         = 0x008FBC8B,   // RGB(0x8F, 0xBC, 0x8B)
00152     darkslateblue        = 0x00483D8B,   // RGB(0x48, 0x3D, 0x8B)
00153     darkslategray        = 0x002F4F4F,   // RGB(0x2F, 0x4F, 0x4F)
00154     darkturquoise        = 0x0000CED1,   // RGB(0x00, 0xCE, 0xD1)
00155     darkviolet           = 0x009400D3,   // RGB(0x94, 0x00, 0xD3)
00156     deeppink             = 0x00FF1493,   // RGB(0xFF, 0x14, 0x93)
00157     deepskyblue          = 0x0000BFFF,   // RGB(0x00, 0xBF, 0xFF)
00158     dimgray              = 0x00696969,   // RGB(0x69, 0x69, 0x69)
00159     dodgerblue           = 0x001E90FF,   // RGB(0x1E, 0x90, 0xFF)
00160     firebrick            = 0x00B22222,   // RGB(0xB2, 0x22, 0x22)
00161     floralwhite          = 0x00FFFAF0,   // RGB(0xFF, 0xFA, 0xF0)
00162     forestgreen          = 0x00228B22,   // RGB(0x22, 0x8B, 0x22)
00163     fuchsia              = 0x00FF00FF,   // RGB(0xFF, 0x00, 0xFF)
00164     gainsboro            = 0x00DCDCDC,   // RGB(0xDC, 0xDC, 0xDC)
00165     ghostwhite           = 0x00F8F8FF,   // RGB(0xF8, 0xF8, 0xFF)
00166     gold                 = 0x00FFD700,   // RGB(0xFF, 0xD7, 0x00)
00167     goldenrod            = 0x00DAA520,   // RGB(0xDA, 0xA5, 0x20)
00168     gray                 = 0x00808080,   // RGB(0x80, 0x80, 0x80)
00169     green                = 0x00008000,   // RGB(0x00, 0x80, 0x00)
00170     greenyellow          = 0x00ADFF2F,   // RGB(0xAD, 0xFF, 0x2F)
00171     honeydew             = 0x00F0FFF0,   // RGB(0xF0, 0xFF, 0xF0)
00172     hotpink              = 0x00FF69B4,   // RGB(0xFF, 0x69, 0xB4)
00173     indianred            = 0x00CD5C5C,   // RGB(0xCD, 0x5C, 0x5C)
00174     indigo               = 0x004B0082,   // RGB(0x4B, 0x00, 0x82)
00175     ivory                = 0x00FFFFF0,   // RGB(0xFF, 0xFF, 0xF0)
00176     khaki                = 0x00F0E68C,   // RGB(0xF0, 0xE6, 0x8C)
00177     lavender             = 0x00E6E6FA,   // RGB(0xE6, 0xE6, 0xFA)
00178     lavenderblush        = 0x00FFF0F5,   // RGB(0xFF, 0xF0, 0xF5)
00179     lawngreen            = 0x007CFC00,   // RGB(0x7C, 0xFC, 0x00)
00180     lemonchiffon         = 0x00FFFACD,   // RGB(0xFF, 0xFA, 0xCD)
00181     lightblue            = 0x00ADD8E6,   // RGB(0xAD, 0xD8, 0xE6)
00182     lightcoral           = 0x00F08080,   // RGB(0xF0, 0x80, 0x80)
00183     lightcyan            = 0x00E0FFFF,   // RGB(0xE0, 0xFF, 0xFF)
00184     lightgoldenrodyellow = 0x00FAFAD2,   // RGB(0xFA, 0xFA, 0xD2)
00185     lightgreen           = 0x0090EE90,   // RGB(0x90, 0xEE, 0x90)
00186     lightgrey            = 0x00D3D3D3,   // RGB(0xD3, 0xD3, 0xD3)
00187     lightpink            = 0x00FFB6C1,   // RGB(0xFF, 0xB6, 0xC1)
00188     lightsalmon          = 0x00FFA07A,   // RGB(0xFF, 0xA0, 0x7A)
00189     lightseagreen        = 0x0020B2AA,   // RGB(0x20, 0xB2, 0xAA)
00190     lightskyblue         = 0x0087CEFA,   // RGB(0x87, 0xCE, 0xFA)
00191     lightslategray       = 0x00778899,   // RGB(0x77, 0x88, 0x99)
00192     lightsteelblue       = 0x00B0C4DE,   // RGB(0xB0, 0xC4, 0xDE)
00193     lightyellow          = 0x00FFFFE0,   // RGB(0xFF, 0xFF, 0xE0)
00194     lime                 = 0x0000FF00,   // RGB(0x00, 0xFF, 0x00)
00195     limegreen            = 0x0032CD32,   // RGB(0x32, 0xCD, 0x32)
00196     linen                = 0x00FAF0E6,   // RGB(0xFA, 0xF0, 0xE6)
00197     magenta              = 0x00FF00FF,   // RGB(0xFF, 0x00, 0xFF)
00198     maroon               = 0x00800000,   // RGB(0x80, 0x00, 0x00)
00199     mediumaquamarine     = 0x0066CDAA,   // RGB(0x66, 0xCD, 0xAA)
00200     mediumblue           = 0x000000CD,   // RGB(0x00, 0x00, 0xCD)
00201     mediumorchid         = 0x00BA55D3,   // RGB(0xBA, 0x55, 0xD3)
00202     mediumpurple         = 0x009370DB,   // RGB(0x93, 0x70, 0xDB)
00203     mediumseagreen       = 0x003CB371,   // RGB(0x3C, 0xB3, 0x71)
00204     mediumslateblue      = 0x007B68EE,   // RGB(0x7B, 0x68, 0xEE)
00205     mediumspringgreen    = 0x0000FA9A,   // RGB(0x00, 0xFA, 0x9A)
00206     mediumturquoise      = 0x0048D1CC,   // RGB(0x48, 0xD1, 0xCC)
00207     mediumvioletred      = 0x00C71585,   // RGB(0xC7, 0x15, 0x85)
00208     midnightblue         = 0x00191970,   // RGB(0x19, 0x19, 0x70)
00209     mintcream            = 0x00F5FFFA,   // RGB(0xF5, 0xFF, 0xFA)
00210     mistyrose            = 0x00FFE4E1,   // RGB(0xFF, 0xE4, 0xE1)
00211     moccasin             = 0x00FFE4B5,   // RGB(0xFF, 0xE4, 0xB5)
00212     navajowhite          = 0x00FFDEAD,   // RGB(0xFF, 0xDE, 0xAD)
00213     navy                 = 0x00000080,   // RGB(0x00, 0x00, 0x80)
00214     oldlace              = 0x00FDF5E6,   // RGB(0xFD, 0xF5, 0xE6)
00215     olive                = 0x00808000,   // RGB(0x80, 0x80, 0x00)
00216     olivedrab            = 0x006B8E23,   // RGB(0x6B, 0x8E, 0x23)
00217     orange               = 0x00FFA500,   // RGB(0xFF, 0xA5, 0x00)
00218     orangered            = 0x00FF4500,   // RGB(0xFF, 0x45, 0x00)
00219     orchid               = 0x00DA70D6,   // RGB(0xDA, 0x70, 0xD6)
00220     palegoldenrod        = 0x00EEE8AA,   // RGB(0xEE, 0xE8, 0xAA)
00221     palegreen            = 0x0098FB98,   // RGB(0x98, 0xFB, 0x98)
00222     paleturquoise        = 0x00AFEEEE,   // RGB(0xAF, 0xEE, 0xEE)
00223     palevioletred        = 0x00DB7093,   // RGB(0xDB, 0x70, 0x93)
00224     papayawhip           = 0x00FFEFD5,   // RGB(0xFF, 0xEF, 0xD5)
00225     peachpuff            = 0x00FFDAB9,   // RGB(0xFF, 0xDA, 0xB9)
00226     peru                 = 0x00CD853F,   // RGB(0xCD, 0x85, 0x3F)
00227     pink                 = 0x00FFC0CB,   // RGB(0xFF, 0xC0, 0xCB)
00228     plum                 = 0x00DDA0DD,   // RGB(0xDD, 0xA0, 0xDD)
00229     powderblue           = 0x00B0E0E6,   // RGB(0xB0, 0xE0, 0xE6)
00230     purple               = 0x00800080,   // RGB(0x80, 0x00, 0x80)
00231     red                  = 0x00FF0000,   // RGB(0xFF, 0x00, 0x00)
00232     rosybrown            = 0x00BC8F8F,   // RGB(0xBC, 0x8F, 0x8F)
00233     royalblue            = 0x004169E1,   // RGB(0x41, 0x69, 0xE1)
00234     saddlebrown          = 0x008B4513,   // RGB(0x8B, 0x45, 0x13)
00235     salmon               = 0x00FA8072,   // RGB(0xFA, 0x80, 0x72)
00236     sandybrown           = 0x00F4A460,   // RGB(0xF4, 0xA4, 0x60)
00237     seagreen             = 0x002E8B57,   // RGB(0x2E, 0x8B, 0x57)
00238     seashell             = 0x00FFF5EE,   // RGB(0xFF, 0xF5, 0xEE)
00239     sienna               = 0x00A0522D,   // RGB(0xA0, 0x52, 0x2D)
00240     silver               = 0x00C0C0C0,   // RGB(0xC0, 0xC0, 0xC0)
00241     skyblue              = 0x0087CEEB,   // RGB(0x87, 0xCE, 0xEB)
00242     slateblue            = 0x006A5ACD,   // RGB(0x6A, 0x5A, 0xCD)
00243     slategray            = 0x00708090,   // RGB(0x70, 0x80, 0x90)
00244     snow                 = 0x00FFFAFA,   // RGB(0xFF, 0xFA, 0xFA)
00245     springgreen          = 0x0000FF7F,   // RGB(0x00, 0xFF, 0x7F)
00246     steelblue            = 0x004682B4,   // RGB(0x46, 0x82, 0xB4)
00247     tan                  = 0x00D2B48C,   // RGB(0xD2, 0xB4, 0x8C)
00248     teal                 = 0x00008080,   // RGB(0x00, 0x80, 0x80)
00249     thistle              = 0x00D8BFD8,   // RGB(0xD8, 0xBF, 0xD8)
00250     tomato               = 0x00FF6347,   // RGB(0xFF, 0x63, 0x47)
00251     turquoise            = 0x0040E0D0,   // RGB(0x40, 0xE0, 0xD0)
00252     violet               = 0x00EE82EE,   // RGB(0xEE, 0x82, 0xEE)
00253     wheat                = 0x00F5DEB3,   // RGB(0xF5, 0xDE, 0xB3)
00254     white                = 0x00FFFFFF,   // RGB(0xFF, 0xFF, 0xFF)
00255     whitesmoke           = 0x00F5F5F5,   // RGB(0xF5, 0xF5, 0xF5)
00256     yellow               = 0x00FFFF00,   // RGB(0xFF, 0xFF, 0x00)
00257     yellowgreen          = 0x009ACD32    // RGB(0x9A, 0xCD, 0x32)
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   // RGB - Routinen
00340   // --------------
00341   void SetRed(int red);     // 0..255
00342   void SetGreen(int green); // 0..255
00343   void SetBlue(int blue);   // 0..255
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   // HLS - Routinen
00363   // --------------
00364   void SetHue(float hue);               // 0.0 .. 360.0
00365   void SetLuminance(float luminance);   // 0.0 .. 1.0
00366   void SetSaturation(float saturation); // 0.0 .. 1.0
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;          // String im Format RRGGBB
00395   bool    SetString(const char* pcColor); // String im Format RRGGBB
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   // Konvertierung
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   // Daten
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;         // 0.0 .. 360.0  // Winkel
00426   float m_saturation;  // 0.0 .. 1.0    // Prozent
00427   float m_luminance;   // 0.0 .. 1.0    // Prozent
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 

Generated on Wed Feb 9 11:31:35 2005 for OpenGUI by  doxygen 1.4.0