From 1a729aa3af7030dd645feeb32fbd6081c5691613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 15 Nov 2012 21:59:36 +0100 Subject: [PATCH] NaClApplication: mouse input handling. --- src/Platform/NaClApplication.cpp | 12 +++++++ src/Platform/NaClApplication.h | 55 +++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/Platform/NaClApplication.cpp b/src/Platform/NaClApplication.cpp index 9db9afa6b..1c57c2f14 100644 --- a/src/Platform/NaClApplication.cpp +++ b/src/Platform/NaClApplication.cpp @@ -91,6 +91,18 @@ bool NaClApplication::HandleInputEvent(const pp::InputEvent& event) { pp::KeyboardInputEvent keyEvent(event); keyReleaseEvent(static_cast(keyEvent.GetKeyCode()), static_cast(keyEvent.GetModifiers()), {}); break; + } case PP_INPUTEVENT_TYPE_MOUSEDOWN: { + pp::MouseInputEvent mouseEvent(event); + mousePressEvent(static_cast(mouseEvent.GetButton()), static_cast(mouseEvent.GetModifiers()), {mouseEvent.GetPosition().x(), mouseEvent.GetPosition().y()}); + break; + } case PP_INPUTEVENT_TYPE_MOUSEUP: { + pp::MouseInputEvent mouseEvent(event); + mouseReleaseEvent(static_cast(mouseEvent.GetButton()), static_cast(mouseEvent.GetModifiers()), {mouseEvent.GetPosition().x(), mouseEvent.GetPosition().y()}); + break; + } case PP_INPUTEVENT_TYPE_MOUSEMOVE: { + pp::MouseInputEvent mouseEvent(event); + mouseMotionEvent(static_cast(mouseEvent.GetModifiers()), {mouseEvent.GetPosition().x(), mouseEvent.GetPosition().y()}); + break; } default: return false; } diff --git a/src/Platform/NaClApplication.h b/src/Platform/NaClApplication.h index 69f64d140..bb66000b5 100644 --- a/src/Platform/NaClApplication.h +++ b/src/Platform/NaClApplication.h @@ -136,7 +136,8 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient { /** * @brief Set of modifiers * - * @see keyPressEvent(), keyReleaseEvent() + * @see keyPressEvent(), keyReleaseEvent(), mousePressEvent(), + * mouseReleaseEvent(), mouseMotionEvent() */ typedef Corrade::Containers::EnumSet Modifiers; @@ -237,6 +238,54 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient { /*@}*/ + /** @{ @name Mouse handling */ + + public: + /** + * @brief Mouse button + * + * @see mousePressEvent(), mouseReleaseEvent() + */ + enum class MouseButton: unsigned int { + Left = PP_INPUTEVENT_MOUSEBUTTON_LEFT, /**< Left button */ + Middle = PP_INPUTEVENT_MOUSEBUTTON_MIDDLE, /**< Middle button */ + Right = PP_INPUTEVENT_MOUSEBUTTON_RIGHT /**< Right button */ + }; + + protected: + /** + * @brief Mouse press event + * @param button Button pressed + * @param modifiers Active modifiers + * @param position Cursor position + * + * Called when mouse button is pressed. Default implementation does + * nothing. + */ + virtual void mousePressEvent(MouseButton button, Modifiers modifiers, const Math::Vector2& position); + + /** + * @brief Mouse release event + * @param button Button released + * @param modifiers Active modifiers + * @param position Cursor position + * + * Called when mouse button is released. Default implementation does + * nothing. + */ + virtual void mouseReleaseEvent(MouseButton button, Modifiers modifiers, const Math::Vector2& position); + + /** + * @brief Mouse motion event + * @param modifiers Active modifiers + * @param position Cursor position + * + * Called when mouse is moved. + */ + virtual void mouseMotionEvent(Modifiers modifiers, const Math::Vector2& position); + + /*@}*/ + private: enum class Flag: std::uint8_t { ViewportUpdated = 1 << 0, @@ -311,6 +360,10 @@ When no other application header is included this macro is also aliased to /* Implementations for inline functions with unused parameters */ inline void NaClApplication::keyPressEvent(Key, Modifiers, const Math::Vector2&) {} inline void NaClApplication::keyReleaseEvent(Key, Modifiers, const Math::Vector2&) {} +inline void NaClApplication::mousePressEvent(MouseButton, Modifiers, const Math::Vector2&) {} +inline void NaClApplication::mouseReleaseEvent(MouseButton, Modifiers, const Math::Vector2&) {} +inline void NaClApplication::mouseMotionEvent(Modifiers, const Math::Vector2&) {} + }}