Made a start at implementing the ideas in http://synfig.org/Linking_to_Blines . ...
authordooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Thu, 6 Mar 2008 21:28:25 +0000 (21:28 +0000)
committerdooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Thu, 6 Mar 2008 21:28:25 +0000 (21:28 +0000)
git-svn-id: http://svn.voria.com/code@1871 1f10aa63-cdf2-0310-b900-c93c546f37ac

synfig-studio/trunk/src/gtkmm/canvasview.cpp
synfig-studio/trunk/src/gtkmm/canvasview.h
synfig-studio/trunk/src/gtkmm/duckmatic.cpp
synfig-studio/trunk/src/gtkmm/instance.cpp
synfig-studio/trunk/src/gtkmm/instance.h
synfig-studio/trunk/src/synfigapp/Makefile.am
synfig-studio/trunk/src/synfigapp/action.cpp
synfig-studio/trunk/src/synfigapp/action.h
synfig-studio/trunk/src/synfigapp/actions/valuedescblinelink.cpp [new file with mode: 0644]
synfig-studio/trunk/src/synfigapp/actions/valuedescblinelink.h [new file with mode: 0644]

index 84b0f45..6a8a44e 100644 (file)
@@ -2159,10 +2159,10 @@ CanvasView::on_layer_toggle(synfig::Layer::Handle layer)
 }
 
 void
-CanvasView::popup_param_menu(synfigapp::ValueDesc value_desc, float location)
+CanvasView::popup_param_menu(synfigapp::ValueDesc value_desc, float location, bool bezier)
 {
        parammenu.items().clear();
-       get_instance()->make_param_menu(&parammenu,get_canvas(),value_desc,location);
+       get_instance()->make_param_menu(&parammenu,get_canvas(),value_desc,location,bezier);
 
        parammenu.popup(3,gtk_get_current_event_time());
 }
index 6afc299..1fe43c6 100644 (file)
@@ -401,9 +401,9 @@ private:
        Gtk::Widget *create_time_bar();
 
        void popup_param_menu_bezier(float location, synfigapp::ValueDesc value_desc)
-       { popup_param_menu(value_desc,location); }
+       { popup_param_menu(value_desc,location,true); }
 
-       void popup_param_menu(synfigapp::ValueDesc value_desc, float location=0);
+       void popup_param_menu(synfigapp::ValueDesc value_desc, float location=0, bool bezier=false);
 
        void workarea_layer_selected(synfig::Layer::Handle layer);
 
