Untangle: make snapping grid invariant under window resize

In grid-snapping mode, Untangle was still recording vertex positions
in increments of one pixel.  This meant that if you positioned
vertices on a small window, then enlarged the window and positioned
more vertices, the two sets of vertices generally wouldn't line up
with one another.  This was annoying, and obviously silly when
Untangle has a resolution-independent co-ordinate system.  So now the
snapped positions are recorded in a form that doesn't depend on the
tilesize.
This commit is contained in:
Ben Harris
2023-08-14 17:13:01 +01:00
parent 899c7c41ef
commit eeec6b867a

View File

@ -1159,18 +1159,18 @@ static void place_dragged_point(const game_state *state, game_ui *ui,
*/ */
int d = state->params.n - 1; int d = state->params.n - 1;
/* Calculate position in terms of the snapping grid. */
x = d * x / (state->w * ds->tilesize); x = d * x / (state->w * ds->tilesize);
x *= (state->w * ds->tilesize) / d;
x += (state->w * ds->tilesize) / (2*d);
y = d * y / (state->h * ds->tilesize); y = d * y / (state->h * ds->tilesize);
y *= (state->h * ds->tilesize) / d; /* Convert to standard co-ordinates, applying a half-square offset. */
y += (state->h * ds->tilesize) / (2*d); ui->newpoint.x = (x * 2 + 1) * state->w;
} ui->newpoint.y = (y * 2 + 1) * state->h;
ui->newpoint.d = d * 2;
} else {
ui->newpoint.x = x; ui->newpoint.x = x;
ui->newpoint.y = y; ui->newpoint.y = y;
ui->newpoint.d = ds->tilesize; ui->newpoint.d = ds->tilesize;
}
} }
static char *interpret_move(const game_state *state, game_ui *ui, static char *interpret_move(const game_state *state, game_ui *ui,