1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
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 ** === N O T E S ===========================================================
23 ** ========================================================================= */
25 /* === H E A D E R S ======================================================= */
35 #include <ETL/stringf>
37 #include <ETL/hermite>
39 #include <synfig/string.h>
40 #include <synfig/time.h>
41 #include <synfig/context.h>
42 #include <synfig/paramdesc.h>
43 #include <synfig/renddesc.h>
44 #include <synfig/surface.h>
45 #include <synfig/value.h>
46 #include <synfig/valuenode.h>
47 #include <synfig/segment.h>
48 #include <synfig/valuenode_bline.h>
54 /* === M A C R O S ========================================================= */
58 /* === G L O B A L S ======================================================= */
60 SYNFIG_LAYER_INIT(Region);
61 SYNFIG_LAYER_SET_NAME(Region,"region");
62 SYNFIG_LAYER_SET_LOCAL_NAME(Region,_("Region"));
63 SYNFIG_LAYER_SET_CATEGORY(Region,_("Geometry"));
64 SYNFIG_LAYER_SET_VERSION(Region,"0.1");
65 SYNFIG_LAYER_SET_CVS_ID(Region,"$Id$");
67 /* === P R O C E D U R E S ================================================= */
69 /* === M E T H O D S ======================================================= */
71 /* === E N T R Y P O I N T ================================================= */
76 vector<BLinePoint> bline_point_list;
77 bline_point_list.push_back(BLinePoint());
78 bline_point_list.push_back(BLinePoint());
79 bline_point_list.push_back(BLinePoint());
80 bline_point_list[0].set_vertex(Point(0,1));
81 bline_point_list[1].set_vertex(Point(0,-1));
82 bline_point_list[2].set_vertex(Point(1,0));
83 bline_point_list[0].set_tangent(bline_point_list[1].get_vertex()-bline_point_list[2].get_vertex()*0.5f);
84 bline_point_list[1].set_tangent(bline_point_list[2].get_vertex()-bline_point_list[0].get_vertex()*0.5f);
85 bline_point_list[2].set_tangent(bline_point_list[0].get_vertex()-bline_point_list[1].get_vertex()*0.5f);
86 bline_point_list[0].set_width(1.0f);
87 bline_point_list[1].set_width(1.0f);
88 bline_point_list[2].set_width(1.0f);
89 bline=bline_point_list;
95 if(bline.get_contained_type()==ValueBase::TYPE_BLINEPOINT)
97 segment_list=convert_bline_to_segment_list(bline);
101 synfig::warning("Region: incorrect type on bline, layer disabled");
106 if(segment_list.empty())
108 synfig::warning("Region: segment_list is empty, layer disabled");
113 bool looped = bline.get_loop();
115 Vector::value_type n;
116 etl::hermite<Vector> curve;
117 vector<Point> vector_list;
119 vector<Segment>::const_iterator iter=segment_list.begin();
120 //Vector last = iter->p1;
122 //make sure the shape has a clean slate for writing
125 //and start off at the first point
126 //move_to(last[0],last[1]);
128 for(;iter!=segment_list.end();++iter)
130 //connect them with a line if they aren't already joined
131 /*if(iter->p1 != last)
133 line_to(iter->p1[0],iter->p1[1]);
136 //curve to the next end point
137 curve_to(iter->p1[0] + iter->t1[0]/3.0,iter->p1[1] + iter->t1[1]/3.0,
138 iter->p2[0] - iter->t2[0]/3.0,iter->p2[1] - iter->t2[1]/3.0,
139 iter->p2[0],iter->p2[1]);
143 if(iter->t1.is_equal_to(Vector(0,0)) && iter->t2.is_equal_to(Vector(0,0)))
145 vector_list.push_back(iter->p2);
155 for(n=0.0;n<1.0;n+=1.0/SAMPLES)
156 vector_list.push_back(curve(n));
160 //add the starting point onto the end so it actually fits the shape, so we can be extra awesome...
162 vector_list.push_back(segment_list[0].p1);
165 add_polygon(vector_list);
172 Region::set_param(const String & param, const ValueBase &value)
174 if(param=="segment_list")
176 if(dynamic_param_list().count("segment_list"))
178 connect_dynamic_param("bline",dynamic_param_list().find("segment_list")->second);
179 disconnect_dynamic_param("segment_list");
180 synfig::warning("Region::set_param(): Updated valuenode connection to use the new \"bline\" parameter.");
183 synfig::warning("Region::set_param(): The parameter \"segment_list\" is deprecated. Use \"bline\" instead.");
186 if( (param=="segment_list" || param=="bline") && value.get_type()==ValueBase::TYPE_LIST)
188 //if(value.get_contained_type()!=ValueBase::TYPE_BLINEPOINT)
196 /* if( param=="segment_list" && value.get_type()==ValueBase::TYPE_LIST)
198 if(value.get_contained_type()==ValueBase::TYPE_BLINEPOINT)
199 segment_list=convert_bline_to_segment_list(value);
201 if(value.get_contained_type()==ValueBase::TYPE_SEGMENT)
205 segment_list.clear();
212 return Layer_Shape::set_param(param,value);
216 Region::get_param(const String& param)const
222 return Layer_Shape::get_param(param);
226 Region::get_param_vocab()const
228 Layer::Vocab ret(Layer_Shape::get_param_vocab());
230 ret.push_back(ParamDesc("bline")
231 .set_local_name(_("Vertices"))
232 .set_origin("offset")
239 Region::set_time(Context context, Time time)const
241 const_cast<Region*>(this)->sync();
242 context.set_time(time);
246 Region::set_time(Context context, Time time, Vector pos)const
248 const_cast<Region*>(this)->sync();
249 context.set_time(time,pos);