Add new valuenode type "Step" to allow values to have a linear stepped value. The...
authordooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Thu, 14 Feb 2008 13:00:22 +0000 (13:00 +0000)
committerdooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Thu, 14 Feb 2008 13:00:22 +0000 (13:00 +0000)
git-svn-id: http://svn.voria.com/code@1691 1f10aa63-cdf2-0310-b900-c93c546f37ac

synfig-core/trunk/po/POTFILES.in
synfig-core/trunk/src/synfig/Makefile.am
synfig-core/trunk/src/synfig/valuenode.cpp
synfig-core/trunk/src/synfig/valuenode_step.cpp [new file with mode: 0644]
synfig-core/trunk/src/synfig/valuenode_step.h [new file with mode: 0644]

index d303c4f..b95cb55 100644 (file)
@@ -325,6 +325,8 @@ src/synfig/valuenode_segcalcvertex.cpp
 src/synfig/valuenode_segcalcvertex.h
 src/synfig/valuenode_sine.cpp
 src/synfig/valuenode_sine.h
+src/synfig/valuenode_step.cpp
+src/synfig/valuenode_step.h
 src/synfig/valuenode_stripes.cpp
 src/synfig/valuenode_stripes.h
 src/synfig/valuenode_subtract.cpp
index 4895302..a52bf7e 100644 (file)
@@ -33,7 +33,7 @@ VALUENODEHEADERS = \
        valuenode_gradientrotate.h   valuenode_integer.h   valuenode_linear.h valuenode_radialcomposite.h               \
        valuenode_range.h   valuenode_reciprocal.h   valuenode_reference.h   valuenode_repeat_gradient.h                \
        valuenode_scale.h   valuenode_segcalctangent.h   valuenode_segcalcvertex.h   valuenode_sine.h                   \
-       valuenode_stripes.h   valuenode_subtract.h    valuenode_switch.h   valuenode_timedswap.h                        \
+       valuenode_step.h   valuenode_stripes.h   valuenode_subtract.h    valuenode_switch.h   valuenode_timedswap.h     \
        valuenode_timeloop.h   valuenode_twotone.h
 VALUENODESOURCES = \
        valuenode_add.cpp valuenode_animated.cpp valuenode_atan2.cpp valuenode_bline.cpp valuenode_blinecalctangent.cpp \
@@ -42,7 +42,7 @@ VALUENODESOURCES = \
        valuenode_gradientrotate.cpp valuenode_integer.cpp valuenode_linear.cpp valuenode_radialcomposite.cpp           \
        valuenode_range.cpp valuenode_reciprocal.cpp valuenode_reference.cpp valuenode_repeat_gradient.cpp              \
        valuenode_scale.cpp valuenode_segcalctangent.cpp valuenode_segcalcvertex.cpp valuenode_sine.cpp                 \
-       valuenode_stripes.cpp valuenode_subtract.cpp valuenode_switch.cpp valuenode_timedswap.cpp                       \
+       valuenode_step.cpp valuenode_stripes.cpp valuenode_subtract.cpp valuenode_switch.cpp valuenode_timedswap.cpp    \
        valuenode_timeloop.cpp valuenode_twotone.cpp
 
 VALUEHEADERS = \
index e6953cf..ced3891 100644 (file)
@@ -70,6 +70,7 @@
 #include "valuenode_reciprocal.h"
 #include "valuenode_duplicate.h"
 #include "valuenode_integer.h"
+#include "valuenode_step.h"
 
 #include "layer.h"
 
@@ -148,6 +149,7 @@ ValueNode::subsys_init()
        ADD_VALUENODE(ValueNode_Reciprocal,             "reciprocal",           _("Reciprocal")          ,RELEASE_VERSION_0_61_08); // SVN r1238
        ADD_VALUENODE(ValueNode_Duplicate,              "duplicate",            _("Duplicate")           ,RELEASE_VERSION_0_61_08); // SVN r1267
        ADD_VALUENODE(ValueNode_Integer,                "fromint",                      _("From Integer")        ,RELEASE_VERSION_0_61_08); // SVN r1267
