From: dooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Date: Wed, 9 Apr 2008 16:36:21 +0000 (+0000)
Subject: Add valuenode "Real String" for converting real values to text strings.
X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=22f60a9317b1f4fd2bdd4e11b584537d725af1a3;p=synfig.git

Add valuenode "Real String" for converting real values to text strings.


git-svn-id: http://svn.voria.com/code@2003 1f10aa63-cdf2-0310-b900-c93c546f37ac
---

diff --git a/synfig-core/trunk/src/synfig/Makefile.am b/synfig-core/trunk/src/synfig/Makefile.am
index 6ba1caa..39fccc8 100644
--- a/synfig-core/trunk/src/synfig/Makefile.am
+++ b/synfig-core/trunk/src/synfig/Makefile.am
@@ -32,9 +32,9 @@ VALUENODEHEADERS = \
 	valuenode_composite.h   valuenode_const.h   valuenode_cos.h   valuenode_dotproduct.h   valuenode_duplicate.h	\
 	valuenode_dynamiclist.h   valuenode_exp.h   valuenode_gradientcolor.h   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_step.h			\
-	valuenode_stripes.h   valuenode_subtract.h   valuenode_switch.h   valuenode_timedswap.h				\
+	valuenode_realstring.h   valuenode_reciprocal.h   valuenode_reference.h   valuenode_repeat_gradient.h		\
+	valuenode_scale.h   valuenode_segcalctangent.h   valuenode_segcalcvertex.h   valuenode_sine.h			\
+	valuenode_step.h   valuenode_stripes.h   valuenode_subtract.h   valuenode_switch.h   valuenode_timedswap.h	\
 	valuenode_timeloop.h   valuenode_timestring.h   valuenode_twotone.h   valuenode_vectorangle.h			\
 	valuenode_vectorlength.h   valuenode_vectorx.h   valuenode_vectory.h
 VALUENODESOURCES = \
@@ -43,9 +43,9 @@ VALUENODESOURCES = \
 	valuenode_composite.cpp valuenode_const.cpp valuenode_cos.cpp valuenode_dotproduct.cpp valuenode_duplicate.cpp	\
 	valuenode_dynamiclist.cpp valuenode_exp.cpp valuenode_gradientcolor.cpp 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_step.cpp			\
-	valuenode_stripes.cpp valuenode_subtract.cpp valuenode_switch.cpp valuenode_timedswap.cpp			\
+	valuenode_realstring.cpp valuenode_reciprocal.cpp valuenode_reference.cpp valuenode_repeat_gradient.cpp		\
+	valuenode_scale.cpp valuenode_segcalctangent.cpp valuenode_segcalcvertex.cpp valuenode_sine.cpp			\
+	valuenode_step.cpp valuenode_stripes.cpp valuenode_subtract.cpp valuenode_switch.cpp valuenode_timedswap.cpp	\
 	valuenode_timeloop.cpp valuenode_timestring.cpp valuenode_twotone.cpp valuenode_vectorangle.cpp			\
 	valuenode_vectorlength.cpp valuenode_vectorx.cpp valuenode_vectory.cpp
 
diff --git a/synfig-core/trunk/src/synfig/valuenode.cpp b/synfig-core/trunk/src/synfig/valuenode.cpp
index d65bfeb..a534e7d 100644
--- a/synfig-core/trunk/src/synfig/valuenode.cpp
+++ b/synfig-core/trunk/src/synfig/valuenode.cpp
@@ -79,6 +79,7 @@
 #include "valuenode_gradientcolor.h"
 #include "valuenode_dotproduct.h"
 #include "valuenode_timestring.h"
+#include "valuenode_realstring.h"
 
 #include "layer.h"
 
@@ -166,7 +167,8 @@ ValueNode::subsys_init()
 	ADD_VALUENODE(ValueNode_VectorY,		  "vectory",		  _("Vector Y"),		 RELEASE_VERSION_0_61_09); // SVN r1882
 	ADD_VALUENODE(ValueNode_GradientColor,	  "gradientcolor",	  _("Gradient Color"),	 RELEASE_VERSION_0_61_09); // SVN r1885
 	ADD_VALUENODE(ValueNode_DotProduct,		  "dotproduct",		  _("Dot Product"),		 RELEASE_VERSION_0_61_09); // SVN r1891
-	ADD_VALUENODE(ValueNode_TimeString,		  "timestring",		  _("Time String"),		 RELEASE_VERSION_0_61_09); // SVN r????
+	ADD_VALUENODE(ValueNode_TimeString,		  "timestring",		  _("Time String"),		 RELEASE_VERSION_0_61_09); // SVN r2000
+	ADD_VALUENODE(ValueNode_RealString,		  "realstring",		  _("Real String"),		 RELEASE_VERSION_0_61_09); // SVN r????
 
 #undef ADD_VALUENODE
 #undef ADD_VALUENODE2
