From 5ec86c03a8bc911bb3dbd77fb7c827eeca975594 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Wed, 9 Aug 2023 09:43:04 +0100 Subject: move_cursor(): handle visible flag; return useful value This adds an extra parameter to move_cursor() that's an optional pointer to a bool indicating whether the cursor is visible. This allows for centralising the common idiom of having the keyboard cursor become visible when a cursor key is pressed. Consistently with the vast majority of existing puzzles, the cursor moves even if it was invisible before, and becomes visible even if it can't move. The function now also returns one of the special constants that can be returned by interpret_move(), so that the caller can correctly return MOVE_UI_UPDATE or MOVE_NO_EFFECT without needing to carefully check for changes itself. Callers are updated only to the extent that they all pass NULL as the new argument. Most of them could now be substantially simplified. --- rect.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'rect.c') diff --git a/rect.c b/rect.c index a20cf18..7228837 100644 --- a/rect.c +++ b/rect.c @@ -2415,7 +2415,8 @@ static char *interpret_move(const game_state *from, game_ui *ui, enddrag = true; erasing = (button == RIGHT_RELEASE); } else if (IS_CURSOR_MOVE(button)) { - move_cursor(button, &ui->cur_x, &ui->cur_y, from->w, from->h, false); + move_cursor(button, &ui->cur_x, &ui->cur_y, from->w, from->h, false, + NULL); ui->cur_visible = true; active = true; if (!ui->cur_dragging) return MOVE_UI_UPDATE; -- cgit v1.1