Skip to content
Permalink
Browse files

- added monospacing support to Screen.DrawText and its native counter…

…parts.
  • Loading branch information...
coelckers committed Apr 13, 2019
1 parent 3938119 commit d73f8faafa4d22e45af92cb2442d1b629ed8196f
@@ -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,20 +563,23 @@ 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;
}

if (am_showtotaltime)
{
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)
@@ -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;
@@ -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;
}

}
}

@@ -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;
@@ -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
@@ -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
};
@@ -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);
}


0 comments on commit d73f8fa

Please sign in to comment.
You can’t perform that action at this time.