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
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_linear.h"
33 #include "valuenode_const.h"
39 /* === U S I N G =========================================================== */
43 using namespace synfig;
45 /* === M A C R O S ========================================================= */
47 /* === G L O B A L S ======================================================= */
49 /* === P R O C E D U R E S ================================================= */
51 /* === M E T H O D S ======================================================= */
53 ValueNode_Linear::ValueNode_Linear(const ValueBase &value):
54 LinkableValueNode(value.get_type())
58 case ValueBase::TYPE_ANGLE:
59 set_link("slope",ValueNode_Const::create(Angle::deg(0)));
60 set_link("offset",ValueNode_Const::create(value.get(Angle())));
62 case ValueBase::TYPE_COLOR:
63 set_link("slope",ValueNode_Const::create(Color(0,0,0,0)));
64 set_link("offset",ValueNode_Const::create(value.get(Color())));
66 case ValueBase::TYPE_INTEGER:
67 set_link("slope",ValueNode_Const::create(int(0)));
68 set_link("offset",ValueNode_Const::create(value.get(int())));
70 case ValueBase::TYPE_REAL:
71 set_link("slope",ValueNode_Const::create(Real(0)));
72 set_link("offset",ValueNode_Const::create(value.get(Real())));
74 case ValueBase::TYPE_TIME:
75 set_link("slope",ValueNode_Const::create(Time(0)));
76 set_link("offset",ValueNode_Const::create(value.get(Time())));
78 case ValueBase::TYPE_VECTOR:
79 set_link("slope",ValueNode_Const::create(Vector(0,0)));
80 set_link("offset",ValueNode_Const::create(value.get(Vector())));
83 throw Exception::BadType(ValueBase::type_name(get_type()));
90 ValueNode_Linear::create_new()const
92 return new ValueNode_Linear(get_type());
96 ValueNode_Linear::create(const ValueBase &x)
98 return new ValueNode_Linear(x);
101 ValueNode_Linear::~ValueNode_Linear()
107 ValueNode_Linear::operator()(Time t)const
111 case ValueBase::TYPE_ANGLE:
112 return (*m_)(t).get( Angle())*t+(*b_)(t).get( Angle());
113 case ValueBase::TYPE_COLOR:
114 return (*m_)(t).get( Color())*t+(*b_)(t).get( Color());
115 case ValueBase::TYPE_INTEGER:
117 Real ret = (*m_)(t).get(int())*t+(*b_)(t).get(int()) + 0.5f;
118 if (ret < 0) return static_cast<int>(ret-1);
119 return static_cast<int>(ret);
121 case ValueBase::TYPE_REAL:
122 return (*m_)(t).get( Real())*t+(*b_)(t).get( Real());
123 case ValueBase::TYPE_TIME:
124 return (*m_)(t).get( Time())*t+(*b_)(t).get( Time());
125 case ValueBase::TYPE_VECTOR:
126 return (*m_)(t).get(Vector())*t+(*b_)(t).get(Vector());
136 ValueNode_Linear::get_name()const
142 ValueNode_Linear::get_local_name()const
148 ValueNode_Linear::check_type(ValueBase::Type type)
151 type==ValueBase::TYPE_ANGLE ||
152 type==ValueBase::TYPE_COLOR ||
153 type==ValueBase::TYPE_INTEGER ||
154 type==ValueBase::TYPE_REAL ||
155 type==ValueBase::TYPE_TIME ||
156 type==ValueBase::TYPE_VECTOR ;
160 ValueNode_Linear::set_link_vfunc(int i,ValueNode::Handle x)
162 assert(i==0 || i==1);
166 signal_child_changed()(i);signal_value_changed()();
172 signal_child_changed()(i);signal_value_changed()();
178 ValueNode::LooseHandle
179 ValueNode_Linear::get_link_vfunc(int i)const
181 assert(i==0 || i==1);
188 ValueNode_Linear::link_count()const
194 ValueNode_Linear::link_name(int i)const
196 assert(i==0 || i==1);
197 if(i==0) return "slope";
198 if(i==1) return "offset";
203 ValueNode_Linear::link_local_name(int i)const
205 assert(i==0 || i==1);
209 case ValueBase::TYPE_ANGLE:
210 case ValueBase::TYPE_COLOR:
211 case ValueBase::TYPE_INTEGER:
212 case ValueBase::TYPE_REAL:
213 case ValueBase::TYPE_TIME:
215 case ValueBase::TYPE_VECTOR:
225 ValueNode_Linear::get_link_index_from_name(const String &name)const
227 if(name=="slope") return 0;
228 if(name=="offset") return 1;
230 throw Exception::BadLinkName(name);