00001 /* === S Y N F I G ========================================================= */ 00022 /* ========================================================================= */ 00023 00024 /* === S T A R T =========================================================== */ 00025 00026 #ifndef __SYNFIG_GRADIENT_H 00027 #define __SYNFIG_GRADIENT_H 00028 00029 /* === H E A D E R S ======================================================= */ 00030 00031 #include "real.h" 00032 #include "color.h" 00033 #include <vector> 00034 #include <utility> 00035 #include "uniqueid.h" 00036 00037 /* === M A C R O S ========================================================= */ 00038 00039 /* === T Y P E D E F S ===================================================== */ 00040 00041 /* === C L A S S E S & S T R U C T S ======================================= */ 00042 00043 namespace synfig { 00044 00048 struct GradientCPoint : public UniqueID 00049 { 00050 Real pos; 00051 Color color; 00052 00053 bool operator<(const GradientCPoint &rhs)const { return pos<rhs.pos; } 00054 bool operator<(const Real &rhs)const { return pos<rhs; } 00055 00056 GradientCPoint() { } 00057 GradientCPoint(const Real &pos, const Color &color):pos(pos),color(color) { } 00058 }; // END of class GradientCPoint 00059 00060 00064 using namespace std; 00065 class Gradient 00066 { 00067 public: 00068 typedef GradientCPoint CPoint; 00069 typedef vector<CPoint> CPointList; 00070 typedef CPointList::const_iterator const_iterator; 00071 typedef CPointList::iterator iterator; 00072 typedef CPointList::const_reverse_iterator const_reverse_iterator; 00073 typedef CPointList::reverse_iterator reverse_iterator; 00074 private: 00075 CPointList cpoints; 00076 public: 00077 Gradient() { } 00078 00080 Gradient(const Color &c1, const Color &c2); 00081 00083 Gradient(const Color &c1, const Color &c2, const Color &c3); 00084 00086 void sync() { sort(); } 00087 00089 void sort(); 00090 00091 void push_back(const CPoint cpoint) { cpoints.push_back(cpoint); } 00092 iterator erase(iterator iter) { return cpoints.erase(iter); } 00093 bool empty()const { return cpoints.empty(); } 00094 size_t size()const { return cpoints.size(); } 00095 00096 iterator begin() { return cpoints.begin(); } 00097 iterator end() { return cpoints.end(); } 00098 reverse_iterator rbegin() { return cpoints.rbegin(); } 00099 reverse_iterator rend() { return cpoints.rend(); } 00100 const_iterator begin()const { return cpoints.begin(); } 00101 const_iterator end()const { return cpoints.end(); } 00102 const_reverse_iterator rbegin()const { return cpoints.rbegin(); } 00103 const_reverse_iterator rend()const { return cpoints.rend(); } 00104 00105 Gradient &operator+=(const Gradient &rhs); 00106 Gradient &operator-=(const Gradient &rhs); 00107 Gradient &operator*=(const float &rhs); 00108 Gradient &operator/=(const float &rhs); 00109 00110 Gradient operator+(const Gradient &rhs)const { return Gradient(*this)+=rhs; } 00111 Gradient operator-(const Gradient &rhs)const { return Gradient(*this)-=rhs; } 00112 Gradient operator*(const float &rhs)const { return Gradient(*this)*=rhs; } 00113 Gradient operator/(const float &rhs)const { return Gradient(*this)/=rhs; } 00114 00115 Color operator()(const Real &x, float supersample=0)const; 00116 00118 iterator proximity(const Real &x); 00119 00121 const_iterator proximity(const Real &x)const; 00122 00124 iterator find(const UniqueID &id); 00125 00127 const_iterator find(const UniqueID &id)const; 00128 }; // END of class Gradient 00129 00130 }; // END of namespace synfig 00131 00132 /* === E N D =============================================================== */ 00133 00134 #endif