More descriptions for layer parameters
[synfig.git] / synfig-core / src / modules / mod_example / simplecircle.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file simplecircle.cpp
3 **      \brief Implementation of the "Simple Circle" layer
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2008 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 <synfig/string.h>
34 #include <synfig/time.h>
35 #include <synfig/context.h>
36 #include <synfig/paramdesc.h>
37 #include <synfig/renddesc.h>
38 #include <synfig/surface.h>
39 #include <synfig/value.h>
40 #include <synfig/valuenode.h>
41
42 #include "simplecircle.h"
43
44 #endif
45
46 /* === U S I N G =========================================================== */
47
48 using namespace etl;
49 using namespace std;
50 using namespace synfig;
51
52 /* === G L O B A L S ======================================================= */
53
54 SYNFIG_LAYER_INIT(SimpleCircle);
55 SYNFIG_LAYER_SET_NAME(SimpleCircle,"simple_circle");
56 SYNFIG_LAYER_SET_LOCAL_NAME(SimpleCircle,N_("Simple Circle"));
57 SYNFIG_LAYER_SET_CATEGORY(SimpleCircle,N_("Example"));
58 SYNFIG_LAYER_SET_VERSION(SimpleCircle,"0.1");
59 SYNFIG_LAYER_SET_CVS_ID(SimpleCircle,"$Id$");
60
61 /* === P R O C E D U R E S ================================================= */
62
63 /* === M E T H O D S ======================================================= */
64
65 /* === E N T R Y P O I N T ================================================= */
66
67 SimpleCircle::SimpleCircle():
68         Layer_Composite(1.0,Color::BLEND_COMPOSITE),
69         color(Color::black()),
70         center(0,0),
71         radius(0.5)
72 {
73         Layer::Vocab voc(get_param_vocab());
74         Layer::fill_static(voc);
75 }
76
77 bool
78 SimpleCircle::set_param(const String & param, const ValueBase &value)
79 {
80         IMPORT(color);
81         IMPORT(center);
82         IMPORT(radius);
83
84         return Layer_Composite::set_param(param,value);
85 }
86
87 ValueBase
88 SimpleCircle::get_param(const String &param)const
89 {
90         EXPORT(color);
91         EXPORT(center);
92         EXPORT(radius);
93
94         EXPORT_NAME();
95         EXPORT_VERSION();
96
97         return Layer_Composite::get_param(param);
98 }
99
100 Layer::Vocab
101 SimpleCircle::get_param_vocab()const
102 {
103         Layer::Vocab ret(Layer_Composite::get_param_vocab());
104
105         ret.push_back(ParamDesc("color")
106                 .set_local_name(_("Color"))
107                 .set_description(_("Fill color of the layer"))
108         );
109
110         ret.push_back(ParamDesc("center")
111                 .set_local_name(_("Center"))
112                 .set_description(_("Center of the circle"))
113         );
114
115         ret.push_back(ParamDesc("radius")
116                 .set_local_name(_("Radius"))
117                 .set_description(_("This is the radius of the circle"))
118                 .set_origin("center")
119         );
120
121         return ret;
122 }
123
124 Color
125 SimpleCircle::get_color(Context context, const Point &pos)const
126 {
127
128         if((pos-center).mag()<radius)
129         {
130                 if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
131                         return color;
132                 else
133                         return Color::blend(color,context.get_color(pos),get_amount(),get_blend_method());
134         }
135         else
136                 return context.get_color(pos);
137 }
138
139 synfig::Layer::Handle
140 SimpleCircle::hit_check(synfig::Context context, const synfig::Point &pos)const
141 {
142         if((pos-center).mag()<radius)
143                 return const_cast<SimpleCircle*>(this);
144         else
145                 return context.hit_check(pos);
146 }
147
148 /*
149 bool
150 SimpleCircle::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
151 {
152         if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
153         {
154                 // Mark our progress as starting
155                 if(cb && !cb->amount_complete(0,1000))
156                         return false;
157
158                 surface->set_wh(renddesc.get_w(),renddesc.get_h());
159                 surface->fill(color);
160
161                 // Mark our progress as finished
162                 if(cb && !cb->amount_complete(1000,1000))
163                         return false;
164
165                 return true;
166         }
167
168         SuperCallback supercb(cb,0,9500,10000);
169
170         if(!context.accelerated_render(surface,quality,renddesc,&supercb))
171                 return false;
172
173         int x,y;
174
175         Surface::alpha_pen apen(surface->begin());
176
177         apen.set_value(color);
178         apen.set_alpha(get_amount());
179         apen.set_blend_method(get_blend_method());
180
181         for(y=0;y<renddesc.get_h();y++,apen.inc_y(),apen.dec_x(x))
182                 for(x=0;x<renddesc.get_w();x++,apen.inc_x())
183                         apen.put_value();
184
185         // Mark our progress as finished
186         if(cb && !cb->amount_complete(10000,10000))
187                 return false;
188
189         return true;
190 }
191 */