Put the three example layers in the 'Example' group in the 'new layer' menu.
[synfig.git] / synfig-core / trunk / src / modules / example / simplecircle.cpp
blobe2eb8969d8bd9e02898078fb6427573136e1224d
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
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.
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
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
26 #ifdef USING_PCH
27 # include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 # include <config.h>
31 #endif
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>
42 #include "simplecircle.h"
44 #endif
46 /* === U S I N G =========================================================== */
48 using namespace etl;
49 using namespace std;
50 using namespace synfig;
52 /* === G L O B A L S ======================================================= */
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$");
61 /* === P R O C E D U R E S ================================================= */
63 /* === M E T H O D S ======================================================= */
65 /* === E N T R Y P O I N T ================================================= */
67 SimpleCircle::SimpleCircle():
68 Layer_Composite(1.0,Color::BLEND_STRAIGHT),
69 color(Color::black()),
70 center(0,0),
71 radius(0.5)
75 bool
76 SimpleCircle::set_param(const String & param, const ValueBase &value)
78 IMPORT(color);
79 IMPORT(center);
80 IMPORT(radius);
82 return Layer_Composite::set_param(param,value);
85 ValueBase
86 SimpleCircle::get_param(const String &param)const
88 EXPORT(color);
89 EXPORT(center);
90 EXPORT(radius);
92 EXPORT_NAME();
93 EXPORT_VERSION();
95 return Layer_Composite::get_param(param);
98 Layer::Vocab
99 SimpleCircle::get_param_vocab()const
101 Layer::Vocab ret(Layer_Composite::get_param_vocab());
103 ret.push_back(ParamDesc("color")
104 .set_local_name(_("Color"))
107 ret.push_back(ParamDesc("center")
108 .set_local_name(_("Center"))
111 ret.push_back(ParamDesc("radius")
112 .set_local_name(_("Radius"))
113 .set_description(_("This is the radius of the circle"))
114 .set_origin("center")
117 return ret;
120 Color
121 SimpleCircle::get_color(Context context, const Point &pos)const
124 if((pos-center).mag()<radius)
126 if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
127 return color;
128 else
129 return Color::blend(color,context.get_color(pos),get_amount(),get_blend_method());
131 else
132 return context.get_color(pos);
135 synfig::Layer::Handle
136 SimpleCircle::hit_check(synfig::Context context, const synfig::Point &pos)const
138 if((pos-center).mag()<radius)
139 return const_cast<SimpleCircle*>(this);
140 else
141 return context.hit_check(pos);
145 bool
146 SimpleCircle::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
148 if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
150 // Mark our progress as starting
151 if(cb && !cb->amount_complete(0,1000))
152 return false;
154 surface->set_wh(renddesc.get_w(),renddesc.get_h());
155 surface->fill(color);
157 // Mark our progress as finished
158 if(cb && !cb->amount_complete(1000,1000))
159 return false;
161 return true;
164 SuperCallback supercb(cb,0,9500,10000);
166 if(!context.accelerated_render(surface,quality,renddesc,&supercb))
167 return false;
169 int x,y;
171 Surface::alpha_pen apen(surface->begin());
173 apen.set_value(color);
174 apen.set_alpha(get_amount());
175 apen.set_blend_method(get_blend_method());
177 for(y=0;y<renddesc.get_h();y++,apen.inc_y(),apen.dec_x(x))
178 for(x=0;x<renddesc.get_w();x++,apen.inc_x())
179 apen.put_value();
181 // Mark our progress as finished
182 if(cb && !cb->amount_complete(10000,10000))
183 return false;
185 return true;