1 /* === S Y N F I G ========================================================= */
3 ** \brief Implementation of the "Zoom" layer
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 ======================================================= */
33 #include <synfig/string.h>
34 #include <synfig/time.h>
35 #include <synfig/context.h>
36 #include <synfig/paramdesc.h>
37 #include <synfig/renddesc.h>
38 #include <synfig/surface.h>
39 #include <synfig/value.h>
40 #include <synfig/valuenode.h>
41 #include <synfig/transform.h>
45 /* === M A C R O S ========================================================= */
47 /* === G L O B A L S ======================================================= */
49 SYNFIG_LAYER_INIT(Zoom);
50 SYNFIG_LAYER_SET_NAME(Zoom,"zoom");
51 SYNFIG_LAYER_SET_LOCAL_NAME(Zoom,N_("Zoom"));
52 SYNFIG_LAYER_SET_CATEGORY(Zoom,N_("Transform"));
53 SYNFIG_LAYER_SET_VERSION(Zoom,"0.1");
54 SYNFIG_LAYER_SET_CVS_ID(Zoom,"$Id$");
56 /* === P R O C E D U R E S ================================================= */
58 /* === M E T H O D S ======================================================= */
60 /* === E N T R Y P O I N T ================================================= */
69 Zoom::set_param(const String & param, const ValueBase &value)
79 Zoom::get_param(const String ¶m)const
91 Zoom::get_param_vocab()const
95 ret.push_back(ParamDesc("amount")
96 .set_local_name(_("Amount"))
97 .set_description(_("Amount to zoom in"))
100 ret.push_back(ParamDesc("center")
101 .set_local_name(_("Center"))
102 .set_description(_("Point to zoom in to"))
108 synfig::Layer::Handle
109 Zoom::hit_check(synfig::Context context, const synfig::Point &pos)const
111 return context.hit_check((pos-center)/exp(amount)+center);
115 Zoom::get_color(Context context, const Point &pos)const
117 return context.get_color((pos-center)/exp(amount)+center);
120 class Zoom_Trans : public Transform
122 etl::handle<const Zoom> layer;
124 Zoom_Trans(const Zoom* x):Transform(x->get_guid()),layer(x) { }
126 synfig::Vector perform(const synfig::Vector& x)const
128 return (x-layer->center)*exp(layer->amount)+layer->center;
131 synfig::Vector unperform(const synfig::Vector& x)const
133 return (x-layer->center)/exp(layer->amount)+layer->center;
136 etl::handle<Transform>
137 Zoom::get_transform()const
139 return new Zoom_Trans(this);
143 Zoom::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
145 Vector::value_type zoomfactor=1.0/exp(amount);
146 RendDesc desc(renddesc);
149 // Adjust the top_left and bottom_right points
150 // for our zoom amount
151 desc.set_tl((desc.get_tl()-center)*zoomfactor+center);
152 desc.set_br((desc.get_br()-center)*zoomfactor+center);
155 return context.accelerated_render(surface,quality,desc,cb);
159 Zoom::get_full_bounding_rect(synfig::Context context)const
161 return (context.get_full_bounding_rect()-center)*exp(amount)+center;