mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 16:05:44 -07:00
David Nickerson reports odd behaviour involving a drag start point
persisting between separate mouse actions. Revamp all uses of the ndragcoords field in an attempt to stamp that out: we now distinguish between active drags (>0), a valid click but no drag yet (0), and a totally invalid situation in which all mouse activity will be ignored until the next fresh attempt (-1). [originally from svn r9405]
This commit is contained in:
25
pearl.c
25
pearl.c
@ -1717,7 +1717,8 @@ static char *game_text_format(game_state *state)
|
|||||||
|
|
||||||
struct game_ui {
|
struct game_ui {
|
||||||
int *dragcoords; /* list of (y*w+x) coords in drag so far */
|
int *dragcoords; /* list of (y*w+x) coords in drag so far */
|
||||||
int ndragcoords; /* number of entries in dragcoords. 0 = no drag. */
|
int ndragcoords; /* number of entries in dragcoords.
|
||||||
|
* 0 = click but no drag yet. -1 = no drag at all */
|
||||||
int clickx, clicky; /* pixel position of initial click */
|
int clickx, clicky; /* pixel position of initial click */
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1726,7 +1727,7 @@ static game_ui *new_ui(game_state *state)
|
|||||||
game_ui *ui = snew(game_ui);
|
game_ui *ui = snew(game_ui);
|
||||||
int sz = state->shared->sz;
|
int sz = state->shared->sz;
|
||||||
|
|
||||||
ui->ndragcoords = 0;
|
ui->ndragcoords = -1;
|
||||||
ui->dragcoords = snewn(sz, int);
|
ui->dragcoords = snewn(sz, int);
|
||||||
|
|
||||||
return ui;
|
return ui;
|
||||||
@ -1805,6 +1806,9 @@ static void update_ui_drag(game_state *state, game_ui *ui, int gx, int gy)
|
|||||||
if (!INGRID(state, gx, gy))
|
if (!INGRID(state, gx, gy))
|
||||||
return; /* square is outside grid */
|
return; /* square is outside grid */
|
||||||
|
|
||||||
|
if (ui->ndragcoords < 0)
|
||||||
|
return; /* drag not in progress anyway */
|
||||||
|
|
||||||
pos = gy * w + gx;
|
pos = gy * w + gx;
|
||||||
|
|
||||||
lastpos = ui->dragcoords[ui->ndragcoords > 0 ? ui->ndragcoords-1 : 0];
|
lastpos = ui->dragcoords[ui->ndragcoords > 0 ? ui->ndragcoords-1 : 0];
|
||||||
@ -1916,7 +1920,10 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
|
|||||||
char tmpbuf[80];
|
char tmpbuf[80];
|
||||||
|
|
||||||
if (IS_MOUSE_DOWN(button)) {
|
if (IS_MOUSE_DOWN(button)) {
|
||||||
if (!INGRID(state, gx, gy)) return NULL;
|
if (!INGRID(state, gx, gy)) {
|
||||||
|
ui->ndragcoords = -1;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
ui->clickx = x; ui->clicky = y;
|
ui->clickx = x; ui->clicky = y;
|
||||||
ui->dragcoords[0] = gy * w + gx;
|
ui->dragcoords[0] = gy * w + gx;
|
||||||
@ -1925,13 +1932,13 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (button == LEFT_DRAG) {
|
if (button == LEFT_DRAG && ui->ndragcoords >= 0) {
|
||||||
update_ui_drag(state, ui, gx, gy);
|
update_ui_drag(state, ui, gx, gy);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_MOUSE_RELEASE(button)) {
|
if (IS_MOUSE_RELEASE(button)) {
|
||||||
if (ui->ndragcoords) {
|
if (ui->ndragcoords > 0) {
|
||||||
/* End of a drag: process the cached line data. */
|
/* End of a drag: process the cached line data. */
|
||||||
int buflen = 0, bufsize = 256, tmplen;
|
int buflen = 0, bufsize = 256, tmplen;
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
@ -1957,16 +1964,18 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->ndragcoords = 0;
|
ui->ndragcoords = -1;
|
||||||
|
|
||||||
return buf ? buf : "";
|
return buf ? buf : "";
|
||||||
} else {
|
} else if (ui->dragcoords == 0) {
|
||||||
/* Click (or tiny drag). Work out which edge we were
|
/* Click (or tiny drag). Work out which edge we were
|
||||||
* closest to. */
|
* closest to. */
|
||||||
int cx, cy;
|
int cx, cy;
|
||||||
int gx2, gy2, l1, l2, ismark = (button == RIGHT_RELEASE);
|
int gx2, gy2, l1, l2, ismark = (button == RIGHT_RELEASE);
|
||||||
char movec = ismark ? 'M' : 'F';
|
char movec = ismark ? 'M' : 'F';
|
||||||
|
|
||||||
|
ui->ndragcoords = -1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We process clicks based on the mouse-down location,
|
* We process clicks based on the mouse-down location,
|
||||||
* because that's more natural for a user to carefully
|
* because that's more natural for a user to carefully
|
||||||
@ -2321,7 +2330,7 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
|
|||||||
flashing = DS_FLASH;
|
flashing = DS_FLASH;
|
||||||
|
|
||||||
memset(ds->draglines, 0, sz);
|
memset(ds->draglines, 0, sz);
|
||||||
if (ui->dragcoords) {
|
if (ui->ndragcoords > 0) {
|
||||||
int i, clearing = TRUE;
|
int i, clearing = TRUE;
|
||||||
for (i = 0; i < ui->ndragcoords - 1; i++) {
|
for (i = 0; i < ui->ndragcoords - 1; i++) {
|
||||||
int sx, sy, dx, dy, dir, oldstate, newstate;
|
int sx, sy, dx, dy, dir, oldstate, newstate;
|
||||||
|
Reference in New Issue
Block a user