1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51:04 +00:00

Added support for alignment in HUD items

This commit is contained in:
Diego Martínez 2013-04-22 06:53:55 -03:00 committed by Perttu Ahola
parent 58ded5cd27
commit 7c37b1891a
9 changed files with 38 additions and 2 deletions

View file

@ -186,6 +186,9 @@ void Hud::drawLuaElements() {
core::rect<s32> rect(0, 0, imgsize.Width * e->scale.X,
imgsize.Height * e->scale.X);
rect += pos;
v2s32 offset((e->align.X - 1.0) * ((imgsize.Width * e->scale.X) / 2),
(e->align.Y - 1.0) * ((imgsize.Height * e->scale.X) / 2));
rect += offset;
driver->draw2DImage(texture, rect,
core::rect<s32>(core::position2d<s32>(0,0), imgsize),
NULL, colors, true);
@ -195,7 +198,11 @@ void Hud::drawLuaElements() {
(e->number >> 8) & 0xFF,
(e->number >> 0) & 0xFF);
core::rect<s32> size(0, 0, e->scale.X, text_height * e->scale.Y);
font->draw(narrow_to_wide(e->text).c_str(), size + pos, color);
std::wstring text = narrow_to_wide(e->text);
core::dimension2d<u32> textsize = font->getDimension(text.c_str());
v2s32 offset((e->align.X - 1.0) * (textsize.Width / 2),
(e->align.Y - 1.0) * (textsize.Height / 2));
font->draw(text.c_str(), size + pos + offset, color);
break; }
case HUD_ELEM_STATBAR:
drawStatbar(pos, HUD_CORNER_UPPER, e->dir, e->text, e->number);