diff --git a/Minecraft.Client/Common/UI/UIScene.cpp b/Minecraft.Client/Common/UI/UIScene.cpp index 9fb67d9e4..dc5c9d8fc 100644 --- a/Minecraft.Client/Common/UI/UIScene.cpp +++ b/Minecraft.Client/Common/UI/UIScene.cpp @@ -469,12 +469,10 @@ bool UIScene::handleMouseClick(F32 x, F32 y) vector *controls = GetControls(); if (!controls) return false; - // Flash may report overlapping bounds for side-by-side controls (e.g. - // TextInputs with full 630px width in debug scenes). Among all controls - // that contain the click point, pick the one whose left edge (cx) is - // closest to the click X — i.e. largest cx that is still <= x. + // Hit-test controls and pick the smallest-area match to handle + // overlapping Flash bounds correctly without sacrificing precision. int bestId = -1; - S32 bestCx = -1; + S32 bestArea = INT_MAX; UIControl *bestCtrl = NULL; for (size_t i = 0; i < controls->size(); ++i) @@ -501,9 +499,10 @@ bool UIScene::handleMouseClick(F32 x, F32 y) if (x >= cx && x <= cx + cw && y >= cy && y <= cy + ch) { - if (cx > bestCx) + S32 area = cw * ch; + if (area < bestArea) { - bestCx = cx; + bestArea = area; bestId = ctrl->getId(); bestCtrl = ctrl; } diff --git a/Minecraft.Client/Common/UI/UIScene.h b/Minecraft.Client/Common/UI/UIScene.h index 416e9374b..df2bc840d 100644 --- a/Minecraft.Client/Common/UI/UIScene.h +++ b/Minecraft.Client/Common/UI/UIScene.h @@ -184,9 +184,8 @@ public: virtual UIControl* GetMainPanel(); #ifdef _WINDOWS64 - // Mouse click dispatch. Default implementation hit-tests C++ controls with - // "best match" logic (largest left-edge X) to handle overlapping Flash bounds, - // then calls the virtual handlePress. Override for custom behaviour (e.g. crafting). + // Mouse click dispatch. Hit-tests C++ controls and picks the smallest-area + // match, then calls handlePress. Override for custom behaviour (e.g. crafting). virtual bool handleMouseClick(F32 x, F32 y); #endif