source: OGRE/trunk/ogrenew/Dependencies/include/CEGUI/CEGUIcolour.h @ 657

Revision 657, 7.3 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1/************************************************************************
2        filename:       CEGUIcolour.h
3        created:        20/8/2004
4        author:         Paul D Turner (with code from Jeff Leigh)
5       
6        purpose:        Defines interface to the colour class used to represent
7                                colour values within the system
8*************************************************************************/
9/*************************************************************************
10    Crazy Eddie's GUI System (http://www.cegui.org.uk)
11    Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
12
13    This library is free software; you can redistribute it and/or
14    modify it under the terms of the GNU Lesser General Public
15    License as published by the Free Software Foundation; either
16    version 2.1 of the License, or (at your option) any later version.
17
18    This library is distributed in the hope that it will be useful,
19    but WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21    Lesser General Public License for more details.
22
23    You should have received a copy of the GNU Lesser General Public
24    License along with this library; if not, write to the Free Software
25    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26*************************************************************************/
27#ifndef _CEGUIcolour_h_
28#define _CEGUIcolour_h_
29
30#include "CEGUIBase.h"
31
32// Start of CEGUI namespace section
33namespace CEGUI
34{
35typedef uint32 argb_t;    //!< 32 bit ARGB representation of a colour.
36
37/*!
38\brief
39        Class representing colour values within the system.
40*/
41class CEGUIEXPORT colour
42{
43public:
44        /*************************************************************************
45                Construction & Destruction
46        *************************************************************************/
47        colour(void);
48        colour(const colour& val);
49        colour(float red, float green, float blue, float alpha = 1.0f);
50        colour(argb_t argb);
51
52        /*************************************************************************
53                Accessors
54        *************************************************************************/
55        argb_t  getARGB(void) const
56        {
57                if (!d_argbValid)
58                {
59                        d_argb = calculateARGB();
60                        d_argbValid = true;
61                }
62
63                return d_argb;
64        }
65       
66        float   getAlpha(void) const    {return d_alpha;}
67        float   getRed(void) const              {return d_red;}
68        float   getGreen(void) const    {return d_green;}
69        float   getBlue(void) const             {return d_blue;}
70
71        float   getHue(void) const;
72        float   getSaturation(void) const;
73        float   getLumination(void) const;
74
75
76        /*************************************************************************
77                Manipulators
78        *************************************************************************/
79        void    setARGB(argb_t argb);
80        inline void setAlpha(float alpha)
81    {
82        d_argbValid = false;
83        d_alpha = alpha;
84    }
85
86        inline void setRed(float red)
87    {   
88        d_argbValid = false;
89        d_red = red;
90    }
91
92        inline void setGreen(float green)
93    {
94        d_argbValid = false;
95        d_green = green;
96    }
97
98        inline void setBlue(float blue)
99    {
100        d_argbValid = false;
101        d_blue = blue;
102    }
103
104        inline void set(float red, float green, float blue, float alpha = 1.0f)
105    {
106        d_argbValid = false;
107        d_alpha = alpha;
108        d_red = red;
109        d_green = green;
110        d_blue = blue;
111    }
112
113        inline void setRGB(float red, float green, float blue)
114    {
115        d_argbValid = false;
116        d_red = red;
117        d_green = green;
118        d_blue = blue;
119    }
120
121        inline void setRGB(const colour& val)
122    {
123        d_red = val.d_red;
124        d_green = val.d_green;
125        d_blue = val.d_blue;
126        if (d_argbValid)
127        {
128            d_argbValid = val.d_argbValid;
129            if (d_argbValid)
130                d_argb = (d_argb & 0xFF000000) | (val.d_argb & 0x00FFFFFF);
131        }
132    }
133
134        void    setHSL(float hue, float saturation, float luminance, float alpha = 1.0f);
135
136        void    invertColour(void);
137        void    invertColourWithAlpha(void);
138
139        /*************************************************************************
140                Operators
141        *************************************************************************/
142        inline colour& operator=(argb_t val)
143    {
144        setARGB(val);
145        return *this;
146    }
147
148        inline colour& operator=(const colour& val)
149    {
150        d_alpha = val.d_alpha;
151        d_red   = val.d_red;
152        d_green = val.d_green;
153        d_blue  = val.d_blue;
154        d_argb  = val.d_argb;
155        d_argbValid = val.d_argbValid;
156
157        return *this;
158    }
159
160        inline colour& operator&=(argb_t val)
161    {
162        setARGB(getARGB() & val);
163        return *this;
164    }
165
166        inline colour& operator&=(const colour& val)
167    {
168        setARGB(getARGB() & val.getARGB());
169        return *this;
170    }
171
172        inline colour& operator|=(argb_t val)
173    {
174        setARGB(getARGB() | val);
175        return *this;
176    }
177
178        inline colour& operator|=(const colour& val)
179    {
180        setARGB(getARGB() | val.getARGB());
181        return *this;
182    }
183
184        inline colour& operator<<=(int val)
185    {
186        setARGB(getARGB() << val);
187        return *this;
188    }
189
190        inline colour& operator>>=(int val)
191    {
192        setARGB(getARGB() >> val);
193        return *this;
194    }
195
196        inline colour operator+(const colour& val) const
197    {
198        return colour(
199            d_red   + val.d_red,
200            d_green + val.d_green,
201            d_blue  + val.d_blue,
202            d_alpha + val.d_alpha
203        );
204    }
205
206        inline colour operator-(const colour& val) const
207    {
208        return colour(
209            d_red   - val.d_red,
210            d_green - val.d_green,
211            d_blue  - val.d_blue,
212            d_alpha - val.d_alpha
213        );
214    }
215
216        inline colour operator*(const float val) const
217    {       
218        return colour(
219            d_red   * val,
220            d_green * val,
221            d_blue  * val,
222            d_alpha * val
223        ); 
224    }
225
226        /*************************************************************************
227                Compare operators
228        *************************************************************************/
229        inline bool operator==(const colour& rhs) const
230    {
231        return d_red   == rhs.d_red   &&
232               d_green == rhs.d_green &&
233               d_blue  == rhs.d_blue  &&
234               d_alpha == rhs.d_alpha;
235    }
236
237        inline bool operator!=(const colour& rhs) const
238    {
239        return !(*this == rhs);
240    }
241
242        //
243        // Conversion operators
244        //
245        operator argb_t() const         {return getARGB();}
246
247private:
248        /*************************************************************************
249                Implementation Methods
250        *************************************************************************/
251        /*!
252        \brief
253                calculate and return the ARGB value based on the current colour component values.
254        */
255        argb_t  calculateARGB(void) const;
256
257        /*************************************************************************
258                Implementation Data
259        *************************************************************************/
260        float d_alpha, d_red, d_green, d_blue;          //!< Colour components.
261        mutable argb_t d_argb;                                          //!< Colour as ARGB value.
262        mutable bool d_argbValid;                                       //!< True if argb value is valid.
263};
264
265} // End of  CEGUI namespace section
266
267
268#endif  // end of guard _CEGUIcolour_h_
Note: See TracBrowser for help on using the repository browser.