Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_07_rc3 / src / modules / lyr_std / zoom.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file zoom.cpp
3 **      \brief writeme
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
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.
14 **
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.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "zoom.h"
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>
42
43 #endif
44
45 /* === M A C R O S ========================================================= */
46
47 /* === G L O B A L S ======================================================= */
48
49 SYNFIG_LAYER_INIT(Zoom);
50 SYNFIG_LAYER_SET_NAME(Zoom,"zoom");
51 SYNFIG_LAYER_SET_LOCAL_NAME(Zoom,_("Zoom"));
52 SYNFIG_LAYER_SET_CATEGORY(Zoom,_("Transform"));
53 SYNFIG_LAYER_SET_VERSION(Zoom,"0.1");
54 SYNFIG_LAYER_SET_CVS_ID(Zoom,"$Id$");
55
56 /* === P R O C E D U R E S ================================================= */
57
58 /* === M E T H O D S ======================================================= */
59
60 /* === E N T R Y P O I N T ================================================= */
61
62 Zoom::Zoom():
63         center(0,0),
64         amount(0)
65 {
66 }
67
68 bool
69 Zoom::set_param(const String & param, const ValueBase &value)
70 {
71
72         IMPORT(center);
73         IMPORT(amount);
74
75         return false;
76 }
77
78 ValueBase
79 Zoom::get_param(const String &param)const
80 {
81         EXPORT(center);
82         EXPORT(amount);
83
84         EXPORT_NAME();
85         EXPORT_VERSION();
86
87         return ValueBase();
88 }
89
90 Layer::Vocab
91 Zoom::get_param_vocab()const
92 {
93         Layer::Vocab ret;
94
95         ret.push_back(ParamDesc("amount")
96                 .set_local_name(_("Amount"))
97                 .set_description(_("Amount to zoom in"))
98         );
99
100         ret.push_back(ParamDesc("center")
101                 .set_local_name(_("Center"))
102                 .set_description(_("Point to zoom in to"))
103         );
104
105         return ret;
106 }
107
108 synfig::Layer::Handle
109 Zoom::hit_check(synfig::Context context, const synfig::Point &pos)const
110 {
111         return context.hit_check((pos-center)/exp(amount)+center);
112 }
113
114 Color
115 Zoom::get_color(Context context, const Point &pos)const
116 {
117         return context.get_color((pos-center)/exp(amount)+center);
118 }
119
120 class Zoom_Trans : public Transform
121 {
122         etl::handle<const Zoom> layer;
123 public:
124         Zoom_Trans(const Zoom* x):Transform(x->get_guid()),layer(x) { }
125
126         synfig::Vector perform(const synfig::Vector& x)const
127         {
128                 return (x-layer->center)*exp(layer->amount)+layer->center;
129         }
130
131         synfig::Vector unperform(const synfig::Vector& x)const
132         {
133                 return (x-layer->center)/exp(layer->amount)+layer->center;
134         }
135 };
136 etl::handle<Transform>
137 Zoom::get_transform()const
138 {
139         return new Zoom_Trans(this);
140 }
141
142 bool
143 Zoom::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
144 {
145         Vector::value_type zoomfactor=1.0/exp(amount);
146         RendDesc desc(renddesc);
147         desc.clear_flags();
148
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);
153
154         // Render the scene
155         return context.accelerated_render(surface,quality,desc,cb);
156 }
157
158 synfig::Rect
159 Zoom::get_full_bounding_rect(synfig::Context context)const
160 {
161         return (context.get_full_bounding_rect()-center)*exp(amount)+center;
162 }