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