From: dvlierop2 Date: Mon, 23 Feb 2009 21:25:08 +0000 (+0000) Subject: Fix snapping when dragging gradients (implement the snap delay, use snap tolerances... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=1d63533b7b2b024f6b25072e0d6fba5cb71626fd;p=inkscape.git Fix snapping when dragging gradients (implement the snap delay, use snap tolerances from the object snapper) --- diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index 76bed32cf..6d8815938 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -541,8 +541,9 @@ gr_knot_moved_handler(SPKnot *knot, Geom::Point const &ppointer, guint state, gp Geom::Point p = ppointer; - // FIXME: take from prefs - double snap_dist = SNAP_DIST / dragger->parent->desktop->current_zoom(); + SPDesktop *desktop = dragger->parent->desktop; + SnapManager &m = desktop->namedview->snap_manager; + double snap_dist = m.snapprefs.getObjectTolerance() / dragger->parent->desktop->current_zoom(); if (state & GDK_SHIFT_MASK) { // with Shift; unsnap if we carry more than one draggable @@ -595,14 +596,12 @@ gr_knot_moved_handler(SPKnot *knot, Geom::Point const &ppointer, guint state, gp if (!((state & GDK_SHIFT_MASK) || ((state & GDK_CONTROL_MASK) && (state & GDK_MOD1_MASK)))) { // Try snapping to the grid or guides - SPDesktop *desktop = dragger->parent->desktop; - SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); Inkscape::SnappedPoint s = m.freeSnap(Inkscape::SnapPreferences::SNAPPOINT_NODE, to_2geom(p), Inkscape::SNAPSOURCE_HANDLE); if (s.getSnapped()) { p = s.getPoint(); sp_knot_moveto (knot, p); - } else { + } else if (m.snapprefs.getSnapEnabledGlobally() && m.snapprefs.getSnapModeNode() && !(m.snapprefs.getSnapPostponedGlobally())) { bool was_snapped = false; double dist = NR_HUGE; // No snapping so far, let's see if we need to snap to any of the levels diff --git a/src/node-context.cpp b/src/node-context.cpp index ec86a4c80..4a36c5d61 100644 --- a/src/node-context.cpp +++ b/src/node-context.cpp @@ -102,7 +102,7 @@ sp_node_context_init(SPNodeContext *node_context) node_context->rightalt = FALSE; node_context->leftctrl = FALSE; node_context->rightctrl = FALSE; - + new (&node_context->sel_changed_connection) sigc::connection(); node_context->flash_tempitem = NULL; @@ -113,9 +113,11 @@ sp_node_context_init(SPNodeContext *node_context) static void sp_node_context_dispose(GObject *object) { - SPNodeContext *nc = SP_NODE_CONTEXT(object); + SPNodeContext *nc = SP_NODE_CONTEXT(object); SPEventContext *ec = SP_EVENT_CONTEXT(object); + sp_canvas_set_snap_delay_active(ec->desktop->canvas, false); + ec->enableGrDrag(false); nc->sel_changed_connection.disconnect(); @@ -173,6 +175,8 @@ sp_node_context_setup(SPEventContext *ec) nc->_node_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack()); ec->shape_editor->update_statusbar(); + + sp_canvas_set_snap_delay_active(ec->desktop->canvas, true); } static void @@ -195,7 +199,7 @@ sp_node_context_flash_path(SPEventContext *event_context, SPItem *item, guint ti } else { g_print ("-----> sp_node_context_flash_path(): TODO: generate the helper path!!\n"); } - + if (canvasitem) { nc->flash_tempitem = desktop->add_temporary_canvasitem (canvasitem, timeout); } @@ -214,7 +218,7 @@ sp_node_context_selection_changed(Inkscape::Selection *selection, gpointer data) // TODO: update ShapeEditorsCollective instead ec->shape_editor->unset_item(SH_NODEPATH); ec->shape_editor->unset_item(SH_KNOTHOLDER); - SPItem *item = selection->singleItem(); + SPItem *item = selection->singleItem(); ec->shape_editor->set_item(item, SH_NODEPATH); ec->shape_editor->set_item(item, SH_KNOTHOLDER); ec->shape_editor->update_statusbar(); @@ -321,7 +325,7 @@ sp_node_context_root_handler(SPEventContext *event_context, GdkEvent *event) // The path went away while dragging; throw away any further motion // events until the mouse pointer is released. - + if (se->hits_curve() && !se->has_nodepath()) { break; } @@ -441,7 +445,7 @@ sp_node_context_root_handler(SPEventContext *event_context, GdkEvent *event) ret = TRUE; break; } - } + } if (event->type == GDK_BUTTON_RELEASE) { event_context->xp = event_context->yp = 0; if (event->button.button == 1) { diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index e3dcbcc14..3049d53e7 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -2017,7 +2017,7 @@ void setup_snap_toolbox(GtkWidget *toolbox, SPDesktop *desktop) Inkscape::IconSize secondarySize = prefToSize("/toolbox/secondary", 1); { - InkToggleAction* act = ink_toggle_action_new("ToggleSnapGlobal", + InkToggleAction* act = ink_toggle_action_new("ToggleSnapGlobal", _("Snap"), _("Enable snapping"), INKSCAPE_ICON_SNAP, secondarySize, SP_ATTR_INKSCAPE_SNAP_GLOBAL); @@ -2073,7 +2073,7 @@ void setup_snap_toolbox(GtkWidget *toolbox, SPDesktop *desktop) { InkToggleAction* act = ink_toggle_action_new("ToggleSnapFromNode", - _("Nodes"), _("Snap nodes"), INKSCAPE_ICON_SNAP_NODES, secondarySize, SP_ATTR_INKSCAPE_SNAP_NODES); + _("Nodes"), _("Snap nodes or handles"), INKSCAPE_ICON_SNAP_NODES, secondarySize, SP_ATTR_INKSCAPE_SNAP_NODES); gtk_action_group_add_action( mainActions->gobj(), GTK_ACTION( act ) ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox );