From 5fd9bb061af49c6416495469a5e5e1fa0347c581 Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Fri, 27 Sep 2024 15:34:23 +0200 Subject: [PATCH 1/2] Restore `Button::mHasMouse` and set it on `mousePressed` (`mouseEntered` doesn't happen on button creation). --- src/widgets/button.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/widgets/button.cpp b/src/widgets/button.cpp index 521509c..3de9bec 100644 --- a/src/widgets/button.cpp +++ b/src/widgets/button.cpp @@ -198,13 +198,15 @@ namespace gcn { if (mMousePressed) { - return true; + return mHasMouse; } return mKeyPressed; } void Button::mousePressed(MouseEvent& mouseEvent) { + mHasMouse = gcn::Rectangle(0, 0, getWidth(), getHeight()) + .isContaining(mouseEvent.getX(), mouseEvent.getY()); if (mouseEvent.isConsumed()) { return; @@ -229,7 +231,8 @@ namespace gcn void Button::mouseReleased(MouseEvent& mouseEvent) { if (mouseEvent.getButton() == MouseEvent::Left - && mMousePressed) + && mMousePressed + && mHasMouse) { mMousePressed = false; distributeActionEvent(); From cd9241f07fecd4c4f83295789c8048de2cd0e966 Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Fri, 27 Sep 2024 15:45:41 +0200 Subject: [PATCH 2/2] Move `distributeActionEvent` from `Button::mouseReleased` into `Button::mouseClicked` --- include/guisan/widgets/button.hpp | 1 + include/guisan/widgets/togglebutton.hpp | 2 +- src/widgets/button.cpp | 13 +++++++------ src/widgets/togglebutton.cpp | 12 ++---------- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/include/guisan/widgets/button.hpp b/include/guisan/widgets/button.hpp index 3d076d7..cb4b31e 100644 --- a/include/guisan/widgets/button.hpp +++ b/include/guisan/widgets/button.hpp @@ -156,6 +156,7 @@ namespace gcn void mousePressed(MouseEvent& mouseEvent) override; void mouseReleased(MouseEvent& mouseEvent) override; + void mouseClicked(MouseEvent& mouseEvent) override; void mouseEntered(MouseEvent& mouseEvent) override; void mouseExited(MouseEvent& mouseEvent) override; void mouseDragged(MouseEvent& mouseEvent) override; diff --git a/include/guisan/widgets/togglebutton.hpp b/include/guisan/widgets/togglebutton.hpp index d85ae2f..3c0d876 100644 --- a/include/guisan/widgets/togglebutton.hpp +++ b/include/guisan/widgets/togglebutton.hpp @@ -112,7 +112,7 @@ namespace gcn // Inherited from MouseListener - void mouseReleased(MouseEvent& mouseEvent) override; + void mouseClicked(MouseEvent& mouseEvent) override; // Inherited from KeyListener diff --git a/src/widgets/button.cpp b/src/widgets/button.cpp index 3de9bec..519de16 100644 --- a/src/widgets/button.cpp +++ b/src/widgets/button.cpp @@ -230,17 +230,18 @@ namespace gcn void Button::mouseReleased(MouseEvent& mouseEvent) { - if (mouseEvent.getButton() == MouseEvent::Left - && mMousePressed - && mHasMouse) + if (mouseEvent.getButton() == MouseEvent::Left) { mMousePressed = false; - distributeActionEvent(); mouseEvent.consume(); } - else if (mouseEvent.getButton() == MouseEvent::Left) + } + + void Button::mouseClicked(MouseEvent& mouseEvent) + { + if (mouseEvent.getButton() == MouseEvent::Left) { - mMousePressed = false; + distributeActionEvent(); mouseEvent.consume(); } } diff --git a/src/widgets/togglebutton.cpp b/src/widgets/togglebutton.cpp index 59e2894..a8f5a48 100644 --- a/src/widgets/togglebutton.cpp +++ b/src/widgets/togglebutton.cpp @@ -158,22 +158,14 @@ namespace gcn mSelected = selected; } - void ToggleButton::mouseReleased(MouseEvent& mouseEvent) + void ToggleButton::mouseClicked(MouseEvent& mouseEvent) { - if (mouseEvent.getButton() == MouseEvent::Left - && mMousePressed - && mHasMouse) + if (mouseEvent.getButton() == MouseEvent::Left) { - mMousePressed = false; toggleSelected(); distributeActionEvent(); mouseEvent.consume(); } - else if (mouseEvent.getButton() == MouseEvent::Left) - { - mMousePressed = false; - mouseEvent.consume(); - } } void ToggleButton::keyReleased(KeyEvent& keyEvent)