Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mouse buttons #489

Merged
merged 4 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/framework/platform/androidwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/framework/platform/platformwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
16 changes: 8 additions & 8 deletions src/framework/platform/win32window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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<Fw::MouseButton>(mouseButton);
m_mouseButtonStates |= mouseButton;
m_mouseButtonStates |= 1 << mouseButton;
if (m_onInputEvent)
m_onInputEvent(m_inputEvent);

Expand All @@ -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<Fw::MouseButton>(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);

Expand Down
12 changes: 6 additions & 6 deletions src/framework/platform/x11window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down