- made adjustments to the text placement on the summary screen.

With extended fonts much of the old code did not work anymore, this needed more precise checks for the sources of the printed texts.
This commit is contained in:
Christoph Oelckers 2019-07-30 10:52:24 +02:00
parent 370f5ef234
commit c36dc137ba
5 changed files with 123 additions and 24 deletions

View File

@ -1107,6 +1107,53 @@ int FFont::StringWidth(const uint8_t *string) const
return MAX(maxw, w); return MAX(maxw, w);
} }
//==========================================================================
//
// Get the largest ascender in the first line of this text.
//
//==========================================================================
int FFont::GetMaxAscender(const uint8_t* string) const
{
int retval = 0;
while (*string)
{
auto chr = GetCharFromString(string);
if (chr == TEXTCOLOR_ESCAPE)
{
// We do not need to check for UTF-8 in here.
if (*string == '[')
{
while (*string != '\0' && *string != ']')
{
++string;
}
}
if (*string != '\0')
{
++string;
}
continue;
}
else if (chr == '\n')
{
break;
}
else
{
auto ctex = GetChar(chr, CR_UNTRANSLATED, nullptr);
if (ctex)
{
auto offs = int(ctex->GetScaledTopOffset(0));
if (offs > retval) retval = offs;
}
}
}
return retval;
}
//========================================================================== //==========================================================================
// //
// FFont :: LoadTranslations // FFont :: LoadTranslations

View File

@ -103,6 +103,9 @@ public:
int GetSpaceWidth () const { return SpaceWidth; } int GetSpaceWidth () const { return SpaceWidth; }
int GetHeight () const { return FontHeight; } int GetHeight () const { return FontHeight; }
int GetDefaultKerning () const { return GlobalKerning; } int GetDefaultKerning () const { return GlobalKerning; }
int GetMaxAscender(const uint8_t* text) const;
int GetMaxAscender(const char* text) const { return GetMaxAscender((uint8_t*)text); }
int GetMaxAscender(const FString &text) const { return GetMaxAscender((uint8_t*)text.GetChars()); }
virtual void LoadTranslations(); virtual void LoadTranslations();
FName GetName() const { return FontName; } FName GetName() const { return FontName; }

View File

