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 © 2000-2002 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 unsigned long RGBA; 00033 typedef unsigned long ARGB; 00034 typedef unsigned long 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 ColourValue( Real red = 1.0f, 00057 Real green = 1.0f, 00058 Real blue = 1.0f, 00059 Real 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 Real r,g,b,a; 00068 }; 00069 Real val[4]; 00070 }; 00071 00074 RGBA getAsLongRGBA(void) const; 00075 00078 ARGB getAsLongARGB(void) const; 00079 00081 ABGR getAsLongABGR(void) const; 00082 00083 // arithmetic operations 00084 inline ColourValue operator + ( const ColourValue& rkVector ) const 00085 { 00086 ColourValue kSum; 00087 00088 kSum.r = r + rkVector.r; 00089 kSum.g = g + rkVector.g; 00090 kSum.b = b + rkVector.b; 00091 kSum.a = a + rkVector.a; 00092 00093 return kSum; 00094 } 00095 00096 inline ColourValue operator - ( const ColourValue& rkVector ) const 00097 { 00098 ColourValue kDiff; 00099 00100 kDiff.r = r - rkVector.r; 00101 kDiff.g = g - rkVector.g; 00102 kDiff.b = b - rkVector.b; 00103 kDiff.a = a - rkVector.a; 00104 00105 return kDiff; 00106 } 00107 00108 inline ColourValue operator * ( Real fScalar ) const 00109 { 00110 ColourValue kProd; 00111 00112 kProd.r = fScalar*r; 00113 kProd.g = fScalar*g; 00114 kProd.b = fScalar*b; 00115 kProd.a = fScalar*a; 00116 00117 return kProd; 00118 } 00119 00120 inline ColourValue operator * ( const ColourValue& rhs) const 00121 { 00122 ColourValue kProd; 00123 00124 kProd.r = rhs.r * r; 00125 kProd.g = rhs.g * g; 00126 kProd.b = rhs.b * b; 00127 kProd.a = rhs.a * 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 / ( Real fScalar ) const 00145 { 00146 assert( fScalar != 0.0 ); 00147 00148 ColourValue kDiv; 00149 00150 Real fInv = 1.0 / fScalar; 00151 kDiv.r = r * fInv; 00152 kDiv.g = g * fInv; 00153 kDiv.b = b * fInv; 00154 kDiv.a = a * fInv; 00155 00156 return kDiv; 00157 } 00158 00159 inline friend ColourValue operator * ( Real fScalar, const ColourValue& rkVector ) 00160 { 00161 ColourValue kProd; 00162 00163 kProd.r = fScalar * rkVector.r; 00164 kProd.g = fScalar * rkVector.g; 00165 kProd.b = fScalar * rkVector.b; 00166 kProd.a = fScalar * rkVector.a; 00167 00168 return kProd; 00169 } 00170 00171 // arithmetic updates 00172 inline ColourValue& operator += ( const ColourValue& rkVector ) 00173 { 00174 r += rkVector.r; 00175 g += rkVector.g; 00176 b += rkVector.b; 00177 a += rkVector.a; 00178 00179 return *this; 00180 } 00181 00182 inline ColourValue& operator -= ( const ColourValue& rkVector ) 00183 { 00184 r -= rkVector.r; 00185 g -= rkVector.g; 00186 b -= rkVector.b; 00187 a -= rkVector.a; 00188 00189 return *this; 00190 } 00191 00192 inline ColourValue& operator *= ( Real fScalar ) 00193 { 00194 r *= fScalar; 00195 g *= fScalar; 00196 b *= fScalar; 00197 a *= fScalar; 00198 return *this; 00199 } 00200 00201 inline ColourValue& operator /= ( Real fScalar ) 00202 { 00203 assert( fScalar != 0.0 ); 00204 00205 Real fInv = 1.0 / fScalar; 00206 00207 r *= fInv; 00208 g *= fInv; 00209 b *= fInv; 00210 a *= fInv; 00211 00212 return *this; 00213 } 00214 00215 00216 }; 00217 00218 } // namespace 00219 00220 #endif
Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:17 2004