Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_07_rc1 / src / modules / example / simplecircle.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file simplecircle.cpp
3 **      \brief Template Header
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include <synfig/string.h>
33 #include <synfig/time.h>
34 #include <synfig/context.h>
35 #include <synfig/paramdesc.h>
36 #include <synfig/renddesc.h>
37 #include <synfig/surface.h>
38 #include <synfig/value.h>
39 #include <synfig/valuenode.h>
40
41 #include "simplecircle.h"
42
43 #endif
44
45 /* === U S I N G =========================================================== */
46
47 using namespace etl;
48 using namespace std;
49 using namespace synfig;
50
51 /* === G L O B A L S ======================================================= */
52
53 SYNFIG_LAYER_INIT(SimpleCircle);
54 SYNFIG_LAYER_SET_NAME(SimpleCircle,"simple_circle");
55 SYNFIG_LAYER_SET_LOCAL_NAME(SimpleCircle,_("Simple Circle"));
56 SYNFIG_LAYER_SET_CATEGORY(SimpleCircle,_("Do Not Use"));
57 SYNFIG_LAYER_SET_VERSION(SimpleCircle,"0.1");
58 SYNFIG_LAYER_SET_CVS_ID(SimpleCircle,"$Id$");
59
60 /* === P R O C E D U R E S ================================================= */
61
62 /* === M E T H O D S ======================================================= */
63
64 /* === E N T R Y P O I N T ================================================= */
65
66 SimpleCircle::SimpleCircle():
67         Layer_Composite(1.0,Color::BLEND_STRAIGHT),
68         color(Color::black()),
69         center(0,0),
70         radius(0.5)
71 {
72 }
73
74 bool
75 SimpleCircle::set_param(const String & param, const ValueBase &value)
76 {
77         IMPORT(color);
78         IMPORT(center);
79         IMPORT(radius);
80
81         return Layer_Composite::set_param(param,value);
82 }
83
84 ValueBase
85 SimpleCircle::get_param(const String &param)const
86 {
87         EXPORT(color);
88         EXPORT(center);
89         EXPORT(radius);
90
91         EXPORT_NAME();
92         EXPORT_VERSION();
93
94         return Layer_Composite::get_param(param);
95 }
96
97 Layer::Vocab
98 SimpleCircle::get_param_vocab()const
99 {
100         Layer::Vocab ret(Layer_Composite::get_param_vocab());
101
102         ret.push_back(ParamDesc("color")
103                 .set_local_name(_("Color"))
104         );
105
106         ret.push_back(ParamDesc("center")
107                 .set_local_name(_("Center"))
108         );
109
110         ret.push_back(ParamDesc("radius")
111                 .set_local_name(_("Radius"))
112                 .set_description(_("This is the radius of the circle"))
113                 .set_origin("center")
114         );
115
116         return ret;
117 }
118
119 Color
120 SimpleCircle::get_color(Context context, const Point &pos)const
121 {
122
123         if((pos-center).mag()<radius)
124         {
125                 if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
126                         return color;
127                 else
128                         return Color::blend(color,context.get_color(pos),get_amount(),get_blend_method());
129         }
130         else
131                 return context.get_color(pos);
132 }
133
134 synfig::Layer::Handle
135 SimpleCircle::hit_check(synfig::Context context, const synfig::Point &pos)const
136 {
137         if((pos-center).mag()<radius)
138                 return const_cast<SimpleCircle*>(this);
139         else
140                 return context.hit_check(pos);
141 }
142
143 /*
144 bool
145 SimpleCircle::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
146 {
147         if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
148         {
149                 // Mark our progress as starting
150                 if(cb && !cb->amount_complete(0,1000))
151                         return false;
152
153                 surface->set_wh(renddesc.get_w(),renddesc.get_h());
154                 surface->fill(color);
155
156                 // Mark our progress as finished
157                 if(cb && !cb->amount_complete(1000,1000))
158                         return false;
159
160                 return true;
161         }
162
163         SuperCallback supercb(cb,0,9500,10000);
164
165         if(!context.accelerated_render(surface,quality,renddesc,&supercb))
166                 return false;
167
168         int x,y;
169
170         Surface::alpha_pen apen(surface->begin());
171
172         apen.set_value(color);
173         apen.set_alpha(get_amount());
174         apen.set_blend_method(get_blend_method());
175
176         for(y=0;y<renddesc.get_h();y++,apen.inc_y(),apen.dec_x(x))
177                 for(x=0;x<renddesc.get_w();x++,apen.inc_x())
178                         apen.put_value();
179
180         // Mark our progress as finished
181         if(cb && !cb->amount_complete(10000,10000))
182                 return false;
183
184         return true;
185 }
186 */