Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre_src_v1-9-0/OgreMain/include/OgreColourValue.h @ 148

Last change on this file since 148 was 148, checked in by patricwi, 6 years ago

Added new dependencies for ogre1.9 and cegui0.8

File size: 8.5 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2013 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28#ifndef _COLOURVALUE_H__
29#define _COLOURVALUE_H__
30
31#include "OgrePrerequisites.h"
32
33namespace Ogre {
34        /** \addtogroup Core
35        *  @{
36        */
37        /** \addtogroup General
38        *  @{
39        */
40
41    typedef uint32 RGBA;
42    typedef uint32 ARGB;
43    typedef uint32 ABGR;
44        typedef uint32 BGRA;
45
46    /** Class representing colour.
47            @remarks
48                    Colour is represented as 4 components, each of which is a
49                    floating-point value from 0.0 to 1.0.
50            @par
51                    The 3 'normal' colour components are red, green and blue, a higher
52                    number indicating greater amounts of that component in the colour.
53                    The forth component is the 'alpha' value, which represents
54                    transparency. In this case, 0.0 is completely transparent and 1.0 is
55                    fully opaque.
56    */
57    class _OgreExport ColourValue
58    {
59    public:
60        static const ColourValue ZERO;
61        static const ColourValue Black;
62        static const ColourValue White;
63        static const ColourValue Red;
64        static const ColourValue Green;
65        static const ColourValue Blue;
66
67            explicit ColourValue( float red = 1.0f,
68                                    float green = 1.0f,
69                                    float blue = 1.0f,
70                                    float alpha = 1.0f ) : r(red), g(green), b(blue), a(alpha)
71        { }
72
73            bool operator==(const ColourValue& rhs) const;
74            bool operator!=(const ColourValue& rhs) const;
75
76        float r,g,b,a;
77
78            /** Retrieves colour as RGBA.
79            */
80            RGBA getAsRGBA(void) const;
81
82            /** Retrieves colour as ARGB.
83            */
84            ARGB getAsARGB(void) const;
85
86                /** Retrieves colour as BGRA.
87                */
88                BGRA getAsBGRA(void) const;
89
90                /** Retrieves colours as ABGR */
91            ABGR getAsABGR(void) const;
92
93            /** Sets colour as RGBA.
94            */
95        void setAsRGBA(const RGBA val);
96
97            /** Sets colour as ARGB.
98            */
99        void setAsARGB(const ARGB val);
100
101                /** Sets colour as BGRA.
102                */
103                void setAsBGRA(const BGRA val);
104
105            /** Sets colour as ABGR.
106            */
107        void setAsABGR(const ABGR val);
108
109        /** Clamps colour value to the range [0, 1].
110        */
111        void saturate(void)
112        {
113            if (r < 0)
114                r = 0;
115            else if (r > 1)
116                r = 1;
117
118            if (g < 0)
119                g = 0;
120            else if (g > 1)
121                g = 1;
122
123            if (b < 0)
124                b = 0;
125            else if (b > 1)
126                b = 1;
127
128            if (a < 0)
129                a = 0;
130            else if (a > 1)
131                a = 1;
132        }
133
134        /** As saturate, except that this colour value is unaffected and
135            the saturated colour value is returned as a copy. */
136        ColourValue saturateCopy(void) const
137        {
138            ColourValue ret = *this;
139            ret.saturate();
140            return ret;
141        }
142
143                /// Array accessor operator
144                inline float operator [] ( const size_t i ) const
145                {
146                        assert( i < 4 );
147
148                        return *(&r+i);
149                }
150
151                /// Array accessor operator
152                inline float& operator [] ( const size_t i )
153                {
154                        assert( i < 4 );
155
156                        return *(&r+i);
157                }
158
159                /// Pointer accessor for direct copying
160                inline float* ptr()
161                {
162                        return &r;
163                }
164                /// Pointer accessor for direct copying
165                inline const float* ptr() const
166                {
167                        return &r;
168                }
169
170               
171                // arithmetic operations
172        inline ColourValue operator + ( const ColourValue& rkVector ) const
173        {
174            ColourValue kSum;
175
176            kSum.r = r + rkVector.r;
177            kSum.g = g + rkVector.g;
178            kSum.b = b + rkVector.b;
179            kSum.a = a + rkVector.a;
180
181            return kSum;
182        }
183
184        inline ColourValue operator - ( const ColourValue& rkVector ) const
185        {
186            ColourValue kDiff;
187
188            kDiff.r = r - rkVector.r;
189            kDiff.g = g - rkVector.g;
190            kDiff.b = b - rkVector.b;
191            kDiff.a = a - rkVector.a;
192
193            return kDiff;
194        }
195
196        inline ColourValue operator * (const float fScalar ) const
197        {
198            ColourValue kProd;
199
200            kProd.r = fScalar*r;
201            kProd.g = fScalar*g;
202            kProd.b = fScalar*b;
203            kProd.a = fScalar*a;
204
205            return kProd;
206        }
207
208        inline ColourValue operator * ( const ColourValue& rhs) const
209        {
210            ColourValue kProd;
211
212            kProd.r = rhs.r * r;
213            kProd.g = rhs.g * g;
214            kProd.b = rhs.b * b;
215            kProd.a = rhs.a * a;
216
217            return kProd;
218        }
219
220        inline ColourValue operator / ( const ColourValue& rhs) const
221        {
222            ColourValue kProd;
223
224            kProd.r = r / rhs.r;
225            kProd.g = g / rhs.g;
226            kProd.b = b / rhs.b;
227            kProd.a = a / rhs.a;
228
229            return kProd;
230        }
231
232        inline ColourValue operator / (const float fScalar ) const
233        {
234            assert( fScalar != 0.0 );
235
236            ColourValue kDiv;
237
238            float fInv = 1.0f / fScalar;
239            kDiv.r = r * fInv;
240            kDiv.g = g * fInv;
241            kDiv.b = b * fInv;
242            kDiv.a = a * fInv;
243
244            return kDiv;
245        }
246
247        inline friend ColourValue operator * (const float fScalar, const ColourValue& rkVector )
248        {
249            ColourValue kProd;
250
251            kProd.r = fScalar * rkVector.r;
252            kProd.g = fScalar * rkVector.g;
253            kProd.b = fScalar * rkVector.b;
254            kProd.a = fScalar * rkVector.a;
255
256            return kProd;
257        }
258
259        // arithmetic updates
260        inline ColourValue& operator += ( const ColourValue& rkVector )
261        {
262            r += rkVector.r;
263            g += rkVector.g;
264            b += rkVector.b;
265            a += rkVector.a;
266
267            return *this;
268        }
269
270        inline ColourValue& operator -= ( const ColourValue& rkVector )
271        {
272            r -= rkVector.r;
273            g -= rkVector.g;
274            b -= rkVector.b;
275            a -= rkVector.a;
276
277            return *this;
278        }
279
280        inline ColourValue& operator *= (const float fScalar )
281        {
282            r *= fScalar;
283            g *= fScalar;
284            b *= fScalar;
285            a *= fScalar;
286            return *this;
287        }
288
289        inline ColourValue& operator /= (const float fScalar )
290        {
291            assert( fScalar != 0.0 );
292
293            float fInv = 1.0f / fScalar;
294
295            r *= fInv;
296            g *= fInv;
297            b *= fInv;
298            a *= fInv;
299
300            return *this;
301        }
302
303                /** Set a colour value from Hue, Saturation and Brightness.
304                @param hue Hue value, scaled to the [0,1] range as opposed to the 0-360
305                @param saturation Saturation level, [0,1]
306                @param brightness Brightness level, [0,1]
307                */
308                void setHSB(Real hue, Real saturation, Real brightness);
309
310                /** Convert the current colour to Hue, Saturation and Brightness values.
311                @param hue Output hue value, scaled to the [0,1] range as opposed to the 0-360
312                @param saturation Output saturation level, [0,1]
313                @param brightness Output brightness level, [0,1]
314                */
315                void getHSB(Real* hue, Real* saturation, Real* brightness) const;
316
317
318
319                /** Function for writing to a stream.
320                */
321                inline _OgreExport friend std::ostream& operator <<
322                        ( std::ostream& o, const ColourValue& c )
323                {
324                        o << "ColourValue(" << c.r << ", " << c.g << ", " << c.b << ", " << c.a << ")";
325                        return o;
326                }
327
328    };
329        /** @} */
330        /** @} */
331
332} // namespace
333
334#endif
Note: See TracBrowser for help on using the repository browser.