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"
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())
60 case ValueBase::TYPE_ANGLE:
61 set_link("slope",ValueNode_Const::create(Angle::deg(0)));
62 set_link("offset",ValueNode_Const::create(value.get(Angle())));
64 case ValueBase::TYPE_COLOR:
65 set_link("slope",ValueNode_Const::create(Color(0,0,0,0)));
66 set_link("offset",ValueNode_Const::create(value.get(Color())));
68 case ValueBase::TYPE_INTEGER:
69 set_link("slope",ValueNode_Const::create(int(0)));
70 set_link("offset",ValueNode_Const::create(value.get(int())));
72 case ValueBase::TYPE_REAL:
73 set_link("slope",ValueNode_Const::create(Real(0)));
74 set_link("offset",ValueNode_Const::create(value.get(Real())));
76 case ValueBase::TYPE_TIME:
77 set_link("slope",ValueNode_Const::create(Time(0)));
78 set_link("offset",ValueNode_Const::create(value.get(Time())));
80 case ValueBase::TYPE_VECTOR:
81 set_link("slope",ValueNode_Const::create(Vector(0,0)));
82 set_link("offset",ValueNode_Const::create(value.get(Vector())));
85 throw Exception::BadType(ValueBase::type_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
113 case ValueBase::TYPE_ANGLE:
114 return (*m_)(t).get( Angle())*t+(*b_)(t).get( Angle());
115 case ValueBase::TYPE_COLOR:
116 return (*m_)(t).get( Color())*t+(*b_)(t).get( Color());
117 case ValueBase::TYPE_INTEGER:
118 return round_to_int((*m_)(t).get(int())*t+(*b_)(t).get(int()));
119 case ValueBase::TYPE_REAL:
120 return (*m_)(t).get( Real())*t+(*b_)(t).get( Real());
121 case ValueBase::TYPE_TIME:
122 return (*m_)(t).get( Time())*t+(*b_)(t).get( Time());
123 case ValueBase::TYPE_VECTOR:
124 return (*m_)(t).get(Vector())*t+(*b_)(t).get(Vector());
134 ValueNode_Linear::get_name()const
140 ValueNode_Linear::get_local_name()const
146 ValueNode_Linear::check_type(ValueBase::Type type)
149 type==ValueBase::TYPE_ANGLE ||
150 type==ValueBase::TYPE_COLOR ||
151 type==ValueBase::TYPE_INTEGER ||
152 type==ValueBase::TYPE_REAL ||
153 type==ValueBase::TYPE_TIME ||
154 type==ValueBase::TYPE_VECTOR ;
158 ValueNode_Linear::set_link_vfunc(int i,ValueNode::Handle x)
160 assert(i==0 || i==1);
164 signal_child_changed()(i);signal_value_changed()();
170 signal_child_changed()(i);signal_value_changed()();
176 ValueNode::LooseHandle
177 ValueNode_Linear::get_link_vfunc(int i)const
179 assert(i==0 || i==1);
186 ValueNode_Linear::link_count()const
192 ValueNode_Linear::link_name(int i)const
194 assert(i==0 || i==1);
195 if(i==0) return "slope";
196 if(i==1) return "offset";
201 ValueNode_Linear::link_local_name(int i)const
203 assert(i==0 || i==1);
207 case ValueBase::TYPE_ANGLE:
208 case ValueBase::TYPE_COLOR:
209 case ValueBase::TYPE_INTEGER:
210 case ValueBase::TYPE_REAL:
211 case ValueBase::TYPE_TIME:
213 case ValueBase::TYPE_VECTOR:
223 ValueNode_Linear::get_link_index_from_name(const String &name)const
225 if(name=="slope") return 0;
226 if(name=="offset") return 1;
228 throw Exception::BadLinkName(name);