/* math/color.h This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_MATH_COLOR_H__ #define __INCLUDED_MATH_COLOR_H__ #include namespace math { /// a class representing an RGBA color value class Color { public: /// create the default color, white Color(); /// create a color from float RGBA value Color(float red, float green, float blue, float alpha = 1.0f); /// create a greyscale color Color(const float grey, const float alpha = 1.0f); /// create a copy from an existing color Color(Color const & other); /// red channel value float red() const; /// green channel value float green() const; /// blue channel value float blue() const; /// alpha channel value float alpha() const; /// assignment void assign(Color const & other); /// assignment void assign(float red, float green, float blue, float alpha = 1.0f); /// assignment void assign(float grey, float alpha = 1.0f); /// assignment operator Color const &operator=(Color const & other); /// multiply rgb values with scalar value. Color operator*(const float scalar) const; /// multiply rgb values with scalar value. Color & operator*=(const float scalar); /// divide rgb values with scalar value. Color & operator/=(const float scalar); /// assign a value to an element of this color /*! WARNING: range is not checked * @param index the index of the element to assign to ( 0 <= index < 4 ) */ inline float& operator[](const size_t index) { return rgba_data[index]; } /// returns the value of an element of this color /*! WARNING: range is not checked * @param index the index of the element to return ( 0 <= index < 4 ) */ inline float operator[](const size_t index) const { return rgba_data[index]; } /// pointer to the internal data inline float *ptr() const { return (float *) rgba_data; } /// clamp color values to the 0-1 range void clamp(); float &r; float &g; float &b; float &a; private: float rgba_data[4]; }; /// write color RGB values to stream std::ostream &operator<<(std::ostream &os, Color const & color); /// read color RGB values from stream, alpha is set to 1.0 std::istream &operator>>(std::istream & is, Color & color); /// scalar-with-color multiplication Color const operator*(float scalar, Color const & color); } // namespace math #endif // __INCLUDED_MATH_COLOR_H__