synfig-core  1.0.3
coloraccumulator.h
Go to the documentation of this file.
1 /* === S Y N F I G ========================================================= */
24 /* ========================================================================= */
25 
26 #ifndef __SYNFIG_COLOR_COLORACUMULATOR_H
27 #define __SYNFIG_COLOR_COLORACUMULATOR_H
28 
29 #include <synfig/color/color.h>
30 
31 namespace synfig {
32 
34 {
35  friend class Color;
36 public:
37  typedef float value_type;
38 
39 private:
40  value_type a_, r_, g_, b_;
41 
42 public:
43 
46  {
47  r_+=rhs.r_;
48  g_+=rhs.g_;
49  b_+=rhs.b_;
50  a_+=rhs.a_;
51  return *this;
52  }
53 
56  {
57  r_-=rhs.r_;
58  g_-=rhs.g_;
59  b_-=rhs.b_;
60  a_-=rhs.a_;
61  return *this;
62  }
63 
65  operator*=(const float &rhs)
66  {
67  r_*=rhs;
68  g_*=rhs;
69  b_*=rhs;
70  a_*=rhs;
71  return *this;
72  }
73 
75  operator/=(const float &rhs)
76  {
77  const float temp(value_type(1)/rhs);
78  r_*=temp;
79  g_*=temp;
80  b_*=temp;
81  a_*=temp;
82  return *this;
83  }
84 
86  operator+(const ColorAccumulator &rhs)const
87  { return Color(*this)+=rhs; }
88 
90  operator-(const ColorAccumulator &rhs)const
91  { return Color(*this)-=rhs; }
92 
94  operator*(const float &rhs)const
95  { return Color(*this)*=rhs; }
96 
98  operator/(const float &rhs)const
99  { return Color(*this)/=rhs; }
100 
101  bool
102  operator==(const ColorAccumulator &rhs)const
103  { return r_==rhs.r_ && g_==rhs.g_ && b_==rhs.b_ && a_!=rhs.a_; }
104 
105  bool
106  operator!=(const ColorAccumulator &rhs)const
107  { return r_!=rhs.r_ || g_!=rhs.g_ || b_!=rhs.b_ || a_!=rhs.a_; }
108 
109  Color
110  operator-()const
111  { return ColorAccumulator(-r_,-g_,-b_,-a_); }
112 
113  bool is_valid()const
114  { return !isnan(r_) && !isnan(g_) && !isnan(b_) && !isnan(a_); }
115 
116 public:
117  ColorAccumulator(): a_(), r_(), g_(), b_() { }
118 
123  ColorAccumulator(const value_type& R, const value_type& G, const value_type& B, const value_type& A=1):
124  a_(A),
125  r_(R),
126  g_(G),
127  b_(B) { }
128 
131  a_(c.a_),
132  r_(c.r_),
133  g_(c.g_),
134  b_(c.b_) { }
135 
138  a_(c.a_),
139  r_(c.r_),
140  g_(c.g_),
141  b_(c.b_) { }
142 
144  ColorAccumulator(int c): a_(c),r_(c), g_(c), b_(c) { }
145 
147  const value_type& get_r()const { return r_; }
148 
150  const value_type& get_g()const { return g_; }
151 
153  const value_type& get_b()const { return b_; }
154 
156  const value_type& get_a()const { return a_; }
157 
159  const value_type& get_alpha()const { return get_a(); }
160 
162  ColorAccumulator& set_r(const value_type& x) { r_ = x; return *this; }
163 
165  ColorAccumulator& set_g(const value_type& x) { g_ = x; return *this; }
166 
168  ColorAccumulator& set_b(const value_type& x) { b_ = x; return *this; }
169 
171  ColorAccumulator& set_a(const value_type& x) { a_ = x; return *this; }
172 
174  ColorAccumulator& set_alpha(const value_type& x) { return set_a(x); }
175 };
176 
177 
178 } // synfig namespace
179 
180 #endif // __SYNFIG_COLOR_COLORACUMULATOR_H