Commit fc2f67c4 authored by Jonathan Wilkes's avatar Jonathan Wilkes
Browse files

snap to closest grid line until we've travelled half the distance to the next

This gives what is to me smoother and more predictable snapping motion with
respect to the current mouse position.

For example-- imagine the grid cell size is 10 and the selected object under
the mouse already has its top left corner aligned with vertical grid line #2.

If I begin dragging that object to the left, within a single pixel of motion
it will snap to vertical grid line #1 which is 9 pixels away from the
object's current position.

With this commit, the user must drag the object cellsize / 2 pixels before it
snaps to a new position.

To me this seems smoother as it rounds to the nearest grid line rather than
to the grid line with the smallest coordinate value.
parent 6dc3d006
......@@ -5827,10 +5827,10 @@ static void canvas_snap_to_grid(t_canvas *x, int xwas, int ywas, int xnew,
anchor_yoff = ynew - oby;
snap_got_anchor = 1;
}
*dx = floor((xnew - anchor_xoff) / gsize) * gsize -
floor((xwas - anchor_xoff) / gsize) * gsize + snap_dx;
*dy = floor((ynew - anchor_yoff) / gsize) * gsize -
floor((ywas - anchor_yoff) / gsize) * gsize + snap_dy;
*dx = floor((xnew - anchor_xoff + gsize / 2) / gsize) * gsize -
floor((xwas - anchor_xoff + gsize / 2) / gsize) * gsize + snap_dx;
*dy = floor((ynew - anchor_yoff + gsize / 2) / gsize) * gsize -
floor((ywas - anchor_yoff + gsize / 2) / gsize) * gsize + snap_dy;
}
static void delay_move(t_canvas *x)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment