From 0204669735d3ba4a997f09514c29f4f0f1ada667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 15 Dec 2013 20:58:59 +0100 Subject: [PATCH 1/2] Platform: add at least some support for wheel events to NaClApplication. In NaCl the wheel event is something completely different than mouse event and in my opinion overly complicated (the scrolled distance is measured in pixel precision!). To preserve at least some compatibility with other toolkits, the events are shoved into normal MouseEvent. Sadly the event doesn't contain any position information. --- src/Platform/NaClApplication.cpp | 16 ++++++++++++++++ src/Platform/NaClApplication.h | 12 ++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Platform/NaClApplication.cpp b/src/Platform/NaClApplication.cpp index 4e8385543..9272fc581 100644 --- a/src/Platform/NaClApplication.cpp +++ b/src/Platform/NaClApplication.cpp @@ -34,6 +34,13 @@ namespace Magnum { namespace Platform { +static_assert(NaClApplication::MouseEvent::Button::WheelUp != NaClApplication::MouseEvent::Button::Left && + NaClApplication::MouseEvent::Button::WheelUp != NaClApplication::MouseEvent::Button::Middle && + NaClApplication::MouseEvent::Button::WheelUp != NaClApplication::MouseEvent::Button::Right && + NaClApplication::MouseEvent::Button::WheelDown != NaClApplication::MouseEvent::Button::Left && + NaClApplication::MouseEvent::Button::WheelDown != NaClApplication::MouseEvent::Button::Middle && + NaClApplication::MouseEvent::Button::WheelDown != NaClApplication::MouseEvent::Button::Right, ""); + struct NaClApplication::ConsoleDebugOutput { explicit ConsoleDebugOutput(pp::Instance* instance); @@ -195,6 +202,15 @@ bool NaClApplication::HandleInputEvent(const pp::InputEvent& event) { break; } + case PP_INPUTEVENT_TYPE_WHEEL: { + pp::WheelInputEvent wheelEvent(event); + if(Math::TypeTraits::equals(wheelEvent.GetDelta().y(), 0.0f)) return false; + MouseEvent e(wheelEvent.GetDelta().y() > 0 ? MouseEvent::Button::WheelUp : MouseEvent::Button::WheelDown, {}, static_cast(wheelEvent.GetModifiers())); + mousePressEvent(e); + if(!e.isAccepted()) return false; + break; + } + case PP_INPUTEVENT_TYPE_MOUSEMOVE: { pp::MouseInputEvent mouseEvent(event); MouseMoveEvent e({mouseEvent.GetPosition().x(), mouseEvent.GetPosition().y()}, {mouseEvent.GetMovement().x(), mouseEvent.GetMovement().y()}, static_cast(mouseEvent.GetModifiers())); diff --git a/src/Platform/NaClApplication.h b/src/Platform/NaClApplication.h index 0377f76b8..d09e62605 100644 --- a/src/Platform/NaClApplication.h +++ b/src/Platform/NaClApplication.h @@ -612,13 +612,21 @@ class NaClApplication::MouseEvent: public NaClApplication::InputEvent { enum class Button: unsigned int { Left = PP_INPUTEVENT_MOUSEBUTTON_LEFT, /**< Left button */ Middle = PP_INPUTEVENT_MOUSEBUTTON_MIDDLE, /**< Middle button */ - Right = PP_INPUTEVENT_MOUSEBUTTON_RIGHT /**< Right button */ + Right = PP_INPUTEVENT_MOUSEBUTTON_RIGHT, /**< Right button */ + WheelUp = 0xFFFF01, /**< Wheel up */ + WheelDown = 0xFFFF02 /**< Wheel down */ }; /** @brief Button */ constexpr Button button() const { return _button; } - /** @brief Position */ + /** + * @brief Position + * + * @attention Note that due to the way the @ref Button::WheelUp and + * @ref Button::WheelDown events are handled by Native Client, the + * position information is not available, i.e. it is set to zero. + */ constexpr Vector2i position() const { return _position; } private: From 8850f69f20c45777cf31e0d38d268bb196d92bcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 15 Dec 2013 21:04:20 +0100 Subject: [PATCH 2/2] external: updated Optional with Native Client support. --- external/Optional/optional.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/external/Optional/optional.hpp b/external/Optional/optional.hpp index 0273a6afd..6656bee81 100644 --- a/external/Optional/optional.hpp +++ b/external/Optional/optional.hpp @@ -147,6 +147,8 @@ template inline constexpr typename std::remove_reference::type&& co { # if defined(EMSCRIPTEN) && EMSCRIPTEN __assert_fail(expr, file, line, ""); + # elif defined __native_client__ + __assert(expr, line, file); // WHY. # elif defined __clang__ || defined __GNU_LIBRARY__ __assert(expr, file, line); # elif defined __GNUC__