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())
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_local_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
109 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
110 printf("%s:%d operator()\n", __FILE__, __LINE__);
114 case ValueBase::TYPE_ANGLE:
115 return (*m_)(t).get( Angle())*t+(*b_)(t).get( Angle());
116 case ValueBase::TYPE_COLOR:
117 return (*m_)(t).get( Color())*t+(*b_)(t).get( Color());
118 case ValueBase::TYPE_INTEGER:
119 return round_to_int((*m_)(t).get(int())*t+(*b_)(t).get(int()));
120 case ValueBase::TYPE_REAL:
121 return (*m_)(t).get( Real())*t+(*b_)(t).get( Real());
122 case ValueBase::TYPE_TIME:
123 return (*m_)(t).get( Time())*t+(*b_)(t).get( Time());
124 case ValueBase::TYPE_VECTOR:
125 return (*m_)(t).get(Vector())*t+(*b_)(t).get(Vector());
135 ValueNode_Linear::get_name()const
141 ValueNode_Linear::get_local_name()const
147 ValueNode_Linear::check_type(ValueBase::Type type)
150 type==ValueBase::TYPE_ANGLE ||
151 type==ValueBase::TYPE_COLOR ||
152 type==ValueBase::TYPE_INTEGER ||
153 type==ValueBase::TYPE_REAL ||
154 type==ValueBase::TYPE_TIME ||
155 type==ValueBase::TYPE_VECTOR ;
159 ValueNode_Linear::set_link_vfunc(int i,ValueNode::Handle value)
161 assert(i>=0 && i<link_count());
165 case 0: CHECK_TYPE_AND_SET_VALUE(m_, get_type());
166 case 1: CHECK_TYPE_AND_SET_VALUE(b_, get_type());
171 ValueNode::LooseHandle
172 ValueNode_Linear::get_link_vfunc(int i)const
174 assert(i>=0 && i<link_count());
182 ValueNode_Linear::link_count()const
188 ValueNode_Linear::link_name(int i)const
190 assert(i>=0 && i<link_count());
192 if(i==0) return "slope";
193 if(i==1) return "offset";
198 ValueNode_Linear::link_local_name(int i)const
200 assert(i>=0 && i<link_count());
205 case ValueBase::TYPE_ANGLE:
206 case ValueBase::TYPE_COLOR:
207 case ValueBase::TYPE_INTEGER:
208 case ValueBase::TYPE_REAL:
209 case ValueBase::TYPE_TIME:
211 case ValueBase::TYPE_VECTOR:
221 ValueNode_Linear::get_link_index_from_name(const String &name)const
223 if(name=="slope") return 0;
224 if(name=="offset") return 1;
226 throw Exception::BadLinkName(name);