ref: 8c768e7444707b1985788d610e8f14148bc36ab6
parent: 5ec86c03a8bc911bb3dbd77fb7c827eeca975594
author: Ben Harris <[email protected]>
date: Wed Aug 9 07:30:24 EDT 2023
Use move_cursor() for cursor movement in Guess This makes interpret_move() properly return MOVE_NO_EFFECT when the cursor can't move, and simplifies the code as well.
--- a/guess.c
+++ b/guess.c
@@ -914,25 +914,15 @@
}
/* keyboard input */
- if (button == CURSOR_UP || button == CURSOR_DOWN) {
- ui->display_cur = true;
- if (button == CURSOR_DOWN && (ui->colour_cur+1) < from->params.ncolours)
- ui->colour_cur++;
- if (button == CURSOR_UP && ui->colour_cur > 0)
- ui->colour_cur--;
- ret = MOVE_UI_UPDATE;
- } else if (button == 'h' || button == 'H' || button == '?') {
- compute_hint(from, ui);
- ret = MOVE_UI_UPDATE;
- } else if (button == CURSOR_LEFT || button == CURSOR_RIGHT) {
+ if (IS_CURSOR_MOVE(button)) {
int maxcur = from->params.npegs;
if (ui->markable) maxcur++;
- ui->display_cur = true;
- if (button == CURSOR_RIGHT && (ui->peg_cur+1) < maxcur)
- ui->peg_cur++;
- if (button == CURSOR_LEFT && ui->peg_cur > 0)
- ui->peg_cur--;
+ ret = move_cursor(button, &ui->peg_cur, &ui->colour_cur,
+ maxcur, from->params.ncolours,
+ false, &ui->display_cur);
+ } else if (button == 'h' || button == 'H' || button == '?') {
+ compute_hint(from, ui);
ret = MOVE_UI_UPDATE;
} else if (button == CURSOR_SELECT) {
ui->display_cur = true;