• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

Color.hpp

Go to the documentation of this file.
00001 
00002 
00003 
00004 #ifndef GOSU_COLOR_HPP
00005 #define GOSU_COLOR_HPP
00006 
00007 #include <boost/cstdint.hpp>
00008 
00009 namespace Gosu
00010 {
00014     class Color
00015     {
00016         boost::uint32_t rep;
00017 
00018     public:
00019         typedef boost::uint8_t Channel;
00020 
00022         Color()
00023         {
00024         }
00025 
00028         Color(boost::uint32_t argb)
00029         : rep(argb)
00030         {
00031         }
00032 
00033         Color(Channel red, Channel green, Channel blue)
00034         {
00035             rep = (0xff << 24) | (red << 16) | (green << 8) | blue;
00036         }
00037 
00038         Color(Channel alpha, Channel red, Channel green, Channel blue)
00039         {
00040             rep = (alpha << 24) | (red << 16) | (green << 8) | blue;
00041         }
00042         
00047         static Color fromHSV(double h, double s, double v);
00048         static Color fromAHSV(Channel alpha, double h, double s, double v);
00049 
00050         Channel alpha() const
00051         {
00052             return static_cast<Channel>((rep >> 24) & 0xff);
00053         }
00054 
00055         Channel red() const
00056         {
00057             return static_cast<Channel>((rep >> 16) & 0xff);
00058         }
00059 
00060         Channel green() const
00061         {
00062             return static_cast<Channel>((rep >> 8) & 0xff);
00063         }
00064 
00065         Channel blue() const
00066         {
00067             return static_cast<Channel>(rep & 0xff);
00068         }
00069 
00070         void setAlpha(Channel value)
00071         {
00072             rep &= 0x00ffffff;
00073             rep |= value << 24;
00074         }
00075 
00076         void setRed(Channel value)
00077         {
00078             rep &= 0xff00ffff;
00079             rep |= value << 16;
00080         }
00081 
00082         void setGreen(Channel value)
00083         {
00084             rep &= 0xffff00ff;
00085             rep |= value << 8;
00086         }
00087 
00088         void setBlue(Channel value)
00089         {
00090             rep &= 0xffffff00;
00091             rep |= value;
00092         }
00093 
00095         double hue() const;
00096         
00098         void setHue(double h);
00099         
00101         double saturation() const;
00102         
00104         void setSaturation(double s);
00105         
00107         double value() const;
00108         
00110         void setValue(double v);
00111 
00113         boost::uint32_t argb() const
00114         {
00115             return rep;
00116         }
00117 
00119         boost::uint32_t bgr() const
00120         {
00121             return red() | (rep & 0x0000ff00) | blue() << 16;
00122         }
00123 
00125         boost::uint32_t abgr() const
00126         {
00127             return alpha() << 24 | bgr();
00128         }
00129         
00130         static const Color NONE;
00131         static const Color BLACK;
00132         static const Color GRAY;
00133         static const Color WHITE;
00134         
00135         static const Color AQUA;
00136         static const Color RED;
00137         static const Color GREEN;
00138         static const Color BLUE;
00139         static const Color YELLOW;
00140         static const Color FUCHSIA;
00141         static const Color CYAN;
00142     };
00143     
00144     // Causes weird errors when included in the SWIG wrapping process.
00145     // If, with a future version of SWIG, this can be included and
00146     // require 'gosu'; include Gosu
00147     // works from within Ruby, the #ifndef guard can be removed.
00148     #ifndef SWIG
00149     inline bool operator<(Color a, Color b)
00150     {
00151         return a.argb() < b.argb();
00152     }
00153     
00154     inline bool operator==(Color a, Color b)
00155     {
00156         return a.argb() == b.argb();
00157     }
00158 
00159     inline bool operator!=(Color a, Color b)
00160     {
00161         return a.argb() != b.argb();
00162     }
00163     #endif
00164 
00168     Color interpolate(Color a, Color b, double weight = 0.5);
00169     
00172     Color multiply(Color a, Color b);
00173 
00174     // Deprecated
00175     namespace Colors
00176     {
00177         const Color none    = 0x00000000;
00178         const Color black   = 0xff000000;
00179         const Color gray    = 0xff808080;
00180         const Color white   = 0xffffffff;
00181         
00182         const Color aqua    = 0xff00ffff;
00183         const Color red     = 0xffff0000;
00184         const Color green   = 0xff00ff00;
00185         const Color blue    = 0xff0000ff;
00186         const Color yellow  = 0xffffff00;
00187         const Color fuchsia = 0xffff00ff;
00188         const Color cyan    = 0xff00ffff;
00189     }
00190 }
00191 
00192 #endif

Documentation not clear enough? Please go to one of the places listed on http://www.libgosu.org/ and leave feedback. Thanks!