1 /* === S Y N F I G ========================================================= */
2 /*! \file translate.cpp
3 ** \brief Template File
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,_("Translate"));
55 SYNFIG_LAYER_SET_CATEGORY(Translate,_("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)
69 Translate::~Translate()
74 Translate::set_param(const String & param, const ValueBase &value)
82 Translate::get_param(const String& param)const
92 Translate::get_param_vocab()const
96 ret.push_back(ParamDesc("origin")
97 .set_local_name(_("Origin"))
98 .set_description(_("Point where you want the origin to be"))
104 synfig::Layer::Handle
105 Translate::hit_check(synfig::Context context, const synfig::Point &pos)const
107 return context.hit_check(pos-origin);
111 Translate::get_color(Context context, const Point &pos)const
113 return context.get_color(pos-origin);
116 class Translate_Trans : public Transform
118 etl::handle<const Translate> layer;
120 Translate_Trans(const Translate* x):Transform(x->get_guid()),layer(x) { }
122 synfig::Vector perform(const synfig::Vector& x)const
124 return x+layer->origin;
127 synfig::Vector unperform(const synfig::Vector& x)const
129 return x-layer->origin;
132 etl::handle<Transform>
133 Translate::get_transform()const
135 return new Translate_Trans(this);
139 Translate::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
141 RendDesc desc(renddesc);
144 desc.set_tl(desc.get_tl()-origin);
145 desc.set_br(desc.get_br()-origin);
148 if(!context.accelerated_render(surface,quality,desc,cb))
150 if(cb)cb->error(strprintf(__FILE__"%d: Accelerated Renderer Failure",__LINE__));
158 Translate::get_full_bounding_rect(Context context)const
160 return context.get_full_bounding_rect() + origin;