Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

CEGUIcolour.h

Go to the documentation of this file.
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 {
00039 class CEGUIBASE_API colour
00040 {
00041 public:
00042         /*************************************************************************
00043                 Construction & Destruction
00044         *************************************************************************/
00045         colour(void);
00046         colour(const colour& val);
00047         colour(float red, float green, float blue, float alpha = 1.0f);
00048         colour(ulong argb);
00049 
00050         ~colour(void);
00051 
00052         /*************************************************************************
00053                 Accessors
00054         *************************************************************************/
00055         ulong   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(ulong 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         void    setHSL(float hue, float saturation, float luminance, float alpha = 1.0f);
00105 
00106 
00107         /*************************************************************************
00108                 Operators
00109         *************************************************************************/
00110         inline colour& operator=(ulong val)
00111     {
00112         setARGB(val);
00113         return *this;
00114     }
00115 
00116         inline colour& operator=(const colour& val)
00117     {
00118         d_alpha = val.d_alpha;
00119         d_red   = val.d_red;
00120         d_green = val.d_green;
00121         d_blue  = val.d_blue;
00122         d_argb  = val.d_argb;
00123         d_argbValid = val.d_argbValid;
00124 
00125         return *this;
00126     }
00127 
00128         inline colour& operator&=(ulong val)
00129     {
00130         setARGB(getARGB() & val);
00131         return *this;
00132     }
00133 
00134         inline colour& operator&=(const colour& val)
00135     {
00136         setARGB(getARGB() & val.getARGB());
00137         return *this;
00138     }
00139 
00140         inline colour& operator|=(ulong val)
00141     {
00142         setARGB(getARGB() | val);
00143         return *this;
00144     }
00145 
00146         inline colour& operator|=(const colour& val)
00147     {
00148         setARGB(getARGB() | val.getARGB());
00149         return *this;
00150     }
00151 
00152         inline colour& operator<<=(int val)
00153     {
00154         setARGB(getARGB() << val);
00155         return *this;
00156     }
00157 
00158         inline colour& operator>>=(int val)
00159     {
00160         setARGB(getARGB() >> val);
00161         return *this;
00162     }
00163 
00164         inline colour operator+(const colour& val) const
00165     {
00166         return colour(
00167             d_red   + val.d_red, 
00168             d_green + val.d_green, 
00169             d_blue  + val.d_blue,
00170             d_alpha + val.d_alpha
00171         );
00172     }
00173 
00174         inline colour operator-(const colour& val) const
00175     {
00176         return colour(
00177             d_red   - val.d_red,
00178             d_green - val.d_green,
00179             d_blue  - val.d_blue,
00180             d_alpha - val.d_alpha
00181         );
00182     }
00183 
00184         inline colour operator*(const float val) const
00185     {       
00186         return colour(
00187             d_red   * val, 
00188             d_green * val, 
00189             d_blue  * val,
00190             d_alpha * val 
00191         );  
00192     }
00193 
00194         //
00195         // Conversion operators
00196         //
00197         operator ulong() const          {return getARGB();}
00198 
00199 private:
00200         /*************************************************************************
00201                 Implementation Methods
00202         *************************************************************************/
00207         ulong   calculateARGB(void) const;
00208 
00209         /*************************************************************************
00210                 Implementation Data
00211         *************************************************************************/
00212         float d_alpha, d_red, d_green, d_blue;          
00213         mutable ulong d_argb;                                           
00214         mutable bool d_argbValid;                                       
00215 };
00216 
00217 } // End of  CEGUI namespace section
00218 
00219 
00220 #endif  // end of guard _CEGUIcolour_h_

Generated on Wed Feb 16 12:41:05 2005 for Crazy Eddies GUI System by  doxygen 1.3.9.1