Browse Source

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.
pull/23/head
Vladimír Vondruš 13 years ago
parent
commit
85974d8123
  1. 48
      src/Platform/AbstractXApplication.h
  2. 48
      src/Platform/NaClApplication.h

48
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<Modifier, unsigned int> 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<Button, unsigned int> 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<unsigned int>(_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

48
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<Modifier, std::uint32_t> 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<Button, std::uint32_t> 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&) {}

Loading…
Cancel
Save