From: Jonas Kölker Date: Mon, 21 Sep 2015 15:44:50 +0000 (+0200) Subject: Rectangles: cancel keyboard drag with Escape. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=sgt-puzzles.git;a=commitdiff_plain;h=e59f820383c9941640d04d7b23e5d964f7ad6ff6 Rectangles: cancel keyboard drag with Escape. --- diff --git a/puzzles.but b/puzzles.but index 44ee326..d0b51de 100644 --- a/puzzles.but +++ b/puzzles.but @@ -786,7 +786,8 @@ around the board. Pressing the return key then allows you to use the cursor keys to drag a rectangle out from that position, and pressing the return key again completes the rectangle. Using the space bar instead of the return key allows you to erase the contents of a -rectangle without affecting its edges, as above. +rectangle without affecting its edges, as above. Pressing escape +cancels a drag. When a rectangle of the correct size is completed, it will be shaded. @@ -2922,6 +2923,7 @@ pressing Space does the same as a right button click. Moving with the cursor keys while holding Shift will place dots in all squares that are moved through. + (All the actions described in \k{common-actions} are also available.) \H{range-parameters} \I{parameters, for Range}Range parameters diff --git a/rect.c b/rect.c index 04f4588..55667c0 100644 --- a/rect.c +++ b/rect.c @@ -2187,18 +2187,24 @@ struct game_ui { int cur_x, cur_y, cur_visible, cur_dragging; }; -static game_ui *new_ui(const game_state *state) +static void reset_ui(game_ui *ui) { - game_ui *ui = snew(game_ui); ui->drag_start_x = -1; ui->drag_start_y = -1; ui->drag_end_x = -1; ui->drag_end_y = -1; - ui->dragged = ui->erasing = FALSE; ui->x1 = -1; ui->y1 = -1; ui->x2 = -1; ui->y2 = -1; + ui->dragged = FALSE; +} + +static game_ui *new_ui(const game_state *state) +{ + game_ui *ui = snew(game_ui); + reset_ui(ui); + ui->erasing = FALSE; ui->cur_x = ui->cur_y = ui->cur_visible = ui->cur_dragging = 0; return ui; } @@ -2381,21 +2387,8 @@ static char *interpret_move(const game_state *from, game_ui *ui, coord_round(FROMCOORD((float)x), FROMCOORD((float)y), &xc, &yc); if (button == LEFT_BUTTON || button == RIGHT_BUTTON) { - if (ui->drag_start_x >= 0 && ui->cur_dragging) { - /* - * If a keyboard drag is in progress, unceremoniously - * cancel it. - */ - ui->drag_start_x = -1; - ui->drag_start_y = -1; - ui->drag_end_x = -1; - ui->drag_end_y = -1; - ui->x1 = -1; - ui->y1 = -1; - ui->x2 = -1; - ui->y2 = -1; - ui->dragged = FALSE; - } + if (ui->drag_start_x >= 0 && ui->cur_dragging) + reset_ui(ui); /* cancel keyboard dragging */ startdrag = TRUE; ui->cur_visible = ui->cur_dragging = FALSE; active = TRUE; @@ -2439,6 +2432,15 @@ static char *interpret_move(const game_state *from, game_ui *ui, startdrag = TRUE; active = TRUE; } + } else if (button == '\b' || button == 27) { + if (!ui->cur_dragging) { + ui->cur_visible = FALSE; + } else { + assert(ui->cur_visible); + reset_ui(ui); /* cancel keyboard dragging */ + ui->cur_dragging = FALSE; + } + return ""; } else if (button != LEFT_DRAG && button != RIGHT_DRAG) { return NULL; } @@ -2515,15 +2517,7 @@ static char *interpret_move(const game_state *from, game_ui *ui, } } - ui->drag_start_x = -1; - ui->drag_start_y = -1; - ui->drag_end_x = -1; - ui->drag_end_y = -1; - ui->x1 = -1; - ui->y1 = -1; - ui->x2 = -1; - ui->y2 = -1; - ui->dragged = FALSE; + reset_ui(ui); active = TRUE; }