From 6cc62ea2bf04e9c0294731c27cd9702ff2fb1128 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Mon, 3 Jun 2013 05:26:44 +0000 Subject: [PATCH] Fix the display of numbers with TEXT_GAMETEXTNUMHACK and TEXT_XOFFSETZERO. (Fix level stats, part 2.) The commit revises the definition of qstrdim when TEXT_[XY]OFFSETZERO are used. With these flags, the offsets the user specifies are now the only dimensions the function cares about in terms of tile placement, so depending on the difference between the offset(s) and the size of the final tile, it may be slightly more or less than the dimensions actually displayed on the screen because tile size is never taken into account. (For example, if your font is nominally 9x7 like the Duke bluefont and you use a TEXT_XOFFSETZERO of 5 with a string five characters long, the total x dimension will be 25 even though the last character will overhang that amount by four pixels. If you use a TEXT_XOFFSETZERO of 12 with the same string, the total x width will be 60 even though there will be three pixels of empty space on the right edge.) This change was made because assigning text an arbitrary constant width in general implies an intent to keep character positions constant even with a variable width font, but returning the visible span of pixels on the screen that the tiles cover would have caused the string to move when alignment options other than the top-left were used. In other words, you can now safely use TEXT_[XY]OFFSETZERO with the alignment options and the text won't jiggle. Also, with TEXT_GAMETEXTNUMHACK, numerals are now effectively TEXT_XOFFSETZERO text that respect the above paragraph, so number count displays can look nice with alignment options too. Having to modify the extent/offset code makes me realize that I'm not quite happy with its structure because it gets tangled juggling different concepts like character width, X offset, and spacing, and how they relate when the line wraps or in terms of the final size. Fortunately, it produces correct results as far as I know, and it's not necessarily ugly, just hard to understand. Handle with care. git-svn-id: https://svn.eduke32.com/eduke32@3850 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/game.c | 38 ++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 366ac9b49..c51116dcc 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -445,6 +445,8 @@ int32_t G_GetStringTile(int32_t font, char *t, int32_t f) return *t - '!' + font; // uses ASCII order } +#define NUMHACKACTIVE ((f & TEXT_GAMETEXTNUMHACK) && t >= '0' && t <= '9') + // qstrdim vec2_t G_ScreenTextSize(const int32_t font, int32_t x, int32_t y, const int32_t z, const int32_t blockangle, @@ -582,7 +584,8 @@ vec2_t G_ScreenTextSize(const int32_t font, case '\n': // near-CODEDUP "if (wrap)" // save the position - pos.x -= offset.x; + if (!(f & TEXT_XOFFSETZERO)) // we want the entire offset to count as the character width + pos.x -= offset.x; SetIfGreater(&size.x, pos.x); // reset the position @@ -623,7 +626,7 @@ vec2_t G_ScreenTextSize(const int32_t font, extent.x = tilesizx[tile] * z; // obnoxious hardcoded functionality from gametext - if ((f & TEXT_GAMETEXTNUMHACK) && t >= '0' && t <= '9') + if (NUMHACKACTIVE) { char numeral = '0'; // this is subject to change as an implementation detail extent.x = (tilesizx[G_GetStringTile(font, &numeral, f)]-1) * z; @@ -639,11 +642,12 @@ vec2_t G_ScreenTextSize(const int32_t font, offset.x = 0; // advance the x coordinate - if (!(f & TEXT_XOFFSETZERO)) + if (!(f & TEXT_XOFFSETZERO) || NUMHACKACTIVE) offset.x += extent.x; // account for text spacing - if (!((f & TEXT_GAMETEXTNUMHACK) && t >= '0' && t <= '9') // this "if" line ONLY == replicating hardcoded stuff + if (!NUMHACKACTIVE // this "if" line ONLY == replicating hardcoded stuff + && t != '\n' && !(f & TEXT_XJUSTIFY)) // to prevent overflow offset.x += xbetween; @@ -711,8 +715,8 @@ vec2_t G_ScreenTextSize(const int32_t font, else pos.x += offset.x; - // save some trouble with calculation - if (!(f & TEXT_XOFFSETZERO)) + // save some trouble with calculation in case the line breaks + if (!(f & TEXT_XOFFSETZERO) || NUMHACKACTIVE) offset.x -= extent.x; // iterate to the next character in the string @@ -720,11 +724,16 @@ vec2_t G_ScreenTextSize(const int32_t font, } // calculate final size - pos.x -= offset.x; - if (f & TEXT_XOFFSETZERO) - pos.x += extent.x; - pos.y -= offset.y; - pos.y += extent.y; + if (!(f & TEXT_XOFFSETZERO)) + pos.x -= offset.x; + + if (!(f & TEXT_YOFFSETZERO)) + { + pos.y -= offset.y; + pos.y += extent.y; + } + else + pos.y += ybetween; SetIfGreater(&size.x, pos.x); SetIfGreater(&size.y, pos.y); @@ -1036,7 +1045,7 @@ vec2_t G_ScreenText(const int32_t font, extent.x = tilesizx[tile] * z; // obnoxious hardcoded functionality from gametext - if ((f & TEXT_GAMETEXTNUMHACK) && t >= '0' && t <= '9') + if (NUMHACKACTIVE) { char numeral = '0'; // this is subject to change as an implementation detail extent.x = (tilesizx[G_GetStringTile(font, &numeral, f)]-1) * z; @@ -1053,11 +1062,12 @@ vec2_t G_ScreenText(const int32_t font, int32_t xoffset = 0; // advance the x coordinate - if (!(f & TEXT_XOFFSETZERO)) + if (!(f & TEXT_XOFFSETZERO) || NUMHACKACTIVE) xoffset += extent.x; // account for text spacing - if (!((f & TEXT_GAMETEXTNUMHACK) && t >= '0' && t <= '9')) // this "if" line ONLY == replicating hardcoded stuff + if (!NUMHACKACTIVE // this "if" line ONLY == replicating hardcoded stuff + && t != '\n') xoffset += xbetween; // line wrapping