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(const ValueBase &x)
92 return new ValueNode_Linear(x);
95 ValueNode_Linear::~ValueNode_Linear()
101 ValueNode_Linear::operator()(Time t)const
105 case ValueBase::TYPE_ANGLE:
106 return (*m_)(t).get( Angle())*t+(*b_)(t).get( Angle());
107 case ValueBase::TYPE_COLOR:
108 return (*m_)(t).get( Color())*t+(*b_)(t).get( Color());
109 case ValueBase::TYPE_INTEGER:
110 return static_cast<int>((*m_)(t).get(int())*t+(*b_)(t).get(int()) + 0.5f);
111 case ValueBase::TYPE_REAL:
112 return (*m_)(t).get( Real())*t+(*b_)(t).get( Real());
113 case ValueBase::TYPE_TIME:
114 return (*m_)(t).get( Time())*t+(*b_)(t).get( Time());
115 case ValueBase::TYPE_VECTOR:
116 return (*m_)(t).get(Vector())*t+(*b_)(t).get(Vector());
126 ValueNode_Linear::get_name()const
132 ValueNode_Linear::get_local_name()const
138 ValueNode_Linear::check_type(ValueBase::Type type)
141 type==ValueBase::TYPE_ANGLE ||
142 type==ValueBase::TYPE_COLOR ||
143 type==ValueBase::TYPE_INTEGER ||
144 type==ValueBase::TYPE_REAL ||
145 type==ValueBase::TYPE_TIME ||
146 type==ValueBase::TYPE_VECTOR ;
150 ValueNode_Linear::set_link_vfunc(int i,ValueNode::Handle x)
152 assert(i==0 || i==1);
156 signal_child_changed()(i);signal_value_changed()();
162 signal_child_changed()(i);signal_value_changed()();
168 ValueNode::LooseHandle
169 ValueNode_Linear::get_link_vfunc(int i)const
171 assert(i==0 || i==1);
178 ValueNode_Linear::link_count()const
184 ValueNode_Linear::link_name(int i)const
186 assert(i==0 || i==1);
187 if(i==0) return "slope";
188 if(i==1) return "offset";
193 ValueNode_Linear::link_local_name(int i)const
195 assert(i==0 || i==1);
199 case ValueBase::TYPE_ANGLE:
200 case ValueBase::TYPE_COLOR:
201 case ValueBase::TYPE_INTEGER:
202 case ValueBase::TYPE_REAL:
203 case ValueBase::TYPE_TIME:
205 case ValueBase::TYPE_VECTOR:
215 ValueNode_Linear::get_link_index_from_name(const String &name)const
217 if(name=="slope") return 0;
218 if(name=="offset") return 1;
220 throw Exception::BadLinkName(name);
224 ValueNode_Linear::create_new()const
226 return new ValueNode_Linear(get_type());