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:
@@ -1851,8 +1851,11 @@ Displays text on the HUD.
|
|||||||
* `text`: The text to be displayed in the HUD element.
|
* `text`: The text to be displayed in the HUD element.
|
||||||
Supports `core.translate` (always)
|
Supports `core.translate` (always)
|
||||||
and `core.colorize` (since protocol version 44)
|
and `core.colorize` (since protocol version 44)
|
||||||
* `number`: An integer containing the RGB value of the color used to draw the
|
* `number`: An integer containing the (A)RGB value of the color used to draw the
|
||||||
text. Specify `0xFFFFFF` for white text, `0xFF0000` for red, and so on.
|
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.
|
* `alignment`: The alignment of the text.
|
||||||
* `offset`: offset in pixels from position.
|
* `offset`: offset in pixels from position.
|
||||||
* `size`: size of the text.
|
* `size`: size of the text.
|
||||||
|
|||||||
@@ -394,9 +394,16 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
|
|||||||
if (textfont->getType() == gui::EGFT_CUSTOM)
|
if (textfont->getType() == gui::EGFT_CUSTOM)
|
||||||
ttfont = static_cast<gui::CGUITTFont *>(textfont);
|
ttfont = static_cast<gui::CGUITTFont *>(textfont);
|
||||||
|
|
||||||
video::SColor color(255, (e->number >> 16) & 0xFF,
|
u32 num = e->number;
|
||||||
(e->number >> 8) & 0xFF,
|
u8 alpha = (num >> 24) & 0xFF;
|
||||||
(e->number >> 0) & 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);
|
EnrichedString text(unescape_string(utf8_to_wide(e->text)), color);
|
||||||
core::dimension2d<u32> textsize = textfont->getDimension(text.c_str());
|
core::dimension2d<u32> textsize = textfont->getDimension(text.c_str());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user