diff --git a/synfig-core/trunk/src/synfig/valuenode_realstring.cpp b/synfig-core/trunk/src/synfig/valuenode_realstring.cpp
new file mode 100644
index 0000000..76c6925
--- /dev/null
+++ b/synfig-core/trunk/src/synfig/valuenode_realstring.cpp
@@ -0,0 +1,207 @@
+/* === S Y N F I G ========================================================= */
+/*!	\file valuenode_realstring.cpp
+**	\brief Implementation of the "RealString" valuenode conversion.
+**
+**	$Id$
+**
+**	\legal
+**	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**	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_realstring.h"
+#include "valuenode_const.h"
+#include "canvas.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_RealString::ValueNode_RealString(const ValueBase &value):
+	LinkableValueNode(value.get_type())
+{
+	switch(value.get_type())
+	{
+	case ValueBase::TYPE_STRING:
+		set_link("real",ValueNode_Const::create(Real(0)));
+		set_link("width",ValueNode_Const::create(int(0)));
+		set_link("precision",ValueNode_Const::create(int(3)));
+		set_link("zero_pad",ValueNode_Const::create(bool(false)));
+		break;
+	default:
+		throw Exception::BadType(ValueBase::type_local_name(value.get_type()));
+	}
+
+	DCAST_HACK_ENABLE();
+}
+
+LinkableValueNode*
+ValueNode_RealString::create_new()const
+{
+	return new ValueNode_RealString(get_type());
+}
+
+ValueNode_RealString*
+ValueNode_RealString::create(const ValueBase &x)
+{
+	return new ValueNode_RealString(x);
+}
+
+ValueNode_RealString::~ValueNode_RealString()
+{
+	unlink_all();
+}
+
+ValueBase
+ValueNode_RealString::operator()(Time t)const
+{
+	Real real((*real_)(t).get(Real()));
+	int width((*width_)(t).get(int()));
+	int precision((*precision_)(t).get(int()));
+	int zero_pad((*zero_pad_)(t).get(bool()));
+
+	switch (get_type())
+	{
+	case ValueBase::TYPE_STRING:
+		return strprintf(strprintf("%%%s%d.%df",
+								   zero_pad ? "0" : "",
+								   width,
+								   precision).c_str(), real);
+	default:
+		break;
+	}
+
+	assert(0);
+	return ValueBase();
+}
+
+String
+ValueNode_RealString::get_name()const
+{
+	return "realstring";
+}
+
+String
+ValueNode_RealString::get_local_name()const
+{
+	return _("Real String");
+}
+
+bool
+ValueNode_RealString::set_link_vfunc(int i,ValueNode::Handle value)
+{
+	assert(i>=0 && i<link_count());
+
+	switch(i)
+	{
+	case 0: CHECK_TYPE_AND_SET_VALUE(real_, ValueBase::TYPE_REAL);
+	case 1: CHECK_TYPE_AND_SET_VALUE(width_, ValueBase::TYPE_INTEGER);
+	case 2: CHECK_TYPE_AND_SET_VALUE(precision_, ValueBase::TYPE_INTEGER);
+	case 3: CHECK_TYPE_AND_SET_VALUE(zero_pad_, ValueBase::TYPE_BOOL);
+	}
+	return false;
+}
+
+ValueNode::LooseHandle
+ValueNode_RealString::get_link_vfunc(int i)const
+{
+	assert(i>=0 && i<link_count());
+
+	switch(i)
+	{
+	case 0: return real_;
+	case 1: return width_;
+	case 2: return precision_;
+	case 3: return zero_pad_;
+	}
+
+	return 0;
+}
+
+int
+ValueNode_RealString::link_count()const
+{
+	return 4;
+}
+
+String
+ValueNode_RealString::link_name(int i)const
+{
+	assert(i>=0 && i<link_count());
+
+	switch(i)
+	{
+		case 0: return "real";
+		case 1: return "width";
+		case 2: return "precision";
+		case 3: return "zero_pad";
+	}
+	return String();
+}
+
+String
+ValueNode_RealString::link_local_name(int i)const
+{
+	assert(i>=0 && i<link_count());
+
+	switch(i)
+	{
+		case 0: return _("Real");
+		case 1: return _("Width");
+		case 2: return _("Precision");
+		case 3: return _("Zero Padding");
+	}
+	return String();
+}
+
+int
+ValueNode_RealString::get_link_index_from_name(const String &name)const
+{
+	if (name=="real") return 0;
+	if (name=="width") return 1;
+	if (name=="precision") return 2;
+	if (name=="zero_pad") return 3;
+
+	throw Exception::BadLinkName(name);
+}
+
+bool
+ValueNode_RealString::check_type(ValueBase::Type type)
+{
+	return
+		type==ValueBase::TYPE_STRING;
+}
diff --git a/synfig-core/trunk/src/synfig/valuenode_realstring.h b/synfig-core/trunk/src/synfig/valuenode_realstring.h
new file mode 100644
index 0000000..34336f0
--- /dev/null
+++ b/synfig-core/trunk/src/synfig/valuenode_realstring.h
@@ -0,0 +1,85 @@
+/* === S Y N F I G ========================================================= */
+/*!	\file valuenode_realstring.h
+**	\brief Header file for implementation of the "Real String" valuenode conversion.
+**
+**	$Id$
+**
+**	\legal
+**	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**	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_REALSTRING_H
+#define __SYNFIG_VALUENODE_REALSTRING_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_RealString : public LinkableValueNode
+{
+	ValueNode::RHandle real_;
+	ValueNode::RHandle width_;
+	ValueNode::RHandle precision_;
+	ValueNode::RHandle zero_pad_;
+
+	ValueNode_RealString(const ValueBase &value);
+
+public:
+
+	typedef etl::handle<ValueNode_RealString> Handle;
+	typedef etl::handle<const ValueNode_RealString> ConstHandle;
+
+
+	virtual ValueBase operator()(Time t)const;
+
+	virtual ~ValueNode_RealString();
+
+	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_RealString* create(const ValueBase &x);
+}; // END of class ValueNode_RealString
+
+}; // END of namespace synfig
+
+/* === E N D =============================================================== */
+
+#endif