1 /* === S Y N F I G ========================================================= */
2 /*! \file translate.cpp
3 ** \brief Template File
6 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
19 ** === N O T E S ===========================================================
21 ** ========================================================================= */
23 /* === H E A D E R S ======================================================= */
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>
46 /* === M A C R O S ========================================================= */
48 /* === G L O B A L S ======================================================= */
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: translate.cpp,v 1.2 2005/01/24 03:08:17 darco Exp $");
57 /* === P R O C E D U R E S ================================================= */
59 /* === M E T H O D S ======================================================= */
61 /* === E N T R Y P O I N T ================================================= */
63 Translate::Translate():origin(0,0)
67 Translate::~Translate()
72 Translate::set_param(const String & param, const ValueBase &value)
80 Translate::get_param(const String& param)const
90 Translate::get_param_vocab()const
94 ret.push_back(ParamDesc("origin")
95 .set_local_name(_("Origin"))
96 .set_description(_("Point where you want the origin to be"))
102 synfig::Layer::Handle
103 Translate::hit_check(synfig::Context context, const synfig::Point &pos)const
105 return context.hit_check(pos-origin);
109 Translate::get_color(Context context, const Point &pos)const
111 return context.get_color(pos-origin);
114 class Translate_Trans : public Transform
116 etl::handle<const Translate> layer;
118 Translate_Trans(const Translate* x):Transform(x->get_guid()),layer(x) { }
120 synfig::Vector perform(const synfig::Vector& x)const
122 return x+layer->origin;
125 synfig::Vector unperform(const synfig::Vector& x)const
127 return x-layer->origin;
130 etl::handle<Transform>
131 Translate::get_transform()const
133 return new Translate_Trans(this);
137 Translate::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
139 RendDesc desc(renddesc);
142 desc.set_tl(desc.get_tl()-origin);
143 desc.set_br(desc.get_br()-origin);
146 if(!context.accelerated_render(surface,quality,desc,cb))
148 if(cb)cb->error(strprintf(__FILE__"%d: Accelerated Renderer Failure",__LINE__));
156 Translate::get_full_bounding_rect(Context context)const
158 return context.get_full_bounding_rect() + origin;