Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_03 / synfig-core / src / modules / lyr_std / timeloop.cpp
1 /*! ========================================================================
2 ** Synfig
3 ** Image Layer_TimeLoop Layer Implementation
4 ** $Id: timeloop.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $
5 **
6 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
7 **
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.
12 **
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.
17 **
18 ** === N O T E S ===========================================================
19 **
20 ** ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "timeloop.h"
32 #include <synfig/time.h>
33 #include <synfig/context.h>
34 #include <synfig/paramdesc.h>
35 #include <synfig/renddesc.h>
36 #include <synfig/value.h>
37
38 #endif
39
40 using namespace synfig;
41 using namespace std;
42 using namespace etl;
43
44 /* === M A C R O S ========================================================= */
45
46 /* === G L O B A L S ======================================================= */
47
48 SYNFIG_LAYER_INIT(Layer_TimeLoop);
49 SYNFIG_LAYER_SET_NAME(Layer_TimeLoop,"timeloop");
50 SYNFIG_LAYER_SET_LOCAL_NAME(Layer_TimeLoop,_("TimeLoop"));
51 SYNFIG_LAYER_SET_CATEGORY(Layer_TimeLoop,_("Other"));
52 SYNFIG_LAYER_SET_VERSION(Layer_TimeLoop,"0.1");
53 SYNFIG_LAYER_SET_CVS_ID(Layer_TimeLoop,"$Id: timeloop.cpp,v 1.1.1.1 2005/01/04 01:23:10 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 Layer_TimeLoop::Layer_TimeLoop()
60 {
61         start_time=0;
62         end_time=1;
63 }
64
65 Layer_TimeLoop::~Layer_TimeLoop()
66 {
67 }
68
69 bool
70 Layer_TimeLoop::set_param(const String & param, const ValueBase &value)
71 {
72         IMPORT(start_time);
73         IMPORT(end_time);
74         return Layer::set_param(param,value);
75 }
76
77 ValueBase
78 Layer_TimeLoop::get_param(const String & param)const
79 {
80         EXPORT(start_time);
81         EXPORT(end_time);
82         EXPORT_NAME();
83         EXPORT_VERSION();
84
85         return Layer::get_param(param);
86 }
87
88 Layer::Vocab
89 Layer_TimeLoop::get_param_vocab()const
90 {
91         Layer::Vocab ret(Layer::get_param_vocab());
92         
93         ret.push_back(ParamDesc("start_time")
94                 .set_local_name(_("Start Time"))
95         );
96
97         ret.push_back(ParamDesc("end_time")
98                 .set_local_name(_("End Time"))
99         );
100         
101         return ret;
102 }
103
104 void
105 Layer_TimeLoop::set_time(Context context, Time time)const
106 {
107         Real diff(end_time-start_time);
108         if(diff>0)
109                 time-=int(Real(time-start_time)/diff)*diff+start_time;
110         context.set_time(time);
111 }
112
113 Color
114 Layer_TimeLoop::get_color(Context context, const Point &pos)const
115 {
116         return context.get_color(pos);
117 }
118
119 bool
120 Layer_TimeLoop::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
121 {
122         return context.accelerated_render(surface,quality,renddesc,cb);
123 }