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
9 ** Copyright (c) 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_composite.h"
34 #include "valuenode_const.h"
37 #include "valuenode_radialcomposite.h"
41 #include "savecanvas.h"
45 /* === U S I N G =========================================================== */
49 using namespace synfig;
51 /* === M A C R O S ========================================================= */
53 /* === G L O B A L S ======================================================= */
55 /* === P R O C E D U R E S ================================================= */
57 /* === M E T H O D S ======================================================= */
59 synfig::ValueNode_Composite::ValueNode_Composite(const ValueBase &value):
60 LinkableValueNode(value.get_type())
64 case ValueBase::TYPE_VECTOR:
65 set_link("x",ValueNode_Const::create(value.get(Vector())[0]));
66 set_link("y",ValueNode_Const::create(value.get(Vector())[1]));
68 case ValueBase::TYPE_COLOR:
69 set_link("r",ValueNode_Const::create(value.get(Color()).get_r()));
70 set_link("g",ValueNode_Const::create(value.get(Color()).get_g()));
71 set_link("b",ValueNode_Const::create(value.get(Color()).get_b()));
72 set_link("a",ValueNode_Const::create(value.get(Color()).get_a()));
74 case ValueBase::TYPE_SEGMENT:
75 set_link("p1",ValueNode_Const::create(value.get(Segment()).p1));
76 set_link("t1",ValueNode_Const::create(value.get(Segment()).t1));
77 set_link("p2",ValueNode_Const::create(value.get(Segment()).p2));
78 set_link("t2",ValueNode_Const::create(value.get(Segment()).t2));
80 case ValueBase::TYPE_BLINEPOINT:
82 BLinePoint bline_point(value);
83 set_link(0,ValueNode_Const::create(bline_point.get_vertex()));
84 set_link(1,ValueNode_Const::create(bline_point.get_width()));
85 set_link(2,ValueNode_Const::create(bline_point.get_origin()));
86 set_link(3,ValueNode_Const::create(bline_point.get_split_tangent_flag()));
87 set_link(4,ValueNode_RadialComposite::create(bline_point.get_tangent1()));
88 set_link(5,ValueNode_RadialComposite::create(bline_point.get_tangent2()));
93 throw Exception::BadType(ValueBase::type_local_name(get_type()));
97 ValueNode_Composite::~ValueNode_Composite()
103 ValueNode_Composite::create(const ValueBase &value)
105 return new ValueNode_Composite(value);
109 ValueNode_Composite::create_new()const
111 return new ValueNode_Composite(ValueBase(get_type()));
115 synfig::ValueNode_Composite::operator()(Time t)const
119 case ValueBase::TYPE_VECTOR:
122 assert(components[0] && components[1]);
123 vect[0]=(*components[0])(t).get(Vector::value_type());
124 vect[1]=(*components[1])(t).get(Vector::value_type());
127 case ValueBase::TYPE_COLOR:
130 assert(components[0] && components[1] && components[2] && components[3]);
131 color.set_r((*components[0])(t).get(Vector::value_type()));
132 color.set_g((*components[1])(t).get(Vector::value_type()));
133 color.set_b((*components[2])(t).get(Vector::value_type()));
134 color.set_a((*components[3])(t).get(Vector::value_type()));
137 case ValueBase::TYPE_SEGMENT:
140 assert(components[0] && components[1] && components[2] && components[3]);
141 seg.p1=(*components[0])(t).get(Point());
142 seg.t1=(*components[1])(t).get(Vector());
143 seg.p2=(*components[2])(t).get(Point());
144 seg.t2=(*components[3])(t).get(Vector());
147 case ValueBase::TYPE_BLINEPOINT:
150 assert(components[0] && components[1] && components[2] && components[3] && components[4] && components[5]);
151 ret.set_vertex((*components[0])(t).get(Point()));
152 ret.set_width((*components[1])(t).get(Real()));
153 ret.set_origin((*components[2])(t).get(Real()));
154 ret.set_split_tangent_flag((*components[3])(t).get(bool()));
155 ret.set_tangent1((*components[4])(t).get(Vector()));
156 if(ret.get_split_tangent_flag())
157 ret.set_tangent2((*components[5])(t).get(Vector()));
161 synfig::error(string("ValueNode_Composite::operator():")+_("Bad type for composite"));
162 assert(components[0]);
163 return (*components[0])(t);
168 ValueNode_Composite::link_count()const
172 case ValueBase::TYPE_VECTOR:
174 case ValueBase::TYPE_COLOR:
176 case ValueBase::TYPE_SEGMENT:
178 case ValueBase::TYPE_BLINEPOINT:
181 synfig::warning(string("ValueNode_Composite::component_count():")+_("Bad type for composite"));
187 ValueNode_Composite::set_link_vfunc(int i,ValueNode::Handle x)
189 assert(i>=0 && i<link_count());
191 if(PlaceholderValueNode::Handle::cast_dynamic(x))
199 case ValueBase::TYPE_VECTOR:
200 if(x->get_type()==ValueBase(Real()).get_type() || PlaceholderValueNode::Handle::cast_dynamic(x))
207 case ValueBase::TYPE_COLOR:
208 if(x->get_type()==ValueBase(Real()).get_type() || PlaceholderValueNode::Handle::cast_dynamic(x))
215 case ValueBase::TYPE_SEGMENT:
216 if(x->get_type()==ValueBase(Point()).get_type() || PlaceholderValueNode::Handle::cast_dynamic(x))
223 case ValueBase::TYPE_BLINEPOINT:
224 if((i==0 || i==4 || i==5) && x->get_type()==ValueBase(Point()).get_type())
229 if((i==1 || i==2) && x->get_type()==ValueBase(Real()).get_type())
234 if(i==3 && x->get_type()==ValueBase(bool()).get_type())
247 ValueNode::LooseHandle
248 ValueNode_Composite::get_link_vfunc(int i)const
250 assert(i>=0 && i<link_count());
252 return components[i];
256 ValueNode_Composite::link_local_name(int i)const
258 assert(i>=0 && i<link_count());
262 case ValueBase::TYPE_VECTOR:
263 return strprintf("%c-Axis",'X'+i);
265 case ValueBase::TYPE_COLOR:
275 case ValueBase::TYPE_SEGMENT:
277 return _("Vertex 1");
279 return _("Tangent 1");
281 return _("Vertex 2");
283 return _("Tangent 2");
285 case ValueBase::TYPE_BLINEPOINT:
293 return _("Split Tangents");
295 return _("Tangent 1");
297 return _("Tangent 2");
301 // notice that Composite counts from 1 and Radial Composite counts
302 // from 0! we need to keep it like that to correctly load old
303 // animations, but let's not save "c%d" format link names in future
304 return etl::strprintf(_("C%d"),i+1);
310 ValueNode_Composite::link_name(int i)const
312 assert(i>=0 && i<link_count());
314 if (get_file_version() < RELEASE_VERSION_0_61_08)
315 return strprintf("c%d",i+1);
319 case ValueBase::TYPE_COLOR:
322 case 0: return "red";
323 case 1: return "green";
324 case 2: return "blue";
325 case 3: return "alpha";
328 case ValueBase::TYPE_SEGMENT:
337 case ValueBase::TYPE_VECTOR:
344 case ValueBase::TYPE_BLINEPOINT:
347 case 0: return "point";
348 case 1: return "width";
349 case 2: return "origin";
350 case 3: return "split";
360 // notice that Composite counts from 1 and Radial Composite counts
361 // from 0! we need to keep it like that to correctly load old
362 // animations, but let's not save "c%d" format link names in future
363 return strprintf("c%d",i+1);
367 ValueNode_Composite::get_link_index_from_name(const String &name)const
370 throw Exception::BadLinkName(name);
372 if(name[0]=='c' && name.size() == 2 && name[1]-'1' >= 0 && name[1]-'1' < link_count())
377 case ValueBase::TYPE_COLOR:
386 case ValueBase::TYPE_SEGMENT:
395 case ValueBase::TYPE_VECTOR:
400 if(name[0]=='z') // \todo "z"? really?
402 case ValueBase::TYPE_BLINEPOINT:
403 if(name[0]=='p' || name=="v1" || name=="p1")
405 if(name=="w" || name=="width")
407 if(name=="o" || name=="origin")
419 throw Exception::BadLinkName(name);
423 ValueNode_Composite::get_name()const
429 ValueNode_Composite::get_local_name()const
431 return _("Composite");
435 ValueNode_Composite::check_type(ValueBase::Type type)
438 type==ValueBase::TYPE_SEGMENT ||
439 type==ValueBase::TYPE_VECTOR ||
440 type==ValueBase::TYPE_COLOR ||
441 type==ValueBase::TYPE_BLINEPOINT;