moreupdates
[synfig.git] / synfig-core / trunk / src / modules / lyr_std / zoom.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file zoom.cpp
3 **      \brief writeme
4 **
5 **      $Id: zoom.cpp,v 1.2 2005/01/24 03:08:17 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "zoom.h"
32 #include <synfig/string.h>
33 #include <synfig/time.h>
34 #include <synfig/context.h>
35 #include <synfig/paramdesc.h>
36 #include <synfig/renddesc.h>
37 #include <synfig/surface.h>
38 #include <synfig/value.h>
39 #include <synfig/valuenode.h>
40 #include <synfig/transform.h>
41
42 #endif
43
44 /* === M A C R O S ========================================================= */
45
46 /* === G L O B A L S ======================================================= */
47
48 SYNFIG_LAYER_INIT(Zoom);
49 SYNFIG_LAYER_SET_NAME(Zoom,"zoom");
50 SYNFIG_LAYER_SET_LOCAL_NAME(Zoom,_("Zoom"));
51 SYNFIG_LAYER_SET_CATEGORY(Zoom,_("Transform"));
52 SYNFIG_LAYER_SET_VERSION(Zoom,"0.1");
53 SYNFIG_LAYER_SET_CVS_ID(Zoom,"$Id: zoom.cpp,v 1.2 2005/01/24 03:08:17 darco Exp $");
54
55 /* === P R O C E D U R E S ================================================= */
56
57 /* === M E T H O D S ======================================================= */
58
59 /* === E N T R Y P O I N T ================================================= */
60
61 Zoom::Zoom():
62         center(0,0),
63         amount(0)
64 {
65 }
66         
67 bool
68 Zoom::set_param(const String & param, const ValueBase &value)
69 {
70
71         IMPORT(center);
72         IMPORT(amount);
73         
74         return false;
75 }
76
77 ValueBase
78 Zoom::get_param(const String &param)const
79 {
80         EXPORT(center);
81         EXPORT(amount);
82
83         EXPORT_NAME();
84         EXPORT_VERSION();
85                 
86         return ValueBase();     
87 }
88
89 Layer::Vocab
90 Zoom::get_param_vocab()const
91 {
92         Layer::Vocab ret;
93         
94         ret.push_back(ParamDesc("amount")
95                 .set_local_name(_("Amount"))
96                 .set_description(_("Amount to zoom in"))
97         );
98
99         ret.push_back(ParamDesc("center")
100                 .set_local_name(_("Center"))
101                 .set_description(_("Point to zoom in to"))
102         );
103         
104         return ret;
105 }
106
107 synfig::Layer::Handle
108 Zoom::hit_check(synfig::Context context, const synfig::Point &pos)const
109 {
110         return context.hit_check((pos-center)/exp(amount)+center);
111 }
112
113 Color
114 Zoom::get_color(Context context, const Point &pos)const
115 {
116         return context.get_color((pos-center)/exp(amount)+center);
117 }
118
119 class Zoom_Trans : public Transform
120 {
121         etl::handle<const Zoom> layer;
122 public:
123         Zoom_Trans(const Zoom* x):Transform(x->get_guid()),layer(x) { }
124         
125         synfig::Vector perform(const synfig::Vector& x)const
126         {
127                 return (x-layer->center)*exp(layer->amount)+layer->center;
128         }
129         
130         synfig::Vector unperform(const synfig::Vector& x)const
131         {
132                 return (x-layer->center)/exp(layer->amount)+layer->center;
133         }
134 };
135 etl::handle<Transform>
136 Zoom::get_transform()const
137 {
138         return new Zoom_Trans(this);
139 }
140
141 bool
142 Zoom::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
143 {
144         Vector::value_type zoomfactor=1.0/exp(amount);
145         RendDesc desc(renddesc);
146         desc.clear_flags();
147
148     // Adjust the top_left and bottom_right points
149         // for our zoom amount
150         desc.set_tl((desc.get_tl()-center)*zoomfactor+center);
151         desc.set_br((desc.get_br()-center)*zoomfactor+center);
152
153         // Render the scene
154         return context.accelerated_render(surface,quality,desc,cb);
155 }
156
157 synfig::Rect
158 Zoom::get_full_bounding_rect(synfig::Context context)const
159 {
160         return context.get_full_bounding_rect();
161 }
162