mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
Galaxies: clean up draw/undraw code for dragged arrows.
The previous code had multiple bugs. We had completely left out the draw_update after drawing each arrow; we omitted the usual precautionary clip() that constrains each arrow draw to the same rectangle we just saved in the blitter; we re-computed the coordinates of the opposite arrow at undraw time, instead of saving the coordinates we _actually_ used after computing them the first time. And we restored from the two blitters in the same order we saved them, instead of reverse order, which was harmless at the time (the drawing happened after both saves), but is generally bad practice, and needed to be fixed when the code was rearranged to fix the rest of these issues. I noticed these issues in passing, while hunting the diagonal-line bug fixed in the previous commit. These fixes by themselves would have prevented any persistent drawing artefact as a result of that bug (the clip() would have constrained the spurious diagonal line to the region saved by the blitter, so it would have been undrawn again afterwards); but it's better to have fixed the root cause as well!
This commit is contained in:
27
galaxies.c
27
galaxies.c
@ -2383,7 +2383,7 @@ struct game_drawstate {
|
|||||||
blitter *blmirror;
|
blitter *blmirror;
|
||||||
|
|
||||||
bool dragging;
|
bool dragging;
|
||||||
int dragx, dragy;
|
int dragx, dragy, oppx, oppy;
|
||||||
|
|
||||||
int *colour_scratch;
|
int *colour_scratch;
|
||||||
|
|
||||||
@ -3112,7 +3112,7 @@ static game_drawstate *game_new_drawstate(drawing *dr, const game_state *state)
|
|||||||
ds->bl = NULL;
|
ds->bl = NULL;
|
||||||
ds->blmirror = NULL;
|
ds->blmirror = NULL;
|
||||||
ds->dragging = false;
|
ds->dragging = false;
|
||||||
ds->dragx = ds->dragy = 0;
|
ds->dragx = ds->dragy = ds->oppx = ds->oppy = 0;
|
||||||
|
|
||||||
ds->colour_scratch = snewn(ds->w * ds->h, int);
|
ds->colour_scratch = snewn(ds->w * ds->h, int);
|
||||||
|
|
||||||
@ -3274,7 +3274,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds,
|
|||||||
int w = ds->w, h = ds->h;
|
int w = ds->w, h = ds->h;
|
||||||
int x, y;
|
int x, y;
|
||||||
bool flashing = false;
|
bool flashing = false;
|
||||||
int oppx, oppy;
|
|
||||||
|
|
||||||
if (flashtime > 0) {
|
if (flashtime > 0) {
|
||||||
int frame = (int)(flashtime / FLASH_TIME);
|
int frame = (int)(flashtime / FLASH_TIME);
|
||||||
@ -3284,14 +3283,10 @@ static void game_redraw(drawing *dr, game_drawstate *ds,
|
|||||||
if (ds->dragging) {
|
if (ds->dragging) {
|
||||||
assert(ds->bl);
|
assert(ds->bl);
|
||||||
assert(ds->blmirror);
|
assert(ds->blmirror);
|
||||||
calculate_opposite_point(ui, ds, ds->dragx + TILE_SIZE/2,
|
blitter_load(dr, ds->blmirror, ds->oppx, ds->oppy);
|
||||||
ds->dragy + TILE_SIZE/2, &oppx, &oppy);
|
draw_update(dr, ds->oppx, ds->oppy, TILE_SIZE, TILE_SIZE);
|
||||||
oppx -= TILE_SIZE/2;
|
|
||||||
oppy -= TILE_SIZE/2;
|
|
||||||
blitter_load(dr, ds->bl, ds->dragx, ds->dragy);
|
blitter_load(dr, ds->bl, ds->dragx, ds->dragy);
|
||||||
draw_update(dr, ds->dragx, ds->dragy, TILE_SIZE, TILE_SIZE);
|
draw_update(dr, ds->dragx, ds->dragy, TILE_SIZE, TILE_SIZE);
|
||||||
blitter_load(dr, ds->blmirror, oppx, oppy);
|
|
||||||
draw_update(dr, oppx, oppy, TILE_SIZE, TILE_SIZE);
|
|
||||||
ds->dragging = false;
|
ds->dragging = false;
|
||||||
}
|
}
|
||||||
if (ds->cur_visible) {
|
if (ds->cur_visible) {
|
||||||
@ -3449,16 +3444,28 @@ static void game_redraw(drawing *dr, game_drawstate *ds,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ui->dragging) {
|
if (ui->dragging) {
|
||||||
|
int oppx, oppy;
|
||||||
|
|
||||||
ds->dragging = true;
|
ds->dragging = true;
|
||||||
ds->dragx = ui->dx - TILE_SIZE/2;
|
ds->dragx = ui->dx - TILE_SIZE/2;
|
||||||
ds->dragy = ui->dy - TILE_SIZE/2;
|
ds->dragy = ui->dy - TILE_SIZE/2;
|
||||||
calculate_opposite_point(ui, ds, ui->dx, ui->dy, &oppx, &oppy);
|
calculate_opposite_point(ui, ds, ui->dx, ui->dy, &oppx, &oppy);
|
||||||
|
ds->oppx = oppx - TILE_SIZE/2;
|
||||||
|
ds->oppy = oppy - TILE_SIZE/2;
|
||||||
|
|
||||||
blitter_save(dr, ds->bl, ds->dragx, ds->dragy);
|
blitter_save(dr, ds->bl, ds->dragx, ds->dragy);
|
||||||
blitter_save(dr, ds->blmirror, oppx - TILE_SIZE/2, oppy - TILE_SIZE/2);
|
clip(dr, ds->dragx, ds->dragy, TILE_SIZE, TILE_SIZE);
|
||||||
draw_arrow(dr, ds, ui->dx, ui->dy, SCOORD(ui->dotx) - ui->dx,
|
draw_arrow(dr, ds, ui->dx, ui->dy, SCOORD(ui->dotx) - ui->dx,
|
||||||
SCOORD(ui->doty) - ui->dy, COL_ARROW);
|
SCOORD(ui->doty) - ui->dy, COL_ARROW);
|
||||||
|
unclip(dr);
|
||||||
|
draw_update(dr, ds->dragx, ds->dragy, TILE_SIZE, TILE_SIZE);
|
||||||
|
|
||||||
|
blitter_save(dr, ds->blmirror, ds->oppx, ds->oppy);
|
||||||
|
clip(dr, ds->oppx, ds->oppy, TILE_SIZE, TILE_SIZE);
|
||||||
draw_arrow(dr, ds, oppx, oppy, SCOORD(ui->dotx) - oppx,
|
draw_arrow(dr, ds, oppx, oppy, SCOORD(ui->dotx) - oppx,
|
||||||
SCOORD(ui->doty) - oppy, COL_ARROW);
|
SCOORD(ui->doty) - oppy, COL_ARROW);
|
||||||
|
unclip(dr);
|
||||||
|
draw_update(dr, ds->oppx, ds->oppy, TILE_SIZE, TILE_SIZE);
|
||||||
}
|
}
|
||||||
#ifdef EDITOR
|
#ifdef EDITOR
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user