From 95a47526b65917f7e9ed3bc8647ca14218548f16 Mon Sep 17 00:00:00 2001 From: namark <namark@disroot.org> Date: Sun, 15 Aug 2021 19:47:18 +0400 Subject: [PATCH] Dubious last mouse state API... --- source/simple/interactive/event.cpp | 14 ++++++++++++++ source/simple/interactive/event.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/source/simple/interactive/event.cpp b/source/simple/interactive/event.cpp index fd1035d..d857f00 100644 --- a/source/simple/interactive/event.cpp +++ b/source/simple/interactive/event.cpp @@ -286,6 +286,20 @@ namespace simple::interactive return screen_normalized(data.window_id, data.motion, false); } + // NOTE: the SDL API functions here (and a number of others) are just getters for one internal structure. that also contains the device/mouse ID which is not exposed... why just not expose said struct? it also requires a self defeating PumpEvents call, i mean how hard is it to just handle the event and store the state on the user side? your brain on C i guess... very hard to do anything there + mouse_motion_data last_mouse_state() noexcept + { + mouse_motion_data data; + + data.button_state = static_cast<mouse_button_mask> + (SDL_GetMouseState( + &data.position.x(), &data.position.y())); + SDL_GetRelativeMouseState(&data.motion.x(), &data.motion.y()); + data.window_id = SDL_GetWindowID(SDL_GetMouseFocus()); + + return data; + } + #if SDL_VERSION_ATLEAST(2,0,4) // better to use expected<bool, error> diff --git a/source/simple/interactive/event.h b/source/simple/interactive/event.h index 5dc79f2..d0d4445 100644 --- a/source/simple/interactive/event.h +++ b/source/simple/interactive/event.h @@ -234,6 +234,9 @@ namespace simple::interactive bool relative_mouse_mode(bool enable) noexcept; void require_relative_mouse_mode(bool enable); + // dubious API that probably shouldn't be used, see note on implementation + mouse_motion_data last_mouse_state() noexcept; + #if SDL_VERSION_ATLEAST(2,0,4) // better to use expected<bool, error> bool mouse_capture(bool enable) noexcept; -- GitLab