more updates
[synfig.git] / synfig-core / trunk / src / synfig / layer_polygon.cpp
1 /* === S I N F G =========================================================== */
2 /*!     \file layer_polygon.cpp
3 **      \brief Template Header
4 **
5 **      $Id: layer_polygon.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
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 "layer_polygon.h"
32 #include "string.h"
33 #include "time.h"
34 #include "context.h"
35 #include "paramdesc.h"
36 #include "renddesc.h"
37 #include "surface.h"
38 #include "value.h"
39 #include "valuenode.h"
40 //#include "ETL/bezier"
41 #include <vector>
42
43 #include <deque>
44 using std::deque;
45
46 #endif
47
48 /* === U S I N G =========================================================== */
49
50 using namespace sinfg;
51 using namespace std;
52 using namespace etl;
53
54 /* === G L O B A L S ======================================================= */
55
56 SINFG_LAYER_INIT(Layer_Polygon);
57 SINFG_LAYER_SET_NAME(Layer_Polygon,"polygon");
58 SINFG_LAYER_SET_LOCAL_NAME(Layer_Polygon,_("Polygon"));
59 SINFG_LAYER_SET_CATEGORY(Layer_Polygon,_("Geometry"));
60 SINFG_LAYER_SET_VERSION(Layer_Polygon,"0.1");
61 SINFG_LAYER_SET_CVS_ID(Layer_Polygon,"$Id: layer_polygon.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $");
62
63 /* === C L A S S E S ======================================================= */
64
65 /* === M E T H O D S ======================================================= */
66
67 Layer_Polygon::Layer_Polygon():
68         Layer_Shape             (1.0,Color::BLEND_COMPOSITE),
69         vector_list             (0)
70 {
71         vector_list.push_back(Point(0,0.5));
72         vector_list.push_back(Point(-0.333333,0));
73         vector_list.push_back(Point(0.333333,0));
74         sync();
75 }
76
77 Layer_Polygon::~Layer_Polygon()
78 {
79 }
80
81 void
82 Layer_Polygon::sync()
83 {
84 /*
85         int i,pointcount=vector_list.size();
86
87         if(pointcount<3)
88                 return;
89
90         //Layer_Shape::clear();
91         //clear();
92
93         // Build edge table
94         move_to(vector_list[0][0],vector_list[0][1]);
95         
96         for(i = 1;i < pointcount; i++)
97         {
98                 if(isnan(vector_list[i][0]) || isnan(vector_list[i][1]))
99                         break;
100                 line_to(vector_list[i][0],vector_list[i][1]);
101         }
102         close();
103         //endpath();
104 */
105 }
106
107 void
108 Layer_Polygon::add_polygon(const vector<Point> &point_list)
109 {
110         int i,pointcount=point_list.size();
111
112         if(pointcount<3)
113                 return;
114
115         //Layer_Shape::clear();
116         //clear();
117
118         // Build edge table
119         move_to(point_list[0][0],point_list[0][1]);
120         
121         for(i = 1;i < pointcount; i++)
122         {
123                 if(isnan(point_list[i][0]) || isnan(point_list[i][1]))
124                         break;
125                 line_to(point_list[i][0],point_list[i][1]);
126         }
127         close();
128         //endpath();
129 }
130
131 void
132 Layer_Polygon::clear()
133 {
134         Layer_Shape::clear();
135         vector_list.clear();
136 }
137         
138 bool
139 Layer_Polygon::set_param(const String & param, const ValueBase &value)
140 {
141         if(     param=="vector_list" && value.same_as(vector_list))
142         {
143                 vector_list=value;
144                 Layer_Shape::clear();
145                 add_polygon(value);
146                 sync();
147                 return true;
148         }
149         
150         return Layer_Shape::set_param(param,value);
151 }
152
153 ValueBase
154 Layer_Polygon::get_param(const String &param)const
155 {
156         EXPORT(vector_list);
157
158         EXPORT_NAME();
159         EXPORT_VERSION();
160                 
161         return Layer_Shape::get_param(param);   
162 }
163
164 Layer::Vocab
165 Layer_Polygon::get_param_vocab()const
166 {
167         Layer::Vocab ret(Layer_Shape::get_param_vocab());
168         
169         ret.push_back(ParamDesc("vector_list")
170                 .set_local_name(_("Vector List"))
171                 .set_origin("offset")
172         );
173         
174         return ret;
175 }