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