From: dooglus Date: Sat, 22 Sep 2007 23:45:35 +0000 (+0000) Subject: Added a new valuenode type for real values: 'Exponent'. Given a real value, it sets... X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=d8a0d032dc97e5c058ef37b79e245689b2ae7c10;p=synfig.git Added a new valuenode type for real values: 'Exponent'. Given a real value, it sets its value to e^(value). git-svn-id: http://svn.voria.com/code@739 1f10aa63-cdf2-0310-b900-c93c546f37ac --- diff --git a/synfig-core/trunk/src/synfig/Makefile.am b/synfig-core/trunk/src/synfig/Makefile.am index 470da2e..2c62161 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_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 +VALUENODEHEADERS=valuenode_exp.h 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_exp.cpp 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 5e23fc7..61714a2 100644 --- a/synfig-core/trunk/src/synfig/valuenode.cpp +++ b/synfig-core/trunk/src/synfig/valuenode.cpp @@ -54,6 +54,7 @@ #include "valuenode_radialcomposite.h" #include "valuenode_gradientrotate.h" #include "valuenode_sine.h" +#include "valuenode_exp.h" #include "layer.h" @@ -115,6 +116,7 @@ ValueNode::subsys_init() ADD_VALUENODE2(ValueNode_DynamicList, "dynamic_list", _("Dynamic List") ); ADD_VALUENODE(ValueNode_GradientRotate, "gradient_rotate", _("Gradient Rotate") ); ADD_VALUENODE(ValueNode_Sine, "sine", _("Sine") ); + ADD_VALUENODE(ValueNode_Exp, "exp", _("Exponential") ); #undef ADD_VALUENODE #undef ADD_VALUENODE2 diff --git a/synfig-core/trunk/src/synfig/valuenode_exp.cpp b/synfig-core/trunk/src/synfig/valuenode_exp.cpp new file mode 100644 index 0000000..b553b1b --- /dev/null +++ b/synfig-core/trunk/src/synfig/valuenode_exp.cpp @@ -0,0 +1,178 @@ +/* === S Y N F I G ========================================================= */ +/*! \file valuenode_exp.cpp +** \brief Template File +** +** $Id$ +** +** \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 "valuenode_exp.h" +#include "valuenode_const.h" +#include "general.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 ======================================================= */ + +ValueNode_Exp::ValueNode_Exp(const ValueBase &value): + LinkableValueNode(value.get_type()) +{ + switch(value.get_type()) + { + case ValueBase::TYPE_REAL: + set_link("exp",ValueNode_Const::create(Real(1))); + set_link("scale",ValueNode_Const::create(value.get(Real()))); + break; + default: + throw Exception::BadType(ValueBase::type_name(value.get_type())); + } + + DCAST_HACK_ENABLE(); +} + +LinkableValueNode* +ValueNode_Exp::create_new()const +{ + return new ValueNode_Exp(get_type()); +} + +ValueNode_Exp* +ValueNode_Exp::create(const ValueBase &x) +{ + return new ValueNode_Exp(x); +} + +ValueNode_Exp::~ValueNode_Exp() +{ + unlink_all(); +} + +ValueBase +ValueNode_Exp::operator()(Time t)const +{ + return (exp((*exp_)(t).get(Real())) * + (*scale_)(t).get(Real())); +} + +String +ValueNode_Exp::get_name()const +{ + return "exp"; +} + +String +ValueNode_Exp::get_local_name()const +{ + return _("Exponential"); +} + +bool +ValueNode_Exp::set_link_vfunc(int i,ValueNode::Handle x) +{ + assert(i==0 || i==1); + if(i==0) + { + exp_=x; + signal_child_changed()(i);signal_value_changed()(); + return true; + } + if(i==1) + { + scale_=x; + signal_child_changed()(i);signal_value_changed()(); + return true; + } + return false; +} + +ValueNode::LooseHandle +ValueNode_Exp::get_link_vfunc(int i)const +{ + assert(i==0 || i==1); + if(i==0) + return exp_; + if(i==1) + return scale_; + + return 0; +} + +int +ValueNode_Exp::link_count()const +{ + return 2; +} + +String +ValueNode_Exp::link_name(int i)const +{ + assert(i==0 || i==1); + if(i==0) + return "exp"; + if(i==1) + return "scale"; + return String(); +} + +String +ValueNode_Exp::link_local_name(int i)const +{ + assert(i==0 || i==1); + if(i==0) + return _("Exponent"); + if(i==1) + return _("Scale"); + return String(); +} + +int +ValueNode_Exp::get_link_index_from_name(const String &name)const +{ + if(name=="exp") + return 0; + if(name=="scale") + return 1; + + throw Exception::BadLinkName(name); +} + +bool +ValueNode_Exp::check_type(ValueBase::Type type) +{ + return type==ValueBase::TYPE_REAL; +} diff --git a/synfig-core/trunk/src/synfig/valuenode_exp.h b/synfig-core/trunk/src/synfig/valuenode_exp.h new file mode 100644 index 0000000..b13760c --- /dev/null +++ b/synfig-core/trunk/src/synfig/valuenode_exp.h @@ -0,0 +1,82 @@ +/* === S Y N F I G ========================================================= */ +/*! \file valuenode_exp.h +** \brief Template Header +** +** $Id$ +** +** \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 +*/ +/* ========================================================================= */ + +/* === S T A R T =========================================================== */ + +#ifndef __SYNFIG_VALUENODE_EXP_H +#define __SYNFIG_VALUENODE_EXP_H + +/* === H E A D E R S ======================================================= */ + +#include "valuenode.h" + +/* === M A C R O S ========================================================= */ + +/* === C L A S S E S & S T R U C T S ======================================= */ + +namespace synfig { + +class ValueNode_Exp : public LinkableValueNode +{ + ValueNode::RHandle exp_; + ValueNode::RHandle scale_; + + ValueNode_Exp(const ValueBase &value); + +public: + + typedef etl::handle Handle; + typedef etl::handle ConstHandle; + + + virtual ValueBase operator()(Time t)const; + + virtual ~ValueNode_Exp(); + + virtual String get_name()const; + virtual String get_local_name()const; + + + virtual ValueNode::LooseHandle get_link_vfunc(int i)const; + virtual int link_count()const; + virtual String link_name(int i)const; + + virtual String link_local_name(int i)const; + virtual int get_link_index_from_name(const String &name)const; + +protected: + LinkableValueNode* create_new()const; + virtual bool set_link_vfunc(int i,ValueNode::Handle x); + +public: + using synfig::LinkableValueNode::get_link_vfunc; + + using synfig::LinkableValueNode::set_link_vfunc; + static bool check_type(ValueBase::Type type); + static ValueNode_Exp* create(const ValueBase &x); +}; // END of class ValueNode_Exp + +}; // END of namespace synfig + +/* === E N D =============================================================== */ + +#endif