diff options
| author | Ben Harris <bjh21@bjh21.me.uk> | 2022-12-29 00:07:55 +0000 |
|---|---|---|
| committer | Ben Harris <bjh21@bjh21.me.uk> | 2023-01-01 16:09:19 +0000 |
| commit | 23c9e0a8b2ca587b093cb8f63d73a6632be6cf98 (patch) | |
| tree | 9105d272765d4aaa6e879163cacec9749e09dd51 /pattern.c | |
| parent | 14c025d192579961d1ade51f2a322bd765aef0e5 (diff) | |
| download | puzzles-23c9e0a8b2ca587b093cb8f63d73a6632be6cf98.zip puzzles-23c9e0a8b2ca587b093cb8f63d73a6632be6cf98.tar.gz puzzles-23c9e0a8b2ca587b093cb8f63d73a6632be6cf98.tar.bz2 puzzles-23c9e0a8b2ca587b093cb8f63d73a6632be6cf98.tar.xz | |
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().
Diffstat (limited to 'pattern.c')
| -rw-r--r-- | pattern.c | 38 |
1 files changed, 19 insertions, 19 deletions
@@ -1760,19 +1760,24 @@ static void draw_numbers( int *rowdata = state->common->rowdata + state->common->rowsize * i; int nfit; int j; + int rx, ry, rw, rh; - if (erase) { - if (i < state->common->w) { - draw_rect(dr, TOCOORD(state->common->w, i), 0, - TILE_SIZE, BORDER + TLBORDER(state->common->h) * TILE_SIZE, - COL_BACKGROUND); - } else { - draw_rect(dr, 0, TOCOORD(state->common->h, i - state->common->w), - BORDER + TLBORDER(state->common->w) * TILE_SIZE, TILE_SIZE, - COL_BACKGROUND); - } + if (i < state->common->w) { + rx = TOCOORD(state->common->w, i); + ry = 0; + rw = TILE_SIZE; + rh = BORDER + TLBORDER(state->common->h) * TILE_SIZE; + } else { + rx = 0; + ry = TOCOORD(state->common->h, i - state->common->w); + 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 * tile size. However, if there are more numbers than available @@ -1790,11 +1795,11 @@ static void draw_numbers( char str[80]; if (i < state->common->w) { - x = TOCOORD(state->common->w, i); + x = rx; y = BORDER + TILE_SIZE * (TLBORDER(state->common->h)-1); y -= ((rowlen-j-1)*TILE_SIZE) * (TLBORDER(state->common->h)-1) / nfit; } else { - y = TOCOORD(state->common->h, i - state->common->w); + y = ry; x = BORDER + TILE_SIZE * (TLBORDER(state->common->w)-1); 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); } - if (i < state->common->w) { - draw_update(dr, TOCOORD(state->common->w, i), 0, - 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); - } + unclip(dr); + draw_update(dr, rx, ry, rw, rh); } static void game_redraw(drawing *dr, game_drawstate *ds, |