From 13d953313f3246b10ae7afc71b8df22072c86a3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Feb 2025 19:53:10 +0100 Subject: [PATCH] Platform: use scroll event properties new since SDL 2.0.18 and 26. That versioning scheme change in between those versions is quite something, ugh. --- src/Magnum/Platform/Sdl2Application.cpp | 16 ++++++++++- src/Magnum/Platform/Sdl2Application.h | 36 ++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index 9cee45e2f..3adc63f03 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -1125,7 +1125,18 @@ bool Sdl2Application::mainLoopIteration() { } break; case SDL_MOUSEWHEEL: { - ScrollEvent e{event, {Float(event.wheel.x), Float(event.wheel.y)}}; + ScrollEvent e{event, + #if SDL_VERSION_ATLEAST(2, 0, 18) + {event.wheel.preciseX, event.wheel.preciseY} + #else + {Float(event.wheel.x), Float(event.wheel.y)} + #endif + /* Yeah, it's 2.0.22 and then 2.24.0, they changed the + versioning */ + #if SDL_VERSION_ATLEAST(2, 26, 0) + , {Float(event.wheel.mouseX), Float(event.wheel.mouseY)} + #endif + }; scrollEvent(e); } break; @@ -1684,6 +1695,8 @@ Sdl2Application::Modifiers Sdl2Application::MouseMoveEvent::modifiers() { CORRADE_IGNORE_DEPRECATED_POP #endif +/* Yeah, it's 2.0.22 and then 2.24.0, they changed the versioning */ +#if !SDL_VERSION_ATLEAST(2, 26, 0) Vector2 Sdl2Application::ScrollEvent::position() { if(!_position) { Vector2i position; @@ -1692,6 +1705,7 @@ Vector2 Sdl2Application::ScrollEvent::position() { } return *_position; } +#endif Sdl2Application::Modifiers Sdl2Application::ScrollEvent::modifiers() { if(!_modifiers) diff --git a/src/Magnum/Platform/Sdl2Application.h b/src/Magnum/Platform/Sdl2Application.h index 8e5c525fc..b2a0a50c1 100644 --- a/src/Magnum/Platform/Sdl2Application.h +++ b/src/Magnum/Platform/Sdl2Application.h @@ -3345,16 +3345,27 @@ CORRADE_IGNORE_DEPRECATED_POP */ class Sdl2Application::ScrollEvent: public Sdl2Application::InputEvent { public: - /** @brief Scroll offset */ + /** + * @brief Scroll offset + * + * @note SDL versions before 2.0.18 only report an integer value, which + * may result in the returned value being zero if the offset + * reported by the system is a fractional value less than one. + */ Vector2 offset() const { return _offset; } /** * @brief Position * - * For mouse input the position is always reported in whole pixels. - * Lazily populated on first request. + * For mouse input the position is always reported in whole pixels. On + * SDL versions before 2.26.0 is lazily populated on first request. */ + /* Yeah, it's 2.0.22 and then 2.24.0, they changed the versioning */ + #if SDL_VERSION_ATLEAST(2, 26, 0) + Vector2 position() const { return _position; } + #else Vector2 position(); + #endif /** * @brief Keyboard modifiers @@ -3366,10 +3377,27 @@ class Sdl2Application::ScrollEvent: public Sdl2Application::InputEvent { private: friend Sdl2Application; - explicit ScrollEvent(const SDL_Event& event, const Vector2& offset): InputEvent{event}, _offset{offset} {} + explicit ScrollEvent(const SDL_Event& event, const Vector2& offset + /* Yeah, it's 2.0.22 and then 2.24.0, they changed the + versioning */ + #if SDL_VERSION_ATLEAST(2, 26, 0) + , const Vector2& position + #endif + ): InputEvent{event}, _offset{offset} + /* Yeah, it's 2.0.22 and then 2.24.0, they changed the + versioning */ + #if SDL_VERSION_ATLEAST(2, 26, 0) + , _position{position} + #endif + {} const Vector2 _offset; + /* Yeah, it's 2.0.22 and then 2.24.0, they changed the versioning */ + #if SDL_VERSION_ATLEAST(2, 26, 0) + const Vector2 _position; + #else Containers::Optional _position; + #endif Containers::Optional _modifiers; };