1 /* === S Y N F I G ========================================================= */
2 /*! \file translate.cpp
3 ** \brief Implementation of the "Translate" layer
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 ** === N O T E S ===========================================================
23 ** ========================================================================= */
25 /* === H E A D E R S ======================================================= */
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>
48 /* === M A C R O S ========================================================= */
50 /* === G L O B A L S ======================================================= */
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$");
59 /* === P R O C E D U R E S ================================================= */
61 /* === M E T H O D S ======================================================= */
63 /* === E N T R Y P O I N T ================================================= */
65 Translate::Translate():origin(0,0)
67 Layer::Vocab voc(get_param_vocab());
68 Layer::fill_static(voc);
71 Translate::~Translate()
76 Translate::set_param(const String & param, const ValueBase &value)
84 Translate::get_param(const String& param)const
94 Translate::get_param_vocab()const
98 ret.push_back(ParamDesc("origin")
99 .set_local_name(_("Origin"))
100 .set_description(_("Point where you want the origin to be"))
106 synfig::Layer::Handle
107 Translate::hit_check(synfig::Context context, const synfig::Point &pos)const
109 return context.hit_check(pos-origin);
113 Translate::get_color(Context context, const Point &pos)const
115 return context.get_color(pos-origin);
118 class Translate_Trans : public Transform
120 etl::handle<const Translate> layer;
122 Translate_Trans(const Translate* x):Transform(x->get_guid()),layer(x) { }
124 synfig::Vector perform(const synfig::Vector& x)const
126 return x+layer->origin;
129 synfig::Vector unperform(const synfig::Vector& x)const
131 return x-layer->origin;
134 etl::handle<Transform>
135 Translate::get_transform()const
137 return new Translate_Trans(this);
141 Translate::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
143 RendDesc desc(renddesc);
146 desc.set_tl(desc.get_tl()-origin);
147 desc.set_br(desc.get_br()-origin);
150 if(!context.accelerated_render(surface,quality,desc,cb))
152 if(cb)cb->error(strprintf(__FILE__"%d: Accelerated Renderer Failure",__LINE__));
160 Translate::get_full_bounding_rect(Context context)const
162 return context.get_full_bounding_rect() + origin;