diff options
author | Diego MartÃnez <kaeza@users.sf.net> | 2013-04-22 06:53:55 -0300 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2013-04-23 09:34:10 +0300 |
commit | 7c37b1891adcddc0e7d11e5faafddaa554443318 (patch) | |
tree | 4abc3352ba67a5e43a1aeaf29bff7e54ecac0906 /src/hud.cpp | |
parent | 58ded5cd27dd6e5ba740b22d8a3b0917f3d98150 (diff) | |
download | minetest-7c37b1891adcddc0e7d11e5faafddaa554443318.tar.gz minetest-7c37b1891adcddc0e7d11e5faafddaa554443318.tar.bz2 minetest-7c37b1891adcddc0e7d11e5faafddaa554443318.zip |
Added support for alignment in HUD items
Diffstat (limited to 'src/hud.cpp')
-rw-r--r-- | src/hud.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/hud.cpp b/src/hud.cpp index 77cf23173..0f3ab40d2 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -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); |