Code

Improve snapping behaviour when creating new shapes
authordvlierop2 <dvlierop2@users.sourceforge.net>
Tue, 20 May 2008 19:21:01 +0000 (19:21 +0000)
committerdvlierop2 <dvlierop2@users.sourceforge.net>
Tue, 20 May 2008 19:21:01 +0000 (19:21 +0000)
src/arc-context.cpp
src/rect-context.cpp
src/spiral-context.cpp
src/star-context.cpp

index 45b67a7dcbc5e8a0e85a276c2f2ddb7320dbc77d..e3dc7161c290df51cb7a0b9f5827a81d8da92345 100644 (file)
@@ -262,6 +262,11 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent
 
                 dragging = true;
                 ac->center = Inkscape::setup_for_drag_start(desktop, event_context, event);
+                
+                /* Snap center */
+                SnapManager &m = desktop->namedview->snap_manager;
+                m.setup(desktop, NULL); //null, because we don't have an item yet
+                m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, ac->center);     
 
                 sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
                                     GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
@@ -425,11 +430,6 @@ static void sp_arc_drag(SPArcContext *ac, NR::Point pt, guint state)
         ac->item->updateRepr();
 
         sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5);
-        
-        /* Snap center */
-        SnapManager &m = desktop->namedview->snap_manager;
-        m.setup(desktop, ac->item);
-        m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, ac->center);
     }
 
     bool ctrl_save = false;
index d1e5fe3817a66c0e4d7fb98b2b62feede493ec7d..f53a399482ee40915684f56a1932f5e31759bae1 100644 (file)
@@ -304,6 +304,11 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent
             NR::Point const button_dt(desktop->w2d(button_w));
             rc->center = button_dt;
             
+            /* Snap center */
+            SnapManager &m = desktop->namedview->snap_manager;
+            m.setup(desktop, NULL); //null, because we don't have an item yet
+            m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, rc->center);     
+            
             sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
                                 ( GDK_KEY_PRESS_MASK |
                                   GDK_BUTTON_RELEASE_MASK       |
@@ -491,11 +496,6 @@ static void sp_rect_drag(SPRectContext &rc, NR::Point const pt, guint state)
         rc.item->updateRepr();
 
         sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5);
-        
-        /* Snap center */
-        SnapManager &m = desktop->namedview->snap_manager;
-        m.setup(desktop, rc.item);
-        m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, rc.center);     
     }
 
     NR::Rect const r = Inkscape::snap_rectangular_box(desktop, rc.item, pt, rc.center, state);
index 31ec40d5033eb357536740029678d56ba298dc92..e868593697e30ab300571ddb76e02deb07deb7d8 100644 (file)
@@ -266,7 +266,7 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event)
                 sc->center = Inkscape::setup_for_drag_start(desktop, event_context, event);
 
                 SnapManager &m = desktop->namedview->snap_manager;
-                m.setup(desktop, sc->item);
+                m.setup(desktop, NULL); //null, because we don't have an item yet
                 m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, sc->center);
 
                 sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
index b6b3c340e01a15286b10676eaf518861eb808478..1b3b1e7b05c25ec0b096409fb8f2a1839383eb58 100644 (file)
@@ -279,10 +279,11 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent
             dragging = TRUE;
 
             sc->center = Inkscape::setup_for_drag_start(desktop, event_context, event);
-
+            
+            /* Snap center */
             SnapManager &m = desktop->namedview->snap_manager;
-            m.setup(desktop, sc->item);
-            m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, sc->center);
+            m.setup(desktop, NULL); //null, because we don't have an item yet
+            m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, sc->center);     
 
             sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
                                 GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
@@ -305,11 +306,7 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent
             event_context->within_tolerance = false;
 
             NR::Point const motion_w(event->motion.x, event->motion.y);
-            NR::Point motion_dt(event_context->desktop->w2d(motion_w));
-            
-            SnapManager &m = desktop->namedview->snap_manager;
-            m.setup(desktop, sc->item);
-            m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, motion_dt);
+            NR::Point motion_dt(desktop->w2d(motion_w));
             
             sp_star_drag (sc, motion_dt, event->motion.state);
 
@@ -449,14 +446,14 @@ static void sp_star_drag(SPStarContext *sc, NR::Point p, guint state)
         sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5);
     }
 
-    NR::Point const p0 = sp_desktop_dt2root_xy_point(desktop, sc->center);
-    NR::Point p1 = sp_desktop_dt2root_xy_point(desktop, p);
-
     /* Snap corner point with no constraints */
     SnapManager &m = desktop->namedview->snap_manager;
     m.setup(desktop, sc->item);
-    m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, p1);
-
+    m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, p);    
+    
+    NR::Point const p0 = sp_desktop_dt2root_xy_point(desktop, sc->center);
+    NR::Point p1 = sp_desktop_dt2root_xy_point(desktop, p);
+    
     SPStar *star = SP_STAR(sc->item);
 
     double const sides = (gdouble) sc->magnitude;