1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_linear.cpp
3 ** \brief Implementation of the "Linear" valuenode conversion.
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 2008 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_linear.h"
34 #include "valuenode_const.h"
41 /* === U S I N G =========================================================== */
45 using namespace synfig;
47 /* === M A C R O S ========================================================= */
49 /* === G L O B A L S ======================================================= */
51 /* === P R O C E D U R E S ================================================= */
53 /* === M E T H O D S ======================================================= */
55 ValueNode_Linear::ValueNode_Linear(const ValueBase &value):
56 LinkableValueNode(value.get_type())
58 Vocab ret(get_children_vocab());
59 set_children_vocab(ret);
62 case ValueBase::TYPE_ANGLE:
63 set_link("slope",ValueNode_Const::create(Angle::deg(0)));
64 set_link("offset",ValueNode_Const::create(value.get(Angle())));
66 case ValueBase::TYPE_COLOR:
67 set_link("slope",ValueNode_Const::create(Color(0,0,0,0)));
68 set_link("offset",ValueNode_Const::create(value.get(Color())));
70 case ValueBase::TYPE_INTEGER:
71 set_link("slope",ValueNode_Const::create(int(0)));
72 set_link("offset",ValueNode_Const::create(value.get(int())));
74 case ValueBase::TYPE_REAL:
75 set_link("slope",ValueNode_Const::create(Real(0)));
76 set_link("offset",ValueNode_Const::create(value.get(Real())));
78 case ValueBase::TYPE_TIME:
79 set_link("slope",ValueNode_Const::create(Time(0)));
80 set_link("offset",ValueNode_Const::create(value.get(Time())));
82 case ValueBase::TYPE_VECTOR:
83 set_link("slope",ValueNode_Const::create(Vector(0,0)));
84 set_link("offset",ValueNode_Const::create(value.get(Vector())));
87 throw Exception::BadType(ValueBase::type_local_name(get_type()));
92 ValueNode_Linear::create_new()const
94 return new ValueNode_Linear(get_type());
98 ValueNode_Linear::create(const ValueBase &x)
100 return new ValueNode_Linear(x);
103 ValueNode_Linear::~ValueNode_Linear()
109 ValueNode_Linear::operator()(Time t)const
111 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
112 printf("%s:%d operator()\n", __FILE__, __LINE__);
116 case ValueBase::TYPE_ANGLE:
117 return (*m_)(t).get( Angle())*t+(*b_)(t).get( Angle());
118 case ValueBase::TYPE_COLOR:
119 return (*m_)(t).get( Color())*t+(*b_)(t).get( Color());
120 case ValueBase::TYPE_INTEGER:
121 return round_to_int((*m_)(t).get(int())*t+(*b_)(t).get(int()));
122 case ValueBase::TYPE_REAL:
123 return (*m_)(t).get( Real())*t+(*b_)(t).get( Real());
124 case ValueBase::TYPE_TIME:
125 return (*m_)(t).get( Time())*t+(*b_)(t).get( Time());
126 case ValueBase::TYPE_VECTOR:
127 return (*m_)(t).get(Vector())*t+(*b_)(t).get(Vector());
137 ValueNode_Linear::get_name()const
143 ValueNode_Linear::get_local_name()const
149 ValueNode_Linear::check_type(ValueBase::Type type)
152 type==ValueBase::TYPE_ANGLE ||
153 type==ValueBase::TYPE_COLOR ||
154 type==ValueBase::TYPE_INTEGER ||
155 type==ValueBase::TYPE_REAL ||
156 type==ValueBase::TYPE_TIME ||
157 type==ValueBase::TYPE_VECTOR ;
161 ValueNode_Linear::set_link_vfunc(int i,ValueNode::Handle value)
163 assert(i>=0 && i<link_count());
167 case 0: CHECK_TYPE_AND_SET_VALUE(m_, get_type());
168 case 1: CHECK_TYPE_AND_SET_VALUE(b_, get_type());
173 ValueNode::LooseHandle
174 ValueNode_Linear::get_link_vfunc(int i)const
176 assert(i>=0 && i<link_count());
183 LinkableValueNode::Vocab
184 ValueNode_Linear::get_children_vocab_vfunc()const
186 if(children_vocab.size())
187 return children_vocab;
189 LinkableValueNode::Vocab ret;
193 case ValueBase::TYPE_ANGLE:
194 case ValueBase::TYPE_COLOR:
195 case ValueBase::TYPE_INTEGER:
196 case ValueBase::TYPE_REAL:
197 case ValueBase::TYPE_TIME:
198 ret.push_back(ParamDesc(ValueBase(),"slope")
199 .set_local_name(_("Rate"))
200 .set_description(_("Value that is multiplied by the current time (in seconds)"))
203 case ValueBase::TYPE_VECTOR:
205 ret.push_back(ParamDesc(ValueBase(),"slope")
206 .set_local_name(_("Slope"))
207 .set_description(_("Value that is multiplied by the current time (in seconds)"))
211 ret.push_back(ParamDesc(ValueBase(),"offset")
212 .set_local_name(_("Offset"))
213 .set_description(_("Returned value when the current time is zero"))