00001
00021
00022
00023
00024
00025 #ifndef __SYNFIG_VALUENODE_DYNAMICLIST_H
00026 #define __SYNFIG_VALUENODE_DYNAMICLIST_H
00027
00028
00029
00030 #include <vector>
00031 #include <list>
00032
00033 #include "valuenode.h"
00034 #include "time.h"
00035 #include "uniqueid.h"
00036 #include "activepoint.h"
00037
00038
00039
00040
00041
00042 namespace synfig {
00043 class ValueNode_BLine;
00044 class Canvas;
00045
00075 class ValueNode_DynamicList : public LinkableValueNode
00076 {
00077 public:
00078
00088 struct ListEntry : public UniqueID
00089 {
00090 friend class ValueNode_DynamicList;
00091 friend class ValueNode_BLine;
00092 public:
00093 typedef synfig::Activepoint Activepoint;
00094
00095 typedef std::list<Activepoint> ActivepointList;
00096
00097 typedef std::pair<ActivepointList::iterator,bool> findresult;
00098 typedef std::pair<ActivepointList::const_iterator,bool> const_findresult;
00099
00100
00101 private:
00102 mutable Node::time_set times;
00103 public:
00104 ValueNode::RHandle value_node;
00105
00106 ActivepointList timing_info;
00107
00108 private:
00109 int index;
00110 etl::loose_handle<ValueNode> parent_;
00111 void set_parent_value_node(const etl::loose_handle<ValueNode> &x) { parent_=x; }
00112
00113 public:
00114
00115 int get_index()const { return index; }
00116
00117
00118 bool status_at_time(const Time &x)const;
00119
00120 float amount_at_time(const Time &x, bool *rising=0)const;
00121
00122 ActivepointList::iterator add(Time time, bool status, int priority=0);
00123 ActivepointList::iterator add(const Activepoint &x);
00124
00125 findresult find_uid(const UniqueID& x);
00126 const_findresult find_uid(const UniqueID& x)const;
00127
00128 findresult find_time(const Time& x);
00129 const_findresult find_time(const Time& x)const;
00130
00131 ActivepointList::iterator find(const UniqueID& x);
00132 ActivepointList::const_iterator find(const UniqueID& x)const;
00133 ActivepointList::iterator find(const Time& x);
00134 ActivepointList::const_iterator find(const Time& x)const;
00135 ActivepointList::iterator find_prev(const Time& x);
00136 ActivepointList::const_iterator find_prev(const Time& x)const;
00137 ActivepointList::iterator find_next(const Time& x);
00138 ActivepointList::const_iterator find_next(const Time& x)const;
00139
00140 Activepoint new_activepoint_at_time(const Time& x)const;
00141
00142 ActivepointList::iterator add(Time time)
00143 { return add(time, status_at_time(time)); }
00144
00145 void erase(const UniqueID& x);
00146
00147 int find(const Time& begin,const Time& end,std::vector<Activepoint*>& list);
00148
00149 const synfig::Node::time_set &get_times() const;
00150
00151 const etl::loose_handle<ValueNode> &get_parent_value_node()const { return parent_; }
00152
00153 ListEntry();
00154 ListEntry(const ValueNode::Handle &value_node);
00155 ListEntry(const ValueNode::Handle &value_node,Time begin, Time end);
00156 };
00157
00158 typedef etl::handle<ValueNode_DynamicList> Handle;
00159 typedef etl::handle<const ValueNode_DynamicList> ConstHandle;
00160
00161 protected:
00162 ValueNode_DynamicList(ValueBase::Type container_type=ValueBase::TYPE_NIL);
00163
00164 ValueBase::Type container_type;
00165
00166 bool loop_;
00167
00168
00169 public:
00170 std::vector<ListEntry> list;
00171
00172 public:
00173
00174 void add(const ValueNode::Handle &value_node, int index=-1);
00175 void add(const ListEntry &value_node, int index=-1);
00176 void erase(const ValueNode::Handle &value_node);
00177 void reindex();
00178
00179 int find_next_valid_entry(int x, Time t)const;
00180 int find_prev_valid_entry(int x, Time t)const;
00181
00182 virtual ValueNode::LooseHandle get_link_vfunc(int i)const;
00183
00184 virtual int link_count()const;
00185
00186 virtual String link_name(int i)const;
00187
00188 virtual ValueBase operator()(Time t)const;
00189
00190 virtual ~ValueNode_DynamicList();
00191
00192 virtual String link_local_name(int i)const;
00193 virtual int get_link_index_from_name(const String &name)const;
00194
00195 virtual String get_name()const;
00196 virtual String get_local_name()const;
00197
00198 bool get_loop()const { return loop_; }
00199 void set_loop(bool x) { loop_=x; }
00200
00201 void set_member_canvas(etl::loose_handle<Canvas>);
00202
00203 ValueBase::Type get_contained_type()const;
00204
00205
00206 template <typename iterator> static Handle
00207 create(iterator begin, iterator end)
00208 {
00209 Handle ret=create((*begin)->get_type());
00210 for(;begin!=end;++begin)
00211 ret->add(ListEntry(*begin));
00212 return ret;
00213 }
00214
00215 void insert_time(const Time& location, const Time& delta);
00216
00217
00218 virtual ValueNode* clone(const GUID& deriv_guid=GUID())const;
00219
00220 virtual ListEntry create_list_entry(int index, Time time=0, Real origin=0.5);
00221
00222 protected:
00223
00224 virtual bool set_link_vfunc(int i,ValueNode::Handle x);
00225 LinkableValueNode* create_new()const;
00226
00227 virtual void get_times_vfunc(Node::time_set &set) const;
00228
00229 public:
00234 static Handle create(ValueBase::Type id=ValueBase::TYPE_NIL);
00235 using synfig::LinkableValueNode::get_link_vfunc;
00236 using synfig::LinkableValueNode::set_link_vfunc;
00237 static bool check_type(ValueBase::Type type);
00238 static ValueNode_DynamicList* create_from(const ValueBase &x=ValueBase::TYPE_GRADIENT);
00239 };
00240
00241 typedef ValueNode_DynamicList::ListEntry::Activepoint Activepoint;
00242 typedef ValueNode_DynamicList::ListEntry::ActivepointList ActivepointList;
00243
00244 };
00245
00246
00247
00248 #endif