@ -2032,6 +2032,19 @@ DEFINE_ACTION_FUNCTION_NATIVE(FFont, StringWidth, StringWidth)
ACTION_RETURN_INT(StringWidth(self, str)); ACTION_RETURN_INT(StringWidth(self, str));
} }
static int GetMaxAscender(FFont* font, const FString& str)
{
const char* txt = str[0] == '$' ? GStrings(&str[1]) : str.GetChars();
return font->GetMaxAscender(txt);
}
DEFINE_ACTION_FUNCTION_NATIVE(FFont, GetMaxAscender, GetMaxAscender)
{
PARAM_SELF_STRUCT_PROLOGUE(FFont);
PARAM_STRING(str);
ACTION_RETURN_INT(GetMaxAscender(self, str));
}
static int CanPrint(FFont *font, const FString &str) static int CanPrint(FFont *font, const FString &str)
{ {
const char *txt = str[0] == '$' ? GStrings(&str[1]) : str.GetChars(); const char *txt = str[0] == '$' ? GStrings(&str[1]) : str.GetChars();

View File

@ -320,6 +320,7 @@ struct Font native
native int GetCharWidth(int code); native int GetCharWidth(int code);
native int StringWidth(String code); native int StringWidth(String code);
native int GetMaxAscender(String code);
native bool CanPrint(String code); native bool CanPrint(String code);
native int GetHeight(); native int GetHeight();
native int GetDisplacement(); native int GetDisplacement();

View File

@ -149,7 +149,7 @@ class StatusScreen abstract play version("2.5")
// //
//==================================================================== //====================================================================
int, int DrawName(int y, TextureID tex, String levelname) int DrawName(int y, TextureID tex, String levelname)
{ {
// draw <LevelName> // draw <LevelName>
if (tex.isValid()) if (tex.isValid())
@ -161,7 +161,7 @@ class StatusScreen abstract play version("2.5")
// patches with vast amounts of empty space at the bottom. // patches with vast amounts of empty space at the bottom.
size.Y = TexMan.CheckRealHeight(tex); size.Y = TexMan.CheckRealHeight(tex);
} }
return y + int(Size.Y), (BigFont.GetHeight() - BigFont.GetDisplacement()) * CleanYfac / 4; return y + int(Size.Y) * CleanYfac;
} }
else if (levelname.Length() > 0) else if (levelname.Length() > 0)
{ {
@ -176,9 +176,9 @@ class StatusScreen abstract play version("2.5")
screen.DrawText(mapname.mFont, mapname.mColor, (screen.GetWidth() - lines.StringWidth(i) * CleanXfac) / 2, y + h, lines.StringAt(i), DTA_CleanNoMove, true); screen.DrawText(mapname.mFont, mapname.mColor, (screen.GetWidth() - lines.StringWidth(i) * CleanXfac) / 2, y + h, lines.StringAt(i), DTA_CleanNoMove, true);
h += lumph; h += lumph;
} }
return y + h, (mapname.mFont.GetHeight() - mapname.mFont.GetDisplacement())/4; return y + h;
} }
return 0, 0; return 0;
} }
//==================================================================== //====================================================================
@ -232,16 +232,34 @@ class StatusScreen abstract play version("2.5")
virtual int drawLF () virtual int drawLF ()
{ {
int y = TITLEY * CleanYfac; bool ispatch = wbs.LName0.isValid();
int oldy = TITLEY * CleanYfac;
int h; int h;
[y, h] = DrawName(y, wbs.LName0, lnametexts[0]); if (!ispatch)
{
let asc = mapname.mFont.GetMaxAscender(lnametexts[1]);
if (asc > TITLEY - 2)
{
oldy = (asc+2) * CleanYfac;
}
}
// Adjustment for different font sizes for map name and 'finished'. int y = DrawName(oldy, wbs.LName0, lnametexts[0]);
let fontspace1 = finished.mFont.GetDisplacement();
let fontspace2 = ((h + (finished.mFont.GetHeight() - fontspace1)/4)) / 2;
y += max(0, fontspace2 - fontspace1) * CleanYFac; // If the displayed info is made of patches we need some additional offsetting here.
if (ispatch)
{
int h1 = BigFont.GetHeight() - BigFont.GetDisplacement();
int h2 = (y - oldy) / CleanYfac / 4;
let disp = min(h1, h2);
// The offset getting applied here must at least be as tall as the largest ascender in the following text to avoid overlaps.
if (!TexMan.OkForLocalization(finishedPatch, "$WI_FINISHED"))
{
disp += finished.mFont.GetMaxAscender("$WI_FINISHED");
}
y += disp * CleanYfac;
}
// draw "Finished!" // draw "Finished!"
@ -266,19 +284,36 @@ class StatusScreen abstract play version("2.5")
virtual void drawEL () virtual void drawEL ()
{ {
int y = TITLEY * CleanYfac; bool ispatch = TexMan.OkForLocalization(enteringPatch, "$WI_ENTERING");
int oldy = TITLEY * CleanYfac;
y = DrawPatchOrText(y, entering, enteringPatch, "$WI_ENTERING"); if (!ispatch)
let h = (entering.mFont.GetHeight() - entering.mFont.GetDisplacement()) / 4; {
let asc = entering.mFont.GetMaxAscender("$WI_ENTERING");
if (asc > TITLEY - 2)
{
oldy = (asc+2) * CleanYfac;
}
}
int y = DrawPatchOrText(oldy, entering, enteringPatch, "$WI_ENTERING");
// If the displayed info is made of patches we need some additional offsetting here.
if (ispatch)
{
int h1 = BigFont.GetHeight() - BigFont.GetDisplacement();
let size = TexMan.GetScaledSize(enteringPatch);
int h2 = int(size.Y);
let disp = min(h1, h2) / 4;
// The offset getting applied here must at least be as tall as the largest ascender in the following text to avoid overlaps.
if (!wbs.LName1.isValid()) if (!wbs.LName1.isValid())
{ {
// Factor out the font's displacement here. disp += mapname.mFont.GetMaxAscender(lnametexts[1]);
let fontspace1 = mapname.mFont.GetDisplacement();
let fontspace2 = ((h + (mapname.mFont.GetHeight() - fontspace1)/4)) / 2;
h = max(0, fontspace2 - fontspace1) * CleanYFac;
} }
y += h * CleanYFac; y += disp * CleanYfac;
}
DrawName(y, wbs.LName1, lnametexts[1]); DrawName(y, wbs.LName1, lnametexts[1]);
} }