mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
Pattern: Clip clues to their proper rectangles
Since the drawing API offers no guarantees about where text drawing might have effects, it's unsafe to erase text other than by wiping the clipping rectangle that was in effect when it was drawn. In practice, this means that all variable (including colour) text should be drawn with a narrow clipping rectangle. It wasn't actually a practical problem that Pattern didn't clip its clues, but I'll like to make its fonts less tiny, which will make it more likely to need clipping in odd cases. This also factors out some repeated computations in draw_numbers().
This commit is contained in:
38
pattern.c
38
pattern.c
@ -1760,19 +1760,24 @@ static void draw_numbers(
|
|||||||
int *rowdata = state->common->rowdata + state->common->rowsize * i;
|
int *rowdata = state->common->rowdata + state->common->rowsize * i;
|
||||||
int nfit;
|
int nfit;
|
||||||
int j;
|
int j;
|
||||||
|
int rx, ry, rw, rh;
|
||||||
|
|
||||||
if (erase) {
|
if (i < state->common->w) {
|
||||||
if (i < state->common->w) {
|
rx = TOCOORD(state->common->w, i);
|
||||||
draw_rect(dr, TOCOORD(state->common->w, i), 0,
|
ry = 0;
|
||||||
TILE_SIZE, BORDER + TLBORDER(state->common->h) * TILE_SIZE,
|
rw = TILE_SIZE;
|
||||||
COL_BACKGROUND);
|
rh = BORDER + TLBORDER(state->common->h) * TILE_SIZE;
|
||||||
} else {
|
} else {
|
||||||
draw_rect(dr, 0, TOCOORD(state->common->h, i - state->common->w),
|
rx = 0;
|
||||||
BORDER + TLBORDER(state->common->w) * TILE_SIZE, TILE_SIZE,
|
ry = TOCOORD(state->common->h, i - state->common->w);
|
||||||
COL_BACKGROUND);
|
rw = BORDER + TLBORDER(state->common->w) * TILE_SIZE;
|
||||||
}
|
rh = TILE_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clip(dr, rx, ry, rw, rh);
|
||||||
|
if (erase)
|
||||||
|
draw_rect(dr, rx, ry, rw, rh, COL_BACKGROUND);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Normally I space the numbers out by the same distance as the
|
* Normally I space the numbers out by the same distance as the
|
||||||
* tile size. However, if there are more numbers than available
|
* tile size. However, if there are more numbers than available
|
||||||
@ -1790,11 +1795,11 @@ static void draw_numbers(
|
|||||||
char str[80];
|
char str[80];
|
||||||
|
|
||||||
if (i < state->common->w) {
|
if (i < state->common->w) {
|
||||||
x = TOCOORD(state->common->w, i);
|
x = rx;
|
||||||
y = BORDER + TILE_SIZE * (TLBORDER(state->common->h)-1);
|
y = BORDER + TILE_SIZE * (TLBORDER(state->common->h)-1);
|
||||||
y -= ((rowlen-j-1)*TILE_SIZE) * (TLBORDER(state->common->h)-1) / nfit;
|
y -= ((rowlen-j-1)*TILE_SIZE) * (TLBORDER(state->common->h)-1) / nfit;
|
||||||
} else {
|
} else {
|
||||||
y = TOCOORD(state->common->h, i - state->common->w);
|
y = ry;
|
||||||
x = BORDER + TILE_SIZE * (TLBORDER(state->common->w)-1);
|
x = BORDER + TILE_SIZE * (TLBORDER(state->common->w)-1);
|
||||||
x -= ((rowlen-j-1)*TILE_SIZE) * (TLBORDER(state->common->w)-1) / nfit;
|
x -= ((rowlen-j-1)*TILE_SIZE) * (TLBORDER(state->common->w)-1) / nfit;
|
||||||
}
|
}
|
||||||
@ -1804,13 +1809,8 @@ static void draw_numbers(
|
|||||||
TILE_SIZE/2, ALIGN_HCENTRE | ALIGN_VCENTRE, colour, str);
|
TILE_SIZE/2, ALIGN_HCENTRE | ALIGN_VCENTRE, colour, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i < state->common->w) {
|
unclip(dr);
|
||||||
draw_update(dr, TOCOORD(state->common->w, i), 0,
|
draw_update(dr, rx, ry, rw, rh);
|
||||||
TILE_SIZE, BORDER + TLBORDER(state->common->h) * TILE_SIZE);
|
|
||||||
} else {
|
|
||||||
draw_update(dr, 0, TOCOORD(state->common->h, i - state->common->w),
|
|
||||||
BORDER + TLBORDER(state->common->w) * TILE_SIZE, TILE_SIZE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void game_redraw(drawing *dr, game_drawstate *ds,
|
static void game_redraw(drawing *dr, game_drawstate *ds,
|
||||||
|
Reference in New Issue
Block a user