synfig-core  1.0.3
cairocoloraccumulator.h
Go to the documentation of this file.
1 /* === S Y N F I G ========================================================= */
24 /* ========================================================================= */
25 
26 #ifndef __SYNFIG_COLOR_CAIROCOLORACUMULATOR_H
27 #define __SYNFIG_COLOR_CAIROCOLORACUMULATOR_H
28 
29 #include <synfig/color/common.h>
30 
31 namespace synfig {
32 
33 class CairoColor;
34 
36 {
37  friend class CairoColor;
38 public:
39  typedef float value_type;
40 
41 private:
42  value_type a_, r_, g_, b_;
43 
44 public:
45 
48  {
49  r_+=rhs.r_;
50  g_+=rhs.g_;
51  b_+=rhs.b_;
52  a_+=rhs.a_;
53  return *this;
54  }
55 
58  {
59  r_-=rhs.r_;
60  g_-=rhs.g_;
61  b_-=rhs.b_;
62  a_-=rhs.a_;
63  return *this;
64  }
65 
67  operator*=(const float &rhs)
68  {
69  r_*=rhs;
70  g_*=rhs;
71  b_*=rhs;
72  a_*=rhs;
73  return *this;
74  }
75 
77  operator/=(const float &rhs)
78  {
79  const float temp(value_type(1)/rhs);
80  r_*=temp;
81  g_*=temp;
82  b_*=temp;
83  a_*=temp;
84  return *this;
85  }
86 
89  { return CairoColorAccumulator(*this)+=rhs; }
90 
93  { return CairoColorAccumulator(*this)-=rhs; }
94 
96  operator*(const float &rhs)const
97  { return CairoColorAccumulator(*this)*=rhs; }
98 
100  operator/(const float &rhs)const
101  { return CairoColorAccumulator(*this)/=rhs; }
102 
103  bool
105  { return r_==rhs.r_ && g_==rhs.g_ && b_==rhs.b_ && a_!=rhs.a_; }
106 
107  bool
109  { return r_!=rhs.r_ || g_!=rhs.g_ || b_!=rhs.b_ || a_!=rhs.a_; }
110 
112  operator-()const
113  { return CairoColorAccumulator(-r_,-g_,-b_,-a_); }
114 
115  bool is_valid()const
116  { return !isnan(r_) && !isnan(g_) && !isnan(b_) && !isnan(a_); }
117 
118 public:
119  CairoColorAccumulator(): a_(), r_(), g_(), b_() { }
120 
125  CairoColorAccumulator(const value_type& R, const value_type& G, const value_type& B, const value_type& A=1):
126  a_(A),
127  r_(R),
128  g_(G),
129  b_(B) { }
130 
133  a_(c.a_),
134  r_(c.r_),
135  g_(c.g_),
136  b_(c.b_) { }
137 
140  a_(c.get_a()/CairoColor::range),
141  r_(c.get_r()/CairoColor::range),
142  g_(c.get_g()/CairoColor::range),
143  b_(c.get_b()/CairoColor::range) { }
144 
146  CairoColorAccumulator(int c): a_(c),r_(c), g_(c), b_(c) { }
147 
149  const value_type& get_r()const { return r_; }
150 
152  const value_type& get_g()const { return g_; }
153 
155  const value_type& get_b()const { return b_; }
156 
158  const value_type& get_a()const { return a_; }
159 
161  const value_type& get_alpha()const { return get_a(); }
162 
164  CairoColorAccumulator& set_r(const value_type& x) { r_ = x; return *this; }
165 
167  CairoColorAccumulator& set_g(const value_type& x) { g_ = x; return *this; }
168 
170  CairoColorAccumulator& set_b(const value_type& x) { b_ = x; return *this; }
171 
173  CairoColorAccumulator& set_a(const value_type& x) { a_ = x; return *this; }
174 
177 };
178 
179 
180 } // synfig namespace
181 
182 #endif // __SYNFIG_COLOR_CAIROCOLORACUMULATOR_H