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