Skip to content

Commit

Permalink
Use KDUtils::Flags for MouseButtons in KDGui
Browse files Browse the repository at this point in the history
Change-Id: If57f2f49826109025dc1bc078dd853e116c0d9f6
Reviewed-on: https://codereview.kdab.com/c/kdab/kdutils/+/133380
Tested-by: Continuous Integration <[email protected]>
Reviewed-by: Sean Harmer <[email protected]>
Reviewed-by: Miłosz Kosobucki <[email protected]>
  • Loading branch information
redstrate authored and MiKom committed Dec 22, 2023
1 parent 3941aea commit d69e782
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/KDGui/gui_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <KDFoundation/event.h>
#include <KDGui/kdgui_keys.h>
#include <KDUtils/flags.h>

#include <string>

Expand All @@ -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<MouseButton>;

class MousePressEvent : public KDFoundation::Event
{
Expand Down Expand Up @@ -183,3 +182,5 @@ class TextInputEvent : public KDFoundation::Event
};

} // namespace KDGui

OPERATORS_FOR_FLAGS(KDGui::MouseButtons)
8 changes: 4 additions & 4 deletions src/KDGui/platform/cocoa/cocoa_platform_window.mm
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ - (void)windowDidResize:(NSNotification *)notification

@interface KDGuiView : NSView {
CocoaPlatformWindow *m_platformWindow;
int m_mouseButtons;
MouseButtons m_mouseButtons;
}

- (instancetype)initWithPlatformWindow:(CocoaPlatformWindow *)platformWindow;
Expand Down Expand Up @@ -314,7 +314,7 @@ - (void)mouseUp:(NSEvent *)event
{
const NSPoint pos = [self localPosition:[event locationInWindow]];
m_platformWindow->handleMouseRelease([self timeStamp:event], LeftButton, static_cast<int16_t>(pos.x), static_cast<int16_t>(pos.y));
m_mouseButtons &= ~LeftButton;
m_mouseButtons.setFlag(LeftButton, false);
}

- (void)mouseMoved:(NSEvent *)event
Expand All @@ -341,7 +341,7 @@ - (void)rightMouseUp:(NSEvent *)event
{
const NSPoint pos = [self localPosition:[event locationInWindow]];
m_platformWindow->handleMouseRelease([self timeStamp:event], RightButton, static_cast<int16_t>(pos.x), static_cast<int16_t>(pos.y));
m_mouseButtons &= ~RightButton;
m_mouseButtons.setFlag(RightButton, false);
}

- (void)otherMouseDown:(NSEvent *)event
Expand Down Expand Up @@ -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<int16_t>(pos.x), static_cast<int16_t>(pos.y));
m_mouseButtons &= ~MiddleButton;
m_mouseButtons.setFlag(MiddleButton, false);
}

- (void)scrollWheel:(NSEvent *)event
Expand Down
2 changes: 1 addition & 1 deletion src/KDGui/platform/win32/win32_platform_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit d69e782

Please sign in to comment.