ref: e59f820383c9941640d04d7b23e5d964f7ad6ff6
parent: c469bd285cc4f482f49203c16169151d2d869d4a
author: Jonas Kölker <jonaskoelker@yahoo.com>
date: Mon Sep 21 13:44:50 EDT 2015
Rectangles: cancel keyboard drag with Escape.
--- a/puzzles.but
+++ b/puzzles.but
@@ -786,7 +786,8 @@
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.
@@ -2921,6 +2922,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.)
--- a/rect.c
+++ b/rect.c
@@ -2187,18 +2187,24 @@
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 @@
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 @@
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 @@
}
}
- 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;
}