Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / stable / src / synfig / layer_polygon.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file layer_polygon.cpp
3 **      \brief Implementation of the "Polygon" layer
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007 Chris Moore
10 **
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.
15 **
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.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "layer_polygon.h"
34 #include "string.h"
35 #include "time.h"
36 #include "context.h"
37 #include "paramdesc.h"
38 #include "renddesc.h"
39 #include "surface.h"
40 #include "value.h"
41 #include "valuenode.h"
42 //#include "ETL/bezier"
43 #include <vector>
44
45 #include <deque>
46 using std::deque;
47
48 #endif
49
50 /* === U S I N G =========================================================== */
51
52 using namespace synfig;
53 using namespace std;
54 using namespace etl;
55
56 /* === G L O B A L S ======================================================= */
57
58 SYNFIG_LAYER_INIT(Layer_Polygon);
59 SYNFIG_LAYER_SET_NAME(Layer_Polygon,"polygon");
60 SYNFIG_LAYER_SET_LOCAL_NAME(Layer_Polygon,N_("Polygon"));
61 SYNFIG_LAYER_SET_CATEGORY(Layer_Polygon,N_("Geometry"));
62 SYNFIG_LAYER_SET_VERSION(Layer_Polygon,"0.1");
63 SYNFIG_LAYER_SET_CVS_ID(Layer_Polygon,"$Id$");
64
65 /* === C L A S S E S ======================================================= */
66
67 /* === M E T H O D S ======================================================= */
68
69 Layer_Polygon::Layer_Polygon():
70         Layer_Shape             (1.0,Color::BLEND_COMPOSITE),
71         vector_list             (0)
72 {
73         vector_list.push_back(Point(0,0.5));
74         vector_list.push_back(Point(-0.333333,0));
75         vector_list.push_back(Point(0.333333,0));
76         sync();
77 }
78
79 Layer_Polygon::~Layer_Polygon()
80 {
81 }
82
83 void
84 Layer_Polygon::sync()
85 {
86 /*
87         int i,pointcount=vector_list.size();
88
89         if(pointcount<3)
90                 return;
91
92         //Layer_Shape::clear();
93         //clear();
94
95         // Build edge table
96         move_to(vector_list[0][0],vector_list[0][1]);
97
98         for(i = 1;i < pointcount; i++)
99         {
100                 if(isnan(vector_list[i][0]) || isnan(vector_list[i][1]))
101                         break;
102                 line_to(vector_list[i][0],vector_list[i][1]);
103         }
104         close();
105         //endpath();
106 */
107 }
108
109 void
110 Layer_Polygon::add_polygon(const std::vector<Point> &point_list)
111 {
112         int i,pointcount=point_list.size();
113
114         if(pointcount<3)
115                 return;
116
117         //Layer_Shape::clear();
118         //clear();
119
120         // Build edge table
121         move_to(point_list[0][0],point_list[0][1]);
122
123         for(i = 1;i < pointcount; i++)
124         {
125                 if(isnan(point_list[i][0]) || isnan(point_list[i][1]))
126                         break;
127                 line_to(point_list[i][0],point_list[i][1]);
128         }
129         close();
130         //endpath();
131 }
132
133 void
134 Layer_Polygon::clear()
135 {
136         Layer_Shape::clear();
137         vector_list.clear();
138 }
139
140 bool
141 Layer_Polygon::set_param(const String & param, const ValueBase &value)
142 {
143         if(     param=="vector_list" && value.same_type_as(vector_list))
144         {
145                 vector_list=value;
146                 Layer_Shape::clear();
147                 add_polygon(value);
148                 sync();
149                 return true;
150         }
151
152         return Layer_Shape::set_param(param,value);
153 }
154
155 ValueBase
156 Layer_Polygon::get_param(const String &param)const
157 {
158         EXPORT(vector_list);
159
160         EXPORT_NAME();
161         EXPORT_VERSION();
162
163         return Layer_Shape::get_param(param);
164 }
165
166 Layer::Vocab
167 Layer_Polygon::get_param_vocab()const
168 {
169         Layer::Vocab ret(Layer_Shape::get_param_vocab());
170
171         ret.push_back(ParamDesc("vector_list")
172                 .set_local_name(_("Vector List"))
173                 .set_origin("origin")
174         );
175
176         return ret;
177 }