From 427c5079add40efe774ca0975a1ba05a4956584b Mon Sep 17 00:00:00 2001 From: dooglus Date: Thu, 13 Sep 2007 22:31:57 +0000 Subject: [PATCH] Allow the user to specify the start and end colors when repeating a gradient. git-svn-id: http://svn.voria.com/code@667 1f10aa63-cdf2-0310-b900-c93c546f37ac --- .../trunk/src/synfig/valuenode_repeat_gradient.cpp | 77 +++++++++++++++++++++- .../trunk/src/synfig/valuenode_repeat_gradient.h | 8 +++ 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/synfig-core/trunk/src/synfig/valuenode_repeat_gradient.cpp b/synfig-core/trunk/src/synfig/valuenode_repeat_gradient.cpp index 30a4d01..45a8d54 100644 --- a/synfig-core/trunk/src/synfig/valuenode_repeat_gradient.cpp +++ b/synfig-core/trunk/src/synfig/valuenode_repeat_gradient.cpp @@ -33,6 +33,7 @@ #include "valuenode_repeat_gradient.h" #include "valuenode_const.h" #include +#include "color.h" #include "gradient.h" #endif @@ -56,6 +57,10 @@ synfig::ValueNode_Repeat_Gradient::ValueNode_Repeat_Gradient():LinkableValueNode set_link("gradient",ValueNode_Const::create(Gradient())); set_link("count",count_=ValueNode_Const::create(int(3))); set_link("width",ValueNode_Const::create(0.5)); + set_link("specify_start",ValueNode_Const::create(true)); + set_link("specify_end",ValueNode_Const::create(true)); + set_link("start_color",ValueNode_Const::create(Color::alpha())); + set_link("end_color",ValueNode_Const::create(Color::alpha())); } LinkableValueNode* @@ -119,6 +124,42 @@ synfig::ValueNode_Repeat_Gradient::set_count(ValueNode::Handle b) return true; } +bool +synfig::ValueNode_Repeat_Gradient::set_specify_start(ValueNode::Handle a) +{ + if(a->get_type()!=ValueBase::TYPE_BOOL) + return false; + specify_start_=a; + return true; +} + +bool +synfig::ValueNode_Repeat_Gradient::set_specify_end(ValueNode::Handle a) +{ + if(a->get_type()!=ValueBase::TYPE_BOOL) + return false; + specify_end_=a; + return true; +} + +bool +synfig::ValueNode_Repeat_Gradient::set_start_color(ValueNode::Handle a) +{ + if(a->get_type()!=ValueBase::TYPE_COLOR) + return false; + start_color_=a; + return true; +} + +bool +synfig::ValueNode_Repeat_Gradient::set_end_color(ValueNode::Handle a) +{ + if(a->get_type()!=ValueBase::TYPE_COLOR) + return false; + end_color_=a; + return true; +} + synfig::ValueBase synfig::ValueNode_Repeat_Gradient::operator()(Time t)const { @@ -131,12 +172,16 @@ synfig::ValueNode_Repeat_Gradient::operator()(Time t)const const Gradient gradient((*gradient_)(t).get(Gradient())); const float width(max(0.0,min(1.0,(*width_)(t).get(Real())))); + const bool specify_start((*specify_start_)(t).get(bool())); + const bool specify_end((*specify_end_)(t).get(bool())); const float gradient_width_a(width/count); const float gradient_width_b((1.0-width)/count); Gradient::const_iterator iter; Gradient::const_reverse_iterator riter; + if (specify_start) + ret.push_back(Gradient::CPoint(0,(*start_color_)(t).get(Color()))); for(i=0;ipos)),riter->color)); } + if (specify_end) + ret.push_back(Gradient::CPoint(1,(*end_color_)(t).get(Color()))); return ret; } @@ -166,6 +213,18 @@ ValueNode_Repeat_Gradient::set_link_vfunc(int i,ValueNode::Handle x) case 2: if(set_width(x)) { signal_child_changed()(i);signal_value_changed()(); return true; } else { return false; } + case 3: + if(set_specify_start(x)) { signal_child_changed()(i);signal_value_changed()(); return true; } + else { return false; } + case 4: + if(set_specify_end(x)) { signal_child_changed()(i);signal_value_changed()(); return true; } + else { return false; } + case 5: + if(set_start_color(x)) { signal_child_changed()(i);signal_value_changed()(); return true; } + else { return false; } + case 6: + if(set_end_color(x)) { signal_child_changed()(i);signal_value_changed()(); return true; } + else { return false; } } return false; @@ -180,6 +239,10 @@ ValueNode_Repeat_Gradient::get_link_vfunc(int i)const case 0: return gradient_; case 1: return count_; case 2: return width_; + case 3: return specify_start_; + case 4: return specify_end_; + case 5: return start_color_; + case 6: return end_color_; default: return 0; } } @@ -187,7 +250,7 @@ ValueNode_Repeat_Gradient::get_link_vfunc(int i)const int ValueNode_Repeat_Gradient::link_count()const { - return 3; + return 7; } String @@ -199,6 +262,10 @@ ValueNode_Repeat_Gradient::link_local_name(int i)const case 0: return _("Gradient"); case 1: return _("Count"); case 2: return _("Width"); + case 3: return _("Specify Start"); + case 4: return _("Specify End"); + case 5: return _("Start Color"); + case 6: return _("End Color"); default: return String(); } } @@ -212,6 +279,10 @@ ValueNode_Repeat_Gradient::link_name(int i)const case 0: return "gradient"; case 1: return "count"; case 2: return "width"; + case 3: return "specify_start"; + case 4: return "specify_end"; + case 5: return "start_color"; + case 6: return "end_color"; default: return String(); } } @@ -222,6 +293,10 @@ ValueNode_Repeat_Gradient::get_link_index_from_name(const String &name)const if(name=="gradient") return 0; if(name=="count") return 1; if(name=="width") return 2; + if(name=="specify_start") return 3; + if(name=="specify_end") return 4; + if(name=="start_color") return 5; + if(name=="end_color") return 6; throw Exception::BadLinkName(name); } diff --git a/synfig-core/trunk/src/synfig/valuenode_repeat_gradient.h b/synfig-core/trunk/src/synfig/valuenode_repeat_gradient.h index 83658df..95555ef 100644 --- a/synfig-core/trunk/src/synfig/valuenode_repeat_gradient.h +++ b/synfig-core/trunk/src/synfig/valuenode_repeat_gradient.h @@ -49,6 +49,10 @@ private: ValueNode::RHandle gradient_; ValueNode::RHandle count_; ValueNode::RHandle width_; + ValueNode::RHandle specify_start_; + ValueNode::RHandle specify_end_; + ValueNode::RHandle start_color_; + ValueNode::RHandle end_color_; public: @@ -63,6 +67,10 @@ public: ValueNode::Handle get_count()const { return count_; } bool set_width(ValueNode::Handle x); + bool set_specify_start(ValueNode::Handle a); + bool set_specify_end(ValueNode::Handle a); + bool set_start_color(ValueNode::Handle a); + bool set_end_color(ValueNode::Handle a); virtual bool set_link_vfunc(int i,ValueNode::Handle x); -- 2.7.4