UGDK  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
color.h
Go to the documentation of this file.
1 #ifndef UGDK_STRUCTURE_COLOR_H_
2 #define UGDK_STRUCTURE_COLOR_H_
3 
4 #include <ugdk/structure/types.h>
5 
6 namespace ugdk {
7 namespace structure {
8 
9 struct Color {
10  Color() : r(1.0), g(1.0), b(1.0), a(1.0) {}
11  explicit Color(double _r, double _g, double _b, double _a = 1.0)
12  : r(_r), g(_g), b(_b), a(_a) {}
13  explicit Color(uint32 hex_val, double _a = 1.0) :
14  r(((hex_val & 0xFF0000) >> 16) / 255.0),
15  g(((hex_val & 0x00FF00) >> 8) / 255.0),
16  b(((hex_val & 0x0000FF) ) / 255.0),
17  a(_a) {}
18 
19  union {
20  struct { double r, g, b, a; };
21  struct { double val[4]; };
22  };
23 
24  void Compose(const Color& rhs) {
25  r *= rhs.r;
26  g *= rhs.g;
27  b *= rhs.b;
28  a *= rhs.a;
29  }
30 
31  Color& operator*=(const Color& rhs) { Compose(rhs); return *this; }
32  Color operator*(const Color& rhs) const {
33  Color result(rhs);
34  result *= *this;
35  return result;
36  }
37 
38  double get_r() const { return r; }
39  double get_g() const { return g; }
40  double get_b() const { return b; }
41  double get_a() const { return a; }
42 
43  void set_r(double r_) { r = r_; }
44  void set_g(double g_) { g = g_; }
45  void set_b(double b_) { b = b_; }
46  void set_a(double a_) { a = a_; }
47 
48 };
49 
50 //static Color BLACK = {0.0, 0.0, 0.0};
51 #ifndef SWIG
52 static const Color WHITE(1.0, 1.0, 1.0);
53 #endif
54 
55 } // namespace structure
56 } // namespace ugdk
57 
58 #endif /* UGDK_STRUCTURE_COLOR_H_ */
double g
Definition: color.h:20
void set_b(double b_)
Definition: color.h:45
uint32_t uint32
Definition: types.h:14
Color & operator*=(const Color &rhs)
Definition: color.h:31
Color()
Definition: color.h:10
void set_a(double a_)
Definition: color.h:46
Definition: color.h:9
Color operator*(const Color &rhs) const
Definition: color.h:32
Color(uint32 hex_val, double _a=1.0)
Definition: color.h:13
void Compose(const Color &rhs)
Definition: color.h:24
Definition: animation.h:11
double a
Definition: color.h:20
double b
Definition: color.h:20
Color(double _r, double _g, double _b, double _a=1.0)
Definition: color.h:11
double val[4]
Definition: color.h:21
void set_r(double r_)
Definition: color.h:43
double get_g() const
Definition: color.h:39
double get_a() const
Definition: color.h:41
double get_r() const
Definition: color.h:38
double get_b() const
Definition: color.h:40
double r
Definition: color.h:20
void set_g(double g_)
Definition: color.h:44