Code

finally getting closer to processing axes and contexts correctly
[inkscape.git] / src / seltrans.cpp
index f83c646b7bc6da5dd61614079524175cd06e62d8..9a648e2efa752649aaba270db9741ccc4ed67a0d 100644 (file)
@@ -39,6 +39,7 @@
 #include "seltrans.h"
 #include "selection-chemistry.h"
 #include "sp-metrics.h"
+#include "verbs.h"
 #include <glibmm/i18n.h>
 #include "display/sp-ctrlline.h"
 #include "prefs-utils.h"
@@ -101,11 +102,13 @@ Inkscape::SelTrans::SelTrans(SPDesktop *desktop) :
 
     _updateVolatileState();
 
+    _center_is_set = false; // reread _center from items, or set to bbox midpoint
+
     _updateHandles();
 
-    _selection = SP_DT_SELECTION(desktop);
+    _selection = sp_desktop_selection(desktop);
 
-    _norm = sp_canvas_item_new(SP_DT_CONTROLS(desktop),
+    _norm = sp_canvas_item_new(sp_desktop_controls(desktop),
                                SP_TYPE_CTRL,
                                "anchor", GTK_ANCHOR_CENTER,
                                "mode", SP_CTRL_MODE_COLOR,
@@ -117,8 +120,8 @@ Inkscape::SelTrans::SelTrans(SPDesktop *desktop) :
                                "stroke_color", 0x000000a0,
                                "pixbuf", handles[12],
                                NULL);
-    
-    _grip = sp_canvas_item_new(SP_DT_CONTROLS(desktop),
+
+    _grip = sp_canvas_item_new(sp_desktop_controls(desktop),
                                SP_TYPE_CTRL,
                                "anchor", GTK_ANCHOR_CENTER,
                                "mode", SP_CTRL_MODE_XOR,
@@ -130,12 +133,12 @@ Inkscape::SelTrans::SelTrans(SPDesktop *desktop) :
                                "stroke_color", 0xffffffff,
                                "pixbuf", handles[12],
                                NULL);
-    
+
     sp_canvas_item_hide(_grip);
     sp_canvas_item_hide(_norm);
 
     for (int i = 0; i < 4; i++) {
-        _l[i] = sp_canvas_item_new(SP_DT_CONTROLS(desktop), SP_TYPE_CTRLLINE, NULL);
+        _l[i] = sp_canvas_item_new(sp_desktop_controls(desktop), SP_TYPE_CTRLLINE, NULL);
         sp_canvas_item_hide(_l[i]);
     }
 
@@ -188,6 +191,7 @@ Inkscape::SelTrans::~SelTrans()
     }
 
     _items.clear();
+    _items_centers.clear();
 }
 
 void Inkscape::SelTrans::resetState()
@@ -203,12 +207,15 @@ void Inkscape::SelTrans::increaseState()
         _state = STATE_SCALE;
     }
 
