diff options
author | est31 <MTest31@outlook.com> | 2016-02-07 20:27:50 +0100 |
---|---|---|
committer | est31 <MTest31@outlook.com> | 2016-02-08 00:35:24 +0100 |
commit | 16c70087711db38ac40a428c64623355b8e7691b (patch) | |
tree | 359ca29f841f95d6ee28190b7331d4a554448b5b /src/hud.cpp | |
parent | 6cd2b3b445bf558fda1e5a7908adef8e3a45449a (diff) | |
download | minetest-16c70087711db38ac40a428c64623355b8e7691b.tar.gz minetest-16c70087711db38ac40a428c64623355b8e7691b.tar.bz2 minetest-16c70087711db38ac40a428c64623355b8e7691b.zip |
small drawItemStack cleanup
-> Replace the three bool params with an enum
-> Add struct for the static content, leads to less repetition
-> cache enable_animations setting
Diffstat (limited to 'src/hud.cpp')
-rw-r--r-- | src/hud.cpp | 53 |
1 files changed, 17 insertions, 36 deletions
diff --git a/src/hud.cpp b/src/hud.cpp index 2d22f963c..1c144b021 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -156,7 +156,7 @@ void Hud::drawItem(const ItemStack &item, const core::rect<s32>& rect, if (!use_hotbar_image) driver->draw2DRectangle(bgcolor2, rect, NULL); drawItemStack(driver, g_fontengine->getFont(), item, rect, NULL, - gamedef, selected, false, false); + gamedef, selected ? IT_ROT_SELECTED : IT_ROT_NONE); } //NOTE: selectitem = 0 -> no selected; selectitem 1-based @@ -486,32 +486,26 @@ void Hud::resizeHotbar() { } } +struct MeshTimeInfo { + s32 time; + scene::IMesh *mesh; +}; + void drawItemStack(video::IVideoDriver *driver, gui::IGUIFont *font, const ItemStack &item, const core::rect<s32> &rect, const core::rect<s32> *clip, IGameDef *gamedef, - bool selected, - bool hovered, - bool dragged) + ItemRotationKind rotation_kind) { - static s32 hovered_time; - static s32 selected_time; - static s32 dragged_time; - static scene::IMesh *hovered_mesh; - static scene::IMesh *selected_mesh; - static scene::IMesh *dragged_mesh; - bool enable_animations = + static MeshTimeInfo rotation_time_infos[IT_ROT_NONE]; + static bool enable_animations = g_settings->getBool("inventory_items_animations"); if (item.empty()) { - if (selected) { - selected_mesh = NULL; - } else if (hovered) { - hovered_mesh = NULL; - } else if (dragged) { - dragged_mesh = NULL; + if (rotation_kind < IT_ROT_NONE) { + rotation_time_infos[rotation_kind].mesh = NULL; } return; } @@ -522,26 +516,13 @@ void drawItemStack(video::IVideoDriver *driver, if (mesh) { driver->clearZBuffer(); s32 delta = 0; - if (selected) { - if (mesh != selected_mesh) { - selected_mesh = mesh; - selected_time = getTimeMs(); - } else { - delta = porting::getDeltaMs(selected_time, getTimeMs()) % 100000; - } - } else if (hovered) { - if (mesh != hovered_mesh) { - hovered_mesh = mesh; - hovered_time = getTimeMs(); - } else { - delta = porting::getDeltaMs(hovered_time, getTimeMs()) % 100000; - } - } else if (dragged) { - if (mesh != dragged_mesh) { - dragged_mesh = mesh; - dragged_time = getTimeMs(); + if (rotation_kind < IT_ROT_NONE) { + MeshTimeInfo &ti = rotation_time_infos[rotation_kind]; + if (mesh != ti.mesh) { + ti.mesh = mesh; + ti.time = getTimeMs(); } else { - delta = porting::getDeltaMs(dragged_time, getTimeMs()) % 100000; + delta = porting::getDeltaMs(ti.time, getTimeMs()) % 100000; } } core::rect<s32> oldViewPort = driver->getViewPort(); |