Code

Node tool: fix snapping of node rotation center
authorKrzysztof Kosiński <tweenk.pl@gmail.com>
Thu, 16 Dec 2010 22:07:52 +0000 (23:07 +0100)
committerKrzysztof Kosiński <tweenk.pl@gmail.com>
Thu, 16 Dec 2010 22:07:52 +0000 (23:07 +0100)
src/ui/tool/node.cpp
src/ui/tool/node.h
src/ui/tool/transform-handle-set.cpp

index a79a5c409ce9a847991593631e8d3466edccacf0..fea02d399f64c01cbd30bfcee4948736eadaa1b4 100644 (file)
@@ -227,6 +227,35 @@ char const *Handle::handle_type_to_localized_string(NodeType type)
     }
 }
 
+bool Handle::_eventHandler(GdkEvent *event)
+{
+    switch (event->type)
+    {
+    case GDK_KEY_PRESS:
+        switch (shortcut_key(event->key))
+        {
+        case GDK_s:
+        case GDK_S:
+            if (held_only_shift(event->key) && _parent->_type == NODE_CUSP) {
+                // when Shift+S is pressed when hovering over a handle belonging to a cusp node,
+                // hold this handle in place; otherwise process normally
+                // this handle is guaranteed not to be degenerate
+                other()->move(_parent->position() - (position() - _parent->position()));
+                _parent->setType(NODE_SMOOTH, false);
+                _parent->_pm().update(); // magic triple combo to add undo event
+                _parent->_pm().writeXML();
+                _parent->_pm()._commit(_("Change node type"));
+                return true;
+            }
+            break;
+        default: break;
+        }
+    default: break;
+    }
+
+    return ControlPoint::_eventHandler(event);
+}
+
 bool Handle::grabbed(GdkEventMotion *)
 {
     _saved_other_pos = other()->position();
index 0194f5053176936f7ee0ef62543cb02fa32d2403..b5d4d88f2045c424edfa7882ba427386434cd1fa 100644 (file)
@@ -102,6 +102,7 @@ public:
 protected:
     Handle(NodeSharedData const &data, Geom::Point const &initial_pos, Node *parent);
 
+    virtual bool _eventHandler(GdkEvent *event);
     virtual void dragged(Geom::Point &, GdkEventMotion *);
     virtual bool grabbed(GdkEventMotion *);
     virtual void ungrabbed(GdkEventButton *);
index ef93a3767c32777722c67854f5fd6d19c66e7a14..cafd592a3622017f42f62fafdd7253bd1b17f461 100644 (file)
@@ -18,6 +18,8 @@
 #include "desktop-handles.h"
 #include "display/sodipodi-ctrlrect.h"
 #include "preferences.h"
+#include "snap.h"
+#include "sp-namedview.h"
 #include "ui/tool/commit-events.h"
 #include "ui/tool/control-point.h"
 #include "ui/tool/event-utils.h"
@@ -473,7 +475,23 @@ public:
     }
 
 protected:
-
+    virtual void dragged(Geom::Point &new_pos, GdkEventMotion *event) {
+        SnapManager &sm = _desktop->namedview->snap_manager;
+        sm.setup(_desktop);
+        bool snap = !held_shift(*event) && sm.someSnapperMightSnap();
+        if (held_control(*event)) {
+            // constrain to axes
+            Geom::Point origin = _last_drag_origin();
+            std::vector<Inkscape::Snapper::SnapConstraint> constraints;
+            constraints.push_back(Inkscape::Snapper::SnapConstraint(origin, Geom::Point(1, 0)));
+            constraints.push_back(Inkscape::Snapper::SnapConstraint(origin, Geom::Point(0, 1)));
+            new_pos = sm.multipleConstrainedSnaps(Inkscape::SnapCandidatePoint(new_pos,
+                SNAPSOURCE_ROTATION_CENTER), constraints, held_shift(*event)).getPoint();
+        } else if (snap) {
+            sm.freeSnapReturnByRef(new_pos, SNAPSOURCE_ROTATION_CENTER);
+        }
+        sm.unSetup();
+    }
     virtual Glib::ustring _getTip(unsigned /*state*/) {
         return C_("Transform handle tip",
             "<b>Rotation center</b>: drag to change the origin of transforms");