abf8b686994ff12c775ce32a3301a51dcada84ec
[mussa.git] / alg / color.hpp
1 #ifndef _GLCOLOR_H_
2 #define _GLCOLOR_H_
3
4 #include <boost/serialization/export.hpp>
5 #include <boost/serialization/nvp.hpp>
6 #include <boost/serialization/version.hpp>
7
8 #include <ostream>
9
10 //! convienece class for handling opengl colors
11 class Color
12 {
13 public:
14   Color();
15   Color(const Color &);
16   //! initialize with red, green, blue, alpha
17   Color(float r, float g, float b, float a=1.0);
18
19   //! set all channels simultaneously 
20   void set(float r, float g, float b, float a=1.0);
21   //! return an array of 4 colors (stored by class)
22   const float* const get() const;
23   void setR(float);
24   float r() const;
25   void setG(float);
26   float g() const;
27   void setB(float);
28   float b() const;
29   void setA(float);
30   float a() const;
31
32   enum color_channels { RedChannel, GreenChannel, BlueChannel, AlphaChannel };
33   friend bool operator==(const Color&, const Color&);
34   friend std::ostream& operator<<(std::ostream&, const Color&);
35
36 protected:
37   float colors[4];
38
39 private:
40   friend class boost::serialization::access;
41   template<class Archive>
42   void serialize(Archive& ar, const unsigned int /*version*/) {
43     ar & boost::serialization::make_nvp("red",   colors[RedChannel]);
44     ar & boost::serialization::make_nvp("green", colors[GreenChannel]);
45     ar & boost::serialization::make_nvp("blue",  colors[BlueChannel]);
46     ar & boost::serialization::make_nvp("alpha", colors[AlphaChannel]);
47   }
48 };
49 BOOST_CLASS_EXPORT(Color)
50
51 #endif
52