mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
Filling: enable keyboard-driven cursor dragging mode.
This commit is contained in:

committed by
Simon Tatham

parent
d5f7c4f871
commit
c469bd285c
58
filling.c
58
filling.c
@ -986,7 +986,7 @@ static char *solve_game(const game_state *state, const game_state *currstate,
|
|||||||
|
|
||||||
struct game_ui {
|
struct game_ui {
|
||||||
int *sel; /* w*h highlighted squares, or NULL */
|
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)
|
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);
|
game_ui *ui = snew(game_ui);
|
||||||
|
|
||||||
ui->sel = NULL;
|
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;
|
return ui;
|
||||||
}
|
}
|
||||||
@ -1023,6 +1023,7 @@ static void game_changed_state(game_ui *ui, const game_state *oldstate,
|
|||||||
sfree(ui->sel);
|
sfree(ui->sel);
|
||||||
ui->sel = NULL;
|
ui->sel = NULL;
|
||||||
}
|
}
|
||||||
|
ui->keydragging = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PREFERRED_TILE_SIZE 32
|
#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)) {
|
if (IS_CURSOR_MOVE(button)) {
|
||||||
ui->cur_visible = 1;
|
ui->cur_visible = 1;
|
||||||
move_cursor(button, &ui->cur_x, &ui->cur_y, w, h, 0);
|
move_cursor(button, &ui->cur_x, &ui->cur_y, w, h, 0);
|
||||||
|
if (ui->keydragging) goto select_square;
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
if (IS_CURSOR_SELECT(button)) {
|
if (button == CURSOR_SELECT) {
|
||||||
if (!ui->cur_visible) {
|
if (!ui->cur_visible) {
|
||||||
ui->cur_visible = 1;
|
ui->cur_visible = 1;
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
ui->keydragging = !ui->keydragging;
|
||||||
|
if (!ui->keydragging) return "";
|
||||||
|
|
||||||
|
select_square:
|
||||||
if (!ui->sel) {
|
if (!ui->sel) {
|
||||||
ui->sel = snewn(w*h, int);
|
ui->sel = snewn(w*h, int);
|
||||||
memset(ui->sel, 0, w*h*sizeof(int));
|
memset(ui->sel, 0, w*h*sizeof(int));
|
||||||
}
|
}
|
||||||
if (state->shared->clues[w*ui->cur_y + ui->cur_x] == 0)
|
if (!state->shared->clues[w*ui->cur_y + ui->cur_x])
|
||||||
ui->sel[w*ui->cur_y + ui->cur_x] ^= 1;
|
ui->sel[w*ui->cur_y + ui->cur_x] = 1;
|
||||||
return "";
|
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) {
|
if (button == '\b' || button == 27) {
|
||||||
case ' ':
|
sfree(ui->sel);
|
||||||
case '\r':
|
ui->sel = NULL;
|
||||||
case '\n':
|
ui->keydragging = FALSE;
|
||||||
case '\b':
|
return "";
|
||||||
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 < '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++) {
|
for (i = 0; i < w*h; i++) {
|
||||||
char buf[32];
|
char buf[32];
|
||||||
if ((ui->sel && ui->sel[i]) ||
|
if ((ui->sel && ui->sel[i]) ||
|
||||||
|
@ -2453,10 +2453,11 @@ press 0, Space, Backspace or Enter to clear it again (or use the Undo
|
|||||||
feature).
|
feature).
|
||||||
|
|
||||||
You can also move around the grid with the cursor keys; typing a digit will
|
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,
|
fill the square containing the cursor with that number; typing 0 will clear
|
||||||
or Enter will clear it. You can also select multiple squares for numbering
|
it. You can also select multiple squares for numbering or clearing with the
|
||||||
or clearing by using the return key, before typing a digit to fill in the
|
return and arrow keys, before typing a digit to fill or clear the highlighted
|
||||||
highlighted squares (as above).
|
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.)
|
(All the actions described in \k{common-actions} are also available.)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user