533f939a938f7222169378f66ae889080be48f0b
[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         WaypointList waypoint_list_;
67
68 public:
69         WaypointList &waypoint_list() { return waypoint_list_; }
70
71         const WaypointList &waypoint_list()const { return waypoint_list_; }
72
73         //! Creates a new waypoint at a Time \t with a given ValueBase \value
74         //! Must be redefined in the inherited class
75         virtual WaypointList::iterator new_waypoint(Time t, ValueBase value)=0;
76         //! Creates a new waypoint at a Time \t with a given ValueNode handle \value_node
77         //! Must be redefined in the inherited class
78         virtual WaypointList::iterator new_waypoint(Time t, ValueNode::Handle value_node)=0;
79
80         //! Returns a new waypoint at a given time but it is not inserted in the Waypoint List.
81         /*! \note this does not add any waypoint to the ValueNode! */
82         Waypoint new_waypoint_at_time(const Time& t)const;
83
84         //! Adds a waypoint \x
85         //! \see : Waypoint new_waypoint_at_time(const Time& t)const;
86         WaypointList::iterator add(const Waypoint &x);
87
88         //! Removes a waypoint based on its UniqueId from the waypoint list
89         void erase(const UniqueID &x);
90
91         //! Finds Waypoint iterator and associated boolean if found. Find by UniqueID
92         findresult                      find_uid(const UniqueID &x);
93         //! Finds Waypoint iterator and associated boolean if found. Find by UniqueID
94         const_findresult        find_uid(const UniqueID &x)const;
95         //! Finds Waypoint iterator and associated boolean if found. Find by Time
96         findresult                      find_time(const Time &x);
97         //! Finds Waypoint iterator and associated boolean if found. Find by Time
98         const_findresult        find_time(const Time &x)const;
99
100         //! Finds a Waypoint by given UniqueID \x
101         WaypointList::iterator find(const UniqueID &x);
102         //! Finds a Waypoint by given UniqueID \x
103         WaypointList::const_iterator find(const UniqueID &x)const;
104         //! Finds a Waypoint by given Time \x
105         WaypointList::iterator find(const Time &x);
106         //! Finds a Waypoint by given Time \x
107         WaypointList::const_iterator find(const Time &x)const;
108
109         //! Finds next Waypoint at a given time \x starting from current waypoint
110         WaypointList::iterator find_next(const Time &x);
111         //! Finds next Waypoint at a given time \x starting from current waypoint
112         WaypointList::const_iterator find_next(const Time &x)const;
113         //! Finds previous Waypoint at a given time \x starting from current waypoint
114         WaypointList::iterator find_prev(const Time &x);
115         //! Finds previous Waypoint at a given time \x starting from current waypoint
116         WaypointList::const_iterator find_prev(const Time &x)const;
117
118         virtual ~ValueNode_Animated();
119
120         virtual String get_name()const;
121         virtual String get_local_name()const;
122
123         //! Creates a Valuenode_Animated by type
124         static Handle create(ValueBase::Type type);
125         //! Creates a Valuenode_Animated by ValueBase and Time
126         static Handle create(const ValueBase& value, const Time& time);
127         //! Creates a Valuenode_Animated by ValueNode and Time
128         static Handle create(ValueNode::Handle value_node, const Time& time);
129
130         //! Fills the \list with the waypoints between \begin and \end
131         int find(const Time& begin,const Time& end,std::vector<Waypoint*>& list);
132
133         //! Inserts time \delta from time \location to the waypoints.
134         //! used to move waypoints in the time line.
135         void insert_time(const Time& location, const Time& delta);
136
137 protected:
138         ValueNode_Animated();
139
140         void set_type(ValueBase::Type t);
141         virtual void get_times_vfunc(Node::time_set &set) const;
142 };
143
144 }; // END of namespace synfig
145
146 /* === E N D =============================================================== */
147
148 #endif