faithcore/faith/color.h

Go to the documentation of this file.
00001 #ifndef KDE__COLOR_H
00002 #define KDE__COLOR_H
00003 
00004 #include <faith/image.h>
00005 #include <faith/tools.h>
00006 #include <faith/core.h>
00007 #include <faith/core.h>
00008 #ifdef WIN32
00009 #include <windows.h>
00010 #endif
00011 
00012 namespace Faith
00013 {
00014 
00015 
00021 class FAITH_CORE_EXPORT Color
00022 {
00023 #ifdef WIN32
00024         COLORREF color;
00025 #else
00026         static int depth;
00027         static int cmapSize;
00028 
00029         static void (Color::*allocator)() const;
00030 
00031 
00032         enum State
00033         {
00034                 Invalid,
00035                 Valid,
00036                 Allocated
00037         };
00038 
00039         mutable State mState;
00040 
00044         Faith::Rgb color;
00045 
00051         mutable unsigned int pix;
00052 #endif
00053 public:
00057         enum Spec {Rgb, Hsv};
00058 
00062         Color();
00063 
00071         Color(int r, int g, int b);
00072 
00081         Color(int x, int y, int z, Spec colorSpec);
00082 
00090         Color(Faith::Rgb rgb, unsigned int pixel = 0xffffffff);
00091 
00095         Color(const Color &col);
00096 
00097 
00101         Color &operator = (const Color &col);
00102 
00103 
00109 /*
00110 */
00118         inline void rgb(int *red, int *green, int *blue) const
00119         {
00120 #ifdef WIN32
00121                 *red = GetRValue(color);
00122                 *green = GetGValue(color);
00123                 *red = GetRValue(color);
00124 #else
00125                 *red = qRed(color);
00126                 *green = qGreen(color);
00127                 *blue = qBlue(color);
00128 #endif
00129         }
00130 
00136         inline Faith::Rgb rgb() const
00137         {
00138                 return (Faith::Rgb)color;
00139         }
00140 
00148         inline void setRgb(int red, int green, int blue)
00149         {
00150                 setRgb(qRgb(red, green, blue));
00151         }
00152 
00158         void setRgb(Faith::Rgb rgb);
00159 
00165         inline int red() const
00166         {
00167 #ifdef WIN32
00168                 return GetRValue(color);
00169 #else
00170                 return qRed(color);
00171 #endif
00172         }
00173 
00179         inline int green() const
00180         {
00181 #ifdef WIN32
00182                 return GetGValue(color);
00183 #else
00184                 return qGreen(color);
00185 #endif
00186         }
00187 
00194         inline int blue() const
00195         {
00196 #ifdef WIN32
00197                 return GetBValue(color);
00198 #else
00199                 return qBlue(color);
00200 #endif
00201         }
00202 
00210         void hsv(int *hue, int *sat, int *value) const;
00211 
00212 
00220         void setHsv(int hue, int sat, int value);
00221 
00228         inline Color light(int f = 150) const
00229         {
00230                 int h, s, v;
00231                 hsv(&h, &s, &v);
00232                 return Color(h, s, v*f / 100, Hsv);
00233         }
00234 
00241         inline Color dark(int f = 200) const
00242         {
00243                 int h, s, v;
00244                 hsv(&h, &s, &v);
00245                 return Color(h, s, v*100 / f, Hsv);
00246         }
00247 
00253         bool operator == (const Color & c) const;
00254 
00260         inline bool operator!=(const Color & c) const
00261         {
00262                 return !operator==(c);
00263         }
00264 
00270 #ifdef WIN32
00271         inline COLORREF pixel() const
00272         {
00273                 return color;   
00274         }
00275 #else
00276         inline unsigned int pixel() const
00277         {
00278                 alloc();
00279                 return pix;
00280         }
00281 #endif
00282 
00287         static void initialize();
00288 
00293         static void cleanup();
00294 
00295 private:
00296 #ifndef WIN32
00297 
00300         enum { INVALID = 1, UNALLOCATED = 2, FIXED = 4 };
00301 
00302 
00306         void truecolor24_alloc() const;
00307         void truecolor16_alloc() const;
00308 
00315         void truecolor_copy(const Color &col, bool del) const;
00316 
00320         void truecolor_dealloc() const;
00321 
00322         void alloc() const;
00323         inline bool isDirty() const
00324         {
00325                 return mState <= Valid;
00326         }
00327         
00333         inline bool isValid() const
00334         {
00335                 return mState >= Valid;
00336         }
00337         
00338 #endif
00339 };
00340 
00344 extern Color black, white, darkGray, gray, lightGray, red, green, blue, cyan;
00345 extern Color magenta, yellow, darkRed, darkGreen, darkBlue, darkCyan, darkMagenta;
00346 extern Color darkYellow, color0, color1;
00347 
00348 }
00349 
00350 #endif
00351 

Generated on Fri Sep 1 00:23:07 2006 for Faith by  doxygen 1.4.7