https://github.com/libsdl-org/Maelstrom/commit/dbcfb39198dda30f16a6e8f9c45af3bdc9462597
From dbcfb39198dda30f16a6e8f9c45af3bdc9462597 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 28 Oct 2011 23:20:59 -0400
Subject: [PATCH] Fixed button handling of mouse clicks without prior motion
---
screenlib/UIElementButton.cpp | 27 ++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)
diff --git a/screenlib/UIElementButton.cpp b/screenlib/UIElementButton.cpp
index 776e0587..23c752dd 100644
--- a/screenlib/UIElementButton.cpp
+++ b/screenlib/UIElementButton.cpp
@@ -148,33 +148,46 @@ UIElementButton::ShouldHandleKey(SDL_Keycode key)
bool
UIElementButton::HandleEvent(const SDL_Event &event)
{
+ bool checkMouseLocation = false;
+ int x, y;
+
if (event.type == SDL_MOUSEMOTION) {
- if (ContainsPoint(event.motion.x, event.motion.y)) {
+ x = event.motion.x;
+ y = event.motion.y;
+ checkMouseLocation = true;
+ }
+ if (event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP) {
+ x = event.button.x;
+ y = event.button.y;
+ checkMouseLocation = true;
+ }
+
+ if (checkMouseLocation) {
+ if (ContainsPoint(x, y)) {
if (!m_mouseInside) {
m_mouseInside = true;
OnMouseEnter();
}
- return true;
} else {
if (m_mouseInside) {
m_mouseInside = false;
OnMouseLeave();
}
- return false;
}
}
+ if (event.type == SDL_MOUSEMOTION) {
+ return m_mouseInside;
+ }
if (event.type == SDL_MOUSEBUTTONDOWN &&
- event.button.button == SDL_BUTTON_LEFT &&
- ContainsPoint(event.motion.x, event.motion.y)) {
+ event.button.button == SDL_BUTTON_LEFT && m_mouseInside) {
m_mousePressed = true;
OnMouseDown();
return true;
}
if (event.type == SDL_MOUSEBUTTONUP &&
- event.button.button == SDL_BUTTON_LEFT &&
- m_mousePressed) {
+ event.button.button == SDL_BUTTON_LEFT && m_mousePressed) {
m_mousePressed = false;
OnMouseUp();
if (m_mouseInside) {