1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
5 ** $Id: stretch.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
25 #define SYNFIG_NO_ANGLE
35 #include <synfig/string.h>
36 #include <synfig/time.h>
37 #include <synfig/context.h>
38 #include <synfig/paramdesc.h>
39 #include <synfig/renddesc.h>
40 #include <synfig/surface.h>
41 #include <synfig/value.h>
42 #include <synfig/valuenode.h>
43 #include <synfig/transform.h>
47 /* === U S I N G =========================================================== */
51 using namespace synfig;
53 /* === G L O B A L S ======================================================= */
55 SYNFIG_LAYER_INIT(Layer_Stretch);
56 SYNFIG_LAYER_SET_NAME(Layer_Stretch,"stretch");
57 SYNFIG_LAYER_SET_LOCAL_NAME(Layer_Stretch,_("Stretch"));
58 SYNFIG_LAYER_SET_CATEGORY(Layer_Stretch,_("Distortions"));
59 SYNFIG_LAYER_SET_VERSION(Layer_Stretch,"0.1");
60 SYNFIG_LAYER_SET_CVS_ID(Layer_Stretch,"$Id: stretch.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
62 /* === P R O C E D U R E S ================================================= */
64 /* === M E T H O D S ======================================================= */
66 /* === E N T R Y P O I N T ================================================= */
68 Layer_Stretch::Layer_Stretch():
76 Layer_Stretch::set_param(const String & param, const ValueBase &value)
85 Layer_Stretch::get_param(const String ¶m)const
97 Layer_Stretch::get_param_vocab()const
101 ret.push_back(ParamDesc("amount")
102 .set_local_name(_("Amount"))
105 ret.push_back(ParamDesc("center")
106 .set_local_name(_("Center"))
112 synfig::Layer::Handle
113 Layer_Stretch::hit_check(synfig::Context context, const synfig::Point &pos)const
116 npos[0]=(npos[0]-center[0])/amount[0]+center[0];
117 npos[1]=(npos[1]-center[1])/amount[1]+center[1];
118 return context.hit_check(npos);
122 Layer_Stretch::get_color(Context context, const Point &pos)const
125 npos[0]=(npos[0]-center[0])/amount[0]+center[0];
126 npos[1]=(npos[1]-center[1])/amount[1]+center[1];
127 return context.get_color(npos);
130 class Stretch_Trans : public Transform
132 etl::handle<const Layer_Stretch> layer;
134 Stretch_Trans(const Layer_Stretch* x):Transform(x->get_guid()),layer(x) { }
136 synfig::Vector perform(const synfig::Vector& x)const
138 return Vector((x[0]-layer->center[0])*layer->amount[0]+layer->center[0],(x[1]-layer->center[1])*layer->amount[1]+layer->center[1]);
141 synfig::Vector unperform(const synfig::Vector& x)const
143 return Vector((x[0]-layer->center[0])/layer->amount[0]+layer->center[0],(x[1]-layer->center[1])/layer->amount[1]+layer->center[1]);
146 etl::handle<Transform>
147 Layer_Stretch::get_transform()const
149 return new Stretch_Trans(this);
153 Layer_Stretch::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
155 RendDesc desc(renddesc);
157 // Adjust the top_left and bottom_right points
158 // for our zoom amount
160 npos[0]=(desc.get_tl()[0]-center[0])/amount[0]+center[0];
161 npos[1]=(desc.get_tl()[1]-center[1])/amount[1]+center[1];
163 npos[0]=(desc.get_br()[0]-center[0])/amount[0]+center[0];
164 npos[1]=(desc.get_br()[1]-center[1])/amount[1]+center[1];
168 return context.accelerated_render(surface,quality,desc,cb);