diff --git a/doc/changelog.dox b/doc/changelog.dox index 9bdbcc0f7..f4c48821a 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -1437,6 +1437,14 @@ See also: @ref Platform::GlfwApplication and the @ref Platform::BasicScreenedApplication / @ref Platform::BasicScreen wrappers as well. +- @cpp Platform::Sdl2Application::multiGestureEvent() @ce and the + @cpp MultiGestureEvent @ce event class is deprecated in favor of a new + @ref Platform::TwoFingerGesture helper. The SDL event reported relative + distance to previous finger positions instead of a relative diameter + between multiple pressed fingers, making it practically useless for + implementing pinch zoom. It additionally reported everything in normalized + coordinates, thus the distance and rotation was only meaningful when the + window was an exact square. - @cpp Platform::Sdl2Application::InputEvent::Modifier @ce, @cpp Modifiers @ce and @cpp Platform::Sdl2Application::KeyEvent::Key @ce enums and the @cpp Platform::Sdl2Application::KeyEvent::keyName(Key) @ce diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index e8264fdcc..70d5d1938 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -1212,11 +1212,15 @@ bool Sdl2Application::mainLoopIteration() { } #endif + #ifdef MAGNUM_BUILD_DEPRECATED case SDL_MULTIGESTURE: { + CORRADE_IGNORE_DEPRECATED_PUSH MultiGestureEvent e{event, {event.mgesture.x, event.mgesture.y}, event.mgesture.dTheta, event.mgesture.dDist, event.mgesture.numFingers}; multiGestureEvent(e); + CORRADE_IGNORE_DEPRECATED_POP break; } + #endif case SDL_TEXTINPUT: { TextInputEvent e{event, event.text.text}; @@ -1590,10 +1594,10 @@ void Sdl2Application::scrollEvent(ScrollEvent& event) { #ifdef MAGNUM_BUILD_DEPRECATED CORRADE_IGNORE_DEPRECATED_PUSH void Sdl2Application::mouseScrollEvent(MouseScrollEvent&) {} +void Sdl2Application::multiGestureEvent(MultiGestureEvent&) {} CORRADE_IGNORE_DEPRECATED_POP #endif -void Sdl2Application::multiGestureEvent(MultiGestureEvent&) {} void Sdl2Application::textInputEvent(TextInputEvent&) {} void Sdl2Application::textEditingEvent(TextEditingEvent&) {} diff --git a/src/Magnum/Platform/Sdl2Application.h b/src/Magnum/Platform/Sdl2Application.h index abbbbceba..f0be2c2c9 100644 --- a/src/Magnum/Platform/Sdl2Application.h +++ b/src/Magnum/Platform/Sdl2Application.h @@ -560,8 +560,8 @@ class Sdl2Application { class MouseEvent; class MouseMoveEvent; class MouseScrollEvent; - #endif class MultiGestureEvent; + #endif class TextInputEvent; class TextEditingEvent; @@ -1353,16 +1353,24 @@ class Sdl2Application { * Default implementation does nothing. */ virtual CORRADE_DEPRECATED("use scrollEvent() instead") void mouseScrollEvent(MouseScrollEvent& event); - #endif /** * @brief Multi gesture event + * @m_deprecated_since_latest The SDL event reports relative distance + * to previous finger positions instead of a relative diameter + * between multiple pressed fingers, making it practically useless + * for implementing pinch zoom. It additionally reports everything + * in normalized coordinates, thus the distance and rotation is + * only meaningful when the window is an exact square. Use the + * @ref TwoFingerGesture helper instead and feed it with events + * coming from @ref pointerPressEvent(), + * @ref pointerReleaseEvent() and @ref pointerMoveEvent(). * * Called when the user performs a gesture using multiple fingers. * Default implementation does nothing. - * @experimental */ - virtual void multiGestureEvent(MultiGestureEvent& event); + virtual CORRADE_DEPRECATED("use pointerEvent(), pointerMoveEvent() and TwoFingerGesture instead") void multiGestureEvent(MultiGestureEvent& event); + #endif /* Since 1.8.17, the original short-hand group closing doesn't work anymore. FFS. */ @@ -3401,15 +3409,21 @@ class CORRADE_DEPRECATED("use ScrollEvent and scrollEvent() instead") Sdl2Applic Containers::Optional _position; Containers::Optional _modifiers; }; -#endif /** @brief Multi gesture event +@m_deprecated_since_latest The SDL event reports relative distance to previous + finger positions instead of a relative diameter between multiple pressed + fingers, making it practically useless for implementing pinch zoom. It + additionally reports everything in normalized coordinates, thus the + distance and rotation is only meaningful when the window is an exact + square. Use the @ref TwoFingerGesture helper instead and feed it with + events coming from @ref pointerPressEvent(), @ref pointerReleaseEvent() and + @ref pointerMoveEvent(). -@experimental @see @ref multiGestureEvent() */ -class Sdl2Application::MultiGestureEvent { +class CORRADE_DEPRECATED("use TwoFingerGesture with pointerPressEvent(), pointerReleaseEvent() and pointerMoveEvent() instead") Sdl2Application::MultiGestureEvent { public: /** @brief Copying is not allowed */ MultiGestureEvent(const MultiGestureEvent&) = delete; @@ -3480,6 +3494,7 @@ class Sdl2Application::MultiGestureEvent { const Int _fingerCount; bool _accepted; }; +#endif /** @brief Text input event diff --git a/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp b/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp index fe099181f..0463b1a11 100644 --- a/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp +++ b/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp @@ -344,13 +344,9 @@ struct Sdl2ApplicationTest: Platform::Application { #if 1 void pointerPressEvent(PointerEvent& event) override { Debug{} << "pointer press:" << event.source() << event.pointer() << (event.isPrimary() ? "primary" : "secondary") << event.id() << event.modifiers() << Debug::packed << event.position(); - _gestureDistance = {}; - _gestureRotation = {}; } void pointerReleaseEvent(PointerEvent& event) override { Debug{} << "pointer release:" << event.source() << event.pointer() << (event.isPrimary() ? "primary" : "secondary") << event.id() << event.modifiers() << Debug::packed << event.position(); - _gestureDistance = {}; - _gestureRotation = {}; } void pointerMoveEvent(PointerMoveEvent& event) override { Debug{} << "pointer move:" << event.source() << event.pointer() << event.pointers() << (event.isPrimary() ? "primary" : "secondary") << event.id() << event.modifiers() << Debug::packed << event.position() << Debug::packed << event.relativePosition(); @@ -362,13 +358,9 @@ struct Sdl2ApplicationTest: Platform::Application { CORRADE_IGNORE_DEPRECATED_PUSH void mousePressEvent(MouseEvent& event) override { Debug{} << "mouse press:" << event.button() << Debug::packed << event.position() << event.modifiers(); - _gestureDistance = {}; - _gestureRotation = {}; } void mouseReleaseEvent(MouseEvent& event) override { Debug{} << "mouse release:" << event.button() << Debug::packed << event.position() << event.modifiers(); - _gestureDistance = {}; - _gestureRotation = {}; } void mouseMoveEvent(MouseMoveEvent& event) override { Debug{} << "mouse move:" << event.buttons() << Debug::packed << event.position() << Debug::packed << event.relativePosition() << event.modifiers(); @@ -379,12 +371,6 @@ struct Sdl2ApplicationTest: Platform::Application { CORRADE_IGNORE_DEPRECATED_POP #endif - void multiGestureEvent(MultiGestureEvent& event) override { - Debug{} << "multi gesture:" << event.center() << "rotation:" << Deg{_gestureRotation} << Debug::nospace << ", relative" << Deg{event.relativeRotation()} << Debug::nospace << ", distance" << _gestureDistance << Debug::nospace << ", relative" << event.relativeDistance() << Debug::nospace << ", fingers" << event.fingerCount(); - _gestureDistance += event.relativeDistance(); - _gestureRotation += Rad(event.relativeRotation()); - } - void keyPressEvent(KeyEvent& event) override { Debug{} << "key press:" << event.key() << event.keyName() << "scancode:" << event.scanCode() #ifndef CORRADE_TARGET_EMSCRIPTEN @@ -517,8 +503,6 @@ struct Sdl2ApplicationTest: Platform::Application { #ifndef CORRADE_TARGET_EMSCRIPTEN bool _vsync = false; #endif - Float _gestureDistance{}; - Rad _gestureRotation{}; }; Sdl2ApplicationTest::Sdl2ApplicationTest(const Arguments& arguments): Platform::Application{arguments, NoCreate} {