Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_06 / 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 **
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.
14 **
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.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === S T A R T =========================================================== */
24
25 #ifndef __SYNFIG_GRADIENT_H
26 #define __SYNFIG_GRADIENT_H
27
28 /* === H E A D E R S ======================================================= */
29
30 #include "real.h"
31 #include "color.h"
32 #include <vector>
33 #include <utility>
34 #include "uniqueid.h"
35
36 /* === M A C R O S ========================================================= */
37
38 /* === T Y P E D E F S ===================================================== */
39
40 /* === C L A S S E S & S T R U C T S ======================================= */
41
42 namespace synfig {
43
44 /*! \struct GradientCPoint
45 **      \brief \todo
46 */
47 struct GradientCPoint : public UniqueID
48 {
49         Real pos;
50         Color color;
51
52         bool operator<(const GradientCPoint &rhs)const { return pos<rhs.pos; }
53         bool operator<(const Real &rhs)const { return pos<rhs; }
54
55         GradientCPoint() { }
56         GradientCPoint(const Real &pos, const Color &color):pos(pos),color(color) { }
57 }; // END of class GradientCPoint
58
59
60 /*! \class Gradient
61 **      \brief Color Gradient Class
62 */
63 class Gradient : public std::vector<GradientCPoint>
64 {
65 public:
66         typedef GradientCPoint CPoint;
67 private:
68
69 public:
70         Gradient() { }
71
72         //! Two-Tone Color Gradient Convience Constructor
73         Gradient(const Color &c1, const Color &c2);
74
75         //! Three-Tone Color Gradient Convience Constructor
76         Gradient(const Color &c1, const Color &c2, const Color &c3);
77
78         //! Alias for sort (Implemented for consistancy)
79         void sync() { sort(); }
80
81         //! You should call this function after changing stuff.
82         void sort();
83
84         Color operator()(const Real &x, float supersample=0)const;
85
86         //! Returns the iterator of the CPoint closest to \a x
87         iterator proximity(const Real &x);
88
89         //! Returns the const_iterator of the CPoint closest to \a x
90         const_iterator proximity(const Real &x)const;
91
92         //! Returns the iterator of the CPoint with UniqueID \a id
93         iterator find(const UniqueID &id);
94
95         //! Returns the const_iterator of the CPoint with UniqueID \a id
96         const_iterator find(const UniqueID &id)const;
97 }; // END of class Gradient
98
99 }; // END of namespace synfig
100
101 /* === E N D =============================================================== */
102
103 #endif