Browse Source

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.
pull/651/merge
Vladimír Vondruš 1 year ago
parent
commit
13d953313f
  1. 16
      src/Magnum/Platform/Sdl2Application.cpp
  2. 36
      src/Magnum/Platform/Sdl2Application.h

16
src/Magnum/Platform/Sdl2Application.cpp

@ -1125,7 +1125,18 @@ bool Sdl2Application::mainLoopIteration() {
} break; } break;
case SDL_MOUSEWHEEL: { 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); scrollEvent(e);
} break; } break;
@ -1684,6 +1695,8 @@ Sdl2Application::Modifiers Sdl2Application::MouseMoveEvent::modifiers() {
CORRADE_IGNORE_DEPRECATED_POP CORRADE_IGNORE_DEPRECATED_POP
#endif #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() { Vector2 Sdl2Application::ScrollEvent::position() {
if(!_position) { if(!_position) {
Vector2i position; Vector2i position;
@ -1692,6 +1705,7 @@ Vector2 Sdl2Application::ScrollEvent::position() {
} }
return *_position; return *_position;
} }
#endif
Sdl2Application::Modifiers Sdl2Application::ScrollEvent::modifiers() { Sdl2Application::Modifiers Sdl2Application::ScrollEvent::modifiers() {
if(!_modifiers) if(!_modifiers)

36
src/Magnum/Platform/Sdl2Application.h

@ -3345,16 +3345,27 @@ CORRADE_IGNORE_DEPRECATED_POP
*/ */
class Sdl2Application::ScrollEvent: public Sdl2Application::InputEvent { class Sdl2Application::ScrollEvent: public Sdl2Application::InputEvent {
public: 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; } Vector2 offset() const { return _offset; }
/** /**
* @brief Position * @brief Position
* *
* For mouse input the position is always reported in whole pixels. * For mouse input the position is always reported in whole pixels. On
* Lazily populated on first request. * 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(); Vector2 position();
#endif
/** /**
* @brief Keyboard modifiers * @brief Keyboard modifiers
@ -3366,10 +3377,27 @@ class Sdl2Application::ScrollEvent: public Sdl2Application::InputEvent {
private: private:
friend Sdl2Application; 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; 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<Vector2> _position; Containers::Optional<Vector2> _position;
#endif
Containers::Optional<Sdl2Application::Modifiers> _modifiers; Containers::Optional<Sdl2Application::Modifiers> _modifiers;
}; };

Loading…
Cancel
Save