Crazy Eddies GUI System: CEGUIcolour.h Source File

Crazy Eddies GUI System 0.7.6

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

CEGUIcolour.h

    00001 /***********************************************************************
    00002         filename:       CEGUIcolour.h
    00003         created:        20/8/2004
    00004         author:         Paul D Turner (with code from Jeff Leigh)
    00005
    00006         purpose:        Defines interface to the colour class used to represent
    00007                                 colour values within the system
    00008 *************************************************************************/
    00009 /***************************************************************************
    00010  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
    00011  *
    00012  *   Permission is hereby granted, free of charge, to any person obtaining
    00013  *   a copy of this software and associated documentation files (the
    00014  *   "Software"), to deal in the Software without restriction, including
    00015  *   without limitation the rights to use, copy, modify, merge, publish,
    00016  *   distribute, sublicense, and/or sell copies of the Software, and to
    00017  *   permit persons to whom the Software is furnished to do so, subject to
    00018  *   the following conditions:
    00019  *
    00020  *   The above copyright notice and this permission notice shall be
    00021  *   included in all copies or substantial portions of the Software.
    00022  *
    00023  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    00024  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    00025  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    00026  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
    00027  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    00028  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    00029  *   OTHER DEALINGS IN THE SOFTWARE.
    00030  ***************************************************************************/
    00031 #ifndef _CEGUIcolour_h_
    00032 #define _CEGUIcolour_h_
    00033
    00034 #include "CEGUIBase.h"
    00035
    00036 // Start of CEGUI namespace section
    00037 namespace CEGUI
    00038 {
    00039 typedef uint32 argb_t;
    00040
    00045 class CEGUIEXPORT colour
    00046 {
    00047 public:
    00048         /*************************************************************************
    00049                 Construction & Destruction
    00050         *************************************************************************/
    00051         colour(void);
    00052         colour(const colour& val);
    00053         colour(float red, float green, float blue, float alpha = 1.0f);
    00054         colour(argb_t argb);
    00055
    00056         /*************************************************************************
    00057                 Accessors
    00058         *************************************************************************/
    00059         argb_t  getARGB(void) const
    00060         {
    00061                 if (!d_argbValid)
    00062                 {
    00063                         d_argb = calculateARGB();
    00064                         d_argbValid = true;
    00065                 }
    00066
    00067                 return d_argb;
    00068         }
    00069
    00070         float   getAlpha(void) const    {return d_alpha;}
    00071         float   getRed(void) const              {return d_red;}
    00072         float   getGreen(void) const    {return d_green;}
    00073         float   getBlue(void) const             {return d_blue;}
    00074
    00075         float   getHue(void) const;
    00076         float   getSaturation(void) const;
    00077         float   getLumination(void) const;
    00078
    00079
    00080         /*************************************************************************
    00081                 Manipulators
    00082         *************************************************************************/
    00083         void    setARGB(argb_t argb);
    00084         inline void setAlpha(float alpha)
    00085     {
    00086         d_argbValid = false;
    00087         d_alpha = alpha;
    00088     }
    00089
    00090         inline void setRed(float red)
    00091     {
    00092         d_argbValid = false;
    00093         d_red = red;
    00094     }
    00095
    00096         inline void setGreen(float green)
    00097     {
    00098         d_argbValid = false;
    00099         d_green = green;
    00100     }
    00101
    00102         inline void setBlue(float blue)
    00103     {
    00104         d_argbValid = false;
    00105         d_blue = blue;
    00106     }
    00107
    00108         inline void set(float red, float green, float blue, float alpha = 1.0f)
    00109     {
    00110         d_argbValid = false;
    00111         d_alpha = alpha;
    00112         d_red = red;
    00113         d_green = green;
    00114         d_blue = blue;
    00115     }
    00116
    00117         inline void setRGB(float red, float green, float blue)
    00118     {
    00119         d_argbValid = false;
    00120         d_red = red;
    00121         d_green = green;
    00122         d_blue = blue;
    00123     }
    00124
    00125         inline void setRGB(const colour& val)
    00126     {
    00127         d_red = val.d_red;
    00128         d_green = val.d_green;
    00129         d_blue = val.d_blue;
    00130         if (d_argbValid)
    00131         {
    00132             d_argbValid = val.d_argbValid;
    00133             if (d_argbValid)
    00134                 d_argb = (d_argb & 0xFF000000) | (val.d_argb & 0x00FFFFFF);
    00135         }
    00136     }
    00137
    00138         void    setHSL(float hue, float saturation, float luminance, float alpha = 1.0f);
    00139
    00140         void    invertColour(void);
    00141         void    invertColourWithAlpha(void);
    00142
    00143         /*************************************************************************
    00144                 Operators
    00145         *************************************************************************/
    00146         inline colour& operator=(argb_t val)
    00147     {
    00148         setARGB(val);
    00149         return *this;
    00150     }
    00151
    00152         inline colour& operator=(const colour& val)
    00153     {
    00154         d_alpha = val.d_alpha;
    00155         d_red   = val.d_red;
    00156         d_green = val.d_green;
    00157         d_blue  = val.d_blue;
    00158         d_argb  = val.d_argb;
    00159         d_argbValid = val.d_argbValid;
    00160
    00161         return *this;
    00162     }
    00163
    00164         inline colour& operator&=(argb_t val)
    00165     {
    00166         setARGB(getARGB() & val);
    00167         return *this;
    00168     }
    00169
    00170         inline colour& operator&=(const colour& val)
    00171     {
    00172         setARGB(getARGB() & val.getARGB());
    00173         return *this;
    00174     }
    00175
    00176         inline colour& operator|=(argb_t val)
    00177     {
    00178         setARGB(getARGB() | val);
    00179         return *this;
    00180     }
    00181
    00182         inline colour& operator|=(const colour& val)
    00183     {
    00184         setARGB(getARGB() | val.getARGB());
    00185         return *this;
    00186     }
    00187
    00188         inline colour& operator<<=(int val)
    00189     {
    00190         setARGB(getARGB() << val);
    00191         return *this;
    00192     }
    00193
    00194         inline colour& operator>>=(int val)
    00195     {
    00196         setARGB(getARGB() >> val);
    00197         return *this;
    00198     }
    00199
    00200         inline colour operator+(const colour& val) const
    00201     {
    00202         return colour(
    00203             d_red   + val.d_red,
    00204             d_green + val.d_green,
    00205             d_blue  + val.d_blue,
    00206             d_alpha + val.d_alpha
    00207         );
    00208     }
    00209
    00210         inline colour operator-(const colour& val) const
    00211     {
    00212         return colour(
    00213             d_red   - val.d_red,
    00214             d_green - val.d_green,
    00215             d_blue  - val.d_blue,
    00216             d_alpha - val.d_alpha
    00217         );
    00218     }
    00219
    00220         inline colour operator*(const float val) const
    00221     {
    00222         return colour(
    00223             d_red   * val,
    00224             d_green * val,
    00225             d_blue  * val,
    00226             d_alpha * val
    00227         );
    00228     }
    00229
    00230     inline colour& operator*=(const colour& val)
    00231     {
    00232         d_red *= val.d_red;
    00233         d_blue *= val.d_blue;
    00234         d_green *= val.d_green;
    00235         d_alpha *= val.d_alpha;
    00236
    00237                 d_argbValid = false;
    00238
    00239         return *this;
    00240     }
    00241
    00242         /*************************************************************************
    00243                 Compare operators
    00244         *************************************************************************/
    00245         inline bool operator==(const colour& rhs) const
    00246     {
    00247         return d_red   == rhs.d_red   &&
    00248                d_green == rhs.d_green &&
    00249                d_blue  == rhs.d_blue  &&
    00250                d_alpha == rhs.d_alpha;
    00251     }
    00252
    00253         inline bool operator!=(const colour& rhs) const
    00254     {
    00255         return !(*this == rhs);
    00256     }
    00257
    00258         //
    00259         // Conversion operators
    00260         //
    00261         operator argb_t() const         {return getARGB();}
    00262
    00263 private:
    00264         /*************************************************************************
    00265                 Implementation Methods
    00266         *************************************************************************/
    00271         argb_t  calculateARGB(void) const;
    00272
    00273         /*************************************************************************
    00274                 Implementation Data
    00275         *************************************************************************/
    00276         float d_alpha, d_red, d_green, d_blue;
    00277         mutable argb_t d_argb;
    00278         mutable bool d_argbValid;
    00279 };
    00280
    00281 } // End of  CEGUI namespace section
    00282
    00283
    00284 #endif  // end of guard _CEGUIcolour_h_