shithub: puzzles

Download patch

ref: 4e724b25c276ec84ce5c95041c0cb3c0256fa388
parent: 2b6c6dce34b9867fd18faed4ca9be6caf4e45bf5
author: Ben Harris <bjh21@bjh21.me.uk>
date: Wed Aug 9 16:38:39 EDT 2023

Flip: use move_cursor() for cursor movement

--- a/flip.c
+++ b/flip.c
@@ -982,22 +982,9 @@
                 return MOVE_NO_EFFECT;
             }
         }
-    }
-    else if (IS_CURSOR_MOVE(button)) {
-        int dx = 0, dy = 0;
-        switch (button) {
-        case CURSOR_UP:         dy = -1; break;
-        case CURSOR_DOWN:       dy = 1; break;
-        case CURSOR_RIGHT:      dx = 1; break;
-        case CURSOR_LEFT:       dx = -1; break;
-        default: assert(!"shouldn't get here");
-        }
-        ui->cx += dx; ui->cy += dy;
-        ui->cx = min(max(ui->cx, 0), state->w - 1);
-        ui->cy = min(max(ui->cy, 0), state->h - 1);
-        ui->cdraw = true;
-        nullret = MOVE_UI_UPDATE;
-    }
+    } else if (IS_CURSOR_MOVE(button))
+        nullret = move_cursor(button, &ui->cx, &ui->cy, state->w, state->h,
+                              false, &ui->cdraw);
 
     return nullret;
 }