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 00131 // Causes weird errors when included in the SWIG wrapping process. 00132 // If, with a future version of SWIG, this can be included and 00133 // require 'gosu'; include Gosu 00134 // works from within Ruby, the #ifndef guard can be removed. 00135 #ifndef SWIG 00136 inline bool operator==(Color a, Color b) 00137 { 00138 return a.argb() == b.argb(); 00139 } 00140 00141 inline bool operator!=(Color a, Color b) 00142 { 00143 return a.argb() != b.argb(); 00144 } 00145 #endif 00146 00150 Color interpolate(Color a, Color b, double weight = 0.5); 00151 00154 Color multiply(Color a, Color b); 00155 00157 namespace Colors 00158 { 00159 const Color none = 0x00000000; 00160 const Color black = 0xff000000; 00161 const Color gray = 0xff808080; 00162 const Color white = 0xffffffff; 00163 const Color red = 0xffff0000; 00164 const Color green = 0xff00ff00; 00165 const Color blue = 0xff0000ff; 00166 const Color yellow = 0xffffff00; 00167 const Color fuchsia = 0xffff00ff; 00168 const Color cyan = 0xff00ffff; 00169 } 00170 } 00171 00172 #endif
Documentation not clear enough? Please go to one of the places listed on http://www.libgosu.org/ and leave feedback. Thanks!