mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-27 11:41:16 +00:00
Clean up string width-related functions.
This commit is contained in:
parent
3013c8aa42
commit
df7efe29cb
2 changed files with 36 additions and 147 deletions
179
src/v_video.c
179
src/v_video.c
|
@ -2141,10 +2141,8 @@ char *V_WordWrap(INT32 x, INT32 w, INT32 option, const char *string)
|
|||
return newstring;
|
||||
}
|
||||
|
||||
//
|
||||
// Write a string using a supplied font and scale
|
||||
// NOTE: the text is centered for screens larger than the base width
|
||||
//
|
||||
void V_DrawFontString(INT32 x, INT32 y, INT32 width, INT32 height, INT32 option, fixed_t scale, const char *string, patch_t **font)
|
||||
{
|
||||
V_DrawFontStringAtFixed((fixed_t)x<<FRACBITS, (fixed_t)y<<FRACBITS, width, height, option, scale, string, font);
|
||||
|
@ -2161,10 +2159,8 @@ void V_DrawRightAlignedFontString(INT32 x, INT32 y, INT32 width, INT32 height, I
|
|||
V_DrawRightAlignedFontStringAtFixed((fixed_t)x<<FRACBITS, (fixed_t)y<<FRACBITS, width, height, option, scale, string, font);
|
||||
}
|
||||
|
||||
//
|
||||
// Write a string using a supplied font and scale at a fixed position
|
||||
// NOTE: the text is centered for screens larger than the base width
|
||||
//
|
||||
void V_DrawFontStringAtFixed(fixed_t x, fixed_t y, INT32 width, INT32 height, INT32 option, fixed_t scale, const char *string, patch_t **font)
|
||||
{
|
||||
fixed_t cx = x, cy = y;
|
||||
|
@ -2269,17 +2265,14 @@ void V_DrawCenteredFontStringAtFixed(fixed_t x, fixed_t y, INT32 width, INT32 he
|
|||
V_DrawFontStringAtFixed(x, y, width, height, option, scale, string, font);
|
||||
}
|
||||
|
||||
|
||||
void V_DrawRightAlignedFontStringAtFixed(fixed_t x, fixed_t y, INT32 width, INT32 height, INT32 option, fixed_t scale, const char *string, patch_t **font)
|
||||
{
|
||||
x -= V_FontStringWidth(string, option, width, font)*scale;
|
||||
V_DrawFontStringAtFixed(x, y, width, height, option, scale, string, font);
|
||||
}
|
||||
|
||||
//
|
||||
// Write a string using the hu_font
|
||||
// NOTE: the text is centered for screens larger than the base width
|
||||
//
|
||||
void V_DrawString(INT32 x, INT32 y, INT32 option, const char *string)
|
||||
{
|
||||
V_DrawFontString(x, y, 8, 12, option, FRACUNIT, string, hu_font);
|
||||
|
@ -2295,10 +2288,8 @@ void V_DrawRightAlignedString(INT32 x, INT32 y, INT32 option, const char *string
|
|||
V_DrawRightAlignedFontString(x, y, 8, 12, option, FRACUNIT, string, hu_font);
|
||||
}
|
||||
|
||||
//
|
||||
// Write a string using the hu_font, 0.5x scale
|
||||
// NOTE: the text is centered for screens larger than the base width
|
||||
//
|
||||
void V_DrawSmallString(INT32 x, INT32 y, INT32 option, const char *string)
|
||||
{
|
||||
V_DrawFontString(x, y, 8, 12, option, FRACUNIT/2, string, hu_font);
|
||||
|
@ -2314,10 +2305,8 @@ void V_DrawRightAlignedSmallString(INT32 x, INT32 y, INT32 option, const char *s
|
|||
V_DrawRightAlignedFontString(x, y, 8, 12, option, FRACUNIT/2, string, hu_font);
|
||||
}
|
||||
|
||||
//
|
||||
// Write a string using the tny_font
|
||||
// NOTE: the text is centered for screens larger than the base width
|
||||
//
|
||||
void V_DrawThinString(INT32 x, INT32 y, INT32 option, const char *string)
|
||||
{
|
||||
V_DrawFontString(x, y, 5, 12, option, FRACUNIT, string, tny_font);
|
||||
|
@ -2333,11 +2322,8 @@ void V_DrawRightAlignedThinString(INT32 x, INT32 y, INT32 option, const char *st
|
|||
V_DrawRightAlignedFontString(x, y, 5, 12, option, FRACUNIT, string, tny_font);
|
||||
}
|
||||
|
||||
//
|
||||
// Write a string using the tny_font, 0.5x scale
|
||||
// NOTE: the text is centered for screens larger than the base width
|
||||
//
|
||||
// Literally a wrapper. ~Golden
|
||||
void V_DrawSmallThinString(INT32 x, INT32 y, INT32 option, const char *string)
|
||||
{
|
||||
V_DrawSmallThinStringAtFixed((fixed_t)x<<FRACBITS, (fixed_t)y<<FRACBITS, option, string);
|
||||
|
@ -2393,14 +2379,12 @@ void V_DrawThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *str
|
|||
|
||||
void V_DrawCenteredThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string)
|
||||
{
|
||||
x -= (V_ThinStringWidth(string, option) / 2)<<FRACBITS;
|
||||
V_DrawThinStringAtFixed(x, y, option, string);
|
||||
V_DrawCenteredThinStringAtFixed(x, y, option, string);
|
||||
}
|
||||
|
||||
void V_DrawRightAlignedThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string)
|
||||
{
|
||||
x -= V_ThinStringWidth(string, option)<<FRACBITS;
|
||||
V_DrawThinStringAtFixed(x, y, option, string);
|
||||
V_DrawRightAlignedThinStringAtFixed(x, y, option, string);
|
||||
}
|
||||
|
||||
// Draws a small string at a fixed_t location.
|
||||
|
@ -2885,133 +2869,6 @@ INT16 V_LevelActNumWidth(UINT8 num)
|
|||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find string width from hu_font chars
|
||||
//
|
||||
INT32 V_StringWidth(const char *string, INT32 option)
|
||||
{
|
||||
INT32 c, w = 0;
|
||||
INT32 spacewidth = 4, charwidth = 0;
|
||||
size_t i;
|
||||
|
||||
switch (option & V_SPACINGMASK)
|
||||
{
|
||||
case V_MONOSPACE:
|
||||
spacewidth = 8;
|
||||
/* FALLTHRU */
|
||||
case V_OLDSPACING:
|
||||
charwidth = 8;
|
||||
break;
|
||||
case V_6WIDTHSPACE:
|
||||
spacewidth = 6;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; i < strlen(string); i++)
|
||||
{
|
||||
if (string[i] & 0x80)
|
||||
continue;
|
||||
c = toupper(string[i]) - HU_FONTSTART;
|
||||
if (c < 0 || c >= HU_FONTSIZE || !hu_font[c])
|
||||
w += spacewidth;
|
||||
else
|
||||
w += (charwidth ? charwidth : hu_font[c]->width);
|
||||
}
|
||||
|
||||
if (option & (V_NOSCALESTART|V_NOSCALEPATCH))
|
||||
w *= vid.dupx;
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
//
|
||||
// Find string width from hu_font chars, 0.5x scale
|
||||
//
|
||||
INT32 V_SmallStringWidth(const char *string, INT32 option)
|
||||
{
|
||||
INT32 c, w = 0;
|
||||
INT32 spacewidth = 2, charwidth = 0;
|
||||
size_t i;
|
||||
|
||||
switch (option & V_SPACINGMASK)
|
||||
{
|
||||
case V_MONOSPACE:
|
||||
spacewidth = 4;
|
||||
/* FALLTHRU */
|
||||
case V_OLDSPACING:
|
||||
charwidth = 4;
|
||||
break;
|
||||
case V_6WIDTHSPACE:
|
||||
spacewidth = 3;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; i < strlen(string); i++)
|
||||
{
|
||||
if (string[i] & 0x80)
|
||||
continue;
|
||||
c = toupper(string[i]) - HU_FONTSTART;
|
||||
if (c < 0 || c >= HU_FONTSIZE || !hu_font[c])
|
||||
w += spacewidth;
|
||||
else
|
||||
w += (charwidth ? charwidth : (hu_font[c]->width / 2));
|
||||
}
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
//
|
||||
// Find string width from tny_font chars
|
||||
//
|
||||
INT32 V_ThinStringWidth(const char *string, INT32 option)
|
||||
{
|
||||
INT32 c, w = 0;
|
||||
INT32 spacewidth = 2, charwidth = 0;
|
||||
size_t i;
|
||||
|
||||
switch (option & V_SPACINGMASK)
|
||||
{
|
||||
case V_MONOSPACE:
|
||||
spacewidth = 5;
|
||||
/* FALLTHRU */
|
||||
case V_OLDSPACING:
|
||||
charwidth = 5;
|
||||
break;
|
||||
case V_6WIDTHSPACE:
|
||||
spacewidth = 3;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; i < strlen(string); i++)
|
||||
{
|
||||
if (string[i] & 0x80)
|
||||
continue;
|
||||
c = toupper(string[i]) - HU_FONTSTART;
|
||||
if (c < 0 || c >= HU_FONTSIZE || !tny_font[c])
|
||||
w += spacewidth;
|
||||
else
|
||||
w += (charwidth ? charwidth : tny_font[c]->width);
|
||||
}
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
//
|
||||
// Find string width from tny_font chars, 0.5x scale
|
||||
//
|
||||
INT32 V_SmallThinStringWidth(const char *string, INT32 option)
|
||||
{
|
||||
INT32 w = V_ThinStringWidth(string, option)<<FRACBITS;
|
||||
return w/2 + FRACUNIT; // +FRACUNIT because otherwise it's offset wrong.
|
||||
}
|
||||
|
||||
boolean *heatshifter = NULL;
|
||||
INT32 lastheight = 0;
|
||||
INT32 heatindex[2] = { 0, 0 };
|
||||
|
||||
//
|
||||
// Find string width from supplied font characters
|
||||
//
|
||||
|
@ -3046,9 +2903,41 @@ INT32 V_FontStringWidth(const char *string, INT32 option, INT32 width, patch_t *
|
|||
w += (charwidth ? charwidth : (font[c]->width));
|
||||
}
|
||||
|
||||
if (option & (V_NOSCALESTART|V_NOSCALEPATCH))
|
||||
w *= vid.dupx;
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
// Find string width from hu_font chars
|
||||
INT32 V_StringWidth(const char *string, INT32 option)
|
||||
{
|
||||
return V_FontStringWidth(string, option, 8, hu_font);
|
||||
}
|
||||
|
||||
// Find string width from hu_font chars, 0.5x scale
|
||||
INT32 V_SmallStringWidth(const char *string, INT32 option)
|
||||
{
|
||||
return V_FontStringWidth(string, option, 8, hu_font)/2;
|
||||
}
|
||||
|
||||
|
||||
// Find string width from tny_font chars
|
||||
INT32 V_ThinStringWidth(const char *string, INT32 option)
|
||||
{
|
||||
return V_FontStringWidth(string, option, 5, tny_font);
|
||||
}
|
||||
|
||||
// Find string width from tny_font chars, 0.5x scale
|
||||
INT32 V_SmallThinStringWidth(const char *string, INT32 option)
|
||||
{
|
||||
return V_FontStringWidth(string, option, 5, tny_font)/2;
|
||||
}
|
||||
|
||||
boolean *heatshifter = NULL;
|
||||
INT32 lastheight = 0;
|
||||
INT32 heatindex[2] = { 0, 0 };
|
||||
|
||||
//
|
||||
// V_DoPostProcessor
|
||||
//
|
||||
|
|
|
@ -275,6 +275,8 @@ void V_DrawNameTag(INT32 x, INT32 y, INT32 option, fixed_t scale, UINT8 *basecol
|
|||
INT32 V_CountNameTagLines(const char *string);
|
||||
INT32 V_NameTagWidth(const char *string);
|
||||
|
||||
// Find string width from supplied font chars
|
||||
INT32 V_FontStringWidth(const char *string, INT32 option, INT32 width, patch_t **font);
|
||||
// Find string width from hu_font chars
|
||||
INT32 V_StringWidth(const char *string, INT32 option);
|
||||
// Find string width from hu_font chars, 0.5x scale
|
||||
|
@ -283,8 +285,6 @@ INT32 V_SmallStringWidth(const char *string, INT32 option);
|
|||
INT32 V_ThinStringWidth(const char *string, INT32 option);
|
||||
// Find string width from tny_font chars, 0.5x scale
|
||||
INT32 V_SmallThinStringWidth(const char *string, INT32 option);
|
||||
// Find string width from supplied font chars
|
||||
INT32 V_FontStringWidth(const char *string, INT32 option, INT32 width, patch_t **font);
|
||||
|
||||
void V_DoPostProcessor(INT32 view, postimg_t type, INT32 param);
|
||||
|
||||
|
|
Loading…
Reference in a new issue