More descriptions for layer parameters
[synfig.git] / synfig-core / 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         Layer::Vocab voc(get_param_vocab());
78         Layer::fill_static(voc);
79 }
80
81 Layer_Polygon::~Layer_Polygon()
82 {
83 }
84
85 void
86 Layer_Polygon::sync()
87 {
88 /*
89         int i,pointcount=vector_list.size();
90
91         if(pointcount<3)
92                 return;
93
94         //Layer_Shape::clear();
95         //clear();
96
97         // Build edge table
98         move_to(vector_list[0][0],vector_list[0][1]);
99
100         for(i = 1;i < pointcount; i++)
101         {
102                 if(isnan(vector_list[i][0]) || isnan(vector_list[i][1]))
103                         break;
104                 line_to(vector_list[i][0],vector_list[i][1]);
105         }
106         close();
107         //endpath();
108 */
109 }
110
111 void
112 Layer_Polygon::add_polygon(const std::vector<Point> &point_list)
113 {
114         int i,pointcount=point_list.size();
115
116         if(pointcount<3)
117                 return;
118
119         //Layer_Shape::clear();
120         //clear();
121
122         // Build edge table
123         move_to(point_list[0][0],point_list[0][1]);
124
125         for(i = 1;i < pointcount; i++)
126         {
127                 if(isnan(point_list[i][0]) || isnan(point_list[i][1]))
128                         break;
129                 line_to(point_list[i][0],point_list[i][1]);
130         }
131         close();
132         //endpath();
133 }
134
135 void
136 Layer_Polygon::clear()
137 {
138         Layer_Shape::clear();
139         vector_list.clear();
140 }
141
142 bool
143 Layer_Polygon::set_param(const String & param, const ValueBase &value)
144 {
145         if(     param=="vector_list" && value.same_type_as(vector_list))
146         {
147                 vector_list=value;
148                 Layer_Shape::clear();
149                 add_polygon(value);
150                 sync();
151                 return true;
152         }
153
154         return Layer_Shape::set_param(param,value);
155 }
156
157 ValueBase
158 Layer_Polygon::get_param(const String &param)const
159 {
160         EXPORT(vector_list);
161
162         EXPORT_NAME();
163         EXPORT_VERSION();
164
165         return Layer_Shape::get_param(param);
166 }
167
168 Layer::Vocab
169 Layer_Polygon::get_param_vocab()const
170 {
171         Layer::Vocab ret(Layer_Shape::get_param_vocab());
172
173         ret.push_back(ParamDesc("vector_list")
174                 .set_local_name(_("Vector List"))
175                 .set_description(_("Define the corners of the polygon"))
176                 .set_origin("origin")
177         );
178
179         return ret;
180 }