Code

now that selection description includes style (filtered, clipped), we need to update...
[inkscape.git] / src / sp-rect.cpp
index 6030991e27cd71ef5a89c370ea0f5f132bc75a51..c88b9eb38df0899f11d88a972de5f35f64e53f3a 100644 (file)
@@ -174,9 +174,8 @@ sp_rect_update(SPObject *object, SPCtx *ctx, guint flags)
         SPRect *rect = (SPRect *) object;
         SPStyle *style = object->style;
         SPItemCtx const *ictx = (SPItemCtx const *) ctx;
-        double const d = ictx->i2vp.descrim();
-        double const w = (ictx->vp.x1 - ictx->vp.x0) / d;
-        double const h = (ictx->vp.y1 - ictx->vp.y0) / d;
+        double const w = (ictx->vp.x1 - ictx->vp.x0);
+        double const h = (ictx->vp.y1 - ictx->vp.y0);
         double const em = style->font_size.computed;
         double const ex = 0.5 * em;  // fixme: get x height from pango or libnrtype.
         rect->x.update(em, ex, w);
@@ -544,11 +543,11 @@ sp_rect_get_visible_height(SPRect *rect)
 /**
  * Sets the snappoint p to the unrounded corners of the rectangle
  */
-static void sp_rect_snappoints(SPItem const *item, SnapPointsIter p, Inkscape::SnapPreferences const */*snapprefs*/)
+static void sp_rect_snappoints(SPItem const *item, SnapPointsIter p, Inkscape::SnapPreferences const *snapprefs)
 {
     /* This method overrides sp_shape_snappoints, which is the default for any shape. The default method
     returns all eight points along the path of a rounded rectangle, but not the real corners. Snapping
-    the startpoint and endpoint of each rounded corner is not very usefull and really confusing. Instead
+    the startpoint and endpoint of each rounded corner is not very useful and really confusing. Instead
     we could snap either the real corners, or not snap at all. Bulia Byak opted to snap the real corners,
     but it should be noted that this might be confusing in some cases with relatively large radii. With
     small radii though the user will easily understand which point is snapping. */
@@ -556,14 +555,38 @@ static void sp_rect_snappoints(SPItem const *item, SnapPointsIter p, Inkscape::S
     g_assert(item != NULL);
     g_assert(SP_IS_RECT(item));
 
+    // Help enforcing strict snapping, i.e. only return nodes when we're snapping nodes to nodes or a guide to nodes
+       if (!(snapprefs->getSnapModeNode() || snapprefs->getSnapModeGuide())) {
+               return;
+       }
+
     SPRect *rect = SP_RECT(item);
 
     Geom::Matrix const i2d (sp_item_i2d_affine (item));
 
-    *p = Geom::Point(rect->x.computed, rect->y.computed) * i2d;
-    *p = Geom::Point(rect->x.computed, rect->y.computed + rect->height.computed) * i2d;
-    *p = Geom::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed) * i2d;
-    *p = Geom::Point(rect->x.computed + rect->width.computed, rect->y.computed) * i2d;
+    Geom::Point p0 = Geom::Point(rect->x.computed, rect->y.computed) * i2d;
+    Geom::Point p1 = Geom::Point(rect->x.computed, rect->y.computed + rect->height.computed) * i2d;
+    Geom::Point p2 = Geom::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed) * i2d;
+    Geom::Point p3 = Geom::Point(rect->x.computed + rect->width.computed, rect->y.computed) * i2d;
+
+    if (snapprefs->getSnapToItemNode()) {
+               *p = p0;
+               *p = p1;
+               *p = p2;
+               *p = p3;
+    }
+
+       if (snapprefs->getSnapLineMidpoints()) { // only do this when we're snapping nodes (enforce strict snapping)
+               *p = (p0 + p1)/2;
+               *p = (p1 + p2)/2;
+               *p = (p2 + p3)/2;
+               *p = (p3 + p0)/2;
+       }
+
+       if (snapprefs->getSnapObjectMidpoints()) { // only do this when we're snapping nodes (enforce strict snapping)
+               *p = (p0 + p2)/2;
+       }
+
 }
 
 void