Enable $Id$ expansion.
[synfig.git] / synfig-core / trunk / src / modules / mod_geometry / star.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file star.cpp
3 **      \brief Template Header
4 **
5 **      \legal
6 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
7 **
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.
12 **
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.
17 **      \endlegal
18 **
19 ** === N O T E S ===========================================================
20 **
21 ** ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "star.h"
33 #include <ETL/stringf>
34 #include <ETL/bezier>
35 #include <ETL/hermite>
36
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
47 #endif
48
49 using namespace etl;
50
51 /* === M A C R O S ========================================================= */
52
53 #define SAMPLES         75
54
55 /* === G L O B A L S ======================================================= */
56
57 SYNFIG_LAYER_INIT(Star);
58 SYNFIG_LAYER_SET_NAME(Star,"star");
59 SYNFIG_LAYER_SET_LOCAL_NAME(Star,_("Star"));
60 SYNFIG_LAYER_SET_CATEGORY(Star,_("Geometry"));
61 SYNFIG_LAYER_SET_VERSION(Star,"0.1");
62 SYNFIG_LAYER_SET_CVS_ID(Star,"$Id$");
63
64 /* === P R O C E D U R E S ================================================= */
65
66 /* === M E T H O D S ======================================================= */
67
68 /* === E N T R Y P O I N T ================================================= */
69
70 Star::Star():
71         radius1(1.0),
72         radius2(0.38),
73         points(5),
74         angle(Angle::deg(90))
75 {
76         sync();
77 }
78
79 void
80 Star::sync()
81 {
82         Angle dist_between_points(Angle::rot(1)/float(points));
83         std::vector<Point> vector_list;
84
85         int i;
86         for(i=0;i<points;i++)
87         {
88                 Angle dist1(dist_between_points*i+angle);
89                 Angle dist2(dist_between_points*i+dist_between_points/2+angle);
90                 vector_list.push_back(Point(Angle::cos(dist1).get()*radius1,Angle::sin(dist1).get()*radius1));
91                 vector_list.push_back(Point(Angle::cos(dist2).get()*radius2,Angle::sin(dist2).get()*radius2));
92         }
93         clear();
94         add_polygon(vector_list);
95 }
96
97 bool
98 Star::set_param(const String & param, const ValueBase &value)
99 {
100         if(     param=="radius1" && value.same_as(radius1))
101         {
102                 value.put(&radius1);
103                 sync();
104                 return true;
105         }
106
107         if(     param=="radius2" && value.same_as(radius2))
108         {
109                 value.put(&radius2);
110                 sync();
111                 return true;
112         }
113
114         if(     param=="points" && value.same_as(points))
115         {
116                 value.put(&points);
117                 if(points<2)points=2;
118                 sync();
119                 return true;
120         }
121
122         if(     param=="angle" && value.same_as(angle))
123         {
124                 value.put(&angle);
125                 sync();
126                 return true;
127         }
128
129         if(param=="vector_list")
130                 return false;
131
132         return Layer_Polygon::set_param(param,value);
133 }
134
135 ValueBase
136 Star::get_param(const String& param)const
137 {
138         EXPORT(radius1);
139         EXPORT(radius2);
140         EXPORT(points);
141         EXPORT(angle);
142
143         EXPORT_NAME();
144         EXPORT_VERSION();
145
146         if(param=="vector_list")
147                 return ValueBase();
148
149         return Layer_Polygon::get_param(param);
150 }
151
152 Layer::Vocab
153 Star::get_param_vocab()const
154 {
155         Layer::Vocab ret(Layer_Polygon::get_param_vocab());
156
157         // Pop off the polygon parameter from the polygon vocab
158         ret.pop_back();
159
160         ret.push_back(ParamDesc("radius1")
161                 .set_local_name(_("Outer Radius"))
162                 .set_description(_("The radius of the outer points in the star"))
163                 .set_is_distance()
164                 .set_origin("offset")
165         );
166
167         ret.push_back(ParamDesc("radius2")
168                 .set_local_name(_("Inner Radius"))
169                 .set_description(_("The radius of the inner points in the star"))
170                 .set_is_distance()
171                 .set_origin("offset")
172         );
173
174         ret.push_back(ParamDesc("angle")
175                 .set_local_name(_("Angle"))
176                 .set_description(_("The orientation of the star"))
177                 .set_origin("offset")
178         );
179
180         ret.push_back(ParamDesc("points")
181                 .set_local_name(_("Points"))
182                 .set_description(_("The number of points in the star"))
183         );
184
185         return ret;
186 }