diff --git a/src/g_statusbar/sbar.h b/src/g_statusbar/sbar.h index fe83d616d..0b3f676ca 100644 --- a/src/g_statusbar/sbar.h +++ b/src/g_statusbar/sbar.h @@ -337,6 +337,32 @@ public: ST_DEADFACE = ST_GODFACE + 1 }; + + enum EAlign + { + TOP = 0, + VCENTER = 1, + BOTTOM = 2, + VOFFSET = 3, + VMASK = 3, + + LEFT = 0, + HCENTER = 4, + RIGHT = 8, + HOFFSET = 12, + HMASK = 12, + + CENTER = VCENTER | HCENTER, + CENTER_BOTTOM = BOTTOM | HCENTER + }; + + enum ETextAlign + { + ALIGN_LEFT = 0, + ALIGN_CENTER = 1, + ALIGN_RIGHT = 2 + }; + DBaseStatusBar (); void SetSize(int reltop = 32, int hres = 320, int vres = 200); void OnDestroy() override; @@ -375,27 +401,11 @@ public: void DrawLog(); uint32_t GetTranslation() const; - enum EAlign - { - TOP = 0, - VCENTER = 1, - BOTTOM = 2, - VOFFSET = 3, - VMASK = 3, - - LEFT = 0, - HCENTER = 4, - RIGHT = 8, - HOFFSET = 12, - HMASK = 12, - - CENTER = VCENTER | HCENTER, - CENTER_BOTTOM = BOTTOM | HCENTER - }; - - void DBaseStatusBar::DrawGraphic(FTextureID texture, bool animate, double x, double y, double Alpha = 1., bool translatable = false, bool dim = false, + void DrawGraphic(FTextureID texture, bool animate, double x, double y, double Alpha = 1., bool translatable = false, bool dim = false, int imgAlign = TOP | LEFT, int screenalign = TOP | LEFT, bool alphamap = false, double width = -1, double height = -1); + void DrawString(FFont *font, const FString &cstring, double x, double y, double Alpha, int translation, int align, int screenalign, int spacing = 0, bool monospaced = false, int shadowX = 0, int shadowY = 0); + void GetCoords(int &x, int &y) { x = ST_X; diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index 66eeca193..939fce82f 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -1492,6 +1492,69 @@ DEFINE_ACTION_FUNCTION(DBaseStatusBar, DrawGraphic) return 0; } +//============================================================================ +// +// draw stuff +// +//============================================================================ + +void DBaseStatusBar::DrawString(FFont *font, const FString &cstring, double x, double y, double Alpha, int translation, int align, int screenalign, int spacing, bool monospaced, int shadowX, int shadowY) +{ + switch (align) + { + default: + break; + case ALIGN_RIGHT: + if (!monospaced) + x -= static_cast (font->StringWidth(cstring) + (spacing * cstring.Len())); + else //monospaced, so just multiply the character size + x -= static_cast ((spacing) * cstring.Len()); + break; + case ALIGN_CENTER: + if (!monospaced) + x -= static_cast (font->StringWidth(cstring) + (spacing * cstring.Len())) / 2; + else //monospaced, so just multiply the character size + x -= static_cast ((spacing)* cstring.Len()) / 2; + break; + } +} + +DEFINE_ACTION_FUNCTION(DBaseStatusBar, DrawString) +{ + PARAM_SELF_PROLOGUE(DBaseStatusBar); + PARAM_POINTER(font, FFont); + PARAM_STRING(string); + PARAM_FLOAT(x); + PARAM_FLOAT(y); + PARAM_FLOAT(alpha); + PARAM_BOOL(trans); + PARAM_INT(ialign); + PARAM_INT(salign); + PARAM_INT_DEF(spacing); + PARAM_BOOL_DEF(monospaced); + PARAM_INT_DEF(shadowX); + PARAM_INT_DEF(shadowY); + PARAM_INT_DEF(wrapwidth); + PARAM_INT_DEF(linespacing); + + if (wrapwidth > 0) + { + FBrokenLines *brk = V_BreakLines(font, wrapwidth, string, true); + for (int i = 0; brk[i].Width >= 0; i++) + { + self->DrawString(font, brk[i].Text, x, y, alpha, trans, ialign, salign, spacing, monospaced, shadowX, shadowY); + y += font->GetHeight() + linespacing; + } + V_FreeBrokenLines(brk); + } + else + { + self->DrawString(font, string, x, y, alpha, trans, ialign, salign, spacing, monospaced, shadowX, shadowY); + } + return 0; +} + + //============================================================================ // // CCMD showpop diff --git a/wadsrc/static/zscript/statusbar/statusbar.txt b/wadsrc/static/zscript/statusbar/statusbar.txt index 12fc7d0f1..742d0995b 100644 --- a/wadsrc/static/zscript/statusbar/statusbar.txt +++ b/wadsrc/static/zscript/statusbar/statusbar.txt @@ -83,6 +83,13 @@ class BaseStatusBar native ui CENTER_BOTTOM = BOTTOM|HCENTER }; + enum ETextAlign + { + ALIGN_LEFT = 0, + ALIGN_CENTER = 1, + ALIGN_RIGHT = 2 + }; + enum SBGameModes { SINGLEPLAYER = 0x1, @@ -151,6 +158,7 @@ class BaseStatusBar native ui native static TextureID, bool GetInventoryIcon(Inventory item, int flags); native void DrawGraphic(TextureID texture, bool animate, Vector2 pos, double Alpha, bool translatable, bool dim, int imgAlign, int screenalign, bool alphamap, Vector2 box); + native void DrawString(Font font, String string, Vector2 pos , double Alpha, int translation, int align, int screenalign, int spacing=0, bool monospaced = false, int shadowX=0, int shadowY=0, int wrapwidth = -1, int linespacing = 4); //============================================================================