From: dvlierop2 Date: Tue, 20 Mar 2007 21:14:34 +0000 (+0000) Subject: Implementing feature request #1673807: snapping of gradient handles X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d46dc7135e50f1af9752c95cf02bf5f25723be17;p=inkscape.git Implementing feature request #1673807: snapping of gradient handles --- diff --git a/src/arc-context.cpp b/src/arc-context.cpp index 1071d6f5d..db64d7951 100644 --- a/src/arc-context.cpp +++ b/src/arc-context.cpp @@ -274,7 +274,7 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent } break; case GDK_MOTION_NOTIFY: - if (dragging && event->motion.state && GDK_BUTTON1_MASK) { + if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) { if ( event_context->within_tolerance && ( abs( (gint) event->motion.x - event_context->xp ) < event_context->tolerance ) diff --git a/src/gradient-context.cpp b/src/gradient-context.cpp index c44cf1c59..42b4df578 100644 --- a/src/gradient-context.cpp +++ b/src/gradient-context.cpp @@ -44,7 +44,8 @@ #include "sp-stop.h" #include "svg/css-ostringstream.h" #include "svg/svg-color.h" - +#include "snap.h" +#include "sp-namedview.h" @@ -410,8 +411,9 @@ sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event) /* Position center */ NR::Point const button_dt = desktop->w2d(button_w); /* Snap center to nearest magnetic point */ - - rc->origin = button_dt; + + SnapManager const &m = desktop->namedview->snap_manager; + rc->origin = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, button_dt, NULL).getPoint(); ret = TRUE; } diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index 4a8f7e8ed..d671b4823 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -41,6 +41,10 @@ #include "gradient-drag.h" #include "sp-stop.h" +#include "snap.h" +#include "sp-namedview.h" + + #define GR_KNOT_COLOR_NORMAL 0xffffff00 #define GR_KNOT_COLOR_SELECTED 0x0000ff00 @@ -429,19 +433,26 @@ gr_knot_moved_handler(SPKnot *knot, NR::Point const *ppointer, guint state, gpoi } } - if (!((state & GDK_SHIFT_MASK) || ((state & GDK_CONTROL_MASK) && (state & GDK_MOD1_MASK)))) { - // See if we need to snap to any of the levels - for (guint i = 0; i < dragger->parent->hor_levels.size(); i++) { - if (fabs(p[NR::Y] - dragger->parent->hor_levels[i]) < snap_dist) { - p[NR::Y] = dragger->parent->hor_levels[i]; - sp_knot_moveto (knot, &p); + // Try snapping to the grid or guides + SnapManager const &m = dragger->parent->desktop->namedview->snap_manager; + Inkscape::SnappedPoint s = m.freeSnap(Inkscape::Snapper::SNAP_POINT | Inkscape::Snapper::BBOX_POINT, p, NULL); + if (s.getDistance() < 1e6) { + p = s.getPoint(); + sp_knot_moveto (knot, &p); + } else { + // No snapping so far, let's see if we need to snap to any of the levels + for (guint i = 0; i < dragger->parent->hor_levels.size(); i++) { + if (fabs(p[NR::Y] - dragger->parent->hor_levels[i]) < snap_dist) { + p[NR::Y] = dragger->parent->hor_levels[i]; + sp_knot_moveto (knot, &p); + } } - } - for (guint i = 0; i < dragger->parent->vert_levels.size(); i++) { - if (fabs(p[NR::X] - dragger->parent->vert_levels[i]) < snap_dist) { - p[NR::X] = dragger->parent->vert_levels[i]; - sp_knot_moveto (knot, &p); + for (guint i = 0; i < dragger->parent->vert_levels.size(); i++) { + if (fabs(p[NR::X] - dragger->parent->vert_levels[i]) < snap_dist) { + p[NR::X] = dragger->parent->vert_levels[i]; + sp_knot_moveto (knot, &p); + } } } } diff --git a/src/spiral-context.cpp b/src/spiral-context.cpp index ef3e3470b..f912d6614 100644 --- a/src/spiral-context.cpp +++ b/src/spiral-context.cpp @@ -276,7 +276,7 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event) } break; case GDK_MOTION_NOTIFY: - if (dragging && event->motion.state && GDK_BUTTON1_MASK) { + if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) { if ( event_context->within_tolerance && ( abs( (gint) event->motion.x - event_context->xp ) < event_context->tolerance )