synfig-core  1.0.3
waypoint.h
Go to the documentation of this file.
1 /* === S Y N F I G ========================================================= */
23 /* ========================================================================= */
24 
25 /* === S T A R T =========================================================== */
26 
27 #ifndef __SYNFIG_WAYPOINT_H
28 #define __SYNFIG_WAYPOINT_H
29 
30 /* === H E A D E R S ======================================================= */
31 
32 #include "time.h"
33 #include "real.h"
34 #include "value.h"
35 #include "uniqueid.h"
36 #include <vector>
37 #include "guid.h"
38 #include "interpolation.h"
39 
40 /* === M A C R O S ========================================================= */
41 
42 /* === T Y P E D E F S ===================================================== */
43 
44 /* === C L A S S E S & S T R U C T S ======================================= */
45 
46 namespace synfig {
47 
48 class ValueNode;
49 class GUID;
50 
51 
60 class Waypoint : public UniqueID
61 {
62  /*
63  -- ** -- T Y P E S -----------------------------------------------------------
64  */
65 
66 public:
67 
69 
76  class Model
77  {
78  friend class Waypoint;
79 
80  int priority;
81  Interpolation before;
82  Interpolation after;
83  Real tension;
84  Real continuity;
85  Real bias;
86  Real temporal_tension;
87 
88  bool priority_flag,before_flag,after_flag,tension_flag,continuity_flag,bias_flag,temporal_tension_flag;
89 
90  public:
91  Model():
92  // we don't need to initialise these 5, but the compiler thinks they're used uninitialised if we don't
93  // and this constructor isn't called often, so it's ok
94  priority(0), before(INTERPOLATION_NIL), after(INTERPOLATION_NIL), tension(0), continuity(0), bias(0), temporal_tension(0),
95 
96  priority_flag(false),
97  before_flag(false),
98  after_flag(false),
99  tension_flag(false),
100  continuity_flag(false),
101  bias_flag(false),
102  temporal_tension_flag(false) { }
103 
105  Interpolation get_before()const { return before; }
107  void set_before(Interpolation x) { before=x; before_flag=true;}
109  Interpolation get_after()const { return after; }
111  void set_after(Interpolation x) { after=x; after_flag=true;}
113  const Real &get_tension()const { return tension; }
115  void set_tension(const Real &x) { tension=x; tension_flag=true;}
117  const Real &get_continuity()const { return continuity; }
119  void set_continuity(const Real &x) { continuity=x; continuity_flag=true;}
121  const Real &get_bias()const { return bias; }
123  void set_bias(const Real &x) { bias=x; bias_flag=true;}
125  const Real &get_temporal_tension()const { return temporal_tension; }
127  void set_temporal_tension(const Real &x) { temporal_tension=x; temporal_tension_flag=true;}
129  int get_priority()const { return priority; }
131  void set_priority(int x) { priority=x; priority_flag=true;}
132 
134  #define FLAG_MACRO(x) bool get_##x##_flag()const { return x##_flag; } void set_##x##_flag(bool y) { x##_flag=y; }
135  FLAG_MACRO(priority)
136  FLAG_MACRO(before)
137  FLAG_MACRO(after)
138  FLAG_MACRO(tension)
139  FLAG_MACRO(continuity)
140  FLAG_MACRO(bias)
141  FLAG_MACRO(temporal_tension)
142  #undef FLAG_MACRO
143 
145  void reset()
146  {
147  priority_flag=false;
148  before_flag=false;
149  after_flag=false;
150  tension_flag=false;
151  continuity_flag=false;
152  bias_flag=false;
153  temporal_tension_flag=false;
154  }
155 
159  bool is_trivial()const
160  {
161  return !(
162  priority_flag||
163  before_flag||
164  after_flag||
165  tension_flag||
166  continuity_flag||
167  bias_flag||
168  temporal_tension_flag
169  );
170  }
171  }; // END of class Model
172 
173  enum Side
174  {
176 
178  };
179 
180  /*
181  -- ** -- D A T A -------------------------------------------------------------
182  */
183 
184 private:
185 
187  int priority_;
190  etl::loose_handle<ValueNode> parent_;
192  Interpolation before, after;
194  etl::rhandle<ValueNode> value_node;
196  Time time;
197 
199  Real tension;
200  Real continuity;
201  Real bias;
202 
205  ValueBase cpoint_before,cpoint_after;
206 
208  float time_tension;
209 
210  /*
211  -- ** -- C O N S T R U C T O R S ---------------------------------------------
212  */
213 
214 public:
215 
217  Waypoint(ValueBase value, Time time);
220  Waypoint(etl::handle<ValueNode> value_node, Time time);
221 
223  Waypoint();
224 
225  /*
226  -- ** -- M E M B E R F U N C T I O N S -------------------------------------
227  */
228 
229 public:
230 
233  void apply_model(const Model &x);
234 
236  Interpolation get_before()const { return before; }
238  void set_before(Interpolation x) { before=x; }
240  Interpolation get_after()const { return after; }
242  void set_after(Interpolation x) { after=x; }
244  ValueBase get_value()const;
246  ValueBase get_value(const Time &t)const;
249  void set_value(const ValueBase &x);
251  const etl::rhandle<ValueNode> &get_value_node()const { return value_node; }
253  void set_value_node(const etl::handle<ValueNode> &x);
254 
256  const Real &get_tension()const { return tension; }
258  void set_tension(const Real &x) { tension=x; }
260  const Real &get_continuity()const { return continuity; }
262  void set_continuity(const Real &x) { continuity=x; }
264  const Real &get_bias()const { return bias; }
266  void set_bias(const Real &x) { bias=x; }
267 
269  const Time &get_time()const { return time; }
271  void set_time(const Time &x);
272 
273  int get_priority()const { return priority_; }
274  void set_priority(int x) { priority_=x; }
275 
277  const etl::loose_handle<ValueNode> &get_parent_value_node()const { return parent_; }
278 
280  void set_parent_value_node(const etl::loose_handle<ValueNode> &x);
281 
283  bool is_static()const;
284 
286  float get_temporal_tension()const { return time_tension; }
288  void set_temporal_tension(const float& x) { time_tension=x; }
289 
291  bool operator<(const Waypoint &rhs)const
292  { return time<rhs.time; }
294  bool operator<(const Time &rhs)const
295  { return time.is_less_than(rhs); }
297  bool operator>(const Time &rhs)const
298  { return time.is_more_than(rhs); }
300  bool operator==(const Time &rhs)const
301  { return time.is_equal(rhs); }
303  bool operator!=(const Time &rhs)const
304  { return !time.is_equal(rhs); }
305 
307  bool operator==(const UniqueID &rhs)const
308  { return get_uid()==rhs.get_uid(); }
310  bool operator!=(const UniqueID &rhs)const
311  { return get_uid()!=rhs.get_uid(); }
312 
313 
316  Waypoint clone(etl::loose_handle<Canvas> canvas, const GUID& deriv_guid=GUID())const;
317 
319  GUID get_guid()const;
320 }; // END of class Waypoint
321 
322 typedef std::vector< Waypoint > WaypointList;
323 
324 }; // END of namespace synfig
325 
326 /* === E N D =============================================================== */
327 
328 #endif