- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/Programmation/Sources/Tensor2/Utils/include/frost_utils_color.h

Go to the documentation of this file.

    00001 /* ###################################### */
    00002 /* ###     Frost Engine, by Kalith    ### */
    00003 /* ###################################### */
    00004 /*                                        */
    00005
    00006
    00007 #ifndef FROST_UTILS_COLOR_H
    00008 #define FROST_UTILS_COLOR_H
    00009
    00010 #include "frost_utils_types.h"
    00011
    00012 #ifdef USING_OGRE
    00013 namespace Ogre
    00014 {
    00015     class ColourValue;
    00016 }
    00017 #endif
    00018
    00019 namespace Frost
    00020 {
    00021     /// Color container
    00022     /** Automatically builds ARGB packed
    00023     *   color out of separated A, R, G and B
    00024     *   values and vice versa.
    00025     */
    00026     class Color
    00027     {
    00028     public :
    00029
    00030         /// Default constructor.
    00031         Color();
    00032
    00033         /// Constructor.
    00034         /** \param fR The red component
    00035         *   \param fG The green component
    00036         *   \param fB The blue component
    00037         */
    00038         Color(const s_float& fR, const s_float& fG, const s_float& fB);
    00039
    00040         /// Constructor.
    00041         /** \param fA The alpha component
    00042         *   \param fR The green component
    00043         *   \param fG The green component
    00044         *   \param fB The blue component
    00045         */
    00046         Color(const s_float& fA, const s_float& fR, const s_float& fG, const s_float& fB);
    00047
    00048         /// Constructor.
    00049         /** \param uiColor The ARGB packed color
    00050         */
    00051         Color(const s_uint& uiColor);
    00052
    00053         /// Returns the alpha component.
    00054         /** \return The alpha component
    00055         */
    00056         const s_float& GetA() const;
    00057
    00058         /// Returns the red component.
    00059         /** \return The red component
    00060         */
    00061         const s_float& GetR() const;
    00062
    00063         /// Returns the green component.
    00064         /** \return The green component
    00065         */
    00066         const s_float& GetG() const;
    00067
    00068         /// Returns the blue component.
    00069         /** \return The blue component
    00070         */
    00071         const s_float& GetB() const;
    00072
    00073         /// Returns the packed ARGB value.
    00074         /** \return The packed ARGB value
    00075         */
    00076         s_uint         GetPacked() const;
    00077
    00078         /// Sets the alpha component.
    00079         /** \param fA The alpha component
    00080         */
    00081         void           SetA(const s_float& fA);
    00082
    00083         /// Sets the red component.
    00084         /** \param fR The red component
    00085         */
    00086         void           SetR(const s_float& fR);
    00087
    00088         /// Sets the green component.
    00089         /** \param fG The green component
    00090         */
    00091         void           SetG(const s_float& fG);
    00092
    00093         /// Sets the blue component.
    00094         /** \param fB The blue component
    00095         */
    00096         void           SetB(const s_float& fB);
    00097
    00098         /// Sets the packed ARGB component.
    00099         /** \param uiColor packed ARGB component.
    00100         */
    00101         void           SetPacked(const s_uint& uiColor);
    00102
    00103         /// Clamps color components to [0,1].
    00104         void           Saturate();
    00105
    00106         /// Sets if this Color has a NaN chanel.
    00107         /** \return 'true' if this Color has a NaN chanel
    00108         */
    00109         s_bool         IsNaN() const;
    00110
    00111         s_float&       operator [] (const s_uint& uiIndex);
    00112         const s_float& operator [] (const s_uint& uiIndex) const;
    00113
    00114         s_bool operator == (const Color& mColor) const;
    00115         s_bool operator != (const Color& mColor) const;
    00116
    00117         Color  operator * (const Color& mColor) const;
    00118         Color  operator / (const Color& mColor) const;
    00119
    00120         Color  operator + (const Color& mColor) const;
    00121         Color  operator - (const Color& mColor) const;
    00122
    00123         Color&  operator *= (const Color& mColor);
    00124         Color&  operator /= (const Color& mColor);
    00125
    00126         Color&  operator += (const Color& mColor);
    00127         Color&  operator -= (const Color& mColor);
    00128
    00129         Color   operator *  (const s_float& fValue) const;
    00130         Color   operator /  (const s_float& fValue) const;
    00131         void    operator *= (const s_float& fValue);
    00132         void    operator /= (const s_float& fValue);
    00133
    00134         /// Creates a random color.
    00135         /** \param bRandomAlpha 'true' to randomize the alpha chanel too,
    00136         *                       'false' to make it opaque (alpha = 255)
    00137         *   \return A random color
    00138         */
    00139         static Color  Random(const s_bool& bRandomAlpha = false);
    00140
    00141         /// Clamps color components to [0,1].
    00142         /** \param mColor The color to clamp
    00143         *   \return The clamped color
    00144         */
    00145         static Color  Saturate(const Color& mColor);
    00146
    00147         #ifdef USING_OGRE
    00148         /// Converts a Frost color to an Ogre one.
    00149         /** \param mColor The color to convert
    00150         *   \return The Ogre color
    00151         */
    00152         static Ogre::ColourValue FrostToOgre(const Color& mColor);
    00153
    00154         /// Converts an Ogre color to a Frost one.
    00155         /** \param mColor The color to convert
    00156         *   \return The Frost color
    00157         */
    00158         static Color OgreToFrost(const Ogre::ColourValue& mColor);
    00159         #endif
    00160
    00161         static const Color BLACK;
    00162         static const Color WHITE;
    00163         static const Color RED;
    00164         static const Color GREEN;
    00165         static const Color BLUE;
    00166         static const Color VOID;
    00167         static const Color NaN;
    00168
    00169         static const s_str CLASS_NAME;
    00170
    00171         s_float r;
    00172         s_float g;
    00173         s_float b;
    00174         s_float a;
    00175
    00176     private :
    00177
    00178         s_uint BuildUIColor_() const;
    00179         void BuildABGRColor_(const s_uint& uiColor);
    00180     };
    00181
    00182     Color operator * (const s_float& fLeft, const Color& mRight);
    00183     Color operator / (const s_float& fLeft, const Color& mRight);
    00184
    00185     /** \cond NOT_REMOVE_FROM_DOC
    00186     */
    00187     template<> class StringConverter<string_element, Color>
    00188     {
    00189     public :
    00190
    00191         typedef s_str::string string;
    00192
    00193         static string Convert(const Color& mColor);
    00194     };
    00195     /** \endcond
    00196     */
    00197 }
    00198
    00199 #endif