aboutsummaryrefslogtreecommitdiff
path: root/pattern.c
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2022-12-29 00:35:02 +0000
committerBen Harris <bjh21@bjh21.me.uk>2023-01-01 16:09:19 +0000
commit1ef9aa4cc26b60d63f134d5f7a3ff9331f8a8b50 (patch)
tree7b53a2c7b18a6c2da968f05cded75bdbf4ba173d /pattern.c
parent23c9e0a8b2ca587b093cb8f63d73a6632be6cf98 (diff)
downloadpuzzles-1ef9aa4cc26b60d63f134d5f7a3ff9331f8a8b50.zip
puzzles-1ef9aa4cc26b60d63f134d5f7a3ff9331f8a8b50.tar.gz
puzzles-1ef9aa4cc26b60d63f134d5f7a3ff9331f8a8b50.tar.bz2
puzzles-1ef9aa4cc26b60d63f134d5f7a3ff9331f8a8b50.tar.xz
Pattern: Pack clues for each row more closely together
Rather than centring each clue in an imaginary box, put equal amounts of space between them (using space characters) and then right-align the whole string. This makes for more efficient use of space, and I think it also looks better when there are two-digit clues. This does introduce a rather grotty (if large) fixed-size buffer for row clues. Probably the row clues should be pre-formatted into a string when the puzzle is set up.
Diffstat (limited to 'pattern.c')
-rw-r--r--pattern.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/pattern.c b/pattern.c
index 73cf12a..9921398 100644
--- a/pattern.c
+++ b/pattern.c
@@ -1790,23 +1790,31 @@ static void draw_numbers(
nfit = max(rowlen, nfit) - 1;
assert(nfit > 0);
- for (j = 0; j < rowlen; j++) {
- int x, y;
- char str[80];
+ if (i < state->common->w) {
+ for (j = 0; j < rowlen; j++) {
+ int x, y;
+ char str[80];
- if (i < state->common->w) {
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 = ry;
- x = BORDER + TILE_SIZE * (TLBORDER(state->common->w)-1);
- x -= ((rowlen-j-1)*TILE_SIZE) * (TLBORDER(state->common->w)-1) / nfit;
+ sprintf(str, "%d", rowdata[j]);
+ draw_text(dr, x+TILE_SIZE/2, y+TILE_SIZE/2, FONT_VARIABLE,
+ TILE_SIZE/2, ALIGN_HCENTRE | ALIGN_VCENTRE, colour, str);
}
+ } else {
+ int x, y;
+ char str[280];
+ size_t off = 0;
- sprintf(str, "%d", rowdata[j]);
- draw_text(dr, x+TILE_SIZE/2, y+TILE_SIZE/2, FONT_VARIABLE,
- TILE_SIZE/2, ALIGN_HCENTRE | ALIGN_VCENTRE, colour, str);
+ for (j = 0; j < rowlen; j++) {
+ assert(off < 260);
+ off += sprintf(str + off, "%s%d", j ? " " : "", rowdata[j]);
+ }
+ y = ry;
+ x = BORDER + TILE_SIZE * (TLBORDER(state->common->w)-1);
+ draw_text(dr, x+TILE_SIZE, y+TILE_SIZE/2, FONT_VARIABLE,
+ TILE_SIZE/2, ALIGN_HRIGHT | ALIGN_VCENTRE, colour, str);
}
unclip(dr);