diff options
author | sfan5 <sfan5@live.de> | 2021-07-27 19:11:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-27 19:11:46 +0200 |
commit | 6e8aebf4327ed43ade17cbe8e6cf652edc099651 (patch) | |
tree | 4977c6c9f9b0ceb92098694b4f8b990dc4b50822 /src/client | |
parent | cf136914cf421ee52f6806eda2fa97740d0ee552 (diff) | |
download | minetest-6e8aebf4327ed43ade17cbe8e6cf652edc099651.tar.gz minetest-6e8aebf4327ed43ade17cbe8e6cf652edc099651.tar.bz2 minetest-6e8aebf4327ed43ade17cbe8e6cf652edc099651.zip |
Add bold, italic and monospace font styling for HUD text elements (#11478)
Co-authored-by: Elias Fleckenstein <eliasfleckenstein@web.de>
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/clientevent.h | 2 | ||||
-rw-r--r-- | src/client/game.cpp | 3 | ||||
-rw-r--r-- | src/client/hud.cpp | 30 |
3 files changed, 17 insertions, 18 deletions
diff --git a/src/client/clientevent.h b/src/client/clientevent.h index 2215aecbd..17d3aedd6 100644 --- a/src/client/clientevent.h +++ b/src/client/clientevent.h @@ -59,7 +59,7 @@ struct ClientEventHudAdd v2f pos, scale; std::string name; std::string text, text2; - u32 number, item, dir; + u32 number, item, dir, style; v2f align, offset; v3f world_pos; v2s32 size; diff --git a/src/client/game.cpp b/src/client/game.cpp index 6fc57c8cc..73ad73e0e 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -2730,6 +2730,7 @@ void Game::handleClientEvent_HudAdd(ClientEvent *event, CameraOrientation *cam) e->size = event->hudadd->size; e->z_index = event->hudadd->z_index; e->text2 = event->hudadd->text2; + e->style = event->hudadd->style; m_hud_server_to_client[server_id] = player->addHud(e); delete event->hudadd; @@ -2795,6 +2796,8 @@ void Game::handleClientEvent_HudChange(ClientEvent *event, CameraOrientation *ca CASE_SET(HUD_STAT_Z_INDEX, z_index, data); CASE_SET(HUD_STAT_TEXT2, text2, sdata); + + CASE_SET(HUD_STAT_STYLE, style, data); } #undef CASE_SET diff --git a/src/client/hud.cpp b/src/client/hud.cpp index fbfc886d2..c5bf0f2f8 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -331,8 +331,8 @@ bool Hud::calculateScreenPos(const v3s16 &camera_offset, HudElement *e, v2s32 *p void Hud::drawLuaElements(const v3s16 &camera_offset) { - u32 text_height = g_fontengine->getTextHeight(); - irr::gui::IGUIFont* font = g_fontengine->getFont(); + const u32 text_height = g_fontengine->getTextHeight(); + gui::IGUIFont *const font = g_fontengine->getFont(); // Reorder elements by z_index std::vector<HudElement*> elems; @@ -356,38 +356,34 @@ 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; unsigned int font_size = g_fontengine->getDefaultFontSize(); if (e->size.X > 0) font_size *= e->size.X; - if (font_size != g_fontengine->getDefaultFontSize()) - textfont = g_fontengine->getFont(font_size); +#ifdef __ANDROID__ + // The text size on Android is not proportional with the actual scaling + // FIXME: why do we have such a weird unportable hack?? + if (font_size > 3 && e->offset.X < -20) + font_size -= 3; +#endif + auto textfont = g_fontengine->getFont(FontSpec(font_size, + (e->style & HUD_STYLE_MONO) ? FM_Mono : FM_Unspecified, + e->style & HUD_STYLE_BOLD, e->style & HUD_STYLE_ITALIC)); video::SColor color(255, (e->number >> 16) & 0xFF, (e->number >> 8) & 0xFF, (e->number >> 0) & 0xFF); std::wstring text = unescape_translate(utf8_to_wide(e->text)); core::dimension2d<u32> textsize = textfont->getDimension(text.c_str()); -#ifdef __ANDROID__ - // The text size on Android is not proportional with the actual scaling - irr::gui::IGUIFont *font_scaled = font_size <= 3 ? - textfont : g_fontengine->getFont(font_size - 3); - if (e->offset.X < -20) - textsize = font_scaled->getDimension(text.c_str()); -#endif + v2s32 offset((e->align.X - 1.0) * (textsize.Width / 2), (e->align.Y - 1.0) * (textsize.Height / 2)); core::rect<s32> size(0, 0, e->scale.X * m_scale_factor, text_height * e->scale.Y * m_scale_factor); v2s32 offs(e->offset.X * m_scale_factor, e->offset.Y * m_scale_factor); -#ifdef __ANDROID__ - if (e->offset.X < -20) - font_scaled->draw(text.c_str(), size + pos + offset + offs, color); - else -#endif + { textfont->draw(text.c_str(), size + pos + offset + offs, color); } |