OgreColourValue.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef _COLOURVALUE_H__
#define _COLOURVALUE_H__
#include "OgrePrerequisites.h"
namespace Ogre {
typedef uint32 RGBA;
typedef uint32 ARGB;
typedef uint32 ABGR;
typedef uint32 BGRA;
class _OgreExport ColourValue
{
public:
static const ColourValue ZERO;
static const ColourValue Black;
static const ColourValue White;
static const ColourValue Red;
static const ColourValue Green;
static const ColourValue Blue;
explicit ColourValue( float red = 1.0f,
float green = 1.0f,
float blue = 1.0f,
float alpha = 1.0f ) : r(red), g(green), b(blue), a(alpha)
{ }
bool operator==(const ColourValue& rhs) const;
bool operator!=(const ColourValue& rhs) const;
float r,g,b,a;
RGBA getAsRGBA(void) const;
ARGB getAsARGB(void) const;
BGRA getAsBGRA(void) const;
ABGR getAsABGR(void) const;
void setAsRGBA(const RGBA val);
void setAsARGB(const ARGB val);
void setAsBGRA(const BGRA val);
void setAsABGR(const ABGR val);
void saturate(void)
{
if (r < 0)
r = 0;
else if (r > 1)
r = 1;
if (g < 0)
g = 0;
else if (g > 1)
g = 1;
if (b < 0)
b = 0;
else if (b > 1)
b = 1;
if (a < 0)
a = 0;
else if (a > 1)
a = 1;
}
ColourValue saturateCopy(void) const
{
ColourValue ret = *this;
ret.saturate();
return ret;
}
inline float operator [] ( const size_t i ) const
{
assert( i < 4 );
return *(&r+i);
}
inline float& operator [] ( const size_t i )
{
assert( i < 4 );
return *(&r+i);
}
inline float* ptr()
{
return &r;
}
inline const float* ptr() const
{
return &r;
}
// arithmetic operations
inline ColourValue operator + ( const ColourValue& rkVector ) const
{
ColourValue kSum;
kSum.r = r + rkVector.r;
kSum.g = g + rkVector.g;
kSum.b = b + rkVector.b;
kSum.a = a + rkVector.a;
return kSum;
}
inline ColourValue operator - ( const ColourValue& rkVector ) const
{
ColourValue kDiff;
kDiff.r = r - rkVector.r;
kDiff.g = g - rkVector.g;
kDiff.b = b - rkVector.b;
kDiff.a = a - rkVector.a;
return kDiff;
}
inline ColourValue operator * (const float fScalar ) const
{
ColourValue kProd;
kProd.r = fScalar*r;
kProd.g = fScalar*g;
kProd.b = fScalar*b;
kProd.a = fScalar*a;
return kProd;
}
inline ColourValue operator * ( const ColourValue& rhs) const
{
ColourValue kProd;
kProd.r = rhs.r * r;
kProd.g = rhs.g * g;
kProd.b = rhs.b * b;
kProd.a = rhs.a * a;
return kProd;
}
inline ColourValue operator / ( const ColourValue& rhs) const
{
ColourValue kProd;
kProd.r = r / rhs.r;
kProd.g = g / rhs.g;
kProd.b = b / rhs.b;
kProd.a = a / rhs.a;
return kProd;
}
inline ColourValue operator / (const float fScalar ) const
{
assert( fScalar != 0.0 );
ColourValue kDiv;
float fInv = 1.0f / fScalar;
kDiv.r = r * fInv;
kDiv.g = g * fInv;
kDiv.b = b * fInv;
kDiv.a = a * fInv;
return kDiv;
}
inline friend ColourValue operator * (const float fScalar, const ColourValue& rkVector )
{
ColourValue kProd;
kProd.r = fScalar * rkVector.r;
kProd.g = fScalar * rkVector.g;
kProd.b = fScalar * rkVector.b;
kProd.a = fScalar * rkVector.a;
return kProd;
}
// arithmetic updates
inline ColourValue& operator += ( const ColourValue& rkVector )
{
r += rkVector.r;
g += rkVector.g;
b += rkVector.b;
a += rkVector.a;
return *this;
}
inline ColourValue& operator -= ( const ColourValue& rkVector )
{
r -= rkVector.r;
g -= rkVector.g;
b -= rkVector.b;
a -= rkVector.a;
return *this;
}
inline ColourValue& operator *= (const float fScalar )
{
r *= fScalar;
g *= fScalar;
b *= fScalar;
a *= fScalar;
return *this;
}
inline ColourValue& operator /= (const float fScalar )
{
assert( fScalar != 0.0 );
float fInv = 1.0f / fScalar;
r *= fInv;
g *= fInv;
b *= fInv;
a *= fInv;
return *this;
}
void setHSB(Real hue, Real saturation, Real brightness);
void getHSB(Real* hue, Real* saturation, Real* brightness) const;
inline _OgreExport friend std::ostream& operator <<
( std::ostream& o, const ColourValue& c )
{
o << "ColourValue(" << c.r << ", " << c.g << ", " << c.b << ", " << c.a << ")";
return o;
}
};
} // namespace
#endif
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::ColourValue::ZERO
static const ColourValue ZERO
Definition: OgreColourValue.h:60
Ogre::ColourValue::r
float r
Definition: OgreColourValue.h:76
Ogre::ColourValue::Green
static const ColourValue Green
Definition: OgreColourValue.h:64
Ogre::ARGB
uint32 ARGB
Definition: OgreColourValue.h:42
Ogre::ColourValue
Class representing colour.
Definition: OgreColourValue.h:57
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::ColourValue::ColourValue
ColourValue(float red=1.0f, float green=1.0f, float blue=1.0f, float alpha=1.0f)
Definition: OgreColourValue.h:67
Ogre::ColourValue::Black
static const ColourValue Black
Definition: OgreColourValue.h:61
Ogre::ColourValue::a
float a
Definition: OgreColourValue.h:76
Ogre::ColourValue::g
float g
Definition: OgreColourValue.h:76
Ogre::ColourValue::saturateCopy
ColourValue saturateCopy(void) const
As saturate, except that this colour value is unaffected and the saturated colour value is returned a...
Definition: OgreColourValue.h:136
Ogre::ColourValue::ptr
const float * ptr() const
Pointer accessor for direct copying.
Definition: OgreColourValue.h:165
Ogre::ColourValue::ptr
float * ptr()
Pointer accessor for direct copying.
Definition: OgreColourValue.h:160
Ogre::ColourValue::White
static const ColourValue White
Definition: OgreColourValue.h:62
Ogre::ColourValue::b
float b
Definition: OgreColourValue.h:76
OgrePrerequisites.h
Ogre::ABGR
uint32 ABGR
Definition: OgreColourValue.h:43
Ogre::operator!=
bool operator!=(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator, (ISO C++)
Definition: OgreMemorySTLAllocator.h:202
Ogre::ColourValue::Blue
static const ColourValue Blue
Definition: OgreColourValue.h:65
Ogre::uint32
unsigned int uint32
Definition: OgrePlatform.h:359
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::BGRA
uint32 BGRA
Definition: OgreColourValue.h:44
Ogre::operator==
bool operator==(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator, (ISO C++)
Definition: OgreMemorySTLAllocator.h:184
Ogre::ColourValue::saturate
void saturate(void)
Clamps colour value to the range [0, 1].
Definition: OgreColourValue.h:111
Ogre::operator/
Radian operator/(Real a, const Radian &b)
Definition: OgreMath.h:752
Ogre::ColourValue::Red
static const ColourValue Red
Definition: OgreColourValue.h:63
Ogre::operator*
Radian operator*(Real a, const Radian &b)
Definition: OgreMath.h:747
Ogre::RGBA
uint32 RGBA
Definition: OgreColourValue.h:41

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.