From 85974d8123185ac2ba9b2698e748cc79b6f08593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Oct 2013 18:18:43 +0200 Subject: [PATCH] Platform: separate mouse buttons from keyboard modifiers. Doing it the same way as in Sdl2Application, as this doesn't have any performance impact (just alias for already present variable). The other way around, i.e. combining mouse buttons and keyboard modifiers in Sdl2Application, would have unnecessary performance penalty, as keyboard modifiers must be queried with separate function, even if they won't probably be used at all. Qt employs similar approach. The old way is preserved for backwards compatibility, but marked as deprecated and will be removed in future releases. --- src/Platform/AbstractXApplication.h | 48 +++++++++++++++++++++++++++-- src/Platform/NaClApplication.h | 48 +++++++++++++++++++++++++++-- 2 files changed, 90 insertions(+), 6 deletions(-) diff --git a/src/Platform/AbstractXApplication.h b/src/Platform/AbstractXApplication.h index 0921d2d6c..d1e61cf5d 100644 --- a/src/Platform/AbstractXApplication.h +++ b/src/Platform/AbstractXApplication.h @@ -257,9 +257,29 @@ class AbstractXApplication::InputEvent { Alt = Mod1Mask, /**< Alt */ AltGr = Mod5Mask, /**< AltGr */ - LeftButton = Button1Mask, /**< Left mouse button */ - MiddleButton = Button2Mask, /**< Middle mouse button */ - RightButton = Button3Mask, /**< Right mouse button */ + /** + * @copybrief Button::Left + * @deprecated Use @ref Magnum::Platform::AbstractXApplication::InputEvent::buttons() "buttons()" + * and @ref Magnum::Platform::AbstractXApplication::InputEvent::Button::Left "Button::Left" + * instead. + */ + LeftButton = Button1Mask, + + /** + * @copybrief Button::Middle + * @deprecated Use @ref Magnum::Platform::AbstractXApplication::InputEvent::buttons() "buttons()" + * and @ref Magnum::Platform::AbstractXApplication::InputEvent::Button::Middle "Button::Middle" + * instead. + */ + MiddleButton = Button2Mask, + + /** + * @copybrief Button::Right + * @deprecated Use @ref Magnum::Platform::AbstractXApplication::InputEvent::buttons() "buttons()" + * and @ref Magnum::Platform::AbstractXApplication::InputEvent::Button::Right "Button::Right" + * instead. + */ + RightButton = Button3Mask, CapsLock = LockMask, /**< Caps lock */ NumLock = Mod2Mask /**< Num lock */ @@ -272,6 +292,24 @@ class AbstractXApplication::InputEvent { */ typedef Containers::EnumSet Modifiers; + /** + * @brief Mouse button + * + * @see @ref Buttons, @ref buttons() + */ + enum class Button: unsigned int { + Left = Button1Mask, /**< Left button */ + Middle = Button2Mask, /**< Middle button */ + Right = Button3Mask /**< Right button */ + }; + + /** + * @brief Set of mouse buttons + * + * @see @ref buttons() + */ + typedef Containers::EnumSet Buttons; + /** @copydoc GlutApplication::InputEvent::setAccepted() */ void setAccepted(bool accepted = true) { _accepted = accepted; } @@ -281,6 +319,9 @@ class AbstractXApplication::InputEvent { /** @brief Modifiers */ constexpr Modifiers modifiers() const { return _modifiers; } + /** @brief Mouse buttons */ + constexpr Buttons buttons() const { return Button(static_cast(_modifiers)); } + #ifndef DOXYGEN_GENERATING_OUTPUT protected: constexpr InputEvent(Modifiers modifiers): _modifiers(modifiers), _accepted(false) {} @@ -294,6 +335,7 @@ class AbstractXApplication::InputEvent { }; CORRADE_ENUMSET_OPERATORS(AbstractXApplication::InputEvent::Modifiers) +CORRADE_ENUMSET_OPERATORS(AbstractXApplication::InputEvent::Buttons) /** @brief Key event diff --git a/src/Platform/NaClApplication.h b/src/Platform/NaClApplication.h index 632232c02..53d76ab07 100644 --- a/src/Platform/NaClApplication.h +++ b/src/Platform/NaClApplication.h @@ -372,9 +372,29 @@ class NaClApplication::InputEvent { Alt = PP_INPUTEVENT_MODIFIER_ALTKEY, /**< Alt */ Meta = PP_INPUTEVENT_MODIFIER_METAKEY, /**< Meta */ - LeftButton = PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN, /**< Left mouse button */ - MiddleButton = PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN, /**< Middle mouse button */ - RightButton = PP_INPUTEVENT_MODIFIER_RIGHTBUTTONDOWN, /**< Right mouse button */ + /** + * @copybrief Button::Left + * @deprecated Use @ref Magnum::Platform::NaClApplication::InputEvent::buttons() "buttons()" + * and @ref Magnum::Platform::NaClApplication::InputEvent::Button::Left "Button::Left" + * instead. + */ + LeftButton = PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN, + + /** + * @copybrief Button::Middle + * @deprecated Use @ref Magnum::Platform::NaClApplication::InputEvent::buttons() "buttons()" + * and @ref Magnum::Platform::NaClApplication::InputEvent::Button::Middle "Button::Middle" + * instead. + */ + MiddleButton = PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN, + + /** + * @copybrief Button::Right + * @deprecated Use @ref Magnum::Platform::NaClApplication::InputEvent::buttons() "buttons()" + * and @ref Magnum::Platform::NaClApplication::InputEvent::Button::Right "Button::Right" + * instead. + */ + RightButton = PP_INPUTEVENT_MODIFIER_RIGHTBUTTONDOWN, CapsLock = PP_INPUTEVENT_MODIFIER_CAPSLOCKKEY, /**< Caps lock */ NumLock = PP_INPUTEVENT_MODIFIER_NUMLOCKKEY /**< Num lock */ @@ -387,9 +407,30 @@ class NaClApplication::InputEvent { */ typedef Containers::EnumSet Modifiers; + /** + * @brief Mouse button + * + * @see @ref Buttons, @ref buttons() + */ + enum class Button: std::uint32_t { + Left = PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN, /**< Left button */ + Middle = PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN, /**< Middle button */ + Right = PP_INPUTEVENT_MODIFIER_RIGHTBUTTONDOWN /**< Right button */ + }; + + /** + * @brief Set of mouse buttons + * + * @see @ref buttons() + */ + typedef Containers::EnumSet Buttons; + /** @brief Modifiers */ constexpr Modifiers modifiers() const { return _modifiers; } + /** @brief Mouse buttons */ + constexpr Buttons buttons() const { return Buttons(_modifiers); } + /** * @brief Set event as accepted * @@ -613,6 +654,7 @@ typedef NaClApplication Application; #endif CORRADE_ENUMSET_OPERATORS(NaClApplication::InputEvent::Modifiers) +CORRADE_ENUMSET_OPERATORS(NaClApplication::InputEvent::Buttons) /* Implementations for inline functions with unused parameters */ inline void NaClApplication::keyPressEvent(KeyEvent&) {}