Crazy Eddie's GUI System
0.8.4
|
00001 /*********************************************************************** 00002 created: 20/8/2004 00003 author: Paul D Turner (with code from Jeff Leigh) 00004 00005 purpose: Defines interface to the colour class used to represent 00006 colour values within the system 00007 *************************************************************************/ 00008 /*************************************************************************** 00009 * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team 00010 * 00011 * Permission is hereby granted, free of charge, to any person obtaining 00012 * a copy of this software and associated documentation files (the 00013 * "Software"), to deal in the Software without restriction, including 00014 * without limitation the rights to use, copy, modify, merge, publish, 00015 * distribute, sublicense, and/or sell copies of the Software, and to 00016 * permit persons to whom the Software is furnished to do so, subject to 00017 * the following conditions: 00018 * 00019 * The above copyright notice and this permission notice shall be 00020 * included in all copies or substantial portions of the Software. 00021 * 00022 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00023 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00024 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00025 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 00026 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00027 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00028 * OTHER DEALINGS IN THE SOFTWARE. 00029 ***************************************************************************/ 00030 #ifndef _CEGUIColour_h_ 00031 #define _CEGUIColour_h_ 00032 00033 #include "CEGUI/Base.h" 00034 00035 // Start of CEGUI namespace section 00036 namespace CEGUI 00037 { 00038 typedef uint32 argb_t; 00039 00044 class CEGUIEXPORT Colour : 00045 public AllocatedObject<Colour> 00046 { 00047 public: 00048 /************************************************************************* 00049 Construction & Destruction 00050 *************************************************************************/ 00051 Colour(void); 00052 Colour(const Colour& val); 00053 Colour(float red, float green, float blue, float alpha = 1.0f); 00054 Colour(argb_t argb); 00055 00056 /************************************************************************* 00057 Accessors 00058 *************************************************************************/ 00059 argb_t getARGB(void) const 00060 { 00061 if (!d_argbValid) 00062 { 00063 d_argb = calculateARGB(); 00064 d_argbValid = true; 00065 } 00066 00067 return d_argb; 00068 } 00069 00070 float getAlpha(void) const {return d_alpha;} 00071 float getRed(void) const {return d_red;} 00072 float getGreen(void) const {return d_green;} 00073 float getBlue(void) const {return d_blue;} 00074 00075 float getHue(void) const; 00076 float getSaturation(void) const; 00077 float getLumination(void) const; 00078 00079 00080 /************************************************************************* 00081 Manipulators 00082 *************************************************************************/ 00083 void setARGB(argb_t argb); 00084 inline void setAlpha(float alpha) 00085 { 00086 d_argbValid = false; 00087 d_alpha = alpha; 00088 } 00089 00090 inline void setRed(float red) 00091 { 00092 d_argbValid = false; 00093 d_red = red; 00094 } 00095 00096 inline void setGreen(float green) 00097 { 00098 d_argbValid = false; 00099 d_green = green; 00100 } 00101 00102 inline void setBlue(float blue) 00103 { 00104 d_argbValid = false; 00105 d_blue = blue; 00106 } 00107 00108 inline void set(float red, float green, float blue, float alpha = 1.0f) 00109 { 00110 d_argbValid = false; 00111 d_alpha = alpha; 00112 d_red = red; 00113 d_green = green; 00114 d_blue = blue; 00115 } 00116 00117 inline void setRGB(float red, float green, float blue) 00118 { 00119 d_argbValid = false; 00120 d_red = red; 00121 d_green = green; 00122 d_blue = blue; 00123 } 00124 00125 inline void setRGB(const Colour& val) 00126 { 00127 d_red = val.d_red; 00128 d_green = val.d_green; 00129 d_blue = val.d_blue; 00130 if (d_argbValid) 00131 { 00132 d_argbValid = val.d_argbValid; 00133 if (d_argbValid) 00134 d_argb = (d_argb & 0xFF000000) | (val.d_argb & 0x00FFFFFF); 00135 } 00136 } 00137 00138 void setHSL(float hue, float saturation, float luminance, float alpha = 1.0f); 00139 00140 void invertColour(void); 00141 void invertColourWithAlpha(void); 00142 00143 /************************************************************************* 00144 Operators 00145 *************************************************************************/ 00146 inline Colour& operator=(argb_t val) 00147 { 00148 setARGB(val); 00149 return *this; 00150 } 00151 00152 inline Colour& operator=(const Colour& val) 00153 { 00154 d_alpha = val.d_alpha; 00155 d_red = val.d_red; 00156 d_green = val.d_green; 00157 d_blue = val.d_blue; 00158 d_argb = val.d_argb; 00159 d_argbValid = val.d_argbValid; 00160 00161 return *this; 00162 } 00163 00164 inline Colour& operator&=(argb_t val) 00165 { 00166 setARGB(getARGB() & val); 00167 return *this; 00168 } 00169 00170 inline Colour& operator&=(const Colour& val) 00171 { 00172 setARGB(getARGB() & val.getARGB()); 00173 return *this; 00174 } 00175 00176 inline Colour& operator|=(argb_t val) 00177 { 00178 setARGB(getARGB() | val); 00179 return *this; 00180 } 00181 00182 inline Colour& operator|=(const Colour& val) 00183 { 00184 setARGB(getARGB() | val.getARGB()); 00185 return *this; 00186 } 00187 00188 inline Colour& operator<<=(int val) 00189 { 00190 setARGB(getARGB() << val); 00191 return *this; 00192 } 00193 00194 inline Colour& operator>>=(int val) 00195 { 00196 setARGB(getARGB() >> val); 00197 return *this; 00198 } 00199 00200 inline Colour operator+(const Colour& val) const 00201 { 00202 return Colour( 00203 d_red + val.d_red, 00204 d_green + val.d_green, 00205 d_blue + val.d_blue, 00206 d_alpha + val.d_alpha 00207 ); 00208 } 00209 00210 inline Colour operator-(const Colour& val) const 00211 { 00212 return Colour( 00213 d_red - val.d_red, 00214 d_green - val.d_green, 00215 d_blue - val.d_blue, 00216 d_alpha - val.d_alpha 00217 ); 00218 } 00219 00220 inline Colour operator*(const float val) const 00221 { 00222 return Colour( 00223 d_red * val, 00224 d_green * val, 00225 d_blue * val, 00226 d_alpha * val 00227 ); 00228 } 00229 00230 inline Colour& operator*=(const Colour& val) 00231 { 00232 d_red *= val.d_red; 00233 d_blue *= val.d_blue; 00234 d_green *= val.d_green; 00235 d_alpha *= val.d_alpha; 00236 00237 d_argbValid = false; 00238 00239 return *this; 00240 } 00241 00242 /************************************************************************* 00243 Compare operators 00244 *************************************************************************/ 00245 inline bool operator==(const Colour& rhs) const 00246 { 00247 return d_red == rhs.d_red && 00248 d_green == rhs.d_green && 00249 d_blue == rhs.d_blue && 00250 d_alpha == rhs.d_alpha; 00251 } 00252 00253 inline bool operator!=(const Colour& rhs) const 00254 { 00255 return !(*this == rhs); 00256 } 00257 00258 // 00259 // Conversion operators 00260 // 00261 operator argb_t() const {return getARGB();} 00262 00263 private: 00264 /************************************************************************* 00265 Implementation Methods 00266 *************************************************************************/ 00271 argb_t calculateARGB(void) const; 00272 00273 /************************************************************************* 00274 Implementation Data 00275 *************************************************************************/ 00276 float d_alpha, d_red, d_green, d_blue; 00277 mutable argb_t d_argb; 00278 mutable bool d_argbValid; 00279 }; 00280 00281 } // End of CEGUI namespace section 00282 00283 00284 #endif // end of guard _CEGUIColour_h_