summaryrefslogtreecommitdiffstats
path: root/src/gradient-drag.cpp
diff options
context:
space:
mode:
authorKrzysztof Kosi??ski <tweenk.pl@gmail.com>2010-11-25 20:51:17 +0000
committerKrzysztof KosiƄski <tweenk.pl@gmail.com>2010-11-25 20:51:17 +0000
commit0bd9f7e209d522dbcebe0449a91397fdd9e38977 (patch)
tree834c7d02456658b57625ab68cc28f7854a5a85dc /src/gradient-drag.cpp
parentFix handling of x and y attributes of patterns (diff)
parentFix ruler redraw issue on GTK 2.22 (diff)
downloadinkscape-0bd9f7e209d522dbcebe0449a91397fdd9e38977.tar.gz
inkscape-0bd9f7e209d522dbcebe0449a91397fdd9e38977.zip
Merge from trunk
(bzr r9508.1.70)
Diffstat (limited to 'src/gradient-drag.cpp')
-rw-r--r--src/gradient-drag.cpp63
1 files changed, 26 insertions, 37 deletions
diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp
index e7536a86a..d5ab64794 100644
--- a/src/gradient-drag.cpp
+++ b/src/gradient-drag.cpp
@@ -568,22 +568,6 @@ SPObject *GrDraggable::getServer()
return server;
}
-static
-boost::optional<Geom::Point>
-get_snap_vector (Geom::Point p, Geom::Point o, double snap, double initial)
-{
- double r = L2 (p - o);
- if (r < 1e-3) {
- return boost::optional<Geom::Point>();
- }
-
- double angle = atan2 (p - o);
- // snap angle to snaps increments, starting from initial:
- double a_snapped = initial + floor((angle - initial)/snap + 0.5) * snap;
- // calculate the new position and subtract p to get the vector:
- return (o + r * Geom::Point(cos(a_snapped), sin(a_snapped)) - p);
-}
-
static void
gr_knot_moved_handler(SPKnot *knot, Geom::Point const &ppointer, guint state, gpointer data)
{
@@ -645,15 +629,17 @@ gr_knot_moved_handler(SPKnot *knot, Geom::Point const &ppointer, guint state, gp
}
}
- m.setup(desktop);
if (!((state & GDK_SHIFT_MASK) || (state & GDK_CONTROL_MASK))) {
+ m.setup(desktop);
Inkscape::SnappedPoint s = m.freeSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_OTHER_HANDLE));
+ m.unSetup();
if (s.getSnapped()) {
p = s.getPoint();
sp_knot_moveto (knot, p);
}
} else if (state & GDK_CONTROL_MASK) {
SnappedConstraints sc;
+ Inkscape::SnapCandidatePoint scp = Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_OTHER_HANDLE);
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
unsigned snaps = abs(prefs->getInt("/options/rotationsnapsperpi/value", 12));
/* 0 means no snapping. */
@@ -699,36 +685,38 @@ gr_knot_moved_handler(SPKnot *knot, Geom::Point const &ppointer, guint state, gp
dr_snap = dragger->point_original;
}
- boost::optional<Geom::Point> snap_vector;
+ // dr_snap contains the origin of the gradient, whereas p will be the new endpoint which we will try to snap now
+ Inkscape::SnappedPoint sp;
if (dr_snap.isFinite()) {
+ m.setup(desktop);
if (state & GDK_MOD1_MASK) {
// with Alt, snap to the original angle and its perpendiculars
- snap_vector = get_snap_vector (p, dr_snap, M_PI/2, Geom::atan2 (dragger->point_original - dr_snap));
+ sp = m.constrainedAngularSnap(scp, dragger->point_original, dr_snap, 2);
} else {
// with Ctrl, snap to M_PI/snaps
- snap_vector = get_snap_vector (p, dr_snap, M_PI/snaps, 0);
- }
- if (snap_vector) {
- Inkscape::Snapper::SnapConstraint cl(dr_snap, p + *snap_vector - dr_snap);
- Inkscape::SnappedPoint s = m.constrainedSnap(Inkscape::SnapCandidatePoint(p + *snap_vector, Inkscape::SNAPSOURCE_OTHER_HANDLE), cl);
- if (s.getSnapped()) {
- s.setTransformation(s.getPoint() - p);
- sc.points.push_back(s);
- } else {
- Inkscape::SnappedPoint dummy(p + *snap_vector, Inkscape::SNAPSOURCE_OTHER_HANDLE, 0, Inkscape::SNAPTARGET_CONSTRAINED_ANGLE, Geom::L2(*snap_vector), 10000, true, true, false);
- dummy.setTransformation(*snap_vector);
- sc.points.push_back(dummy);
- }
+ sp = m.constrainedAngularSnap(scp, boost::optional<Geom::Point>(), dr_snap, snaps);
}
+ m.unSetup();
+ sc.points.push_back(sp);
}
}
- Inkscape::SnappedPoint bsp = m.findBestSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_OTHER_HANDLE), sc, true); // snap indicator will be displayed if needed
-
- if (bsp.getSnapped()) {
- p += bsp.getTransformation();
- sp_knot_moveto (knot, p);
+ m.setup(desktop, false); // turn of the snap indicator temporarily
+ Inkscape::SnappedPoint bsp = m.findBestSnap(scp, sc, true);
+ m.unSetup();
+ if (!bsp.getSnapped()) {
+ // If we didn't truly snap to an object or to a grid, then we will still have to look for the
+ // closest projection onto one of the constraints. findBestSnap() will not do this for us
+ for (std::list<Inkscape::SnappedPoint>::const_iterator i = sc.points.begin(); i != sc.points.end(); i++) {
+ if (i == sc.points.begin() || (Geom::L2((*i).getPoint() - p) < Geom::L2(bsp.getPoint() - p))) {
+ bsp.setPoint((*i).getPoint());
+ bsp.setTarget(Inkscape::SNAPTARGET_CONSTRAINED_ANGLE);
+ }
+ }
}
+ //p = sc.points.front().getPoint();
+ p = bsp.getPoint();
+ sp_knot_moveto (knot, p);
}
drag->keep_selection = (bool) g_list_find(drag->selected, dragger);
@@ -864,6 +852,7 @@ gr_knot_moved_midpoint_handler(SPKnot */*knot*/, Geom::Point const &ppointer, gu
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop);
m.constrainedSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE, cl);
+ m.unSetup();
}
}
Geom::Point displacement = p - dragger->point;