Code

Fix snapping when dragging gradients (implement the snap delay, use snap tolerances...
authordvlierop2 <dvlierop2@users.sourceforge.net>
Mon, 23 Feb 2009 21:25:08 +0000 (21:25 +0000)
committerdvlierop2 <dvlierop2@users.sourceforge.net>
Mon, 23 Feb 2009 21:25:08 +0000 (21:25 +0000)
src/gradient-drag.cpp
src/node-context.cpp
src/widgets/toolbox.cpp

index 76bed32cf5c1e3a953489a030e2f68e9958ad347..6d8815938af690f41a91d1aecc85c80cd9ae5f16 100644 (file)
@@ -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
index ec86a4c8096a82311172a5a2d5bc7eae2ed647f8..4a36c5d615eef273386dd3088e7000fad33ac6af 100644 (file)
@@ -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) {
index e3dcbcc14a9ebfd3bd63ea2d879633c7e74f32e7..3049d53e7f9dee784f33a96fccdddc04ae8b07a6 100644 (file)
@@ -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 );