Add parameter static option for rest of layers.
[synfig.git] / synfig-core / src / modules / lyr_std / zoom.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file zoom.cpp
3 **      \brief Implementation of the "Zoom" layer
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,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$");
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         Layer::Vocab voc(get_param_vocab());
67         Layer::fill_static(voc);
68 }
69
70 bool
71 Zoom::set_param(const String & param, const ValueBase &value)
72 {
73
74         IMPORT(center);
75         IMPORT(amount);
76
77         return false;
78 }
79
80 ValueBase
81 Zoom::get_param(const String &param)const
82 {
83         EXPORT(center);
84         EXPORT(amount);
85
86         EXPORT_NAME();
87         EXPORT_VERSION();
88
89         return ValueBase();
90 }
91
92 Layer::Vocab
93 Zoom::get_param_vocab()const
94 {
95         Layer::Vocab ret;
96
97         ret.push_back(ParamDesc("amount")
98                 .set_local_name(_("Amount"))
99                 .set_description(_("Amount to zoom in"))
100         );
101
102         ret.push_back(ParamDesc("center")
103                 .set_local_name(_("Center"))
104                 .set_description(_("Point to zoom in to"))
105         );
106
107         return ret;
108 }
109
110 synfig::Layer::Handle
111 Zoom::hit_check(synfig::Context context, const synfig::Point &pos)const
112 {
113         return context.hit_check((pos-center)/exp(amount)+center);
114 }
115
116 Color
117 Zoom::get_color(Context context, const Point &pos)const
118 {
119         return context.get_color((pos-center)/exp(amount)+center);
120 }
121
122 class Zoom_Trans : public Transform
123 {
124         etl::handle<const Zoom> layer;
125 public:
126         Zoom_Trans(const Zoom* x):Transform(x->get_guid()),layer(x) { }
127
128         synfig::Vector perform(const synfig::Vector& x)const
129         {
130                 return (x-layer->center)*exp(layer->amount)+layer->center;
131         }
132
133         synfig::Vector unperform(const synfig::Vector& x)const
134         {
135                 return (x-layer->center)/exp(layer->amount)+layer->center;
136         }
137 };
138 etl::handle<Transform>
139 Zoom::get_transform()const
140 {
141         return new Zoom_Trans(this);
142 }
143
144 bool
145 Zoom::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
146 {
147         Vector::value_type zoomfactor=1.0/exp(amount);
148         RendDesc desc(renddesc);
149         desc.clear_flags();
150
151     // Adjust the top_left and bottom_right points
152         // for our zoom amount
153         desc.set_tl((desc.get_tl()-center)*zoomfactor+center);
154         desc.set_br((desc.get_br()-center)*zoomfactor+center);
155
156         // Render the scene
157         return context.accelerated_render(surface,quality,desc,cb);
158 }
159
160 synfig::Rect
161 Zoom::get_full_bounding_rect(synfig::Context context)const
162 {
163         return (context.get_full_bounding_rect()-center)*exp(amount)+center;
164 }