More documentation for Value Node Animated
[synfig.git] / synfig-core / src / synfig / valuenode_animated.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_animated.h
3 **      \brief Header file for implementation of the "Animated" valuenode conversion.
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 /* ========================================================================= */
22
23 /* === S T A R T =========================================================== */
24
25 #ifndef __SYNFIG_VALUENODE_ANIMATED_H
26 #define __SYNFIG_VALUENODE_ANIMATED_H
27
28 /* === H E A D E R S ======================================================= */
29
30 #include <list>
31
32 #include "valuenode.h"
33 #include "uniqueid.h"
34 #include "waypoint.h"
35
36 /* === M A C R O S ========================================================= */
37
38 /* === C L A S S E S & S T R U C T S ======================================= */
39
40 namespace synfig {
41
42 /*! \class ValueNode_Animated
43  *  \brief Virtual class for the derived ValueNode Animated implementations.
44  *
45  * It stores the list of waypoints and defines the base methods for:
46  * add a given waypoint, return a new waypoint at a given time, some find
47  * functions to find waypoints in the list, and to create a handles to
48  * ValueNode_Animated based on the ValueBase Type of the given value node.
49  * Also defines virtual methods to add a new waypoint at a given time using
50  * a value node. They must be redefined by the inherited classes and will
51  * be different depending on the type of value being animated.
52 */
53 struct ValueNode_Animated : public ValueNode
54 {
55 public:
56         typedef etl::handle<ValueNode_Animated> Handle;
57         typedef etl::handle<const ValueNode_Animated> ConstHandle;
58
59         typedef synfig::Waypoint Waypoint;
60         typedef synfig::WaypointList WaypointList;
61
62         typedef std::pair<WaypointList::iterator,bool>  findresult;
63         typedef std::pair<WaypointList::const_iterator,bool>    const_findresult;
64
65 protected:
66         //! List of Waypoints. \see waypoint.h
67         WaypointList waypoint_list_;
68
69 public:
70         WaypointList &waypoint_list() { return waypoint_list_; }
71
72         const WaypointList &waypoint_list()const { return waypoint_list_; }
73
74         //! Creates a new waypoint at a Time \t with a given ValueBase \value
75         //! Must be redefined in the inherited class
76         virtual WaypointList::iterator new_waypoint(Time t, ValueBase value)=0;
77         //! Creates a new waypoint at a Time \t with a given ValueNode handle \value_node
78         //! Must be redefined in the inherited class
79         virtual WaypointList::iterator new_waypoint(Time t, ValueNode::Handle value_node)=0;
80
81         //! Returns a new waypoint at a given time but it is not inserted in the Waypoint List.
82         /*! \note this does not add any waypoint to the ValueNode! */
83         Waypoint new_waypoint_at_time(const Time& t)const;
84
85         //! Adds a waypoint \x
86         //! \see : Waypoint new_waypoint_at_time(const Time& t)const;
87         WaypointList::iterator add(const Waypoint &x);
88
89         //! Removes a waypoint based on its UniqueId from the waypoint list
90         void erase(const UniqueID &x);
91
92         //! Finds Waypoint iterator and associated boolean if found. Find by UniqueID
93         findresult                      find_uid(const UniqueID &x);
94         //! Finds Waypoint iterator and associated boolean if found. Find by UniqueID
95         const_findresult        find_uid(const UniqueID &x)const;
96         //! Finds Waypoint iterator and associated boolean if found. Find by Time
97         findresult                      find_time(const Time &x);
98         //! Finds Waypoint iterator and associated boolean if found. Find by Time
99         const_findresult        find_time(const Time &x)const;
100
101         //! Finds a Waypoint by given UniqueID \x
102         WaypointList::iterator find(const UniqueID &x);
103         //! Finds a Waypoint by given UniqueID \x
104         WaypointList::const_iterator find(const UniqueID &x)const;
105         //! Finds a Waypoint by given Time \x
106         WaypointList::iterator find(const Time &x);
107         //! Finds a Waypoint by given Time \x
108         WaypointList::const_iterator find(const Time &x)const;
109
110         //! Finds next Waypoint at a given time \x starting from current waypoint
111         WaypointList::iterator find_next(const Time &x);
112         //! Finds next Waypoint at a given time \x starting from current waypoint
113         WaypointList::const_iterator find_next(const Time &x)const;
114         //! Finds previous Waypoint at a given time \x starting from current waypoint
115         WaypointList::iterator find_prev(const Time &x);
116         //! Finds previous Waypoint at a given time \x starting from current waypoint
117         WaypointList::const_iterator find_prev(const Time &x)const;
118
119         virtual ~ValueNode_Animated();
120
121         //! Virtual member to be filled by inherited classes
122         virtual String get_name()const;
123         //! Virtual member to be filled by inherited classes
124         virtual String get_local_name()const;
125
126         //! Creates a Valuenode_Animated by type
127         static Handle create(ValueBase::Type type);
128         //! Creates a Valuenode_Animated by ValueBase and Time
129         static Handle create(const ValueBase& value, const Time& time);
130         //! Creates a Valuenode_Animated by ValueNode and Time
131         static Handle create(ValueNode::Handle value_node, const Time& time);
132
133         //! Fills the \list with the waypoints between \begin and \end
134         int find(const Time& begin,const Time& end,std::vector<Waypoint*>& list);
135
136         //! Inserts time \delta from time \location to the waypoints.
137         //! used to move waypoints in the time line.
138         void insert_time(const Time& location, const Time& delta);
139
140 protected:
141         ValueNode_Animated();
142
143         //! Sets thee type of the Animated Value Node
144         void set_type(ValueBase::Type t);
145         //!     Function to be overloaded that fills the Time Point Set with
146         //! all the children Time Points. Time Point is like Waypoint but
147         //! without value node
148         virtual void get_times_vfunc(Node::time_set &set) const;
149 };
150
151 }; // END of namespace synfig
152
153 /* === E N D =============================================================== */
154
155 #endif