+    _center_is_set = true; // no need to reread center
+
     _updateHandles();
 }
 
 void Inkscape::SelTrans::setCenter(NR::Point const &p)
 {
     _center = p;
+    _center_is_set = true;
 
     // Write the new center position into all selected items
     for (GSList const *l = _desktop->selection->itemList(); l; l = l->next) {
@@ -216,14 +223,15 @@ void Inkscape::SelTrans::setCenter(NR::Point const &p)
         it->setCenter(p);
         SP_OBJECT(it)->updateRepr();
     }
-    sp_document_maybe_done (SP_DT_DOCUMENT(_desktop), "center::move");
+    sp_document_maybe_done (sp_desktop_document(_desktop), "center::move", SP_VERB_CONTEXT_SELECT, 
+                            _("Set center"));
 
     _updateHandles();
 }
 
 void Inkscape::SelTrans::grab(NR::Point const &p, gdouble x, gdouble y, bool show_handles)
 {
-    Inkscape::Selection *selection = SP_DT_SELECTION(_desktop);
+    Inkscape::Selection *selection = sp_desktop_selection(_desktop);
 
     g_return_if_fail(!_grabbed);
 
@@ -240,14 +248,15 @@ void Inkscape::SelTrans::grab(NR::Point const &p, gdouble x, gdouble y, bool sho
     for (GSList const *l = selection->itemList(); l; l = l->next) {
         SPItem *it = (SPItem*)sp_object_ref(SP_OBJECT(l->data), NULL);
         _items.push_back(std::pair<SPItem *, NR::Matrix>(it, sp_item_i2d_affine(it)));
+        _items_centers.push_back(std::pair<SPItem *, NR::Point>(it, it->getCenter())); // for content-dragging, we need to remember original centers
     }
 
     _current.set_identity();
 
     _point = p;
 
-    _snap_points = selection->getSnapPoints();
-    _bbox_points = selection->getBBoxPoints();
+    _snap_points = selection->getSnapPointsConvexHull();
+    _bbox_points = selection->getBBoxPointsOuter();
 
     gchar const *scale_origin = prefs_get_string_attribute("tools.select", "scale_origin");
     bool const origin_on_bbox = (scale_origin == NULL || !strcmp(scale_origin, "bbox"));
@@ -313,22 +322,40 @@ void Inkscape::SelTrans::ungrab()
 {
     g_return_if_fail(_grabbed);
 
-    Inkscape::Selection *selection = SP_DT_SELECTION(_desktop);
+    Inkscape::Selection *selection = sp_desktop_selection(_desktop);
     bool updh = true;
     if (!_empty && _changed) {
         sp_selection_apply_affine(selection, _current, (_show == SHOW_OUTLINE)? true : false);
         _center *= _current;
-
-        // Transform may have changed the objects' bboxes, so we need to write the _center into them again
-        for (unsigned i = 0; i < _items.size(); i++) {
-            SPItem *currentItem = _items[i].first;
-            if (currentItem->isCenterSet() || _current[1] != 0 || _current[2] != 0) { // only if it's already set, or if it's a rotation/skew
-                currentItem->setCenter (_center);
-                SP_OBJECT(currentItem)->updateRepr();
+        _center_is_set = true;
+
+// If dragging showed content live, sp_selection_apply_affine cannot change the centers
+// appropriately - it does not know the original positions of the centers (all objects already have
+// the new bboxes). So we need to reset the centers from our saved array.
+        if (_show != SHOW_OUTLINE && !_current.is_translation()) {
+            for (unsigned i = 0; i < _items_centers.size(); i++) {
+                SPItem *currentItem = _items_centers[i].first;
+                if (currentItem->isCenterSet()) { // only if it's already set
+                    currentItem->setCenter (_items_centers[i].second * _current);
+                    SP_OBJECT(currentItem)->updateRepr();
+                }
             }
         }
 
-        sp_document_done(SP_DT_DOCUMENT(_desktop));
+        if (_current.is_translation()) {
+            sp_document_done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_SELECT,
+                             _("Move"));
+        } else if (_current.is_scale()) {
+            sp_document_done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_SELECT,
+                             _("Scale"));
+        } else if (_current.is_rotation()) {
+            sp_document_done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_SELECT,
+                             _("Rotate"));
+        } else {
+            sp_document_done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_SELECT,
+                             _("Skew"));
+        }
+
         updh = false;
     }
 
@@ -336,6 +363,7 @@ void Inkscape::SelTrans::ungrab()
         sp_object_unref(SP_OBJECT(_items[i].first), NULL);
     }
     _items.clear();
+    _items_centers.clear();
 
     _grabbed = false;
     _show_handles = true;
