From 747906730c8a6306b818014a136d08b3afa9818d Mon Sep 17 00:00:00 2001 From: Player701 Date: Sat, 13 Apr 2019 19:10:58 +0300 Subject: [PATCH] Added support for monospacing alignment modes to HUDFont / BaseStatusBar.DrawString (#810) * - Added support for monospacing alignment modes to HUDFont / BaseStatusBar.DrawString * - added underlying type declaration for EMonospacing * - replaced "#include v_video.h" with a declaration of EMonospacing --- src/g_statusbar/sbar.h | 10 ++++++---- src/g_statusbar/shared_sbar.cpp | 14 ++++++++++---- src/scripting/vmthunks.cpp | 8 ++++---- src/v_video.h | 2 +- wadsrc/static/zscript/ui/statusbar/doom_sbar.zs | 4 ++-- wadsrc/static/zscript/ui/statusbar/heretic_sbar.zs | 6 +++--- wadsrc/static/zscript/ui/statusbar/hexen_sbar.zs | 6 +++--- wadsrc/static/zscript/ui/statusbar/statusbar.zs | 2 +- wadsrc/static/zscript/ui/statusbar/strife_sbar.zs | 6 +++--- 9 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/g_statusbar/sbar.h b/src/g_statusbar/sbar.h index 55d26e71b..1b89190ca 100644 --- a/src/g_statusbar/sbar.h +++ b/src/g_statusbar/sbar.h @@ -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. @@ -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) {} }; @@ -434,7 +436,7 @@ public: 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); diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index 46e3af0ca..ccbcadc3a 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -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: @@ -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); @@ -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) @@ -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); } } diff --git a/src/scripting/vmthunks.cpp b/src/scripting/vmthunks.cpp index 5cdd1aaca..df5169b1a 100644 --- a/src/scripting/vmthunks.cpp +++ b/src/scripting/vmthunks.cpp @@ -2632,9 +2632,9 @@ 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(fnt, spac, mono, sy, sy)); + return (Create(fnt, spac, EMonospacing(mono), sy, sy)); } DEFINE_ACTION_FUNCTION_NATIVE(DHUDFont, Create, CreateHudFont) @@ -2642,10 +2642,10 @@ 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(fnt, spac, mono, sy, sy)); + ACTION_RETURN_POINTER(Create(fnt, spac, EMonospacing(mono), sy, sy)); } diff --git a/src/v_video.h b/src/v_video.h index be3246515..ee355daac 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -240,7 +240,7 @@ enum DTA_Monospace, // Fonts only: Use a fixed distance between characters. }; -enum EMonospacing +enum EMonospacing : int { Off = 0, CellLeft = 1, diff --git a/wadsrc/static/zscript/ui/statusbar/doom_sbar.zs b/wadsrc/static/zscript/ui/statusbar/doom_sbar.zs index bd2681a05..4fc7347ca 100644 --- a/wadsrc/static/zscript/ui/statusbar/doom_sbar.zs +++ b/wadsrc/static/zscript/ui/statusbar/doom_sbar.zs @@ -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(); } diff --git a/wadsrc/static/zscript/ui/statusbar/heretic_sbar.zs b/wadsrc/static/zscript/ui/statusbar/heretic_sbar.zs index 38569ac93..04785270d 100644 --- a/wadsrc/static/zscript/ui/statusbar/heretic_sbar.zs +++ b/wadsrc/static/zscript/ui/statusbar/heretic_sbar.zs @@ -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); diff --git a/wadsrc/static/zscript/ui/statusbar/hexen_sbar.zs b/wadsrc/static/zscript/ui/statusbar/hexen_sbar.zs index a39244a49..26794e933 100644 --- a/wadsrc/static/zscript/ui/statusbar/hexen_sbar.zs +++ b/wadsrc/static/zscript/ui/statusbar/hexen_sbar.zs @@ -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); diff --git a/wadsrc/static/zscript/ui/statusbar/statusbar.zs b/wadsrc/static/zscript/ui/statusbar/statusbar.zs index 4cb6675c6..18f04af7f 100644 --- a/wadsrc/static/zscript/ui/statusbar/statusbar.zs +++ b/wadsrc/static/zscript/ui/statusbar/statusbar.zs @@ -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 diff --git a/wadsrc/static/zscript/ui/statusbar/strife_sbar.zs b/wadsrc/static/zscript/ui/statusbar/strife_sbar.zs index 7d5e42fec..c2318ef44 100644 --- a/wadsrc/static/zscript/ui/statusbar/strife_sbar.zs +++ b/wadsrc/static/zscript/ui/statusbar/strife_sbar.zs @@ -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 ()