1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_integer.cpp
3 ** \brief Implementation of the "Integer" valuenode conversion.
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 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_integer.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_Integer::ValueNode_Integer(const ValueBase::Type &x):
59 ValueNode_Integer::ValueNode_Integer(const ValueBase &x):
60 LinkableValueNode(x.get_type())
64 case ValueBase::TYPE_ANGLE:
65 set_link("integer", ValueNode_Const::create(round_to_int(Angle::deg(x.get(Angle())).get())));
67 case ValueBase::TYPE_BOOL:
68 set_link("integer", ValueNode_Const::create(int(x.get(bool()))));
70 case ValueBase::TYPE_REAL:
71 set_link("integer", ValueNode_Const::create(round_to_int(x.get(Real()))));
73 case ValueBase::TYPE_TIME:
74 set_link("integer", ValueNode_Const::create(round_to_int(x.get(Time()))));
78 throw runtime_error("synfig::ValueNode_Integer:Bad type "+ValueBase::type_name(x.get_type()));
83 ValueNode_Integer::create(const ValueBase &x)
85 return new ValueNode_Integer(x);
89 ValueNode_Integer::create_new()const
91 return new ValueNode_Integer(get_type());
94 ValueNode_Integer::~ValueNode_Integer()
100 ValueNode_Integer::set_link_vfunc(int i,ValueNode::Handle x)
102 assert(i >= 0 && i < link_count());
105 case 0: integer_ = x; break;
106 default: return false;
109 signal_child_changed()(i);
110 signal_value_changed()();
114 ValueNode::LooseHandle
115 ValueNode_Integer::get_link_vfunc(int i)const
117 assert(i >= 0 && i < link_count());
118 if(i==0) return integer_;
124 ValueNode_Integer::link_count()const
130 ValueNode_Integer::link_local_name(int i)const
132 assert(i >= 0 && i < link_count());
133 if(i==0) return _("Integer");
138 ValueNode_Integer::link_name(int i)const
140 assert(i >= 0 && i < link_count());
141 if(i==0) return "integer";
146 ValueNode_Integer::get_link_index_from_name(const String &name)const
148 if(name=="integer") return 0;
150 throw Exception::BadLinkName(name);
154 ValueNode_Integer::operator()(Time t)const
156 int integer = (*integer_)(t).get(int());
160 case ValueBase::TYPE_ANGLE:
161 return Angle::deg(integer);
162 case ValueBase::TYPE_BOOL:
163 return bool(integer);
164 case ValueBase::TYPE_REAL:
165 return Real(integer);
166 case ValueBase::TYPE_TIME:
167 return Time(integer);
170 throw runtime_error("synfig::ValueNode_Integer:Bad type "+ValueBase::type_name(get_type()));
175 ValueNode_Integer::get_name()const
181 ValueNode_Integer::get_local_name()const
183 return _("From Integer");
186 // don't show this to the user at the moment - maybe it's not very useful
188 ValueNode_Integer::check_type(ValueBase::Type type)
192 // type==ValueBase::TYPE_ANGLE ||
193 // type==ValueBase::TYPE_BOOL ||
194 // type==ValueBase::TYPE_REAL ||
195 // type==ValueBase::TYPE_TIME;