state->completed = TRUE;
}
-static game_state *new_game(midend_data *me, game_params *params, char *desc)
+static game_state *new_game(midend *me, game_params *params, char *desc)
{
int n = params->n;
game_state *state = snew(game_state);
struct game_drawstate {
long tilesize;
+ int bg, dragpoint;
+ long *x, *y;
};
static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
*x = *y = COORDLIMIT(params->n) * tilesize;
}
-static void game_set_size(game_drawstate *ds, game_params *params,
- int tilesize)
+static void game_set_size(drawing *dr, game_drawstate *ds,
+ game_params *params, int tilesize)
{
ds->tilesize = tilesize;
}
-static float *game_colours(frontend *fe, game_state *state, int *ncolours)
+static float *game_colours(frontend *fe, int *ncolours)
{
float *ret = snewn(3 * NCOLOURS, float);
return ret;
}
-static game_drawstate *game_new_drawstate(game_state *state)
+static game_drawstate *game_new_drawstate(drawing *dr, game_state *state)
{
struct game_drawstate *ds = snew(struct game_drawstate);
+ int i;
ds->tilesize = 0;
+ ds->x = snewn(state->params.n, long);
+ ds->y = snewn(state->params.n, long);
+ for (i = 0; i < state->params.n; i++)
+ ds->x[i] = ds->y[i] = -1;
+ ds->bg = -1;
+ ds->dragpoint = -1;
return ds;
}
-static void game_free_drawstate(game_drawstate *ds)
+static void game_free_drawstate(drawing *dr, game_drawstate *ds)
{
+ sfree(ds->y);
+ sfree(ds->x);
sfree(ds);
}
return ret;
}
-static void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
+static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
game_state *state, int dir, game_ui *ui,
float animtime, float flashtime)
{
int w, h;
edge *e;
int i, j;
- int bg;
+ int bg, points_moved;
/*
* There's no terribly sensible way to do partial redraws of
else
bg = COL_FLASH2;
+ /*
+ * To prevent excessive spinning on redraw during a completion
+ * flash, we first check to see if _either_ the flash
+ * background colour has changed _or_ at least one point has
+ * moved _or_ a drag has begun or ended, and abandon the redraw
+ * if neither is the case.
+ *
+ * Also in this loop we work out the coordinates of all the
+ * points for this redraw.
+ */
+ points_moved = FALSE;
+ for (i = 0; i < state->params.n; i++) {
+ point p = state->pts[i];
+ long x, y;
+
+ if (ui->dragpoint == i)
+ p = ui->newpoint;
+
+ if (oldstate)
+ p = mix(oldstate->pts[i], p, animtime / ui->anim_length);
+
+ x = p.x * ds->tilesize / p.d;
+ y = p.y * ds->tilesize / p.d;
+
+ if (ds->x[i] != x || ds->y[i] != y)
+ points_moved = TRUE;
+
+ ds->x[i] = x;
+ ds->y[i] = y;
+ }
+
+ if (ds->bg == bg && ds->dragpoint == ui->dragpoint && !points_moved)
+ return; /* nothing to do */
+
+ ds->dragpoint = ui->dragpoint;
+ ds->bg = bg;
+
game_compute_size(&state->params, ds->tilesize, &w, &h);
- draw_rect(fe, 0, 0, w, h, bg);
+ draw_rect(dr, 0, 0, w, h, bg);
/*
* Draw the edges.
*/
for (i = 0; (e = index234(state->graph->edges, i)) != NULL; i++) {
- point p1, p2;
- long x1, y1, x2, y2;
-
- p1 = state->pts[e->a];
- p2 = state->pts[e->b];
- if (ui->dragpoint == e->a)
- p1 = ui->newpoint;
- else if (ui->dragpoint == e->b)
- p2 = ui->newpoint;
-
- if (oldstate) {
- p1 = mix(oldstate->pts[e->a], p1, animtime / ui->anim_length);
- p2 = mix(oldstate->pts[e->b], p2, animtime / ui->anim_length);
- }
-
- x1 = p1.x * ds->tilesize / p1.d;
- y1 = p1.y * ds->tilesize / p1.d;
- x2 = p2.x * ds->tilesize / p2.d;
- y2 = p2.y * ds->tilesize / p2.d;
-
- draw_line(fe, x1, y1, x2, y2,
+ draw_line(dr, ds->x[e->a], ds->y[e->a], ds->x[e->b], ds->y[e->b],
#ifdef SHOW_CROSSINGS
(oldstate?oldstate:state)->crosses[i] ?
COL_CROSSEDLINE :
int thisc = (j == 0 ? COL_POINT :
j == 1 ? COL_NEIGHBOUR : COL_DRAGPOINT);
for (i = 0; i < state->params.n; i++) {
- long x, y;
int c;
- point p = state->pts[i];
if (ui->dragpoint == i) {
- p = ui->newpoint;
c = COL_DRAGPOINT;
} else if (ui->dragpoint >= 0 &&
isedge(state->graph->edges, ui->dragpoint, i)) {
c = COL_POINT;
}
- if (oldstate)
- p = mix(oldstate->pts[i], p, animtime / ui->anim_length);
-
if (c == thisc) {
- x = p.x * ds->tilesize / p.d;
- y = p.y * ds->tilesize / p.d;
-
#ifdef VERTEX_NUMBERS
- draw_circle(fe, x, y, DRAG_THRESHOLD, bg, bg);
+ draw_circle(dr, ds->x[i], ds->y[i], DRAG_THRESHOLD, bg, bg);
{
char buf[80];
sprintf(buf, "%d", i);
- draw_text(fe, x, y, FONT_VARIABLE, DRAG_THRESHOLD*3/2,
+ draw_text(dr, ds->x[i], ds->y[i], FONT_VARIABLE,
+ DRAG_THRESHOLD*3/2,
ALIGN_VCENTRE|ALIGN_HCENTRE, c, buf);
}
#else
- draw_circle(fe, x, y, CIRCLE_RADIUS, c, COL_OUTLINE);
+ draw_circle(dr, ds->x[i], ds->y[i], CIRCLE_RADIUS,
+ c, COL_OUTLINE);
#endif
}
}
}
- draw_update(fe, 0, 0, w, h);
+ draw_update(dr, 0, 0, w, h);
}
static float game_anim_length(game_state *oldstate, game_state *newstate,
return 0.0F;
}
-static int game_wants_statusbar(void)
+static int game_timing_state(game_state *state, game_ui *ui)
+{
+ return TRUE;
+}
+
+static void game_print_size(game_params *params, float *x, float *y)
{
- return FALSE;
}
-static int game_timing_state(game_state *state, game_ui *ui)
+static void game_print(drawing *dr, game_state *state, int tilesize)
{
- return TRUE;
}
#ifdef COMBINED
game_redraw,
game_anim_length,
game_flash_length,
- game_wants_statusbar,
+ FALSE, FALSE, game_print_size, game_print,
+ FALSE, /* wants_statusbar */
FALSE, game_timing_state,
- SOLVE_ANIMATES, /* mouse_priorities */
+ SOLVE_ANIMATES, /* flags */
};