summaryrefslogtreecommitdiff
path: root/src/gui/widgets/itemcontainer.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-05-09 09:55:39 +0200
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-05-09 09:57:08 +0200
commitf0f2589451aeab54995ff2e8f384d1523fffd87a (patch)
tree00661de97871341c34324d899b457e6571025653 /src/gui/widgets/itemcontainer.cpp
parent3f630c76de06a0cbda163342b5ae0bf166aaad9f (diff)
downloadmana-fix-item-tooltip-visibility.tar.gz
mana-fix-item-tooltip-visibility.tar.bz2
mana-fix-item-tooltip-visibility.tar.xz
mana-fix-item-tooltip-visibility.zip
Fixed tooltip visibility logic for shortcut and inventory windowsfix-item-tooltip-visibility
* When hovering an empty box in the shortcut window, the tooltip of a previously hovered non-empty box would stay visible. * When hovering to the right of a row of inventory items, the tooltip for the left-most item on the next row would be displayed. Also added some padding to shift the text and item icon a little in the shortcut window when using the Jewelry theme.
Diffstat (limited to 'src/gui/widgets/itemcontainer.cpp')
-rw-r--r--src/gui/widgets/itemcontainer.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index 57e8a973..d0d24c51 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -354,9 +354,7 @@ void ItemContainer::mouseReleased(gcn::MouseEvent &event)
// Show ItemTooltip
void ItemContainer::mouseMoved(gcn::MouseEvent &event)
{
- Item *item = getItemAt(getSlotIndex(event.getX(), event.getY()));
-
- if (item)
+ if (Item *item = getItemAt(getSlotIndex(event.getX(), event.getY())))
{
mItemPopup->setItem(item->getInfo());
mItemPopup->position(viewport->getMouseX(), viewport->getMouseY());
@@ -394,12 +392,17 @@ void ItemContainer::adjustHeight()
int ItemContainer::getSlotIndex(int x, int y) const
{
+ if (x >= getWidth() || y >= getHeight())
+ return Inventory::NO_SLOT_INDEX;
+
auto &slotSkin = gui->getTheme()->getSkin(SkinType::ItemSlot);
+ const auto row = y / slotSkin.height;
+ const auto column = x / slotSkin.width;
- if (x < getWidth() && y < getHeight())
- return (y / slotSkin.height) * mGridColumns + (x / slotSkin.width);
+ if (row < 0 || row >= mGridRows || column < 0 || column >= mGridColumns)
+ return Inventory::NO_SLOT_INDEX;
- return Inventory::NO_SLOT_INDEX;
+ return (row * mGridColumns) + column;
}
void ItemContainer::keyAction()