From: cilix42 Date: Mon, 16 Jun 2008 15:45:47 +0000 (+0000) Subject: Second step: try to make helper curves respond faster (don't recreate/delete the... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=bb78cf2c3a2ee8ea2c98433128556847f03f5799;p=inkscape.git Second step: try to make helper curves respond faster (don't recreate/delete the temporary canvasitems each time the selection is modified); better use of flash paths --- diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 0497d0e37..9476f0377 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -408,12 +408,16 @@ Effect::addHelperPaths(SPLPEItem *lpeitem, SPDesktop *desktop) { g_return_if_fail(SP_IS_PATH(lpeitem)); - if (show_orig_path) { + if (providesKnotholder() && showOrigPath()) { + // TODO: we assume that if the LPE provides its own knotholder, there is no nodepath so we + // must create the helper curve for the original path manually; when we allow nodepaths and + // knotholders alongside each other, this needs to be rethought! SPCanvasItem *canvasitem = sp_nodepath_generate_helperpath(desktop, SP_PATH(lpeitem)); // TODO: Make sure the tempitem doesn't get destroyed when the mouse leaves the item Inkscape::Display::TemporaryItem* tmpitem = desktop->add_temporary_canvasitem (canvasitem, 0); lpeitem->lpe_helperpaths.push_back(tmpitem); } + addHelperPathsImpl(lpeitem, desktop); } diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 32917f8c8..9bcbf51ab 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -116,6 +116,8 @@ public: virtual void transform_multiply(Geom::Matrix const& postmul, bool set); + // TODO: providesKnotholder() is currently used as an indicator of whether a nodepath is + // created for an item or not. When we allow both at the same time, this needs rethinking! bool providesKnotholder() { return (kh_entity_vector.size() > 0); } virtual LPEPathFlashType pathFlashType() { return DEFAULT; } void addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); @@ -124,6 +126,7 @@ public: inline bool providesOwnFlashPaths() { return provides_own_flash_paths || show_orig_path; } + inline bool showOrigPath() { return show_orig_path; } Glib::ustring getName(); Inkscape::XML::Node * getRepr(); diff --git a/src/live_effects/lpe-mirror_reflect.h b/src/live_effects/lpe-mirror_reflect.h index a19aafb89..b4f7029a0 100644 --- a/src/live_effects/lpe-mirror_reflect.h +++ b/src/live_effects/lpe-mirror_reflect.h @@ -31,7 +31,7 @@ public: virtual void acceptParamPath (SPPath *param_path); virtual int acceptsNumParams() { return 2; } - virtual LPEPathFlashType pathFlashType() { return PERMANENT_FLASH; } + virtual LPEPathFlashType pathFlashType() { return SUPPRESS_FLASH; } virtual std::vector doEffect_path (std::vector const & path_in); diff --git a/src/live_effects/lpe-tangent_to_curve.h b/src/live_effects/lpe-tangent_to_curve.h index 8d9622c67..464b692bf 100644 --- a/src/live_effects/lpe-tangent_to_curve.h +++ b/src/live_effects/lpe-tangent_to_curve.h @@ -38,7 +38,7 @@ public: virtual Geom::Piecewise > doEffect_pwd2 (Geom::Piecewise > const & pwd2_in); - virtual LPEPathFlashType pathFlashType() { return PERMANENT_FLASH; } + virtual LPEPathFlashType pathFlashType() { return SUPPRESS_FLASH; } /* the knotholder entity classes must be declared friends */ friend class TtC::KnotHolderEntityLeftEnd; diff --git a/src/node-context.cpp b/src/node-context.cpp index 88ea1667d..b85e08b68 100644 --- a/src/node-context.cpp +++ b/src/node-context.cpp @@ -37,6 +37,8 @@ #include "shape-editor.h" #include "live_effects/effect.h" +#include "sp-lpe-item.h" + // needed for flash nodepath upon mouseover: #include "display/canvas-bpath.h" #include "display/curve.h" @@ -119,6 +121,12 @@ sp_node_context_dispose(GObject *object) nc->sel_changed_connection.disconnect(); nc->sel_changed_connection.~connection(); + // TODO: should this be here? + SPItem *item = sp_desktop_selection(ec->desktop)->singleItem(); + if (item && SP_IS_LPE_ITEM(item)) { + sp_lpe_item_remove_temporary_canvasitems(SP_LPE_ITEM(item), ec->desktop); + } + delete nc->shape_editor; if (nc->_node_message_context) { @@ -138,11 +146,8 @@ sp_node_context_setup(SPEventContext *ec) Inkscape::Selection *selection = sp_desktop_selection (ec->desktop); nc->sel_changed_connection.disconnect(); - nc->sel_modified_connection.disconnect(); nc->sel_changed_connection = selection->connectChanged(sigc::bind(sigc::ptr_fun(&sp_node_context_selection_changed), (gpointer)nc)); - nc->sel_modified_connection = - selection->connectModified(sigc::bind(sigc::ptr_fun(&sp_node_context_selection_modified), (gpointer)nc)); SPItem *item = selection->singleItem(); @@ -212,27 +217,6 @@ sp_node_context_selection_changed(Inkscape::Selection *selection, gpointer data) nc->shape_editor->update_statusbar(); } -/** -\brief Callback that processes the "modified" signal on the selection; -updates temporary canvasitems associated to LPEItems in the selection -*/ -void -sp_node_context_selection_modified(Inkscape::Selection *selection, guint /*flags*/, gpointer /*data*/) -{ - // TODO: do this for *all* items in the selection - SPItem *item = selection->singleItem(); - - // TODO: This is *very* inefficient! Can we avoid destroying and recreating the temporary - // items? Also, we should only update those that actually need it! - if (item && SP_IS_LPE_ITEM(item)) { - SPLPEItem *lpeitem = SP_LPE_ITEM(item); - SPDesktop *desktop = selection->desktop(); - - sp_lpe_item_remove_temporary_canvasitems(lpeitem, desktop); - sp_lpe_item_add_temporary_canvasitems(lpeitem, desktop); - } -} - void sp_node_context_show_modifier_tip(SPEventContext *event_context, GdkEvent *event) { diff --git a/src/node-context.h b/src/node-context.h index f67a32f6b..922569d27 100644 --- a/src/node-context.h +++ b/src/node-context.h @@ -48,7 +48,6 @@ struct SPNodeContext { bool rb_escaped; sigc::connection sel_changed_connection; - sigc::connection sel_modified_connection; Inkscape::MessageContext *_node_message_context; diff --git a/src/nodepath.cpp b/src/nodepath.cpp index ee8e5e123..c9456d17e 100644 --- a/src/nodepath.cpp +++ b/src/nodepath.cpp @@ -152,6 +152,20 @@ static void sp_nodepath_set_curve (Inkscape::NodePath::Path *np, SPCurve *curve) // active_node indicates mouseover node Inkscape::NodePath::Node * Inkscape::NodePath::Path::active_node = NULL; +static void sp_nodepath_draw_helper_curve(Inkscape::NodePath::Path *np, SPDesktop *desktop) { + // Draw helper curve + if (np->show_helperpath) { + SPCurve *helper_curve = np->curve->copy(); + helper_curve->transform(np->i2d ); + np->helper_path = sp_canvas_bpath_new(sp_desktop_controls(desktop), helper_curve); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(np->helper_path), np->helperpath_rgba, np->helperpath_width, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); + sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(np->helper_path), 0, SP_WIND_RULE_NONZERO); + sp_canvas_item_move_to_z(np->helper_path, 0); + sp_canvas_item_show(np->helper_path); + helper_curve->unref(); + } +} + /** * \brief Creates new nodepath from item */ @@ -208,7 +222,13 @@ Inkscape::NodePath::Path *sp_nodepath_new(SPDesktop *desktop, SPObject *object, np->helperpath_rgba = prefs_get_int_attribute("tools.nodes", "highlight_color", 0xff0000ff); np->helperpath_width = 1.0; np->curve = curve->copy(); - np->show_helperpath = prefs_get_int_attribute ("tools.nodes", "show_helperpath", 0) == 1; + np->show_helperpath = (prefs_get_int_attribute ("tools.nodes", "show_helperpath", 0) == 1); + if (SP_IS_LPE_ITEM(object)) { + Inkscape::LivePathEffect::Effect *lpe = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(object)); + if (lpe && lpe->isVisible() && lpe->showOrigPath()) { + np->show_helperpath = true; + } + } np->straight_path = false; if (IS_LIVEPATHEFFECT(object) && item) { np->item = item; @@ -264,17 +284,7 @@ Inkscape::NodePath::Path *sp_nodepath_new(SPDesktop *desktop, SPObject *object, // create the livarot representation from the same item sp_nodepath_ensure_livarot_path(np); - // Draw helper curve - if (np->show_helperpath) { - SPCurve *helper_curve = np->curve->copy(); - helper_curve->transform(np->i2d ); - np->helper_path = sp_canvas_bpath_new(sp_desktop_controls(desktop), helper_curve); - sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(np->helper_path), np->helperpath_rgba, np->helperpath_width, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); - sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(np->helper_path), 0, SP_WIND_RULE_NONZERO); - sp_canvas_item_move_to_z(np->helper_path, 0); - sp_canvas_item_show(np->helper_path); - helper_curve->unref(); - } + sp_nodepath_draw_helper_curve(np, desktop); return np; } diff --git a/src/shape-editor.cpp b/src/shape-editor.cpp index b975d3f79..d5712525a 100644 --- a/src/shape-editor.cpp +++ b/src/shape-editor.cpp @@ -192,13 +192,14 @@ void ShapeEditor::set_item(SPItem *item) { if (item) { if (SP_IS_LPE_ITEM(item)) { SPLPEItem *lpeitem = SP_LPE_ITEM(item); - if (!sp_lpe_item_get_current_lpe(lpeitem) || // if returns NULL, the whole expression evaluates to true and C++ will not call the otherwise crashing 2 functions below - !sp_lpe_item_get_current_lpe(lpeitem)->isVisible() || - !sp_lpe_item_get_current_lpe(lpeitem)->providesKnotholder()) { - // only create nodepath if the item either doesn't have an LPE - // or the LPE is invisible or it doesn't provide a knotholder itself - this->nodepath = - sp_nodepath_new(desktop, item, (prefs_get_int_attribute("tools.nodes", "show_handles", 1) != 0)); + Inkscape::LivePathEffect::Effect *lpe = sp_lpe_item_get_current_lpe(lpeitem); + if (!(lpe && lpe->isVisible() && lpe->providesKnotholder())) { + // only create nodepath if the item either doesn't have an LPE + // or the LPE is invisible or it doesn't provide a knotholder itself + this->nodepath = sp_nodepath_new(desktop, item, + (prefs_get_int_attribute("tools.nodes", "show_handles", 1) != 0)); + } else if (lpe && lpe->isVisible() && lpe->showOrigPath()) { + sp_lpe_item_add_temporary_canvasitems(lpeitem, desktop); } }