1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_radialcomposite.cpp
3 ** \brief Template File
5 ** $Id: valuenode_radialcomposite.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 ======================================================= */
32 #include "valuenode_radialcomposite.h"
33 #include "valuenode_const.h"
39 /* === U S I N G =========================================================== */
43 using namespace synfig;
45 /* === M A C R O S ========================================================= */
47 /* === G L O B A L S ======================================================= */
49 /* === P R O C E D U R E S ================================================= */
51 /* === M E T H O D S ======================================================= */
53 synfig::ValueNode_RadialComposite::ValueNode_RadialComposite(const ValueBase &value):
54 LinkableValueNode(value.get_type())
58 case ValueBase::TYPE_VECTOR:
60 Vector vect(value.get(Vector()));
61 set_link("r",ValueNode_Const::create(vect.mag()));
62 set_link("t",ValueNode_Const::create(Angle(Angle::tan(vect[1],vect[0]))));
65 case ValueBase::TYPE_COLOR:
66 set_link("y",ValueNode_Const::create(value.get(Color()).get_y()));
67 set_link("s",ValueNode_Const::create(value.get(Color()).get_s()));
68 set_link("h",ValueNode_Const::create(value.get(Color()).get_hue()));
69 set_link("a",ValueNode_Const::create(value.get(Color()).get_a()));
73 throw Exception::BadType(ValueBase::type_name(get_type()));
77 ValueNode_RadialComposite::~ValueNode_RadialComposite()
82 ValueNode_RadialComposite*
83 ValueNode_RadialComposite::create(const ValueBase &value)
85 return new ValueNode_RadialComposite(value);
89 ValueNode_RadialComposite::create_new()const
91 return new ValueNode_RadialComposite(ValueBase(get_type()));
95 synfig::ValueNode_RadialComposite::operator()(Time t)const
99 case ValueBase::TYPE_VECTOR:
103 assert(components[0] && components[1]);
104 mag=(*components[0])(t).get(mag);
105 angle=(*components[1])(t).get(angle);
106 return Vector(Angle::cos(angle).get()*mag,Angle::sin(angle).get()*mag);
108 case ValueBase::TYPE_COLOR:
110 assert(components[0] && components[1] && components[2] && components[3]);
112 (*components[0])(t).get(Real()),
113 (*components[1])(t).get(Real()),
114 (*components[2])(t).get(Angle()),
115 (*components[3])(t).get(Real())
119 synfig::error(string("ValueNode_RadialComposite::operator():")+_("Bad type for radialcomposite"));
120 assert(components[0]);
121 return (*components[0])(t);
126 ValueNode_RadialComposite::link_count()const
130 case ValueBase::TYPE_VECTOR:
132 case ValueBase::TYPE_COLOR:
135 synfig::warning(string("ValueNode_RadialComposite::component_count():")+_("Bad type for radialcomposite"));
141 ValueNode_RadialComposite::set_link_vfunc(int i,ValueNode::Handle x)
146 if(PlaceholderValueNode::Handle::cast_dynamic(x))
154 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:
166 if((i==0 || i==1 || i==3) && x->get_type()!=ValueBase::TYPE_REAL)
168 if((i==2) && x->get_type()!=ValueBase::TYPE_ANGLE)
181 ValueNode::LooseHandle
182 ValueNode_RadialComposite::get_link_vfunc(int i)const
185 return components[i];
189 ValueNode_RadialComposite::link_local_name(int i)const
194 case ValueBase::TYPE_VECTOR:
201 case ValueBase::TYPE_COLOR:
205 return _("Saturation");
215 return etl::strprintf(_("C%d"),i+1);
220 ValueNode_RadialComposite::link_name(int i)const
223 return strprintf("c%d",i);
227 ValueNode_RadialComposite::get_link_index_from_name(const String &name)const
230 throw Exception::BadLinkName(name);
237 case ValueBase::TYPE_COLOR:
246 case ValueBase::TYPE_VECTOR:
255 throw Exception::BadLinkName(name);
259 ValueNode_RadialComposite::get_name()const
261 return "radial_composite";
265 ValueNode_RadialComposite::get_local_name()const
267 return _("RadialComposite");
271 ValueNode_RadialComposite::check_type(ValueBase::Type type)
274 type==ValueBase::TYPE_VECTOR ||
275 type==ValueBase::TYPE_COLOR;