Author: Carlos Lopez <genet...@gmail.com>
Date:   Sat Apr  2 18:51:53 2011 +0200

Partially fix create a new widthpoint entry using the contextual menu.
TODO: when the first widthpoint is used to insert, calculate the width 
correctly.

---

 synfig-core/src/synfig/valuenode_wplist.cpp |   31 ++++++++++++--------------
 synfig-core/src/synfig/valuenode_wplist.h   |   10 +++++---
 2 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/synfig-core/src/synfig/valuenode_wplist.cpp 
b/synfig-core/src/synfig/valuenode_wplist.cpp
index 4d20194..0c044b4 100644
--- a/synfig-core/src/synfig/valuenode_wplist.cpp
+++ b/synfig-core/src/synfig/valuenode_wplist.cpp
@@ -248,29 +248,26 @@ ValueNode_WPList::create(const ValueBase &value)
 }
 
 ValueNode_WPList::ListEntry
-ValueNode_WPList::create_list_entry(Real position, Time time)
+ValueNode_WPList::create_list_entry(int index, Time time, Real /*origin*/)
 {
        ValueNode_WPList::ListEntry ret;
-       WidthPoint wpoint(position, interpolated_width(position, time));
-       // as width points are unsorted in terms of position,
-       // we always insert the width point at the begining of the list
+       synfig::WidthPoint curr, prev, inserted;
+       //ValueNode_Composite::Handle 
vnh(ValueNode_Composite::Handle::cast_dynamic(list[index].value_node));
+       curr=(*(list[index].value_node))(time).get(curr);
+       Real curr_pos(curr.get_norm_position());
+       prev=find_prev_valid_entry_by_position(curr_pos, time);
+       Real prev_pos(prev.get_norm_position());
+       inserted.set_position((prev_pos+curr_pos)/2);
+       Real prev_width(prev.get_width());
+       Real curr_width(curr.get_width());
+       inserted.set_width((prev_width+curr_width)/2);
        ret.index=0;
        ret.set_parent_value_node(this);
-       // Note: before and after interpolations are INTERPOLATE by default.
-       // not need to set it up here.
-       ret.value_node=ValueNode_Composite::create(wpoint);
+       ret.value_node=ValueNode_Composite::create(inserted);
        ret.value_node->set_parent_canvas(get_parent_canvas());
        return ret;
 }
 
-ValueNode_WPList::ListEntry
-ValueNode_WPList::create_list_entry(int /*index*/, Time /*time*/, Real 
/*origin*/)
-{
-       // Initially all the width points are created at 0.0
-       // TODO: take the decision on what to call on 
valuenodedynamiclistinsert action
-       return create_list_entry(0.0);
-}
-
 ValueBase
 ValueNode_WPList::operator()(Time t)const
 {
@@ -378,7 +375,7 @@ ValueNode_WPList::find_next_valid_entry_by_position(Real 
position, Time time)con
                curr=(*iter->value_node)(time).get(curr);
                Real curr_pos(curr.get_norm_position());
                bool status((*iter).status_at_time(time));
-               if((curr_pos >= position) && (curr_pos <= next_pos) && status)
+               if((curr_pos > position) && (curr_pos < next_pos) && status)
                {
                        next_pos=curr_pos;
                        next_ret=curr;
@@ -398,7 +395,7 @@ ValueNode_WPList::find_prev_valid_entry_by_position(Real 
position, Time time)con
                curr=(*iter->value_node)(time).get(curr);
                Real curr_pos(curr.get_norm_position());
                bool status((*iter).status_at_time(time));
-               if((curr_pos <= position) && (curr_pos >= prev_pos) && status)
+               if((curr_pos < position) && (curr_pos > prev_pos) && status)
                {
                        prev_pos=curr_pos;
                        prev_ret=curr;
diff --git a/synfig-core/src/synfig/valuenode_wplist.h 
b/synfig-core/src/synfig/valuenode_wplist.h
index fadaf66..e326796 100644
--- a/synfig-core/src/synfig/valuenode_wplist.h
+++ b/synfig-core/src/synfig/valuenode_wplist.h
@@ -78,12 +78,14 @@ public:
        virtual String link_local_name(int i)const;
        virtual String get_name()const;
        virtual String get_local_name()const;
-       //! Inserts a new entry at index with time used for
-       //! \param position the position of the width point to be inserted
+       //! Inserts a new entry between the previous found
+       //! widthpoint and the one where the action was called
+       //! with an average width and a middle position.
+       //! \param index the index of the entry wher the action is done
        //! \param time the time when inserted in animation mode
+       //! \param origin unused. Always is in the middle.
        //! \return the new List Entry
-       virtual ListEntry create_list_entry(Real position, Time time=0);
-       virtual ListEntry create_list_entry(int index, Time time=0, Real 
origin=0);
+       virtual ListEntry create_list_entry(int index, Time time=0, Real 
origin=0.5);
        //! Finds a fully on width point at given time and after the given 
position
        //! \param position the position where to start to seek from
        //! \param time the time when things are evaluated


------------------------------------------------------------------------------
Create and publish websites with WebMatrix
Use the most popular FREE web apps or write code yourself; 
WebMatrix provides all the features you need to develop and 
publish your website. http://p.sf.net/sfu/ms-webmatrix-sf
_______________________________________________
Synfig-devl mailing list
Synfig-devl@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synfig-devl

Reply via email to