diff --git a/src/g_statusbar/sbar.h b/src/g_statusbar/sbar.h index f7faee70bc..1f53859c03 100644 --- a/src/g_statusbar/sbar.h +++ b/src/g_statusbar/sbar.h @@ -437,7 +437,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, EMonospacing monospacing, 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, double scaleX, double scaleY); 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 dc836d0324..aa09670802 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -1675,28 +1675,30 @@ 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, EMonospacing monospacing, 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, double scaleX, double scaleY) { bool monospaced = monospacing != EMonospacing::Off; + double dx = 0; switch (flags & DI_TEXT_ALIGN) { default: break; case DI_TEXT_ALIGN_RIGHT: - if (!monospaced) - x -= static_cast (font->StringWidth(cstring) + (spacing * cstring.CharacterCount())); - else //monospaced, so just multiply the character size - x -= static_cast ((spacing) * cstring.CharacterCount()); + dx = monospaced + ? static_cast ((spacing)*cstring.CharacterCount()) //monospaced, so just multiply the character size + : static_cast (font->StringWidth(cstring) + (spacing * cstring.CharacterCount())); break; case DI_TEXT_ALIGN_CENTER: - if (!monospaced) - x -= static_cast (font->StringWidth(cstring) + (spacing * cstring.CharacterCount())) / 2; - else //monospaced, so just multiply the character size - x -= static_cast ((spacing)* cstring.CharacterCount()) / 2; + dx = monospaced + ? static_cast ((spacing)*cstring.CharacterCount()) / 2 //monospaced, so just multiply the character size + : static_cast (font->StringWidth(cstring) + (spacing * cstring.CharacterCount())) / 2; break; } + // Take text scale into account + x -= dx * scaleX; + const uint8_t* str = (const uint8_t*)cstring.GetChars(); const EColorRange boldTranslation = EColorRange(translation ? translation - 1 : NumTextColors - 1); int fontcolor = translation; @@ -1781,6 +1783,11 @@ void DBaseStatusBar::DrawString(FFont *font, const FString &cstring, double x, d rx += orgx; ry += orgy; } + + // Apply text scale + rw *= scaleX; + rh *= scaleY; + // This is not really such a great way to draw shadows because they can overlap with previously drawn characters. // This may have to be changed to draw the shadow text up front separately. if ((shadowX != 0 || shadowY != 0) && !(flags & DI_NOSHADOW)) @@ -1798,14 +1805,16 @@ void DBaseStatusBar::DrawString(FFont *font, const FString &cstring, double x, d DTA_Alpha, Alpha, TAG_DONE); - if (!monospaced) - x += width + spacing - (c->GetDisplayLeftOffsetDouble() + 1); - else - x += spacing; + dx = monospaced + ? spacing + : width + spacing - (c->GetDisplayLeftOffsetDouble() + 1); + + // Take text scale into account + x += dx * scaleX; } } -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, double scaleX, double scaleY) { if (font == nullptr) ThrowAbortException(X_READ_NIL, nullptr); if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); @@ -1821,16 +1830,16 @@ void SBar_DrawString(DBaseStatusBar *self, DHUDFont *font, const FString &string if (wrapwidth > 0) { - auto brk = V_BreakLines(font->mFont, wrapwidth, string, true); + auto brk = V_BreakLines(font->mFont, int(wrapwidth * scaleX), string, true); for (auto &line : brk) { - self->DrawString(font->mFont, line.Text, x, y, flags, alpha, trans, font->mSpacing, font->mMonospacing, font->mShadowX, font->mShadowY); - y += font->mFont->GetHeight() + linespacing; + self->DrawString(font->mFont, line.Text, x, y, flags, alpha, trans, font->mSpacing, font->mMonospacing, font->mShadowX, font->mShadowY, scaleX, scaleY); + y += (font->mFont->GetHeight() + linespacing) * scaleY; } } else { - self->DrawString(font->mFont, string, x, y, flags, alpha, trans, font->mSpacing, font->mMonospacing, font->mShadowX, font->mShadowY); + self->DrawString(font->mFont, string, x, y, flags, alpha, trans, font->mSpacing, font->mMonospacing, font->mShadowX, font->mShadowY, scaleX, scaleY); } } diff --git a/src/scripting/vmthunks.cpp b/src/scripting/vmthunks.cpp index d21fe03941..4f0d2fb328 100644 --- a/src/scripting/vmthunks.cpp +++ b/src/scripting/vmthunks.cpp @@ -2541,7 +2541,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, DrawImage, SBar_DrawImage) return 0; } -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, double scaleX, double scaleY); DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, DrawString, SBar_DrawString) { @@ -2555,7 +2555,9 @@ DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, DrawString, SBar_DrawString) PARAM_FLOAT(alpha); PARAM_INT(wrapwidth); PARAM_INT(linespacing); - SBar_DrawString(self, font, string, x, y, flags, trans, alpha, wrapwidth, linespacing); + PARAM_FLOAT(scaleX); + PARAM_FLOAT(scaleY); + SBar_DrawString(self, font, string, x, y, flags, trans, alpha, wrapwidth, linespacing, scaleX, scaleY); return 0; } diff --git a/wadsrc/static/zscript/ui/statusbar/statusbar.zs b/wadsrc/static/zscript/ui/statusbar/statusbar.zs index 4f84fad3aa..85cf54475b 100644 --- a/wadsrc/static/zscript/ui/statusbar/statusbar.zs +++ b/wadsrc/static/zscript/ui/statusbar/statusbar.zs @@ -349,7 +349,7 @@ class BaseStatusBar native ui native static TextureID, bool GetInventoryIcon(Inventory item, int flags); native void DrawTexture(TextureID texture, Vector2 pos, int flags = 0, double Alpha = 1., Vector2 box = (-1, -1), Vector2 scale = (1, 1)); native void DrawImage(String texture, Vector2 pos, int flags = 0, double Alpha = 1., Vector2 box = (-1, -1), Vector2 scale = (1, 1)); - native void DrawString(HUDFont font, String string, Vector2 pos, int flags = 0, int translation = Font.CR_UNTRANSLATED, double Alpha = 1., int wrapwidth = -1, int linespacing = 4); + native void DrawString(HUDFont font, String string, Vector2 pos, int flags = 0, int translation = Font.CR_UNTRANSLATED, double Alpha = 1., int wrapwidth = -1, int linespacing = 4, Vector2 scale = (1, 1)); native double, double, double, double TransformRect(double x, double y, double w, double h, int flags = 0); native void Fill(Color col, double x, double y, double w, double h, int flags = 0); native static String FormatNumber(int number, int minsize = 0, int maxsize = 0, int format = 0, String prefix = "");