1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_scale.cpp
3 ** \brief Template File
5 ** $Id: valuenode_scale.cpp,v 1.1.1.1 2005/01/04 01:23:15 darco Exp $
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():LinkableValueNode(synfig::ValueBase::TYPE_NIL)
64 ValueNode_Scale::create(const ValueBase& x)
66 ValueNode_Scale* value_node;
69 case ValueBase::TYPE_VECTOR:
70 case ValueBase::TYPE_REAL:
71 case ValueBase::TYPE_TIME:
72 case ValueBase::TYPE_INTEGER:
73 case ValueBase::TYPE_ANGLE:
74 case ValueBase::TYPE_COLOR:
75 value_node=new ValueNode_Scale();
76 if(!value_node->set_value_node(ValueNode_Const::create(x)))
78 assert(value_node->get_value_node()->get_type()==x.get_type());
82 throw runtime_error("synfig::ValueNode_Scale:Bad type "+ValueBase::type_name(x.get_type()));
85 assert(value_node->get_type()==x.get_type());
91 ValueNode_Scale::create_new()const
93 return new ValueNode_Scale();
96 synfig::ValueNode_Scale::~ValueNode_Scale()
102 ValueNode_Scale::set_scalar(Real x)
104 set_link("scalar",ValueNode::Handle(ValueNode_Const::create(x)));
108 ValueNode_Scale::set_scalar(const ValueNode::Handle &x)
111 || x->get_type()!=ValueBase::TYPE_REAL
112 && !PlaceholderValueNode::Handle::cast_dynamic(x)
120 ValueNode_Scale::get_scalar()const
126 ValueNode_Scale::set_value_node(const ValueNode::Handle &x)
129 || ( get_type()==ValueBase::TYPE_NIL
130 && !check_type(x->get_type()) )
131 || ( get_type()!=ValueBase::TYPE_NIL
132 && x->get_type()!=get_type() ) &&
133 !PlaceholderValueNode::Handle::cast_dynamic(x)
137 assert(!(PlaceholderValueNode::Handle::cast_dynamic(x) && !get_type()));
142 set_type(x->get_type());
148 ValueNode_Scale::get_value_node()const
155 synfig::ValueNode_Scale::operator()(Time t)const
157 if(!value_node || !scalar)
158 throw runtime_error(strprintf("ValueNode_Scale: %s",_("One or both of my parameters aren't set!")));
160 if(get_type()==ValueBase::TYPE_VECTOR)
161 return (*value_node)(t).get(Vector())*(*scalar)(t).get(Real());
163 if(get_type()==ValueBase::TYPE_REAL)
164 return (*value_node)(t).get(Real())*(*scalar)(t).get(Real());
166 if(get_type()==ValueBase::TYPE_TIME)
167 return (*value_node)(t).get(Time())*(*scalar)(t).get(Time());
169 if(get_type()==ValueBase::TYPE_INTEGER)
170 return (*value_node)(t).get(int())*(*scalar)(t).get(Real());
172 if(get_type()==ValueBase::TYPE_ANGLE)
173 return (*value_node)(t).get(Angle())*(*scalar)(t).get(Real());
175 if(get_type()==ValueBase::TYPE_COLOR)
177 Color ret((*value_node)(t).get(Color()));
178 Real s((*scalar)(t).get(Real()));
179 ret.set_r(ret.get_r()*s);
180 ret.set_g(ret.get_r()*s);
181 ret.set_b(ret.get_r()*s);
191 ValueNode_Scale::set_link_vfunc(int i,ValueNode::Handle x)
196 if(i==0 && !set_value_node(x))
199 if(i==1 && !set_scalar(x))
202 signal_child_changed()(i);signal_value_changed()();
207 ValueNode::LooseHandle
208 ValueNode_Scale::get_link_vfunc(int i)const
210 assert(i==0 || i==1);
219 ValueNode_Scale::link_count()const
225 ValueNode_Scale::link_local_name(int i)const
227 assert(i==0 || i==1);
236 ValueNode_Scale::link_name(int i)const
238 assert(i==0 || i==1);
247 ValueNode_Scale::get_link_index_from_name(const String &name)const
254 throw Exception::BadLinkName(name);
258 ValueNode_Scale::get_name()const
264 ValueNode_Scale::get_local_name()const
270 ValueNode_Scale::check_type(ValueBase::Type type)
273 type==ValueBase::TYPE_VECTOR ||
274 type==ValueBase::TYPE_REAL ||
275 type==ValueBase::TYPE_INTEGER ||
276 type==ValueBase::TYPE_COLOR ||
277 type==ValueBase::TYPE_ANGLE;