moreupdates
[synfig.git] / synfig-core / trunk / src / modules / lyr_std / translate.cpp
1 /*! ========================================================================
2 ** Synfig
3 ** Template File
4 ** $Id: translate.cpp,v 1.2 2005/01/24 03:08:17 darco Exp $
5 **
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
7 **
8 ** This software and associated documentation
9 ** are CONFIDENTIAL and PROPRIETARY property of
10 ** the above-mentioned copyright holder.
11 **
12 ** You may not copy, print, publish, or in any
13 ** other way distribute this software without
14 ** a prior written agreement with
15 ** the copyright holder.
16 **
17 ** === N O T E S ===========================================================
18 **
19 ** ========================================================================= */
20
21 /* === H E A D E R S ======================================================= */
22
23 #ifdef USING_PCH
24 #       include "pch.h"
25 #else
26 #ifdef HAVE_CONFIG_H
27 #       include <config.h>
28 #endif
29
30 #include "translate.h"
31 #include <synfig/string.h>
32 #include <synfig/time.h>
33 #include <synfig/context.h>
34 #include <synfig/paramdesc.h>
35 #include <synfig/renddesc.h>
36 #include <synfig/surface.h>
37 #include <synfig/value.h>
38 #include <synfig/valuenode.h>
39 #include <synfig/canvas.h>
40 #include <synfig/transform.h>
41
42 #endif
43
44 /* === M A C R O S ========================================================= */
45
46 /* === G L O B A L S ======================================================= */
47
48 SYNFIG_LAYER_INIT(Translate);
49 SYNFIG_LAYER_SET_NAME(Translate,"translate");
50 SYNFIG_LAYER_SET_LOCAL_NAME(Translate,_("Translate"));
51 SYNFIG_LAYER_SET_CATEGORY(Translate,_("Transform"));
52 SYNFIG_LAYER_SET_VERSION(Translate,"0.1");
53 SYNFIG_LAYER_SET_CVS_ID(Translate,"$Id: translate.cpp,v 1.2 2005/01/24 03:08:17 darco Exp $");
54
55 /* === P R O C E D U R E S ================================================= */
56
57 /* === M E T H O D S ======================================================= */
58
59 /* === E N T R Y P O I N T ================================================= */
60
61 Translate::Translate():origin(0,0)
62 {
63 }
64
65 Translate::~Translate()
66 {
67 }
68         
69 bool
70 Translate::set_param(const String & param, const ValueBase &value)
71 {
72         IMPORT(origin);
73         
74         return false;
75 }
76
77 ValueBase
78 Translate::get_param(const String& param)const
79 {
80         EXPORT(origin);
81         EXPORT_NAME();
82         EXPORT_VERSION();
83                 
84         return ValueBase();     
85 }
86
87 Layer::Vocab
88 Translate::get_param_vocab()const
89 {
90         Layer::Vocab ret;
91         
92         ret.push_back(ParamDesc("origin")
93                 .set_local_name(_("Origin"))
94                 .set_description(_("Point where you want the origin to be"))
95         );
96         
97         return ret;
98 }
99
100 synfig::Layer::Handle
101 Translate::hit_check(synfig::Context context, const synfig::Point &pos)const
102 {
103         return context.hit_check(pos-origin);
104 }
105
106 Color
107 Translate::get_color(Context context, const Point &pos)const
108 {
109         return context.get_color(pos-origin);
110 }
111
112 class Translate_Trans : public Transform
113 {
114         etl::handle<const Translate> layer;
115 public:
116         Translate_Trans(const Translate* x):Transform(x->get_guid()),layer(x) { }
117         
118         synfig::Vector perform(const synfig::Vector& x)const
119         {
120                 return x+layer->origin;
121         }
122         
123         synfig::Vector unperform(const synfig::Vector& x)const
124         {
125                 return x-layer->origin;
126         }
127 };
128 etl::handle<Transform>
129 Translate::get_transform()const
130 {
131         return new Translate_Trans(this);
132 }
133
134 bool
135 Translate::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
136 {
137         RendDesc desc(renddesc);
138
139         desc.clear_flags();
140         desc.set_tl(desc.get_tl()-origin);
141         desc.set_br(desc.get_br()-origin);
142
143         // Render the scene
144         if(!context.accelerated_render(surface,quality,desc,cb))
145         {
146                 if(cb)cb->error(strprintf(__FILE__"%d: Accelerated Renderer Failure",__LINE__));
147                 return false;
148         }
149
150         return true;
151 }
152
153 Rect
154 Translate::get_full_bounding_rect(Context context)const
155 {
156         return context.get_full_bounding_rect() + origin;
157 }