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 Vocab ret(get_children_vocab());
58 set_children_vocab(ret);
59 set_link("duration", ValueNode_Const::create(Time(1)));
60 set_link("start_time", ValueNode_Const::create(Time(0)));
61 set_link("intersection", ValueNode_Const::create(Real(0.5)));
65 case ValueBase::TYPE_ANGLE:
66 set_link("link",ValueNode_Const::create(value.get(Angle())));
68 case ValueBase::TYPE_COLOR:
69 set_link("link",ValueNode_Const::create(value.get(Color())));
71 case ValueBase::TYPE_INTEGER:
72 set_link("link",ValueNode_Const::create(value.get(int())));
74 case ValueBase::TYPE_REAL:
75 set_link("link",ValueNode_Const::create(value.get(Real())));
77 case ValueBase::TYPE_TIME:
78 set_link("link",ValueNode_Const::create(value.get(Time())));
80 case ValueBase::TYPE_VECTOR:
81 set_link("link",ValueNode_Const::create(value.get(Vector())));
84 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 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
109 printf("%s:%d operator()\n", __FILE__, __LINE__);
111 Time duration ((*duration_ )(t).get(Time()));
112 Time start_time ((*start_time_ )(t).get(Time()));
113 Real intersection((*intersection_)(t).get(Real()));
115 t = (floor((t - start_time) / duration) + intersection) * duration + start_time;
119 case ValueBase::TYPE_ANGLE: return (*link_)(t).get( Angle());
120 case ValueBase::TYPE_COLOR: return (*link_)(t).get( Color());
121 case ValueBase::TYPE_INTEGER: return (*link_)(t).get( int());
122 case ValueBase::TYPE_REAL: return (*link_)(t).get( Real());
123 case ValueBase::TYPE_TIME: return (*link_)(t).get( Time());
124 case ValueBase::TYPE_VECTOR: return (*link_)(t).get(Vector());
133 ValueNode_Step::get_name()const
139 ValueNode_Step::get_local_name()const
145 ValueNode_Step::check_type(ValueBase::Type type)
148 type==ValueBase::TYPE_ANGLE ||
149 type==ValueBase::TYPE_COLOR ||
150 type==ValueBase::TYPE_INTEGER ||
151 type==ValueBase::TYPE_REAL ||
152 type==ValueBase::TYPE_TIME ||
153 type==ValueBase::TYPE_VECTOR ;
157 ValueNode_Step::set_link_vfunc(int i,ValueNode::Handle value)
159 assert(i>=0 && i<link_count());
163 case 0: CHECK_TYPE_AND_SET_VALUE(link_, get_type());
164 case 1: CHECK_TYPE_AND_SET_VALUE(duration_, ValueBase::TYPE_TIME);
165 case 2: CHECK_TYPE_AND_SET_VALUE(start_time_, ValueBase::TYPE_TIME);
166 case 3: CHECK_TYPE_AND_SET_VALUE(intersection_, ValueBase::TYPE_REAL);
171 ValueNode::LooseHandle
172 ValueNode_Step::get_link_vfunc(int i)const
174 assert(i>=0 && i<link_count());
178 case 0: return link_;
179 case 1: return duration_;
180 case 2: return start_time_;
181 case 3: return intersection_;
187 LinkableValueNode::Vocab
188 ValueNode_Step::get_children_vocab_vfunc()const
190 if(children_vocab.size())
191 return children_vocab;
193 LinkableValueNode::Vocab ret;
195 ret.push_back(ParamDesc(ValueBase(),"link")
196 .set_local_name(_("Link"))
197 .set_description(_("The value node used to make the step"))
200 ret.push_back(ParamDesc(ValueBase(),"duration")
201 .set_local_name(_("Duration"))
202 .set_description(_("The duration of the step"))
205 ret.push_back(ParamDesc(ValueBase(),"start_time")
206 .set_local_name(_("Start Time"))
207 .set_description(_("The time when the step conversion starts"))
210 ret.push_back(ParamDesc(ValueBase(),"intersection")
211 .set_local_name(_("Intersection"))
212 .set_description(_("Value that define whether the step is centerd on the value [0,1]"))