From fb5a72174252e0e79107dcad3bf5a2bbd73e349c Mon Sep 17 00:00:00 2001 From: johanengelen Date: Sun, 28 Oct 2007 16:03:07 +0000 Subject: [PATCH] LPE: implement 'edit next LPE parameter'. Accessible through key '7'. --- share/keys/default.xml | 4 ++- share/keys/inkscape.xml | 2 ++ src/live_effects/effect.cpp | 41 ++++++++++++++++++++++++ src/live_effects/effect.h | 8 ++++- src/live_effects/parameter/parameter.cpp | 1 + src/live_effects/parameter/parameter.h | 7 ++++ src/live_effects/parameter/path.cpp | 36 ++++++++++++++------- src/live_effects/parameter/path.h | 2 ++ src/selection-chemistry.cpp | 18 +++++++++++ src/selection-chemistry.h | 2 ++ src/sp-shape.cpp | 8 +++++ src/sp-shape.h | 3 ++ src/verbs.cpp | 11 +------ 13 files changed, 119 insertions(+), 24 deletions(-) diff --git a/share/keys/default.xml b/share/keys/default.xml index d77cdaa25..cb8044a0a 100644 --- a/share/keys/default.xml +++ b/share/keys/default.xml @@ -320,7 +320,9 @@ override) the bindings in the main default.xml. - + + + diff --git a/share/keys/inkscape.xml b/share/keys/inkscape.xml index d77cdaa25..d478010a3 100644 --- a/share/keys/inkscape.xml +++ b/share/keys/inkscape.xml @@ -320,6 +320,8 @@ override) the bindings in the main default.xml. + + diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index cfabc88b4..3802066ec 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -90,6 +90,7 @@ Effect::Effect(LivePathEffectObject *lpeobject) vbox = NULL; tooltips = NULL; lpeobj = lpeobject; + oncanvasedit_it = param_map.begin(); } Effect::~Effect() @@ -261,6 +262,46 @@ Effect::getSPDoc() return SP_OBJECT_DOCUMENT(lpeobj); } +Parameter * +Effect::getNextOncanvasEditableParam() +{ + oncanvasedit_it++; + if (oncanvasedit_it == param_map.end()) { + oncanvasedit_it = param_map.begin(); + } + param_map_type::iterator old_it = oncanvasedit_it; + + do { + Parameter * param = oncanvasedit_it->second; + if(param->oncanvas_editable) { + return param; + } else { + oncanvasedit_it++; + if (oncanvasedit_it == param_map.end()) { // loop round the map + oncanvasedit_it = param_map.begin(); + } + } + } while (oncanvasedit_it != old_it); // iterate until complete loop through map has been made + + return NULL; +} + +void +Effect::editNextParamOncanvas(SPItem * item, SPDesktop * desktop) +{ + if (!desktop) return; + + Parameter * param = getNextOncanvasEditableParam(); + if (param) { + param->param_editOncanvas(item, desktop); + gchar *message = g_strdup_printf(_("Editing parameter %s."), param->param_label.c_str()); + desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, message); + g_free(message); + } else { + desktop->messageStack()->flash( Inkscape::WARNING_MESSAGE, + _("None of the applied path effect's parameters can be edited on-canvas.") ); + } +} } /* namespace LivePathEffect */ diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 8c647e599..844a158b5 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -21,8 +21,9 @@ //#define LPE_ENABLE_TEST_EFFECTS -struct SPShape; struct SPDocument; +struct SPDesktop; +struct SPItem; class NArtBpath; struct LivePathEffectObject; @@ -75,6 +76,8 @@ public: void readallParameters(Inkscape::XML::Node * repr); void setParameter(const gchar * key, const gchar * new_value); + void editNextParamOncanvas(SPItem * item, SPDesktop * desktop); + protected: Effect(LivePathEffectObject *lpeobject); @@ -91,6 +94,7 @@ protected: doEffect (Geom::Piecewise > & pwd2_in); void registerParameter(Parameter * param); + Parameter * getNextOncanvasEditableParam(); typedef std::map param_map_type; param_map_type param_map; @@ -101,6 +105,8 @@ protected: LivePathEffectObject *lpeobj; + param_map_type::iterator oncanvasedit_it; + private: Effect(const Effect&); Effect& operator=(const Effect&); diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index efca9908d..9ee7faae4 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -28,6 +28,7 @@ namespace LivePathEffect { Parameter::Parameter( const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect ) + : oncanvas_editable(false) { param_label = label; param_tooltip = tip; diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index a6b05bf36..a41d5f7c6 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -16,6 +16,9 @@ #include "ui/widget/registry.h" #include "ui/widget/registered-widget.h" +struct SPDesktop; +struct SPItem; + namespace Gtk { class Widget; } @@ -45,10 +48,14 @@ public: virtual Gtk::Widget * param_getWidget() = 0; virtual Glib::ustring * param_getTooltip() { return ¶m_tooltip; }; + virtual void param_editOncanvas(SPItem * item, SPDesktop * dt) { return; }; + Glib::ustring param_key; Inkscape::UI::Widget::Registry * param_wr; Glib::ustring param_label; + bool oncanvas_editable; + protected: Glib::ustring param_tooltip; diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp index db1064511..2b558d2dd 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -46,6 +46,7 @@ PathParam::PathParam( const Glib::ustring& label, const Glib::ustring& tip, edit_button = NULL; defvalue = g_strdup(default_value); param_readSVGValue(defvalue); + oncanvas_editable = true; } PathParam::~PathParam() @@ -128,17 +129,34 @@ PathParam::param_getWidget() } void -PathParam::on_edit_button_click() +PathParam::param_editOncanvas(SPItem * item, SPDesktop * dt) { - // Switch to node edit tool: - tools_switch_current(TOOLS_NODES); + // If not already in nodecontext, goto it! + if (!tools_isactive(dt, TOOLS_NODES)) { + tools_switch_current(TOOLS_NODES); + } - // set this parameter to edit: - ShapeEditor * shape_editor = SP_NODE_CONTEXT( SP_ACTIVE_DESKTOP->event_context )->shape_editor; - SPItem * item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem(); + ShapeEditor * shape_editor = SP_NODE_CONTEXT( dt->event_context )->shape_editor; shape_editor->set_item_livepatheffect_parameter(item, SP_OBJECT(param_effect->getLPEObj()), param_key.c_str()); } +void +PathParam::param_write_to_repr(const char * svgd) +{ + param_effect->getRepr()->setAttribute(param_key.c_str(), svgd); +} + + +/* CALLBACK FUNCTIONS FOR THE BUTTONS */ +void +PathParam::on_edit_button_click() +{ + SPItem * item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem(); + if (item != NULL) { + param_editOncanvas(item, SP_ACTIVE_DESKTOP); + } +} + void PathParam::on_paste_button_click() { @@ -170,12 +188,6 @@ PathParam::on_paste_button_click() } } -void -PathParam::param_write_to_repr(const char * svgd) -{ - param_effect->getRepr()->setAttribute(param_key.c_str(), svgd); -} - } /* namespace LivePathEffect */ diff --git a/src/live_effects/parameter/path.h b/src/live_effects/parameter/path.h index 14387f419..6ba6e7e4b 100644 --- a/src/live_effects/parameter/path.h +++ b/src/live_effects/parameter/path.h @@ -44,6 +44,8 @@ public: void param_set_default(); + void param_editOncanvas(SPItem * item, SPDesktop * dt); + sigc::signal signal_path_pasted; sigc::signal signal_path_changed; diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 8d0aa4e79..d97bcfc08 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -2005,6 +2005,24 @@ sp_selection_item_prev(void) } } +void sp_selection_next_patheffect_param(SPDesktop * dt) +{ + if (!dt) return; + + Inkscape::Selection *selection = sp_desktop_selection(dt); + if ( selection && !selection->isEmpty() ) { + SPItem *item = selection->singleItem(); + if ( item && SP_IS_SHAPE(item)) { + SPShape *shape = SP_SHAPE(item); + if (sp_shape_has_path_effect(shape)) { + sp_shape_edit_next_param_oncanvas(shape, dt); + } else { + dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("The selection has no applied path effect.")); + } + } + } +} + namespace { template diff --git a/src/selection-chemistry.h b/src/selection-chemistry.h index 66aab7d77..09f957332 100644 --- a/src/selection-chemistry.h +++ b/src/selection-chemistry.h @@ -88,6 +88,8 @@ void sp_selection_move_screen (gdouble dx, gdouble dy); void sp_selection_item_next (void); void sp_selection_item_prev (void); +void sp_selection_next_patheffect_param(SPDesktop * dt); + void scroll_to_show_item(SPDesktop *desktop, SPItem *item); void sp_undo (SPDesktop *desktop, SPDocument *doc); diff --git a/src/sp-shape.cpp b/src/sp-shape.cpp index 511081b4c..ddec7aecc 100644 --- a/src/sp-shape.cpp +++ b/src/sp-shape.cpp @@ -1214,6 +1214,14 @@ bool sp_shape_has_path_effect(SPShape *shape) return (shape->path_effect_href != NULL); } +void sp_shape_edit_next_param_oncanvas(SPShape *shape, SPDesktop *dt) +{ + LivePathEffectObject *lpeobj = sp_shape_get_livepatheffectobject(shape); + if (lpeobj && lpeobj->lpe) { + lpeobj->lpe->editNextParamOncanvas(SP_ITEM(shape), dt); + } +} + /* Local Variables: mode:c++ diff --git a/src/sp-shape.h b/src/sp-shape.h index 7563e2c7d..eb7d01245 100644 --- a/src/sp-shape.h +++ b/src/sp-shape.h @@ -27,6 +27,7 @@ #define SP_SHAPE_WRITE_PATH (1 << 2) +struct SPDesktop; struct LivePathEffectObject; namespace Inkscape{ namespace LivePathEffect{ @@ -84,4 +85,6 @@ void sp_shape_set_path_effect(SPShape *shape, gchar *value); void sp_shape_remove_path_effect(SPShape *shape); bool sp_shape_has_path_effect(SPShape *shape); +void sp_shape_edit_next_param_oncanvas(SPShape *shape, SPDesktop *dt); + #endif diff --git a/src/verbs.cpp b/src/verbs.cpp index 32e0c46af..cc3adb8e2 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -1001,16 +1001,7 @@ EditVerb::perform(SPAction *action, void *data, void *pdata) break; case SP_VERB_EDIT_NEXT_PATHEFFECT_PARAMETER: - //FACTOR OUT THIS CODE TO SOMEWHERE ELSE! - // if(selection has LPE) { - // If not already in nodecontext, goto it! - // if (!tools_isactive(dt, TOOLS_NODES)) { - // tools_switch_current(TOOLS_NODES); - // } - // add goto next code here: - //} else { - // statusbar message: selection has no path effect applied. - //} + sp_selection_next_patheffect_param(dt); break; default: break; -- 2.30.2