From 6bc89879bc83ef112694a6fe55bafb728241ce33 Mon Sep 17 00:00:00 2001 From: Riverlance Date: Thu, 23 Mar 2023 03:07:29 -0300 Subject: [PATCH 1/3] Fix mouse buttons As an example, MouseMidButton was the same as pressing MouseLeftButton+MouseRightButton at the same time. Because MouseLeftButton (1) + MouseRightButton (2) = MouseMidButton (3). It means, if I check in my code if I'm pressing mid button `g_window.isPressed(MouseMidButton)`, it will work with mid button, but ALSO if I click left+right buttons. It should not work like that. Mouse buttons uses bitwise logic, so these values should be like 0, 1, 2, 4, 8, and so on, not like 0, 1, 2, 3, 4, 5, 6, 7, 8, and so on. --- modules/corelib/const.lua | 3 ++- src/framework/const.h | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/corelib/const.lua b/modules/corelib/const.lua index 086f6880d2..750731149c 100644 --- a/modules/corelib/const.lua +++ b/modules/corelib/const.lua @@ -47,7 +47,8 @@ KeyboardCtrlAltShiftModifier = 7 MouseNoButton = 0 MouseLeftButton = 1 MouseRightButton = 2 -MouseMidButton = 3 +MouseMidButton = 4 +MouseXButton = 8 MouseNoWheel = 0 MouseWheelUp = 1 diff --git a/src/framework/const.h b/src/framework/const.h index 30720ff219..58e32e2b43 100644 --- a/src/framework/const.h +++ b/src/framework/const.h @@ -251,10 +251,10 @@ namespace Fw enum MouseButton : uint8_t { MouseNoButton = 0, - MouseLeftButton, - MouseRightButton, - MouseMidButton, - MouseXButton + MouseLeftButton = 1 << 0, + MouseRightButton = 1 << 1, + MouseMidButton = 1 << 2, + MouseXButton = 1 << 3 }; enum MouseWheelDirection : uint8_t From 55f2722bb4e7141f6799dc41fe62689ca100f648 Mon Sep 17 00:00:00 2001 From: Renato Date: Thu, 30 Mar 2023 14:05:45 -0300 Subject: [PATCH 2/3] Revert "Fix mouse buttons" This reverts commit 6bc89879bc83ef112694a6fe55bafb728241ce33. --- modules/corelib/const.lua | 3 +-- src/framework/const.h | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/modules/corelib/const.lua b/modules/corelib/const.lua index 750731149c..086f6880d2 100644 --- a/modules/corelib/const.lua +++ b/modules/corelib/const.lua @@ -47,8 +47,7 @@ KeyboardCtrlAltShiftModifier = 7 MouseNoButton = 0 MouseLeftButton = 1 MouseRightButton = 2 -MouseMidButton = 4 -MouseXButton = 8 +MouseMidButton = 3 MouseNoWheel = 0 MouseWheelUp = 1 diff --git a/src/framework/const.h b/src/framework/const.h index 58e32e2b43..30720ff219 100644 --- a/src/framework/const.h +++ b/src/framework/const.h @@ -251,10 +251,10 @@ namespace Fw enum MouseButton : uint8_t { MouseNoButton = 0, - MouseLeftButton = 1 << 0, - MouseRightButton = 1 << 1, - MouseMidButton = 1 << 2, - MouseXButton = 1 << 3 + MouseLeftButton, + MouseRightButton, + MouseMidButton, + MouseXButton }; enum MouseWheelDirection : uint8_t From 554532fd09b942cdb0e1988747ce2ec3753b3154 Mon Sep 17 00:00:00 2001 From: Renato Date: Thu, 30 Mar 2023 14:17:17 -0300 Subject: [PATCH 3/3] changes --- src/framework/platform/androidwindow.cpp | 4 ++-- src/framework/platform/platformwindow.h | 2 +- src/framework/platform/win32window.cpp | 16 ++++++++-------- src/framework/platform/x11window.cpp | 12 ++++++------ 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/framework/platform/androidwindow.cpp b/src/framework/platform/androidwindow.cpp index 3951030f96..e17ca88675 100644 --- a/src/framework/platform/androidwindow.cpp +++ b/src/framework/platform/androidwindow.cpp @@ -255,9 +255,9 @@ void AndroidWindow::processFingerDownAndUp() { m_inputEvent.type = (isTouchdown) ? Fw::MousePressInputEvent : Fw::MouseReleaseInputEvent; m_inputEvent.mouseButton = mouseButton; if(isTouchdown) { - m_mouseButtonStates |= mouseButton; + m_mouseButtonStates |= 1 << mouseButton; } else { - g_dispatcher.addEvent([this, mouseButton] { m_mouseButtonStates &= ~mouseButton; }); + g_dispatcher.addEvent([this, mouseButton] { m_mouseButtonStates &= ~(1 << mouseButton); }); } handleInputEvent(); diff --git a/src/framework/platform/platformwindow.h b/src/framework/platform/platformwindow.h index fba26906a7..7cc3f34aac 100644 --- a/src/framework/platform/platformwindow.h +++ b/src/framework/platform/platformwindow.h @@ -88,7 +88,7 @@ class PlatformWindow bool isKeyPressed(Fw::Key keyCode) { return m_keysState[keyCode]; } bool isMouseButtonPressed(Fw::MouseButton mouseButton) - { if (mouseButton == Fw::MouseNoButton) return m_mouseButtonStates != 0; return (m_mouseButtonStates & mouseButton) == mouseButton; } + { if (mouseButton == Fw::MouseNoButton) return m_mouseButtonStates != 0; return (m_mouseButtonStates & (1 << mouseButton)) == (1 << mouseButton); } bool isVisible() { return m_visible; } bool isMaximized() { return m_maximized; } bool isFullscreen() { return m_fullscreen; } diff --git a/src/framework/platform/win32window.cpp b/src/framework/platform/win32window.cpp index 924db1ea25..8125ef5efd 100644 --- a/src/framework/platform/win32window.cpp +++ b/src/framework/platform/win32window.cpp @@ -647,7 +647,7 @@ LRESULT WIN32Window::windowProc(HWND hWnd, uint32_t uMsg, WPARAM wParam, LPARAM SetCapture(m_window); m_inputEvent.reset(Fw::MousePressInputEvent); m_inputEvent.mouseButton = Fw::MouseLeftButton; - m_mouseButtonStates |= Fw::MouseLeftButton; + m_mouseButtonStates |= 1 << Fw::MouseLeftButton; if (m_onInputEvent) m_onInputEvent(m_inputEvent); break; @@ -657,7 +657,7 @@ LRESULT WIN32Window::windowProc(HWND hWnd, uint32_t uMsg, WPARAM wParam, LPARAM SetCapture(nullptr); m_inputEvent.reset(Fw::MouseReleaseInputEvent); m_inputEvent.mouseButton = Fw::MouseLeftButton; - g_dispatcher.addEvent([this] { m_mouseButtonStates &= ~Fw::MouseLeftButton; }); + g_dispatcher.addEvent([this] { m_mouseButtonStates &= ~(1 << Fw::MouseLeftButton); }); if (m_onInputEvent) m_onInputEvent(m_inputEvent); break; @@ -667,7 +667,7 @@ LRESULT WIN32Window::windowProc(HWND hWnd, uint32_t uMsg, WPARAM wParam, LPARAM SetCapture(m_window); m_inputEvent.reset(Fw::MousePressInputEvent); m_inputEvent.mouseButton = Fw::MouseMidButton; - m_mouseButtonStates |= Fw::MouseMidButton; + m_mouseButtonStates |= 1 << Fw::MouseMidButton; if (m_onInputEvent) m_onInputEvent(m_inputEvent); break; @@ -677,7 +677,7 @@ LRESULT WIN32Window::windowProc(HWND hWnd, uint32_t uMsg, WPARAM wParam, LPARAM SetCapture(nullptr); m_inputEvent.reset(Fw::MouseReleaseInputEvent); m_inputEvent.mouseButton = Fw::MouseMidButton; - g_dispatcher.addEvent([this] { m_mouseButtonStates &= ~Fw::MouseMidButton; }); + g_dispatcher.addEvent([this] { m_mouseButtonStates &= ~(1 << Fw::MouseMidButton); }); if (m_onInputEvent) m_onInputEvent(m_inputEvent); break; @@ -687,7 +687,7 @@ LRESULT WIN32Window::windowProc(HWND hWnd, uint32_t uMsg, WPARAM wParam, LPARAM SetCapture(m_window); m_inputEvent.reset(Fw::MousePressInputEvent); m_inputEvent.mouseButton = Fw::MouseRightButton; - m_mouseButtonStates |= Fw::MouseRightButton; + m_mouseButtonStates |= 1 << Fw::MouseRightButton; if (m_onInputEvent) m_onInputEvent(m_inputEvent); break; @@ -697,7 +697,7 @@ LRESULT WIN32Window::windowProc(HWND hWnd, uint32_t uMsg, WPARAM wParam, LPARAM SetCapture(nullptr); m_inputEvent.reset(Fw::MouseReleaseInputEvent); m_inputEvent.mouseButton = Fw::MouseRightButton; - g_dispatcher.addEvent([this] { m_mouseButtonStates &= ~Fw::MouseRightButton; }); + g_dispatcher.addEvent([this] { m_mouseButtonStates &= ~(1 << Fw::MouseRightButton); }); if (m_onInputEvent) m_onInputEvent(m_inputEvent); break; @@ -710,7 +710,7 @@ LRESULT WIN32Window::windowProc(HWND hWnd, uint32_t uMsg, WPARAM wParam, LPARAM const uint32_t mouseButton = (Fw::MouseXButton - 1) + GET_XBUTTON_WPARAM(wParam); m_inputEvent.reset(Fw::MousePressInputEvent); m_inputEvent.mouseButton = static_cast(mouseButton); - m_mouseButtonStates |= mouseButton; + m_mouseButtonStates |= 1 << mouseButton; if (m_onInputEvent) m_onInputEvent(m_inputEvent); @@ -723,7 +723,7 @@ LRESULT WIN32Window::windowProc(HWND hWnd, uint32_t uMsg, WPARAM wParam, LPARAM const uint32_t mouseButton = (Fw::MouseXButton - 1) + GET_XBUTTON_WPARAM(wParam); m_inputEvent.reset(Fw::MouseReleaseInputEvent); m_inputEvent.mouseButton = static_cast(mouseButton); - g_dispatcher.addEvent([this, mouseButton] { m_mouseButtonStates &= ~mouseButton; }); + g_dispatcher.addEvent([this, mouseButton] { m_mouseButtonStates &= ~(1 << mouseButton); }); if (m_onInputEvent) m_onInputEvent(m_inputEvent); diff --git a/src/framework/platform/x11window.cpp b/src/framework/platform/x11window.cpp index e596c1e5a0..b35466922c 100644 --- a/src/framework/platform/x11window.cpp +++ b/src/framework/platform/x11window.cpp @@ -782,18 +782,18 @@ void X11Window::poll() switch (event.xbutton.button) { case Button1: m_inputEvent.mouseButton = Fw::MouseLeftButton; - if (event.type == ButtonPress) { m_mouseButtonStates |= Fw::MouseLeftButton; } - else { g_dispatcher.addEvent([this] { m_mouseButtonStates &= ~Fw::MouseLeftButton; }); } + if (event.type == ButtonPress) { m_mouseButtonStates |= 1 << Fw::MouseLeftButton; } + else { g_dispatcher.addEvent([this] { m_mouseButtonStates &= ~(1 << Fw::MouseLeftButton); }); } break; case Button3: m_inputEvent.mouseButton = Fw::MouseRightButton; - if (event.type == ButtonPress) { m_mouseButtonStates |= Fw::MouseRightButton; } - else { g_dispatcher.addEvent([this] { m_mouseButtonStates &= ~Fw::MouseRightButton; }); } + if (event.type == ButtonPress) { m_mouseButtonStates |= 1 << Fw::MouseRightButton; } + else { g_dispatcher.addEvent([this] { m_mouseButtonStates &= ~(1 << Fw::MouseRightButton); }); } break; case Button2: m_inputEvent.mouseButton = Fw::MouseMidButton; - if (event.type == ButtonPress) { m_mouseButtonStates |= Fw::MouseMidButton; } - else { g_dispatcher.addEvent([this] { m_mouseButtonStates &= ~Fw::MouseMidButton; }); } + if (event.type == ButtonPress) { m_mouseButtonStates |= 1 << Fw::MouseMidButton; } + else { g_dispatcher.addEvent([this] { m_mouseButtonStates &= ~(1 << Fw::MouseMidButton); }); } break; case Button4: if (event.type == ButtonPress) {