1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
6 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
8 ** This package is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License as
10 ** published by the Free Software Foundation; either version 2 of
11 ** the License, or (at your option) any later version.
13 ** This package is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ** General Public License for more details.
19 ** === N O T E S ===========================================================
21 ** ========================================================================= */
23 /* === H E A D E R S ======================================================= */
33 #include <ETL/stringf>
35 #include <ETL/hermite>
37 #include <synfig/string.h>
38 #include <synfig/time.h>
39 #include <synfig/context.h>
40 #include <synfig/paramdesc.h>
41 #include <synfig/renddesc.h>
42 #include <synfig/surface.h>
43 #include <synfig/value.h>
44 #include <synfig/valuenode.h>
45 #include <synfig/segment.h>
46 #include <synfig/valuenode_bline.h>
52 /* === M A C R O S ========================================================= */
56 /* === G L O B A L S ======================================================= */
58 SYNFIG_LAYER_INIT(Region);
59 SYNFIG_LAYER_SET_NAME(Region,"region");
60 SYNFIG_LAYER_SET_LOCAL_NAME(Region,_("Region"));
61 SYNFIG_LAYER_SET_CATEGORY(Region,_("Geometry"));
62 SYNFIG_LAYER_SET_VERSION(Region,"0.1");
63 SYNFIG_LAYER_SET_CVS_ID(Region,"$Id$");
65 /* === P R O C E D U R E S ================================================= */
67 /* === M E T H O D S ======================================================= */
69 /* === E N T R Y P O I N T ================================================= */
74 vector<BLinePoint> bline_point_list;
75 bline_point_list.push_back(BLinePoint());
76 bline_point_list.push_back(BLinePoint());
77 bline_point_list.push_back(BLinePoint());
78 bline_point_list[0].set_vertex(Point(0,1));
79 bline_point_list[1].set_vertex(Point(0,-1));
80 bline_point_list[2].set_vertex(Point(1,0));
81 bline_point_list[0].set_tangent(bline_point_list[1].get_vertex()-bline_point_list[2].get_vertex()*0.5f);
82 bline_point_list[1].set_tangent(bline_point_list[2].get_vertex()-bline_point_list[0].get_vertex()*0.5f);
83 bline_point_list[2].set_tangent(bline_point_list[0].get_vertex()-bline_point_list[1].get_vertex()*0.5f);
84 bline_point_list[0].set_width(1.0f);
85 bline_point_list[1].set_width(1.0f);
86 bline_point_list[2].set_width(1.0f);
87 bline=bline_point_list;
93 if(bline.get_contained_type()==ValueBase::TYPE_BLINEPOINT)
95 segment_list=convert_bline_to_segment_list(bline);
99 synfig::warning("Region: incorrect type on bline, layer disabled");
104 if(segment_list.empty())
106 synfig::warning("Region: segment_list is empty, layer disabled");
111 bool looped = bline.get_loop();
113 Vector::value_type n;
114 etl::hermite<Vector> curve;
115 vector<Point> vector_list;
117 vector<Segment>::const_iterator iter=segment_list.begin();
118 //Vector last = iter->p1;
120 //make sure the shape has a clean slate for writing
123 //and start off at the first point
124 //move_to(last[0],last[1]);
126 for(;iter!=segment_list.end();++iter)
128 //connect them with a line if they aren't already joined
129 /*if(iter->p1 != last)
131 line_to(iter->p1[0],iter->p1[1]);
134 //curve to the next end point
135 curve_to(iter->p1[0] + iter->t1[0]/3.0,iter->p1[1] + iter->t1[1]/3.0,
136 iter->p2[0] - iter->t2[0]/3.0,iter->p2[1] - iter->t2[1]/3.0,
137 iter->p2[0],iter->p2[1]);
141 if(iter->t1.is_equal_to(Vector(0,0)) && iter->t2.is_equal_to(Vector(0,0)))
143 vector_list.push_back(iter->p2);
153 for(n=0.0;n<1.0;n+=1.0/SAMPLES)
154 vector_list.push_back(curve(n));
158 //add a single point onto the end so it actually fits the shape, so we can be awesome...
161 vector_list.push_back(curve.p2());
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);