1 /* === S I N F G =========================================================== */
2 /*! \file spiralgradient.cpp
3 ** \brief Template Header
5 ** $Id: twirl.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
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.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include <sinfg/string.h>
32 #include <sinfg/time.h>
33 #include <sinfg/context.h>
34 #include <sinfg/paramdesc.h>
35 #include <sinfg/renddesc.h>
36 #include <sinfg/surface.h>
37 #include <sinfg/value.h>
38 #include <sinfg/valuenode.h>
39 #include <sinfg/transform.h>
44 /* === U S I N G =========================================================== */
48 using namespace sinfg;
50 /* === G L O B A L S ======================================================= */
52 SINFG_LAYER_INIT(Twirl);
53 SINFG_LAYER_SET_NAME(Twirl,"twirl");
54 SINFG_LAYER_SET_LOCAL_NAME(Twirl,_("Twirl"));
55 SINFG_LAYER_SET_CATEGORY(Twirl,_("Distortions"));
56 SINFG_LAYER_SET_VERSION(Twirl,"0.1");
57 SINFG_LAYER_SET_CVS_ID(Twirl,"$Id: twirl.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
59 /* === P R O C E D U R E S ================================================= */
61 /* === M E T H O D S ======================================================= */
63 /* === E N T R Y P O I N T ================================================= */
66 Layer_Composite(1.0,Color::BLEND_STRAIGHT),
69 rotations(Angle::zero()),
71 distort_outside(false)
76 Twirl::set_param(const String & param, const ValueBase &value)
81 IMPORT(distort_inside);
82 IMPORT(distort_outside);
84 return Layer_Composite::set_param(param,value);
88 Twirl::get_param(const String ¶m)const
93 EXPORT(distort_inside);
94 EXPORT(distort_outside);
103 Twirl::get_param_vocab()const
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"))
115 .set_origin("center")
118 ret.push_back(ParamDesc("rotations")
119 .set_local_name(_("Rotations"))
120 .set_origin("center")
123 ret.push_back(ParamDesc("distort_inside")
124 .set_local_name(_("Distort Inside"))
127 ret.push_back(ParamDesc("distort_outside")
128 .set_local_name(_("Distort Outside"))
135 Twirl::distort(const sinfg::Point &pos,bool reverse)const
137 Point centered(pos-center);
138 Real mag(centered.mag());
142 if((distort_inside || mag>radius) && (distort_outside || mag<radius))
143 a=rotations*((centered.mag()-radius)/radius);
149 const Real sin(Angle::sin(a).get());
150 const Real cos(Angle::cos(a).get());
153 twirled[0]=cos*centered[0]-sin*centered[1];
154 twirled[1]=sin*centered[0]+cos*centered[1];
156 return twirled+center;
160 Twirl::hit_check(sinfg::Context context, const sinfg::Point &pos)const
162 return context.hit_check(distort(pos));
166 Twirl::get_color(Context context, const Point &pos)const
168 return context.get_color(distort(pos));
171 class Twirl_Trans : public Transform
173 etl::handle<const Twirl> layer;
175 Twirl_Trans(const Twirl* x):Transform(x->get_guid()),layer(x) { }
177 sinfg::Vector perform(const sinfg::Vector& x)const
179 return layer->distort(x,true);
182 sinfg::Vector unperform(const sinfg::Vector& x)const
184 return layer->distort(x,false);
187 etl::handle<Transform>
188 Twirl::get_transform()const
190 return new Twirl_Trans(this);
195 Twirl::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
197 SuperCallback supercb(cb,0,9500,10000);
199 if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
201 surface->set_wh(renddesc.get_w(),renddesc.get_h());
205 if(!context.accelerated_render(surface,quality,renddesc,&supercb))
214 Surface::pen pen(surface->begin());
215 const Real pw(renddesc.get_pw()),ph(renddesc.get_ph());
217 Point tl(renddesc.get_tl());
218 const int w(surface->get_w());
219 const int h(surface->get_h());
221 if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
223 for(y=0,pos[1]=tl[1];y<h;y++,pen.inc_y(),pen.dec_x(x),pos[1]+=ph)
224 for(x=0,pos[0]=tl[0];x<w;x++,pen.inc_x(),pos[0]+=pw)
225 pen.put_value(color_func(pos));
229 for(y=0,pos[1]=tl[1];y<h;y++,pen.inc_y(),pen.dec_x(x),pos[1]+=ph)
230 for(x=0,pos[0]=tl[0];x<w;x++,pen.inc_x(),pos[0]+=pw)
231 pen.put_value(Color::blend(color_func(pos),pen.get_value(),get_amount(),get_blend_method()));
234 // Mark our progress as finished
235 if(cb && !cb->amount_complete(10000,10000))