- Implemented scale parameter for BaseStatusBar::DrawString

This commit is contained in:
Player701 2019-11-14 18:51:06 +03:00 committed by Christoph Oelckers
parent 354d5eb66e
commit db1359f98e
4 changed files with 33 additions and 22 deletions

View file

@ -437,7 +437,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, 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 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);

View file

@ -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; bool monospaced = monospacing != EMonospacing::Off;
double dx = 0;
switch (flags & DI_TEXT_ALIGN) switch (flags & DI_TEXT_ALIGN)
{ {
default: default:
break; break;
case DI_TEXT_ALIGN_RIGHT: case DI_TEXT_ALIGN_RIGHT:
if (!monospaced) dx = monospaced
x -= static_cast<int> (font->StringWidth(cstring) + (spacing * cstring.CharacterCount())); ? static_cast<int> ((spacing)*cstring.CharacterCount()) //monospaced, so just multiply the character size
else //monospaced, so just multiply the character size : static_cast<int> (font->StringWidth(cstring) + (spacing * cstring.CharacterCount()));
x -= static_cast<int> ((spacing) * cstring.CharacterCount());
break; break;
case DI_TEXT_ALIGN_CENTER: case DI_TEXT_ALIGN_CENTER:
if (!monospaced) dx = monospaced
x -= static_cast<int> (font->StringWidth(cstring) + (spacing * cstring.CharacterCount())) / 2; ? static_cast<int> ((spacing)*cstring.CharacterCount()) / 2 //monospaced, so just multiply the character size
else //monospaced, so just multiply the character size : static_cast<int> (font->StringWidth(cstring) + (spacing * cstring.CharacterCount())) / 2;
x -= static_cast<int> ((spacing)* cstring.CharacterCount()) / 2;
break; break;
} }
// Take text scale into account
x -= dx * scaleX;
const uint8_t* str = (const uint8_t*)cstring.GetChars(); const uint8_t* str = (const uint8_t*)cstring.GetChars();
const EColorRange boldTranslation = EColorRange(translation ? translation - 1 : NumTextColors - 1); const EColorRange boldTranslation = EColorRange(translation ? translation - 1 : NumTextColors - 1);
int fontcolor = translation; int fontcolor = translation;
@ -1781,6 +1783,11 @@ void DBaseStatusBar::DrawString(FFont *font, const FString &cstring, double x, d
rx += orgx; rx += orgx;
ry += orgy; 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 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. // This may have to be changed to draw the shadow text up front separately.
if ((shadowX != 0 || shadowY != 0) && !(flags & DI_NOSHADOW)) 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, DTA_Alpha, Alpha,
TAG_DONE); TAG_DONE);
if (!monospaced) dx = monospaced
x += width + spacing - (c->GetDisplayLeftOffsetDouble() + 1); ? spacing
else : width + spacing - (c->GetDisplayLeftOffsetDouble() + 1);
x += spacing;
// 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 (font == nullptr) ThrowAbortException(X_READ_NIL, nullptr);
if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); 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) 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) for (auto &line : brk)
{ {
self->DrawString(font->mFont, line.Text, x, y, flags, alpha, trans, font->mSpacing, font->mMonospacing, font->mShadowX, font->mShadowY); 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; y += (font->mFont->GetHeight() + linespacing) * scaleY;
} }
} }
else 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);
} }
} }

View file

@ -2541,7 +2541,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, DrawImage, SBar_DrawImage)
return 0; 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) DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, DrawString, SBar_DrawString)
{ {
@ -2555,7 +2555,9 @@ DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, DrawString, SBar_DrawString)
PARAM_FLOAT(alpha); PARAM_FLOAT(alpha);
PARAM_INT(wrapwidth); PARAM_INT(wrapwidth);
PARAM_INT(linespacing); 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; return 0;
} }

View file

@ -349,7 +349,7 @@ class BaseStatusBar native ui
native static TextureID, bool GetInventoryIcon(Inventory item, int flags); 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 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 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 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 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 = ""); native static String FormatNumber(int number, int minsize = 0, int maxsize = 0, int format = 0, String prefix = "");