Formspec: Don't start a button click when the pointer isn't on top (#9332)
authorHugues Ross <hugues.ross@gmail.com>
Wed, 22 Jan 2020 09:18:09 +0000 (04:18 -0500)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Wed, 22 Jan 2020 09:18:09 +0000 (10:18 +0100)
src/gui/guiButton.cpp

index 0d69ff143bd946c3e35bd20fa1f524af3a817a46..ed79999cf3e489885c0beecd057b01423d86cfb4 100644 (file)
@@ -203,8 +203,12 @@ bool GUIButton::OnEvent(const SEvent& event)
        case EET_MOUSE_INPUT_EVENT:\r
                if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)\r
                {\r
-                       if (!IsPushButton)\r
+                       // Sometimes formspec elements can receive mouse events when the\r
+                       // mouse is outside of the formspec. Thus, we test the position here.\r
+                       if ( !IsPushButton && AbsoluteClippingRect.isPointInside(\r
+                                               core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y ))) {\r
                                setPressed(true);\r
+                       }\r
 \r
                        return true;\r
                }\r