1 /*! ========================================================================
4 ** $Id: translate.cpp,v 1.2 2005/01/24 03:08:17 darco Exp $
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.
18 ** === N O T E S ===========================================================
20 ** ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include "translate.h"
32 #include <synfig/string.h>
33 #include <synfig/time.h>
34 #include <synfig/context.h>
35 #include <synfig/paramdesc.h>
36 #include <synfig/renddesc.h>
37 #include <synfig/surface.h>
38 #include <synfig/value.h>
39 #include <synfig/valuenode.h>
40 #include <synfig/canvas.h>
41 #include <synfig/transform.h>
45 /* === M A C R O S ========================================================= */
47 /* === G L O B A L S ======================================================= */
49 SYNFIG_LAYER_INIT(Translate);
50 SYNFIG_LAYER_SET_NAME(Translate,"translate");
51 SYNFIG_LAYER_SET_LOCAL_NAME(Translate,_("Translate"));
52 SYNFIG_LAYER_SET_CATEGORY(Translate,_("Transform"));
53 SYNFIG_LAYER_SET_VERSION(Translate,"0.1");
54 SYNFIG_LAYER_SET_CVS_ID(Translate,"$Id: translate.cpp,v 1.2 2005/01/24 03:08:17 darco Exp $");
56 /* === P R O C E D U R E S ================================================= */
58 /* === M E T H O D S ======================================================= */
60 /* === E N T R Y P O I N T ================================================= */
62 Translate::Translate():origin(0,0)
66 Translate::~Translate()
71 Translate::set_param(const String & param, const ValueBase &value)
79 Translate::get_param(const String& param)const
89 Translate::get_param_vocab()const
93 ret.push_back(ParamDesc("origin")
94 .set_local_name(_("Origin"))
95 .set_description(_("Point where you want the origin to be"))
101 synfig::Layer::Handle
102 Translate::hit_check(synfig::Context context, const synfig::Point &pos)const
104 return context.hit_check(pos-origin);
108 Translate::get_color(Context context, const Point &pos)const
110 return context.get_color(pos-origin);
113 class Translate_Trans : public Transform
115 etl::handle<const Translate> layer;
117 Translate_Trans(const Translate* x):Transform(x->get_guid()),layer(x) { }
119 synfig::Vector perform(const synfig::Vector& x)const
121 return x+layer->origin;
124 synfig::Vector unperform(const synfig::Vector& x)const
126 return x-layer->origin;
129 etl::handle<Transform>
130 Translate::get_transform()const
132 return new Translate_Trans(this);
136 Translate::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
138 RendDesc desc(renddesc);
141 desc.set_tl(desc.get_tl()-origin);
142 desc.set_br(desc.get_br()-origin);
145 if(!context.accelerated_render(surface,quality,desc,cb))
147 if(cb)cb->error(strprintf(__FILE__"%d: Accelerated Renderer Failure",__LINE__));
155 Translate::get_full_bounding_rect(Context context)const
157 return context.get_full_bounding_rect() + origin;