index ccedcae..b89ff83 100644 (file)
@@ -1064,9 +1064,11 @@ Duckmatic::add_to_ducks(const synfigapp::ValueDesc& value_desc,etl::handle<Canva
                        duck->signal_user_click(2).connect(
                                sigc::bind(
                                        sigc::bind(
-                                               sigc::mem_fun(
-                                                       *canvas_view,
-                                                       &studio::CanvasView::popup_param_menu),
+                                               sigc::bind(
+                                                       sigc::mem_fun(
+                                                               *canvas_view,
+                                                               &studio::CanvasView::popup_param_menu),
+                                                       false),
                                                0.0f),
                                        value_desc));
 
@@ -1134,9 +1136,11 @@ Duckmatic::add_to_ducks(const synfigapp::ValueDesc& value_desc,etl::handle<Canva
                        duck->signal_user_click(2).connect(
                                sigc::bind(
                                        sigc::bind(
-                                               sigc::mem_fun(
-                                                       *canvas_view,
-                                                       &studio::CanvasView::popup_param_menu),
+                                               sigc::bind(
+                                                       sigc::mem_fun(
+                                                               *canvas_view,
+                                                               &studio::CanvasView::popup_param_menu),
+                                                       false),
                                                0.0f),
                                        value_desc));
                        duck->set_guid(calc_duck_guid(value_desc,transform_stack)^synfig::GUID::hasher(multiple));
@@ -1225,9 +1229,11 @@ Duckmatic::add_to_ducks(const synfigapp::ValueDesc& value_desc,etl::handle<Canva
                        duck->signal_user_click(2).connect(
                                sigc::bind(
                                        sigc::bind(
-                                               sigc::mem_fun(
-                                                       *canvas_view,
-                                                       &studio::CanvasView::popup_param_menu),
+                                               sigc::bind(
+                                                       sigc::mem_fun(
+                                                               *canvas_view,
+                                                               &studio::CanvasView::popup_param_menu),
+                                                       false),
                                                1.0f),
                                        value_desc));
                        duck->set_guid(calc_duck_guid(value_desc,transform_stack)^synfig::GUID::hasher(multiple));
@@ -1423,9 +1429,11 @@ Duckmatic::add_to_ducks(const synfigapp::ValueDesc& value_desc,etl::handle<Canva
                                                duck->signal_user_click(2).connect(
                                                        sigc::bind(
                                                                sigc::bind(
-                                                                       sigc::mem_fun(
-                                                                               *canvas_view,
-                                                                               &studio::CanvasView::popup_param_menu),
+                                                                       sigc::bind(
+                                                                               sigc::mem_fun(
+                                                                                       *canvas_view,
+                                                                                       &studio::CanvasView::popup_param_menu),
+                                                                               false),
                                                                        1.0f),
                                                                synfigapp::ValueDesc(value_node,i)));
                                                duck->set_value_desc(synfigapp::ValueDesc(value_node,i));
@@ -1551,9 +1559,11 @@ Duckmatic::add_to_ducks(const synfigapp::ValueDesc& value_desc,etl::handle<Canva
                                        duck->signal_user_click(2).connect(
                                                sigc::bind(
                                                        sigc::bind(
-                                                               sigc::mem_fun(
-                                                                       *canvas_view,
-                                                                       &studio::CanvasView::popup_param_menu),
+                                                               sigc::bind(
+                                                                       sigc::mem_fun(
+                                                                               *canvas_view,
+                                                                               &studio::CanvasView::popup_param_menu),
+                                                                       false),
                                                                1.0f),
                                                        synfigapp::ValueDesc(value_node,i)));
                                        duck->set_value_desc(synfigapp::ValueDesc(value_node,i));
@@ -1606,9 +1616,11 @@ Duckmatic::add_to_ducks(const synfigapp::ValueDesc& value_desc,etl::handle<Canva
                                        duck->signal_user_click(2).connect(
                                                sigc::bind(
                                                        sigc::bind(
-                                                               sigc::mem_fun(
-                                                                       *canvas_view,
-                                                                       &studio::CanvasView::popup_param_menu),
+                                                               sigc::bind(
+                                                                       sigc::mem_fun(
+                                                                               *canvas_view,
+                                                                               &studio::CanvasView::popup_param_menu),
+                                                                       false),
                                                                1.0f),
                                                        synfigapp::ValueDesc(value_node,i)));
                                        duck->set_value_desc(synfigapp::ValueDesc(value_node,i));
@@ -1672,9 +1684,11 @@ Duckmatic::add_to_ducks(const synfigapp::ValueDesc& value_desc,etl::handle<Canva
                                duck->signal_user_click(2).connect(
                                        sigc::bind(
                                                sigc::bind(
-                                                       sigc::mem_fun(
-                                                               *canvas_view,
-                                                               &studio::CanvasView::popup_param_menu),
+                                                       sigc::bind(
+                                                               sigc::mem_fun(
+                                                                       *canvas_view,
+                                                                       &studio::CanvasView::popup_param_menu),
+                                                               false),
                                                        1.0f),
                                                synfigapp::ValueDesc(value_node,first)));
                                duck->set_value_desc(synfigapp::ValueDesc(value_node,first));
index 7cfba5c..65c63d8 100644 (file)
@@ -53,6 +53,7 @@
 #include "widget_waypointmodel.h"
 #include <gtkmm/actiongroup.h>
 #include "iconcontroller.h"
+#include "workarea.h"
 #include <sys/stat.h>
 #include <errno.h>
 #include <ETL/stringf>
@@ -1002,7 +1003,7 @@ Instance::process_action(synfig::String name, synfigapp::Action::ParamList param
 }
 
 void
-Instance::make_param_menu(Gtk::Menu *menu,synfig::Canvas::Handle canvas, synfigapp::ValueDesc value_desc, float location)
+Instance::make_param_menu(Gtk::Menu *menu,synfig::Canvas::Handle canvas, synfigapp::ValueDesc value_desc, float location, bool bezier)
 {
        Gtk::Menu& parammenu(*menu);
 
@@ -1065,10 +1066,24 @@ Instance::make_param_menu(Gtk::Menu *menu,synfig::Canvas::Handle canvas, synfiga
                parammenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::Stock::CONVERT,*convert_menu));
        }
 
+       synfigapp::Action::Category categories = synfigapp::Action::CATEGORY_VALUEDESC|synfigapp::Action::CATEGORY_VALUENODE;
+       if (bezier)
+       {
+               categories = categories|synfigapp::Action::CATEGORY_BEZIER;
+
+               const DuckList selected_ducks(find_canvas_view(canvas)->get_work_area()->get_selected_ducks());
+               for(DuckList::const_iterator iter=selected_ducks.begin();iter!=selected_ducks.end();++iter)
+               {
+                       synfigapp::ValueDesc value_desc((*iter)->get_value_desc());
+                       if(value_desc.is_valid())
+                               param_list.add("selected_value_desc",value_desc);
+               }
+       }
+
        if(param_list2.empty())
-               add_actions_to_menu(&parammenu, param_list,synfigapp::Action::CATEGORY_VALUEDESC|synfigapp::Action::CATEGORY_VALUENODE);
+               add_actions_to_menu(&parammenu, param_list,categories);
        else
-               add_actions_to_menu(&parammenu, param_list2,param_list,synfigapp::Action::CATEGORY_VALUEDESC|synfigapp::Action::CATEGORY_VALUENODE);
+               add_actions_to_menu(&parammenu, param_list2,param_list,categories);
 
        if(value_desc.get_value_type()==ValueBase::TYPE_BLINEPOINT && value_desc.is_value_node() && ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node()))
        {
index 06a0fa4..16842c1 100644 (file)
@@ -216,7 +216,7 @@ public:
 
        void process_action(synfig::String name, synfigapp::Action::ParamList param_list);
 
-       void make_param_menu(Gtk::Menu *menu,synfig::Canvas::Handle canvas, synfigapp::ValueDesc value_desc, float location=0.5f);
+       void make_param_menu(Gtk::Menu *menu,synfig::Canvas::Handle canvas, synfigapp::ValueDesc value_desc, float location=0.5f, bool bezier=false);
 
        void make_param_menu(Gtk::Menu *menu,synfig::Canvas::Handle canvas,const std::list<synfigapp::ValueDesc>& value_desc_list);
 
index 226874a..c1dd93c 100644 (file)
@@ -14,10 +14,10 @@ LAYER_ACTION_CC = \
 
 VALUEDESC_ACTION_HH = \
        actions/valuedescconnect.h   actions/valuedescconvert.h   actions/valuedescdisconnect.h                         \
-       actions/valuedescexport.h   actions/valuedesclink.h   actions/valuedescset.h
+       actions/valuedescexport.h   actions/valuedesclink.h   actions/valuedescblinelink.h   actions/valuedescset.h
 VALUEDESC_ACTION_CC = \
        actions/valuedescconnect.cpp actions/valuedescconvert.cpp actions/valuedescdisconnect.cpp                       \
-       actions/valuedescexport.cpp actions/valuedesclink.cpp actions/valuedescset.cpp
+       actions/valuedescexport.cpp actions/valuedesclink.cpp actions/valuedescblinelink.cpp actions/valuedescset.cpp
 
 VALUENODE_ACTION_HH = \
        actions/valuenodeadd.h   actions/valuenodeconstset.h   actions/valuenodedynamiclistinsert.h                     \
index 05c5be8..5193f7b 100644 (file)
 #include "actions/valuedescconnect.h"
 #include "actions/valuedescdisconnect.h"
 #include "actions/valuedesclink.h"
+#include "actions/valuedescblinelink.h"
 
 #include "actions/waypointadd.h"
 #include "actions/waypointset.h"
 #include "actions/waypointsetsmart.h"
 #include "actions/waypointremove.h"
+// #include "actions/waypointsimpleadd.h"
 
 #include "actions/activepointadd.h"
 #include "actions/activepointset.h"
@@ -80,6 +82,7 @@
 #include "actions/activepointsetoff.h"
 #include "actions/activepointseton.h"
 #include "actions/activepointremove.h"
+// #include "actions/activepointsimpleadd.h"
 
 #include "actions/keyframeadd.h"
 #include "actions/keyframeset.h"
@@ -180,11 +183,13 @@ Action::Main::Main()
        ADD_ACTION(Action::ValueDescConnect);
        ADD_ACTION(Action::ValueDescDisconnect);
        ADD_ACTION(Action::ValueDescLink);
+       ADD_ACTION(Action::ValueDescBLineLink);
 
        ADD_ACTION(Action::WaypointAdd);
        ADD_ACTION(Action::WaypointSet);
        ADD_ACTION(Action::WaypointSetSmart);
        ADD_ACTION(Action::WaypointRemove);
+//     ADD_ACTION(Action::WaypointSimpleAdd);
 
        ADD_ACTION(Action::ActivepointAdd);
        ADD_ACTION(Action::ActivepointSet);
@@ -192,6 +197,7 @@ Action::Main::Main()
        ADD_ACTION(Action::ActivepointSetOn);
        ADD_ACTION(Action::ActivepointSetOff);
        ADD_ACTION(Action::ActivepointRemove);
+//     ADD_ACTION(Action::ActivepointSimpleAdd);
 
        ADD_ACTION(Action::KeyframeAdd);
        ADD_ACTION(Action::KeyframeSet);
index 0bd843b..661c5e3 100644 (file)
@@ -168,6 +168,7 @@ enum Category
        CATEGORY_VALUENODE              =(1<<5),
        CATEGORY_KEYFRAME               =(1<<6),
        CATEGORY_GROUP                  =(1<<7),
+       CATEGORY_BEZIER                 =(1<<8),
 
        CATEGORY_OTHER                  =(1<<12),
 
diff --git a/synfig-studio/trunk/src/synfigapp/actions/valuedescblinelink.cpp b/synfig-studio/trunk/src/synfigapp/actions/valuedescblinelink.cpp
new file mode 100644 (file)
index 0000000..14e5654
--- /dev/null
@@ -0,0 +1,200 @@
+/* === S Y N F I G ========================================================= */
+/*!    \file valuedescblinelink.cpp
+**     \brief Template File
+**
+**     $Id$
+**
+**     \legal
+**     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**     Copyright (c) 2007, 2008 Chris Moore
+**
+**     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 "valuenodelinkconnect.h"
+#include "valuedescblinelink.h"
+
+#include <synfigapp/canvasinterface.h>
+#include <synfig/valuenode_const.h>
+#include <synfig/valuenode_composite.h>
+#include <synfig/valuenode_blinecalcvertex.h>
+
+#include <synfigapp/general.h>
+
+#endif
+
+using namespace std;
+using namespace etl;
+using namespace synfig;
+using namespace synfigapp;
+using namespace Action;
+
+/* === M A C R O S ========================================================= */
+
+ACTION_INIT(Action::ValueDescBLineLink);
+ACTION_SET_NAME(Action::ValueDescBLineLink,"value_desc_bline_link");
+ACTION_SET_LOCAL_NAME(Action::ValueDescBLineLink,N_("Link to BLine"));
+ACTION_SET_TASK(Action::ValueDescBLineLink,"connect");
+ACTION_SET_CATEGORY(Action::ValueDescBLineLink,Action::CATEGORY_BEZIER);
+ACTION_SET_PRIORITY(Action::ValueDescBLineLink,0);
+ACTION_SET_VERSION(Action::ValueDescBLineLink,"0.0");
+ACTION_SET_CVS_ID(Action::ValueDescBLineLink,"$Id$");
+
+/* === G L O B A L S ======================================================= */
+
+/* === P R O C E D U R E S ================================================= */
+
+/* === M E T H O D S ======================================================= */
+
+Action::ValueDescBLineLink::ValueDescBLineLink()
+{
+}
+
+Action::ParamVocab
+Action::ValueDescBLineLink::get_param_vocab()
+{
+       ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
+
+       ret.push_back(ParamDesc("selected_value_desc",Param::TYPE_VALUEDESC)
+               .set_local_name(_("ValueDesc to link"))
+               .set_supports_multiple()
+       );
+       ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
+               .set_local_name(_("ValueDesc on BLine to link to"))
+       );
+       ret.push_back(ParamDesc("time",Param::TYPE_TIME)
+               .set_local_name(_("Time"))
+               .set_optional()
+       );
+       ret.push_back(ParamDesc("origin",Param::TYPE_REAL)
+               .set_local_name(_("Origin"))
+               .set_optional()
+       );
+
+       return ret;
+}
+
+bool
+Action::ValueDescBLineLink::is_candidate(const ParamList &x)
+{
+       ParamList::const_iterator i;
+
+       ValueDesc value_desc(x.find("value_desc")->second.get_value_desc());
+
+       if (!candidate_check(get_param_vocab(),x))
+               return false;
+
+       return (value_desc.parent_is_value_node() &&
+                       // We need a dynamic list.
+                       ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()));
+}
+
+bool
+Action::ValueDescBLineLink::set_param(const synfig::String& name, const Action::Param &param)
+{
+       if(name=="time" && param.get_type()==Param::TYPE_TIME)
+       {
+               time=param.get_time();
+               return true;
+       }
+
+       if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
+       {
+               value_desc = param.get_value_desc();
+               index=value_desc.get_index();
+               return true;
+       }
+
+       if(name=="selected_value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
+       {
+               ValueDesc value_desc(param.get_value_desc());
+               value_desc_list.push_back(value_desc);
+               return true;
+       }
+
+       if(name=="origin" && param.get_type()==Param::TYPE_REAL)
+       {
+               origin=param.get_real();
+               return true;
+       }
+
+       return Action::CanvasSpecific::set_param(name,param);
+}
+
+bool
+Action::ValueDescBLineLink::is_ready()const
+{
+       if(value_desc_list.size()<1)
+               return false;
+       if(!value_desc)
+               return false;
+       return Action::CanvasSpecific::is_ready();
+}
+
+void
+Action::ValueDescBLineLink::prepare()
+{
+       if(value_desc_list.empty())
+               throw Error(Error::TYPE_NOTREADY);
+
+       clear();
+
+       ValueNode_DynamicList::Handle bline_value_node(ValueNode_DynamicList::Handle::cast_dynamic(value_desc.get_parent_value_node()));
+       bool loop(bline_value_node->get_loop());
+       int loop_adjust(loop ? 0 : -1);
+       const std::vector<ValueBase> bline((*bline_value_node)(time));
+       int size = bline.size();
+       Real amount = (index + origin + loop_adjust) / (size + loop_adjust);
+
+       std::list<ValueDesc>::iterator iter;
+       for(iter=value_desc_list.begin();iter!=value_desc_list.end();++iter)
+       {
+               ValueDesc& value_desc(*iter);
+               if (value_desc.parent_is_value_node())
+               {
+                       ValueNode::Handle value_node(value_desc.get_value_node());
+                       if (value_desc.get_value_type()==ValueBase::TYPE_BLINEPOINT &&
+                               value_desc.is_value_node() &&
+                               ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node()))
+                       {
+                               LinkableValueNode::Handle bline_vertex(ValueNode_BLineCalcVertex::create(ValueBase::TYPE_VECTOR));
+                               bline_vertex->set_link("bline", bline_value_node);
+                               bline_vertex->set_link("loop", ValueNode_Const::create(loop));
+                               bline_vertex->set_link("amount", ValueNode_Const::create(amount));
+
+                               Action::Handle action(ValueNodeLinkConnect::create());
+
+                               action->set_param("canvas",get_canvas());
+                               action->set_param("canvas_interface",get_canvas_interface());
+                               action->set_param("parent_value_node",value_node);
+                               action->set_param("value_node",ValueNode::Handle(bline_vertex));
+                               action->set_param("index",0); // index for 'vertex' in 'composite'
+
+                               assert(action->is_ready());
+                               if(!action->is_ready())
+                                       throw Error(Error::TYPE_NOTREADY);
+
+                               add_action_front(action);
+                       }
+               }
+       }
+}
diff --git a/synfig-studio/trunk/src/synfigapp/actions/valuedescblinelink.h b/synfig-studio/trunk/src/synfigapp/actions/valuedescblinelink.h
new file mode 100644 (file)
index 0000000..7b726cf
--- /dev/null
@@ -0,0 +1,77 @@
+/* === S Y N F I G ========================================================= */
+/*!    \file valuedescblinelink.h
+**     \brief Template File
+**
+**     $Id$
+**
+**     \legal
+**     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**     Copyright (c) 2007 Chris Moore
+**
+**     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_APP_ACTION_VALUEDESCBLINELINK_H
+#define __SYNFIG_APP_ACTION_VALUEDESCBLINELINK_H
+
+/* === H E A D E R S ======================================================= */
+
+#include <synfigapp/action.h>
+#include <synfigapp/value_desc.h>
+#include <synfig/valuenode_dynamiclist.h>
+#include <list>
+
+/* === M A C R O S ========================================================= */
+
+/* === T Y P E D E F S ===================================================== */
+
+/* === C L A S S E S & S T R U C T S ======================================= */
+
+namespace synfigapp {
+
+namespace Action {
+
+class ValueDescBLineLink :
+       public Super
+{
+private:
+
+       ValueDesc value_desc;
+       std::list<ValueDesc> value_desc_list;
+       synfig::ValueNode::Handle link_value_node;
+       synfig::Time time;
+       synfig::Real origin;
+       int index;
+public:
+
+       ValueDescBLineLink();
+
+       static ParamVocab get_param_vocab();
+       static bool is_candidate(const ParamList &x);
+
+       virtual bool set_param(const synfig::String& name, const Param &);
+       virtual bool is_ready()const;
+
+       virtual void prepare();
+
+       ACTION_MODULE_EXT
+};
+
+}; // END of namespace action
+}; // END of namespace studio
+
+/* === E N D =============================================================== */
+
+#endif