- Main Page
- Namespaces
- Classes
- Files
- Directories
- 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-2006 Torus Knot Software Ltd
    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 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef _COLOURVALUE_H__
    00030 #define _COLOURVALUE_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033
    00034 namespace Ogre {
    00035
    00036     typedef uint32 RGBA;
    00037     typedef uint32 ARGB;
    00038     typedef uint32 ABGR;
    00039     typedef uint32 BGRA;
    00040
    00052     class _OgreExport ColourValue
    00053     {
    00054     public:
    00055         static const ColourValue ZERO;
    00056         static const ColourValue Black;
    00057         static const ColourValue White;
    00058         static const ColourValue Red;
    00059         static const ColourValue Green;
    00060         static const ColourValue Blue;
    00061
    00062         explicit ColourValue( float red = 1.0f,
    00063                     float green = 1.0f,
    00064                     float blue = 1.0f,
    00065                     float alpha = 1.0f ) : r(red), g(green), b(blue), a(alpha)
    00066         { }
    00067
    00068         bool operator==(const ColourValue& rhs) const;
    00069         bool operator!=(const ColourValue& rhs) const;
    00070
    00071         float r,g,b,a;
    00072
    00075         RGBA getAsRGBA(void) const;
    00076
    00079         ARGB getAsARGB(void) const;
    00080
    00083         BGRA getAsBGRA(void) const;
    00084
    00086         ABGR getAsABGR(void) const;
    00087
    00090         void setAsRGBA(const RGBA val);
    00091
    00094         void setAsARGB(const ARGB val);
    00095
    00098         void setAsBGRA(const BGRA val);
    00099
    00102         void setAsABGR(const ABGR val);
    00103
    00106         void saturate(void)
    00107         {
    00108             if (r < 0)
    00109                 r = 0;
    00110             else if (r > 1)
    00111                 r = 1;
    00112
    00113             if (g < 0)
    00114                 g = 0;
    00115             else if (g > 1)
    00116                 g = 1;
    00117
    00118             if (b < 0)
    00119                 b = 0;
    00120             else if (b > 1)
    00121                 b = 1;
    00122
    00123             if (a < 0)
    00124                 a = 0;
    00125             else if (a > 1)
    00126                 a = 1;
    00127         }
    00128
    00131         ColourValue saturateCopy(void) const
    00132         {
    00133             ColourValue ret = *this;
    00134             ret.saturate();
    00135             return ret;
    00136         }
    00137
    00139         inline float operator [] ( const size_t i ) const
    00140         {
    00141             assert( i < 4 );
    00142
    00143             return *(&r+i);
    00144         }
    00145
    00147         inline float& operator [] ( const size_t i )
    00148         {
    00149             assert( i < 4 );
    00150
    00151             return *(&r+i);
    00152         }
    00153
    00155         inline float* ptr()
    00156         {
    00157             return &r;
    00158         }
    00160         inline const float* ptr() const
    00161         {
    00162             return &r;
    00163         }
    00164
    00165
    00166         // arithmetic operations
    00167         inline ColourValue operator + ( const ColourValue& rkVector ) const
    00168         {
    00169             ColourValue kSum;
    00170
    00171             kSum.r = r + rkVector.r;
    00172             kSum.g = g + rkVector.g;
    00173             kSum.b = b + rkVector.b;
    00174             kSum.a = a + rkVector.a;
    00175
    00176             return kSum;
    00177         }
    00178
    00179         inline ColourValue operator - ( const ColourValue& rkVector ) const
    00180         {
    00181             ColourValue kDiff;
    00182
    00183             kDiff.r = r - rkVector.r;
    00184             kDiff.g = g - rkVector.g;
    00185             kDiff.b = b - rkVector.b;
    00186             kDiff.a = a - rkVector.a;
    00187
    00188             return kDiff;
    00189         }
    00190
    00191         inline ColourValue operator * (const float fScalar ) const
    00192         {
    00193             ColourValue kProd;
    00194
    00195             kProd.r = fScalar*r;
    00196             kProd.g = fScalar*g;
    00197             kProd.b = fScalar*b;
    00198             kProd.a = fScalar*a;
    00199
    00200             return kProd;
    00201         }
    00202
    00203         inline ColourValue operator * ( const ColourValue& rhs) const
    00204         {
    00205             ColourValue kProd;
    00206
    00207             kProd.r = rhs.r * r;
    00208             kProd.g = rhs.g * g;
    00209             kProd.b = rhs.b * b;
    00210             kProd.a = rhs.a * a;
    00211
    00212             return kProd;
    00213         }
    00214
    00215         inline ColourValue operator / ( const ColourValue& rhs) const
    00216         {
    00217             ColourValue kProd;
    00218
    00219             kProd.r = rhs.r / r;
    00220             kProd.g = rhs.g / g;
    00221             kProd.b = rhs.b / b;
    00222             kProd.a = rhs.a / a;
    00223
    00224             return kProd;
    00225         }
    00226
    00227         inline ColourValue operator / (const float fScalar ) const
    00228         {
    00229             assert( fScalar != 0.0 );
    00230
    00231             ColourValue kDiv;
    00232
    00233             float fInv = 1.0 / fScalar;
    00234             kDiv.r = r * fInv;
    00235             kDiv.g = g * fInv;
    00236             kDiv.b = b * fInv;
    00237             kDiv.a = a * fInv;
    00238
    00239             return kDiv;
    00240         }
    00241
    00242         inline friend ColourValue operator * (const float fScalar, const ColourValue& rkVector )
    00243         {
    00244             ColourValue kProd;
    00245
    00246             kProd.r = fScalar * rkVector.r;
    00247             kProd.g = fScalar * rkVector.g;
    00248             kProd.b = fScalar * rkVector.b;
    00249             kProd.a = fScalar * rkVector.a;
    00250
    00251             return kProd;
    00252         }
    00253
    00254         // arithmetic updates
    00255         inline ColourValue& operator += ( const ColourValue& rkVector )
    00256         {
    00257             r += rkVector.r;
    00258             g += rkVector.g;
    00259             b += rkVector.b;
    00260             a += rkVector.a;
    00261
    00262             return *this;
    00263         }
    00264
    00265         inline ColourValue& operator -= ( const ColourValue& rkVector )
    00266         {
    00267             r -= rkVector.r;
    00268             g -= rkVector.g;
    00269             b -= rkVector.b;
    00270             a -= rkVector.a;
    00271
    00272             return *this;
    00273         }
    00274
    00275         inline ColourValue& operator *= (const float fScalar )
    00276         {
    00277             r *= fScalar;
    00278             g *= fScalar;
    00279             b *= fScalar;
    00280             a *= fScalar;
    00281             return *this;
    00282         }
    00283
    00284         inline ColourValue& operator /= (const float fScalar )
    00285         {
    00286             assert( fScalar != 0.0 );
    00287
    00288             float fInv = 1.0 / fScalar;
    00289
    00290             r *= fInv;
    00291             g *= fInv;
    00292             b *= fInv;
    00293             a *= fInv;
    00294
    00295             return *this;
    00296         }
    00297
    00303         void setHSB(Real hue, Real saturation, Real brightness);
    00304
    00305
    00308         inline _OgreExport friend std::ostream& operator <<
    00309             ( std::ostream& o, const ColourValue& c )
    00310         {
    00311             o << "ColourValue(" << c.r << ", " << c.g << ", " << c.b << ", " << c.a << ")";
    00312             return o;
    00313         }
    00314
    00315     };
    00316
    00317 } // namespace
    00318
    00319 #endif

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Mon Jun 16 12:48:49 2008