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"
40 #include "savecanvas.h"
44 /* === U S I N G =========================================================== */
48 using namespace synfig;
50 /* === M A C R O S ========================================================= */
52 /* === G L O B A L S ======================================================= */
54 /* === P R O C E D U R E S ================================================= */
56 /* === M E T H O D S ======================================================= */
58 synfig::ValueNode_Composite::ValueNode_Composite(const ValueBase &value):
59 LinkableValueNode(value.get_type())
63 case ValueBase::TYPE_VECTOR:
64 set_link("x",ValueNode_Const::create(value.get(Vector())[0]));
65 set_link("y",ValueNode_Const::create(value.get(Vector())[1]));
67 case ValueBase::TYPE_COLOR:
68 set_link("r",ValueNode_Const::create(value.get(Color()).get_r()));
69 set_link("g",ValueNode_Const::create(value.get(Color()).get_g()));
70 set_link("b",ValueNode_Const::create(value.get(Color()).get_b()));
71 set_link("a",ValueNode_Const::create(value.get(Color()).get_a()));
73 case ValueBase::TYPE_SEGMENT:
74 set_link("p1",ValueNode_Const::create(value.get(Segment()).p1));
75 set_link("t1",ValueNode_Const::create(value.get(Segment()).t1));
76 set_link("p2",ValueNode_Const::create(value.get(Segment()).p2));
77 set_link("t2",ValueNode_Const::create(value.get(Segment()).t2));
79 case ValueBase::TYPE_BLINEPOINT:
81 BLinePoint bline_point(value);
82 set_link(0,ValueNode_Const::create(bline_point.get_vertex()));
83 set_link(1,ValueNode_Const::create(bline_point.get_width()));
84 set_link(2,ValueNode_Const::create(bline_point.get_origin()));
85 set_link(3,ValueNode_Const::create(bline_point.get_split_tangent_flag()));
86 set_link(4,ValueNode_RadialComposite::create(bline_point.get_tangent1()));
87 set_link(5,ValueNode_RadialComposite::create(bline_point.get_tangent2()));
92 throw Exception::BadType(ValueBase::type_local_name(get_type()));
96 ValueNode_Composite::~ValueNode_Composite()
102 ValueNode_Composite::create(const ValueBase &value)
104 return new ValueNode_Composite(value);
108 ValueNode_Composite::create_new()const
110 return new ValueNode_Composite(ValueBase(get_type()));
114 synfig::ValueNode_Composite::operator()(Time t)const
118 case ValueBase::TYPE_VECTOR:
121 assert(components[0] && components[1]);
122 vect[0]=(*components[0])(t).get(Vector::value_type());
123 vect[1]=(*components[1])(t).get(Vector::value_type());
126 case ValueBase::TYPE_COLOR:
129 assert(components[0] && components[1] && components[2] && components[3]);
130 color.set_r((*components[0])(t).get(Vector::value_type()));
131 color.set_g((*components[1])(t).get(Vector::value_type()));
132 color.set_b((*components[2])(t).get(Vector::value_type()));
133 color.set_a((*components[3])(t).get(Vector::value_type()));
136 case ValueBase::TYPE_SEGMENT:
139 assert(components[0] && components[1] && components[2] && components[3]);
140 seg.p1=(*components[0])(t).get(Point());
141 seg.t1=(*components[1])(t).get(Vector());
142 seg.p2=(*components[2])(t).get(Point());
143 seg.t2=(*components[3])(t).get(Vector());
146 case ValueBase::TYPE_BLINEPOINT:
149 assert(components[0] && components[1] && components[2] && components[3] && components[4] && components[5]);
150 ret.set_vertex((*components[0])(t).get(Point()));
151 ret.set_width((*components[1])(t).get(Real()));
152 ret.set_origin((*components[2])(t).get(Real()));
153 ret.set_split_tangent_flag((*components[3])(t).get(bool()));
154 ret.set_tangent1((*components[4])(t).get(Vector()));
155 if(ret.get_split_tangent_flag())
156 ret.set_tangent2((*components[5])(t).get(Vector()));
160 synfig::error(string("ValueNode_Composite::operator():")+_("Bad type for composite"));
161 assert(components[0]);
162 return (*components[0])(t);
167 ValueNode_Composite::link_count()const
171 case ValueBase::TYPE_VECTOR:
173 case ValueBase::TYPE_COLOR:
175 case ValueBase::TYPE_SEGMENT:
177 case ValueBase::TYPE_BLINEPOINT:
180 synfig::warning(string("ValueNode_Composite::component_count():")+_("Bad type for composite"));
186 ValueNode_Composite::set_link_vfunc(int i,ValueNode::Handle x)
188 assert(i>=0 && i<link_count());
190 if(PlaceholderValueNode::Handle::cast_dynamic(x))
198 case ValueBase::TYPE_VECTOR:
199 if(x->get_type()==ValueBase(Real()).get_type() || PlaceholderValueNode::Handle::cast_dynamic(x))
206 case ValueBase::TYPE_COLOR:
207 if(x->get_type()==ValueBase(Real()).get_type() || PlaceholderValueNode::Handle::cast_dynamic(x))
214 case ValueBase::TYPE_SEGMENT:
215 if(x->get_type()==ValueBase(Point()).get_type() || PlaceholderValueNode::Handle::cast_dynamic(x))
222 case ValueBase::TYPE_BLINEPOINT:
223 if((i==0 || i==4 || i==5) && x->get_type()==ValueBase(Point()).get_type())
228 if((i==1 || i==2) && x->get_type()==ValueBase(Real()).get_type())
233 if(i==3 && x->get_type()==ValueBase(bool()).get_type())
246 ValueNode::LooseHandle
247 ValueNode_Composite::get_link_vfunc(int i)const
249 assert(i>=0 && i<link_count());
251 return components[i];
255 ValueNode_Composite::link_local_name(int i)const
257 assert(i>=0 && i<link_count());
261 case ValueBase::TYPE_VECTOR:
262 return strprintf("%c-Axis",'X'+i);
264 case ValueBase::TYPE_COLOR:
274 case ValueBase::TYPE_SEGMENT:
276 return _("Vertex 1");
278 return _("Tangent 1");
280 return _("Vertex 2");
282 return _("Tangent 2");
284 case ValueBase::TYPE_BLINEPOINT:
292 return _("Split Tangents");
294 return _("Tangent 1");
296 return _("Tangent 2");
300 // notice that Composite counts from 1 and Radial Composite counts
301 // from 0! we need to keep it like that to correctly load old
302 // animations, but let's not save "c%d" format link names in future
303 return etl::strprintf(_("C%d"),i+1);
309 ValueNode_Composite::link_name(int i)const
311 assert(i>=0 && i<link_count());
313 if (get_file_version() < RELEASE_VERSION_0_61_08)
314 return strprintf("c%d",i+1);
318 case ValueBase::TYPE_COLOR:
321 case 0: return "red";
322 case 1: return "green";
323 case 2: return "blue";
324 case 3: return "alpha";
327 case ValueBase::TYPE_SEGMENT:
336 case ValueBase::TYPE_VECTOR:
343 case ValueBase::TYPE_BLINEPOINT:
346 case 0: return "point";
347 case 1: return "width";
348 case 2: return "origin";
349 case 3: return "split";
359 // notice that Composite counts from 1 and Radial Composite counts
360 // from 0! we need to keep it like that to correctly load old
361 // animations, but let's not save "c%d" format link names in future
362 return strprintf("c%d",i+1);
366 ValueNode_Composite::get_link_index_from_name(const String &name)const
369 throw Exception::BadLinkName(name);
371 if(name[0]=='c' && name.size() == 2 && name[1]-'1' >= 0 && name[1]-'1' < link_count())
376 case ValueBase::TYPE_COLOR:
385 case ValueBase::TYPE_SEGMENT:
394 case ValueBase::TYPE_VECTOR:
399 if(name[0]=='z') // \todo "z"? really?
401 case ValueBase::TYPE_BLINEPOINT:
402 if(name[0]=='p' || name=="v1" || name=="p1")
404 if(name=="w" || name=="width")
406 if(name=="o" || name=="origin")
418 throw Exception::BadLinkName(name);
422 ValueNode_Composite::get_name()const
428 ValueNode_Composite::get_local_name()const
430 return _("Composite");
434 ValueNode_Composite::check_type(ValueBase::Type type)
437 type==ValueBase::TYPE_SEGMENT ||
438 type==ValueBase::TYPE_VECTOR ||
439 type==ValueBase::TYPE_COLOR ||
440 type==ValueBase::TYPE_BLINEPOINT;