Stop the analysis pass in Loopy's redraw routine from being
[sgt/puzzles] / slant.c
diff --git a/slant.c b/slant.c
index 25dd4bc..2f9de52 100644 (file)
--- a/slant.c
+++ b/slant.c
@@ -39,6 +39,8 @@ enum {
     COL_SLANT1,
     COL_SLANT2,
     COL_ERROR,
+    COL_CURSOR,
+    COL_FILLEDSQUARE,
     NCOLOURS
 };
 
@@ -1594,13 +1596,20 @@ static char *game_text_format(game_state *state)
     return ret;
 }
 
+struct game_ui {
+    int cur_x, cur_y, cur_visible;
+};
+
 static game_ui *new_ui(game_state *state)
 {
-    return NULL;
+    game_ui *ui = snew(game_ui);
+    ui->cur_x = ui->cur_y = ui->cur_visible = 0;
+    return ui;
 }
 
 static void free_ui(game_ui *ui)
 {
+    sfree(ui);
 }
 
 static char *encode_ui(game_ui *ui)
@@ -1648,6 +1657,7 @@ static void game_changed_state(game_ui *ui, game_state *oldstate,
 #define ERR_TR    0x00008000L
 #define ERR_BL    0x00010000L
 #define ERR_BR    0x00020000L
+#define CURSOR    0x00040000L
 
 struct game_drawstate {
     int tilesize;
@@ -1656,15 +1666,15 @@ struct game_drawstate {
     long *todraw;
 };
 
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+static char *interpret_move(game_state *state, game_ui *ui, const game_drawstate *ds,
                            int x, int y, int button)
 {
     int w = state->p.w, h = state->p.h;
+    int v;
+    char buf[80];
+    enum { CLOCKWISE, ANTICLOCKWISE, NONE } action = NONE;
 
     if (button == LEFT_BUTTON || button == RIGHT_BUTTON) {
-        int v;
-        char buf[80];
-
        /*
         * This is an utterly awful hack which I should really sort out
         * by means of a proper configuration mechanism. One Slant
@@ -1687,13 +1697,29 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
                    button = LEFT_BUTTON;
            }
        }
+        action = (button == LEFT_BUTTON) ? CLOCKWISE : ANTICLOCKWISE;
 
         x = FROMCOORD(x);
         y = FROMCOORD(y);
         if (x < 0 || y < 0 || x >= w || y >= h)
             return NULL;
+    } else if (IS_CURSOR_SELECT(button)) {
+        if (!ui->cur_visible) {
+            ui->cur_visible = 1;
+            return "";
+        }
+        x = ui->cur_x;
+        y = ui->cur_y;
+
+        action = (button == CURSOR_SELECT2) ? ANTICLOCKWISE : CLOCKWISE;
+    } else if (IS_CURSOR_MOVE(button)) {
+        move_cursor(button, &ui->cur_x, &ui->cur_y, w, h, 0);
+        ui->cur_visible = 1;
+        return "";
+    }
 
-        if (button == LEFT_BUTTON) {
+    if (action != NONE) {
+        if (action == CLOCKWISE) {
             /*
              * Left-clicking cycles blank -> \ -> / -> blank.
              */
@@ -1784,7 +1810,12 @@ static float *game_colours(frontend *fe, int *ncolours)
 {
     float *ret = snewn(3 * NCOLOURS, float);
 
-    frontend_default_colour(fe, &ret[COL_BACKGROUND * 3]);
+    /* CURSOR colour is a background highlight. */
+    game_mkhighlight(fe, ret, COL_BACKGROUND, COL_CURSOR, -1);
+
+    ret[COL_FILLEDSQUARE * 3 + 0] = ret[COL_BACKGROUND * 3 + 0];
+    ret[COL_FILLEDSQUARE * 3 + 1] = ret[COL_BACKGROUND * 3 + 1];
+    ret[COL_FILLEDSQUARE * 3 + 2] = ret[COL_BACKGROUND * 3 + 2];
 
     ret[COL_GRID * 3 + 0] = ret[COL_BACKGROUND * 3 + 0] * 0.7F;
     ret[COL_GRID * 3 + 1] = ret[COL_BACKGROUND * 3 + 1] * 0.7F;
@@ -1843,7 +1874,7 @@ static void draw_clue(drawing *dr, game_drawstate *ds,
     if (v < 0)
        return;
 
-    p[0] = v + '0';
+    p[0] = (char)v + '0';
     p[1] = '\0';
     draw_circle(dr, COORD(x), COORD(y), CLUE_RADIUS,
                bg >= 0 ? bg : COL_BACKGROUND, ccol);
@@ -1862,7 +1893,10 @@ static void draw_tile(drawing *dr, game_drawstate *ds, game_clues *clues,
     clip(dr, COORD(x), COORD(y), TILESIZE, TILESIZE);
 
     draw_rect(dr, COORD(x), COORD(y), TILESIZE, TILESIZE,
-             (v & FLASH) ? COL_GRID : COL_BACKGROUND);
+             (v & FLASH) ? COL_GRID :
+              (v & CURSOR) ? COL_CURSOR :
+             (v & (BACKSLASH | FORWSLASH)) ? COL_FILLEDSQUARE :
+             COL_BACKGROUND);
 
     /*
      * Draw the grid lines.
@@ -2001,6 +2035,8 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
                     ds->todraw[(y+2)*(w+2)+(x+1)] |= ERR_T_L | ERR_C_TL;
                 }
            }
+            if (ui->cur_visible && ui->cur_x == x && ui->cur_y == y)
+                ds->todraw[(y+1)*(w+2)+(x+1)] |= CURSOR;
        }
     }
 
@@ -2043,6 +2079,11 @@ static float game_flash_length(game_state *oldstate, game_state *newstate,
     return 0.0F;
 }
 
+static int game_status(game_state *state)
+{
+    return state->completed ? +1 : 0;
+}
+
 static int game_timing_state(game_state *state, game_ui *ui)
 {
     return TRUE;
@@ -2056,8 +2097,8 @@ static void game_print_size(game_params *params, float *x, float *y)
      * I'll use 6mm squares by default.
      */
     game_compute_size(params, 600, &pw, &ph);
-    *x = pw / 100.0;
-    *y = ph / 100.0;
+    *x = pw / 100.0F;
+    *y = ph / 100.0F;
 }
 
 static void game_print(drawing *dr, game_state *state, int tilesize)
@@ -2154,6 +2195,7 @@ const struct game thegame = {
     game_redraw,
     game_anim_length,
     game_flash_length,
+    game_status,
     TRUE, FALSE, game_print_size, game_print,
     FALSE,                            /* wants_statusbar */
     FALSE, game_timing_state,
@@ -2249,3 +2291,5 @@ int main(int argc, char **argv)
 }
 
 #endif
+
+/* vim: set shiftwidth=4 tabstop=8: */