1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 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.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
26 #define SYNFIG_NO_ANGLE
36 #include <synfig/string.h>
37 #include <synfig/time.h>
38 #include <synfig/context.h>
39 #include <synfig/paramdesc.h>
40 #include <synfig/renddesc.h>
41 #include <synfig/surface.h>
42 #include <synfig/value.h>
43 #include <synfig/valuenode.h>
44 #include <synfig/transform.h>
48 /* === U S I N G =========================================================== */
52 using namespace synfig;
54 /* === G L O B A L S ======================================================= */
56 SYNFIG_LAYER_INIT(Layer_Stretch);
57 SYNFIG_LAYER_SET_NAME(Layer_Stretch,"stretch");
58 SYNFIG_LAYER_SET_LOCAL_NAME(Layer_Stretch,_("Stretch"));
59 SYNFIG_LAYER_SET_CATEGORY(Layer_Stretch,_("Distortions"));
60 SYNFIG_LAYER_SET_VERSION(Layer_Stretch,"0.1");
61 SYNFIG_LAYER_SET_CVS_ID(Layer_Stretch,"$Id$");
63 /* === P R O C E D U R E S ================================================= */
65 /* === M E T H O D S ======================================================= */
67 /* === E N T R Y P O I N T ================================================= */
69 Layer_Stretch::Layer_Stretch():
77 Layer_Stretch::set_param(const String & param, const ValueBase &value)
86 Layer_Stretch::get_param(const String ¶m)const
98 Layer_Stretch::get_param_vocab()const
102 ret.push_back(ParamDesc("amount")
103 .set_local_name(_("Amount"))
106 ret.push_back(ParamDesc("center")
107 .set_local_name(_("Center"))
113 synfig::Layer::Handle
114 Layer_Stretch::hit_check(synfig::Context context, const synfig::Point &pos)const
117 npos[0]=(npos[0]-center[0])/amount[0]+center[0];
118 npos[1]=(npos[1]-center[1])/amount[1]+center[1];
119 return context.hit_check(npos);
123 Layer_Stretch::get_color(Context context, const Point &pos)const
126 npos[0]=(npos[0]-center[0])/amount[0]+center[0];
127 npos[1]=(npos[1]-center[1])/amount[1]+center[1];
128 return context.get_color(npos);
131 class Stretch_Trans : public Transform
133 etl::handle<const Layer_Stretch> layer;
135 Stretch_Trans(const Layer_Stretch* x):Transform(x->get_guid()),layer(x) { }
137 synfig::Vector perform(const synfig::Vector& x)const
139 return Vector((x[0]-layer->center[0])*layer->amount[0]+layer->center[0],
140 (x[1]-layer->center[1])*layer->amount[1]+layer->center[1]);
143 synfig::Vector unperform(const synfig::Vector& x)const
145 return Vector((x[0]-layer->center[0])/layer->amount[0]+layer->center[0],
146 (x[1]-layer->center[1])/layer->amount[1]+layer->center[1]);
149 etl::handle<Transform>
150 Layer_Stretch::get_transform()const
152 return new Stretch_Trans(this);
156 Layer_Stretch::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
158 RendDesc desc(renddesc);
160 // Adjust the top_left and bottom_right points
161 // for our zoom amount
163 npos[0]=(desc.get_tl()[0]-center[0])/amount[0]+center[0];
164 npos[1]=(desc.get_tl()[1]-center[1])/amount[1]+center[1];
166 npos[0]=(desc.get_br()[0]-center[0])/amount[0]+center[0];
167 npos[1]=(desc.get_br()[1]-center[1])/amount[1]+center[1];
171 return context.accelerated_render(surface,quality,desc,cb);
175 Layer_Stretch::get_full_bounding_rect(Context context)const
177 Rect rect(context.get_full_bounding_rect());
178 Point min(rect.get_min()), max(rect.get_max());
180 return Rect(Point((min[0]-center[0])*amount[0]+center[0],
181 (min[1]-center[1])*amount[1]+center[1]),
182 Point((max[0]-center[0])*amount[0]+center[0],
183 (max[1]-center[1])*amount[1]+center[1]));