From 1fc6be2a64797935d8810c64995f9ec111974df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 18 May 2016 13:04:23 +0200 Subject: [PATCH] Platform: added Sdl2Application::multiGestureEvent(). --- src/Magnum/Platform/Sdl2Application.cpp | 7 +++ src/Magnum/Platform/Sdl2Application.h | 83 +++++++++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index b68cf3433..3de708987 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -390,6 +390,12 @@ void Sdl2Application::mainLoop() { break; } + case SDL_MULTIGESTURE: { + MultiGestureEvent e({event.mgesture.x, event.mgesture.y}, event.mgesture.dTheta, event.mgesture.dDist, event.mgesture.numFingers); + multiGestureEvent(e); + break; + } + #ifndef CORRADE_TARGET_EMSCRIPTEN case SDL_TEXTINPUT: { TextInputEvent e{{event.text.text, std::strlen(event.text.text)}}; @@ -476,6 +482,7 @@ void Sdl2Application::keyReleaseEvent(KeyEvent&) {} void Sdl2Application::mousePressEvent(MouseEvent&) {} void Sdl2Application::mouseReleaseEvent(MouseEvent&) {} void Sdl2Application::mouseMoveEvent(MouseMoveEvent&) {} +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 7c3aa831b..110a62436 100644 --- a/src/Magnum/Platform/Sdl2Application.h +++ b/src/Magnum/Platform/Sdl2Application.h @@ -331,6 +331,7 @@ class Sdl2Application { class KeyEvent; class MouseEvent; class MouseMoveEvent; + class MultiGestureEvent; class TextInputEvent; class TextEditingEvent; @@ -583,6 +584,19 @@ class Sdl2Application { /*@}*/ + /** @{ @name Touch gesture handling */ + + /** + * @brief Multi gesture event + * + * Called when the user performs a gesture using multiple fingers. + * Default implementation does nothing. + * @experimental + */ + virtual void multiGestureEvent(MultiGestureEvent& event); + + /*@}*/ + /** @{ @name Text input handling */ public: /** @@ -1210,6 +1224,75 @@ class Sdl2Application::MouseMoveEvent: public Sdl2Application::InputEvent { Modifiers _modifiers; }; +/** +@brief Multi gesture event + +@experimental +@see @ref multiGestureEvent() +*/ +class Sdl2Application::MultiGestureEvent { + friend Sdl2Application; + + public: + /** @brief Copying is not allowed */ + MultiGestureEvent(const MultiGestureEvent&) = delete; + + /** @brief Moving is not allowed */ + MultiGestureEvent(MultiGestureEvent&&) = delete; + + /** @brief Copying is not allowed */ + MultiGestureEvent& operator=(const MultiGestureEvent&) = delete; + + /** @brief Moving is not allowed */ + MultiGestureEvent& operator=(MultiGestureEvent&&) = delete; + + /** @brief Whether the event is accepted */ + constexpr bool isAccepted() const { return _accepted; } + + /** + * @brief Set event as accepted + * + * If the event is ignored (i.e., not set as accepted), it might be + * propagated elsewhere, for example to another screen when using + * @ref BasicScreenedApplication "ScreenedApplication". By default is + * each event ignored and thus propagated. + */ + void setAccepted(bool accepted = true) { _accepted = accepted; } + + /** @brief Gesture center */ + Vector2 center() const { return _center; } + + /** + * @brief Relative rotation + * + * Rotation relative to previous event. + */ + Float relativeRotation() const { return _relativeRotation; } + + /** + * @brief Relative distance + * + * Distance of the fingers relative to previous event. + */ + Float relativeDistance() const { return _relativeDistance; } + + /** + * @brief Finger count + * + * Count of fingers performing the gesture. + */ + Int fingerCount() const { return _fingerCount; } + + private: + constexpr MultiGestureEvent(const Vector2& center, Float relativeRotation, Float relativeDistance, Int fingerCount): _center{center}, _relativeRotation{relativeRotation}, _relativeDistance{relativeDistance}, _fingerCount{fingerCount}, _accepted{false} {} + + Vector2 _center; + Float _relativeRotation, + _relativeDistance; + Int _fingerCount; + bool _accepted; +}; + /** @brief Text input event