1 /* === S I N F G =========================================================== */
2 /*! \file valuenode_dynamiclist.h
3 ** \brief Template Header
5 ** $Id: valuenode_dynamiclist.h,v 1.1.1.1 2005/01/04 01:23:15 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === S T A R T =========================================================== */
24 #ifndef __SINFG_VALUENODE_DYNAMICLIST_H
25 #define __SINFG_VALUENODE_DYNAMICLIST_H
27 /* === H E A D E R S ======================================================= */
32 #include "valuenode.h"
35 #include "activepoint.h"
37 /* === M A C R O S ========================================================= */
39 /* === C L A S S E S & S T R U C T S ======================================= */
42 class ValueNode_BLine;
44 /*! \class ValueNode_DynamicList
45 ** \brief Animated List ValueNode
47 ** This ValueNode was originaly set up to have a list
48 ** of ValueNodes and their associated "on" and "off" points.
49 ** ie: Any time that was directly after an "on" point,
50 ** the item would be "on", and any time that was directly
51 ** after an "off" point would be "off". This is pretty intuitive.
52 ** However, it does have it's problems.
54 ** The problems arrise when we introduce the concept of a
55 ** Keyframe. Keyframes can be manipulated via the Sinfg
56 ** Application Library. They allow the user to quickly
57 ** and "automagickly" rearange an animation by moving
58 ** the associated keyframes. With they old way that the
59 ** "on" and "off" points were handled, this task became
60 ** overly complicated.
62 ** What is required is a "symetric" system of describing
63 ** "on" and "off" points. Instead of the point representing
64 ** the state of the item after that point in time, we have
65 ** the point represent <i>only that frame</i>. The state
66 ** of the item is calculated by looking at the points
67 ** around it: If either (or both) points are "on", then the
68 ** current state is "on". Otherwise, the point is "off"
70 ** This may be a bit confusing at first, but it is required
71 ** if we want the keyframe mechanism to "just work".
73 class ValueNode_DynamicList : public LinkableValueNode
78 ** \brief Contains a potential list item, and associated timing information
80 ** This structure contains a RHandle to a ValueNode,
81 ** as well as the associated on/off timing information
82 ** which determines when this item is included in the list.
84 ** The timing information is stored in the member <tt>timing_info</tt>.
86 struct ListEntry : public UniqueID
88 friend class ValueNode_DynamicList;
89 friend class ValueNode_BLine;
91 typedef sinfg::Activepoint Activepoint;
93 typedef std::list<Activepoint> ActivepointList;
95 typedef std::pair<ActivepointList::iterator,bool> findresult;
96 typedef std::pair<ActivepointList::const_iterator,bool> const_findresult;
100 mutable Node::time_set times;
102 ValueNode::RHandle value_node;
104 ActivepointList timing_info;
108 etl::loose_handle<ValueNode> parent_;
109 void set_parent_value_node(const etl::loose_handle<ValueNode> &x) { parent_=x; }
113 int get_index()const { return index; }
116 bool status_at_time(const Time &x)const;
118 float amount_at_time(const Time &x, bool *rising=0)const;
120 ActivepointList::iterator add(Time time, bool status, int priority=0);
121 ActivepointList::iterator add(const Activepoint &x);
123 findresult find_uid(const UniqueID& x);
124 const_findresult find_uid(const UniqueID& x)const;
126 findresult find_time(const Time& x);
127 const_findresult find_time(const Time& x)const;
129 ActivepointList::iterator find(const UniqueID& x);
130 ActivepointList::const_iterator find(const UniqueID& x)const;
131 ActivepointList::iterator find(const Time& x);
132 ActivepointList::const_iterator find(const Time& x)const;
133 ActivepointList::iterator find_prev(const Time& x);
134 ActivepointList::const_iterator find_prev(const Time& x)const;
135 ActivepointList::iterator find_next(const Time& x);
136 ActivepointList::const_iterator find_next(const Time& x)const;
138 Activepoint new_activepoint_at_time(const Time& x)const;
140 ActivepointList::iterator add(Time time)
141 { return add(time, status_at_time(time)); }
143 void erase(const UniqueID& x);
145 int find(const Time& begin,const Time& end,std::vector<Activepoint*>& list);
147 const sinfg::Node::time_set &get_times() const;
149 const etl::loose_handle<ValueNode> &get_parent_value_node()const { return parent_; }
152 ListEntry(const ValueNode::Handle &value_node);
153 ListEntry(const ValueNode::Handle &value_node,Time begin, Time end);
154 }; // END of struct ValueNode_DynamicList::ListEntry
156 typedef etl::handle<ValueNode_DynamicList> Handle;
157 typedef etl::handle<const ValueNode_DynamicList> ConstHandle;
160 ValueNode_DynamicList(ValueBase::Type container_type=ValueBase::TYPE_NIL);
162 ValueBase::Type container_type;
168 std::vector<ListEntry> list;
172 void add(const ValueNode::Handle &value_node, int index=-1);
173 void add(const ListEntry &value_node, int index=-1);
174 void erase(const ValueNode::Handle &value_node);
177 int find_next_valid_entry(int x, Time t)const;
178 int find_prev_valid_entry(int x, Time t)const;
180 virtual ValueNode::LooseHandle get_link_vfunc(int i)const;
182 virtual int link_count()const;
184 virtual String link_name(int i)const;
186 virtual ValueBase operator()(Time t)const;
188 virtual ~ValueNode_DynamicList();
190 virtual String link_local_name(int i)const;
191 virtual int get_link_index_from_name(const String &name)const;
193 virtual String get_name()const;
194 virtual String get_local_name()const;
196 bool get_loop()const { return loop_; }
197 void set_loop(bool x) { loop_=x; }
199 ValueBase::Type get_contained_type()const;
202 template <typename iterator> static Handle
203 create(iterator begin, iterator end)
205 Handle ret=create((*begin)->get_type());
206 for(;begin!=end;++begin)
207 ret->add(ListEntry(*begin));
211 void insert_time(const Time& location, const Time& delta);
212 //void manipulate_time(const Time& old_begin,const Time& old_end,const Time& new_begin,const Time& new_end);
214 virtual ValueNode* clone(const GUID& deriv_guid=GUID())const;
216 virtual ListEntry create_list_entry(int index, Time time=0, Real origin=0.5);
220 virtual bool set_link_vfunc(int i,ValueNode::Handle x);
221 LinkableValueNode* create_new()const;
223 virtual void get_times_vfunc(Node::time_set &set) const;
226 /*! \note The construction parameter (\a id) is the type that the list
227 ** contains, rather than the type that it will yield
228 ** (which is ValueBase::TYPE_LIST)
230 static Handle create(ValueBase::Type id=ValueBase::TYPE_NIL);
231 using sinfg::LinkableValueNode::get_link_vfunc;
232 using sinfg::LinkableValueNode::set_link_vfunc;
233 static bool check_type(ValueBase::Type type);
234 static ValueNode_DynamicList* create_from(const ValueBase &x=ValueBase::TYPE_GRADIENT);
235 }; // END of class ValueNode_DynamicList
237 typedef ValueNode_DynamicList::ListEntry::Activepoint Activepoint;
238 typedef ValueNode_DynamicList::ListEntry::ActivepointList ActivepointList;
240 }; // END of namespace sinfg
242 /* === E N D =============================================================== */