Author: Carlos Lopez <[email protected]>
Date:   Thu Jul 28 08:41:05 2011 +0200

New Valuenode DashItem List

---

 synfig-core/src/synfig/Makefile.am             |    2 +
 synfig-core/src/synfig/valuenode_dilist.cpp    |  196 ++++++++++++++++++++++++
 synfig-core/src/synfig/valuenode_dilist.h      |   99 ++++++++++++
 synfig-core/src/synfig/valuenode_dynamiclist.h |    1 +
 4 files changed, 298 insertions(+), 0 deletions(-)

diff --git a/synfig-core/src/synfig/Makefile.am 
b/synfig-core/src/synfig/Makefile.am
index 53d3533..0849c13 100644
--- a/synfig-core/src/synfig/Makefile.am
+++ b/synfig-core/src/synfig/Makefile.am
@@ -77,6 +77,7 @@ VALUENODEHEADERS = \
        valuenode_composite.h \
        valuenode_const.h \
        valuenode_cos.h \
+       valuenode_dilist.h \
        valuenode_dotproduct.h \
        valuenode_duplicate.h \
        valuenode_dynamiclist.h \
@@ -131,6 +132,7 @@ VALUENODESOURCES = \
        valuenode_composite.cpp \
        valuenode_const.cpp \
        valuenode_cos.cpp \
+       valuenode_dilist.cpp \
        valuenode_dotproduct.cpp \
        valuenode_duplicate.cpp \
        valuenode_dynamiclist.cpp \
