1 /* === S Y N F I G ========================================================= */
3 ** \brief Implementation of the "Star" layer
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 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 ** === N O T E S ===========================================================
24 ** ========================================================================= */
26 /* === H E A D E R S ======================================================= */
36 #include <ETL/stringf>
38 #include <ETL/hermite>
40 #include <synfig/string.h>
41 #include <synfig/time.h>
42 #include <synfig/context.h>
43 #include <synfig/paramdesc.h>
44 #include <synfig/renddesc.h>
45 #include <synfig/surface.h>
46 #include <synfig/value.h>
47 #include <synfig/valuenode.h>
48 #include <synfig/segment.h>
54 /* === M A C R O S ========================================================= */
58 /* === G L O B A L S ======================================================= */
60 SYNFIG_LAYER_INIT(Star);
61 SYNFIG_LAYER_SET_NAME(Star,"star");
62 SYNFIG_LAYER_SET_LOCAL_NAME(Star,N_("Star"));
63 SYNFIG_LAYER_SET_CATEGORY(Star,N_("Geometry"));
64 SYNFIG_LAYER_SET_VERSION(Star,"0.1");
65 SYNFIG_LAYER_SET_CVS_ID(Star,"$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 ================================================= */
77 angle(Angle::deg(90)),
78 regular_polygon(false)
86 Angle dist_between_points(Angle::rot(1)/float(points));
87 std::vector<Point> vector_list;
92 Angle dist1(dist_between_points*i+angle);
93 Angle dist2(dist_between_points*i+dist_between_points/2+angle);
94 vector_list.push_back(Point(Angle::cos(dist1).get()*radius1,Angle::sin(dist1).get()*radius1));
96 vector_list.push_back(Point(Angle::cos(dist2).get()*radius2,Angle::sin(dist2).get()*radius2));
99 add_polygon(vector_list);
103 Star::set_param(const String & param, const ValueBase &value)
105 if( param=="radius1" && value.same_type_as(radius1))
112 if( param=="radius2" && value.same_type_as(radius2))
119 if( param=="points" && value.same_type_as(points))
122 if(points<2)points=2;
127 if( param=="angle" && value.same_type_as(angle))
134 if(param=="regular_polygon" && value.same_type_as(regular_polygon))
136 value.put(®ular_polygon);
141 if(param=="vector_list")
144 return Layer_Polygon::set_param(param,value);
148 Star::get_param(const String& param)const
154 EXPORT(regular_polygon);
159 if(param=="vector_list")
162 return Layer_Polygon::get_param(param);
166 Star::get_param_vocab()const
168 Layer::Vocab ret(Layer_Polygon::get_param_vocab());
170 // Pop off the polygon parameter from the polygon vocab
173 ret.push_back(ParamDesc("radius1")
174 .set_local_name(_("Outer Radius"))
175 .set_description(_("The radius of the outer points in the star"))
177 .set_origin("offset")
180 ret.push_back(ParamDesc("radius2")
181 .set_local_name(_("Inner Radius"))
182 .set_description(_("The radius of the inner points in the star"))
184 .set_origin("offset")
187 ret.push_back(ParamDesc("angle")
188 .set_local_name(_("Angle"))
189 .set_description(_("The orientation of the star"))
190 .set_origin("offset")
193 ret.push_back(ParamDesc("points")
194 .set_local_name(_("Points"))
195 .set_description(_("The number of points in the star"))
198 ret.push_back(ParamDesc("regular_polygon")
199 .set_local_name(_("Regular Polygon"))
200 .set_description(_("Whether to draw a star or a regular polygon"))