+       ADD_VALUENODE(ValueNode_Step,                   "step",                         _("Step")                        ,RELEASE_VERSION_0_61_08); // SVN r1691
 
 #undef ADD_VALUENODE
 #undef ADD_VALUENODE2
diff --git a/synfig-core/trunk/src/synfig/valuenode_step.cpp b/synfig-core/trunk/src/synfig/valuenode_step.cpp
new file mode 100644 (file)
index 0000000..9a163f8
--- /dev/null
@@ -0,0 +1,233 @@
+/* === S Y N F I G ========================================================= */
+/*!    \file valuenode_step.cpp
+**     \brief Implementation of the "Step" valuenode conversion.
+**
+**     $Id$
+**
+**     \legal
+**     Copyright (c) 2008 Chris Moore
+**
+**     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 <config.h>
+#endif
+
+#include "valuenode_step.h"
+#include "valuenode_const.h"
+#include "general.h"
+#include "color.h"
+#include <ETL/misc>
+
+#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_Step::ValueNode_Step(const ValueBase &value):
+       LinkableValueNode(value.get_type())
+{
+       set_link("width",ValueNode_Const::create(Time(1)));
+       set_link("time",ValueNode_Const::create(Time(0)));
+
+       switch(get_type())
+       {
+       case ValueBase::TYPE_ANGLE:
+               set_link("height",ValueNode_Const::create(Angle::deg(0)));
+               set_link("value",ValueNode_Const::create(value.get(Angle())));
+               break;
+       case ValueBase::TYPE_COLOR:
+               set_link("height",ValueNode_Const::create(Color(0,0,0,0)));
+               set_link("value",ValueNode_Const::create(value.get(Color())));
+               break;
+       case ValueBase::TYPE_INTEGER:
+               set_link("height",ValueNode_Const::create(int(0)));
+               set_link("value",ValueNode_Const::create(value.get(int())));
+               break;
+       case ValueBase::TYPE_REAL:
+               set_link("height",ValueNode_Const::create(Real(0)));
+               set_link("value",ValueNode_Const::create(value.get(Real())));
+               break;
+       case ValueBase::TYPE_TIME:
+               set_link("height",ValueNode_Const::create(Time(0)));
+               set_link("value",ValueNode_Const::create(value.get(Time())));
+               break;
+       case ValueBase::TYPE_VECTOR:
+               set_link("height",ValueNode_Const::create(Vector(0,0)));
+               set_link("value",ValueNode_Const::create(value.get(Vector())));
+               break;
+       default:
+               throw Exception::BadType(ValueBase::type_local_name(get_type()));
+       }
+
+       DCAST_HACK_ENABLE();
+}
+
+LinkableValueNode*
+ValueNode_Step::create_new()const
+{
+       return new ValueNode_Step(get_type());
+}
+
+ValueNode_Step*
+ValueNode_Step::create(const ValueBase &x)
+{
+       return new ValueNode_Step(x);
+}
+
+ValueNode_Step::~ValueNode_Step()
+{
+       unlink_all();
+}
+
+ValueBase
+ValueNode_Step::operator()(Time t)const
+{
+       int step = floor((t - ((*time_)(t).get(Time()))) /
+                                        ((*width_)(t).get(Time())));
+
+       switch(get_type())
+       {
+       case ValueBase::TYPE_ANGLE:   return (*value_)(t).get( Angle()) + (*height_)(t).get( Angle())*step;
+       case ValueBase::TYPE_COLOR:   return (*value_)(t).get( Color()) + (*height_)(t).get( Color())*step;
+       case ValueBase::TYPE_INTEGER: return (*value_)(t).get(   int()) + (*height_)(t).get(   int())*step;
+       case ValueBase::TYPE_REAL:    return (*value_)(t).get(  Real()) + (*height_)(t).get(  Real())*step;
+       case ValueBase::TYPE_TIME:    return (*value_)(t).get(  Time()) + (*height_)(t).get(  Time())*step;
+       case ValueBase::TYPE_VECTOR:  return (*value_)(t).get(Vector()) + (*height_)(t).get(Vector())*step;
+       default:
+               assert(0);
+               return ValueBase();
+       }
+}
+
+
+String
+ValueNode_Step::get_name()const
+{
+       return "step";
+}
+
+String
+ValueNode_Step::get_local_name()const
+{
+       return _("Step");
+}
+
+bool
+ValueNode_Step::check_type(ValueBase::Type type)
+{
+       return
+               type==ValueBase::TYPE_ANGLE             ||
+               type==ValueBase::TYPE_COLOR             ||
+               type==ValueBase::TYPE_INTEGER   ||
+               type==ValueBase::TYPE_REAL              ||
+               type==ValueBase::TYPE_TIME              ||
+               type==ValueBase::TYPE_VECTOR    ;
+}
+
+bool
+ValueNode_Step::set_link_vfunc(int i,ValueNode::Handle value)
+{
+       assert(i>=0 && i<link_count());
+
+       switch(i)
+       {
+       case 0: CHECK_TYPE_AND_SET_VALUE(width_,  ValueBase::TYPE_TIME);
+       case 1: CHECK_TYPE_AND_SET_VALUE(height_, get_type());
+       case 2: CHECK_TYPE_AND_SET_VALUE(time_,   ValueBase::TYPE_TIME);
+       case 3: CHECK_TYPE_AND_SET_VALUE(value_,  get_type());
+       }
+       return false;
+}
+
+ValueNode::LooseHandle
+ValueNode_Step::get_link_vfunc(int i)const
+{
+       assert(i>=0 && i<link_count());
+
+       switch(i)
+       {
+       case 0: return width_;
+       case 1: return height_;
+       case 2: return time_;
+       case 3: return value_;
+       default:
+               return 0;
+       }
+}
+
+int
+ValueNode_Step::link_count()const
+{
+       return 4;
+}
+
+String
+ValueNode_Step::link_name(int i)const
+{
+       assert(i>=0 && i<link_count());
+
+       switch(i)
+       {
+       case 0: return "width";
+       case 1: return "height";
+       case 2: return "time";
+       case 3: return "value";
+       default:
+               return String();
+       }
+}
+
+String
+ValueNode_Step::link_local_name(int i)const
+{
+       assert(i>=0 && i<link_count());
+
+       switch(i)
+       {
+       case 0: return _("Width");
+       case 1: return _("Height");
+       case 2: return _("Time");
+       case 3: return _("Value");
+       default:
+               return String();
+       }
+}
+
+int
+ValueNode_Step::get_link_index_from_name(const String &name)const
+{
+       if(name=="width")  return 0;
+       if(name=="height") return 1;
+       if(name=="time")   return 2;
+       if(name=="value")  return 3;
+
+       throw Exception::BadLinkName(name);
+}
diff --git a/synfig-core/trunk/src/synfig/valuenode_step.h b/synfig-core/trunk/src/synfig/valuenode_step.h
new file mode 100644 (file)
index 0000000..fc2fc6b
--- /dev/null
@@ -0,0 +1,84 @@
+/* === S Y N F I G ========================================================= */
+/*!    \file valuenode_step.h
+**     \brief Header file for implementation of the "Step" valuenode conversion.
+**
+**     $Id$
+**
+**     \legal
+**     Copyright (c) 2008 Chris Moore
+**
+**     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_INTERPOLATION_STEP_H
+#define __SYNFIG_VALUENODE_INTERPOLATION_STEP_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_Step : public LinkableValueNode
+{
+       ValueNode::RHandle width_;
+       ValueNode::RHandle height_;
+       ValueNode::RHandle time_;
+       ValueNode::RHandle value_;
+
+       ValueNode_Step(const ValueBase &value);
+
+public:
+
+       typedef etl::handle<ValueNode_Step> Handle;
+       typedef etl::handle<const ValueNode_Step> ConstHandle;
+
+
+       virtual ValueBase operator()(Time t)const;
+
+       virtual ~ValueNode_Step();
+
+       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_Step* create(const ValueBase &x);
+}; // END of class ValueNode_Step
+
+}; // END of namespace synfig
+
+/* === E N D =============================================================== */
+
+#endif