Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / 0.61.09 / src / modules / lyr_std / translate.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file translate.cpp
3 **      \brief Implementation of the "Translate" 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 ** === N O T E S ===========================================================
22 **
23 ** ========================================================================= */
24
25 /* === H E A D E R S ======================================================= */
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 "translate.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/canvas.h>
44 #include <synfig/transform.h>
45
46 #endif
47
48 /* === M A C R O S ========================================================= */
49
50 /* === G L O B A L S ======================================================= */
51
52 SYNFIG_LAYER_INIT(Translate);
53 SYNFIG_LAYER_SET_NAME(Translate,"translate");
54 SYNFIG_LAYER_SET_LOCAL_NAME(Translate,N_("Translate"));
55 SYNFIG_LAYER_SET_CATEGORY(Translate,N_("Transform"));
56 SYNFIG_LAYER_SET_VERSION(Translate,"0.1");
57 SYNFIG_LAYER_SET_CVS_ID(Translate,"$Id$");
58
59 /* === P R O C E D U R E S ================================================= */
60
61 /* === M E T H O D S ======================================================= */
62
63 /* === E N T R Y P O I N T ================================================= */
64
65 Translate::Translate():origin(0,0)
66 {
67 }
68
69 Translate::~Translate()
70 {
71 }
72
73 bool
74 Translate::set_param(const String & param, const ValueBase &value)
75 {
76         IMPORT(origin);
77
78         return false;
79 }
80
81 ValueBase
82 Translate::get_param(const String& param)const
83 {
84         EXPORT(origin);
85         EXPORT_NAME();
86         EXPORT_VERSION();
87
88         return ValueBase();
89 }
90
91 Layer::Vocab
92 Translate::get_param_vocab()const
93 {
94         Layer::Vocab ret;
95
96         ret.push_back(ParamDesc("origin")
97                 .set_local_name(_("Origin"))
98                 .set_description(_("Point where you want the origin to be"))
99         );
100
101         return ret;
102 }
103
104 synfig::Layer::Handle
105 Translate::hit_check(synfig::Context context, const synfig::Point &pos)const
106 {
107         return context.hit_check(pos-origin);
108 }
109
110 Color
111 Translate::get_color(Context context, const Point &pos)const
112 {
113         return context.get_color(pos-origin);
114 }
115
116 class Translate_Trans : public Transform
117 {
118         etl::handle<const Translate> layer;
119 public:
120         Translate_Trans(const Translate* x):Transform(x->get_guid()),layer(x) { }
121
122         synfig::Vector perform(const synfig::Vector& x)const
123         {
124                 return x+layer->origin;
125         }
126
127         synfig::Vector unperform(const synfig::Vector& x)const
128         {
129                 return x-layer->origin;
130         }
131 };
132 etl::handle<Transform>
133 Translate::get_transform()const
134 {
135         return new Translate_Trans(this);
136 }
137
138 bool
139 Translate::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
140 {
141         RendDesc desc(renddesc);
142
143         desc.clear_flags();
144         desc.set_tl(desc.get_tl()-origin);
145         desc.set_br(desc.get_br()-origin);
146
147         // Render the scene
148         if(!context.accelerated_render(surface,quality,desc,cb))
149         {
150                 if(cb)cb->error(strprintf(__FILE__"%d: Accelerated Renderer Failure",__LINE__));
151                 return false;
152         }
153
154         return true;
155 }
156
157 Rect
158 Translate::get_full_bounding_rect(Context context)const
159 {
160         return context.get_full_bounding_rect() + origin;
161 }