aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoneWolfHT <lonewolf04361@gmail.com>2020-05-19 10:10:39 -0700
committerGitHub <noreply@github.com>2020-05-19 19:10:39 +0200
commit7d3972a5049324f776ab008894c34569641f0073 (patch)
treed0590be6cb5c6dcc4da7002e189f93107a599b3a
parent0fc51db7722f9aa1e0aa2dacade6041c932b0731 (diff)
downloadminetest-7d3972a5049324f776ab008894c34569641f0073.tar.gz
minetest-7d3972a5049324f776ab008894c34569641f0073.tar.bz2
minetest-7d3972a5049324f776ab008894c34569641f0073.zip
Add ability to scale HUD text (#9814)
Add 'size' property to HUD text elements that is used for relative font size calculations.
-rw-r--r--doc/lua_api.txt2
-rw-r--r--src/client/hud.cpp9
2 files changed, 9 insertions, 2 deletions
diff --git a/doc/lua_api.txt b/doc/lua_api.txt
index 07758c237..9c7c42436 100644
--- a/doc/lua_api.txt
+++ b/doc/lua_api.txt
@@ -1356,6 +1356,8 @@ Displays text on the HUD.
text. Specify `0xFFFFFF` for white text, `0xFF0000` for red, and so on.
* `alignment`: The alignment of the text.
* `offset`: offset in pixels from position.
+* `size`: size of the text.
+ The player-set font size is multiplied by size.x (y value isn't used).
### `statbar`
diff --git a/src/client/hud.cpp b/src/client/hud.cpp
index f8f712762..4edc229b2 100644
--- a/src/client/hud.cpp
+++ b/src/client/hud.cpp
@@ -319,16 +319,21 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
floor(e->pos.Y * (float) m_screensize.Y + 0.5));
switch (e->type) {
case HUD_ELEM_TEXT: {
+ irr::gui::IGUIFont *textfont = font;
+ if (e->size.X > 0)
+ textfont = g_fontengine->getFont(
+ e->size.X * g_fontengine->getDefaultFontSize());
+
video::SColor color(255, (e->number >> 16) & 0xFF,
(e->number >> 8) & 0xFF,
(e->number >> 0) & 0xFF);
core::rect<s32> size(0, 0, e->scale.X, text_height * e->scale.Y);
std::wstring text = unescape_translate(utf8_to_wide(e->text));
- core::dimension2d<u32> textsize = font->getDimension(text.c_str());
+ core::dimension2d<u32> textsize = textfont->getDimension(text.c_str());
v2s32 offset((e->align.X - 1.0) * (textsize.Width / 2),
(e->align.Y - 1.0) * (textsize.Height / 2));
v2s32 offs(e->offset.X, e->offset.Y);
- font->draw(text.c_str(), size + pos + offset + offs, color);
+ textfont->draw(text.c_str(), size + pos + offset + offs, color);
break; }
case HUD_ELEM_STATBAR: {
v2s32 offs(e->offset.X, e->offset.Y);