1 /*! ========================================================================
4 ** $Id: region.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $
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.
18 ** === N O T E S ===========================================================
20 ** ========================================================================= */
22 /* === H E A D E R S ======================================================= */
32 #include <ETL/stringf>
34 #include <ETL/hermite>
36 #include <synfig/string.h>
37 #include <synfig/time.h>
38 #include <synfig/context.h>
39 #include <synfig/paramdesc.h>
40 #include <synfig/renddesc.h>
41 #include <synfig/surface.h>
42 #include <synfig/value.h>
43 #include <synfig/valuenode.h>
44 #include <synfig/segment.h>
45 #include <synfig/valuenode_bline.h>
51 /* === M A C R O S ========================================================= */
55 /* === G L O B A L S ======================================================= */
57 SYNFIG_LAYER_INIT(Region);
58 SYNFIG_LAYER_SET_NAME(Region,"region");
59 SYNFIG_LAYER_SET_LOCAL_NAME(Region,_("Region"));
60 SYNFIG_LAYER_SET_CATEGORY(Region,_("Geometry"));
61 SYNFIG_LAYER_SET_VERSION(Region,"0.1");
62 SYNFIG_LAYER_SET_CVS_ID(Region,"$Id: region.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
64 /* === P R O C E D U R E S ================================================= */
66 /* === M E T H O D S ======================================================= */
68 /* === E N T R Y P O I N T ================================================= */
73 vector<BLinePoint> bline_point_list;
74 bline_point_list.push_back(BLinePoint());
75 bline_point_list.push_back(BLinePoint());
76 bline_point_list.push_back(BLinePoint());
77 bline_point_list[0].set_vertex(Point(0,1));
78 bline_point_list[1].set_vertex(Point(0,-1));
79 bline_point_list[2].set_vertex(Point(1,0));
80 bline_point_list[0].set_tangent(bline_point_list[1].get_vertex()-bline_point_list[2].get_vertex()*0.5f);
81 bline_point_list[1].set_tangent(bline_point_list[2].get_vertex()-bline_point_list[0].get_vertex()*0.5f);
82 bline_point_list[2].set_tangent(bline_point_list[0].get_vertex()-bline_point_list[1].get_vertex()*0.5f);
83 bline_point_list[0].set_width(1.0f);
84 bline_point_list[1].set_width(1.0f);
85 bline_point_list[2].set_width(1.0f);
86 bline=bline_point_list;
92 if(bline.get_contained_type()==ValueBase::TYPE_BLINEPOINT)
94 segment_list=convert_bline_to_segment_list(bline);
98 synfig::warning("Region: incorrect type on bline, layer disabled");
103 if(segment_list.empty())
105 synfig::warning("Region: segment_list is empty, layer disabled");
110 bool looped = bline.get_loop();
112 Vector::value_type n;
113 etl::hermite<Vector> curve;
114 vector<Point> vector_list;
116 vector<Segment>::const_iterator iter=segment_list.begin();
117 //Vector last = iter->p1;
119 //make sure the shape has a clean slate for writing
122 //and start off at the first point
123 //move_to(last[0],last[1]);
125 for(;iter!=segment_list.end();++iter)
127 //connect them with a line if they aren't already joined
128 /*if(iter->p1 != last)
130 line_to(iter->p1[0],iter->p1[1]);
133 //curve to the next end point
134 curve_to(iter->p1[0] + iter->t1[0]/3.0,iter->p1[1] + iter->t1[1]/3.0,
135 iter->p2[0] - iter->t2[0]/3.0,iter->p2[1] - iter->t2[1]/3.0,
136 iter->p2[0],iter->p2[1]);
140 if(iter->t1.is_equal_to(Vector(0,0)) && iter->t2.is_equal_to(Vector(0,0)))
142 vector_list.push_back(iter->p2);
152 for(n=0.0;n<1.0;n+=1.0/SAMPLES)
153 vector_list.push_back(curve(n));
157 //add a single point onto the end so it actually fits the shape, so we can be awesome...
160 vector_list.push_back(curve.p2());
164 add_polygon(vector_list);
171 Region::set_param(const String & param, const ValueBase &value)
173 if(param=="segment_list")
175 if(dynamic_param_list().count("segment_list"))
177 connect_dynamic_param("bline",dynamic_param_list().find("segment_list")->second);
178 disconnect_dynamic_param("segment_list");
179 synfig::warning("Region::set_param(): Updated valuenode connection to use the new \"bline\" parameter.");
182 synfig::warning("Region::set_param(): The parameter \"segment_list\" is deprecated. Use \"bline\" instead.");
185 if( (param=="segment_list" || param=="bline") && value.get_type()==ValueBase::TYPE_LIST)
187 //if(value.get_contained_type()!=ValueBase::TYPE_BLINEPOINT)
195 /* if( param=="segment_list" && value.get_type()==ValueBase::TYPE_LIST)
197 if(value.get_contained_type()==ValueBase::TYPE_BLINEPOINT)
198 segment_list=convert_bline_to_segment_list(value);
200 if(value.get_contained_type()==ValueBase::TYPE_SEGMENT)
204 segment_list.clear();
211 return Layer_Shape::set_param(param,value);
215 Region::get_param(const String& param)const
221 return Layer_Shape::get_param(param);
225 Region::get_param_vocab()const
227 Layer::Vocab ret(Layer_Shape::get_param_vocab());
229 ret.push_back(ParamDesc("bline")
230 .set_local_name(_("Vertices"))
231 .set_origin("offset")
238 Region::set_time(Context context, Time time)const
240 const_cast<Region*>(this)->sync();
241 context.set_time(time);
245 Region::set_time(Context context, Time time, Vector pos)const
247 const_cast<Region*>(this)->sync();
248 context.set_time(time,pos);