1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_scale.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 ======================================================= */
33 #include "valuenode_scale.h"
34 #include "valuenode_const.h"
44 /* === U S I N G =========================================================== */
48 using namespace synfig;
50 /* === M A C R O S ========================================================= */
52 /* === G L O B A L S ======================================================= */
54 /* === P R O C E D U R E S ================================================= */
56 /* === M E T H O D S ======================================================= */
58 ValueNode_Scale::ValueNode_Scale():
59 LinkableValueNode(synfig::ValueBase::TYPE_NIL)
65 ValueNode_Scale::create(const ValueBase& x)
67 ValueNode_Scale* value_node;
70 case ValueBase::TYPE_VECTOR:
71 case ValueBase::TYPE_REAL:
72 case ValueBase::TYPE_TIME:
73 case ValueBase::TYPE_INTEGER:
74 case ValueBase::TYPE_ANGLE:
75 case ValueBase::TYPE_COLOR:
76 value_node=new ValueNode_Scale();
77 if(!value_node->set_value_node(ValueNode_Const::create(x)))
79 assert(value_node->get_value_node()->get_type()==x.get_type());
83 throw runtime_error("synfig::ValueNode_Scale:Bad type "+ValueBase::type_name(x.get_type()));
86 assert(value_node->get_type()==x.get_type());
92 ValueNode_Scale::create_new()const
94 return new ValueNode_Scale();
97 synfig::ValueNode_Scale::~ValueNode_Scale()
103 ValueNode_Scale::set_scalar(Real x)
105 set_link("scalar",ValueNode::Handle(ValueNode_Const::create(x)));
109 ValueNode_Scale::set_scalar(const ValueNode::Handle &x)
112 || x->get_type()!=ValueBase::TYPE_REAL
113 && !PlaceholderValueNode::Handle::cast_dynamic(x)
121 ValueNode_Scale::get_scalar()const
127 ValueNode_Scale::set_value_node(const ValueNode::Handle &x)
130 || ( get_type()==ValueBase::TYPE_NIL
131 && !check_type(x->get_type()) )
132 || ( get_type()!=ValueBase::TYPE_NIL
133 && x->get_type()!=get_type() ) &&
134 !PlaceholderValueNode::Handle::cast_dynamic(x)
138 assert(!(PlaceholderValueNode::Handle::cast_dynamic(x) && !get_type()));
143 set_type(x->get_type());
149 ValueNode_Scale::get_value_node()const
156 synfig::ValueNode_Scale::operator()(Time t)const
158 if(!value_node || !scalar)
159 throw runtime_error(strprintf("ValueNode_Scale: %s",_("One or both of my parameters aren't set!")));
161 if(get_type()==ValueBase::TYPE_VECTOR)
162 return (*value_node)(t).get(Vector())*(*scalar)(t).get(Real());
164 if(get_type()==ValueBase::TYPE_REAL)
165 return (*value_node)(t).get(Real())*(*scalar)(t).get(Real());
167 if(get_type()==ValueBase::TYPE_TIME)
168 return (*value_node)(t).get(Time())*(*scalar)(t).get(Time());
170 if(get_type()==ValueBase::TYPE_INTEGER)
171 return (*value_node)(t).get(int())*(*scalar)(t).get(Real());
173 if(get_type()==ValueBase::TYPE_ANGLE)
174 return (*value_node)(t).get(Angle())*(*scalar)(t).get(Real());
176 if(get_type()==ValueBase::TYPE_COLOR)
178 Color ret((*value_node)(t).get(Color()));
179 Real s((*scalar)(t).get(Real()));
180 ret.set_r(ret.get_r()*s);
181 ret.set_g(ret.get_g()*s);
182 ret.set_b(ret.get_b()*s);
192 ValueNode_Scale::set_link_vfunc(int i,ValueNode::Handle x)
197 if(i==0 && !set_value_node(x))
200 if(i==1 && !set_scalar(x))
203 signal_child_changed()(i);signal_value_changed()();
208 ValueNode::LooseHandle
209 ValueNode_Scale::get_link_vfunc(int i)const
211 assert(i==0 || i==1);
220 ValueNode_Scale::link_count()const
226 ValueNode_Scale::link_local_name(int i)const
228 assert(i==0 || i==1);
237 ValueNode_Scale::link_name(int i)const
239 assert(i==0 || i==1);
248 ValueNode_Scale::get_link_index_from_name(const String &name)const
255 throw Exception::BadLinkName(name);
259 ValueNode_Scale::get_name()const
265 ValueNode_Scale::get_local_name()const
271 ValueNode_Scale::check_type(ValueBase::Type type)
274 type==ValueBase::TYPE_VECTOR ||
275 type==ValueBase::TYPE_REAL ||
276 type==ValueBase::TYPE_INTEGER ||
277 type==ValueBase::TYPE_COLOR ||
278 type==ValueBase::TYPE_ANGLE;