1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_composite.cpp
3 ** \brief Implementation of the "Composite" valuenode conversion.
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_composite.h"
33 #include "valuenode_const.h"
36 #include "valuenode_radialcomposite.h"
43 /* === U S I N G =========================================================== */
47 using namespace synfig;
49 /* === M A C R O S ========================================================= */
51 /* === G L O B A L S ======================================================= */
53 /* === P R O C E D U R E S ================================================= */
55 /* === M E T H O D S ======================================================= */
57 synfig::ValueNode_Composite::ValueNode_Composite(const ValueBase &value):
58 LinkableValueNode(value.get_type())
62 case ValueBase::TYPE_VECTOR:
63 set_link("x",ValueNode_Const::create(value.get(Vector())[0]));
64 set_link("y",ValueNode_Const::create(value.get(Vector())[1]));
66 case ValueBase::TYPE_COLOR:
67 set_link("r",ValueNode_Const::create(value.get(Color()).get_r()));
68 set_link("g",ValueNode_Const::create(value.get(Color()).get_g()));
69 set_link("b",ValueNode_Const::create(value.get(Color()).get_b()));
70 set_link("a",ValueNode_Const::create(value.get(Color()).get_a()));
72 case ValueBase::TYPE_SEGMENT:
73 set_link("p1",ValueNode_Const::create(value.get(Segment()).p1));
74 set_link("t1",ValueNode_Const::create(value.get(Segment()).t1));
75 set_link("p2",ValueNode_Const::create(value.get(Segment()).p2));
76 set_link("t2",ValueNode_Const::create(value.get(Segment()).t2));
78 case ValueBase::TYPE_BLINEPOINT:
80 BLinePoint bline_point(value);
81 set_link(0,ValueNode_Const::create(bline_point.get_vertex()));
82 set_link(1,ValueNode_Const::create(bline_point.get_width()));
83 set_link(2,ValueNode_Const::create(bline_point.get_origin()));
84 set_link(3,ValueNode_Const::create(bline_point.get_split_tangent_flag()));
85 set_link(4,ValueNode_RadialComposite::create(bline_point.get_tangent1()));
86 set_link(5,ValueNode_RadialComposite::create(bline_point.get_tangent2()));
91 throw Exception::BadType(ValueBase::type_local_name(get_type()));
95 ValueNode_Composite::~ValueNode_Composite()
101 ValueNode_Composite::create(const ValueBase &value)
103 return new ValueNode_Composite(value);
107 ValueNode_Composite::create_new()const
109 return new ValueNode_Composite(ValueBase(get_type()));
113 synfig::ValueNode_Composite::operator()(Time t)const
117 case ValueBase::TYPE_VECTOR:
120 assert(components[0] && components[1]);
121 vect[0]=(*components[0])(t).get(Vector::value_type());
122 vect[1]=(*components[1])(t).get(Vector::value_type());
125 case ValueBase::TYPE_COLOR:
128 assert(components[0] && components[1] && components[2] && components[3]);
129 color.set_r((*components[0])(t).get(Vector::value_type()));
130 color.set_g((*components[1])(t).get(Vector::value_type()));
131 color.set_b((*components[2])(t).get(Vector::value_type()));
132 color.set_a((*components[3])(t).get(Vector::value_type()));
135 case ValueBase::TYPE_SEGMENT:
138 assert(components[0] && components[1] && components[2] && components[3]);
139 seg.p1=(*components[0])(t).get(Point());
140 seg.t1=(*components[1])(t).get(Vector());
141 seg.p2=(*components[2])(t).get(Point());
142 seg.t2=(*components[3])(t).get(Vector());
145 case ValueBase::TYPE_BLINEPOINT:
148 assert(components[0] && components[1] && components[2] && components[3] && components[4] && components[5]);
149 ret.set_vertex((*components[0])(t).get(Point()));
150 ret.set_width((*components[1])(t).get(Real()));
151 ret.set_origin((*components[2])(t).get(Real()));
152 ret.set_split_tangent_flag((*components[3])(t).get(bool()));
153 ret.set_tangent1((*components[4])(t).get(Vector()));
154 if(ret.get_split_tangent_flag())
155 ret.set_tangent2((*components[5])(t).get(Vector()));
159 synfig::error(string("ValueNode_Composite::operator():")+_("Bad type for composite"));
160 assert(components[0]);
161 return (*components[0])(t);
166 ValueNode_Composite::link_count()const
170 case ValueBase::TYPE_VECTOR:
172 case ValueBase::TYPE_COLOR:
174 case ValueBase::TYPE_SEGMENT:
176 case ValueBase::TYPE_BLINEPOINT:
179 synfig::warning(string("ValueNode_Composite::component_count():")+_("Bad type for composite"));
185 ValueNode_Composite::set_link_vfunc(int i,ValueNode::Handle x)
187 assert(i>=0 && i<link_count());
189 if(PlaceholderValueNode::Handle::cast_dynamic(x))
197 case ValueBase::TYPE_VECTOR:
198 if(x->get_type()==ValueBase(Real()).get_type() || PlaceholderValueNode::Handle::cast_dynamic(x))
205 case ValueBase::TYPE_COLOR:
206 if(x->get_type()==ValueBase(Real()).get_type() || PlaceholderValueNode::Handle::cast_dynamic(x))
213 case ValueBase::TYPE_SEGMENT:
214 if(x->get_type()==ValueBase(Point()).get_type() || PlaceholderValueNode::Handle::cast_dynamic(x))
221 case ValueBase::TYPE_BLINEPOINT:
222 if((i==0 || i==4 || i==5) && x->get_type()==ValueBase(Point()).get_type())
227 if((i==1 || i==2) && x->get_type()==ValueBase(Real()).get_type())
232 if(i==3 && x->get_type()==ValueBase(bool()).get_type())
245 ValueNode::LooseHandle
246 ValueNode_Composite::get_link_vfunc(int i)const
248 assert(i>=0 && i<link_count());
250 return components[i];
254 ValueNode_Composite::link_local_name(int i)const
256 assert(i>=0 && i<link_count());
260 case ValueBase::TYPE_VECTOR:
261 return strprintf("%c-Axis",'X'+i);
263 case ValueBase::TYPE_COLOR:
273 case ValueBase::TYPE_SEGMENT:
275 return _("Vertex 1");
277 return _("Tangent 1");
279 return _("Vertex 2");
281 return _("Tangent 2");
283 case ValueBase::TYPE_BLINEPOINT:
291 return _("Split Tangents");
293 return _("Tangent 1");
295 return _("Tangent 2");
299 // notice that Composite counts from 1 and Radial Composite counts
300 // from 0! we need to keep it like that to correctly load old
301 // animations, but let's not save "c%d" format link names in future
302 return etl::strprintf(_("C%d"),i+1);
308 ValueNode_Composite::link_name(int i)const
310 assert(i>=0 && i<link_count());
314 case ValueBase::TYPE_COLOR:
317 case 0: return "red";
318 case 1: return "green";
319 case 2: return "blue";
320 case 3: return "alpha";
323 case ValueBase::TYPE_SEGMENT:
332 case ValueBase::TYPE_VECTOR:
339 case ValueBase::TYPE_BLINEPOINT:
342 case 0: return "point";
343 case 1: return "width";
344 case 2: return "origin";
345 case 3: return "split";
355 // notice that Composite counts from 1 and Radial Composite counts
356 // from 0! we need to keep it like that to correctly load old
357 // animations, but let's not save "c%d" format link names in future
358 return strprintf("c%d",i+1);
362 ValueNode_Composite::get_link_index_from_name(const String &name)const
365 throw Exception::BadLinkName(name);
367 if(name[0]=='c' && name.size() == 2 && name[1]-'1' >= 0 && name[1]-'1' < link_count())
372 case ValueBase::TYPE_COLOR:
381 case ValueBase::TYPE_SEGMENT:
390 case ValueBase::TYPE_VECTOR:
395 if(name[0]=='z') // \todo "z"? really?
397 case ValueBase::TYPE_BLINEPOINT:
398 if(name[0]=='p' || name=="v1" || name=="p1")
400 if(name=="w" || name=="width")
402 if(name=="o" || name=="origin")
414 throw Exception::BadLinkName(name);
418 ValueNode_Composite::get_name()const
424 ValueNode_Composite::get_local_name()const
426 return _("Composite");
430 ValueNode_Composite::check_type(ValueBase::Type type)
433 type==ValueBase::TYPE_SEGMENT ||
434 type==ValueBase::TYPE_VECTOR ||
435 type==ValueBase::TYPE_COLOR ||
436 type==ValueBase::TYPE_BLINEPOINT;