Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_07_rc1 / src / modules / lyr_std / timeloop.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file timeloop.cpp
3 **      \brief Image Layer_TimeLoop Layer Implementation
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 **
22 ** === N O T E S ===========================================================
23 **
24 ** ========================================================================= */
25
26 /* === H E A D E R S ======================================================= */
27
28 #ifdef USING_PCH
29 #       include "pch.h"
30 #else
31 #ifdef HAVE_CONFIG_H
32 #       include <config.h>
33 #endif
34
35 #include "timeloop.h"
36 #include <synfig/time.h>
37 #include <synfig/context.h>
38 #include <synfig/paramdesc.h>
39 #include <synfig/renddesc.h>
40 #include <synfig/value.h>
41
42 #endif
43
44 using namespace synfig;
45 using namespace std;
46 using namespace etl;
47
48 /* === M A C R O S ========================================================= */
49
50 /* === G L O B A L S ======================================================= */
51
52 SYNFIG_LAYER_INIT(Layer_TimeLoop);
53 SYNFIG_LAYER_SET_NAME(Layer_TimeLoop,"timeloop");
54 SYNFIG_LAYER_SET_LOCAL_NAME(Layer_TimeLoop,_("Time Loop"));
55 SYNFIG_LAYER_SET_CATEGORY(Layer_TimeLoop,_("Other"));
56 SYNFIG_LAYER_SET_VERSION(Layer_TimeLoop,"0.1");
57 SYNFIG_LAYER_SET_CVS_ID(Layer_TimeLoop,"$Id$");
58
59 /* === P R O C E D U R E S ================================================= */
60
61 /* === M E T H O D S ======================================================= */
62
63 Layer_TimeLoop::Layer_TimeLoop()
64 {
65         start_time=0;
66         end_time=1;
67 }
68
69 Layer_TimeLoop::~Layer_TimeLoop()
70 {
71 }
72
73 bool
74 Layer_TimeLoop::set_param(const String & param, const ValueBase &value)
75 {
76         IMPORT(start_time);
77         IMPORT(end_time);
78         return Layer::set_param(param,value);
79 }
80
81 ValueBase
82 Layer_TimeLoop::get_param(const String & param)const
83 {
84         EXPORT(start_time);
85         EXPORT(end_time);
86         EXPORT_NAME();
87         EXPORT_VERSION();
88
89         return Layer::get_param(param);
90 }
91
92 Layer::Vocab
93 Layer_TimeLoop::get_param_vocab()const
94 {
95         Layer::Vocab ret(Layer::get_param_vocab());
96
97         ret.push_back(ParamDesc("start_time")
98                 .set_local_name(_("Start Time"))
99         );
100
101         ret.push_back(ParamDesc("end_time")
102                 .set_local_name(_("End Time"))
103         );
104
105         return ret;
106 }
107
108 void
109 Layer_TimeLoop::set_time(Context context, Time time)const
110 {
111         Real diff(end_time-start_time);
112         if(diff>0)
113                 time-=int(Real(time-start_time)/diff)*diff+start_time;
114         context.set_time(time);
115 }
116
117 Color
118 Layer_TimeLoop::get_color(Context context, const Point &pos)const
119 {
120         return context.get_color(pos);
121 }
122
123 bool
124 Layer_TimeLoop::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
125 {
126         return context.accelerated_render(surface,quality,renddesc,cb);
127 }