diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp
index 2f3fc1864acab40039b0c3e3f4d4144df0c1b160..aa026abb3eab890ab17824a6b3a06fd275de0661 100644 (file)
--- a/src/sp-rect.cpp
+++ b/src/sp-rect.cpp
#include <display/curve.h>
#include <libnr/nr-matrix-ops.h>
#include <libnr/nr-matrix-fns.h>
+#include <2geom/rect.h>
#include "inkscape.h"
#include "document.h"
static void sp_rect_convert_to_guides(SPItem *item);
static void sp_rect_set_shape(SPShape *shape);
-static void sp_rect_snappoints(SPItem const *item, SnapPointsIter p, Inkscape::SnapPreferences const *snapprefs);
+static void sp_rect_snappoints(SPItem const *item, bool const target, SnapPointsWithType &p, Inkscape::SnapPreferences const *snapprefs);
static SPShapeClass *parent_class;
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);
SP_ITEM(rect)->transform);
}
+Geom::Rect
+sp_rect_get_rect (SPRect *rect)
+{
+ Geom::Point p0 = Geom::Point(rect->x.computed, rect->y.computed);
+ Geom::Point p2 = Geom::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed);
+ return Geom::Rect(p0, p2);
+}
+
void
sp_rect_compensate_rxry(SPRect *rect, Geom::Matrix xform)
{
/**
* 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, bool const target, SnapPointsWithType &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
@@ -556,6 +564,11 @@ 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));
@@ -565,17 +578,29 @@ static void sp_rect_snappoints(SPItem const *item, SnapPointsIter p, Inkscape::S
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;
- *p = p0;
- *p = p1;
- *p = p2;
- *p = p3;
+ int type;
- if (snapprefs->getSnapMidpoints()) {
- *p = (p0 + p1)/2;
- *p = (p1 + p2)/2;
- *p = (p2 + p3)/2;
- *p = (p3 + p0)/2;
+ if (snapprefs->getSnapToItemNode()) {
+ type = target ? int(Inkscape::SNAPTARGET_CORNER) : int(Inkscape::SNAPSOURCE_CORNER);
+ p.push_back(std::make_pair(p0, type));
+ p.push_back(std::make_pair(p1, type));
+ p.push_back(std::make_pair(p2, type));
+ p.push_back(std::make_pair(p3, type));
}
+
+ if (snapprefs->getSnapLineMidpoints()) { // only do this when we're snapping nodes (enforce strict snapping)
+ type = target ? int(Inkscape::SNAPTARGET_LINE_MIDPOINT) : int(Inkscape::SNAPSOURCE_LINE_MIDPOINT);
+ p.push_back(std::make_pair((p0 + p1)/2, type));
+ p.push_back(std::make_pair((p1 + p2)/2, type));
+ p.push_back(std::make_pair((p2 + p3)/2, type));
+ p.push_back(std::make_pair((p3 + p0)/2, type));
+ }
+
+ if (snapprefs->getSnapObjectMidpoints()) { // only do this when we're snapping nodes (enforce strict snapping)
+ type = target ? int(Inkscape::SNAPTARGET_OBJECT_MIDPOINT) : int(Inkscape::SNAPSOURCE_OBJECT_MIDPOINT);
+ p.push_back(std::make_pair((p0 + p2)/2, type));
+ }
+
}
void