Using idTech 5 fonts for gui and console.

This commit is contained in:
Justin Marshall
2026-05-28 19:17:27 -07:00
parent e4c87fd5a4
commit 0591e0b5c1
28 changed files with 459 additions and 1019 deletions
+39 -6
View File
@@ -523,6 +523,42 @@ void idEditField::SetBuffer( const char *buf ) {
SetCursor( strlen( buffer ) );
}
static int EditFieldSmallStringWidth( const char *text, int length ) {
if ( text == NULL || length <= 0 ) {
return 0;
}
idFont *font = renderSystem->RegisterFont( "editor" );
if ( font == NULL ) {
return length * SMALLCHAR_WIDTH;
}
int width = 0;
for ( int i = 0; text[i] != '\0' && i < length; i++ ) {
if ( idStr::IsColor( text + i ) ) {
i++;
continue;
}
float advance = font->GetGlyphWidth( 0.255f, (const unsigned char)text[i] );
if ( advance <= 0.0f ) {
advance = SMALLCHAR_WIDTH;
}
width += idMath::FtoiFast( advance + 0.75f );
}
return width;
}
static int EditFieldSmallCharLeft( int ch ) {
idFont *font = renderSystem->RegisterFont( "editor" );
if ( font == NULL ) {
return 0;
}
scaledGlyphInfo_t glyphInfo;
font->GetScaledGlyph( 0.255f, ch & 255, glyphInfo );
return idMath::FtoiFast( glyphInfo.left );
}
/*
===============
idEditField::Draw
@@ -534,9 +570,6 @@ void idEditField::Draw( int x, int y, int width, bool showCursor, const idMateri
int prestep;
int cursorChar;
char str[MAX_EDIT_LINE];
int size;
size = SMALLCHAR_WIDTH;
drawLen = widthInChars;
len = strlen( buffer ) + 1;
@@ -587,9 +620,9 @@ void idEditField::Draw( int x, int y, int width, bool showCursor, const idMateri
}
if ( idKeyInput::GetOverstrikeMode() ) {
cursorChar = 11;
cursorChar = '_';
} else {
cursorChar = 10;
cursorChar = '|';
}
// Move the cursor back to account for color codes
@@ -600,5 +633,5 @@ void idEditField::Draw( int x, int y, int width, bool showCursor, const idMateri
}
}
renderSystem->DrawSmallChar( x + ( cursor - prestep ) * size, y, cursorChar, shader );
renderSystem->DrawSmallChar( x + EditFieldSmallStringWidth( str, cursor - prestep ) - EditFieldSmallCharLeft( cursorChar ), y, cursorChar, shader );
}