1 /* === S Y N F I G ========================================================= */
3 ** \brief Implementation of the "Stretch" layer
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 ======================================================= */
34 #include <synfig/string.h>
35 #include <synfig/time.h>
36 #include <synfig/context.h>
37 #include <synfig/paramdesc.h>
38 #include <synfig/renddesc.h>
39 #include <synfig/surface.h>
40 #include <synfig/value.h>
41 #include <synfig/valuenode.h>
42 #include <synfig/transform.h>
46 /* === U S I N G =========================================================== */
50 using namespace synfig;
52 /* === G L O B A L S ======================================================= */
54 SYNFIG_LAYER_INIT(Layer_Stretch);
55 SYNFIG_LAYER_SET_NAME(Layer_Stretch,"stretch");
56 SYNFIG_LAYER_SET_LOCAL_NAME(Layer_Stretch,N_("Stretch"));
57 SYNFIG_LAYER_SET_CATEGORY(Layer_Stretch,N_("Distortions"));
58 SYNFIG_LAYER_SET_VERSION(Layer_Stretch,"0.1");
59 SYNFIG_LAYER_SET_CVS_ID(Layer_Stretch,"$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 Layer_Stretch::Layer_Stretch():
71 Layer::Vocab voc(get_param_vocab());
72 Layer::fill_static(voc);
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"))
104 .set_origin("center")
107 ret.push_back(ParamDesc("center")
108 .set_local_name(_("Center"))
114 synfig::Layer::Handle
115 Layer_Stretch::hit_check(synfig::Context context, const synfig::Point &pos)const
118 npos[0]=(npos[0]-center[0])/amount[0]+center[0];
119 npos[1]=(npos[1]-center[1])/amount[1]+center[1];
120 return context.hit_check(npos);
124 Layer_Stretch::get_color(Context context, const Point &pos)const
127 npos[0]=(npos[0]-center[0])/amount[0]+center[0];
128 npos[1]=(npos[1]-center[1])/amount[1]+center[1];
129 return context.get_color(npos);
132 class Stretch_Trans : public Transform
134 etl::handle<const Layer_Stretch> layer;
136 Stretch_Trans(const Layer_Stretch* x):Transform(x->get_guid()),layer(x) { }
138 synfig::Vector perform(const synfig::Vector& x)const
140 return Vector((x[0]-layer->center[0])*layer->amount[0]+layer->center[0],
141 (x[1]-layer->center[1])*layer->amount[1]+layer->center[1]);
144 synfig::Vector unperform(const synfig::Vector& x)const
146 return Vector((x[0]-layer->center[0])/layer->amount[0]+layer->center[0],
147 (x[1]-layer->center[1])/layer->amount[1]+layer->center[1]);
150 etl::handle<Transform>
151 Layer_Stretch::get_transform()const
153 return new Stretch_Trans(this);
157 Layer_Stretch::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
159 if (amount[0] == 0 || amount[1] == 0)
161 surface->set_wh(renddesc.get_w(), renddesc.get_h());
166 RendDesc desc(renddesc);
168 // Adjust the top_left and bottom_right points
169 // for our zoom amount
171 npos[0]=(desc.get_tl()[0]-center[0])/amount[0]+center[0];
172 npos[1]=(desc.get_tl()[1]-center[1])/amount[1]+center[1];
174 npos[0]=(desc.get_br()[0]-center[0])/amount[0]+center[0];
175 npos[1]=(desc.get_br()[1]-center[1])/amount[1]+center[1];
179 return context.accelerated_render(surface,quality,desc,cb);
183 Layer_Stretch::get_full_bounding_rect(Context context)const
185 Rect rect(context.get_full_bounding_rect());
186 Point min(rect.get_min()), max(rect.get_max());
188 return Rect(Point((min[0]-center[0])*amount[0]+center[0],
189 (min[1]-center[1])*amount[1]+center[1]),
190 Point((max[0]-center[0])*amount[0]+center[0],
191 (max[1]-center[1])*amount[1]+center[1]));