Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

OgreColourValue.h

Go to the documentation of this file.
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     typedef uint32 BGRA;
00036 
00048     class _OgreExport ColourValue
00049     {
00050     public:
00051         static const ColourValue ZERO;
00052         static const ColourValue Black;
00053         static const ColourValue White;
00054         static const ColourValue Red;
00055         static const ColourValue Green;
00056         static const ColourValue Blue;
00057 
00058         explicit ColourValue( float red = 1.0f,
00059                     float green = 1.0f,
00060                     float blue = 1.0f,
00061                     float alpha = 1.0f ) : r(red), g(green), b(blue), a(alpha)
00062         { }
00063 
00064         bool operator==(const ColourValue& rhs) const;
00065         bool operator!=(const ColourValue& rhs) const;
00066 
00067         union {
00068             struct {
00069                 float r,g,b,a;
00070             };
00071             float val[4];
00072         };
00073 
00076         RGBA getAsRGBA(void) const;
00077 
00080         ARGB getAsARGB(void) const;
00081 
00084         BGRA getAsBGRA(void) const;
00085 
00087         ABGR getAsABGR(void) const;
00088 
00091         void setAsRGBA(const RGBA val);
00092 
00095         void setAsARGB(const ARGB val);
00096 
00099         void setAsBGRA(const BGRA val);
00100 
00103         void setAsABGR(const ABGR val);
00104 
00107         void saturate(void)
00108         {
00109             if (r < 0)
00110                 r = 0;
00111             else if (r > 1)
00112                 r = 1;
00113 
00114             if (g < 0)
00115                 g = 0;
00116             else if (g > 1)
00117                 g = 1;
00118 
00119             if (b < 0)
00120                 b = 0;
00121             else if (b > 1)
00122                 b = 1;
00123 
00124             if (a < 0)
00125                 a = 0;
00126             else if (a > 1)
00127                 a = 1;
00128         }
00129 
00132         ColourValue saturateCopy(void) const
00133         {
00134             ColourValue ret = *this;
00135             ret.saturate();
00136             return ret;
00137         }
00138 
00139         // arithmetic operations
00140         inline ColourValue operator + ( const ColourValue& rkVector ) const
00141         {
00142             ColourValue kSum;
00143 
00144             kSum.r = r + rkVector.r;
00145             kSum.g = g + rkVector.g;
00146             kSum.b = b + rkVector.b;
00147             kSum.a = a + rkVector.a;
00148 
00149             return kSum;
00150         }
00151 
00152         inline ColourValue operator - ( const ColourValue& rkVector ) const
00153         {
00154             ColourValue kDiff;
00155 
00156             kDiff.r = r - rkVector.r;
00157             kDiff.g = g - rkVector.g;
00158             kDiff.b = b - rkVector.b;
00159             kDiff.a = a - rkVector.a;
00160 
00161             return kDiff;
00162         }
00163 
00164         inline ColourValue operator * (const float fScalar ) const
00165         {
00166             ColourValue kProd;
00167 
00168             kProd.r = fScalar*r;
00169             kProd.g = fScalar*g;
00170             kProd.b = fScalar*b;
00171             kProd.a = fScalar*a;
00172 
00173             return kProd;
00174         }
00175 
00176         inline ColourValue operator * ( const ColourValue& rhs) const
00177         {
00178             ColourValue kProd;
00179 
00180             kProd.r = rhs.r * r;
00181             kProd.g = rhs.g * g;
00182             kProd.b = rhs.b * b;
00183             kProd.a = rhs.a * a;
00184 
00185             return kProd;
00186         }
00187 
00188         inline ColourValue operator / ( const ColourValue& rhs) const
00189         {
00190             ColourValue kProd;
00191 
00192             kProd.r = rhs.r / r;
00193             kProd.g = rhs.g / g;
00194             kProd.b = rhs.b / b;
00195             kProd.a = rhs.a / a;
00196 
00197             return kProd;
00198         }
00199 
00200         inline ColourValue operator / (const float fScalar ) const
00201         {
00202             assert( fScalar != 0.0 );
00203 
00204             ColourValue kDiv;
00205 
00206             float fInv = 1.0 / fScalar;
00207             kDiv.r = r * fInv;
00208             kDiv.g = g * fInv;
00209             kDiv.b = b * fInv;
00210             kDiv.a = a * fInv;
00211 
00212             return kDiv;
00213         }
00214 
00215         inline friend ColourValue operator * (const float fScalar, const ColourValue& rkVector )
00216         {
00217             ColourValue kProd;
00218 
00219             kProd.r = fScalar * rkVector.r;
00220             kProd.g = fScalar * rkVector.g;
00221             kProd.b = fScalar * rkVector.b;
00222             kProd.a = fScalar * rkVector.a;
00223 
00224             return kProd;
00225         }
00226 
00227         // arithmetic updates
00228         inline ColourValue& operator += ( const ColourValue& rkVector )
00229         {
00230             r += rkVector.r;
00231             g += rkVector.g;
00232             b += rkVector.b;
00233             a += rkVector.a;
00234 
00235             return *this;
00236         }
00237 
00238         inline ColourValue& operator -= ( const ColourValue& rkVector )
00239         {
00240             r -= rkVector.r;
00241             g -= rkVector.g;
00242             b -= rkVector.b;
00243             a -= rkVector.a;
00244 
00245             return *this;
00246         }
00247 
00248         inline ColourValue& operator *= (const float fScalar )
00249         {
00250             r *= fScalar;
00251             g *= fScalar;
00252             b *= fScalar;
00253             a *= fScalar;
00254             return *this;
00255         }
00256 
00257         inline ColourValue& operator /= (const float fScalar )
00258         {
00259             assert( fScalar != 0.0 );
00260 
00261             float fInv = 1.0 / fScalar;
00262 
00263             r *= fInv;
00264             g *= fInv;
00265             b *= fInv;
00266             a *= fInv;
00267 
00268             return *this;
00269         }
00270 
00276         void setHSB(Real hue, Real saturation, Real brightness);
00277 
00278 
00281         inline _OgreExport friend std::ostream& operator <<
00282             ( std::ostream& o, const ColourValue& c )
00283         {
00284             o << "ColourValue(" << c.r << ", " << c.g << ", " << c.b << ", " << c.a << ")";
00285             return o;
00286         }
00287 
00288     };
00289 
00290 } // namespace
00291 
00292 #endif

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 12 14:37:38 2006