Crazy Eddies GUI System: CEGUIcolour.h Source File

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

# 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     Crazy Eddie's GUI System (http://www.cegui.org.uk)
    00011     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
    00012
    00013     This library is free software; you can redistribute it and/or
    00014     modify it under the terms of the GNU Lesser General Public
    00015     License as published by the Free Software Foundation; either
    00016     version 2.1 of the License, or (at your option) any later version.
    00017
    00018     This library is distributed in the hope that it will be useful,
    00019     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00020     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00021     Lesser General Public License for more details.
    00022
    00023     You should have received a copy of the GNU Lesser General Public
    00024     License along with this library; if not, write to the Free Software
    00025     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00026 *************************************************************************/
    00027 #ifndef _CEGUIcolour_h_
    00028 #define _CEGUIcolour_h_
    00029
    00030 #include "CEGUIBase.h"
    00031
    00032 // Start of CEGUI namespace section
    00033 namespace CEGUI
    00034 {
    00035 typedef uint32 argb_t;
    00036
    00041 class CEGUIEXPORT colour
    00042 {
    00043 public:
    00044         /*************************************************************************
    00045                 Construction & Destruction
    00046         *************************************************************************/
    00047         colour(void);
    00048         colour(const colour& val);
    00049         colour(float red, float green, float blue, float alpha = 1.0f);
    00050         colour(argb_t argb);
    00051
    00052         /*************************************************************************
    00053                 Accessors
    00054         *************************************************************************/
    00055         argb_t  getARGB(void) const
    00056         {
    00057                 if (!d_argbValid)
    00058                 {
    00059                         d_argb = calculateARGB();
    00060                         d_argbValid = true;
    00061                 }
    00062
    00063                 return d_argb;
    00064         }
    00065
    00066         float   getAlpha(void) const    {return d_alpha;}
    00067         float   getRed(void) const              {return d_red;}
    00068         float   getGreen(void) const    {return d_green;}
    00069         float   getBlue(void) const             {return d_blue;}
    00070
    00071         float   getHue(void) const;
    00072         float   getSaturation(void) const;
    00073         float   getLumination(void) const;
    00074
    00075
    00076         /*************************************************************************
    00077                 Manipulators
    00078         *************************************************************************/
    00079         void    setARGB(argb_t argb);
    00080         inline void setAlpha(float alpha)
    00081     {
    00082         d_argbValid = false;
    00083         d_alpha = alpha;
    00084     }
    00085
    00086         inline void setRed(float red)
    00087     {
    00088         d_argbValid = false;
    00089         d_red = red;
    00090     }
    00091
    00092         inline void setGreen(float green)
    00093     {
    00094         d_argbValid = false;
    00095         d_green = green;
    00096     }
    00097
    00098         inline void setBlue(float blue)
    00099     {
    00100         d_argbValid = false;
    00101         d_blue = blue;
    00102     }
    00103
    00104         inline void set(float red, float green, float blue, float alpha = 1.0f)
    00105     {
    00106         d_argbValid = false;
    00107         d_alpha = alpha;
    00108         d_red = red;
    00109         d_green = green;
    00110         d_blue = blue;
    00111     }
    00112
    00113         inline void setRGB(float red, float green, float blue)
    00114     {
    00115         d_argbValid = false;
    00116         d_red = red;
    00117         d_green = green;
    00118         d_blue = blue;
    00119     }
    00120
    00121         inline void setRGB(const colour& val)
    00122     {
    00123         d_red = val.d_red;
    00124         d_green = val.d_green;
    00125         d_blue = val.d_blue;
    00126         if (d_argbValid)
    00127         {
    00128             d_argbValid = val.d_argbValid;
    00129             if (d_argbValid)
    00130                 d_argb = (d_argb & 0xFF000000) | (val.d_argb & 0x00FFFFFF);
    00131         }
    00132     }
    00133
    00134         void    setHSL(float hue, float saturation, float luminance, float alpha = 1.0f);
    00135
    00136         void    invertColour(void);
    00137         void    invertColourWithAlpha(void);
    00138
    00139         /*************************************************************************
    00140                 Operators
    00141         *************************************************************************/
    00142         inline colour& operator=(argb_t val)
    00143     {
    00144         setARGB(val);
    00145         return *this;
    00146     }
    00147
    00148         inline colour& operator=(const colour& val)
    00149     {
    00150         d_alpha = val.d_alpha;
    00151         d_red   = val.d_red;
    00152         d_green = val.d_green;
    00153         d_blue  = val.d_blue;
    00154         d_argb  = val.d_argb;
    00155         d_argbValid = val.d_argbValid;
    00156
    00157         return *this;
    00158     }
    00159
    00160         inline colour& operator&=(argb_t val)
    00161     {
    00162         setARGB(getARGB() & val);
    00163         return *this;
    00164     }
    00165
    00166         inline colour& operator&=(const colour& val)
    00167     {
    00168         setARGB(getARGB() & val.getARGB());
    00169         return *this;
    00170     }
    00171
    00172         inline colour& operator|=(argb_t val)
    00173     {
    00174         setARGB(getARGB() | val);
    00175         return *this;
    00176     }
    00177
    00178         inline colour& operator|=(const colour& val)
    00179     {
    00180         setARGB(getARGB() | val.getARGB());
    00181         return *this;
    00182     }
    00183
    00184         inline colour& operator<<=(int val)
    00185     {
    00186         setARGB(getARGB() << val);
    00187         return *this;
    00188     }
    00189
    00190         inline colour& operator>>=(int val)
    00191     {
    00192         setARGB(getARGB() >> val);
    00193         return *this;
    00194     }
    00195
    00196         inline colour operator+(const colour& val) const
    00197     {
    00198         return colour(
    00199             d_red   + val.d_red,
    00200             d_green + val.d_green,
    00201             d_blue  + val.d_blue,
    00202             d_alpha + val.d_alpha
    00203         );
    00204     }
    00205
    00206         inline colour operator-(const colour& val) const
    00207     {
    00208         return colour(
    00209             d_red   - val.d_red,
    00210             d_green - val.d_green,
    00211             d_blue  - val.d_blue,
    00212             d_alpha - val.d_alpha
    00213         );
    00214     }
    00215
    00216         inline colour operator*(const float val) const
    00217     {
    00218         return colour(
    00219             d_red   * val,
    00220             d_green * val,
    00221             d_blue  * val,
    00222             d_alpha * val
    00223         );
    00224     }
    00225
    00226     inline colour& operator*=(const colour& val)
    00227     {
    00228         d_red *= val.d_red;
    00229         d_blue *= val.d_blue;
    00230         d_green *= val.d_green;
    00231         d_alpha *= val.d_alpha;
    00232
    00233                 d_argbValid = false;
    00234
    00235         return *this;
    00236     }
    00237
    00238         /*************************************************************************
    00239                 Compare operators
    00240         *************************************************************************/
    00241         inline bool operator==(const colour& rhs) const
    00242     {
    00243         return d_red   == rhs.d_red   &&
    00244                d_green == rhs.d_green &&
    00245                d_blue  == rhs.d_blue  &&
    00246                d_alpha == rhs.d_alpha;
    00247     }
    00248
    00249         inline bool operator!=(const colour& rhs) const
    00250     {
    00251         return !(*this == rhs);
    00252     }
    00253
    00254         //
    00255         // Conversion operators
    00256         //
    00257         operator argb_t() const         {return getARGB();}
    00258
    00259 private:
    00260         /*************************************************************************
    00261                 Implementation Methods
    00262         *************************************************************************/
    00267         argb_t  calculateARGB(void) const;
    00268
    00269         /*************************************************************************
    00270                 Implementation Data
    00271         *************************************************************************/
    00272         float d_alpha, d_red, d_green, d_blue;
    00273         mutable argb_t d_argb;
    00274         mutable bool d_argbValid;
    00275 };
    00276
    00277 } // End of  CEGUI namespace section
    00278
    00279
    00280 #endif  // end of guard _CEGUIcolour_h_