X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/08dd70c37cb71db7e157bfff0246d9a9c6f50cf0..863c39456be84101fc24b8323960d8b324657bb6:/rect.c diff --git a/rect.c b/rect.c index b6e71d2..35d7c25 100644 --- a/rect.c +++ b/rect.c @@ -917,7 +917,7 @@ int coord_round(float coord) /* * Find the distance from us to that integer. */ - dist = fabs(coord - (float)i); + dist = (float)fabs(coord - (float)i); /* * If we're within the tolerance limit, return the edge @@ -1009,38 +1009,45 @@ game_state *make_move(game_state *from, game_ui *ui, int x, int y, int button) active = TRUE; } - if (enddrag && (xc >= 0 && xc <= 2*from->w && - yc >= 0 && yc <= 2*from->h)) { - ret = dup_game(from); + ret = NULL; - if (ui->dragged) { - ui_draw_rect(ret, ui, ret->hedge, ret->vedge, 1); - } else { - if ((xc & 1) && !(yc & 1) && HRANGE(from,xc/2,yc/2)) { - hedge(ret,xc/2,yc/2) = !hedge(ret,xc/2,yc/2); - } - if ((yc & 1) && !(xc & 1) && VRANGE(from,xc/2,yc/2)) { - vedge(ret,xc/2,yc/2) = !vedge(ret,xc/2,yc/2); - } - } + if (enddrag) { + if (xc >= 0 && xc <= 2*from->w && + yc >= 0 && yc <= 2*from->h) { + ret = dup_game(from); - ui->drag_start_x = -1; - ui->drag_start_y = -1; - ui->drag_end_x = -1; - ui->drag_end_y = -1; - ui->dragged = FALSE; - active = TRUE; + if (ui->dragged) { + ui_draw_rect(ret, ui, ret->hedge, ret->vedge, 1); + } else { + if ((xc & 1) && !(yc & 1) && HRANGE(from,xc/2,yc/2)) { + hedge(ret,xc/2,yc/2) = !hedge(ret,xc/2,yc/2); + } + if ((yc & 1) && !(xc & 1) && VRANGE(from,xc/2,yc/2)) { + vedge(ret,xc/2,yc/2) = !vedge(ret,xc/2,yc/2); + } + } - if (!memcmp(ret->hedge, from->hedge, from->w*from->h) && - !memcmp(ret->vedge, from->vedge, from->w*from->h)) { - free_game(ret); - } else - return ret; /* a move has been made */ + if (!memcmp(ret->hedge, from->hedge, from->w*from->h) && + !memcmp(ret->vedge, from->vedge, from->w*from->h)) { + free_game(ret); + ret = NULL; + } + } + + ui->drag_start_x = -1; + ui->drag_start_y = -1; + ui->drag_end_x = -1; + ui->drag_end_y = -1; + ui->dragged = FALSE; + active = TRUE; } - if (active) + if (ret) + return ret; /* a move has been made */ + else if (active) return from; /* UI activity has occurred */ - return NULL; + else + return NULL; } /* ---------------------------------------------------------------------- @@ -1129,7 +1136,7 @@ void draw_tile(frontend *fe, game_state *state, int x, int y, if (grid(state,x,y)) { sprintf(str, "%d", grid(state,x,y)); draw_text(fe, cx+TILE_SIZE/2, cy+TILE_SIZE/2, FONT_VARIABLE, - TILE_SIZE/3, ALIGN_HCENTRE | ALIGN_VCENTRE, COL_TEXT, str); + TILE_SIZE/2, ALIGN_HCENTRE | ALIGN_VCENTRE, COL_TEXT, str); } /* @@ -1209,9 +1216,15 @@ void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate, } if (!ds->started) { + draw_rect(fe, 0, 0, + state->w * TILE_SIZE + 2*BORDER + 1, + state->h * TILE_SIZE + 2*BORDER + 1, COL_BACKGROUND); draw_rect(fe, COORD(0)-1, COORD(0)-1, ds->w*TILE_SIZE+3, ds->h*TILE_SIZE+3, COL_LINE); ds->started = TRUE; + draw_update(fe, 0, 0, + state->w * TILE_SIZE + 2*BORDER + 1, + state->h * TILE_SIZE + 2*BORDER + 1); } for (x = 0; x < state->w; x++)