From ac566c5d4f1ae7f74b8f7b5e14f3a3037f709f2f Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Mon, 9 Apr 2012 17:18:36 +0200 Subject: [PATCH] Add a STYLUS_BASED variant to magnets --- magnets.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/magnets.c b/magnets.c index e49b7a5..00a272c 100644 --- a/magnets.c +++ b/magnets.c @@ -1759,7 +1759,7 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds, { int gx = FROMCOORD(x), gy = FROMCOORD(y), idx, curr; char *nullret = NULL, buf[80], movech; - enum { CYCLE_MAGNET, CYCLE_NEUTRAL } action; + enum { CYCLE_MAGNET, CYCLE_NEUTRAL, STYLUS_CYCLE } action; if (IS_CURSOR_MOVE(button)) { move_cursor(button, &ui->cur_x, &ui->cur_y, state->w, state->h, 0); @@ -1779,7 +1779,11 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds, ui->cur_visible = 0; nullret = ""; } +#ifndef STYLUS_BASED action = (button == LEFT_BUTTON) ? CYCLE_MAGNET : CYCLE_NEUTRAL; +#else + action = STYLUS_CYCLE; +#endif } else return NULL; @@ -1790,13 +1794,13 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds, if (action == CYCLE_MAGNET) { /* ... empty --> positive --> negative --> empty ... */ - if (state->grid[idx] == NEUTRAL && state->flags[idx] & GS_SET) + if (curr == NEUTRAL && state->flags[idx] & GS_SET) return nullret; /* can't cycle a magnet from a neutral. */ movech = (curr == EMPTY) ? '+' : (curr == POSITIVE) ? '-' : ' '; } else if (action == CYCLE_NEUTRAL) { /* ... empty -> neutral -> !neutral --> empty ... */ - if (state->grid[idx] != NEUTRAL) + if (curr != NEUTRAL) return nullret; /* can't cycle through neutral from a magnet. */ /* All of these are grid == EMPTY == NEUTRAL; it twiddles @@ -1807,6 +1811,14 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds, movech = ' '; else movech = '.'; + } else if (action == STYLUS_CYCLE) { + /* ... empty --> positive --> negative -> neutral -> !neutral --> empty ... */ + movech = + (curr == NEUTRAL && state->flags[idx] & GS_SET) ? '?' : /* neutral */ + (curr == NEUTRAL && state->flags[idx] & GS_NOTNEUTRAL) ? ' ' : /* !neutral */ + (curr == EMPTY) ? '+' : /* warning: EMPTY==NEUTRAL ... */ + (curr == POSITIVE) ? '-' : + '.'; /* negative */ } else { assert(!"unknown action"); movech = 0; /* placate optimiser */ -- 2.11.4.GIT