From d69e7821e811f1a659e012304e6a17c10fffaa13 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Wed, 8 Nov 2023 11:24:37 -0500 Subject: [PATCH] Use KDUtils::Flags for MouseButtons in KDGui MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: If57f2f49826109025dc1bc078dd853e116c0d9f6 Reviewed-on: https://codereview.kdab.com/c/kdab/kdutils/+/133380 Tested-by: Continuous Integration Reviewed-by: Sean Harmer Reviewed-by: MiƂosz Kosobucki --- src/KDGui/gui_events.h | 7 ++++--- src/KDGui/platform/cocoa/cocoa_platform_window.mm | 8 ++++---- src/KDGui/platform/win32/win32_platform_window.cpp | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/KDGui/gui_events.h b/src/KDGui/gui_events.h index 022b278..941b5d3 100644 --- a/src/KDGui/gui_events.h +++ b/src/KDGui/gui_events.h @@ -13,6 +13,7 @@ #include #include +#include #include @@ -24,9 +25,7 @@ enum MouseButton { MiddleButton = 0x00000002, RightButton = 0x00000004 }; -// TODO: Need a ype-safe flags class. See e.g. -// https://stackoverflow.com/a/4226975 -using MouseButtons = uint32_t; +using MouseButtons = KDUtils::Flags; class MousePressEvent : public KDFoundation::Event { @@ -183,3 +182,5 @@ class TextInputEvent : public KDFoundation::Event }; } // namespace KDGui + +OPERATORS_FOR_FLAGS(KDGui::MouseButtons) diff --git a/src/KDGui/platform/cocoa/cocoa_platform_window.mm b/src/KDGui/platform/cocoa/cocoa_platform_window.mm index 04e3d71..c87b193 100644 --- a/src/KDGui/platform/cocoa/cocoa_platform_window.mm +++ b/src/KDGui/platform/cocoa/cocoa_platform_window.mm @@ -252,7 +252,7 @@ - (void)windowDidResize:(NSNotification *)notification @interface KDGuiView : NSView { CocoaPlatformWindow *m_platformWindow; - int m_mouseButtons; + MouseButtons m_mouseButtons; } - (instancetype)initWithPlatformWindow:(CocoaPlatformWindow *)platformWindow; @@ -314,7 +314,7 @@ - (void)mouseUp:(NSEvent *)event { const NSPoint pos = [self localPosition:[event locationInWindow]]; m_platformWindow->handleMouseRelease([self timeStamp:event], LeftButton, static_cast(pos.x), static_cast(pos.y)); - m_mouseButtons &= ~LeftButton; + m_mouseButtons.setFlag(LeftButton, false); } - (void)mouseMoved:(NSEvent *)event @@ -341,7 +341,7 @@ - (void)rightMouseUp:(NSEvent *)event { const NSPoint pos = [self localPosition:[event locationInWindow]]; m_platformWindow->handleMouseRelease([self timeStamp:event], RightButton, static_cast(pos.x), static_cast(pos.y)); - m_mouseButtons &= ~RightButton; + m_mouseButtons.setFlag(RightButton, false); } - (void)otherMouseDown:(NSEvent *)event @@ -370,7 +370,7 @@ - (void)otherMouseUp:(NSEvent *)event return; const NSPoint pos = [self localPosition:[event locationInWindow]]; m_platformWindow->handleMousePress([self timeStamp:event], MiddleButton, static_cast(pos.x), static_cast(pos.y)); - m_mouseButtons &= ~MiddleButton; + m_mouseButtons.setFlag(MiddleButton, false); } - (void)scrollWheel:(NSEvent *)event diff --git a/src/KDGui/platform/win32/win32_platform_window.cpp b/src/KDGui/platform/win32/win32_platform_window.cpp index 758d6d8..3b01306 100644 --- a/src/KDGui/platform/win32/win32_platform_window.cpp +++ b/src/KDGui/platform/win32/win32_platform_window.cpp @@ -464,5 +464,5 @@ void Win32PlatformWindow::processRawInput(HRAWINPUT rawInput) pos.y = m_previousCursorPosition.y + m_rawInputData->data.mouse.lLastY; SPDLOG_LOGGER_TRACE(m_logger, "RawInput (Relative): delta = {}, {}", pos.x, pos.y); } - handleMouseMove(GetMessageTime(), 0, pos.x, pos.y); + handleMouseMove(GetMessageTime(), NoButton, pos.x, pos.y); }