ref: f46eceb714ac038e0721f2b16e19e089859bc051
parent: 4169a54831e4dd1549438386302140430501b0cf
author: Simon Tatham <anakin@pobox.com>
date: Mon Jan 19 13:38:29 EST 2009
Keyboard control patch for Solo, from James H. [originally from svn r8418]
--- a/puzzles.but
+++ b/puzzles.but
@@ -942,7 +942,8 @@
If you \e{right}-click in a square and then type a number, that
number will be entered in the square as a \q{pencil mark}. You can
-have pencil marks for multiple numbers in the same square.
+have pencil marks for multiple numbers in the same square. Squares
+containing filled-in numbers cannot also contain pencil marks.
The game pays no attention to pencil marks, so exactly what you use
them for is up to you: you can use them as reminders that a
@@ -956,6 +957,12 @@
All pencil marks in a square are erased when you left-click and type
a number, or when you left-click and press space. Right-clicking and
pressing space will also erase pencil marks.
+
+Alternatively, use the cursor keys to move the mark around the grid.
+Pressing the return key toggles the mark (from a normal mark to a
+pencil mark), and typing a number in is entered in the square in the
+appropriate way; typing in a 0 or using the space bar will clear a
+filled square.
(All the actions described in \k{common-actions} are also available.)
--- a/solo.c
+++ b/solo.c
@@ -2886,7 +2886,7 @@
p += 1 + sprintf(p, "(%d,%d)", bx+1, by+1);
}
}
- assert(p - (char *)state->blocks->blocknames < cr*(sizeof(char *)+80));
+ assert(p - (char *)state->blocks->blocknames < (int)(cr*(sizeof(char *)+80)));
for (i = 0; i < cr; i++)
assert(state->blocks->blocknames[i]);
}
@@ -3176,9 +3176,7 @@
struct game_ui {
/*
* These are the coordinates of the currently highlighted
- * square on the grid, or -1,-1 if there isn't one. When there
- * is, pressing a valid number or letter key or Space will
- * enter that number or letter in the grid.
+ * square on the grid, if hshow = 1.
*/
int hx, hy;
/*
@@ -3186,6 +3184,20 @@
* pencil-mark one or a real one.
*/
int hpencil;
+ /*
+ * This indicates whether or not we're showing the highlight
+ * (used to be hx = hy = -1); important so that when we're
+ * using the cursor keys it doesn't keep coming back at a
+ * fixed position. When hshow = 1, pressing a valid number
+ * or letter key or Space will enter that number or letter in the grid.
+ */
+ int hshow;
+ /*
+ * This indicates whether we're using the highlight as a cursor;
+ * it means that it doesn't vanish on a keypress, and that it is
+ * allowed on immutable squares.
+ */
+ int hcursor;
};
static game_ui *new_ui(game_state *state)
@@ -3192,8 +3204,8 @@
{
game_ui *ui = snew(game_ui);
- ui->hx = ui->hy = -1;
- ui->hpencil = 0;
+ ui->hx = ui->hy = 0;
+ ui->hpencil = ui->hshow = ui->hcursor = 0;
return ui;
}
@@ -3217,14 +3229,14 @@
{
int cr = newstate->cr;
/*
- * We prevent pencil-mode highlighting of a filled square. So
- * if the user has just filled in a square which we had a
- * pencil-mode highlight in (by Undo, or by Redo, or by Solve),
- * then we cancel the highlight.
+ * We prevent pencil-mode highlighting of a filled square, unless
+ * we're using the cursor keys. So if the user has just filled in
+ * a square which we had a pencil-mode highlight in (by Undo, or
+ * by Redo, or by Solve), then we cancel the highlight.
*/
- if (ui->hx >= 0 && ui->hy >= 0 && ui->hpencil &&
+ if (ui->hshow && ui->hpencil && !ui->hcursor &&
newstate->grid[ui->hy * cr + ui->hx] != 0) {
- ui->hx = ui->hy = -1;
+ ui->hshow = 0;
}
}
@@ -3254,14 +3266,17 @@
if (tx >= 0 && tx < cr && ty >= 0 && ty < cr) {
if (button == LEFT_BUTTON) {
if (state->immutable[ty*cr+tx]) {
- ui->hx = ui->hy = -1;
- } else if (tx == ui->hx && ty == ui->hy && ui->hpencil == 0) {
- ui->hx = ui->hy = -1;
+ ui->hshow = 0;
+ } else if (tx == ui->hx && ty == ui->hy &&
+ ui->hshow && ui->hpencil == 0) {
+ ui->hshow = 0;
} else {
ui->hx = tx;
ui->hy = ty;
+ ui->hshow = 1;
ui->hpencil = 0;
}
+ ui->hcursor = 0;
return ""; /* UI activity occurred */
}
if (button == RIGHT_BUTTON) {
@@ -3269,47 +3284,57 @@
* Pencil-mode highlighting for non filled squares.
*/
if (state->grid[ty*cr+tx] == 0) {
- if (tx == ui->hx && ty == ui->hy && ui->hpencil) {
- ui->hx = ui->hy = -1;
+ if (tx == ui->hx && ty == ui->hy &&
+ ui->hshow && ui->hpencil) {
+ ui->hshow = 0;
} else {
ui->hpencil = 1;
ui->hx = tx;
ui->hy = ty;
+ ui->hshow = 1;
}
} else {
- ui->hx = ui->hy = -1;
+ ui->hshow = 0;
}
+ ui->hcursor = 0;
return ""; /* UI activity occurred */
}
}
+ if (IS_CURSOR_MOVE(button)) {
+ move_cursor(button, &ui->hx, &ui->hy, cr, cr, 0);
+ ui->hshow = ui->hcursor = 1;
+ return "";
+ }
+ if (ui->hshow &&
+ (button == CURSOR_SELECT)) {
+ ui->hpencil = 1 - ui->hpencil;
+ ui->hcursor = 1;
+ return "";
+ }
- if (ui->hx != -1 && ui->hy != -1 &&
- ((button >= '1' && button <= '9' && button - '0' <= cr) ||
+ if (ui->hshow &&
+ ((button >= '0' && button <= '9' && button - '0' <= cr) ||
(button >= 'a' && button <= 'z' && button - 'a' + 10 <= cr) ||
(button >= 'A' && button <= 'Z' && button - 'A' + 10 <= cr) ||
- button == ' ' || button == '\010' || button == '\177')) {
+ button == CURSOR_SELECT2 || button == '\010' || button == '\177')) {
int n = button - '0';
if (button >= 'A' && button <= 'Z')
n = button - 'A' + 10;
if (button >= 'a' && button <= 'z')
n = button - 'a' + 10;
- if (button == ' ' || button == '\010' || button == '\177')
+ if (button == CURSOR_SELECT2 || button == '\010' || button == '\177')
n = 0;
/*
- * Can't overwrite this square. In principle this shouldn't
- * happen anyway because we should never have even been
- * able to highlight the square, but it never hurts to be
- * careful.
+ * Can't overwrite this square. This can only happen here
+ * if we're using the cursor keys.
*/
if (state->immutable[ui->hy*cr+ui->hx])
return NULL;
/*
- * Can't make pencil marks in a filled square. In principle
- * this shouldn't happen anyway because we should never
- * have even been able to pencil-highlight the square, but
- * it never hurts to be careful.
+ * Can't make pencil marks in a filled square. Again, this
+ * can only become highlighted if we're using cursor keys.
*/
if (ui->hpencil && state->grid[ui->hy*cr+ui->hx])
return NULL;
@@ -3317,7 +3342,7 @@
sprintf(buf, "%c%d,%d,%d",
(char)(ui->hpencil && n > 0 ? 'P' : 'R'), ui->hx, ui->hy, n);
- ui->hx = ui->hy = -1;
+ if (!ui->hcursor) ui->hshow = 0;
return dupstr(buf);
}
@@ -3651,7 +3676,7 @@
highlight = 1;
/* Highlight active input areas. */
- if (x == ui->hx && y == ui->hy)
+ if (x == ui->hx && y == ui->hy && ui->hshow)
highlight = ui->hpencil ? 2 : 1;
/* Mark obvious errors (ie, numbers which occur more than once
@@ -3706,8 +3731,8 @@
* of pencil marks in the squares.
*/
game_compute_size(params, 900, &pw, &ph);
- *x = pw / 100.0;
- *y = ph / 100.0;
+ *x = pw / 100.0F;
+ *y = ph / 100.0F;
}
static void game_print(drawing *dr, game_state *state, int tilesize)
@@ -4026,3 +4051,5 @@
}
#endif
+
+/* vim: set shiftwidth=4 tabstop=8: */