diff options
| author | Jonas Kölker <jonaskoelker@yahoo.com> | 2015-09-21 17:41:10 +0200 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2015-10-03 16:59:04 +0100 |
| commit | c469bd285cc4f482f49203c16169151d2d869d4a (patch) | |
| tree | 74a240ebc65ca2f286dd5313f1b72ab301e92151 | |
| parent | d5f7c4f871200f9808e284408e28defaa8afbcd3 (diff) | |
| download | puzzles-c469bd285cc4f482f49203c16169151d2d869d4a.zip puzzles-c469bd285cc4f482f49203c16169151d2d869d4a.tar.gz puzzles-c469bd285cc4f482f49203c16169151d2d869d4a.tar.bz2 puzzles-c469bd285cc4f482f49203c16169151d2d869d4a.tar.xz | |
Filling: enable keyboard-driven cursor dragging mode.
| -rw-r--r-- | filling.c | 58 | ||||
| -rw-r--r-- | puzzles.but | 9 |
2 files changed, 46 insertions, 21 deletions
@@ -986,7 +986,7 @@ static char *solve_game(const game_state *state, const game_state *currstate, struct game_ui { int *sel; /* w*h highlighted squares, or NULL */ - int cur_x, cur_y, cur_visible; + int cur_x, cur_y, cur_visible, keydragging; }; static game_ui *new_ui(const game_state *state) @@ -994,7 +994,7 @@ static game_ui *new_ui(const game_state *state) game_ui *ui = snew(game_ui); ui->sel = NULL; - ui->cur_x = ui->cur_y = ui->cur_visible = 0; + ui->cur_x = ui->cur_y = ui->cur_visible = ui->keydragging = 0; return ui; } @@ -1023,6 +1023,7 @@ static void game_changed_state(game_ui *ui, const game_state *oldstate, sfree(ui->sel); ui->sel = NULL; } + ui->keydragging = FALSE; } #define PREFERRED_TILE_SIZE 32 @@ -1079,35 +1080,58 @@ static char *interpret_move(const game_state *state, game_ui *ui, if (IS_CURSOR_MOVE(button)) { ui->cur_visible = 1; move_cursor(button, &ui->cur_x, &ui->cur_y, w, h, 0); + if (ui->keydragging) goto select_square; return ""; } - if (IS_CURSOR_SELECT(button)) { + if (button == CURSOR_SELECT) { if (!ui->cur_visible) { ui->cur_visible = 1; return ""; } + ui->keydragging = !ui->keydragging; + if (!ui->keydragging) return ""; + + select_square: if (!ui->sel) { ui->sel = snewn(w*h, int); memset(ui->sel, 0, w*h*sizeof(int)); } - if (state->shared->clues[w*ui->cur_y + ui->cur_x] == 0) - ui->sel[w*ui->cur_y + ui->cur_x] ^= 1; - return ""; + if (!state->shared->clues[w*ui->cur_y + ui->cur_x]) + ui->sel[w*ui->cur_y + ui->cur_x] = 1; + return ""; + } + if (button == CURSOR_SELECT2) { + if (!ui->cur_visible) { + ui->cur_visible = 1; + return ""; + } + if (!ui->sel) { + ui->sel = snewn(w*h, int); + memset(ui->sel, 0, w*h*sizeof(int)); + } + ui->keydragging = FALSE; + if (!state->shared->clues[w*ui->cur_y + ui->cur_x]) + ui->sel[w*ui->cur_y + ui->cur_x] ^= 1; + for (i = 0; i < w*h && !ui->sel[i]; i++); + if (i == w*h) { + sfree(ui->sel); + ui->sel = NULL; + } + return ""; } - switch (button) { - case ' ': - case '\r': - case '\n': - case '\b': - button = 0; - break; - default: - if (button < '0' || button > '9') return NULL; - button -= '0'; - if (button > (w == 2 && h == 2? 3: max(w, h))) return NULL; + if (button == '\b' || button == 27) { + sfree(ui->sel); + ui->sel = NULL; + ui->keydragging = FALSE; + return ""; } + if (button < '0' || button > '9') return NULL; + button -= '0'; + if (button > (w == 2 && h == 2 ? 3 : max(w, h))) return NULL; + ui->keydragging = FALSE; + for (i = 0; i < w*h; i++) { char buf[32]; if ((ui->sel && ui->sel[i]) || diff --git a/puzzles.but b/puzzles.but index e22c438..44ee326 100644 --- a/puzzles.but +++ b/puzzles.but @@ -2453,10 +2453,11 @@ press 0, Space, Backspace or Enter to clear it again (or use the Undo feature). You can also move around the grid with the cursor keys; typing a digit will -fill the square containing the cursor with that number, or typing 0, Space, -or Enter will clear it. You can also select multiple squares for numbering -or clearing by using the return key, before typing a digit to fill in the -highlighted squares (as above). +fill the square containing the cursor with that number; typing 0 will clear +it. You can also select multiple squares for numbering or clearing with the +return and arrow keys, before typing a digit to fill or clear the highlighted +squares (as above). The space bar adds and removes single squares to and from +the selection. Backspace and escape remove all squares from the selection. (All the actions described in \k{common-actions} are also available.) |