1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_timeloop.cpp
3 ** \brief Implementation of the "Time Loop" valuenode conversion.
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 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "valuenode_timeloop.h"
34 #include "valuenode_const.h"
39 /* === U S I N G =========================================================== */
43 using namespace synfig;
45 /* === M A C R O S ========================================================= */
47 /* === G L O B A L S ======================================================= */
49 /* === P R O C E D U R E S ================================================= */
51 /* === M E T H O D S ======================================================= */
53 ValueNode_TimeLoop::ValueNode_TimeLoop(const ValueBase::Type &x):
58 ValueNode_TimeLoop::ValueNode_TimeLoop(const ValueNode::Handle &x):
59 LinkableValueNode(x->get_type())
62 set_link("link_time", ValueNode_Const::create(Time(0)));
63 set_link("local_time", ValueNode_Const::create(Time(0)));
64 set_link("duration", ValueNode_Const::create(Time(1)));
68 ValueNode_TimeLoop::create(const ValueBase &x)
70 return new ValueNode_TimeLoop(ValueNode_Const::create(x));
74 ValueNode_TimeLoop::create_new()const
76 return new ValueNode_TimeLoop(get_type());
79 ValueNode_TimeLoop::~ValueNode_TimeLoop()
85 ValueNode_TimeLoop::set_link_vfunc(int i,ValueNode::Handle x)
87 assert(i>=0 && i<link_count());
91 case 0: link_ = x; break;
92 case 1: link_time_ = x; break;
93 case 2: local_time_ = x; break;
94 case 3: duration_ = x; break;
95 default: return false;
98 signal_child_changed()(i);
99 signal_value_changed()();
103 ValueNode::LooseHandle
104 ValueNode_TimeLoop::get_link_vfunc(int i)const
106 assert(i>=0 && i<link_count());
108 if(i==0) return link_;
109 if(i==1) return link_time_;
110 if(i==2) return local_time_;
111 if(i==3) return duration_;
117 ValueNode_TimeLoop::link_count()const
123 ValueNode_TimeLoop::link_local_name(int i)const
125 assert(i>=0 && i<link_count());
127 if(i==0) return _("Link");
128 if(i==1) return _("Link Time");
129 if(i==2) return _("Local Time");
130 if(i==3) return _("Duration");
135 ValueNode_TimeLoop::link_name(int i)const
137 assert(i>=0 && i<link_count());
139 if(i==0) return "link";
140 if(i==1) return "link_time";
141 if(i==2) return "local_time";
142 if(i==3) return "duration";
147 ValueNode_TimeLoop::get_link_index_from_name(const String &name)const
149 if(name=="link") return 0;
150 if(name=="link_time") return 1;
151 if(name=="local_time") return 2;
152 if(name=="duration") return 3;
154 throw Exception::BadLinkName(name);
158 ValueNode_TimeLoop::operator()(Time t)const
160 Time link_time = (*link_time_) (t).get(Time());
161 Time local_time = (*local_time_)(t).get(Time());
162 Time duration = (*duration_) (t).get(Time());
166 else if (duration > 0)
169 t -= floor(t / duration) * duration;
174 duration = -duration;
176 t -= floor(t / duration) * duration;
184 ValueNode_TimeLoop::get_name()const
190 ValueNode_TimeLoop::get_local_name()const
192 return _("Time Loop");
196 ValueNode_TimeLoop::check_type(ValueBase::Type type)