mirror of
https://github.com/minetest/minetest.git
synced 2025-01-11 07:47:31 +01:00
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
This commit is contained in:
parent
6cd2b3b445
commit
16c7008771
@ -2196,6 +2196,8 @@ void GUIFormSpecMenu::drawList(const ListDrawSpec &s, int phase,
|
|||||||
&& m_selected_item->listname == s.listname
|
&& m_selected_item->listname == s.listname
|
||||||
&& m_selected_item->i == item_i;
|
&& m_selected_item->i == item_i;
|
||||||
bool hovering = rect.isPointInside(m_pointer);
|
bool hovering = rect.isPointInside(m_pointer);
|
||||||
|
ItemRotationKind rotation_kind = selected ? IT_ROT_SELECTED :
|
||||||
|
(hovering ? IT_ROT_HOVERED : IT_ROT_NONE);
|
||||||
|
|
||||||
if (phase == 0) {
|
if (phase == 0) {
|
||||||
if (hovering) {
|
if (hovering) {
|
||||||
@ -2238,7 +2240,7 @@ void GUIFormSpecMenu::drawList(const ListDrawSpec &s, int phase,
|
|||||||
{
|
{
|
||||||
drawItemStack(driver, m_font, item,
|
drawItemStack(driver, m_font, item,
|
||||||
rect, &AbsoluteClippingRect, m_gamedef,
|
rect, &AbsoluteClippingRect, m_gamedef,
|
||||||
selected, hovering, false);
|
rotation_kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw tooltip
|
// Draw tooltip
|
||||||
@ -2284,7 +2286,7 @@ void GUIFormSpecMenu::drawSelectedItem()
|
|||||||
if (!m_selected_item) {
|
if (!m_selected_item) {
|
||||||
drawItemStack(driver, m_font, ItemStack(),
|
drawItemStack(driver, m_font, ItemStack(),
|
||||||
core::rect<s32>(v2s32(0, 0), v2s32(0, 0)),
|
core::rect<s32>(v2s32(0, 0), v2s32(0, 0)),
|
||||||
NULL, m_gamedef, false, false, true);
|
NULL, m_gamedef, IT_ROT_DRAGGED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2297,7 +2299,7 @@ void GUIFormSpecMenu::drawSelectedItem()
|
|||||||
|
|
||||||
core::rect<s32> imgrect(0,0,imgsize.X,imgsize.Y);
|
core::rect<s32> imgrect(0,0,imgsize.X,imgsize.Y);
|
||||||
core::rect<s32> rect = imgrect + (m_pointer - imgrect.getCenter());
|
core::rect<s32> rect = imgrect + (m_pointer - imgrect.getCenter());
|
||||||
drawItemStack(driver, m_font, stack, rect, NULL, m_gamedef, false, false, true);
|
drawItemStack(driver, m_font, stack, rect, NULL, m_gamedef, IT_ROT_DRAGGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIFormSpecMenu::drawMenu()
|
void GUIFormSpecMenu::drawMenu()
|
||||||
@ -2434,7 +2436,7 @@ void GUIFormSpecMenu::drawMenu()
|
|||||||
// Viewport rectangle on screen
|
// Viewport rectangle on screen
|
||||||
core::rect<s32> rect = imgrect + spec.pos;
|
core::rect<s32> rect = imgrect + spec.pos;
|
||||||
drawItemStack(driver, m_font, item, rect, &AbsoluteClippingRect,
|
drawItemStack(driver, m_font, item, rect, &AbsoluteClippingRect,
|
||||||
m_gamedef, false, false, false);
|
m_gamedef, IT_ROT_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2452,7 +2454,7 @@ void GUIFormSpecMenu::drawMenu()
|
|||||||
if (!item_hovered) {
|
if (!item_hovered) {
|
||||||
drawItemStack(driver, m_font, ItemStack(),
|
drawItemStack(driver, m_font, ItemStack(),
|
||||||
core::rect<s32>(v2s32(0, 0), v2s32(0, 0)),
|
core::rect<s32>(v2s32(0, 0), v2s32(0, 0)),
|
||||||
NULL, m_gamedef, false, true, false);
|
NULL, m_gamedef, IT_ROT_HOVERED);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO find way to show tooltips on touchscreen */
|
/* TODO find way to show tooltips on touchscreen */
|
||||||
|
53
src/hud.cpp
53
src/hud.cpp
@ -156,7 +156,7 @@ void Hud::drawItem(const ItemStack &item, const core::rect<s32>& rect,
|
|||||||
if (!use_hotbar_image)
|
if (!use_hotbar_image)
|
||||||
driver->draw2DRectangle(bgcolor2, rect, NULL);
|
driver->draw2DRectangle(bgcolor2, rect, NULL);
|
||||||
drawItemStack(driver, g_fontengine->getFont(), item, 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
|
//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,
|
void drawItemStack(video::IVideoDriver *driver,
|
||||||
gui::IGUIFont *font,
|
gui::IGUIFont *font,
|
||||||
const ItemStack &item,
|
const ItemStack &item,
|
||||||
const core::rect<s32> &rect,
|
const core::rect<s32> &rect,
|
||||||
const core::rect<s32> *clip,
|
const core::rect<s32> *clip,
|
||||||
IGameDef *gamedef,
|
IGameDef *gamedef,
|
||||||
bool selected,
|
ItemRotationKind rotation_kind)
|
||||||
bool hovered,
|
|
||||||
bool dragged)
|
|
||||||
{
|
{
|
||||||
static s32 hovered_time;
|
static MeshTimeInfo rotation_time_infos[IT_ROT_NONE];
|
||||||
static s32 selected_time;
|
static bool enable_animations =
|
||||||
static s32 dragged_time;
|
|
||||||
static scene::IMesh *hovered_mesh;
|
|
||||||
static scene::IMesh *selected_mesh;
|
|
||||||
static scene::IMesh *dragged_mesh;
|
|
||||||
bool enable_animations =
|
|
||||||
g_settings->getBool("inventory_items_animations");
|
g_settings->getBool("inventory_items_animations");
|
||||||
|
|
||||||
if (item.empty()) {
|
if (item.empty()) {
|
||||||
if (selected) {
|
if (rotation_kind < IT_ROT_NONE) {
|
||||||
selected_mesh = NULL;
|
rotation_time_infos[rotation_kind].mesh = NULL;
|
||||||
} else if (hovered) {
|
|
||||||
hovered_mesh = NULL;
|
|
||||||
} else if (dragged) {
|
|
||||||
dragged_mesh = NULL;
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -522,26 +516,13 @@ void drawItemStack(video::IVideoDriver *driver,
|
|||||||
if (mesh) {
|
if (mesh) {
|
||||||
driver->clearZBuffer();
|
driver->clearZBuffer();
|
||||||
s32 delta = 0;
|
s32 delta = 0;
|
||||||
if (selected) {
|
if (rotation_kind < IT_ROT_NONE) {
|
||||||
if (mesh != selected_mesh) {
|
MeshTimeInfo &ti = rotation_time_infos[rotation_kind];
|
||||||
selected_mesh = mesh;
|
if (mesh != ti.mesh) {
|
||||||
selected_time = getTimeMs();
|
ti.mesh = mesh;
|
||||||
|
ti.time = getTimeMs();
|
||||||
} else {
|
} else {
|
||||||
delta = porting::getDeltaMs(selected_time, getTimeMs()) % 100000;
|
delta = porting::getDeltaMs(ti.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();
|
|
||||||
} else {
|
|
||||||
delta = porting::getDeltaMs(dragged_time, getTimeMs()) % 100000;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
core::rect<s32> oldViewPort = driver->getViewPort();
|
core::rect<s32> oldViewPort = driver->getViewPort();
|
||||||
|
11
src/hud.h
11
src/hud.h
@ -147,15 +147,20 @@ private:
|
|||||||
video::SColor hbar_colors[4];
|
video::SColor hbar_colors[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum ItemRotationKind {
|
||||||
|
IT_ROT_SELECTED,
|
||||||
|
IT_ROT_HOVERED,
|
||||||
|
IT_ROT_DRAGGED,
|
||||||
|
IT_ROT_NONE, // Must be last, also serves as number
|
||||||
|
};
|
||||||
|
|
||||||
void drawItemStack(video::IVideoDriver *driver,
|
void drawItemStack(video::IVideoDriver *driver,
|
||||||
gui::IGUIFont *font,
|
gui::IGUIFont *font,
|
||||||
const ItemStack &item,
|
const ItemStack &item,
|
||||||
const core::rect<s32> &rect,
|
const core::rect<s32> &rect,
|
||||||
const core::rect<s32> *clip,
|
const core::rect<s32> *clip,
|
||||||
IGameDef *gamedef,
|
IGameDef *gamedef,
|
||||||
bool selected,
|
ItemRotationKind rotation_kind);
|
||||||
bool hovered,
|
|
||||||
bool dragged);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user