From: simon Date: Wed, 8 Feb 2012 23:31:58 +0000 (+0000) Subject: David Nickerson reports odd behaviour involving a drag start point X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/commitdiff_plain/f1992163a16c1d1280f921c918a928c185f3dc74 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). git-svn-id: svn://svn.tartarus.org/sgt/puzzles@9405 cda61777-01e9-0310-a592-d414129be87e --- diff --git a/pearl.c b/pearl.c index fe6b9c3..2ff58f6 100644 --- a/pearl.c +++ b/pearl.c @@ -1717,7 +1717,8 @@ static char *game_text_format(game_state *state) struct game_ui { 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 */ }; @@ -1726,7 +1727,7 @@ static game_ui *new_ui(game_state *state) game_ui *ui = snew(game_ui); int sz = state->shared->sz; - ui->ndragcoords = 0; + ui->ndragcoords = -1; ui->dragcoords = snewn(sz, int); 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)) return; /* square is outside grid */ + if (ui->ndragcoords < 0) + return; /* drag not in progress anyway */ + pos = gy * w + gx; 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]; 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->dragcoords[0] = gy * w + gx; @@ -1925,13 +1932,13 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds, return ""; } - if (button == LEFT_DRAG) { + if (button == LEFT_DRAG && ui->ndragcoords >= 0) { update_ui_drag(state, ui, gx, gy); return ""; } if (IS_MOUSE_RELEASE(button)) { - if (ui->ndragcoords) { + if (ui->ndragcoords > 0) { /* End of a drag: process the cached line data. */ int buflen = 0, bufsize = 256, tmplen; 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 : ""; - } else { + } else if (ui->dragcoords == 0) { /* Click (or tiny drag). Work out which edge we were * closest to. */ int cx, cy; int gx2, gy2, l1, l2, ismark = (button == RIGHT_RELEASE); char movec = ismark ? 'M' : 'F'; + ui->ndragcoords = -1; + /* * We process clicks based on the mouse-down location, * 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; memset(ds->draglines, 0, sz); - if (ui->dragcoords) { + if (ui->ndragcoords > 0) { int i, clearing = TRUE; for (i = 0; i < ui->ndragcoords - 1; i++) { int sx, sy, dx, dy, dir, oldstate, newstate;