Client: Add helper functions for right-aligned text drawing.

This commit is contained in:
Marco Cawthorne 2022-01-31 17:04:08 -08:00
parent 155b8c343b
commit eb01a1d8d2
Signed by: eukara
GPG Key ID: C196CD8BA993248A
2 changed files with 48 additions and 1 deletions

View File

@ -33,10 +33,29 @@ typedef struct
} font_s;
void Font_Load(string strFile, font_s &fntNew);
/* standard drawing */
void Font_DrawText(vector vecOrigin, string strText, font_s fnt);
void Font_DrawText_A(vector vecOrigin, string strText, float a, font_s fnt);
void Font_DrawText_RGB(vector vecOrigin, string strText, vector col, font_s fnt);
void Font_DrawText_RGBA(vector vecOrigin, string strText, vector col, float a, font_s fnt);
/* right aligned variants */
void Font_DrawRText(vector vecOrigin, string strText, font_s fnt);
void Font_DrawRText_A(vector vecOrigin, string strText, float a, font_s fnt);
void Font_DrawRText_RGB(vector vecOrigin, string strText, vector col, font_s fnt);
void Font_DrawRText_RGBA(vector vecOrigin, string strText, vector col, float a, font_s fnt);
void Font_DrawField(vector vecOrigin, vector vecSize, string strText, font_s fnt, int iAlignFlags);
/* returns a 0xFFFFFF type color code you can put into your strings */
string Font_RGBtoHex(vector vecColor);
/* gets the height for a single character of the specified font */
int Font_GetHeight(font_s);
/* gets the width of a series of characters */
float Font_StringWidth(string strText, float flColors, font_s fnt);
/* get the 'drawfont' ID, only use this when porting old code quickly. */
float Font_GetID(font_s fnt);

View File

@ -96,7 +96,7 @@ Font_DrawText(vector vecOrigin, string strText, font_s fnt)
}
void
Font_DrawText_A(vector vecOrigin, string strText, vector rgb, float a, font_s fnt)
Font_DrawText_A(vector vecOrigin, string strText, float a, font_s fnt)
{
drawfont = (float)fnt.iID;
drawstring(vecOrigin, strText, [fnt.iScaleX, fnt.iScaleY], fnt.vecColor, a, (float)fnt.iFlags);
@ -119,6 +119,34 @@ Font_DrawText_RGBA(vector vecOrigin, string strText, vector rgb, float a, font_s
drawfont = 0;
}
void
Font_DrawRText(vector vecOrigin, string strText, font_s fnt)
{
vecOrigin[0] -= Font_StringWidth(strText, TRUE, fnt);
Font_DrawText(vecOrigin, strText, fnt);
}
void
Font_DrawRText_A(vector vecOrigin, string strText, float a, font_s fnt)
{
vecOrigin[0] -= Font_StringWidth(strText, TRUE, fnt);
Font_DrawText_A(vecOrigin, strText, a, fnt);
}
void
Font_DrawRText_RGB(vector vecOrigin, string strText, vector rgb, font_s fnt)
{
vecOrigin[0] -= Font_StringWidth(strText, TRUE, fnt);
Font_DrawText_RGB(vecOrigin, strText, rgb, fnt);
}
void
Font_DrawRText_RGBA(vector vecOrigin, string strText, vector rgb, float a, font_s fnt)
{
vecOrigin[0] -= Font_StringWidth(strText, TRUE, fnt);
Font_DrawText_RGBA(vecOrigin, strText, rgb, a, fnt);
}
void
Font_DrawField(vector vecOrigin, vector vecSize, string strText, font_s fnt, int iAlignFlags)
{