diff --git a/source/simple/interactive/event.cpp b/source/simple/interactive/event.cpp index fd1035da6595f71062896daa730722c4508028c0..d857f00db822799ac02e417d837cbf492d1d35b7 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 5dc79f2a0e33b989f7ad9bc78dd17800f622581f..d0d4445c02e8504087d39440c4625efcf0aedb2b 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;