Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for monospacing alignment modes to HUDFont / BaseStatusBar.DrawString #810

Merged
merged 3 commits into from Apr 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/g_statusbar/sbar.h
Expand Up @@ -52,6 +52,8 @@ enum EHudState
HUD_AltHud // Used for passing through popups to the alt hud
};

enum EMonospacing : int;

// HUD Message base object --------------------------------------------------

// This is a mo-op base class to allow derived ZScript message types that can be managed by the status bar.
Expand Down Expand Up @@ -332,12 +334,12 @@ class DHUDFont : public DObject
public:
FFont *mFont;
int mSpacing;
bool mMonospaced;
EMonospacing mMonospacing;
int mShadowX;
int mShadowY;

DHUDFont(FFont *f, int sp, bool ms, int sx, int sy)
: mFont(f), mSpacing(sp), mMonospaced(ms), mShadowX(sx), mShadowY(sy)
DHUDFont(FFont *f, int sp, EMonospacing ms, int sx, int sy)
: mFont(f), mSpacing(sp), mMonospacing(ms), mShadowX(sx), mShadowY(sy)
{}
};

Expand Down Expand Up @@ -434,7 +436,7 @@ class DBaseStatusBar : public DObject
void DrawAltHUD();

void DrawGraphic(FTextureID texture, double x, double y, int flags, double Alpha, double boxwidth, double boxheight, double scaleX, double scaleY);
void DrawString(FFont *font, const FString &cstring, double x, double y, int flags, double Alpha, int translation, int spacing, bool monospaced, int shadowX, int shadowY);
void DrawString(FFont *font, const FString &cstring, double x, double y, int flags, double Alpha, int translation, int spacing, EMonospacing monospacing, int shadowX, int shadowY);
void TransformRect(double &x, double &y, double &w, double &h, int flags = 0);
void Fill(PalEntry color, double x, double y, double w, double h, int flags = 0);
void SetClipRect(double x, double y, double w, double h, int flags = 0);
Expand Down
14 changes: 10 additions & 4 deletions src/g_statusbar/shared_sbar.cpp
Expand Up @@ -1586,8 +1586,10 @@ void DBaseStatusBar::DrawGraphic(FTextureID texture, double x, double y, int fla
//
//============================================================================

void DBaseStatusBar::DrawString(FFont *font, const FString &cstring, double x, double y, int flags, double Alpha, int translation, int spacing, bool monospaced, int shadowX, int shadowY)
void DBaseStatusBar::DrawString(FFont *font, const FString &cstring, double x, double y, int flags, double Alpha, int translation, int spacing, EMonospacing monospacing, int shadowX, int shadowY)
{
bool monospaced = monospacing != EMonospacing::Off;

switch (flags & DI_TEXT_ALIGN)
{
default:
Expand Down Expand Up @@ -1671,6 +1673,11 @@ void DBaseStatusBar::DrawString(FFont *font, const FString &cstring, double x, d
rw = c->GetDisplayWidthDouble();
rh = c->GetDisplayHeightDouble();

if (monospacing == EMonospacing::CellCenter)
rx += (spacing - rw) / 2;
else if (monospacing == EMonospacing::CellRight)
rx += (spacing - rw);

if (!fullscreenOffsets)
{
StatusbarToRealCoords(rx, ry, rw, rh);
Expand Down Expand Up @@ -1707,7 +1714,6 @@ void DBaseStatusBar::DrawString(FFont *font, const FString &cstring, double x, d
else
x += spacing;
}

}

void SBar_DrawString(DBaseStatusBar *self, DHUDFont *font, const FString &string, double x, double y, int flags, int trans, double alpha, int wrapwidth, int linespacing)
Expand All @@ -1729,13 +1735,13 @@ void SBar_DrawString(DBaseStatusBar *self, DHUDFont *font, const FString &string
auto brk = V_BreakLines(font->mFont, wrapwidth, string, true);
for (auto &line : brk)
{
self->DrawString(font->mFont, line.Text, x, y, flags, alpha, trans, font->mSpacing, font->mMonospaced, font->mShadowX, font->mShadowY);
self->DrawString(font->mFont, line.Text, x, y, flags, alpha, trans, font->mSpacing, font->mMonospacing, font->mShadowX, font->mShadowY);
y += font->mFont->GetHeight() + linespacing;
}
}
else
{
self->DrawString(font->mFont, string, x, y, flags, alpha, trans, font->mSpacing, font->mMonospaced, font->mShadowX, font->mShadowY);
self->DrawString(font->mFont, string, x, y, flags, alpha, trans, font->mSpacing, font->mMonospacing, font->mShadowX, font->mShadowY);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/scripting/vmthunks.cpp
Expand Up @@ -2632,20 +2632,20 @@ DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, GetInventoryIcon, GetInventoryIcon
//
//=====================================================================================

DHUDFont *CreateHudFont(FFont *fnt, int spac, bool mono, int sx, int sy)
DHUDFont *CreateHudFont(FFont *fnt, int spac, int mono, int sx, int sy)
{
return (Create<DHUDFont>(fnt, spac, mono, sy, sy));
return (Create<DHUDFont>(fnt, spac, EMonospacing(mono), sy, sy));
}

DEFINE_ACTION_FUNCTION_NATIVE(DHUDFont, Create, CreateHudFont)
{
PARAM_PROLOGUE;
PARAM_POINTER(fnt, FFont);
PARAM_INT(spac);
PARAM_BOOL(mono);
PARAM_INT(mono);
PARAM_INT(sx);
PARAM_INT(sy);
ACTION_RETURN_POINTER(Create<DHUDFont>(fnt, spac, mono, sy, sy));
ACTION_RETURN_POINTER(Create<DHUDFont>(fnt, spac, EMonospacing(mono), sy, sy));
}


Expand Down
2 changes: 1 addition & 1 deletion src/v_video.h
Expand Up @@ -240,7 +240,7 @@ enum
DTA_Monospace, // Fonts only: Use a fixed distance between characters.
};

enum EMonospacing
enum EMonospacing : int
{
Off = 0,
CellLeft = 1,
Expand Down
4 changes: 2 additions & 2 deletions wadsrc/static/zscript/ui/statusbar/doom_sbar.zs
Expand Up @@ -13,9 +13,9 @@ class DoomStatusBar : BaseStatusBar

// Create the font used for the fullscreen HUD
Font fnt = "HUDFONT_DOOM";
mHUDFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true, 1, 1);
mHUDFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), Mono_CellLeft, 1, 1);
fnt = "INDEXFONT_DOOM";
mIndexFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true);
mIndexFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), Mono_CellLeft);
mAmountFont = HUDFont.Create("INDEXFONT");
diparms = InventoryBarState.Create();
}
Expand Down
6 changes: 3 additions & 3 deletions wadsrc/static/zscript/ui/statusbar/heretic_sbar.zs
Expand Up @@ -16,11 +16,11 @@ class HereticStatusBar : BaseStatusBar

