mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
GUIInventoryList: Override isPointInside()
This commit is contained in:
parent
90c3479520
commit
4cfb2f206a
2 changed files with 9 additions and 26 deletions
|
@ -185,32 +185,13 @@ bool GUIInventoryList::OnEvent(const SEvent &event)
|
||||||
|
|
||||||
m_hovered_i = getItemIndexAtPos(v2s32(event.MouseInput.X, event.MouseInput.Y));
|
m_hovered_i = getItemIndexAtPos(v2s32(event.MouseInput.X, event.MouseInput.Y));
|
||||||
|
|
||||||
if (m_hovered_i != -1)
|
|
||||||
return IGUIElement::OnEvent(event);
|
return IGUIElement::OnEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
// no item slot at pos of mouse event => allow clicking through
|
|
||||||
// find the element that would be hovered if this inventorylist was invisible
|
|
||||||
bool was_visible = IsVisible;
|
|
||||||
IsVisible = false;
|
|
||||||
IGUIElement *hovered =
|
|
||||||
Environment->getRootGUIElement()->getElementFromPoint(
|
|
||||||
core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y));
|
|
||||||
|
|
||||||
// if the player clicks outside of the formspec window, hovered is not
|
bool GUIInventoryList::isPointInside(const core::position2d<s32> &point) const
|
||||||
// m_fs_menu, but some other weird element (with ID -1). we do however need
|
{
|
||||||
// hovered to be m_fs_menu as item dropping when clicking outside of the
|
return getItemIndexAtPos(point) != -1;
|
||||||
// formspec window is handled in its OnEvent callback
|
|
||||||
if (!hovered || hovered->getID() == -1)
|
|
||||||
hovered = m_fs_menu;
|
|
||||||
|
|
||||||
bool ret = hovered->OnEvent(event);
|
|
||||||
|
|
||||||
// Set visible again *after* processing the event. Otherwise, hovered could
|
|
||||||
// be another GUIInventoryList, which will call this one again, resulting in
|
|
||||||
// an infinite loop.
|
|
||||||
IsVisible = was_visible;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 GUIInventoryList::getItemIndexAtPos(v2s32 p) const
|
s32 GUIInventoryList::getItemIndexAtPos(v2s32 p) const
|
||||||
|
|
|
@ -70,9 +70,11 @@ public:
|
||||||
const Options &options,
|
const Options &options,
|
||||||
gui::IGUIFont *font);
|
gui::IGUIFont *font);
|
||||||
|
|
||||||
virtual void draw() override;
|
void draw() override;
|
||||||
|
|
||||||
virtual bool OnEvent(const SEvent &event) override;
|
bool OnEvent(const SEvent &event) override;
|
||||||
|
|
||||||
|
bool isPointInside(const core::position2d<s32> &point) const override;
|
||||||
|
|
||||||
const InventoryLocation &getInventoryloc() const
|
const InventoryLocation &getInventoryloc() const
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue