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