- added monospacing support to Screen.DrawText and its native counterparts.

This commit is contained in:
Christoph Oelckers 2019-04-13 12:17:38 +02:00
parent 3938119192
commit d73f8faafa
7 changed files with 61 additions and 35 deletions

View file

@ -552,23 +552,6 @@ void DBaseStatusBar::BeginHUD(int resW, int resH, double Alpha, bool forcescaled
void FormatMapName(FLevelLocals *self, int cr, FString *result);
static void DrawAMText(FFont *fnt, int color, const char *text, int vwidth, int vheight, int x, int y)
{
int zerowidth = fnt->GetCharWidth('0');
x += zerowidth / 2;
for (int i = 0; text[i]; i++)
{
int c = text[i];
int width = fnt->GetCharWidth(c);
screen->DrawChar(fnt, color, x, y, c, DTA_KeepRatio, true,
DTA_VirtualWidth, vwidth, DTA_VirtualHeight, vheight, DTA_LeftOffset, width / 2, TAG_DONE);
x += zerowidth;
}
}
void DBaseStatusBar::DoDrawAutomapHUD(int crdefault, int highlight)
{
auto scale = GetUIScale(hud_scale);
@ -580,12 +563,14 @@ void DBaseStatusBar::DoDrawAutomapHUD(int crdefault, int highlight)
int sec;
int y = 0;
int textdist = 4;
int zerowidth = font->GetCharWidth('0');
if (am_showtime)
{
sec = Tics2Seconds(primaryLevel->time);
textbuffer.Format("%02d:%02d:%02d", sec / 3600, (sec % 3600) / 60, sec % 60);
DrawAMText(font, crdefault, textbuffer, vwidth, vheight, vwidth - font->GetCharWidth('0') * 8 - textdist, y);
screen->DrawText(font, crdefault, vwidth - zerowidth * 8 - textdist, y, textbuffer, DTA_VirtualWidth, vwidth, DTA_VirtualHeight, vheight,
DTA_Monospace, EMonospacing::CellCenter, DTA_Spacing, zerowidth, DTA_KeepRatio, true, TAG_END);
y += fheight;
}
@ -593,7 +578,8 @@ void DBaseStatusBar::DoDrawAutomapHUD(int crdefault, int highlight)
{
sec = Tics2Seconds(primaryLevel->totaltime);
textbuffer.Format("%02d:%02d:%02d", sec / 3600, (sec % 3600) / 60, sec % 60);
DrawAMText(font, crdefault, textbuffer, vwidth, vheight, vwidth - font->GetCharWidth('0') * 8 - textdist, y);
screen->DrawText(font, crdefault, vwidth - zerowidth * 8 - textdist, y, textbuffer, DTA_VirtualWidth, vwidth, DTA_VirtualHeight, vheight,
DTA_Monospace, EMonospacing::CellCenter, DTA_Spacing, zerowidth, DTA_KeepRatio, true, TAG_END);
}
if (!deathmatch)

View file

@ -545,6 +545,8 @@ bool DFrameBuffer::ParseDrawTextureTags(FTexture *img, double x, double y, uint3
parms->srcwidth = 1.;
parms->srcheight = 1.;
parms->burn = false;
parms->monospace = EMonospacing::Off;
parms->spacing = 0;
// Parse the tag list for attributes. (For floating point attributes,
// consider that the C ABI dictates that all floats be promoted to
@ -896,7 +898,15 @@ bool DFrameBuffer::ParseDrawTextureTags(FTexture *img, double x, double y, uint3
case DTA_CellY:
parms->celly = ListGetInt(tags);
break;
case DTA_Monospace:
parms->monospace = ListGetInt(tags);
break;
case DTA_Spacing:
parms->spacing = ListGetInt(tags);
break;
case DTA_Burn:
parms->burn = true;
break;

View file

@ -296,6 +296,11 @@ void DFrameBuffer::DrawTextCommon(FFont *font, int normalcolor, double x, double
cx = x;
cy = y;
if (parms.monospace == EMonospacing::CellCenter)
cx += parms.spacing / 2;
else if (parms.monospace == EMonospacing::CellRight)
cx += parms.spacing;
auto currentcolor = normalcolor;
while (ch - string < parms.maxstrlen)
@ -334,9 +339,24 @@ void DFrameBuffer::DrawTextCommon(FFont *font, int normalcolor, double x, double
parms.destwidth = parms.cellx;
parms.destheight = parms.celly;
}
if (parms.monospace == EMonospacing::CellLeft)
parms.left = 0;
else if (parms.monospace == EMonospacing::CellCenter)
parms.left = w / 2.;
else if (parms.monospace == EMonospacing::CellRight)
parms.left = w;
DrawTextureParms(pic, parms);
}
cx += (w + kerning) * parms.scalex;
if (parms.monospace == EMonospacing::Off)
{
cx += (w + kerning + parms.spacing) * parms.scalex;
}
else
{
cx += (parms.spacing) * parms.scalex;
}
}
}

View file

@ -236,6 +236,16 @@ enum
DTA_SrcHeight,
DTA_LegacyRenderStyle, // takes an old-style STYLE_* constant instead of an FRenderStyle
DTA_Burn, // activates the burn shader for this element
DTA_Spacing, // Strings only: Additional spacing between characters
DTA_Monospace, // Fonts only: Use a fixed distance between characters.
};
enum EMonospacing
{
Off = 0,
CellLeft = 1,
CellCenter = 2,
CellRight = 3
};
enum
@ -286,6 +296,8 @@ struct DrawParms
int desaturate;
int scalex, scaley;
int cellx, celly;
int monospace;
int spacing;
int maxstrlen;
bool fortext;
bool virtBottom;

View file

@ -186,6 +186,8 @@ enum DrawTextureTags
DTA_SrcHeight,
DTA_LegacyRenderStyle, // takes an old-style STYLE_* constant instead of an FRenderStyle
DTA_Internal3,
DTA_Spacing, // Strings only: Additional spacing between characters
DTA_Monospace, // Strings only: Use a fixed distance between characters.
};
class Shape2D : Object native

View file

@ -1344,3 +1344,11 @@ enum ECompatFlags
COMPATF2_EXPLODE2 = 1 << 9, // Use original explosion code throughout.
COMPATF2_RAILING = 1 << 10, // Bugged Strife railings.
};
enum EMonospacing
{
Mono_Off = 0,
Mono_CellLeft = 1,
Mono_CellCenter = 2,
Mono_CellRight = 3
};

View file

@ -120,20 +120,8 @@ class AltHud ui
void DrawHudText(Font fnt, int color, String text, int x, int y, double trans = 0.75)
{
int zerowidth = fnt.GetCharWidth("0");
x += zerowidth / 2;
for(int i=0; i < text.length(); i++)
{
int c = text.ByteAt(i);
int width = fnt.GetCharWidth(c);
double offset = fnt.GetBottomAlignOffset(c);
screen.DrawChar(fnt, color, x, y, c,
DTA_KeepRatio, true,
DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight, DTA_Alpha, trans,
DTA_LeftOffset, width/2, DTA_TopOffsetF, offset);
x += zerowidth;
}
screen.DrawText(fnt, color, x, y-fnt.GetHeight(), text, DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight,
DTA_KeepRatio, true, DTA_Alpha, trans, DTA_Monospace, MONO_CellCenter, DTA_Spacing, zerowidth);
}