From 8f3abe9dadf8fa1c630684d0724620c893d996d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 19 Aug 2012 12:59:58 +0200 Subject: [PATCH] AbstractXContext: added modifiers to key and mouse events. --- src/Contexts/AbstractXContext.cpp | 8 +++--- src/Contexts/AbstractXContext.h | 43 +++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/Contexts/AbstractXContext.cpp b/src/Contexts/AbstractXContext.cpp index ab7b3bf1a..ffc4e10f5 100644 --- a/src/Contexts/AbstractXContext.cpp +++ b/src/Contexts/AbstractXContext.cpp @@ -111,16 +111,16 @@ int AbstractXContext::exec() { /* Key/mouse events */ case KeyPress: - keyPressEvent(static_cast(XLookupKeysym(&event.xkey, 0)), {event.xkey.x, event.xkey.y}); + keyPressEvent(static_cast(XLookupKeysym(&event.xkey, 0)), static_cast(event.xkey.state), {event.xkey.x, event.xkey.y}); break; case KeyRelease: - keyReleaseEvent(static_cast(XLookupKeysym(&event.xkey, 0)), {event.xkey.x, event.xkey.y}); + keyReleaseEvent(static_cast(XLookupKeysym(&event.xkey, 0)), static_cast(event.xkey.state), {event.xkey.x, event.xkey.y}); break; case ButtonPress: - mousePressEvent(static_cast(event.xbutton.button), {event.xbutton.x, event.xbutton.y}); + mousePressEvent(static_cast(event.xbutton.button), static_cast(event.xkey.state), {event.xbutton.x, event.xbutton.y}); break; case ButtonRelease: - mouseReleaseEvent(static_cast(event.xbutton.button), {event.xbutton.x, event.xbutton.y}); + mouseReleaseEvent(static_cast(event.xbutton.button), static_cast(event.xkey.state), {event.xbutton.x, event.xbutton.y}); break; } } diff --git a/src/Contexts/AbstractXContext.h b/src/Contexts/AbstractXContext.h index 4e7d13fb6..3f30bee54 100644 --- a/src/Contexts/AbstractXContext.h +++ b/src/Contexts/AbstractXContext.h @@ -27,6 +27,8 @@ #undef None #undef Always +#include + #include "AbstractContext.h" #include "AbstractGlInterface.h" @@ -82,6 +84,27 @@ class AbstractXContext: public AbstractContext { /** @{ @name Keyboard handling */ public: + /** + * @brief %Modifier + * + * @see Modifiers, keyPressEvent(), keyReleaseEvent() + */ + enum class Modifier: unsigned int { + Shift = ShiftMask, /**< Shift */ + CapsLock = LockMask, /**< Caps lock */ + Ctrl = ControlMask, /**< Ctrl */ + Alt = Mod1Mask, /**< Alt */ + NumLock = Mod2Mask, /**< Num lock */ + AltGr = Mod5Mask /**< AltGr */ + }; + + /** + * @brief Set of modifiers + * + * @see keyPressEvent(), keyReleaseEvent() + */ + typedef Corrade::Containers::EnumSet Modifiers; + /** * @brief Key * @@ -161,20 +184,22 @@ class AbstractXContext: public AbstractContext { /** * @brief Key press event * @param key Key pressed + * @param modifiers Active modifiers * @param position Cursor position * * Called when an key is pressed. Default implementation does nothing. */ - virtual void keyPressEvent(Key key, const Math::Vector2& position); + virtual void keyPressEvent(Key key, Modifiers modifiers, const Math::Vector2& position); /** * @brief Key press event * @param key Key released + * @param modifiers Active modifiers * @param position Cursor position * * Called when an key is released. Default implementation does nothing. */ - virtual void keyReleaseEvent(Key key, const Math::Vector2& position); + virtual void keyReleaseEvent(Key key, Modifiers modifiers, const Math::Vector2& position); /*@}*/ @@ -198,22 +223,24 @@ class AbstractXContext: public AbstractContext { /** * @brief Mouse press event * @param button Button pressed + * @param modifiers Active modifiers * @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 * @param position Cursor position * * Called when mouse button is released. Default implementation does * nothing. */ - virtual void mouseReleaseEvent(MouseButton button, const Math::Vector2& position); + virtual void mouseReleaseEvent(MouseButton button, Modifiers modifiers, const Math::Vector2& position); /*@}*/ @@ -230,10 +257,10 @@ class AbstractXContext: public AbstractContext { bool _redraw; }; -inline void AbstractXContext::keyPressEvent(Key, const Math::Vector2&) {} -inline void AbstractXContext::keyReleaseEvent(Key, const Math::Vector2&) {} -inline void AbstractXContext::mousePressEvent(MouseButton, const Math::Vector2&) {} -inline void AbstractXContext::mouseReleaseEvent(MouseButton, const Math::Vector2&) {} +inline void AbstractXContext::keyPressEvent(Key, Modifiers, const Math::Vector2&) {} +inline void AbstractXContext::keyReleaseEvent(Key, Modifiers, const Math::Vector2&) {} +inline void AbstractXContext::mousePressEvent(MouseButton, Modifiers, const Math::Vector2&) {} +inline void AbstractXContext::mouseReleaseEvent(MouseButton, Modifiers, const Math::Vector2&) {} }}