1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_linear.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 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"
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_Linear::ValueNode_Linear(const ValueBase &value):
55 LinkableValueNode(value.get_type())
59 case ValueBase::TYPE_ANGLE:
60 set_link("slope",ValueNode_Const::create(Angle::deg(0)));
61 set_link("offset",ValueNode_Const::create(value.get(Angle())));
63 case ValueBase::TYPE_COLOR:
64 set_link("slope",ValueNode_Const::create(Color(0,0,0,0)));
65 set_link("offset",ValueNode_Const::create(value.get(Color())));
67 case ValueBase::TYPE_INTEGER:
68 set_link("slope",ValueNode_Const::create(int(0)));
69 set_link("offset",ValueNode_Const::create(value.get(int())));
71 case ValueBase::TYPE_REAL:
72 set_link("slope",ValueNode_Const::create(Real(0)));
73 set_link("offset",ValueNode_Const::create(value.get(Real())));
75 case ValueBase::TYPE_TIME:
76 set_link("slope",ValueNode_Const::create(Time(0)));
77 set_link("offset",ValueNode_Const::create(value.get(Time())));
79 case ValueBase::TYPE_VECTOR:
80 set_link("slope",ValueNode_Const::create(Vector(0,0)));
81 set_link("offset",ValueNode_Const::create(value.get(Vector())));
84 throw Exception::BadType(ValueBase::type_name(get_type()));
91 ValueNode_Linear::create_new()const
93 return new ValueNode_Linear(get_type());
97 ValueNode_Linear::create(const ValueBase &x)
99 return new ValueNode_Linear(x);
102 ValueNode_Linear::~ValueNode_Linear()
108 ValueNode_Linear::operator()(Time t)const
112 case ValueBase::TYPE_ANGLE:
113 return (*m_)(t).get( Angle())*t+(*b_)(t).get( Angle());
114 case ValueBase::TYPE_COLOR:
115 return (*m_)(t).get( Color())*t+(*b_)(t).get( Color());
116 case ValueBase::TYPE_INTEGER:
118 Real ret = (*m_)(t).get(int())*t+(*b_)(t).get(int()) + 0.5f;
119 if (ret < 0) return static_cast<int>(ret-1);
120 return static_cast<int>(ret);
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 x)
163 assert(i==0 || i==1);
167 signal_child_changed()(i);signal_value_changed()();
173 signal_child_changed()(i);signal_value_changed()();
179 ValueNode::LooseHandle
180 ValueNode_Linear::get_link_vfunc(int i)const
182 assert(i==0 || i==1);
189 ValueNode_Linear::link_count()const
195 ValueNode_Linear::link_name(int i)const
197 assert(i==0 || i==1);
198 if(i==0) return "slope";
199 if(i==1) return "offset";
204 ValueNode_Linear::link_local_name(int i)const
206 assert(i==0 || i==1);
210 case ValueBase::TYPE_ANGLE:
211 case ValueBase::TYPE_COLOR:
212 case ValueBase::TYPE_INTEGER:
213 case ValueBase::TYPE_REAL:
214 case ValueBase::TYPE_TIME:
216 case ValueBase::TYPE_VECTOR:
226 ValueNode_Linear::get_link_index_from_name(const String &name)const
228 if(name=="slope") return 0;
229 if(name=="offset") return 1;
231 throw Exception::BadLinkName(name);