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("duration", ValueNode_Const::create(Time(1)));
58 set_link("start_time", ValueNode_Const::create(Time(0)));
59 set_link("intersection", ValueNode_Const::create(Real(0.5)));
63 case ValueBase::TYPE_ANGLE:
64 set_link("link",ValueNode_Const::create(value.get(Angle())));
66 case ValueBase::TYPE_COLOR:
67 set_link("link",ValueNode_Const::create(value.get(Color())));
69 case ValueBase::TYPE_INTEGER:
70 set_link("link",ValueNode_Const::create(value.get(int())));
72 case ValueBase::TYPE_REAL:
73 set_link("link",ValueNode_Const::create(value.get(Real())));
75 case ValueBase::TYPE_TIME:
76 set_link("link",ValueNode_Const::create(value.get(Time())));
78 case ValueBase::TYPE_VECTOR:
79 set_link("link",ValueNode_Const::create(value.get(Vector())));
82 throw Exception::BadType(ValueBase::type_local_name(get_type()));
89 ValueNode_Step::create_new()const
91 return new ValueNode_Step(get_type());
95 ValueNode_Step::create(const ValueBase &x)
97 return new ValueNode_Step(x);
100 ValueNode_Step::~ValueNode_Step()
106 ValueNode_Step::operator()(Time t)const
108 Time duration ((*duration_ )(t).get(Time()));
109 Time start_time ((*start_time_ )(t).get(Time()));
110 Real intersection((*intersection_)(t).get(Real()));
112 t = (floor((t - start_time) / duration) + intersection) * duration + start_time;
116 case ValueBase::TYPE_ANGLE: return (*link_)(t).get( Angle());
117 case ValueBase::TYPE_COLOR: return (*link_)(t).get( Color());
118 case ValueBase::TYPE_INTEGER: return (*link_)(t).get( int());
119 case ValueBase::TYPE_REAL: return (*link_)(t).get( Real());
120 case ValueBase::TYPE_TIME: return (*link_)(t).get( Time());
121 case ValueBase::TYPE_VECTOR: return (*link_)(t).get(Vector());
130 ValueNode_Step::get_name()const
136 ValueNode_Step::get_local_name()const
142 ValueNode_Step::check_type(ValueBase::Type type)
145 type==ValueBase::TYPE_ANGLE ||
146 type==ValueBase::TYPE_COLOR ||
147 type==ValueBase::TYPE_INTEGER ||
148 type==ValueBase::TYPE_REAL ||
149 type==ValueBase::TYPE_TIME ||
150 type==ValueBase::TYPE_VECTOR ;
154 ValueNode_Step::set_link_vfunc(int i,ValueNode::Handle value)
156 assert(i>=0 && i<link_count());
160 case 0: CHECK_TYPE_AND_SET_VALUE(link_, get_type());
161 case 1: CHECK_TYPE_AND_SET_VALUE(duration_, ValueBase::TYPE_TIME);
162 case 2: CHECK_TYPE_AND_SET_VALUE(start_time_, ValueBase::TYPE_TIME);
163 case 3: CHECK_TYPE_AND_SET_VALUE(intersection_, ValueBase::TYPE_REAL);
168 ValueNode::LooseHandle
169 ValueNode_Step::get_link_vfunc(int i)const
171 assert(i>=0 && i<link_count());
175 case 0: return link_;
176 case 1: return duration_;
177 case 2: return start_time_;
178 case 3: return intersection_;
185 ValueNode_Step::link_count()const
191 ValueNode_Step::link_name(int i)const
193 assert(i>=0 && i<link_count());
197 case 0: return "link";
198 case 1: return "duration";
199 case 2: return "start_time";
200 case 3: return "intersection";
207 ValueNode_Step::link_local_name(int i)const
209 assert(i>=0 && i<link_count());
213 case 0: return _("Link");
214 case 1: return _("Duration");
215 case 2: return _("Start Time");
216 case 3: return _("Intersection");
223 ValueNode_Step::get_link_index_from_name(const String &name)const
225 if(name=="link") return 0;
226 if(name=="duration") return 1;
227 if(name=="start_time") return 2;
228 if(name=="intersection") return 3;
230 throw Exception::BadLinkName(name);