Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / 0.61.09 / src / synfig / gradient.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file gradient.h
3 **      \brief Color Gradient Class
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === S T A R T =========================================================== */
25
26 #ifndef __SYNFIG_GRADIENT_H
27 #define __SYNFIG_GRADIENT_H
28
29 /* === H E A D E R S ======================================================= */
30
31 #include "real.h"
32 #include "color.h"
33 #include <vector>
34 #include <utility>
35 #include "uniqueid.h"
36
37 /* === M A C R O S ========================================================= */
38
39 /* === T Y P E D E F S ===================================================== */
40
41 /* === C L A S S E S & S T R U C T S ======================================= */
42
43 namespace synfig {
44
45 /*! \struct GradientCPoint
46 **      \brief \todo
47 */
48 struct GradientCPoint : public UniqueID
49 {
50         Real pos;
51         Color color;
52
53         bool operator<(const GradientCPoint &rhs)const { return pos<rhs.pos; }
54         bool operator<(const Real &rhs)const { return pos<rhs; }
55
56         GradientCPoint() { }
57         GradientCPoint(const Real &pos, const Color &color):pos(pos),color(color) { }
58 }; // END of class GradientCPoint
59
60
61 /*! \class Gradient
62 **      \brief Color Gradient Class
63 */
64 using namespace std;
65 class Gradient
66 {
67 public:
68         typedef GradientCPoint CPoint;
69         typedef vector<CPoint> CPointList;
70         typedef CPointList::const_iterator                      const_iterator;
71         typedef CPointList::iterator                            iterator;
72         typedef CPointList::const_reverse_iterator      const_reverse_iterator;
73         typedef CPointList::reverse_iterator            reverse_iterator;
74 private:
75         CPointList cpoints;
76 public:
77         Gradient() { }
78
79         //! Two-Tone Color Gradient Convenience Constructor
80         Gradient(const Color &c1, const Color &c2);
81
82         //! Three-Tone Color Gradient Convenience Constructor
83         Gradient(const Color &c1, const Color &c2, const Color &c3);
84
85         //! Alias for sort (Implemented for consistency)
86         void sync() { sort(); }
87
88         //! You should call this function after changing stuff.
89         void sort();
90
91         void push_back(const CPoint cpoint) { cpoints.push_back(cpoint); }
92         iterator erase(iterator iter) { return cpoints.erase(iter); }
93         bool empty()const { return cpoints.empty(); }
94         size_t size()const { return cpoints.size(); }
95
96         iterator begin() { return cpoints.begin(); }
97         iterator end() { return cpoints.end(); }
98         reverse_iterator rbegin() { return cpoints.rbegin(); }
99         reverse_iterator rend() { return cpoints.rend(); }
100         const_iterator begin()const { return cpoints.begin(); }
101         const_iterator end()const { return cpoints.end(); }
102         const_reverse_iterator rbegin()const { return cpoints.rbegin(); }
103         const_reverse_iterator rend()const { return cpoints.rend(); }
104
105         Gradient &operator+=(const Gradient &rhs);
106         Gradient &operator-=(const Gradient &rhs);
107         Gradient &operator*=(const float    &rhs);
108         Gradient &operator/=(const float    &rhs);
109
110         Gradient operator+(const Gradient &rhs)const { return Gradient(*this)+=rhs; }
111         Gradient operator-(const Gradient &rhs)const { return Gradient(*this)-=rhs; }
112         Gradient operator*(const float    &rhs)const { return Gradient(*this)*=rhs; }
113         Gradient operator/(const float    &rhs)const { return Gradient(*this)/=rhs; }
114
115         Color operator()(const Real &x, float supersample=0)const;
116
117         //! Returns the iterator of the CPoint closest to \a x
118         iterator proximity(const Real &x);
119
120         //! Returns the const_iterator of the CPoint closest to \a x
121         const_iterator proximity(const Real &x)const;
122
123         //! Returns the iterator of the CPoint with UniqueID \a id
124         iterator find(const UniqueID &id);
125
126         //! Returns the const_iterator of the CPoint with UniqueID \a id
127         const_iterator find(const UniqueID &id)const;
128 }; // END of class Gradient
129
130 }; // END of namespace synfig
131
132 /* === E N D =============================================================== */
133
134 #endif