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 / translate.cpp
1 /*! ========================================================================
2 ** Synfig
3 ** Template File
4 ** $Id: translate.cpp,v 1.2 2005/01/24 03:08:17 darco Exp $
5 **
6 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
7 **
8 **      This package is free software; you can redistribute it and/or
9 **      modify it under the terms of the GNU General Public License as
10 **      published by the Free Software Foundation; either version 2 of
11 **      the License, or (at your option) any later version.
12 **
13 **      This package is distributed in the hope that it will be useful,
14 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
15 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 **      General Public License for more details.
17 **
18 ** === N O T E S ===========================================================
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 "translate.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/canvas.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(Translate);
50 SYNFIG_LAYER_SET_NAME(Translate,"translate");
51 SYNFIG_LAYER_SET_LOCAL_NAME(Translate,_("Translate"));
52 SYNFIG_LAYER_SET_CATEGORY(Translate,_("Transform"));
53 SYNFIG_LAYER_SET_VERSION(Translate,"0.1");
54 SYNFIG_LAYER_SET_CVS_ID(Translate,"$Id: translate.cpp,v 1.2 2005/01/24 03:08:17 darco Exp $");
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 Translate::Translate():origin(0,0)
63 {
64 }
65
66 Translate::~Translate()
67 {
68 }
69         
70 bool
71 Translate::set_param(const String & param, const ValueBase &value)
72 {
73         IMPORT(origin);
74         
75         return false;
76 }
77
78 ValueBase
79 Translate::get_param(const String& param)const
80 {
81         EXPORT(origin);
82         EXPORT_NAME();
83         EXPORT_VERSION();
84                 
85         return ValueBase();     
86 }
87
88 Layer::Vocab
89 Translate::get_param_vocab()const
90 {
91         Layer::Vocab ret;
92         
93         ret.push_back(ParamDesc("origin")
94                 .set_local_name(_("Origin"))
95                 .set_description(_("Point where you want the origin to be"))
96         );
97         
98         return ret;
99 }
100
101 synfig::Layer::Handle
102 Translate::hit_check(synfig::Context context, const synfig::Point &pos)const
103 {
104         return context.hit_check(pos-origin);
105 }
106
107 Color
108 Translate::get_color(Context context, const Point &pos)const
109 {
110         return context.get_color(pos-origin);
111 }
112
113 class Translate_Trans : public Transform
114 {
115         etl::handle<const Translate> layer;
116 public:
117         Translate_Trans(const Translate* x):Transform(x->get_guid()),layer(x) { }
118         
119         synfig::Vector perform(const synfig::Vector& x)const
120         {
121                 return x+layer->origin;
122         }
123         
124         synfig::Vector unperform(const synfig::Vector& x)const
125         {
126                 return x-layer->origin;
127         }
128 };
129 etl::handle<Transform>
130 Translate::get_transform()const
131 {
132         return new Translate_Trans(this);
133 }
134
135 bool
136 Translate::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
137 {
138         RendDesc desc(renddesc);
139
140         desc.clear_flags();
141         desc.set_tl(desc.get_tl()-origin);
142         desc.set_br(desc.get_br()-origin);
143
144         // Render the scene
145         if(!context.accelerated_render(surface,quality,desc,cb))
146         {
147                 if(cb)cb->error(strprintf(__FILE__"%d: Accelerated Renderer Failure",__LINE__));
148                 return false;
149         }
150
151         return true;
152 }
153
154 Rect
155 Translate::get_full_bounding_rect(Context context)const
156 {
157         return context.get_full_bounding_rect() + origin;
158 }