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
This commit is contained in:
hendricks266 2013-06-03 05:26:44 +00:00
parent e74ac19cd2
commit 6cc62ea2bf

View file

@ -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