1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_radialcomposite.cpp
3 ** \brief Implementation of the "Radial Composite" valuenode conversion.
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_radialcomposite.h"
34 #include "valuenode_const.h"
40 /* === U S I N G =========================================================== */
44 using namespace synfig;
46 /* === M A C R O S ========================================================= */
48 /* === G L O B A L S ======================================================= */
50 /* === P R O C E D U R E S ================================================= */
52 /* === M E T H O D S ======================================================= */
54 synfig::ValueNode_RadialComposite::ValueNode_RadialComposite(const ValueBase &value):
55 LinkableValueNode(value.get_type())
59 case ValueBase::TYPE_VECTOR:
61 Vector vect(value.get(Vector()));
62 set_link("r",ValueNode_Const::create(vect.mag()));
63 set_link("t",ValueNode_Const::create(Angle(Angle::tan(vect[1],vect[0]))));
66 case ValueBase::TYPE_COLOR:
67 set_link("y",ValueNode_Const::create(value.get(Color()).get_y()));
68 set_link("s",ValueNode_Const::create(value.get(Color()).get_s()));
69 set_link("h",ValueNode_Const::create(value.get(Color()).get_hue()));
70 set_link("a",ValueNode_Const::create(value.get(Color()).get_a()));
74 throw Exception::BadType(ValueBase::type_local_name(get_type()));
78 ValueNode_RadialComposite::~ValueNode_RadialComposite()
83 ValueNode_RadialComposite*
84 ValueNode_RadialComposite::create(const ValueBase &value)
86 return new ValueNode_RadialComposite(value);
90 ValueNode_RadialComposite::create_new()const
92 return new ValueNode_RadialComposite(ValueBase(get_type()));
96 synfig::ValueNode_RadialComposite::operator()(Time t)const
100 case ValueBase::TYPE_VECTOR:
104 assert(components[0] && components[1]);
105 mag=(*components[0])(t).get(mag);
106 angle=(*components[1])(t).get(angle);
107 return Vector(Angle::cos(angle).get()*mag,Angle::sin(angle).get()*mag);
109 case ValueBase::TYPE_COLOR:
111 assert(components[0] && components[1] && components[2] && components[3]);
113 (*components[0])(t).get(Real()),
114 (*components[1])(t).get(Real()),
115 (*components[2])(t).get(Angle()),
116 (*components[3])(t).get(Real())
120 synfig::error(string("ValueNode_RadialComposite::operator():")+_("Bad type for radialcomposite"));
121 assert(components[0]);
122 return (*components[0])(t);
127 ValueNode_RadialComposite::link_count()const
131 case ValueBase::TYPE_VECTOR:
133 case ValueBase::TYPE_COLOR:
136 synfig::warning(string("ValueNode_RadialComposite::component_count():")+_("Bad type for radialcomposite"));
142 ValueNode_RadialComposite::set_link_vfunc(int i,ValueNode::Handle x)
144 assert(i>=0 && i<link_count());
146 if(PlaceholderValueNode::Handle::cast_dynamic(x))
154 case ValueBase::TYPE_VECTOR:
155 if(i==0 && x->get_type()!=ValueBase::TYPE_REAL)
157 if(i==1 && x->get_type()!=ValueBase::TYPE_ANGLE)
163 case ValueBase::TYPE_COLOR:
164 if((i==0 || i==1 || i==3) && x->get_type()!=ValueBase::TYPE_REAL)
166 if((i==2) && x->get_type()!=ValueBase::TYPE_ANGLE)
179 ValueNode::LooseHandle
180 ValueNode_RadialComposite::get_link_vfunc(int i)const
182 assert(i>=0 && i<link_count());
184 return components[i];
188 ValueNode_RadialComposite::link_local_name(int i)const
190 assert(i>=0 && i<link_count());
194 case ValueBase::TYPE_VECTOR:
201 case ValueBase::TYPE_COLOR:
205 return _("Saturation");
216 return etl::strprintf(_("C%d"),i+1);
221 ValueNode_RadialComposite::link_name(int i)const
223 assert(i>=0 && i<link_count());
225 return strprintf("c%d",i);
229 ValueNode_RadialComposite::get_link_index_from_name(const String &name)const
232 throw Exception::BadLinkName(name);
239 case ValueBase::TYPE_COLOR:
248 case ValueBase::TYPE_VECTOR:
257 throw Exception::BadLinkName(name);
261 ValueNode_RadialComposite::get_name()const
263 return "radial_composite";
267 ValueNode_RadialComposite::get_local_name()const
269 return _("Radial Composite");
273 ValueNode_RadialComposite::check_type(ValueBase::Type type)
276 type==ValueBase::TYPE_VECTOR ||
277 type==ValueBase::TYPE_COLOR;