From eb01a1d8d2338ef6e68aca72575b56c3694eed7d Mon Sep 17 00:00:00 2001 From: Marco Hladik Date: Mon, 31 Jan 2022 17:04:08 -0800 Subject: [PATCH] Client: Add helper functions for right-aligned text drawing. --- src/client/font.h | 19 +++++++++++++++++++ src/client/font.qc | 30 +++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/client/font.h b/src/client/font.h index be75fef6..ee56b391 100644 --- a/src/client/font.h +++ b/src/client/font.h @@ -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); diff --git a/src/client/font.qc b/src/client/font.qc index 48a1ca8d..1eeb0675 100644 --- a/src/client/font.qc +++ b/src/client/font.qc @@ -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) {