mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-15 01:01:33 +00:00
Make level title font use generalized functions, plus:
- Fixed V_FontStringWidth not accounting for lowercase characters. - Added V_FontStringHeight. - Combine name tag base & outline loading.
This commit is contained in:
parent
412381da4c
commit
7929a89394
4 changed files with 41 additions and 146 deletions
|
@ -63,12 +63,11 @@
|
|||
fontdef_t hu_font;
|
||||
fontdef_t tny_font;
|
||||
fontdef_t cred_font;
|
||||
fontdef_t lt_font;
|
||||
|
||||
patch_t *tallnum[10]; // 0-9
|
||||
patch_t *nightsnum[10]; // 0-9
|
||||
|
||||
// Level title fonts
|
||||
patch_t *lt_font[LT_FONTSIZE];
|
||||
patch_t *ttlnum[10]; // act numbers (0-9)
|
||||
|
||||
// Name tag fonts
|
||||
|
@ -211,6 +210,13 @@ void HU_LoadGraphics(void)
|
|||
cred_font.chars[i] = NULL;
|
||||
else
|
||||
cred_font.chars[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX);
|
||||
|
||||
// level title font
|
||||
sprintf(buffer, "LTFNT%.3d", j);
|
||||
if (W_CheckNumForName(buffer) == LUMPERROR)
|
||||
lt_font.chars[i] = NULL;
|
||||
else
|
||||
lt_font.chars[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX);
|
||||
}
|
||||
|
||||
hu_font.kerning = 0;
|
||||
|
@ -225,17 +231,9 @@ void HU_LoadGraphics(void)
|
|||
cred_font.spacewidth = 16;
|
||||
cred_font.linespacing = 16;
|
||||
|
||||
j = LT_FONTSTART;
|
||||
for (i = 0; i < LT_FONTSIZE; i++)
|
||||
{
|
||||
sprintf(buffer, "LTFNT%.3d", j);
|
||||
j++;
|
||||
|
||||
if (W_CheckNumForName(buffer) == LUMPERROR)
|
||||
lt_font[i] = NULL;
|
||||
else
|
||||
lt_font[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX);
|
||||
}
|
||||
lt_font.kerning = 0;
|
||||
lt_font.spacewidth = 16;
|
||||
lt_font.linespacing = 20;
|
||||
|
||||
//cache numbers too!
|
||||
for (i = 0; i < 10; i++)
|
||||
|
@ -257,26 +255,17 @@ void HU_LoadGraphics(void)
|
|||
ttlnum[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX);
|
||||
}
|
||||
|
||||
// cache the base name tag font for entire game execution
|
||||
// cache the base name tag font & outline for entire game execution
|
||||
j = NT_FONTSTART;
|
||||
for (i = 0; i < NT_FONTSIZE; i++)
|
||||
for (i = 0; i < NT_FONTSIZE; i++, j++)
|
||||
{
|
||||
sprintf(buffer, "NTFNT%.3d", j);
|
||||
j++;
|
||||
|
||||
if (W_CheckNumForName(buffer) == LUMPERROR)
|
||||
ntb_font[i] = NULL;
|
||||
else
|
||||
ntb_font[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX);
|
||||
}
|
||||
|
||||
// cache the outline name tag font for entire game execution
|
||||
j = NT_FONTSTART;
|
||||
for (i = 0; i < NT_FONTSIZE; i++)
|
||||
{
|
||||
sprintf(buffer, "NTFNO%.3d", j);
|
||||
j++;
|
||||
|
||||
if (W_CheckNumForName(buffer) == LUMPERROR)
|
||||
nto_font[i] = NULL;
|
||||
else
|
||||
|
|
|
@ -25,11 +25,6 @@
|
|||
#define HU_FONTEND '~'
|
||||
#define HU_FONTSIZE (HU_FONTEND - HU_FONTSTART + 1)
|
||||
|
||||
// Level title font
|
||||
#define LT_FONTSTART '!' // the first font characters
|
||||
#define LT_FONTEND 'z' // the last font characters
|
||||
#define LT_FONTSIZE (LT_FONTEND - LT_FONTSTART + 1)
|
||||
|
||||
// Name tag font
|
||||
// Used by base and outline font set
|
||||
#define NT_FONTSTART '!' // the first font character
|
||||
|
@ -49,7 +44,7 @@ typedef struct
|
|||
UINT32 linespacing;
|
||||
} fontdef_t;
|
||||
|
||||
extern fontdef_t hu_font, tny_font, cred_font;
|
||||
extern fontdef_t hu_font, tny_font, cred_font, lt_font;
|
||||
|
||||
//------------------------------------
|
||||
// sorted player lines
|
||||
|
@ -85,7 +80,6 @@ extern boolean chat_on;
|
|||
|
||||
extern patch_t *tallnum[10];
|
||||
extern patch_t *nightsnum[10];
|
||||
extern patch_t *lt_font[LT_FONTSIZE];
|
||||
extern patch_t *ntb_font[NT_FONTSIZE];
|
||||
extern patch_t *nto_font[NT_FONTSIZE];
|
||||
extern patch_t *ttlnum[10];
|
||||
|
|
132
src/v_video.c
132
src/v_video.c
|
@ -2533,116 +2533,6 @@ INT32 V_NameTagWidth(const char *string)
|
|||
return w;
|
||||
}
|
||||
|
||||
// Write a string using the level title font
|
||||
// NOTE: the text is centered for screens larger than the base width
|
||||
//
|
||||
void V_DrawLevelTitle(INT32 x, INT32 y, INT32 option, const char *string)
|
||||
{
|
||||
INT32 w, c, cx = x, cy = y, dupx, dupy, scrwidth, left = 0;
|
||||
const char *ch = string;
|
||||
INT32 charflags = (option & V_CHARCOLORMASK);
|
||||
const UINT8 *colormap = NULL;
|
||||
|
||||
if (option & V_NOSCALESTART)
|
||||
{
|
||||
dupx = vid.dupx;
|
||||
dupy = vid.dupy;
|
||||
scrwidth = vid.width;
|
||||
}
|
||||
else
|
||||
{
|
||||
dupx = dupy = 1;
|
||||
scrwidth = vid.width/vid.dupx;
|
||||
left = (scrwidth - BASEVIDWIDTH)/2;
|
||||
scrwidth -= left;
|
||||
}
|
||||
|
||||
if (option & V_NOSCALEPATCH)
|
||||
scrwidth *= vid.dupx;
|
||||
|
||||
for (;;ch++)
|
||||
{
|
||||
if (!*ch)
|
||||
break;
|
||||
if (*ch & 0x80) //color parsing -x 2.16.09
|
||||
{
|
||||
// manually set flags override color codes
|
||||
if (!(option & V_CHARCOLORMASK))
|
||||
charflags = ((*ch & 0x7f) << V_CHARCOLORSHIFT) & V_CHARCOLORMASK;
|
||||
continue;
|
||||
}
|
||||
if (*ch == '\n')
|
||||
{
|
||||
cx = x;
|
||||
cy += 12*dupy;
|
||||
continue;
|
||||
}
|
||||
|
||||
c = *ch - LT_FONTSTART;
|
||||
if (c < 0 || c >= LT_FONTSIZE || !lt_font[c])
|
||||
{
|
||||
cx += 16*dupx;
|
||||
continue;
|
||||
}
|
||||
|
||||
w = lt_font[c]->width * dupx;
|
||||
|
||||
if (cx > scrwidth)
|
||||
continue;
|
||||
if (cx+left + w < 0) //left boundary check
|
||||
{
|
||||
cx += w;
|
||||
continue;
|
||||
}
|
||||
|
||||
colormap = V_GetStringColormap(charflags);
|
||||
V_DrawFixedPatch(cx<<FRACBITS, cy<<FRACBITS, FRACUNIT, option, lt_font[c], colormap);
|
||||
|
||||
cx += w;
|
||||
}
|
||||
}
|
||||
|
||||
// Find string width from lt_font chars
|
||||
//
|
||||
INT32 V_LevelNameWidth(const char *string)
|
||||
{
|
||||
INT32 c, w = 0;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < strlen(string); i++)
|
||||
{
|
||||
if (string[i] & 0x80)
|
||||
continue;
|
||||
c = string[i] - LT_FONTSTART;
|
||||
if (c < 0 || c >= LT_FONTSIZE || !lt_font[c])
|
||||
w += 16;
|
||||
else
|
||||
w += lt_font[c]->width;
|
||||
}
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
// Find max height of the string
|
||||
//
|
||||
INT32 V_LevelNameHeight(const char *string)
|
||||
{
|
||||
INT32 c, w = 0;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < strlen(string); i++)
|
||||
{
|
||||
c = string[i] - LT_FONTSTART;
|
||||
if (c < 0 || c >= LT_FONTSIZE || !lt_font[c])
|
||||
continue;
|
||||
|
||||
if (lt_font[c]->height > w)
|
||||
w = lt_font[c]->height;
|
||||
}
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
// For ST_drawTitleCard
|
||||
// Returns the width of the act num patch(es)
|
||||
INT16 V_LevelActNumWidth(UINT8 num)
|
||||
|
@ -2687,7 +2577,7 @@ INT32 V_FontStringWidth(const char *string, INT32 option, fontdef_t font)
|
|||
{
|
||||
if (string[i] & 0x80)
|
||||
continue;
|
||||
c = toupper(string[i]) - HU_FONTSTART;
|
||||
c = ((option & V_ALLOWLOWERCASE ? string[i] : toupper(string[i])) - HU_FONTSTART);
|
||||
if (c < 0 || c >= HU_FONTSIZE || !font.chars[c])
|
||||
w += spacewidth;
|
||||
else
|
||||
|
@ -2700,6 +2590,26 @@ INT32 V_FontStringWidth(const char *string, INT32 option, fontdef_t font)
|
|||
return w;
|
||||
}
|
||||
|
||||
// Find max string height from supplied font characters
|
||||
//
|
||||
INT32 V_FontStringHeight(const char *string, INT32 option, fontdef_t font)
|
||||
{
|
||||
INT32 c, h = 0;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < strlen(string); i++)
|
||||
{
|
||||
c = string[i] - HU_FONTSTART;
|
||||
if (c < 0 || c >= HU_FONTSIZE || !font.chars[c])
|
||||
continue;
|
||||
|
||||
if (font.chars[c]->height > h)
|
||||
h = font.chars[c]->height;
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
boolean *heatshifter = NULL;
|
||||
INT32 lastheight = 0;
|
||||
INT32 heatindex[2] = { 0, 0 };
|
||||
|
|
|
@ -254,15 +254,14 @@ void V_DrawRightAlignedFontStringAtFixed(fixed_t x, fixed_t y, INT32 option, fix
|
|||
#define V_DrawRightAlignedSmallThinStringAtFixed(x,y,o,str) V_DrawRightAlignedFontStringAtFixed(x,y,o,FRACUNIT/2,FRACUNIT/2,str,tny_font)
|
||||
// draw a string using the credit font
|
||||
#define V_DrawCreditString(x,y,o,str) V_DrawFontStringAtFixed(x,y,o,FRACUNIT,FRACUNIT,str,cred_font)
|
||||
// draw a string using the level title font
|
||||
#define V_DrawLevelTitle(x,y,o,str) V_DrawFontString(x,y,o|V_ALLOWLOWERCASE,FRACUNIT,FRACUNIT,str,lt_font)
|
||||
|
||||
// Draw tall nums, used for menu, HUD, intermission
|
||||
void V_DrawTallNum(INT32 x, INT32 y, INT32 flags, INT32 num);
|
||||
void V_DrawPaddedTallNum(INT32 x, INT32 y, INT32 flags, INT32 num, INT32 digits);
|
||||
void V_DrawLevelActNum(INT32 x, INT32 y, INT32 flags, UINT8 num);
|
||||
|
||||
// Find string width from lt_font chars
|
||||
INT32 V_LevelNameWidth(const char *string);
|
||||
INT32 V_LevelNameHeight(const char *string);
|
||||
INT16 V_LevelActNumWidth(UINT8 num); // act number width
|
||||
|
||||
// Draw a string using the nt_font
|
||||
|
@ -270,8 +269,9 @@ 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
|
||||
// Find string width or height from supplied font chars
|
||||
INT32 V_FontStringWidth(const char *string, INT32 option, fontdef_t font);
|
||||
INT32 V_FontStringHeight(const char *string, INT32 option, fontdef_t font);
|
||||
|
||||
// Defines for old string width functions.
|
||||
#define V_StringWidth(str,o) V_FontStringWidth(str,o,hu_font)
|
||||
|
@ -279,6 +279,8 @@ INT32 V_FontStringWidth(const char *string, INT32 option, fontdef_t font);
|
|||
#define V_ThinStringWidth(str,o) V_FontStringWidth(str,o,tny_font)
|
||||
#define V_SmallThinStringWidth(str,o) V_FontStringWidth(str,o,tny_font)/2
|
||||
#define V_CreditStringWidth(str) V_FontStringWidth(str,0,cred_font)
|
||||
#define V_LevelNameWidth(str) V_FontStringWidth(str,V_ALLOWLOWERCASE,lt_font)
|
||||
#define V_LevelNameHeight(str) V_FontStringHeight(str,V_ALLOWLOWERCASE,lt_font)
|
||||
|
||||
void V_DoPostProcessor(INT32 view, postimg_t type, INT32 param);
|
||||
|
||||
|
|
Loading…
Reference in a new issue