chiark / gitweb /
Rectangles: cancel keyboard drag with Escape.
authorJonas Kölker <jonaskoelker@yahoo.com>
Mon, 21 Sep 2015 15:44:50 +0000 (17:44 +0200)
committerSimon Tatham <anakin@pobox.com>
Sat, 3 Oct 2015 15:59:04 +0000 (16:59 +0100)
puzzles.but
rect.c

index 44ee32666161205dbd96204bab459fdeecafa7de..d0b51de6faf289fa4a9208cd420f0172eb176d93 100644 (file)
@@ -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 04f4588f0e5abce2b908afbdf101189ea474c864..55667c02a8372dd05ba30992c2643e0e247168f3 100644 (file)
--- 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;
     }