From e0192e256ff4b782c7b8b561b5c15ae4c8961d08 Mon Sep 17 00:00:00 2001 From: Desour Date: Mon, 17 Jul 2023 18:53:17 +0200 Subject: [PATCH] Fix incorrect rounding in GUIInventoryList::getItemIndexAtPos --- src/gui/guiInventoryList.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/guiInventoryList.cpp b/src/gui/guiInventoryList.cpp index d2a0d344e..b84a13290 100644 --- a/src/gui/guiInventoryList.cpp +++ b/src/gui/guiInventoryList.cpp @@ -217,8 +217,8 @@ s32 GUIInventoryList::getItemIndexAtPos(v2s32 p) const v2s32 base_pos = AbsoluteRect.UpperLeftCorner; // instead of looping through each slot, we look where p would be in the grid - s32 i = (p.X - base_pos.X) / (s32)m_slot_spacing.X - + m_geom.X * ((p.Y - base_pos.Y) / (s32)m_slot_spacing.Y); + s32 i = static_cast((p.X - base_pos.X) / m_slot_spacing.X) + + static_cast((p.Y - base_pos.Y) / m_slot_spacing.Y) * m_geom.X; v2s32 p0((i % m_geom.X) * m_slot_spacing.X, (i / m_geom.X) * m_slot_spacing.Y);