Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_05 / synfig-core / src / modules / lyr_std / stretch.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file stretch.cpp
3 **      \brief Template Header
4 **
5 **      $Id: stretch.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $
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 #define SYNFIG_NO_ANGLE
26
27 #ifdef USING_PCH
28 #       include "pch.h"
29 #else
30 #ifdef HAVE_CONFIG_H
31 #       include <config.h>
32 #endif
33
34 #include "stretch.h"
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>
44
45 #endif
46
47 /* === U S I N G =========================================================== */
48
49 using namespace etl;
50 using namespace std;
51 using namespace synfig;
52
53 /* === G L O B A L S ======================================================= */
54
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 $");
61
62 /* === P R O C E D U R E S ================================================= */
63
64 /* === M E T H O D S ======================================================= */
65
66 /* === E N T R Y P O I N T ================================================= */
67
68 Layer_Stretch::Layer_Stretch():
69         amount(1,1),
70         center(0,0)
71 {
72 }
73
74         
75 bool
76 Layer_Stretch::set_param(const String & param, const ValueBase &value)
77 {
78         IMPORT(amount);
79         IMPORT(center);
80         
81         return false;   
82 }
83
84 ValueBase
85 Layer_Stretch::get_param(const String &param)const
86 {
87         EXPORT(amount);
88         EXPORT(center);
89
90         EXPORT_NAME();
91         EXPORT_VERSION();
92                 
93         return ValueBase();     
94 }
95
96 Layer::Vocab
97 Layer_Stretch::get_param_vocab()const
98 {
99         Layer::Vocab ret;
100         
101         ret.push_back(ParamDesc("amount")
102                 .set_local_name(_("Amount"))
103         );
104
105         ret.push_back(ParamDesc("center")
106                 .set_local_name(_("Center"))
107         );
108         
109         return ret;
110 }
111
112 synfig::Layer::Handle
113 Layer_Stretch::hit_check(synfig::Context context, const synfig::Point &pos)const
114 {
115         Point npos(pos);
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);
119 }
120
121 Color
122 Layer_Stretch::get_color(Context context, const Point &pos)const
123 {
124         Point npos(pos);
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);
128 }
129
130 class Stretch_Trans : public Transform
131 {
132         etl::handle<const Layer_Stretch> layer;
133 public:
134         Stretch_Trans(const Layer_Stretch* x):Transform(x->get_guid()),layer(x) { }
135         
136         synfig::Vector perform(const synfig::Vector& x)const
137         {
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]);
139         }
140         
141         synfig::Vector unperform(const synfig::Vector& x)const
142         {
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]);
144         }
145 };
146 etl::handle<Transform>
147 Layer_Stretch::get_transform()const
148 {
149         return new Stretch_Trans(this);
150 }
151
152 bool
153 Layer_Stretch::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
154 {
155         RendDesc desc(renddesc);
156         desc.clear_flags();
157     // Adjust the top_left and bottom_right points
158         // for our zoom amount
159         Point npos;
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];
162         desc.set_tl(npos);
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];
165         desc.set_br(npos);
166
167         // Render the scene
168         return context.accelerated_render(surface,quality,desc,cb);
169 }