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, 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_radialcomposite.h"
34 #include "valuenode_const.h"
38 #include "savecanvas.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 synfig::ValueNode_RadialComposite::ValueNode_RadialComposite(const ValueBase &value):
56 LinkableValueNode(value.get_type())
60 case ValueBase::TYPE_VECTOR:
62 Vector vect(value.get(Vector()));
63 set_link("r",ValueNode_Const::create(vect.mag()));
64 set_link("t",ValueNode_Const::create(Angle(Angle::tan(vect[1],vect[0]))));
67 case ValueBase::TYPE_COLOR:
68 set_link("y",ValueNode_Const::create(value.get(Color()).get_y()));
69 set_link("s",ValueNode_Const::create(value.get(Color()).get_s()));
70 set_link("h",ValueNode_Const::create(value.get(Color()).get_hue()));
71 set_link("a",ValueNode_Const::create(value.get(Color()).get_a()));
75 throw Exception::BadType(ValueBase::type_local_name(get_type()));
79 ValueNode_RadialComposite::~ValueNode_RadialComposite()
84 ValueNode_RadialComposite*
85 ValueNode_RadialComposite::create(const ValueBase &value)
87 return new ValueNode_RadialComposite(value);
91 ValueNode_RadialComposite::create_new()const
93 return new ValueNode_RadialComposite(ValueBase(get_type()));
97 synfig::ValueNode_RadialComposite::operator()(Time t)const
101 case ValueBase::TYPE_VECTOR:
105 assert(components[0] && components[1]);
106 mag=(*components[0])(t).get(mag);
107 angle=(*components[1])(t).get(angle);
108 return Vector(Angle::cos(angle).get()*mag,Angle::sin(angle).get()*mag);
110 case ValueBase::TYPE_COLOR:
112 assert(components[0] && components[1] && components[2] && components[3]);
114 (*components[0])(t).get(Real()),
115 (*components[1])(t).get(Real()),
116 (*components[2])(t).get(Angle()),
117 (*components[3])(t).get(Real())
121 synfig::error(string("ValueNode_RadialComposite::operator():")+_("Bad type for radialcomposite"));
122 assert(components[0]);
123 return (*components[0])(t);
128 ValueNode_RadialComposite::link_count()const
132 case ValueBase::TYPE_VECTOR:
134 case ValueBase::TYPE_COLOR:
137 synfig::warning(string("ValueNode_RadialComposite::component_count():")+_("Bad type for radialcomposite"));
143 ValueNode_RadialComposite::set_link_vfunc(int i,ValueNode::Handle x)
145 assert(i>=0 && i<link_count());
147 if(PlaceholderValueNode::Handle::cast_dynamic(x))
155 case ValueBase::TYPE_VECTOR:
156 if(i==0 && x->get_type()!=ValueBase::TYPE_REAL)
158 if(i==1 && x->get_type()!=ValueBase::TYPE_ANGLE)
164 case ValueBase::TYPE_COLOR:
165 if((i==0 || i==1 || i==3) && x->get_type()!=ValueBase::TYPE_REAL)
167 if((i==2) && x->get_type()!=ValueBase::TYPE_ANGLE)
180 ValueNode::LooseHandle
181 ValueNode_RadialComposite::get_link_vfunc(int i)const
183 assert(i>=0 && i<link_count());
185 return components[i];
189 ValueNode_RadialComposite::link_local_name(int i)const
191 assert(i>=0 && i<link_count());
195 case ValueBase::TYPE_VECTOR:
202 case ValueBase::TYPE_COLOR:
206 return _("Saturation");
218 // notice that Composite counts from 1 and Radial Composite counts
219 // from 0! we need to keep it like that to correctly load old
220 // animations, but let's not save "c%d" format link names in future
221 return etl::strprintf(_("C%d"),i);
226 ValueNode_RadialComposite::link_name(int i)const
228 assert(i>=0 && i<link_count());
230 if (get_file_version() < RELEASE_VERSION_0_61_08)
231 return strprintf("c%d",i);
235 case ValueBase::TYPE_COLOR:
238 case 0: return "y_luma"; // the 'luma' attribute is recognised by the fact that it starts with a 'y'
239 case 1: return "saturation";
240 case 2: return "hue";
241 case 3: return "alpha";
244 case ValueBase::TYPE_VECTOR:
247 case 0: return "radius";
248 case 1: return "theta";
256 // notice that Composite counts from 1 and Radial Composite counts
257 // from 0! we need to keep it like that to correctly load old
258 // animations, but let's not save "c%d" format link names in future
259 return strprintf("c%d",i);
263 ValueNode_RadialComposite::get_link_index_from_name(const String &name)const
266 throw Exception::BadLinkName(name);
268 if(name[0]=='c' && name.size() == 2 && name[1]-'0' >= 0 && name[1]-'0' < link_count())
273 case ValueBase::TYPE_COLOR:
282 case ValueBase::TYPE_VECTOR:
291 throw Exception::BadLinkName(name);
295 ValueNode_RadialComposite::get_name()const
297 return "radial_composite";
301 ValueNode_RadialComposite::get_local_name()const
303 return _("Radial Composite");
307 ValueNode_RadialComposite::check_type(ValueBase::Type type)
310 type==ValueBase::TYPE_VECTOR ||
311 type==ValueBase::TYPE_COLOR;