1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_step.cpp
3 ** \brief Implementation of the "Step" valuenode conversion.
8 ** Copyright (c) 2008 Chris Moore
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include "valuenode_step.h"
33 #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_Step::ValueNode_Step(const ValueBase &value):
55 LinkableValueNode(value.get_type())
57 set_link("width",ValueNode_Const::create(Time(1)));
58 set_link("offset",ValueNode_Const::create(Time(0)));
62 case ValueBase::TYPE_ANGLE:
63 set_link("link",ValueNode_Const::create(value.get(Angle())));
65 case ValueBase::TYPE_COLOR:
66 set_link("link",ValueNode_Const::create(value.get(Color())));
68 case ValueBase::TYPE_INTEGER:
69 set_link("link",ValueNode_Const::create(value.get(int())));
71 case ValueBase::TYPE_REAL:
72 set_link("link",ValueNode_Const::create(value.get(Real())));
74 case ValueBase::TYPE_TIME:
75 set_link("link",ValueNode_Const::create(value.get(Time())));
77 case ValueBase::TYPE_VECTOR:
78 set_link("link",ValueNode_Const::create(value.get(Vector())));
81 throw Exception::BadType(ValueBase::type_local_name(get_type()));
88 ValueNode_Step::create_new()const
90 return new ValueNode_Step(get_type());
94 ValueNode_Step::create(const ValueBase &x)
96 return new ValueNode_Step(x);
99 ValueNode_Step::~ValueNode_Step()
105 ValueNode_Step::operator()(Time t)const
107 Time width ((*width_ )(t).get(Time()));
108 Time offset((*offset_)(t).get(Time()));
110 t = floor((t - offset) / width) * width + offset;
114 case ValueBase::TYPE_ANGLE: return (*link_)(t).get( Angle());
115 case ValueBase::TYPE_COLOR: return (*link_)(t).get( Color());
116 case ValueBase::TYPE_INTEGER: return (*link_)(t).get( int());
117 case ValueBase::TYPE_REAL: return (*link_)(t).get( Real());
118 case ValueBase::TYPE_TIME: return (*link_)(t).get( Time());
119 case ValueBase::TYPE_VECTOR: return (*link_)(t).get(Vector());
128 ValueNode_Step::get_name()const
134 ValueNode_Step::get_local_name()const
140 ValueNode_Step::check_type(ValueBase::Type type)
143 type==ValueBase::TYPE_ANGLE ||
144 type==ValueBase::TYPE_COLOR ||
145 type==ValueBase::TYPE_INTEGER ||
146 type==ValueBase::TYPE_REAL ||
147 type==ValueBase::TYPE_TIME ||
148 type==ValueBase::TYPE_VECTOR ;
152 ValueNode_Step::set_link_vfunc(int i,ValueNode::Handle value)
154 assert(i>=0 && i<link_count());
158 case 0: CHECK_TYPE_AND_SET_VALUE(link_, get_type());
159 case 1: CHECK_TYPE_AND_SET_VALUE(width_, ValueBase::TYPE_TIME);
160 case 2: CHECK_TYPE_AND_SET_VALUE(offset_, ValueBase::TYPE_TIME);
165 ValueNode::LooseHandle
166 ValueNode_Step::get_link_vfunc(int i)const
168 assert(i>=0 && i<link_count());
172 case 0: return link_;
173 case 1: return width_;
174 case 2: return offset_;
181 ValueNode_Step::link_count()const
187 ValueNode_Step::link_name(int i)const
189 assert(i>=0 && i<link_count());
193 case 0: return "link";
194 case 1: return "width";
195 case 2: return "offset";
202 ValueNode_Step::link_local_name(int i)const
204 assert(i>=0 && i<link_count());
208 case 0: return _("Link");
209 case 1: return _("Width");
210 case 2: return _("Offset");
217 ValueNode_Step::get_link_index_from_name(const String &name)const
219 if(name=="link") return 0;
220 if(name=="width") return 1;
221 if(name=="offset") return 2;
223 throw Exception::BadLinkName(name);