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("time",ValueNode_Const::create(Time(0)));
62 case ValueBase::TYPE_ANGLE:
63 set_link("height",ValueNode_Const::create(Angle::deg(0)));
64 set_link("value",ValueNode_Const::create(value.get(Angle())));
66 case ValueBase::TYPE_COLOR:
67 set_link("height",ValueNode_Const::create(Color(0,0,0,0)));
68 set_link("value",ValueNode_Const::create(value.get(Color())));
70 case ValueBase::TYPE_INTEGER:
71 set_link("height",ValueNode_Const::create(int(0)));
72 set_link("value",ValueNode_Const::create(value.get(int())));
74 case ValueBase::TYPE_REAL:
75 set_link("height",ValueNode_Const::create(Real(0)));
76 set_link("value",ValueNode_Const::create(value.get(Real())));
78 case ValueBase::TYPE_TIME:
79 set_link("height",ValueNode_Const::create(Time(0)));
80 set_link("value",ValueNode_Const::create(value.get(Time())));
82 case ValueBase::TYPE_VECTOR:
83 set_link("height",ValueNode_Const::create(Vector(0,0)));
84 set_link("value",ValueNode_Const::create(value.get(Vector())));
87 throw Exception::BadType(ValueBase::type_local_name(get_type()));
94 ValueNode_Step::create_new()const
96 return new ValueNode_Step(get_type());
100 ValueNode_Step::create(const ValueBase &x)
102 return new ValueNode_Step(x);
105 ValueNode_Step::~ValueNode_Step()
111 ValueNode_Step::operator()(Time t)const
113 int step = floor((t - ((*time_)(t).get(Time()))) /
114 ((*width_)(t).get(Time())));
118 case ValueBase::TYPE_ANGLE: return (*value_)(t).get( Angle()) + (*height_)(t).get( Angle())*step;
119 case ValueBase::TYPE_COLOR: return (*value_)(t).get( Color()) + (*height_)(t).get( Color())*step;
120 case ValueBase::TYPE_INTEGER: return (*value_)(t).get( int()) + (*height_)(t).get( int())*step;
121 case ValueBase::TYPE_REAL: return (*value_)(t).get( Real()) + (*height_)(t).get( Real())*step;
122 case ValueBase::TYPE_TIME: return (*value_)(t).get( Time()) + (*height_)(t).get( Time())*step;
123 case ValueBase::TYPE_VECTOR: return (*value_)(t).get(Vector()) + (*height_)(t).get(Vector())*step;
132 ValueNode_Step::get_name()const
138 ValueNode_Step::get_local_name()const
144 ValueNode_Step::check_type(ValueBase::Type type)
147 type==ValueBase::TYPE_ANGLE ||
148 type==ValueBase::TYPE_COLOR ||
149 type==ValueBase::TYPE_INTEGER ||
150 type==ValueBase::TYPE_REAL ||
151 type==ValueBase::TYPE_TIME ||
152 type==ValueBase::TYPE_VECTOR ;
156 ValueNode_Step::set_link_vfunc(int i,ValueNode::Handle value)
158 assert(i>=0 && i<link_count());
162 case 0: CHECK_TYPE_AND_SET_VALUE(width_, ValueBase::TYPE_TIME);
163 case 1: CHECK_TYPE_AND_SET_VALUE(height_, get_type());
164 case 2: CHECK_TYPE_AND_SET_VALUE(time_, ValueBase::TYPE_TIME);
165 case 3: CHECK_TYPE_AND_SET_VALUE(value_, get_type());
170 ValueNode::LooseHandle
171 ValueNode_Step::get_link_vfunc(int i)const
173 assert(i>=0 && i<link_count());
177 case 0: return width_;
178 case 1: return height_;
179 case 2: return time_;
180 case 3: return value_;
187 ValueNode_Step::link_count()const
193 ValueNode_Step::link_name(int i)const
195 assert(i>=0 && i<link_count());
199 case 0: return "width";
200 case 1: return "height";
201 case 2: return "time";
202 case 3: return "value";
209 ValueNode_Step::link_local_name(int i)const
211 assert(i>=0 && i<link_count());
215 case 0: return _("Width");
216 case 1: return _("Height");
217 case 2: return _("Time");
218 case 3: return _("Value");
225 ValueNode_Step::get_link_index_from_name(const String &name)const
227 if(name=="width") return 0;
228 if(name=="height") return 1;
229 if(name=="time") return 2;
230 if(name=="value") return 3;
232 throw Exception::BadLinkName(name);