diff --git a/OpenTESArena/src/Interface/CharacterEquipmentPanel.cpp b/OpenTESArena/src/Interface/CharacterEquipmentPanel.cpp index 319617eb7..8f70f09ed 100644 --- a/OpenTESArena/src/Interface/CharacterEquipmentPanel.cpp +++ b/OpenTESArena/src/Interface/CharacterEquipmentPanel.cpp @@ -79,12 +79,26 @@ bool CharacterEquipmentPanel::init() this->inventoryListBox.setOverrideColor(i, equipColor); }); - this->addButtonProxy(MouseButtonType::Left, this->inventoryListBox.getItemGlobalRect(i), - [this, i]() + ButtonProxy::RectFunction itemRectFunc = [this, i]() { - const int firstVisibleIndex = this->inventoryListBox.getFirstVisibleItemIndex(); - this->inventoryListBox.getCallback(firstVisibleIndex + i)(); - }); + return this->inventoryListBox.getItemGlobalRect(i); + }; + + ButtonProxy::Callback itemCallback = this->inventoryListBox.getCallback(i); + + ButtonProxy::ActiveFunction itemActiveFunction = [this, &game]() + { + // @todo: I don't like every button proxy having to handle mouse position, fix this design. + // - maybe should give the button proxy a parent rect that all clicks have to be inside, then + // the active func becomes obsolete + const InputManager &inputManager = game.inputManager; + const Int2 mousePosition = inputManager.getMousePosition(); + const Int2 mouseClassicPosition = game.renderer.nativeToOriginal(mousePosition); + const Rect inventoryListBoxRect = this->inventoryListBox.getRect(); + return inventoryListBoxRect.contains(mouseClassicPosition); + }; + + this->addButtonProxy(MouseButtonType::Left, itemRectFunc, itemCallback, itemActiveFunction); } this->backToStatsButton = Button(