mirror of
https://github.com/jmarshall23/DoomRTX.git
synced 2026-08-12 16:21:04 +02:00
Using idTech 5 fonts for gui and console.
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user