more updates
[synfig.git] / synfig-core / trunk / src / synfig / gradient.h
1 /* === S I N F G =========================================================== */
2 /*!     \file gradient.h
3 **      \brief Color Gradient Class
4 **
5 **      $Id: gradient.h,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === S T A R T =========================================================== */
23
24 #ifndef __SINFG_GRADIENT_H
25 #define __SINFG_GRADIENT_H
26
27 /* === H E A D E R S ======================================================= */
28
29 #include "real.h"
30 #include "color.h"
31 #include <vector>
32 #include <utility>
33 #include "uniqueid.h"
34
35 /* === M A C R O S ========================================================= */
36
37 /* === T Y P E D E F S ===================================================== */
38
39 /* === C L A S S E S & S T R U C T S ======================================= */
40
41 namespace sinfg {
42
43 /*! \struct GradientCPoint
44 **      \brief \todo
45 */
46 struct GradientCPoint : public UniqueID
47 {
48         Real pos;
49         Color color;
50         
51         bool operator<(const GradientCPoint &rhs)const { return pos<rhs.pos; }
52         bool operator<(const Real &rhs)const { return pos<rhs; }
53         
54         GradientCPoint() { }
55         GradientCPoint(const Real &pos, const Color &color):pos(pos),color(color) { }
56 }; // END of class GradientCPoint
57
58         
59 /*! \class Gradient
60 **      \brief Color Gradient Class
61 */
62 class Gradient : public std::vector<GradientCPoint>
63 {
64 public:
65         typedef GradientCPoint CPoint;
66 private:
67         
68 public:
69         Gradient() { }
70         
71         //! Two-Tone Color Gradient Convience Constructor
72         Gradient(const Color &c1, const Color &c2);
73
74         //! Three-Tone Color Gradient Convience Constructor
75         Gradient(const Color &c1, const Color &c2, const Color &c3);
76
77         //! Alias for sort (Implemented for consistancy)
78         void sync() { sort(); }
79
80         //! You should call this function after changing stuff.
81         void sort();
82         
83         Color operator()(const Real &x, float supersample=0)const;
84
85         //! Returns the iterator of the CPoint closest to \a x
86         iterator proximity(const Real &x);
87
88         //! Returns the const_iterator of the CPoint closest to \a x
89         const_iterator proximity(const Real &x)const;
90
91         //! Returns the iterator of the CPoint with UniqueID \a id
92         iterator find(const UniqueID &id);
93         
94         //! Returns the const_iterator of the CPoint with UniqueID \a id
95         const_iterator find(const UniqueID &id)const;
96 }; // END of class Gradient
97         
98 }; // END of namespace sinfg
99
100 /* === E N D =============================================================== */
101
102 #endif