@@ -365,7 +393,14 @@ void Inkscape::SelTrans::ungrab()
 
 void Inkscape::SelTrans::stamp()
 {
-    Inkscape::Selection *selection = SP_DT_SELECTION(_desktop);
+    Inkscape::Selection *selection = sp_desktop_selection(_desktop);
+
+    bool fixup = !_grabbed;
+    if ( fixup && _stamp_cache ) {
+        // TODO - give a proper fix. Simple temproary work-around for the grab() issue
+        g_slist_free(_stamp_cache);
+        _stamp_cache = NULL;
+    }
 
     /* stamping mode */
     if (!_empty) {
@@ -395,7 +430,7 @@ void Inkscape::SelTrans::stamp()
             // move to the saved position
             copy_repr->setPosition(pos > 0 ? pos : 0);
 
-            SPItem *copy_item = (SPItem *) SP_DT_DOCUMENT(_desktop)->getObjectByRepr(copy_repr);
+            SPItem *copy_item = (SPItem *) sp_desktop_document(_desktop)->getObjectByRepr(copy_repr);
 
             NR::Matrix const *new_affine;
             if (_show == SHOW_OUTLINE) {
@@ -409,10 +444,21 @@ void Inkscape::SelTrans::stamp()
 
             sp_item_write_transform(copy_item, copy_repr, *new_affine);
 
+            if (copy_item->isCenterSet()) {
+                copy_item->setCenter(_center * _current);
+            }
+
             Inkscape::GC::release(copy_repr);
             l = l->next;
         }
-        sp_document_done(SP_DT_DOCUMENT(_desktop));
+        sp_document_done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_SELECT,
+                         _("Stamp"));
+    }
+
+    if ( fixup && _stamp_cache ) {
+        // TODO - give a proper fix. Simple temproary work-around for the grab() issue
+        g_slist_free(_stamp_cache);
+        _stamp_cache = NULL;
     }
 }
 
@@ -428,19 +474,17 @@ void Inkscape::SelTrans::_updateHandles()
 
     // center handle
     if ( _chandle == NULL ) {
-        _chandle = sp_knot_new(_desktop);
-        g_object_set(G_OBJECT(_chandle),
-                     "anchor", handle_center.anchor,
-                     "shape", SP_CTRL_SHAPE_BITMAP,
-                     "size", 13,
-                     "mode", SP_CTRL_MODE_XOR,
-                     "fill", 0x00000000,
-                     "fill_mouseover", 0x00000000,
-                     "stroke", 0x000000ff,
-                     "stroke_mouseover", 0xff0000b0,
-                     "pixbuf", handles[handle_center.control],
-                     "tip", _("<b>Center</b> of rotation and skewing: drag to reposition; scaling with Shift also uses this center"),
-                     NULL);
+        _chandle = sp_knot_new(_desktop, _("<b>Center</b> of rotation and skewing: drag to reposition; scaling with Shift also uses this center"));
+
+        _chandle->setShape (SP_CTRL_SHAPE_BITMAP);
+        _chandle->setSize (13);
+        _chandle->setAnchor (handle_center.anchor);
+        _chandle->setMode (SP_CTRL_MODE_XOR);
+        _chandle->setFill(0x00000000, 0x00000000, 0x00000000);
+        _chandle->setStroke(0x000000ff, 0xff0000b0, 0xff0000b0);
+        _chandle->setPixbuf(handles[handle_center.control]);
+        sp_knot_update_ctrl(_chandle);
+
         g_signal_connect(G_OBJECT(_chandle), "request",
                          G_CALLBACK(sp_sel_trans_handle_request), (gpointer) &handle_center);
         g_signal_connect(G_OBJECT(_chandle), "moved",
@@ -466,17 +510,9 @@ void Inkscape::SelTrans::_updateHandles()
                     _("<b>Rotate</b> selection; with <b>Ctrl</b> to snap angle; with <b>Shift</b> to rotate around the opposite corner"));
     }
 
