summaryrefslogtreecommitdiff
path: root/src/hud.cpp
diff options
context:
space:
mode:
authorsapier <Sapier at GMX dot net>2014-04-28 23:41:27 +0200
committersapier <Sapier at GMX dot net>2014-05-07 21:46:27 +0200
commitd3ee617f37984b380ebe32cd37ef1cda66d96c48 (patch)
treeff40e272e0b5ab7525d66ddd3b98fa3eed71a496 /src/hud.cpp
parentc80d67f48e2011c88bbb9e755ee4f5e7f5391f63 (diff)
downloadminetest-d3ee617f37984b380ebe32cd37ef1cda66d96c48.tar.gz
minetest-d3ee617f37984b380ebe32cd37ef1cda66d96c48.tar.bz2
minetest-d3ee617f37984b380ebe32cd37ef1cda66d96c48.zip
Fix heart + bubble bar size on different texture packs
Add DPI support for statbar Move heart+bubble bar to Lua HUD Add statbar size (based upon an idea by blue42u) Add support for customizing breath and statbar
Diffstat (limited to 'src/hud.cpp')
-rw-r--r--src/hud.cpp43
1 files changed, 27 insertions, 16 deletions
diff --git a/src/hud.cpp b/src/hud.cpp
index c385211f2..7f2f4276c 100644
--- a/src/hud.cpp
+++ b/src/hud.cpp
@@ -228,7 +228,8 @@ void Hud::drawLuaElements(v3s16 camera_offset) {
if (!e)
continue;
- v2s32 pos(e->pos.X * m_screensize.X, e->pos.Y * m_screensize.Y);
+ v2s32 pos(floor(e->pos.X * (float) m_screensize.X + 0.5),
+ floor(e->pos.Y * (float) m_screensize.Y + 0.5));
switch (e->type) {
case HUD_ELEM_IMAGE: {
video::ITexture *texture = tsrc->getTexture(e->text);
@@ -266,7 +267,7 @@ void Hud::drawLuaElements(v3s16 camera_offset) {
break; }
case HUD_ELEM_STATBAR: {
v2s32 offs(e->offset.X, e->offset.Y);
- drawStatbar(pos, HUD_CORNER_UPPER, e->dir, e->text, e->number, offs);
+ drawStatbar(pos, HUD_CORNER_UPPER, e->dir, e->text, e->number, offs, e->size);
break; }
case HUD_ELEM_INVENTORY: {
InventoryList *inv = inventory->getList(e->text);
@@ -308,7 +309,9 @@ void Hud::drawLuaElements(v3s16 camera_offset) {
}
-void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s32 count, v2s32 offset) {
+void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture,
+ s32 count, v2s32 offset, v2s32 size)
+{
const video::SColor color(255, 255, 255, 255);
const video::SColor colors[] = {color, color, color, color};
@@ -317,10 +320,25 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s
return;
core::dimension2di srcd(stat_texture->getOriginalSize());
+ core::dimension2di dstd;
+ if (size == v2s32()) {
+ dstd = srcd;
+ } else {
+ dstd.Height = size.Y * g_settings->getFloat("gui_scaling") *
+ porting::getDisplayDensity();
+ dstd.Width = size.X * g_settings->getFloat("gui_scaling") *
+ porting::getDisplayDensity();
+
+ offset.X *= g_settings->getFloat("gui_scaling") *
+ porting::getDisplayDensity();
+
+ offset.Y *= g_settings->getFloat("gui_scaling") *
+ porting::getDisplayDensity();
+ }
v2s32 p = pos;
if (corner & HUD_CORNER_LOWER)
- p -= srcd.Height;
+ p -= dstd.Height;
p += offset;
@@ -338,13 +356,13 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s
default:
steppos = v2s32(1, 0);
}
- steppos.X *= srcd.Width;
- steppos.Y *= srcd.Height;
+ steppos.X *= dstd.Width;
+ steppos.Y *= dstd.Height;
for (s32 i = 0; i < count / 2; i++)
{
core::rect<s32> srcrect(0, 0, srcd.Width, srcd.Height);
- core::rect<s32> dstrect(srcrect);
+ core::rect<s32> dstrect(0,0, dstd.Width, dstd.Height);
dstrect += p;
driver->draw2DImage(stat_texture, dstrect, srcrect, NULL, colors, true);
@@ -354,7 +372,7 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s
if (count % 2 == 1)
{
core::rect<s32> srcrect(0, 0, srcd.Width / 2, srcd.Height);
- core::rect<s32> dstrect(srcrect);
+ core::rect<s32> dstrect(0,0, dstd.Width / 2, dstd.Height);
dstrect += p;
driver->draw2DImage(stat_texture, dstrect, srcrect, NULL, colors, true);
@@ -362,7 +380,7 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s
}
-void Hud::drawHotbar(s32 halfheartcount, u16 playeritem, s32 breath) {
+void Hud::drawHotbar(u16 playeritem) {
v2s32 centerlowerpos(m_displaycenter.X, m_screensize.Y);
@@ -393,13 +411,6 @@ void Hud::drawHotbar(s32 halfheartcount, u16 playeritem, s32 breath) {
drawItems(secondpos, hotbar_itemcount, hotbar_itemcount/2, mainlist, playeritem + 1, 0);
}
}
-
- if (player->hud_flags & HUD_FLAG_HEALTHBAR_VISIBLE)
- drawStatbar(pos - v2s32(0, 4), HUD_CORNER_LOWER, HUD_DIR_LEFT_RIGHT,
- "heart.png", halfheartcount, v2s32(0, 0));
- if (player->hud_flags & HUD_FLAG_BREATHBAR_VISIBLE && breath <= 10)
- drawStatbar(pos - v2s32(-180, 4), HUD_CORNER_LOWER, HUD_DIR_LEFT_RIGHT,
- "bubble.png", breath*2, v2s32(0, 0));
}