[657] | 1 | /*
|
---|
| 2 | -----------------------------------------------------------------------------
|
---|
| 3 | This source file is part of OGRE
|
---|
| 4 | (Object-oriented Graphics Rendering Engine)
|
---|
| 5 | For the latest info, see http://www.ogre3d.org/
|
---|
| 6 |
|
---|
| 7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | This program is free software; you can redistribute it and/or modify it under
|
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
| 13 | version.
|
---|
| 14 |
|
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
| 18 |
|
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
| 23 | -----------------------------------------------------------------------------
|
---|
| 24 | */
|
---|
| 25 | #ifndef _COLOURVALUE_H__
|
---|
| 26 | #define _COLOURVALUE_H__
|
---|
| 27 |
|
---|
| 28 | #include "OgrePrerequisites.h"
|
---|
| 29 |
|
---|
| 30 | namespace Ogre {
|
---|
| 31 |
|
---|
| 32 | typedef uint32 RGBA;
|
---|
| 33 | typedef uint32 ARGB;
|
---|
| 34 | typedef uint32 ABGR;
|
---|
| 35 |
|
---|
| 36 | /** Class representing colour.
|
---|
| 37 | @remarks
|
---|
| 38 | Colour is represented as 4 components, each of which is a
|
---|
| 39 | floating-point value from 0.0 to 1.0.
|
---|
| 40 | @par
|
---|
| 41 | The 3 'normal' colour components are red, green and blue, a higher
|
---|
| 42 | number indicating greater amounts of that component in the colour.
|
---|
| 43 | The forth component is the 'alpha' value, which represents
|
---|
| 44 | transparency. In this case, 0.0 is completely transparent and 1.0 is
|
---|
| 45 | fully opaque.
|
---|
| 46 | */
|
---|
| 47 | class _OgreExport ColourValue
|
---|
| 48 | {
|
---|
| 49 | public:
|
---|
| 50 | static ColourValue Black;
|
---|
| 51 | static ColourValue White;
|
---|
| 52 | static ColourValue Red;
|
---|
| 53 | static ColourValue Green;
|
---|
| 54 | static ColourValue Blue;
|
---|
| 55 |
|
---|
| 56 | explicit ColourValue( float red = 1.0f,
|
---|
| 57 | float green = 1.0f,
|
---|
| 58 | float blue = 1.0f,
|
---|
| 59 | float alpha = 1.0f ) : r(red), g(green), b(blue), a(alpha)
|
---|
| 60 | { }
|
---|
| 61 |
|
---|
| 62 | bool operator==(const ColourValue& rhs) const;
|
---|
| 63 | bool operator!=(const ColourValue& rhs) const;
|
---|
| 64 |
|
---|
| 65 | union {
|
---|
| 66 | struct {
|
---|
| 67 | float r,g,b,a;
|
---|
| 68 | };
|
---|
| 69 | float val[4];
|
---|
| 70 | };
|
---|
| 71 |
|
---|
| 72 | /** Retrieves colour as RGBA.
|
---|
| 73 | */
|
---|
| 74 | RGBA getAsRGBA(void) const;
|
---|
| 75 |
|
---|
| 76 | /** Retrieves colour as ARGB.
|
---|
| 77 | */
|
---|
| 78 | ARGB getAsARGB(void) const;
|
---|
| 79 |
|
---|
| 80 | /** Retrieves colours as ABGR */
|
---|
| 81 | ABGR getAsABGR(void) const;
|
---|
| 82 |
|
---|
| 83 | /** Sets colour as RGBA.
|
---|
| 84 | */
|
---|
| 85 | void setAsRGBA(const RGBA val);
|
---|
| 86 |
|
---|
| 87 | /** Sets colour as ARGB.
|
---|
| 88 | */
|
---|
| 89 | void setAsARGB(const ARGB val);
|
---|
| 90 |
|
---|
| 91 | /** Sets colour as ABGR.
|
---|
| 92 | */
|
---|
| 93 | void setAsABGR(const ABGR val);
|
---|
| 94 |
|
---|
| 95 | // arithmetic operations
|
---|
| 96 | inline ColourValue operator + ( const ColourValue& rkVector ) const
|
---|
| 97 | {
|
---|
| 98 | ColourValue kSum;
|
---|
| 99 |
|
---|
| 100 | kSum.r = r + rkVector.r;
|
---|
| 101 | kSum.g = g + rkVector.g;
|
---|
| 102 | kSum.b = b + rkVector.b;
|
---|
| 103 | kSum.a = a + rkVector.a;
|
---|
| 104 |
|
---|
| 105 | return kSum;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | inline ColourValue operator - ( const ColourValue& rkVector ) const
|
---|
| 109 | {
|
---|
| 110 | ColourValue kDiff;
|
---|
| 111 |
|
---|
| 112 | kDiff.r = r - rkVector.r;
|
---|
| 113 | kDiff.g = g - rkVector.g;
|
---|
| 114 | kDiff.b = b - rkVector.b;
|
---|
| 115 | kDiff.a = a - rkVector.a;
|
---|
| 116 |
|
---|
| 117 | return kDiff;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | inline ColourValue operator * (const float fScalar ) const
|
---|
| 121 | {
|
---|
| 122 | ColourValue kProd;
|
---|
| 123 |
|
---|
| 124 | kProd.r = fScalar*r;
|
---|
| 125 | kProd.g = fScalar*g;
|
---|
| 126 | kProd.b = fScalar*b;
|
---|
| 127 | kProd.a = fScalar*a;
|
---|
| 128 |
|
---|
| 129 | return kProd;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | inline ColourValue operator * ( const ColourValue& rhs) const
|
---|
| 133 | {
|
---|
| 134 | ColourValue kProd;
|
---|
| 135 |
|
---|
| 136 | kProd.r = rhs.r * r;
|
---|
| 137 | kProd.g = rhs.g * g;
|
---|
| 138 | kProd.b = rhs.b * b;
|
---|
| 139 | kProd.a = rhs.a * a;
|
---|
| 140 |
|
---|
| 141 | return kProd;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | inline ColourValue operator / ( const ColourValue& rhs) const
|
---|
| 145 | {
|
---|
| 146 | ColourValue kProd;
|
---|
| 147 |
|
---|
| 148 | kProd.r = rhs.r / r;
|
---|
| 149 | kProd.g = rhs.g / g;
|
---|
| 150 | kProd.b = rhs.b / b;
|
---|
| 151 | kProd.a = rhs.a / a;
|
---|
| 152 |
|
---|
| 153 | return kProd;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | inline ColourValue operator / (const float fScalar ) const
|
---|
| 157 | {
|
---|
| 158 | assert( fScalar != 0.0 );
|
---|
| 159 |
|
---|
| 160 | ColourValue kDiv;
|
---|
| 161 |
|
---|
| 162 | float fInv = 1.0 / fScalar;
|
---|
| 163 | kDiv.r = r * fInv;
|
---|
| 164 | kDiv.g = g * fInv;
|
---|
| 165 | kDiv.b = b * fInv;
|
---|
| 166 | kDiv.a = a * fInv;
|
---|
| 167 |
|
---|
| 168 | return kDiv;
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | inline friend ColourValue operator * (const float fScalar, const ColourValue& rkVector )
|
---|
| 172 | {
|
---|
| 173 | ColourValue kProd;
|
---|
| 174 |
|
---|
| 175 | kProd.r = fScalar * rkVector.r;
|
---|
| 176 | kProd.g = fScalar * rkVector.g;
|
---|
| 177 | kProd.b = fScalar * rkVector.b;
|
---|
| 178 | kProd.a = fScalar * rkVector.a;
|
---|
| 179 |
|
---|
| 180 | return kProd;
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | // arithmetic updates
|
---|
| 184 | inline ColourValue& operator += ( const ColourValue& rkVector )
|
---|
| 185 | {
|
---|
| 186 | r += rkVector.r;
|
---|
| 187 | g += rkVector.g;
|
---|
| 188 | b += rkVector.b;
|
---|
| 189 | a += rkVector.a;
|
---|
| 190 |
|
---|
| 191 | return *this;
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | inline ColourValue& operator -= ( const ColourValue& rkVector )
|
---|
| 195 | {
|
---|
| 196 | r -= rkVector.r;
|
---|
| 197 | g -= rkVector.g;
|
---|
| 198 | b -= rkVector.b;
|
---|
| 199 | a -= rkVector.a;
|
---|
| 200 |
|
---|
| 201 | return *this;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | inline ColourValue& operator *= (const float fScalar )
|
---|
| 205 | {
|
---|
| 206 | r *= fScalar;
|
---|
| 207 | g *= fScalar;
|
---|
| 208 | b *= fScalar;
|
---|
| 209 | a *= fScalar;
|
---|
| 210 | return *this;
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | inline ColourValue& operator /= (const float fScalar )
|
---|
| 214 | {
|
---|
| 215 | assert( fScalar != 0.0 );
|
---|
| 216 |
|
---|
| 217 | float fInv = 1.0 / fScalar;
|
---|
| 218 |
|
---|
| 219 | r *= fInv;
|
---|
| 220 | g *= fInv;
|
---|
| 221 | b *= fInv;
|
---|
| 222 | a *= fInv;
|
---|
| 223 |
|
---|
| 224 | return *this;
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 |
|
---|
| 228 | };
|
---|
| 229 |
|
---|
| 230 | } // namespace
|
---|
| 231 |
|
---|
| 232 | #endif
|
---|