diff --git a/src/Magnum/Platform/GlfwApplication.cpp b/src/Magnum/Platform/GlfwApplication.cpp index 7753bb9f1..bac69aa43 100644 --- a/src/Magnum/Platform/GlfwApplication.cpp +++ b/src/Magnum/Platform/GlfwApplication.cpp @@ -187,13 +187,22 @@ void GlfwApplication::staticMouseEvent(GLFWwindow*, int button, int action, int } void GlfwApplication::staticMouseScrollEvent(GLFWwindow* window, double xoffset, double yoffset) { - MouseScrollEvent e(Vector2d{xoffset, yoffset}, KeyEvent::getCurrentGlfwModifiers(window)); + MouseScrollEvent e(Vector2{Float(xoffset), Float(yoffset)}, KeyEvent::getCurrentGlfwModifiers(window)); _instance->mouseScrollEvent(e); + #ifdef MAGNUM_BUILD_DEPRECATED if(yoffset != 0.0) { + #ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" + #endif MouseEvent e1((yoffset > 0.0) ? MouseEvent::Button::WheelUp : MouseEvent::Button::WheelDown, KeyEvent::getCurrentGlfwModifiers(window)); + #ifdef __GNUC__ + #pragma GCC diagnostic pop + #endif _instance->mousePressEvent(e1); } + #endif } void GlfwApplication::staticErrorCallback(int, const char* description) { diff --git a/src/Magnum/Platform/GlfwApplication.h b/src/Magnum/Platform/GlfwApplication.h index f61565f4b..4ba7537d4 100644 --- a/src/Magnum/Platform/GlfwApplication.h +++ b/src/Magnum/Platform/GlfwApplication.h @@ -247,12 +247,7 @@ class GlfwApplication { */ virtual void mouseMoveEvent(MouseMoveEvent& event); - /** - * @brief Mouse scroll event - * - * Called when a scrolling device is used (mouse wheel or scrolling - * area on touchpad). Default implementation does nothing. - */ + /** @copydoc Sdl2Application::mouseScrollEvent() */ virtual void mouseScrollEvent(MouseScrollEvent& event); /*@}*/ @@ -706,7 +701,8 @@ class GlfwApplication::KeyEvent: public GlfwApplication::InputEvent { /** @brief Mouse event -@see @ref MouseMoveEvent, @ref MouseScrollEvent, @ref mousePressEvent(), @ref mouseReleaseEvent() +@see @ref MouseMoveEvent, @ref MouseScrollEvent, @ref mousePressEvent(), + @ref mouseReleaseEvent() */ class GlfwApplication::MouseEvent: public GlfwApplication::InputEvent { friend GlfwApplication; @@ -730,8 +726,19 @@ class GlfwApplication::MouseEvent: public GlfwApplication::InputEvent { Button7 = GLFW_MOUSE_BUTTON_7, /**< Mouse button 7 */ Button8 = GLFW_MOUSE_BUTTON_8, /**< Mouse button 8 */ - WheelUp = GLFW_MOUSE_BUTTON_LAST + 1, /**< Mouse wheel up */ - WheelDown = GLFW_MOUSE_BUTTON_LAST + 2 /**< Mouse wheel down */ + #ifdef MAGNUM_BUILD_DEPRECATED + /** + * Wheel up + * @deprecated Use @ref MouseScrollEvent and @ref mouseScrollEvent() instead. + */ + WheelUp CORRADE_DEPRECATED_ENUM("use mouseScrollEvent() and MouseScrollEvent instead") = GLFW_MOUSE_BUTTON_LAST + 1, + + /** + * Wheel down + * @deprecated Use @ref MouseScrollEvent and @ref mouseScrollEvent() instead. + */ + WheelDown CORRADE_DEPRECATED_ENUM("use mouseScrollEvent() and MouseScrollEvent instead") = GLFW_MOUSE_BUTTON_LAST + 2 + #endif }; /** @brief Button */ @@ -779,15 +786,15 @@ class GlfwApplication::MouseScrollEvent: public GlfwApplication::InputEvent { public: /** @brief Scroll offset */ - constexpr Vector2d offset() const { return _offset; } + constexpr Vector2 offset() const { return _offset; } /** @brief Modifiers */ constexpr Modifiers modifiers() const { return _modifiers; } private: - constexpr MouseScrollEvent(const Vector2d& offset, Modifiers modifiers): _offset(offset), _modifiers(modifiers) {} + constexpr MouseScrollEvent(const Vector2& offset, Modifiers modifiers): _offset(offset), _modifiers(modifiers) {} - const Vector2d _offset; + const Vector2 _offset; const Modifiers _modifiers; }; diff --git a/src/Magnum/Platform/NaClApplication.cpp b/src/Magnum/Platform/NaClApplication.cpp index 9dafcd8c9..afe153845 100644 --- a/src/Magnum/Platform/NaClApplication.cpp +++ b/src/Magnum/Platform/NaClApplication.cpp @@ -192,10 +192,17 @@ bool NaClApplication::HandleInputEvent(const pp::InputEvent& event) { 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); + MouseScrollEvent e{{wheelEvent.GetDelta().x(), wheelEvent.GetDelta().y()}, static_cast(wheelEvent.GetModifiers())}; + mouseScrollEvent(e); + #ifdef MAGNUM_BUILD_DEPRECATED + if(!Math::TypeTraits::equals(wheelEvent.GetDelta().y(), 0.0f)) { + MouseEvent e2(wheelEvent.GetDelta().y() > 0 ? MouseEvent::Button::WheelUp : MouseEvent::Button::WheelDown, {}, static_cast(wheelEvent.GetModifiers())); + mousePressEvent(e2); + if(!e.isAccepted() && !e2.isAccepted()) return false; + } else if(!e.isAccepted()) return false; + #else if(!e.isAccepted()) return false; + #endif break; } @@ -261,6 +268,7 @@ void NaClApplication::keyReleaseEvent(KeyEvent&) {} void NaClApplication::mousePressEvent(MouseEvent&) {} void NaClApplication::mouseReleaseEvent(MouseEvent&) {} void NaClApplication::mouseMoveEvent(MouseMoveEvent&) {} +void NaClApplication::mouseScrollEvent(MouseScrollEvent&) {} template class BasicScreen; template class BasicScreenedApplication; diff --git a/src/Magnum/Platform/NaClApplication.h b/src/Magnum/Platform/NaClApplication.h index 488b4e742..29c22ef4b 100644 --- a/src/Magnum/Platform/NaClApplication.h +++ b/src/Magnum/Platform/NaClApplication.h @@ -204,6 +204,7 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public class KeyEvent; class MouseEvent; class MouseMoveEvent; + class MouseScrollEvent; /** @copydoc Sdl2Application::Sdl2Application(const Arguments&, const Configuration&) */ #ifdef DOXYGEN_GENERATING_OUTPUT @@ -355,6 +356,16 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public */ virtual void mouseMoveEvent(MouseMoveEvent& event); + /** + * @brief Mouse scroll event + * + * Called when a scrolling device is used (mouse wheel or scrolling + * area on a touchpad). Default implementation does nothing. If you + * accept the event, call @ref InputEvent::setAccepted() "setAccepted()" + * on it, otherwise the event will be propagated to the browser. + */ + virtual void mouseScrollEvent(MouseScrollEvent& event); + /*@}*/ private: @@ -650,7 +661,8 @@ class NaClApplication::KeyEvent: public NaClApplication::InputEvent { @brief Mouse event See also @ref InputEvent for more information. -@see @ref MouseMoveEvent, @ref mousePressEvent(), @ref mouseReleaseEvent() +@see @ref MouseMoveEvent, @ref MouseScrollEvent, @ref mousePressEvent(), + @ref mouseReleaseEvent() */ class NaClApplication::MouseEvent: public NaClApplication::InputEvent { friend NaClApplication; @@ -665,8 +677,20 @@ class NaClApplication::MouseEvent: public NaClApplication::InputEvent { Left = PP_INPUTEVENT_MOUSEBUTTON_LEFT, /**< Left button */ Middle = PP_INPUTEVENT_MOUSEBUTTON_MIDDLE, /**< Middle button */ Right = PP_INPUTEVENT_MOUSEBUTTON_RIGHT, /**< Right button */ - WheelUp = 0xFFFF01, /**< Wheel up */ - WheelDown = 0xFFFF02 /**< Wheel down */ + + #ifdef MAGNUM_BUILD_DEPRECATED + /** + * Wheel up + * @deprecated Use @ref MouseScrollEvent and @ref mouseScrollEvent() instead. + */ + WheelUp CORRADE_DEPRECATED_ENUM("use mouseScrollEvent() and MouseScrollEvent instead") = 0xFFFF01, + + /** + * Wheel down + * @deprecated Use @ref MouseScrollEvent and @ref mouseScrollEvent() instead. + */ + WheelDown CORRADE_DEPRECATED_ENUM("use mouseScrollEvent() and MouseScrollEvent instead") = 0xFFFF02 + #endif }; /** @brief Button */ @@ -692,7 +716,7 @@ class NaClApplication::MouseEvent: public NaClApplication::InputEvent { @brief Mouse move event See also @ref InputEvent for more information. -@see @ref MouseEvent, @ref mouseMoveEvent() +@see @ref MouseEvent, @ref MouseScrollEvent, @ref mouseMoveEvent() */ class NaClApplication::MouseMoveEvent: public NaClApplication::InputEvent { friend NaClApplication; @@ -714,6 +738,25 @@ class NaClApplication::MouseMoveEvent: public NaClApplication::InputEvent { const Vector2i _position, _relativePosition; }; +/** +@brief Mouse scroll event + +See also @ref InputEvent for more information. +@see @ref MouseEvent, @ref MouseMoveEvent, @ref mouseScrollEvent() +*/ +class NaClApplication::MouseScrollEvent: public NaClApplication::InputEvent { + friend NaClApplication; + + public: + /** @brief Scroll offset */ + constexpr Vector2 offset() const { return _offset; } + + private: + constexpr MouseScrollEvent(const Vector2& offset, Modifiers modifiers): InputEvent{modifiers}, _offset{offset} {} + + const Vector2 _offset; +}; + CORRADE_ENUMSET_OPERATORS(NaClApplication::Flags) namespace Implementation { diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index ffcefec35..7578fdbdd 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -384,15 +384,28 @@ void Sdl2Application::mainLoop() { event.type == SDL_MOUSEBUTTONDOWN ? mousePressEvent(e) : mouseReleaseEvent(e); } break; - case SDL_MOUSEWHEEL: + case SDL_MOUSEWHEEL: { + MouseScrollEvent e{{Float(event.wheel.x), Float(event.wheel.y)}}; + mouseScrollEvent(e); + + #ifdef MAGNUM_BUILD_DEPRECATED if(event.wheel.y != 0) { + #ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" + #endif MouseEvent e(event.wheel.y > 0 ? MouseEvent::Button::WheelUp : MouseEvent::Button::WheelDown, {event.wheel.x, event.wheel.y} #ifndef CORRADE_TARGET_EMSCRIPTEN , 0 #endif ); + #ifdef __GNUC__ + #pragma GCC diagnostic pop + #endif mousePressEvent(e); - } break; + } + #endif + } break; case SDL_MOUSEMOTION: { MouseMoveEvent e({event.motion.x, event.motion.y}, {event.motion.xrel, event.motion.yrel}, static_cast(event.motion.state)); @@ -510,6 +523,7 @@ void Sdl2Application::keyReleaseEvent(KeyEvent&) {} void Sdl2Application::mousePressEvent(MouseEvent&) {} void Sdl2Application::mouseReleaseEvent(MouseEvent&) {} void Sdl2Application::mouseMoveEvent(MouseMoveEvent&) {} +void Sdl2Application::mouseScrollEvent(MouseScrollEvent&) {} void Sdl2Application::multiGestureEvent(MultiGestureEvent&) {} void Sdl2Application::textInputEvent(TextInputEvent&) {} void Sdl2Application::textEditingEvent(TextEditingEvent&) {} @@ -543,6 +557,12 @@ Sdl2Application::InputEvent::Modifiers Sdl2Application::MouseMoveEvent::modifier return _modifiers = fixedModifiers(Uint16(SDL_GetModState())); } +Sdl2Application::InputEvent::Modifiers Sdl2Application::MouseScrollEvent::modifiers() { + if(_modifiersLoaded) return _modifiers; + _modifiersLoaded = true; + return _modifiers = fixedModifiers(Uint16(SDL_GetModState())); +} + template class BasicScreen; template class BasicScreenedApplication; diff --git a/src/Magnum/Platform/Sdl2Application.h b/src/Magnum/Platform/Sdl2Application.h index 47f9d1f48..a44feb9e7 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 MouseScrollEvent; class MultiGestureEvent; class TextInputEvent; class TextEditingEvent; @@ -586,6 +587,14 @@ class Sdl2Application { */ virtual void mouseMoveEvent(MouseMoveEvent& event); + /** + * @brief Mouse scroll event + * + * Called when a scrolling device is used (mouse wheel or scrolling + * area on a touchpad). Default implementation does nothing. + */ + virtual void mouseScrollEvent(MouseScrollEvent& event); + /*@}*/ /** @{ @name Touch gesture handling */ @@ -1125,7 +1134,8 @@ class Sdl2Application::KeyEvent: public Sdl2Application::InputEvent { /** @brief Mouse event -@see @ref MouseMoveEvent, @ref mousePressEvent(), @ref mouseReleaseEvent() +@see @ref MouseMoveEvent, @ref MouseScrollEvent, @ref mousePressEvent(), + @ref mouseReleaseEvent() */ class Sdl2Application::MouseEvent: public Sdl2Application::InputEvent { friend Sdl2Application; @@ -1140,26 +1150,38 @@ class Sdl2Application::MouseEvent: public Sdl2Application::InputEvent { Left = SDL_BUTTON_LEFT, /**< Left button */ Middle = SDL_BUTTON_MIDDLE, /**< Middle button */ Right = SDL_BUTTON_RIGHT, /**< Right button */ - WheelUp = SDL_BUTTON_X1, /**< Wheel up */ - WheelDown = SDL_BUTTON_X2 /**< Wheel down */ + + /** First extra button (e.g. wheel left) */ + X1 = SDL_BUTTON_X1, + + /** Second extra button (e.g. wheel right) */ + X2 = SDL_BUTTON_X2, + + #ifdef MAGNUM_BUILD_DEPRECATED + /** + * Wheel up + * @deprecated Use @ref MouseScrollEvent and @ref mouseScrollEvent() instead. + */ + WheelUp CORRADE_DEPRECATED_ENUM("use mouseScrollEvent() and MouseScrollEvent instead") = SDL_BUTTON_X2 + 1, + + /** + * Wheel down + * @deprecated Use @ref MouseScrollEvent and @ref mouseScrollEvent() instead. + */ + WheelDown CORRADE_DEPRECATED_ENUM("use mouseScrollEvent() and MouseScrollEvent instead") = SDL_BUTTON_X2 + 2 + #endif }; /** @brief Button */ constexpr Button button() const { return _button; } - /** - * @brief Position - * - * For whell events this contains the horizontal and vertical scroll - * amount. - */ + /** @brief Position */ constexpr Vector2i position() const { return _position; } #ifndef CORRADE_TARGET_EMSCRIPTEN /** * @brief Click count * - * Ignored for wheel events. * @note Not available in @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten". */ constexpr Int clickCount() const { return _clickCount; } @@ -1195,7 +1217,7 @@ class Sdl2Application::MouseEvent: public Sdl2Application::InputEvent { /** @brief Mouse move event -@see @ref MouseEvent, @ref mouseMoveEvent() +@see @ref MouseEvent, @ref MouseScrollEvent, @ref mouseMoveEvent() */ class Sdl2Application::MouseMoveEvent: public Sdl2Application::InputEvent { friend Sdl2Application; @@ -1210,8 +1232,12 @@ class Sdl2Application::MouseMoveEvent: public Sdl2Application::InputEvent { Left = SDL_BUTTON_LMASK, /**< Left button */ Middle = SDL_BUTTON_MMASK, /**< Middle button */ Right = SDL_BUTTON_RMASK, /**< Right button */ - WheelUp = SDL_BUTTON_X1MASK, /**< Wheel up */ - WheelDown = SDL_BUTTON_X2MASK /**< Wheel down */ + + /** First extra button (e.g. wheel left) */ + X1 = SDL_BUTTON_X1MASK, + + /** Second extra button (e.g. wheel right) */ + X2 = SDL_BUTTON_X2MASK }; /** @@ -1250,6 +1276,33 @@ class Sdl2Application::MouseMoveEvent: public Sdl2Application::InputEvent { Modifiers _modifiers; }; +/** +@brief Mouse scroll event + +@see @ref MouseEvent, @ref MouseMoveEvent, @ref mouseScrollEvent() +*/ +class Sdl2Application::MouseScrollEvent: public Sdl2Application::InputEvent { + friend Sdl2Application; + + public: + /** @brief Scroll offset */ + constexpr Vector2 offset() const { return _offset; } + + /** + * @brief Modifiers + * + * Lazily populated on first request. + */ + Modifiers modifiers(); + + private: + constexpr MouseScrollEvent(const Vector2& offset): _offset{offset}, _modifiersLoaded{false} {} + + const Vector2 _offset; + bool _modifiersLoaded; + Modifiers _modifiers; +}; + /** @brief Multi gesture event