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