// Create the font used for the fullscreen HUD
Font fnt = "HUDFONT_RAVEN";
mHUDFont = HUDFont.Create(fnt, fnt.GetCharWidth("0") + 1, true, 1, 1);
mHUDFont = HUDFont.Create(fnt, fnt.GetCharWidth("0") + 1, Mono_CellLeft, 1, 1);
fnt = "INDEXFONT_RAVEN";
mIndexFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true);
mIndexFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), Mono_CellLeft);
fnt = "BIGFONT";
mBigFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true, 2, 2);
mBigFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), Mono_CellLeft, 2, 2);
diparms = InventoryBarState.Create(mIndexFont);
diparms_sbar = InventoryBarState.CreateNoBox(mIndexFont, boxsize:(31, 31), arrowoffs:(0,-10));
mHealthInterpolator = DynamicValueInterpolator.Create(0, 0.25, 1, 8);
Expand Down
6 changes: 3 additions & 3 deletions wadsrc/static/zscript/ui/statusbar/hexen_sbar.zs
Expand Up @@ -16,11 +16,11 @@ class HexenStatusBar : BaseStatusBar

// Create the font used for the fullscreen HUD
Font fnt = "HUDFONT_RAVEN";
mHUDFont = HUDFont.Create(fnt, fnt.GetCharWidth("0") + 1, true, 1, 1);
mHUDFont = HUDFont.Create(fnt, fnt.GetCharWidth("0") + 1, Mono_CellLeft, 1, 1);
fnt = "INDEXFONT_RAVEN";
mIndexFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true);
mIndexFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), Mono_CellLeft);
fnt = "BIGFONT";
mBigFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true, 2, 2);
mBigFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), Mono_CellLeft, 2, 2);
diparms = InventoryBarState.Create(mIndexFont);
diparms_sbar = InventoryBarState.CreateNoBox(mIndexFont, boxsize:(31, 31), arrowoffs:(0,-10));
mHealthInterpolator = DynamicValueInterpolator.Create(0, 0.25, 1, 8);
Expand Down
2 changes: 1 addition & 1 deletion wadsrc/static/zscript/ui/statusbar/statusbar.zs
Expand Up @@ -18,7 +18,7 @@ struct MugShot
class HUDFont native ui
{
native Font mFont;
native static HUDFont Create(Font fnt, int spacing = 0, bool monospaced = false, int shadowx = 0, int shadowy = 0);
native static HUDFont Create(Font fnt, int spacing = 0, EMonospacing monospacing = Mono_Off, int shadowx = 0, int shadowy = 0);
}

class InventoryBarState ui
Expand Down
6 changes: 3 additions & 3 deletions wadsrc/static/zscript/ui/statusbar/strife_sbar.zs
Expand Up @@ -63,9 +63,9 @@ class StrifeStatusBar : BaseStatusBar

CursorImage = Images[imgINVCURS].IsValid() ? imgINVCURS : imgCURSOR01;

mYelFont = HUDFont.Create("Indexfont_Strife_Yellow", 7, true, 1, 1);
mGrnFont = HUDFont.Create("Indexfont_Strife_Green", 7, true, 1, 1);
mBigFont = HUDFont.Create("BigFont", 0, false, 2, 2);
mYelFont = HUDFont.Create("Indexfont_Strife_Yellow", 7, Mono_CellLeft, 1, 1);
mGrnFont = HUDFont.Create("Indexfont_Strife_Green", 7, Mono_CellLeft, 1, 1);
mBigFont = HUDFont.Create("BigFont", 0, Mono_Off, 2, 2);
}

override void NewGame ()
Expand Down