1 /* === S Y N F I G ========================================================= */
3 ** \brief Implementation of the "Time Loop" layer
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 Chris Moore
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.
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.
22 ** === N O T E S ===========================================================
24 ** ========================================================================= */
26 /* === H E A D E R S ======================================================= */
36 #include <synfig/valuenode.h>
37 #include <synfig/valuenode_const.h>
38 #include <synfig/valuenode_subtract.h>
39 #include <synfig/time.h>
40 #include <synfig/context.h>
41 #include <synfig/paramdesc.h>
42 #include <synfig/renddesc.h>
43 #include <synfig/value.h>
47 using namespace synfig;
51 /* === M A C R O S ========================================================= */
53 /* === G L O B A L S ======================================================= */
55 SYNFIG_LAYER_INIT(Layer_TimeLoop);
56 SYNFIG_LAYER_SET_NAME(Layer_TimeLoop,"timeloop");
57 SYNFIG_LAYER_SET_LOCAL_NAME(Layer_TimeLoop,N_("Time Loop"));
58 SYNFIG_LAYER_SET_CATEGORY(Layer_TimeLoop,N_("Other"));
59 SYNFIG_LAYER_SET_VERSION(Layer_TimeLoop,"0.2");
60 SYNFIG_LAYER_SET_CVS_ID(Layer_TimeLoop,"$Id$");
62 /* === P R O C E D U R E S ================================================= */
64 /* === M E T H O D S ======================================================= */
66 Layer_TimeLoop::Layer_TimeLoop()
74 Layer_TimeLoop::~Layer_TimeLoop()
79 Layer_TimeLoop::set_param(const String & param, const ValueBase &value)
93 return Layer::set_param(param,value);
97 Layer_TimeLoop::get_param(const String & param)const
105 return Layer::get_param(param);
109 Layer_TimeLoop::get_param_vocab()const
111 Layer::Vocab ret(Layer::get_param_vocab());
113 ret.push_back(ParamDesc("link_time")
114 .set_local_name(_("Link Time"))
117 ret.push_back(ParamDesc("local_time")
118 .set_local_name(_("Local Time"))
121 ret.push_back(ParamDesc("duration")
122 .set_local_name(_("Duration"))
129 Layer_TimeLoop::set_version(const String &ver)
138 Layer_TimeLoop::reset_version()
140 // if we're not converting from an old version of the layer, there's nothing to do
146 // these are the conversions to go from 0.1 to 0.2:
148 // local_time = start_time
149 // duration = end_time - start_time
150 // if (time < start_time)
151 // link_time = -duration : if we want to reproduce the old behaviour - do we?
155 // convert the static parameters
156 local_time = start_time;
157 duration = end_time - start_time;
158 //! \todo layer version 0.1 acted differently before start_time was reached - possibly due to a bug
161 // convert the dynamic parameters
162 const DynamicParamList &dpl = dynamic_param_list();
164 // if neither start_time nor end_time are dynamic, there's nothing more to do
165 if (dpl.count("start_time") == 0 && dpl.count("end_time") == 0)
168 etl::rhandle<ValueNode> start_time_value_node, end_time_value_node;
169 LinkableValueNode* duration_value_node;
171 if (dpl.count("start_time"))
173 start_time_value_node = dpl.find("start_time")->second;
174 disconnect_dynamic_param("start_time");
177 start_time_value_node = ValueNode_Const::create(start_time);
179 if (dpl.count("end_time"))
181 end_time_value_node = dpl.find("end_time")->second;
182 disconnect_dynamic_param("end_time");
185 end_time_value_node = ValueNode_Const::create(end_time);
187 duration_value_node = ValueNode_Subtract::create(Time(0));
188 duration_value_node->set_link("lhs", end_time_value_node);
189 duration_value_node->set_link("rhs", start_time_value_node);
191 connect_dynamic_param("local_time", start_time_value_node);
192 connect_dynamic_param("duration", duration_value_node);
193 connect_dynamic_param("link_time", ValueNode_Const::create(Time(0)));
197 Layer_TimeLoop::set_time(Context context, Time t)const
201 else if (duration > 0)
204 t -= floor(t / duration) * duration;
210 t -= floor(t / -duration) * -duration;
218 Layer_TimeLoop::get_color(Context context, const Point &pos)const
220 return context.get_color(pos);
224 Layer_TimeLoop::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
226 return context.accelerated_render(surface,quality,renddesc,cb);