CAlphaColour.hpp

Go to the documentation of this file.
00001 #ifndef __CAlphaColour__
00002 #define __CAlphaColour__
00003 
00004 #include "CColour.hpp"
00005 using Exponent::GUI::Basics::CColour;
00006 
00007 //  ===========================================================================
00008 
00009 namespace Exponent
00010 {
00011     namespace GUI
00012     {
00013         namespace Basics
00014         {
00036             class CAlphaColour : public CColour
00037             {
00039                 EXPONENT_CLASS_DECLARATION;
00042 //  ===========================================================================
00043 
00044             public:
00045 
00046 //  ===========================================================================
00047 
00048                 const static CAlphaColour CALPHACOLOUR_BLACK;           
00049                 const static CAlphaColour CALPHACOLOUR_WHITE;           
00050                 const static CAlphaColour CALPHACOLOUR_RED;             
00051                 const static CAlphaColour CALPHACOLOUR_GREEN;           
00052                 const static CAlphaColour CALPHACOLOUR_BLUE;            
00053                 const static CAlphaColour CALPHACOLOUR_YELLOW;          
00054                 const static CAlphaColour CALPHACOLOUR_ORANGE;          
00055                 const static CAlphaColour CALPHACOLOUR_TURQUOISE;       
00056                 const static CAlphaColour CALPHACOLOUR_PURPLE;          
00057                 const static CAlphaColour CALPHACOLOUR_PINK;            
00058                 const static CAlphaColour CALPHACOLOUR_LIGHT_GREY;      
00059                 const static CAlphaColour CALPHACOLOUR_DARK_GREY;       
00061 //  ===========================================================================
00062 
00070                 CAlphaColour(const unsigned long red, const unsigned long green, const unsigned long blue, const unsigned long alpha = 255);
00071 
00075                 CAlphaColour();
00076 
00081                 CAlphaColour(const CAlphaColour &colour);
00082 
00086                 virtual ~CAlphaColour();
00087 
00088 //  ===========================================================================
00089 
00094                 CAlphaColour &operator = (const CAlphaColour &colour);
00095 
00100                 CAlphaColour &operator = (const CColour &colour);
00101 
00107                 bool operator == (const CAlphaColour &colour) const;
00108 
00109 //  ===========================================================================
00110 
00115                 void setAlpha(const unsigned long alpha) { m_alpha = alpha; }
00116 
00121                 unsigned long getAlpha() const { return m_alpha; }
00122 
00123 //  ===========================================================================
00124 
00128                 void darkenColour();
00129 
00133                 void lightenColour();
00134 
00135 //  ============================================================================
00136 
00144                 virtual void setColour(const unsigned long red, const unsigned long green, const unsigned long blue, const unsigned long alpha);
00145 
00150                 CColour *getAsColour() const;
00151 
00156                 void getAsColour(CColour &colour) const;
00157 
00158 //  ===========================================================================
00159 
00166                 static FORCEINLINE void alphaBlend(CColour &destination, const CAlphaColour &background, const CAlphaColour &source)
00167                 {
00168                     destination.setRed(CAlphaColour::alphaComposite(source.getRed(), background.getRed(), source.getAlpha()));
00169                     destination.setGreen(CAlphaColour::alphaComposite(source.getGreen(), background.getGreen(), source.getAlpha()));
00170                     destination.setBlue(CAlphaColour::alphaComposite(source.getBlue(), background.getBlue(), source.getAlpha()));
00171                 }
00172 
00180                 static FORCEINLINE void alphaBlend(CColour &destination, const CColour &background, const CColour &source, const unsigned long alpha)
00181                 {
00182                     destination.setRed(CAlphaColour::alphaComposite(source.getRed(), background.getRed(), alpha));
00183                     destination.setGreen(CAlphaColour::alphaComposite(source.getGreen(), background.getGreen(), alpha));
00184                     destination.setBlue(CAlphaColour::alphaComposite(source.getBlue(), background.getBlue(), alpha));
00185                 }
00186 
00187 //  ===========================================================================
00188 
00194                 virtual void getObjectDescription(char *string, const long size) const;
00195 
00196 //  ===========================================================================
00197 
00198             protected:
00199 
00200 //  ===========================================================================
00201 
00208                 static FORCEINLINE unsigned long alphaComposite(const unsigned long foreground, const unsigned long background, const unsigned long alpha)
00209                 {
00210                     unsigned long temp = ((unsigned long)(foreground)*(unsigned long)(alpha) + (unsigned long)(background)*(unsigned long)(255 - (unsigned long)(alpha)) + (unsigned long)128); 
00211                     return (unsigned long)((temp + (temp >> 8)) >> 8);
00212                 }
00213 
00214 //  ===========================================================================
00215 
00216                 unsigned long m_alpha;      
00218             };
00219         }
00220     }
00221 }
00222 #endif  // end of CAlphaColour.hpp

Infinity API - CAlphaColour.hpp Source File generated on 7 Mar 2007