1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_anglestring.cpp
3 ** \brief Implementation of the "AngleString" valuenode conversion.
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "valuenode_anglestring.h"
34 #include "valuenode_const.h"
40 /* === U S I N G =========================================================== */
44 using namespace synfig;
46 /* === M A C R O S ========================================================= */
48 /* === G L O B A L S ======================================================= */
50 /* === P R O C E D U R E S ================================================= */
52 /* === M E T H O D S ======================================================= */
54 ValueNode_AngleString::ValueNode_AngleString(const ValueBase &value):
55 LinkableValueNode(value.get_type())
57 switch(value.get_type())
59 case ValueBase::TYPE_STRING:
60 set_link("angle",ValueNode_Const::create(Angle::deg(0)));
61 set_link("width",ValueNode_Const::create(int(0)));
62 set_link("precision",ValueNode_Const::create(int(3)));
63 set_link("zero_pad",ValueNode_Const::create(bool(false)));
66 throw Exception::BadType(ValueBase::type_local_name(value.get_type()));
71 ValueNode_AngleString::create_new()const
73 return new ValueNode_AngleString(get_type());
76 ValueNode_AngleString*
77 ValueNode_AngleString::create(const ValueBase &x)
79 return new ValueNode_AngleString(x);
82 ValueNode_AngleString::~ValueNode_AngleString()
88 ValueNode_AngleString::operator()(Time t)const
90 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
91 printf("%s:%d operator()\n", __FILE__, __LINE__);
93 Real angle(Angle::deg((*angle_)(t).get(Angle())).get());
94 int width((*width_)(t).get(int()));
95 int precision((*precision_)(t).get(int()));
96 int zero_pad((*zero_pad_)(t).get(bool()));
100 case ValueBase::TYPE_STRING:
101 return strprintf(strprintf("%%%s%d.%df",
104 precision).c_str(), angle);
114 ValueNode_AngleString::get_name()const
116 return "anglestring";
120 ValueNode_AngleString::get_local_name()const
122 return _("Angle String");
126 ValueNode_AngleString::set_link_vfunc(int i,ValueNode::Handle value)
128 assert(i>=0 && i<link_count());
132 case 0: CHECK_TYPE_AND_SET_VALUE(angle_, ValueBase::TYPE_ANGLE);
133 case 1: CHECK_TYPE_AND_SET_VALUE(width_, ValueBase::TYPE_INTEGER);
134 case 2: CHECK_TYPE_AND_SET_VALUE(precision_, ValueBase::TYPE_INTEGER);
135 case 3: CHECK_TYPE_AND_SET_VALUE(zero_pad_, ValueBase::TYPE_BOOL);
140 ValueNode::LooseHandle
141 ValueNode_AngleString::get_link_vfunc(int i)const
143 assert(i>=0 && i<link_count());
147 case 0: return angle_;
148 case 1: return width_;
149 case 2: return precision_;
150 case 3: return zero_pad_;
157 ValueNode_AngleString::link_count()const
163 ValueNode_AngleString::link_name(int i)const
165 assert(i>=0 && i<link_count());
169 case 0: return "angle";
170 case 1: return "width";
171 case 2: return "precision";
172 case 3: return "zero_pad";
178 ValueNode_AngleString::link_local_name(int i)const
180 assert(i>=0 && i<link_count());
184 case 0: return _("Angle");
185 case 1: return _("Width");
186 case 2: return _("Precision");
187 case 3: return _("Zero Padded");
193 ValueNode_AngleString::get_link_index_from_name(const String &name)const
195 if (name=="angle") return 0;
196 if (name=="width") return 1;
197 if (name=="precision") return 2;
198 if (name=="zero_pad") return 3;
200 throw Exception::BadLinkName(name);
204 ValueNode_AngleString::check_type(ValueBase::Type type)
207 type==ValueBase::TYPE_STRING;