From d9afc943ab013facd36dc048ef861679174f87f4 Mon Sep 17 00:00:00 2001 From: dooglus Date: Sat, 15 Sep 2007 20:10:31 +0000 Subject: [PATCH] Partially fix 1568818: Define mathematical operators so that we can animate gradients. git-svn-id: http://svn.voria.com/code@675 1f10aa63-cdf2-0310-b900-c93c546f37ac --- synfig-core/trunk/src/synfig/gradient.cpp | 83 +++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/synfig-core/trunk/src/synfig/gradient.cpp b/synfig-core/trunk/src/synfig/gradient.cpp index 11b2295..2411006 100644 --- a/synfig-core/trunk/src/synfig/gradient.cpp +++ b/synfig-core/trunk/src/synfig/gradient.cpp @@ -140,6 +140,89 @@ supersample_helper(const synfig::Gradient::CPoint &color1, const synfig::Gradien // assert(0); } +Gradient & +synfig::Gradient::operator+=(const Gradient &rhs) +{ + CPointList ret; + const_iterator iter1 = begin(), iter2 = rhs.begin(), left_same, right_same; + CPoint left, right; + if (iter1 != end()) left = *iter1; + if (iter2 != rhs.end()) right = *iter2; + if (iter1 != end() && iter2 != rhs.end()) + while(true) + { + if (left.pos < right.pos) + { + ret.push_back(CPoint(left.pos, left.color + rhs(left.pos))); + if(++iter1 == end()) break; + left=*iter1; + } + else if (left.pos > right.pos) + { + ret.push_back(CPoint(right.pos, right.color + (*this)(right.pos))); + if(++iter2 == rhs.end()) break; + right=*iter2; + } + else + { + for(left_same = iter1++; (*iter1).pos == left.pos; iter1++); + for(right_same = iter2++; (*iter2).pos == right.pos; iter2++); + if (iter1 == left_same+1 && iter2 == right_same+1) + ret.push_back(CPoint(left.pos, left.color + right.color)); + else + { + ret.push_back(CPoint(left.pos, left.color + right.color)); + ret.push_back(CPoint(left.pos, (*(iter1-1)).color + (*(iter2-1)).color)); + } + if (iter1 != end()) left=*iter1; + if (iter2 == rhs.end()) break; + right = *iter2; + if (iter1 == end()) break; + } + } + + if (iter1 != end()) + while(true) + { + ret.push_back(CPoint(left.pos, left.color + rhs(left.pos))); + if(++iter1 == end()) break; + left = *iter1; + } + + if (iter2 != rhs.end()) + while(true) + { + ret.push_back(CPoint(right.pos, right.color + (*this)(right.pos))); + if(++iter2 == rhs.end()) break; + right = *iter2; + } + + cpoints = ret; + return *this; +} + +Gradient & +synfig::Gradient::operator-=(const Gradient &rhs) +{ + return (*this)+=(rhs*-1); +} + +Gradient & +synfig::Gradient::operator*=(const float &rhs) +{ + for (iterator iter = cpoints.begin(); iter!=cpoints.end(); iter++) + (*iter).color *= rhs; + return *this; +} + +Gradient & +synfig::Gradient::operator/=(const float &rhs) +{ + for (iterator iter = cpoints.begin(); iter!=cpoints.end(); iter++) + (*iter).color /= rhs; + return *this; +} + Color synfig::Gradient::operator()(const Real &x,float supersample)const { -- 2.7.4