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())
58 Vocab ret(get_children_vocab());
59 set_children_vocab(ret);
62 case ValueBase::TYPE_VECTOR:
64 Vector vect(value.get(Vector()));
65 set_link("r",ValueNode_Const::create(vect.mag()));
66 set_link("t",ValueNode_Const::create(Angle(Angle::tan(vect[1],vect[0]))));
69 case ValueBase::TYPE_COLOR:
70 set_link("y",ValueNode_Const::create(value.get(Color()).get_y()));
71 set_link("s",ValueNode_Const::create(value.get(Color()).get_s()));
72 set_link("h",ValueNode_Const::create(value.get(Color()).get_hue()));
73 set_link("a",ValueNode_Const::create(value.get(Color()).get_a()));
77 throw Exception::BadType(ValueBase::type_local_name(get_type()));
81 ValueNode_RadialComposite::~ValueNode_RadialComposite()
86 ValueNode_RadialComposite*
87 ValueNode_RadialComposite::create(const ValueBase &value)
89 return new ValueNode_RadialComposite(value);
93 ValueNode_RadialComposite::create_new()const
95 return new ValueNode_RadialComposite(ValueBase(get_type()));
99 synfig::ValueNode_RadialComposite::operator()(Time t)const
101 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
102 printf("%s:%d operator()\n", __FILE__, __LINE__);
106 case ValueBase::TYPE_VECTOR:
110 assert(components[0] && components[1]);
111 mag=(*components[0])(t).get(mag);
112 angle=(*components[1])(t).get(angle);
113 return Vector(Angle::cos(angle).get()*mag,Angle::sin(angle).get()*mag);
115 case ValueBase::TYPE_COLOR:
117 assert(components[0] && components[1] && components[2] && components[3]);
119 (*components[0])(t).get(Real()),
120 (*components[1])(t).get(Real()),
121 (*components[2])(t).get(Angle()),
122 (*components[3])(t).get(Real())
126 synfig::error(string("ValueNode_RadialComposite::operator():")+_("Bad type for radialcomposite"));
127 assert(components[0]);
128 return (*components[0])(t);
133 ValueNode_RadialComposite::set_link_vfunc(int i,ValueNode::Handle x)
135 assert(i>=0 && i<link_count());
137 if(PlaceholderValueNode::Handle::cast_dynamic(x))
145 case ValueBase::TYPE_VECTOR:
146 if(i==0 && x->get_type()!=ValueBase::TYPE_REAL)
148 if(i==1 && x->get_type()!=ValueBase::TYPE_ANGLE)
154 case ValueBase::TYPE_COLOR:
155 if((i==0 || i==1 || i==3) && x->get_type()!=ValueBase::TYPE_REAL)
157 if((i==2) && x->get_type()!=ValueBase::TYPE_ANGLE)
170 ValueNode::LooseHandle
171 ValueNode_RadialComposite::get_link_vfunc(int i)const
173 assert(i>=0 && i<link_count());
175 return components[i];
179 ValueNode_RadialComposite::link_name(int i)const
181 assert(i>=0 && i<link_count());
183 if (get_file_version() < RELEASE_VERSION_0_61_08)
184 return strprintf("c%d",i);
186 return LinkableValueNode::link_name(i);
190 ValueNode_RadialComposite::get_link_index_from_name(const String &name)const
192 // Here we don't use the LinkableValueNode::get_link_index_from_name
193 // due to the particularities of the link index from name for old files.
194 // So we keep this alive to maintain old file compatibilities.
196 throw Exception::BadLinkName(name);
198 if(name[0]=='c' && name.size() == 2 && name[1]-'0' >= 0 && name[1]-'0' < link_count())
203 case ValueBase::TYPE_COLOR:
212 case ValueBase::TYPE_VECTOR:
221 throw Exception::BadLinkName(name);
225 ValueNode_RadialComposite::get_name()const
227 return "radial_composite";
231 ValueNode_RadialComposite::get_local_name()const
233 return _("Radial Composite");
237 ValueNode_RadialComposite::check_type(ValueBase::Type type)
240 type==ValueBase::TYPE_VECTOR ||
241 type==ValueBase::TYPE_COLOR;
244 LinkableValueNode::Vocab
245 ValueNode_RadialComposite::get_children_vocab_vfunc()const
247 if(children_vocab.size())
248 return children_vocab;
250 LinkableValueNode::Vocab ret;
254 case ValueBase::TYPE_COLOR:
255 ret.push_back(ParamDesc(ValueBase(),"y_luma")
256 .set_local_name(_("Luma"))
258 ret.push_back(ParamDesc(ValueBase(),"saturation")
259 .set_local_name(_("Saturation"))
261 ret.push_back(ParamDesc(ValueBase(),"hue")
262 .set_local_name(_("Hue"))
264 ret.push_back(ParamDesc(ValueBase(),"alpha")
265 .set_local_name(_("Saturation"))
269 case ValueBase::TYPE_VECTOR:
270 ret.push_back(ParamDesc(ValueBase(),"radius")
271 .set_local_name(_("Radius"))
272 .set_description(_("The length of the vector"))
274 ret.push_back(ParamDesc(ValueBase(),"theta")
275 .set_local_name(_("Theta"))
276 .set_description(_("The angle of the vector with the X axis"))