1 /* === S Y N F I G ========================================================= */
3 ** \brief Color Gradient Class
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === S T A R T =========================================================== */
25 #ifndef __SYNFIG_GRADIENT_H
26 #define __SYNFIG_GRADIENT_H
28 /* === H E A D E R S ======================================================= */
36 /* === M A C R O S ========================================================= */
38 /* === T Y P E D E F S ===================================================== */
40 /* === C L A S S E S & S T R U C T S ======================================= */
44 /*! \struct GradientCPoint
47 struct GradientCPoint : public UniqueID
52 bool operator<(const GradientCPoint &rhs)const { return pos<rhs.pos; }
53 bool operator<(const Real &rhs)const { return pos<rhs; }
56 GradientCPoint(const Real &pos, const Color &color):pos(pos),color(color) { }
57 }; // END of class GradientCPoint
61 ** \brief Color Gradient Class
67 typedef GradientCPoint CPoint;
68 typedef vector<GradientCPoint>::const_iterator const_iterator;
69 typedef vector<GradientCPoint>::iterator iterator;
70 typedef vector<GradientCPoint>::const_reverse_iterator const_reverse_iterator;
71 typedef vector<GradientCPoint>::reverse_iterator reverse_iterator;
73 vector<GradientCPoint> cpoints;
77 //! Two-Tone Color Gradient Convenience Constructor
78 Gradient(const Color &c1, const Color &c2);
80 //! Three-Tone Color Gradient Convenience Constructor
81 Gradient(const Color &c1, const Color &c2, const Color &c3);
83 //! Alias for sort (Implemented for consistency)
84 void sync() { sort(); }
86 //! You should call this function after changing stuff.
89 void push_back(const GradientCPoint cpoint) { cpoints.push_back(cpoint); }
90 iterator erase(iterator iter) { return cpoints.erase(iter); }
91 bool empty()const { return cpoints.empty(); }
92 size_t size()const { return cpoints.size(); }
94 iterator begin() { return cpoints.begin(); }
95 iterator end() { return cpoints.end(); }
96 reverse_iterator rbegin() { return cpoints.rbegin(); }
97 reverse_iterator rend() { return cpoints.rend(); }
98 const_iterator begin()const { return cpoints.begin(); }
99 const_iterator end()const { return cpoints.end(); }
100 const_reverse_iterator rbegin()const { return cpoints.rbegin(); }
101 const_reverse_iterator rend()const { return cpoints.rend(); }
103 Color operator()(const Real &x, float supersample=0)const;
105 //! Returns the iterator of the CPoint closest to \a x
106 iterator proximity(const Real &x);
108 //! Returns the const_iterator of the CPoint closest to \a x
109 const_iterator proximity(const Real &x)const;
111 //! Returns the iterator of the CPoint with UniqueID \a id
112 iterator find(const UniqueID &id);
114 //! Returns the const_iterator of the CPoint with UniqueID \a id
115 const_iterator find(const UniqueID &id)const;
116 }; // END of class Gradient
118 }; // END of namespace synfig
120 /* === E N D =============================================================== */