Add parameter static option for rest of layers.
[synfig.git] / synfig-core / 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         Layer::Vocab voc(get_param_vocab());
68         Layer::fill_static(voc);
69 }
70
71 Translate::~Translate()
72 {
73 }
74
75 bool
76 Translate::set_param(const String & param, const ValueBase &value)
77 {
78         IMPORT(origin);
79
80         return false;
81 }
82
83 ValueBase
84 Translate::get_param(const String& param)const
85 {
86         EXPORT(origin);
87         EXPORT_NAME();
88         EXPORT_VERSION();
89
90         return ValueBase();
91 }
92
93 Layer::Vocab
94 Translate::get_param_vocab()const
95 {
96         Layer::Vocab ret;
97
98         ret.push_back(ParamDesc("origin")
99                 .set_local_name(_("Origin"))
100                 .set_description(_("Point where you want the origin to be"))
101         );
102
103         return ret;
104 }
105
106 synfig::Layer::Handle
107 Translate::hit_check(synfig::Context context, const synfig::Point &pos)const
108 {
109         return context.hit_check(pos-origin);
110 }
111
112 Color
113 Translate::get_color(Context context, const Point &pos)const
114 {
115         return context.get_color(pos-origin);
116 }
117
118 class Translate_Trans : public Transform
119 {
120         etl::handle<const Translate> layer;
121 public:
122         Translate_Trans(const Translate* x):Transform(x->get_guid()),layer(x) { }
123
124         synfig::Vector perform(const synfig::Vector& x)const
125         {
126                 return x+layer->origin;
127         }
128
129         synfig::Vector unperform(const synfig::Vector& x)const
130         {
131                 return x-layer->origin;
132         }
133 };
134 etl::handle<Transform>
135 Translate::get_transform()const
136 {
137         return new Translate_Trans(this);
138 }
139
140 bool
141 Translate::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
142 {
143         RendDesc desc(renddesc);
144
145         desc.clear_flags();
146         desc.set_tl(desc.get_tl()-origin);
147         desc.set_br(desc.get_br()-origin);
148
149         // Render the scene
150         if(!context.accelerated_render(surface,quality,desc,cb))
151         {
152                 if(cb)cb->error(strprintf(__FILE__"%d: Accelerated Renderer Failure",__LINE__));
153                 return false;
154         }
155
156         return true;
157 }
158
159 Rect
160 Translate::get_full_bounding_rect(Context context)const
161 {
162         return context.get_full_bounding_rect() + origin;
163 }