-    // Extract the position of the center from the first selected object
-    GSList *items = (GSList *) _desktop->selection->itemList();
-    if (items) {
-        SPItem *first = reinterpret_cast<SPItem*>(g_slist_last(items)->data); // from the first item in selection
-        if (first->isCenterSet()) { // only if set explicitly
-            _center =  first->getCenter(); 
-        } else {
-            _center = _box.midpoint();
-        }
-    } else {
-        _center = _box.midpoint();
+    if (!_center_is_set) {
+        _center = _desktop->selection->center();
+        _center_is_set = true;
     }
 
     if ( _state == STATE_SCALE ) {
@@ -489,7 +525,7 @@ void Inkscape::SelTrans::_updateHandles()
 
 void Inkscape::SelTrans::_updateVolatileState()
 {
-    Inkscape::Selection *selection = SP_DT_SELECTION(_desktop);
+    Inkscape::Selection *selection = sp_desktop_selection(_desktop);
     _empty = selection->isEmpty();
 
     if (_empty) {
@@ -523,19 +559,16 @@ void Inkscape::SelTrans::_showHandles(SPKnot *knot[], SPSelTransHandle const han
 
     for (int i = 0; i < num; i++) {
         if (knot[i] == NULL) {
-            knot[i] = sp_knot_new(_desktop);
-            g_object_set(G_OBJECT(knot[i]),
-                         "anchor", handle[i].anchor,
-                         "shape", SP_CTRL_SHAPE_BITMAP,
-                         "size", 13,
-                         "mode", SP_KNOT_MODE_XOR,
-                         "fill", 0x000000ff, // inversion
-                         "fill_mouseover", 0x00ff6600, // green
-                         "stroke", 0x000000ff, // inversion
-                         "stroke_mouseover", 0x000000ff, // inversion
-                         "pixbuf", handles[handle[i].control],
-                         "tip", i % 2 ? even_tip : odd_tip,
-                         NULL);
+            knot[i] = sp_knot_new(_desktop, i % 2 ? even_tip : odd_tip);
+
+            knot[i]->setShape (SP_CTRL_SHAPE_BITMAP);
+            knot[i]->setSize (13);
+            knot[i]->setAnchor (handle[i].anchor);
+            knot[i]->setMode (SP_CTRL_MODE_XOR);
+            knot[i]->setFill(0x000000ff, 0x00ff6600, 0x00ff6600); // inversion, green, green
+            knot[i]->setStroke(0x000000ff, 0x000000ff, 0x000000ff); // inversion
+            knot[i]->setPixbuf(handles[handle[i].control]);
+            sp_knot_update_ctrl(knot[i]);
 
             g_signal_connect(G_OBJECT(knot[i]), "request",
                              G_CALLBACK(sp_sel_trans_handle_request), (gpointer) &handle[i]);
@@ -601,8 +634,11 @@ void Inkscape::SelTrans::handleClick(SPKnot *knot, guint state, SPSelTransHandle
                     SPItem *it = (SPItem*)sp_object_ref(SP_OBJECT(l->data), NULL);
                     it->unsetCenter();
                     SP_OBJECT(it)->updateRepr();
+                    _center_is_set = false;  // center has changed
+                    _updateHandles();
                 }
-                sp_document_maybe_done (SP_DT_DOCUMENT(_desktop), "center::unset");
+                sp_document_maybe_done (sp_desktop_document(_desktop), "center::unset", SP_VERB_CONTEXT_SELECT, 
+                                        _("Reset center"));
             }
             break;
         default:
@@ -662,7 +698,7 @@ gboolean Inkscape::SelTrans::handleRequest(SPKnot *knot, NR::Point *position, gu
     knot->desktop->set_coordinate_status(*position);
     knot->desktop->setPosition(*position);
 
-    
+
     if (state & GDK_MOD1_MASK) {
         *position = _point + ( *position - _point ) / 10;
     }
@@ -686,6 +722,7 @@ void Inkscape::SelTrans::_selChanged(Inkscape::Selection *selection)
 {
     if (!_grabbed) {
         _updateVolatileState();
+        _center_is_set = false; // center(s) may have changed
         _updateHandles();
     }
 }
@@ -698,6 +735,8 @@ void Inkscape::SelTrans::_selModified(Inkscape::Selection *selection, guint flag
         // reset internal flag
         _changed = false;
 
+        _center_is_set = false;  // center(s) may have changed
+
         _updateHandles();
     }
 }
@@ -762,6 +801,8 @@ gboolean Inkscape::SelTrans::scaleRequest(NR::Point &pt, guint state)
         }
     }
 
+    SnapManager const &m = _desktop->namedview->snap_manager;
+
     /* Get a STL list of the selected items.
     ** FIXME: this should probably be done by Inkscape::Selection.
     */
@@ -771,50 +812,72 @@ gboolean Inkscape::SelTrans::scaleRequest(NR::Point &pt, guint state)
     }
 
     if ((state & GDK_CONTROL_MASK) || _desktop->isToolboxButtonActive ("lock")) {
-        /* Scale is locked to a 1:1 aspect ratio, so that s[X] must be made to equal s[Y] */
+        /* Scale is locked to a 1:1 aspect ratio, so that s[X] must be made to equal s[Y].
+        ** To do this, we snap along a suitable constraint vector from the origin.
+        */
 
-        NR::Dim2 locked_dim;
+        NR::Point const cv = NR::Point(
+            pt[NR::X] > _origin[NR::X] ? 1 : -1,
+            pt[NR::Y] > _origin[NR::Y] ? 1 : -1
+            );
+
+        std::pair<NR::scale, bool> bb = m.constrainedSnapScale(Snapper::BBOX_POINT,
+                                                               _bbox_points,
+                                                               it,
+                                                               Snapper::ConstraintLine(_origin, cv),
+                                                               s,
+                                                               _origin);
+
+        std::pair<NR::scale, bool> sn = m.constrainedSnapScale(Snapper::SNAP_POINT,
+                                                               _snap_points,
+                                                               it,
+                                                               Snapper::ConstraintLine(_origin, cv),
+                                                               s,
+                                                               _origin);
+
+        if (bb.second == false && sn.second == false) {
+
+            /* We didn't snap, so just lock aspect ratio */
+            if (fabs(s[NR::X]) > fabs(s[NR::Y])) {
+                s[NR::X] = fabs(s[NR::Y]) * sign(s[NR::X]);
+            } else {
+                s[NR::Y] = fabs(s[NR::X]) * sign(s[NR::Y]);
+            }
 
-        /* Lock aspect ratio, using the smaller of the x and y factors */
-        if (fabs(s[NR::X]) > fabs(s[NR::Y])) {
-            s[NR::X] = fabs(s[NR::Y]) * sign(s[NR::X]);
-            locked_dim = NR::X;
         } else {
-            s[NR::Y] = fabs(s[NR::X]) * sign(s[NR::Y]);
-            locked_dim = NR::Y;
-        }
 
-        /* Snap the scale factor */
-        std::pair<double, bool> bb = namedview_vector_snap_list(_desktop->namedview,
-                                                                Snapper::BBOX_POINT, _bbox_points,
-                                                                _origin, s, it);
-        std::pair<double, bool> sn = namedview_vector_snap_list(_desktop->namedview,
-                                                                Snapper::SNAP_POINT, _snap_points,
-                                                                _origin, s, it);
-
-        double bd = bb.second ? fabs(bb.first - s[locked_dim]) : NR_HUGE;
-        double sd = sn.second ? fabs(sn.first - s[locked_dim]) : NR_HUGE;
-        double r = (bd < sd) ? bb.first : sn.first;
-
-        for ( unsigned int i = 0 ; i < 2 ; i++ ) {
-            s[i] = r * sign(s[i]);
+            /* Choose the smaller difference in scale.  Since s[X] == s[Y] we can
+            ** just compare difference in s[X].
+            */
+            double const bd = bb.second ? fabs(bb.first[NR::X] - s[NR::X]) : NR_HUGE;
+            double const sd = sn.second ? fabs(sn.first[NR::X] - s[NR::X]) : NR_HUGE;
+            s = (bd < sd) ? bb.first : sn.first;
         }
 
     } else {
         /* Scale aspect ratio is unlocked */
-        for ( unsigned int i = 0 ; i < 2 ; i++ ) {
-            std::pair<double, bool> bb = namedview_dim_snap_list_scale(_desktop->namedview,
-                                                                       Snapper::BBOX_POINT, _bbox_points,
-                                                                       _origin, s[i], NR::Dim2(i), it);
-            std::pair<double, bool> sn = namedview_dim_snap_list_scale(_desktop->namedview,
-                                                                       Snapper::SNAP_POINT, _snap_points,
-                                                                       _origin, s[i], NR::Dim2(i), it);
-
-            /* Pick the snap that puts us closest to the original scale */
-            NR::Coord bd = bb.second ? fabs(bb.first - s[i]) : NR_HUGE;
-            NR::Coord sd = sn.second ? fabs(sn.first - s[i]) : NR_HUGE;
-            s[i] = (bd < sd) ? bb.first : sn.first;
-        }
+        
+        std::pair<NR::scale, bool> bb = m.freeSnapScale(Snapper::BBOX_POINT,
+                                                        _bbox_points,
+                                                        it,
+                                                        s,
+                                                        _origin);
+        std::pair<NR::scale, bool> sn = m.freeSnapScale(Snapper::SNAP_POINT,
+                                                        _snap_points,
+                                                        it,
+                                                        s,
+                                                        _origin);
+
+        /* Pick the snap that puts us closest to the original scale */
+        NR::Coord bd = bb.second ?
+            fabs(NR::L2(NR::Point(bb.first[NR::X], bb.first[NR::Y])) -
+                 NR::L2(NR::Point(s[NR::X], s[NR::Y])))
+            : NR_HUGE;
+        NR::Coord sd = sn.second ?
+            fabs(NR::L2(NR::Point(sn.first[NR::X], sn.first[NR::Y])) -
+                 NR::L2(NR::Point(s[NR::X], s[NR::Y])))
+            : NR_HUGE;
+        s = (bd < sd) ? bb.first : sn.first;
     }
 
     /* Update the knot position */
@@ -869,35 +932,61 @@ gboolean Inkscape::SelTrans::stretchRequest(SPSelTransHandle const &handle, NR::
     for (GSList const *i = _selection->itemList(); i != NULL; i = i->next) {
         it.push_back(reinterpret_cast<SPItem*>(i->data));
     }
-    
+
+    SnapManager const &m = _desktop->namedview->snap_manager;
+
     if ( state & GDK_CONTROL_MASK ) {
         s[perp] = fabs(s[axis]);
 
-        std::pair<double, bool> sn = namedview_vector_snap_list(_desktop->namedview,
-                                                                Snapper::BBOX_POINT,
-                                                                _bbox_points, _origin, s, it);
-        std::pair<double, bool> bb = namedview_vector_snap_list(_desktop->namedview,
-                                                                Snapper::SNAP_POINT,
-                                                                _snap_points, _origin, s, it);
-
-        double bd = bb.second ? fabs(bb.first - s[axis]) : NR_HUGE;
-        double sd = sn.second ? fabs(sn.first - s[axis]) : NR_HUGE;
-        double ratio = (bd < sd) ? bb.first : sn.first;
+        std::pair<NR::Coord, bool> const bb = m.freeSnapStretch(
+            Snapper::BBOX_POINT,
+            _bbox_points,
+            it,
+            s[axis],
+            _origin,
+            axis,
+            true);
+
+        std::pair<NR::Coord, bool> const sn = m.freeSnapStretch(
+            Snapper::SNAP_POINT,
+            _snap_points,
+            it,
+            s[axis],
+            _origin,
+            axis,
+            true);
+
+        NR::Coord const bd = bb.second ? fabs(bb.first - s[axis]) : NR_HUGE;
+        NR::Coord const sd = sn.second ? fabs(sn.first - s[axis]) : NR_HUGE;
+        NR::Coord const ratio = (bd < sd) ? bb.first : sn.first;
 
         s[axis] = fabs(ratio) * sign(s[axis]);
         s[perp] = fabs(s[axis]);
     } else {
-        std::pair<NR::Coord, bool> bb = namedview_dim_snap_list_scale(_desktop->namedview, Snapper::BBOX_POINT,
-                                                                      _bbox_points, _origin,
-                                                                      s[axis], axis, it);
-        std::pair<NR::Coord, bool> sn = namedview_dim_snap_list_scale(_desktop->namedview, Snapper::SNAP_POINT,
-                                                                      _snap_points, _origin,
-                                                                      s[axis], axis, it);
 
-        /* Pick the snap that puts us closest to the original scale */
-        NR::Coord bd = bb.second ? fabs(bb.first - s[axis]) : NR_HUGE;
-        NR::Coord sd = sn.second ? fabs(sn.first - s[axis]) : NR_HUGE;
+        std::pair<NR::Coord, bool> const bb = m.freeSnapStretch(
+            Snapper::BBOX_POINT,
+            _bbox_points,
+            it,
+            s[axis],
+            _origin,
+            axis,
+            false);
+
+        std::pair<NR::Coord, bool> const sn = m.freeSnapStretch(
+            Snapper::SNAP_POINT,
+            _snap_points,
+            it,
+            s[axis],
+            _origin,
+            axis,
+            false);
+
+        /* Choose the smaller difference in scale */
+        NR::Coord const bd = bb.second ? fabs(bb.first - s[axis]) : NR_HUGE;
+        NR::Coord const sd = sn.second ? fabs(sn.first - s[axis]) : NR_HUGE;
         s[axis] = (bd < sd) ? bb.first : sn.first;
+        s[perp] = 1;
     }
 
     pt = ( _point - _origin ) * NR::scale(s) + _origin;
@@ -963,9 +1052,28 @@ gboolean Inkscape::SelTrans::skewRequest(SPSelTransHandle const &handle, NR::Poi
         }
         skew[dim_a] = tan(radians) * s[dim_a];
     } else {
-        skew[dim_a] = namedview_dim_snap_list_skew(_desktop->namedview,
-                Snapper::SNAP_POINT, _snap_points,
-                _origin, skew[dim_a], dim_b);
+        SnapManager const &m = _desktop->namedview->snap_manager;
+
+        std::pair<NR::Coord, bool> bb = m.freeSnapSkew(Inkscape::Snapper::BBOX_POINT,
+                                                       _bbox_points,
+                                                       std::list<SPItem const *>(),
+                                                       skew[dim_a],
+                                                       _origin,
+                                                       dim_a);
+
+        std::pair<NR::Coord, bool> sn = m.freeSnapSkew(Inkscape::Snapper::SNAP_POINT,
+                                                       _snap_points,
+                                                       std::list<SPItem const *>(),
+                                                       skew[dim_a],
+                                                       _origin,
+                                                       dim_a);
+        
+        if (bb.second || sn.second) {
+            /* We snapped something, so change the skew to reflect it */
+            NR::Coord const bd = bb.second ? bb.first : NR_HUGE;
+            NR::Coord const sd = sn.second ? sn.first : NR_HUGE;
+            skew[dim_a] = std::min(bd, sd);
+        }
     }
 
     pt[dim_b] = ( _point[dim_a] - _origin[dim_a] ) * skew[dim_a] + _point[dim_b];
@@ -1038,7 +1146,7 @@ gboolean Inkscape::SelTrans::centerRequest(NR::Point &pt, guint state)
     using NR::X;
     using NR::Y;
 
-    SnapManager const m(_desktop->namedview);
+    SnapManager const &m = _desktop->namedview->snap_manager;
     pt = m.freeSnap(Snapper::SNAP_POINT, pt, NULL).getPoint();
 
     if (state & GDK_CONTROL_MASK) {
@@ -1103,7 +1211,7 @@ void sp_sel_trans_rotate(Inkscape::SelTrans *seltrans, SPSelTransHandle const &,
 {
     seltrans->rotate(pt, state);
 }
-    
+
 void Inkscape::SelTrans::stretch(SPSelTransHandle const &handle, NR::Point &pt, guint state)
 {
     using NR::X;
@@ -1144,11 +1252,12 @@ void Inkscape::SelTrans::stretch(SPSelTransHandle const &handle, NR::Point &pt,
         s[!dim] = fabs(s[dim]);
     }
 
-    NR::Rect new_bbox = _box * (NR::translate(-scale_origin) * NR::Matrix(s) * NR::translate(scale_origin));
+    NR::Point new_bbox_min = _box.min() * (NR::translate(-scale_origin) * NR::Matrix(s) * NR::translate(scale_origin));
+    NR::Point new_bbox_max = _box.max() * (NR::translate(-scale_origin) * NR::Matrix(s) * NR::translate(scale_origin));
 
     int transform_stroke = prefs_get_int_attribute ("options.transform", "stroke", 1);
-    NR::Matrix scaler = get_scale_transform_with_stroke (_box, _strokewidth, transform_stroke, 
-                   new_bbox.min()[NR::X], new_bbox.min()[NR::Y], new_bbox.max()[NR::X], new_bbox.max()[NR::Y]);
+    NR::Matrix scaler = get_scale_transform_with_stroke (_box, _strokewidth, transform_stroke,
+                   new_bbox_min[NR::X], new_bbox_min[NR::Y], new_bbox_max[NR::X], new_bbox_max[NR::Y]);
 
     transform(scaler, NR::Point(0, 0)); // we have already accounted for origin, so pass 0,0
 }
@@ -1164,11 +1273,12 @@ void Inkscape::SelTrans::scale(NR::Point &pt, guint state)
         if (fabs(s[i]) < 1e-9)
             s[i] = 1e-9;
     }
-    NR::Rect new_bbox = _box * (NR::translate(-_origin) * NR::Matrix(s) * NR::translate(_origin));
+    NR::Point new_bbox_min = _box.min() * (NR::translate(-_origin) * NR::Matrix(s) * NR::translate(_origin));
+    NR::Point new_bbox_max = _box.max() * (NR::translate(-_origin) * NR::Matrix(s) * NR::translate(_origin));
 
     int transform_stroke = prefs_get_int_attribute ("options.transform", "stroke", 1);
-    NR::Matrix scaler = get_scale_transform_with_stroke (_box, _strokewidth, transform_stroke, 
-                   new_bbox.min()[NR::X], new_bbox.min()[NR::Y], new_bbox.max()[NR::X], new_bbox.max()[NR::Y]);
+    NR::Matrix scaler = get_scale_transform_with_stroke (_box, _strokewidth, transform_stroke,
+                   new_bbox_min[NR::X], new_bbox_min[NR::Y], new_bbox_max[NR::X], new_bbox_max[NR::Y]);
 
     transform(scaler, NR::Point(0, 0)); // we have already accounted for origin, so pass 0,0
 }
@@ -1236,8 +1346,8 @@ void sp_sel_trans_center(Inkscape::SelTrans *seltrans, SPSelTransHandle const &,
 
 void Inkscape::SelTrans::moveTo(NR::Point const &xy, guint state)
 {
-    SnapManager const m(_desktop->namedview);
-    
+    SnapManager const &m = _desktop->namedview->snap_manager;
+
     /* The amount that we've moved by during this drag */
     NR::Point dxy = xy - _point;
 
@@ -1270,20 +1380,25 @@ void Inkscape::SelTrans::moveTo(NR::Point const &xy, guint state)
 
         /* This will be our list of possible translations */
         std::list<std::pair<NR::Point, bool> > s;
-        
+
         if (control) {
-            
+
             /* Snap to things, and also constrain to horizontal or vertical movement */
 
             for (unsigned int dim = 0; dim < 2; dim++) {
                 s.push_back(m.constrainedSnapTranslation(Inkscape::Snapper::BBOX_POINT,
                                                          _bbox_points,
-                                                         component_vectors[dim], it, dxy));
+                                                         it,
+                                                         Inkscape::Snapper::ConstraintLine(component_vectors[dim]),
+                                                         dxy));
+                            
                 s.push_back(m.constrainedSnapTranslation(Inkscape::Snapper::SNAP_POINT,
                                                          _snap_points,
-                                                         component_vectors[dim], it, dxy));
+                                                         it,
+                                                         Inkscape::Snapper::ConstraintLine(component_vectors[dim]),
+                                                         dxy));
             }
-            
+
         } else {
 
             /* Snap to things with no constraint */
@@ -1306,7 +1421,7 @@ void Inkscape::SelTrans::moveTo(NR::Point const &xy, guint state)
             }
         }
     }
-    
+
     if (control) {
         /* Ensure that the horizontal and vertical constraint has been applied */
         if (fabs(dxy[NR::X]) > fabs(dxy[NR::Y])) {
@@ -1315,7 +1430,7 @@ void Inkscape::SelTrans::moveTo(NR::Point const &xy, guint state)
             dxy[NR::X] = 0;
         }
     }
-    
+
     NR::Matrix const move((NR::translate(dxy)));
     NR::Point const norm(0, 0);
     transform(move, norm);