mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-26 14:01:45 +00:00
- fixed text size calculations in the status bar.
To avoid errors, all spacing calculations have been added to FFont::StringWidth which already performs proper escape filtering.
This commit is contained in:
parent
17df95d69e
commit
9a3b663e04
3 changed files with 13 additions and 12 deletions
|
@ -1093,7 +1093,7 @@ bool FFont::CanPrint(const uint8_t *string) const
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
int FFont::StringWidth(const uint8_t *string) const
|
||||
int FFont::StringWidth(const uint8_t *string, int spacing) const
|
||||
{
|
||||
int w = 0;
|
||||
int maxw = 0;
|
||||
|
@ -1123,13 +1123,17 @@ int FFont::StringWidth(const uint8_t *string) const
|
|||
maxw = w;
|
||||
w = 0;
|
||||
}
|
||||
else if (spacing >= 0)
|
||||
{
|
||||
w += GetCharWidth(chr) + GlobalKerning + spacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
w += GetCharWidth(chr) + GlobalKerning;
|
||||
w -= spacing;
|
||||
}
|
||||
}
|
||||
|
||||
return MAX(maxw, w);
|
||||
return std::max(maxw, w);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
@ -113,9 +113,9 @@ public:
|
|||
static FFont *FindFont(FName fontname);
|
||||
|
||||
// Return width of string in pixels (unscaled)
|
||||
int StringWidth (const uint8_t *str) const;
|
||||
inline int StringWidth (const char *str) const { return StringWidth ((const uint8_t *)str); }
|
||||
inline int StringWidth (const FString &str) const { return StringWidth ((const uint8_t *)str.GetChars()); }
|
||||
int StringWidth (const uint8_t *str, int spacing = 0) const;
|
||||
inline int StringWidth (const char *str, int spacing = 0) const { return StringWidth ((const uint8_t *)str, spacing); }
|
||||
inline int StringWidth (const FString &str, int spacing = 0) const { return StringWidth ((const uint8_t *)str.GetChars(), spacing); }
|
||||
|
||||
// Checks if the font contains all characters to print this text.
|
||||
bool CanPrint(const uint8_t *str) const;
|
||||
|
|
|
@ -1670,20 +1670,17 @@ void DBaseStatusBar::DrawString(FFont *font, const FString &cstring, double x, d
|
|||
{
|
||||
bool monospaced = monospacing != EMonospacing::Off;
|
||||
double dx = 0;
|
||||
int spacingparm = monospaced ? -spacing : spacing;
|
||||
|
||||
switch (flags & DI_TEXT_ALIGN)
|
||||
{
|
||||
default:
|
||||
break;
|
||||
case DI_TEXT_ALIGN_RIGHT:
|
||||
dx = monospaced
|
||||
? static_cast<int> ((spacing)*cstring.CharacterCount()) //monospaced, so just multiply the character size
|
||||
: static_cast<int> (font->StringWidth(cstring) + (spacing * cstring.CharacterCount()));
|
||||
dx = font->StringWidth(cstring, spacingparm);
|
||||
break;
|
||||
case DI_TEXT_ALIGN_CENTER:
|
||||
dx = monospaced
|
||||
? static_cast<int> ((spacing)*cstring.CharacterCount()) / 2 //monospaced, so just multiply the character size
|
||||
: static_cast<int> (font->StringWidth(cstring) + (spacing * cstring.CharacterCount())) / 2;
|
||||
dx = font->StringWidth(cstring, spacingparm) / 2;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue