Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_07 / src / synfig / layer_polygon.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file layer_polygon.cpp
3 **      \brief Template Header
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
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 "layer_polygon.h"
33 #include "string.h"
34 #include "time.h"
35 #include "context.h"
36 #include "paramdesc.h"
37 #include "renddesc.h"
38 #include "surface.h"
39 #include "value.h"
40 #include "valuenode.h"
41 //#include "ETL/bezier"
42 #include <vector>
43
44 #include <deque>
45 using std::deque;
46
47 #endif
48
49 /* === U S I N G =========================================================== */
50
51 using namespace synfig;
52 using namespace std;
53 using namespace etl;
54
55 /* === G L O B A L S ======================================================= */
56
57 SYNFIG_LAYER_INIT(Layer_Polygon);
58 SYNFIG_LAYER_SET_NAME(Layer_Polygon,"polygon");
59 SYNFIG_LAYER_SET_LOCAL_NAME(Layer_Polygon,_("Polygon"));
60 SYNFIG_LAYER_SET_CATEGORY(Layer_Polygon,_("Geometry"));
61 SYNFIG_LAYER_SET_VERSION(Layer_Polygon,"0.1");
62 SYNFIG_LAYER_SET_CVS_ID(Layer_Polygon,"$Id$");
63
64 /* === C L A S S E S ======================================================= */
65
66 /* === M E T H O D S ======================================================= */
67
68 Layer_Polygon::Layer_Polygon():
69         Layer_Shape             (1.0,Color::BLEND_COMPOSITE),
70         vector_list             (0)
71 {
72         vector_list.push_back(Point(0,0.5));
73         vector_list.push_back(Point(-0.333333,0));
74         vector_list.push_back(Point(0.333333,0));
75         sync();
76 }
77
78 Layer_Polygon::~Layer_Polygon()
79 {
80 }
81
82 void
83 Layer_Polygon::sync()
84 {
85 /*
86         int i,pointcount=vector_list.size();
87
88         if(pointcount<3)
89                 return;
90
91         //Layer_Shape::clear();
92         //clear();
93
94         // Build edge table
95         move_to(vector_list[0][0],vector_list[0][1]);
96
97         for(i = 1;i < pointcount; i++)
98         {
99                 if(isnan(vector_list[i][0]) || isnan(vector_list[i][1]))
100                         break;
101                 line_to(vector_list[i][0],vector_list[i][1]);
102         }
103         close();
104         //endpath();
105 */
106 }
107
108 void
109 Layer_Polygon::add_polygon(const vector<Point> &point_list)
110 {
111         int i,pointcount=point_list.size();
112
113         if(pointcount<3)
114                 return;
115
116         //Layer_Shape::clear();
117         //clear();
118
119         // Build edge table
120         move_to(point_list[0][0],point_list[0][1]);
121
122         for(i = 1;i < pointcount; i++)
123         {
124                 if(isnan(point_list[i][0]) || isnan(point_list[i][1]))
125                         break;
126                 line_to(point_list[i][0],point_list[i][1]);
127         }
128         close();
129         //endpath();
130 }
131
132 void
133 Layer_Polygon::clear()
134 {
135         Layer_Shape::clear();
136         vector_list.clear();
137 }
138
139 bool
140 Layer_Polygon::set_param(const String & param, const ValueBase &value)
141 {
142         if(     param=="vector_list" && value.same_type_as(vector_list))
143         {
144                 vector_list=value;
145                 Layer_Shape::clear();
146                 add_polygon(value);
147                 sync();
148                 return true;
149         }
150
151         return Layer_Shape::set_param(param,value);
152 }
153
154 ValueBase
155 Layer_Polygon::get_param(const String &param)const
156 {
157         EXPORT(vector_list);
158
159         EXPORT_NAME();
160         EXPORT_VERSION();
161
162         return Layer_Shape::get_param(param);
163 }
164
165 Layer::Vocab
166 Layer_Polygon::get_param_vocab()const
167 {
168         Layer::Vocab ret(Layer_Shape::get_param_vocab());
169
170         ret.push_back(ParamDesc("vector_list")
171                 .set_local_name(_("Vector List"))
172                 .set_origin("offset")
173         );
174
175         return ret;
176 }