diff --git a/src/Contexts/Sdl2WindowContext.cpp b/src/Contexts/Sdl2WindowContext.cpp index 2c2677bfc..905ef61da 100644 --- a/src/Contexts/Sdl2WindowContext.cpp +++ b/src/Contexts/Sdl2WindowContext.cpp @@ -83,23 +83,23 @@ int Sdl2WindowContext::exec() { break; } break; case SDL_KEYDOWN: - keyPressEvent(static_cast(event.key.keysym.sym), event.key.repeat); + keyPressEvent(static_cast(event.key.keysym.sym), Modifiers(), {}); break; case SDL_KEYUP: - keyReleaseEvent(static_cast(event.key.keysym.sym)); + keyReleaseEvent(static_cast(event.key.keysym.sym), Modifiers(), {}); break; case SDL_MOUSEBUTTONDOWN: - mousePressEvent(static_cast(event.button.button), {event.button.x, event.button.y}); + mousePressEvent(static_cast(event.button.button), Modifiers(), {event.button.x, event.button.y}); break; case SDL_MOUSEBUTTONUP: - mouseReleaseEvent(static_cast(event.button.button), {event.button.x, event.button.y}); + mouseReleaseEvent(static_cast(event.button.button), Modifiers(), {event.button.x, event.button.y}); break; case SDL_MOUSEWHEEL: - mouseWheelEvent({event.wheel.x, event.wheel.y}); + if(event.wheel.y != 0) + mousePressEvent(event.wheel.y < 0 ? MouseButton::WheelUp : MouseButton::WheelDown, Modifiers(), {event.wheel.x, event.wheel.y}); break; case SDL_MOUSEMOTION: - mouseMotionEvent({event.motion.x, event.motion.y}, - {event.motion.xrel, event.motion.yrel}); + mouseMotionEvent(Modifiers(), {event.motion.x, event.motion.y}); break; case SDL_QUIT: return 0; diff --git a/src/Contexts/Sdl2WindowContext.h b/src/Contexts/Sdl2WindowContext.h index c0d0f916d..3117270c9 100644 --- a/src/Contexts/Sdl2WindowContext.h +++ b/src/Contexts/Sdl2WindowContext.h @@ -24,6 +24,7 @@ #include #include +#include #include "AbstractWindowContext.h" @@ -83,6 +84,21 @@ class Sdl2WindowContext: public AbstractWindowContext { /** @{ @name Keyboard handling */ public: + /** + * @brief %Modifier + * + * @see Modifiers, keyPressEvent(), keyReleaseEvent(), + * mousePressEvent(), mouseReleaseEvent(), mouseMotionEvent() + */ + enum class Modifier: unsigned int {}; + + /** + * @brief Set of modifiers + * + * @see keyPressEvent(), keyReleaseEvent() + */ + typedef Corrade::Containers::EnumSet Modifiers; + /** * @brief Key * @@ -101,15 +117,18 @@ class Sdl2WindowContext: public AbstractWindowContext { /** * @brief Key press event * @param key Key pressed - * @param repeat Non-zero if this is a key repeat + * @param modifiers Active modifiers (not yet implemented) + * @param position Cursor position (not yet implemented) */ - virtual void keyPressEvent(Key key, Uint8 repeat); + virtual void keyPressEvent(Key key, Modifiers modifiers, const Math::Vector2& position); /** * @brief Key release event * @param key Key released + * @param modifiers Active modifiers (not yet implemented) + * @param position Cursor position (not yet implemented) */ - virtual void keyReleaseEvent(Key key); + virtual void keyReleaseEvent(Key key, Modifiers modifiers, const Math::Vector2& position); /*@}*/ @@ -124,7 +143,9 @@ class Sdl2WindowContext: public AbstractWindowContext { enum class MouseButton: Uint8 { Left = SDL_BUTTON_LEFT, /**< Left button */ Middle = SDL_BUTTON_MIDDLE, /**< Middle button */ - Right = SDL_BUTTON_RIGHT /**< Right button */ + Right = SDL_BUTTON_RIGHT, /**< Right button */ + WheelUp = 4, /**< Wheel up */ + WheelDown = 5 /**< Wheel down */ }; /** @@ -141,41 +162,33 @@ class Sdl2WindowContext: public AbstractWindowContext { /** * @brief Mouse press event * @param button Button pressed + * @param modifiers Active modifiers (not yet implemented) * @param position Cursor position * * Called when mouse button is pressed. Default implementation does * nothing. */ - virtual void mousePressEvent(MouseButton button, const Math::Vector2& position); + virtual void mousePressEvent(MouseButton button, Modifiers modifiers, const Math::Vector2& position); /** * @brief Mouse release event * @param button Button released + * @param modifiers Active modifiers (not yet implemented) * @param position Cursor position * * Called when mouse button is released. Default implementation does * nothing. */ - virtual void mouseReleaseEvent(MouseButton button, const Math::Vector2& position); - - /** - * @brief Mouse wheel event - * @param direction Wheel rotation direction. Negative Y is up and - * positive X is right. - * - * Called when mouse wheel is rotated. Default implementation does - * nothing. - */ - virtual void mouseWheelEvent(const Math::Vector2& direction); + virtual void mouseReleaseEvent(MouseButton button, Modifiers modifiers, const Math::Vector2& position); /** * @brief Mouse motion event + * @param modifiers Active modifiers (not yet implemented) * @param position Mouse position relative to the window - * @param delta Mouse position relative to last motion event * * Called when mouse is moved. Default implementation does nothing. */ - virtual void mouseMotionEvent(const Math::Vector2& position, const Math::Vector2& delta); + virtual void mouseMotionEvent(Modifiers modifiers, const Math::Vector2& position); /*@}*/ @@ -188,13 +201,14 @@ class Sdl2WindowContext: public AbstractWindowContext { bool _redraw; }; +CORRADE_ENUMSET_OPERATORS(Sdl2WindowContext::Modifiers) + /* Implementations for inline functions with unused parameters */ -inline void Sdl2WindowContext::keyPressEvent(Key, Uint8) {} -inline void Sdl2WindowContext::keyReleaseEvent(Key) {} -inline void Sdl2WindowContext::mousePressEvent(MouseButton, const Math::Vector2&) {} -inline void Sdl2WindowContext::mouseReleaseEvent(MouseButton, const Math::Vector2&) {} -inline void Sdl2WindowContext::mouseWheelEvent(const Math::Vector2&) {} -inline void Sdl2WindowContext::mouseMotionEvent(const Math::Vector2&, const Math::Vector2&) {} +inline void Sdl2WindowContext::keyPressEvent(Key, Modifiers, const Math::Vector2&) {} +inline void Sdl2WindowContext::keyReleaseEvent(Key, Modifiers, const Math::Vector2&) {} +inline void Sdl2WindowContext::mousePressEvent(MouseButton, Modifiers, const Math::Vector2&) {} +inline void Sdl2WindowContext::mouseReleaseEvent(MouseButton, Modifiers, const Math::Vector2&) {} +inline void Sdl2WindowContext::mouseMotionEvent(Modifiers, const Math::Vector2&) {} }}