Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BaseMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ typedef struct
HFont hBoldFont;
HFont hLightBlur;
HFont hHeavyBlur;
HFont hHudFont;

bool m_fDemosPlayed;
bool m_fNoOldBackground;
Expand Down
49 changes: 49 additions & 0 deletions HudFont.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
HudFont.cpp - engine callbacks for drawing HUD text
Uses mainui's font rendering stack instead of the engine bitmap font
*/
#include "extdll_menu.h"
#include "BaseMenu.h"
#include "font/FontManager.h"
#include "font/BaseFontBackend.h"

// all coordinates and return values are in real screen pixels

int UI_DrawHudCharacter( int x, int y, int ch, int r, int g, int b )
{
if( !g_FontMgr || !uiStatic.hHudFont )
return 0;

CBaseFont *font = g_FontMgr->GetIFontFromHandle( uiStatic.hHudFont );
if( !font )
return 0;

unsigned int color = PackRGBA( r, g, b, 255 );
return font->DrawCharacter( ch, Point( x, y ), font->GetTall( ), color, true );
}

int UI_GetHudFontHeight( void )
{
if( !g_FontMgr || !uiStatic.hHudFont )
return 0;

CBaseFont *font = g_FontMgr->GetIFontFromHandle( uiStatic.hHudFont );
if( !font )
return 0;

return font->GetHeight( );
}

int UI_GetHudCharWidth( int ch )
{
if( !g_FontMgr || !uiStatic.hHudFont )
return 0;

CBaseFont *font = g_FontMgr->GetIFontFromHandle( uiStatic.hHudFont );
if( !font )
return 0;

int a, b, c;
font->GetCharABCWidths( ch, a, b, c );
return a + b + c;
}
3 changes: 3 additions & 0 deletions Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ int KEY_GetKey( const char *binding ); // ripped out from engine
char *StringCopy( const char *input ); // copy string into new memory
void Com_EscapeCommand( char *newCommand, const char *oldCommand, int len );
void UI_EnableTextInput( bool enable );
int UI_DrawHudCharacter( int x, int y, int ch, int r, int g, int b );
int UI_GetHudFontHeight( void );
int UI_GetHudCharWidth( int ch );

void UI_LoadCustomStrings( void );
const char *L( const char *szStr ); // L means Localize!
Expand Down
9 changes: 9 additions & 0 deletions font/FontManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ void CFontManager::VidInit( void )
.Create();
prevScale = scale;
}

// rebuild hud font every VidInit since hud_truetype_size may change
if( uiStatic.hHudFont )
g_FontMgr->DeleteFont( uiStatic.hHudFont );
float hudSize = EngFuncs::GetCvarFloat( "hud_truetype_size" );
if( hudSize <= 0.0f )
hudSize = 16.0f;
uiStatic.hHudFont = CFontBuilder( DEFAULT_MENUFONT, hudSize * scale, DEFAULT_WEIGHT )
.Create();
}

void CFontManager::DeleteAllFonts()
Expand Down
3 changes: 3 additions & 0 deletions sdk_includes/engine/menu_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ typedef struct
void (*pfnConnectionProgress_Connect)( const char *server ); // NULL for local server
void (*pfnConnectionProgress_ChangeLevel)( void );
void (*pfnConnectionProgress_ParseServerInfo)( const char *server );
int (*pfnDrawHudCharacter)( int x, int y, int ch, int r, int g, int b );
int (*pfnGetHudFontHeight)( void );
int (*pfnGetHudCharWidth)( int ch );
} UI_EXTENDED_FUNCTIONS;

typedef int (*MENUAPI)( UI_FUNCTIONS *pFunctionTable, ui_enginefuncs_t* engfuncs, ui_globalvars_t *pGlobals );
Expand Down
5 changes: 4 additions & 1 deletion udll_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ static UI_EXTENDED_FUNCTIONS gExtendedTable =
UI_ConnectionProgress_Precache,
UI_ConnectionProgress_Connect,
UI_ConnectionProgress_ChangeLevel,
UI_ConnectionProgress_ParseServerInfo
UI_ConnectionProgress_ParseServerInfo,
UI_DrawHudCharacter,
UI_GetHudFontHeight,
UI_GetHudCharWidth,
};

extern "C" EXPORT int GetExtAPI( int version, UI_EXTENDED_FUNCTIONS *pFunctionTable, ui_extendedfuncs_t *pEngfuncsFromEngine )
Expand Down