mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-28 06:53:58 +00:00
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
This commit is contained in:
parent
4668fa95e3
commit
747906730c
9 changed files with 33 additions and 25 deletions
|
@ -52,6 +52,8 @@ enum EHudState
|
||||||
HUD_AltHud // Used for passing through popups to the alt hud
|
HUD_AltHud // Used for passing through popups to the alt hud
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum EMonospacing : int;
|
||||||
|
|
||||||
// HUD Message base object --------------------------------------------------
|
// 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.
|
// 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:
|
public:
|
||||||
FFont *mFont;
|
FFont *mFont;
|
||||||
int mSpacing;
|
int mSpacing;
|
||||||
bool mMonospaced;
|
EMonospacing mMonospacing;
|
||||||
int mShadowX;
|
int mShadowX;
|
||||||
int mShadowY;
|
int mShadowY;
|
||||||
|
|
||||||
DHUDFont(FFont *f, int sp, bool ms, int sx, int sy)
|
DHUDFont(FFont *f, int sp, EMonospacing ms, int sx, int sy)
|
||||||
: mFont(f), mSpacing(sp), mMonospaced(ms), mShadowX(sx), mShadowY(sy)
|
: mFont(f), mSpacing(sp), mMonospacing(ms), mShadowX(sx), mShadowY(sy)
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -434,7 +436,7 @@ public:
|
||||||
void DrawAltHUD();
|
void DrawAltHUD();
|
||||||
|
|
||||||
void DrawGraphic(FTextureID texture, double x, double y, int flags, double Alpha, double boxwidth, double boxheight, double scaleX, double scaleY);
|
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 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 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);
|
void SetClipRect(double x, double y, double w, double h, int flags = 0);
|
||||||
|
|
|
@ -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)
|
switch (flags & DI_TEXT_ALIGN)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
|
@ -1671,6 +1673,11 @@ void DBaseStatusBar::DrawString(FFont *font, const FString &cstring, double x, d
|
||||||
rw = c->GetDisplayWidthDouble();
|
rw = c->GetDisplayWidthDouble();
|
||||||
rh = c->GetDisplayHeightDouble();
|
rh = c->GetDisplayHeightDouble();
|
||||||
|
|
||||||
|
if (monospacing == EMonospacing::CellCenter)
|
||||||
|
rx += (spacing - rw) / 2;
|
||||||
|
else if (monospacing == EMonospacing::CellRight)
|
||||||
|
rx += (spacing - rw);
|
||||||
|
|
||||||
if (!fullscreenOffsets)
|
if (!fullscreenOffsets)
|
||||||
{
|
{
|
||||||
StatusbarToRealCoords(rx, ry, rw, rh);
|
StatusbarToRealCoords(rx, ry, rw, rh);
|
||||||
|
@ -1707,7 +1714,6 @@ void DBaseStatusBar::DrawString(FFont *font, const FString &cstring, double x, d
|
||||||
else
|
else
|
||||||
x += spacing;
|
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)
|
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);
|
auto brk = V_BreakLines(font->mFont, wrapwidth, string, true);
|
||||||
for (auto &line : brk)
|
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;
|
y += font->mFont->GetHeight() + linespacing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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<DHUDFont>(fnt, spac, mono, sy, sy));
|
return (Create<DHUDFont>(fnt, spac, EMonospacing(mono), sy, sy));
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFINE_ACTION_FUNCTION_NATIVE(DHUDFont, Create, CreateHudFont)
|
DEFINE_ACTION_FUNCTION_NATIVE(DHUDFont, Create, CreateHudFont)
|
||||||
|
@ -2642,10 +2642,10 @@ DEFINE_ACTION_FUNCTION_NATIVE(DHUDFont, Create, CreateHudFont)
|
||||||
PARAM_PROLOGUE;
|
PARAM_PROLOGUE;
|
||||||
PARAM_POINTER(fnt, FFont);
|
PARAM_POINTER(fnt, FFont);
|
||||||
PARAM_INT(spac);
|
PARAM_INT(spac);
|
||||||
PARAM_BOOL(mono);
|
PARAM_INT(mono);
|
||||||
PARAM_INT(sx);
|
PARAM_INT(sx);
|
||||||
PARAM_INT(sy);
|
PARAM_INT(sy);
|
||||||
ACTION_RETURN_POINTER(Create<DHUDFont>(fnt, spac, mono, sy, sy));
|
ACTION_RETURN_POINTER(Create<DHUDFont>(fnt, spac, EMonospacing(mono), sy, sy));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -240,7 +240,7 @@ enum
|
||||||
DTA_Monospace, // Fonts only: Use a fixed distance between characters.
|
DTA_Monospace, // Fonts only: Use a fixed distance between characters.
|
||||||
};
|
};
|
||||||
|
|
||||||
enum EMonospacing
|
enum EMonospacing : int
|
||||||
{
|
{
|
||||||
Off = 0,
|
Off = 0,
|
||||||
CellLeft = 1,
|
CellLeft = 1,
|
||||||
|
|
|
@ -13,9 +13,9 @@ class DoomStatusBar : BaseStatusBar
|
||||||
|
|
||||||
// Create the font used for the fullscreen HUD
|
// Create the font used for the fullscreen HUD
|
||||||
Font fnt = "HUDFONT_DOOM";
|
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";
|
fnt = "INDEXFONT_DOOM";
|
||||||
mIndexFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true);
|
mIndexFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), Mono_CellLeft);
|
||||||
mAmountFont = HUDFont.Create("INDEXFONT");
|
mAmountFont = HUDFont.Create("INDEXFONT");
|
||||||
diparms = InventoryBarState.Create();
|
diparms = InventoryBarState.Create();
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,11 @@ class HereticStatusBar : BaseStatusBar
|
||||||
|
|
||||||
// Create the font used for the fullscreen HUD
|
// Create the font used for the fullscreen HUD
|
||||||
Font fnt = "HUDFONT_RAVEN";
|
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";
|
fnt = "INDEXFONT_RAVEN";
|
||||||
mIndexFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true);
|
mIndexFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), Mono_CellLeft);
|
||||||
fnt = "BIGFONT";
|
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 = InventoryBarState.Create(mIndexFont);
|
||||||
diparms_sbar = InventoryBarState.CreateNoBox(mIndexFont, boxsize:(31, 31), arrowoffs:(0,-10));
|
diparms_sbar = InventoryBarState.CreateNoBox(mIndexFont, boxsize:(31, 31), arrowoffs:(0,-10));
|
||||||
mHealthInterpolator = DynamicValueInterpolator.Create(0, 0.25, 1, 8);
|
mHealthInterpolator = DynamicValueInterpolator.Create(0, 0.25, 1, 8);
|
||||||
|
|
|
@ -16,11 +16,11 @@ class HexenStatusBar : BaseStatusBar
|
||||||
|
|
||||||
// Create the font used for the fullscreen HUD
|
// Create the font used for the fullscreen HUD
|
||||||
Font fnt = "HUDFONT_RAVEN";
|
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";
|
fnt = "INDEXFONT_RAVEN";
|
||||||
mIndexFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true);
|
mIndexFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), Mono_CellLeft);
|
||||||
fnt = "BIGFONT";
|
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 = InventoryBarState.Create(mIndexFont);
|
||||||
diparms_sbar = InventoryBarState.CreateNoBox(mIndexFont, boxsize:(31, 31), arrowoffs:(0,-10));
|
diparms_sbar = InventoryBarState.CreateNoBox(mIndexFont, boxsize:(31, 31), arrowoffs:(0,-10));
|
||||||
mHealthInterpolator = DynamicValueInterpolator.Create(0, 0.25, 1, 8);
|
mHealthInterpolator = DynamicValueInterpolator.Create(0, 0.25, 1, 8);
|
||||||
|
|
|
@ -18,7 +18,7 @@ struct MugShot
|
||||||
class HUDFont native ui
|
class HUDFont native ui
|
||||||
{
|
{
|
||||||
native Font mFont;
|
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
|
class InventoryBarState ui
|
||||||
|
|
|
@ -63,9 +63,9 @@ class StrifeStatusBar : BaseStatusBar
|
||||||
|
|
||||||
CursorImage = Images[imgINVCURS].IsValid() ? imgINVCURS : imgCURSOR01;
|
CursorImage = Images[imgINVCURS].IsValid() ? imgINVCURS : imgCURSOR01;
|
||||||
|
|
||||||
mYelFont = HUDFont.Create("Indexfont_Strife_Yellow", 7, true, 1, 1);
|
mYelFont = HUDFont.Create("Indexfont_Strife_Yellow", 7, Mono_CellLeft, 1, 1);
|
||||||
mGrnFont = HUDFont.Create("Indexfont_Strife_Green", 7, true, 1, 1);
|
mGrnFont = HUDFont.Create("Indexfont_Strife_Green", 7, Mono_CellLeft, 1, 1);
|
||||||
mBigFont = HUDFont.Create("BigFont", 0, false, 2, 2);
|
mBigFont = HUDFont.Create("BigFont", 0, Mono_Off, 2, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void NewGame ()
|
override void NewGame ()
|
||||||
|
|
Loading…
Reference in a new issue