00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright (c) 2000-2005 The OGRE Team 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 #ifndef _COLOURVALUE_H__ 00026 #define _COLOURVALUE_H__ 00027 00028 #include "OgrePrerequisites.h" 00029 00030 namespace Ogre { 00031 00032 typedef uint32 RGBA; 00033 typedef uint32 ARGB; 00034 typedef uint32 ABGR; 00035 00047 class _OgreExport ColourValue 00048 { 00049 public: 00050 static ColourValue Black; 00051 static ColourValue White; 00052 static ColourValue Red; 00053 static ColourValue Green; 00054 static ColourValue Blue; 00055 00056 explicit ColourValue( float red = 1.0f, 00057 float green = 1.0f, 00058 float blue = 1.0f, 00059 float alpha = 1.0f ) : r(red), g(green), b(blue), a(alpha) 00060 { } 00061 00062 bool operator==(const ColourValue& rhs) const; 00063 bool operator!=(const ColourValue& rhs) const; 00064 00065 union { 00066 struct { 00067 float r,g,b,a; 00068 }; 00069 float val[4]; 00070 }; 00071 00074 RGBA getAsRGBA(void) const; 00075 00078 ARGB getAsARGB(void) const; 00079 00081 ABGR getAsABGR(void) const; 00082 00085 void setAsRGBA(const RGBA val); 00086 00089 void setAsARGB(const ARGB val); 00090 00093 void setAsABGR(const ABGR val); 00094 00095 // arithmetic operations 00096 inline ColourValue operator + ( const ColourValue& rkVector ) const 00097 { 00098 ColourValue kSum; 00099 00100 kSum.r = r + rkVector.r; 00101 kSum.g = g + rkVector.g; 00102 kSum.b = b + rkVector.b; 00103 kSum.a = a + rkVector.a; 00104 00105 return kSum; 00106 } 00107 00108 inline ColourValue operator - ( const ColourValue& rkVector ) const 00109 { 00110 ColourValue kDiff; 00111 00112 kDiff.r = r - rkVector.r; 00113 kDiff.g = g - rkVector.g; 00114 kDiff.b = b - rkVector.b; 00115 kDiff.a = a - rkVector.a; 00116 00117 return kDiff; 00118 } 00119 00120 inline ColourValue operator * (const float fScalar ) const 00121 { 00122 ColourValue kProd; 00123 00124 kProd.r = fScalar*r; 00125 kProd.g = fScalar*g; 00126 kProd.b = fScalar*b; 00127 kProd.a = fScalar*a; 00128 00129 return kProd; 00130 } 00131 00132 inline ColourValue operator * ( const ColourValue& rhs) const 00133 { 00134 ColourValue kProd; 00135 00136 kProd.r = rhs.r * r; 00137 kProd.g = rhs.g * g; 00138 kProd.b = rhs.b * b; 00139 kProd.a = rhs.a * a; 00140 00141 return kProd; 00142 } 00143 00144 inline ColourValue operator / ( const ColourValue& rhs) const 00145 { 00146 ColourValue kProd; 00147 00148 kProd.r = rhs.r / r; 00149 kProd.g = rhs.g / g; 00150 kProd.b = rhs.b / b; 00151 kProd.a = rhs.a / a; 00152 00153 return kProd; 00154 } 00155 00156 inline ColourValue operator / (const float fScalar ) const 00157 { 00158 assert( fScalar != 0.0 ); 00159 00160 ColourValue kDiv; 00161 00162 float fInv = 1.0 / fScalar; 00163 kDiv.r = r * fInv; 00164 kDiv.g = g * fInv; 00165 kDiv.b = b * fInv; 00166 kDiv.a = a * fInv; 00167 00168 return kDiv; 00169 } 00170 00171 inline friend ColourValue operator * (const float fScalar, const ColourValue& rkVector ) 00172 { 00173 ColourValue kProd; 00174 00175 kProd.r = fScalar * rkVector.r; 00176 kProd.g = fScalar * rkVector.g; 00177 kProd.b = fScalar * rkVector.b; 00178 kProd.a = fScalar * rkVector.a; 00179 00180 return kProd; 00181 } 00182 00183 // arithmetic updates 00184 inline ColourValue& operator += ( const ColourValue& rkVector ) 00185 { 00186 r += rkVector.r; 00187 g += rkVector.g; 00188 b += rkVector.b; 00189 a += rkVector.a; 00190 00191 return *this; 00192 } 00193 00194 inline ColourValue& operator -= ( const ColourValue& rkVector ) 00195 { 00196 r -= rkVector.r; 00197 g -= rkVector.g; 00198 b -= rkVector.b; 00199 a -= rkVector.a; 00200 00201 return *this; 00202 } 00203 00204 inline ColourValue& operator *= (const float fScalar ) 00205 { 00206 r *= fScalar; 00207 g *= fScalar; 00208 b *= fScalar; 00209 a *= fScalar; 00210 return *this; 00211 } 00212 00213 inline ColourValue& operator /= (const float fScalar ) 00214 { 00215 assert( fScalar != 0.0 ); 00216 00217 float fInv = 1.0 / fScalar; 00218 00219 r *= fInv; 00220 g *= fInv; 00221 b *= fInv; 00222 a *= fInv; 00223 00224 return *this; 00225 } 00226 00227 00228 }; 00229 00230 } // namespace 00231 00232 #endif
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Feb 12 12:59:42 2006