1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-12-23 06:55:30 +01:00

Add alpha channel in HUD text elements (#16730)

This commit is contained in:
Zughy
2025-12-20 15:14:08 +01:00
committed by GitHub
parent 4cb32467d3
commit 0fe6827dae
2 changed files with 15 additions and 5 deletions

View File

@@ -1851,8 +1851,11 @@ Displays text on the HUD.
* `text`: The text to be displayed in the HUD element.
Supports `core.translate` (always)
and `core.colorize` (since protocol version 44)
* `number`: An integer containing the RGB value of the color used to draw the
text. Specify `0xFFFFFF` for white text, `0xFF0000` for red, and so on.
* `number`: An integer containing the (A)RGB value of the color used to draw the
text. Specify `0xFFFFFF` for white text, `0x80FF0000` for semi-transparent red, and so on.
* Alpha only works on Luanti 5.15+ clients. Older clients will see the text as opaque.
* To completely hide a text, set `text` to `""`. Setting the alpha value to `00`
will not work due to compatibility reasons (it'll be treated as `FF`).
* `alignment`: The alignment of the text.
* `offset`: offset in pixels from position.
* `size`: size of the text.

View File

@@ -394,9 +394,16 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
if (textfont->getType() == gui::EGFT_CUSTOM)
ttfont = static_cast<gui::CGUITTFont *>(textfont);
video::SColor color(255, (e->number >> 16) & 0xFF,
(e->number >> 8) & 0xFF,
(e->number >> 0) & 0xFF);
u32 num = e->number;
u8 alpha = (num >> 24) & 0xFF;
if (alpha == 0)
alpha = 0xFF; // Backwards compatibility
video::SColor color = video::SColor(alpha,
(num >> 16) & 0xFF,
(num >> 8) & 0xFF,
(num >> 0) & 0xFF);
EnrichedString text(unescape_string(utf8_to_wide(e->text)), color);
core::dimension2d<u32> textsize = textfont->getDimension(text.c_str());