diff --git a/synfig-core/src/synfig/valuenode_dilist.cpp 
b/synfig-core/src/synfig/valuenode_dilist.cpp
new file mode 100644
index 0000000..193d091
--- /dev/null
+++ b/synfig-core/src/synfig/valuenode_dilist.cpp
@@ -0,0 +1,196 @@
+/* === S Y N F I G ========================================================= */
+/*!    \file valuenode_DIList.cpp
+**     \brief Implementation of the "Dash Item List" valuenode conversion.
+**
+**     $Id$
+**
+**     \legal
+**     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**     Copyright (c) 2011 Carlos López
+**
+**     This package is free software; you can redistribute it and/or
+**     modify it under the terms of the GNU General Public License as
+**     published by the Free Software Foundation; either version 2 of
+**     the License, or (at your option) any later version.
+**
+**     This package is distributed in the hope that it will be useful,
+**     but WITHOUT ANY WARRANTY; without even the implied warranty of
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+**     General Public License for more details.
+**     \endlegal
+*/
+/* ========================================================================= */
+
+/* === H E A D E R S ======================================================= */
+
+#ifdef USING_PCH
+#      include "pch.h"
+#else
+#ifdef HAVE_CONFIG_H
+#      include <config.h>
+#endif
+
+#include "valuenode_dilist.h"
+#include "valuenode_const.h"
+#include "valuenode_composite.h"
+#include "valuenode_bline.h"
+#include "general.h"
+#include "exception.h"
+#include "dashitem.h"
+#include <vector>
+#include <list>
+
+#endif
+
+/* === U S I N G =========================================================== */
+
+using namespace std;
+using namespace etl;
+using namespace synfig;
+
+/* === M A C R O S ========================================================= */
+
+/* === G L O B A L S ======================================================= */
+
+/* === P R O C E D U R E S ================================================= */
+
+/* === M E T H O D S ======================================================= */
+
+
+ValueNode_DIList::ValueNode_DIList():
+       ValueNode_DynamicList(ValueBase::TYPE_DASHITEM)
+{
+}
+
+ValueNode_DIList::~ValueNode_DIList()
+{
+}
+
+ValueNode_DIList*
+ValueNode_DIList::create(const ValueBase &value)
+{
+       // if the parameter is not a list type, return null
+       if(value.get_type()!=ValueBase::TYPE_LIST)
+               return NULL;
+       // create an empty list
+       ValueNode_DIList* value_node(new ValueNode_DIList());
+       // If the value parameter is not empty
+       if(!value.empty())
+       {
+               switch(value.get_contained_type())
+               {
+               case ValueBase::TYPE_DASHITEM:
+               {
+                       std::vector<DashItem> 
list(value.get_list().begin(),value.get_list().end());
+                       std::vector<DashItem>::const_iterator iter;
+
+                       for(iter=list.begin();iter!=list.end();iter++)
+                       {
+                               
value_node->add(ValueNode::Handle(ValueNode_Composite::create(*iter)));
+                       }
+                       value_node->set_loop(value.get_loop());
+               }
+                       break;
+               default:
+                       // We got a list of who-knows-what. We don't have any 
idea
+                       // what to do with it.
+                       return NULL;
+                       break;
+               }
+       }
+
+       return value_node;
+}
+
+ValueNode_DIList::ListEntry
+ValueNode_DIList::create_list_entry(int index, Time time, Real /*origin*/)
+{
+       ValueNode_DIList::ListEntry ret;
+       int new_index(find_prev_valid_entry(index, time));
+       ret.index=new_index;
+       ret.set_parent_value_node(this);
+       ret.value_node=ValueNode_Composite::create(ret);
+       ret.value_node->set_parent_canvas(get_parent_canvas());
+       return ret;
+}
+
+ValueBase
+ValueNode_DIList::operator()(Time t)const
+{
+       if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
+               printf("%s:%d operator()\n", __FILE__, __LINE__);
+
+       std::vector<DashItem> ret_list;
+
+       std::vector<ListEntry>::const_iterator iter;
+       bool rising;
+
+       DashItem curr;
+
+       // go through all the list's entries
+       for(iter=list.begin();iter!=list.end();++iter)
+       {
+               // how 'on' is this widthpoint?
+               float amount(iter->amount_at_time(t,&rising));
+               assert(amount>=0.0f);
+               assert(amount<=1.0f);
+               // we store the current dash item
+               curr=(*iter->value_node)(t).get(curr);
+               // it's fully on
+               if (amount > 1.0f - 0.0000001f)
+               {
+                       // push back to the returning list
+                       ret_list.push_back(curr);
+               }
+       }
+       if(list.empty())
+               synfig::warning(string("ValueNode_DIList::operator()():")+_("No 
entries in list"));
+       else
+       if(ret_list.empty())
+               synfig::warning(string("ValueNode_DIList::operator()():")+_("No 
entries in ret_list"));
+
+       return ValueBase(ret_list,get_loop());
+}
+
+String
+ValueNode_DIList::link_local_name(int i)const
+{
+       assert(i>=0 && (unsigned)i<list.size());
+       return etl::strprintf(_("DashItem %03d"),i+1);
+}
+
+String
+ValueNode_DIList::get_name()const
+{
+       return "dilist";
+}
+
+String
+ValueNode_DIList::get_local_name()const
+{
+       return _("DIList");
+}
+
+LinkableValueNode*
+ValueNode_DIList::create_new()const
+{
+       return new ValueNode_DIList();
+}
+
+bool
+ValueNode_DIList::check_type(ValueBase::Type type)
+{
+       return type==ValueBase::TYPE_LIST;
+}
+
+ValueNode::LooseHandle
+ValueNode_DIList::get_bline()const
+{
+       return bline_;
+}
+
+void
+ValueNode_DIList::set_bline(ValueNode::Handle b)
+{
+       bline_=b;
+}
diff --git a/synfig-core/src/synfig/valuenode_dilist.h 
b/synfig-core/src/synfig/valuenode_dilist.h
new file mode 100644
index 0000000..7be4b1c
--- /dev/null
+++ b/synfig-core/src/synfig/valuenode_dilist.h
@@ -0,0 +1,99 @@
+/* === S Y N F I G ========================================================= */
+/*!    \file valuenode_bline.h
+**     \brief Header file for implementation of the "Dash Item List" valuenode
+**     conversion.
+**
+**     $Id$
+**
+**     \legal
+**     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**     Copyright (c) 2011 Carlos López
+**
+**     This package is free software; you can redistribute it and/or
+**     modify it under the terms of the GNU General Public License as
+**     published by the Free Software Foundation; either version 2 of
+**     the License, or (at your option) any later version.
+**
+**     This package is distributed in the hope that it will be useful,
+**     but WITHOUT ANY WARRANTY; without even the implied warranty of
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+**     General Public License for more details.
+**     \endlegal
+*/
+/* ========================================================================= */
+
+/* === S T A R T =========================================================== */
+
+#ifndef __SYNFIG_VALUENODE_DILIST_H
+#define __SYNFIG_VALUENODE_DILIST_H
+
+/* === H E A D E R S ======================================================= */
+
+#include <vector>
+#include <list>
+
+#include "valuenode.h"
+#include "time.h"
+#include "uniqueid.h"
+#include "dashitem.h"
+#include "valuenode_dynamiclist.h"
+
+/* === M A C R O S ========================================================= */
+
+/* === C L A S S E S & S T R U C T S ======================================= */
+
+namespace synfig {
+//! Converts a ValueNode_DIList into a DashItem list
+// TODO synfig::ValueBase convert_bline_to_DIList(const ValueBase& bline);
+
+/*! \class ValueNode_DIList
+**     \brief This class implements a list of Dash Items
+*/
+class ValueNode_DIList : public ValueNode_DynamicList
+{
+private:
+       ValueNode::RHandle bline_;
+public:
+
+       typedef etl::handle<ValueNode_DIList> Handle;
+       typedef etl::handle<const ValueNode_DIList> ConstHandle;
+       typedef etl::handle<const ValueNode_DIList> LooseHandle;
+       ValueNode_DIList();
+
+public:
+
+       virtual ValueBase operator()(Time t)const;
+       virtual ~ValueNode_DIList();
+       virtual String link_local_name(int i)const;
+       virtual String get_name()const;
+       virtual String get_local_name()const;
+       //! Inserts a new entry between the previous found
+       //! dashitem and the one where the action was called
+       //! \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(int index, Time time=0, Real 
origin=0.5);
+       //! Gets the bline RHandle
+       ValueNode::LooseHandle get_bline()const;
+       //! Sets the bline RHandle
+       void set_bline(ValueNode::Handle b);
+
+protected:
+
+       LinkableValueNode* create_new()const;
+
+public:
+
+       static bool check_type(ValueBase::Type type);
+       // Creates a Value Node Width Point List from another compatible list
+       static ValueNode_DIList* create(const ValueBase 
&x=ValueBase::TYPE_LIST);
+}; // END of class ValueNode_DIList
+
+typedef ValueNode_DIList::ListEntry::ActivepointList ActivepointList;
+
+}; // END of namespace synfig
+
+/* === E N D =============================================================== */
+
+#endif
diff --git a/synfig-core/src/synfig/valuenode_dynamiclist.h 
b/synfig-core/src/synfig/valuenode_dynamiclist.h
index 34a4e39..d789aa5 100644
--- a/synfig-core/src/synfig/valuenode_dynamiclist.h
+++ b/synfig-core/src/synfig/valuenode_dynamiclist.h
@@ -91,6 +91,7 @@ public:
                friend class ValueNode_DynamicList;
                friend class ValueNode_BLine;
                friend class ValueNode_WPList;
+               friend class ValueNode_DIList;
        public:
                typedef synfig::Activepoint Activepoint;
 


------------------------------------------------------------------------------
Got Input?   Slashdot Needs You.
Take our quick survey online.  Come on, we don't ask for help often.
Plus, you'll get a chance to win $100 to spend on ThinkGeek.
http://p.sf.net/sfu/slashdot-survey
_______________________________________________
Synfig-devl mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synfig-devl

Reply via email to