From: dooglus Date: Thu, 13 Sep 2007 16:53:01 +0000 (+0000) Subject: Add a new type of valuenode conversion for gradients: "repeat gradient" which lets... X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=83fc7407cf368b3f537dee4509b404f73b766dfe;p=synfig.git Add a new type of valuenode conversion for gradients: "repeat gradient" which lets you loop a gradient a specified number of times. See wiki.synfig.com/Convert#Repeat_Gradient . git-svn-id: http://svn.voria.com/code@666 1f10aa63-cdf2-0310-b900-c93c546f37ac --- diff --git a/synfig-core/trunk/src/synfig/Makefile.am b/synfig-core/trunk/src/synfig/Makefile.am index 980956d..470da2e 100644 --- a/synfig-core/trunk/src/synfig/Makefile.am +++ b/synfig-core/trunk/src/synfig/Makefile.am @@ -16,8 +16,8 @@ TARGETSOURCES=target_scanline.cpp target_tile.cpp target_multi.cpp target_null.c IMPORTERHEADERS=listimporter.h IMPORTERSOURCES=listimporter.cpp -VALUENODEHEADERS=valuenode_sine.h valuenode_radialcomposite.h valuenode_bline.h valuenode_segcalcvertex.h valuenode_segcalctangent.h valuenode_twotone.h valuenode_stripes.h valuenode_subtract.h valuenode_const.h valuenode_reference.h valuenode_linear.h valuenode_composite.h valuenode_dynamiclist.h valuenode_animated.h valuenode_scale.h valuenode_timedswap.h valuenode_gradientrotate.h -VALUENODESOURCES=valuenode_sine.cpp valuenode_radialcomposite.cpp valuenode_bline.cpp valuenode_segcalcvertex.cpp valuenode_segcalctangent.cpp valuenode_twotone.cpp valuenode_stripes.cpp valuenode_subtract.cpp valuenode_const.cpp valuenode_reference.cpp valuenode_linear.cpp valuenode_composite.cpp valuenode_dynamiclist.cpp valuenode_animated.cpp valuenode_scale.cpp valuenode_timedswap.cpp valuenode_gradientrotate.cpp +VALUENODEHEADERS=valuenode_sine.h valuenode_radialcomposite.h valuenode_bline.h valuenode_segcalcvertex.h valuenode_segcalctangent.h valuenode_twotone.h valuenode_repeat_gradient.h valuenode_stripes.h valuenode_subtract.h valuenode_const.h valuenode_reference.h valuenode_linear.h valuenode_composite.h valuenode_dynamiclist.h valuenode_animated.h valuenode_scale.h valuenode_timedswap.h valuenode_gradientrotate.h +VALUENODESOURCES=valuenode_sine.cpp valuenode_radialcomposite.cpp valuenode_bline.cpp valuenode_segcalcvertex.cpp valuenode_segcalctangent.cpp valuenode_twotone.cpp valuenode_repeat_gradient.cpp valuenode_stripes.cpp valuenode_subtract.cpp valuenode_const.cpp valuenode_reference.cpp valuenode_linear.cpp valuenode_composite.cpp valuenode_dynamiclist.cpp valuenode_animated.cpp valuenode_scale.cpp valuenode_timedswap.cpp valuenode_gradientrotate.cpp VALUEHEADERS=blinepoint.h gradient.h value.h VALUESOURCES=blinepoint.cpp gradient.cpp value.cpp diff --git a/synfig-core/trunk/src/synfig/valuenode.cpp b/synfig-core/trunk/src/synfig/valuenode.cpp index ee0feb8..cd7a7b5 100644 --- a/synfig-core/trunk/src/synfig/valuenode.cpp +++ b/synfig-core/trunk/src/synfig/valuenode.cpp @@ -44,6 +44,7 @@ #include "valuenode_scale.h" #include "valuenode_segcalctangent.h" #include "valuenode_segcalcvertex.h" +#include "valuenode_repeat_gradient.h" #include "valuenode_stripes.h" #include "valuenode_subtract.h" #include "valuenode_timedswap.h" @@ -102,6 +103,7 @@ ValueNode::subsys_init() ADD_VALUENODE(ValueNode_Composite, "composite", _("Composite") ); ADD_VALUENODE(ValueNode_RadialComposite,"radial_composite", _("Radial Composite") ); ADD_VALUENODE(ValueNode_Reference, "reference", _("Reference") ); + ADD_VALUENODE(ValueNode_Repeat_Gradient,"repeat_gradient", _("Repeat Gradient") ); ADD_VALUENODE(ValueNode_Scale, "scale", _("Scale") ); ADD_VALUENODE(ValueNode_SegCalcTangent, "segcalctangent", _("Segment Tangent") ); ADD_VALUENODE(ValueNode_SegCalcVertex, "segcalcvertex", _("Segment Vertex") ); diff --git a/synfig-core/trunk/src/synfig/valuenode_repeat_gradient.cpp b/synfig-core/trunk/src/synfig/valuenode_repeat_gradient.cpp new file mode 100644 index 0000000..30a4d01 --- /dev/null +++ b/synfig-core/trunk/src/synfig/valuenode_repeat_gradient.cpp @@ -0,0 +1,244 @@ +/* === S Y N F I G ========================================================= */ +/*! \file valuenode_repeat_gradient.cpp +** \brief Template File +** +** $Id: valuenode_repeat_gradient.cpp 604 2007-09-05 14:29:02Z dooglus $ +** +** \legal +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === H E A D E R S ======================================================= */ + +#ifdef USING_PCH +# include "pch.h" +#else +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "general.h" +#include "valuenode_repeat_gradient.h" +#include "valuenode_const.h" +#include +#include "gradient.h" + +#endif + +/* === U S I N G =========================================================== */ + +using namespace std; +using namespace etl; +using namespace synfig; + +/* === M A C R O S ========================================================= */ + +/* === G L O B A L S ======================================================= */ + +/* === P R O C E D U R E S ================================================= */ + +/* === M E T H O D S ======================================================= */ + +synfig::ValueNode_Repeat_Gradient::ValueNode_Repeat_Gradient():LinkableValueNode(synfig::ValueBase::TYPE_GRADIENT) +{ + set_link("gradient",ValueNode_Const::create(Gradient())); + set_link("count",count_=ValueNode_Const::create(int(3))); + set_link("width",ValueNode_Const::create(0.5)); +} + +LinkableValueNode* +ValueNode_Repeat_Gradient::create_new()const +{ + return new ValueNode_Repeat_Gradient(); +} + +ValueNode_Repeat_Gradient* +ValueNode_Repeat_Gradient::create(const ValueBase& x) +{ + ValueBase::Type id(x.get_type()); + + if(id!=ValueBase::TYPE_GRADIENT) + { + assert(0); + throw runtime_error("synfig::ValueNode_Repeat_Gradient:Bad type "+ValueBase::type_name(id)); + } + + ValueNode_Repeat_Gradient* value_node=new ValueNode_Repeat_Gradient(); + value_node->set_gradient(ValueNode_Const::create(x.get(Gradient()))); + + assert(value_node->get_type()==id); + + return value_node; +} + +synfig::ValueNode_Repeat_Gradient::~ValueNode_Repeat_Gradient() +{ + unlink_all(); +} + +bool +synfig::ValueNode_Repeat_Gradient::set_gradient(ValueNode::Handle a) +{ + if(a->get_type()!=ValueBase::TYPE_GRADIENT) + return false; + + gradient_=a; + + return true; +} + +bool +synfig::ValueNode_Repeat_Gradient::set_width(ValueNode::Handle x) +{ + if(x->get_type()!=ValueBase::TYPE_REAL) + return false; + + width_=x; + + return true; +} + +bool +synfig::ValueNode_Repeat_Gradient::set_count(ValueNode::Handle b) +{ + if(b->get_type()!=ValueBase::TYPE_INTEGER) + return false; + count_=b; + return true; +} + +synfig::ValueBase +synfig::ValueNode_Repeat_Gradient::operator()(Time t)const +{ + const int count((*count_)(t).get(int())); + int i; + Gradient ret; + + if(count<=0) + return ret; + + const Gradient gradient((*gradient_)(t).get(Gradient())); + const float width(max(0.0,min(1.0,(*width_)(t).get(Real())))); + + 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; + for(i=0;ipos,iter->color)); + pos+=gradient_width_a; + if (width != 1.0) + for(riter=gradient.rbegin();riter!=gradient.rend();riter++) + ret.push_back(Gradient::CPoint(pos+gradient_width_b*(1-(riter->pos)),riter->color)); + } + return ret; +} + +bool +ValueNode_Repeat_Gradient::set_link_vfunc(int i,ValueNode::Handle x) +{ + assert(i>=0 && i=0 && i=0 && i=0 && i Handle; + typedef etl::handle ConstHandle; + +protected: + + ValueNode_Repeat_Gradient(); + +private: + + ValueNode::RHandle gradient_; + ValueNode::RHandle count_; + ValueNode::RHandle width_; + +public: + + virtual ~ValueNode_Repeat_Gradient(); + +// static Handle create(ValueBase::Type id=ValueBase::TYPE_GRADIENT); + + bool set_gradient(ValueNode::Handle a); + ValueNode::Handle get_gradient()const { return gradient_; } + + bool set_count(ValueNode::Handle b); + ValueNode::Handle get_count()const { return count_; } + + bool set_width(ValueNode::Handle x); + + + virtual bool set_link_vfunc(int i,ValueNode::Handle x); + + virtual ValueNode::LooseHandle get_link_vfunc(int i)const; + + virtual int link_count()const; + + virtual String link_local_name(int i)const; + virtual String link_name(int i)const; + virtual int get_link_index_from_name(const String &name)const; + + virtual ValueBase operator()(Time t)const; + + virtual String get_name()const; + virtual String get_local_name()const; + +// static bool check_type(const ValueBase::Type &type); + + LinkableValueNode* create_new()const; + +public: + using synfig::LinkableValueNode::get_link_vfunc; + using synfig::LinkableValueNode::set_link_vfunc; + static bool check_type(ValueBase::Type type); + static ValueNode_Repeat_Gradient* create(const ValueBase &x=ValueBase::TYPE_GRADIENT); +}; // END of class ValueNode_Repeat_Gradient + +}; // END of namespace synfig + +/* === E N D =============================================================== */ + +#endif