diff --git a/doc/changelog.dox b/doc/changelog.dox index 39c4375f0..a9d7bf6e2 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -1421,6 +1421,15 @@ See also: @ref Platform::GlfwApplication and the @ref Platform::BasicScreenedApplication / @ref Platform::BasicScreen wrappers as well. +- @cpp Platform::Sdl2Application::InputEvent::Modifier @ce, + @cpp Modifiers @ce and @cpp Platform::Sdl2Application::KeyEvent::Key @ce + enums are deprecated in favor of @ref Platform::Sdl2Application::Modifier, + @relativeref{Platform::Sdl2Application,Modifiers} and + @relativeref{Platform::Sdl2Application,Key} enums contained directly in + the application class. Besides the obvious advantage of them being shorter + to type, this allows them to be used outside of the event class scope. The + same change is done in @ref Platform::AbstractXApplication, + @ref Platform::EmscriptenApplication and @ref Platform::GlfwApplication. - @cpp Platform::AbstractXApplication::MouseEvent::Button::WheelUp @ce and `WheelDown` members are deprecated in favor of a dedicated @ref Platform::AbstractXApplication::scrollEvent(). Similar change was done diff --git a/src/Magnum/Platform/AbstractXApplication.cpp b/src/Magnum/Platform/AbstractXApplication.cpp index 21ff9b22e..cf4236251 100644 --- a/src/Magnum/Platform/AbstractXApplication.cpp +++ b/src/Magnum/Platform/AbstractXApplication.cpp @@ -197,7 +197,7 @@ bool AbstractXApplication::mainLoopIteration() { /* Key/mouse events */ case KeyPress: case KeyRelease: { - KeyEvent e(static_cast(XLookupKeysym(&event.xkey, 0)), event.xkey.state, {event.xkey.x, event.xkey.y}); + KeyEvent e{Key(XLookupKeysym(&event.xkey, 0)), event.xkey.state, {event.xkey.x, event.xkey.y}}; event.type == KeyPress ? keyPressEvent(e) : keyReleaseEvent(e); } break; case ButtonPress: diff --git a/src/Magnum/Platform/AbstractXApplication.h b/src/Magnum/Platform/AbstractXApplication.h index c714b0e8e..6dbe2fb4e 100644 --- a/src/Magnum/Platform/AbstractXApplication.h +++ b/src/Magnum/Platform/AbstractXApplication.h @@ -115,10 +115,20 @@ class AbstractXApplication { /* The damn thing cannot handle forward enum declarations */ #ifndef DOXYGEN_GENERATING_OUTPUT + enum class Modifier: unsigned int; + enum class Key: KeySym; enum class PointerEventSource: UnsignedByte; enum class Pointer: UnsignedByte; #endif + /** + * @brief Set of keyboard modifiers + * @m_since_latest + * + * @see @ref InputEvent::modifiers() + */ + typedef Containers::EnumSet Modifiers; + /** * @brief Set of pointer types * @m_since_latest @@ -454,6 +464,389 @@ class AbstractXApplication { Flags _flags; }; +/** +@brief Keyboard modifier +@m_since_latest + +@see @ref Modifiers, @ref InputEvent::modifiers() +*/ +enum class AbstractXApplication::Modifier: unsigned int { + /** + * Shift + * + * @see @ref KeyEvent::Key::LeftShift, @ref KeyEvent::Key::RightShift + */ + Shift = ShiftMask, + + /** + * Ctrl + * + * @see @ref KeyEvent::Key::LeftCtrl, @ref KeyEvent::Key::RightCtrl + */ + Ctrl = ControlMask, + + /** + * Alt + * + * @see @ref KeyEvent::Key::LeftAlt, @ref KeyEvent::Key::RightAlt + */ + Alt = Mod1Mask, + + AltGr = Mod5Mask, /**< AltGr */ + + /** + * Caps lock + * + * @see @ref KeyEvent::Key::CapsLock + */ + CapsLock = LockMask, + + /** + * Num lock + * + * @see @ref KeyEvent::Key::NumLock + */ + NumLock = Mod2Mask +}; + +CORRADE_ENUMSET_OPERATORS(AbstractXApplication::Modifiers) + +/** +@brief Key +@m_since_latest + +@see @ref KeyEvent::key() +*/ +enum class AbstractXApplication::Key: KeySym { + /** + * Left Shift + * @m_since_latest + * + * @see @ref InputEvent::Modifier::Shift + */ + LeftShift = XK_Shift_L, + + /** + * Right Shift + * @m_since_latest + * + * @see @ref InputEvent::Modifier::Shift + */ + RightShift = XK_Shift_R, + + /** + * Left Ctrl + * @m_since_latest + * + * @see @ref InputEvent::Modifier::Ctrl + */ + LeftCtrl = XK_Control_L, + + /** + * Right Ctrl + * @m_since_latest + * + * @see @ref InputEvent::Modifier::Ctrl + */ + RightCtrl = XK_Control_R, + + /** + * Left Alt + * @m_since_latest + * + * @see @ref InputEvent::Modifier::Alt + */ + LeftAlt = XK_Alt_L, + + /** + * Right Alt + * @m_since_latest + * + * @see @ref InputEvent::Modifier::Alt + */ + RightAlt = XK_Alt_R, + + /** + * Left Super key (Windows/⌘) + * @m_since_latest + */ + LeftSuper = XK_Super_L, + + /** + * Right Super key (Windows/⌘) + * @m_since_latest + */ + RightSuper = XK_Super_R, + + /* AltGr missing */ + + Enter = XK_Return, /**< Enter */ + Esc = XK_Escape, /**< Escape */ + + Up = XK_Up, /**< Up arrow */ + Down = XK_Down, /**< Down arrow */ + Left = XK_Left, /**< Left arrow */ + Right = XK_Right, /**< Right arrow */ + Home = XK_Home, /**< Home */ + End = XK_End, /**< End */ + PageUp = XK_Page_Up, /**< Page up */ + PageDown = XK_Page_Down, /**< Page down */ + + /** + * Backspace + * @m_since_latest + */ + Backspace = XK_BackSpace, + + /** + * Insert + * @m_since_latest + */ + Insert = XK_Insert, + + /** + * Delete + * @m_since_latest + */ + Delete = XK_Delete, + + F1 = XK_F1, /**< F1 */ + F2 = XK_F2, /**< F2 */ + F3 = XK_F3, /**< F3 */ + F4 = XK_F4, /**< F4 */ + F5 = XK_F5, /**< F5 */ + F6 = XK_F6, /**< F6 */ + F7 = XK_F7, /**< F7 */ + F8 = XK_F8, /**< F8 */ + F9 = XK_F9, /**< F9 */ + F10 = XK_F10, /**< F10 */ + F11 = XK_F11, /**< F11 */ + F12 = XK_F12, /**< F12 */ + + Space = XK_space, /**< Space */ + + /** + * Tab + * @m_since_latest + */ + Tab = XK_Tab, + + /** + * Quote (') + * @m_since_latest + */ + Quote = XK_apostrophe, + + Comma = XK_comma, /**< Comma */ + Period = XK_period, /**< Period */ + Minus = XK_minus, /**< Minus */ + Plus = XK_plus, /**< Plus */ + Slash = XK_slash, /**< Slash */ + Percent = XK_percent, /**< Percent */ + + /** + * Semicolon (`;`) + * @m_since_latest + */ + Semicolon = XK_semicolon, + + Equal = XK_equal, /**< Equal */ + + /** + * Left bracket (`[`) + * @m_since_latest + */ + LeftBracket = XK_bracketleft, + + /** + * Right bracket (`]`) + * @m_since_latest + */ + RightBracket = XK_bracketright, + + /** + * Backslash (`\`) + * @m_since_latest + */ + Backslash = XK_backslash, + + /** + * Backquote (`) + * @m_since_latest + */ + Backquote = XK_grave, + + Zero = XK_0, /**< Zero */ + One = XK_1, /**< One */ + Two = XK_2, /**< Two */ + Three = XK_3, /**< Three */ + Four = XK_4, /**< Four */ + Five = XK_5, /**< Five */ + Six = XK_6, /**< Six */ + Seven = XK_7, /**< Seven */ + Eight = XK_8, /**< Eight */ + Nine = XK_9, /**< Nine */ + + A = XK_a, /**< Small letter A */ + B = XK_b, /**< Small letter B */ + C = XK_c, /**< Small letter C */ + D = XK_d, /**< Small letter D */ + E = XK_e, /**< Small letter E */ + F = XK_f, /**< Small letter F */ + G = XK_g, /**< Small letter G */ + H = XK_h, /**< Small letter H */ + I = XK_i, /**< Small letter I */ + J = XK_j, /**< Small letter J */ + K = XK_k, /**< Small letter K */ + L = XK_l, /**< Small letter L */ + M = XK_m, /**< Small letter M */ + N = XK_n, /**< Small letter N */ + O = XK_o, /**< Small letter O */ + P = XK_p, /**< Small letter P */ + Q = XK_q, /**< Small letter Q */ + R = XK_r, /**< Small letter R */ + S = XK_s, /**< Small letter S */ + T = XK_t, /**< Small letter T */ + U = XK_u, /**< Small letter U */ + V = XK_v, /**< Small letter V */ + W = XK_w, /**< Small letter W */ + X = XK_x, /**< Small letter X */ + Y = XK_y, /**< Small letter Y */ + Z = XK_z, /**< Small letter Z */ + + /** + * Caps lock + * + * @see @ref InputEvent::Modifier::CapsLock + * @m_since_latest + */ + CapsLock = XK_Caps_Lock, + + /** + * Scroll lock + * @m_since_latest + */ + ScrollLock = XK_Scroll_Lock, + + /** + * Num lock + * + * @see @ref InputEvent::Modifier::NumLock + * @m_since_latest + */ + NumLock = XK_Num_Lock, + + /** + * Print screen + * @m_since_latest + */ + PrintScreen = XK_Print, + + /* Pause, Menu missing */ + + /** + * Numpad zero + * @m_since_latest + */ + NumZero = XK_KP_0, + + /** + * Numpad one + * @m_since_latest + */ + NumOne = XK_KP_1, + + /** + * Numpad two + * @m_since_latest + */ + NumTwo = XK_KP_2, + + /** + * Numpad three + * @m_since_latest + */ + NumThree = XK_KP_3, + + /** + * Numpad four + * @m_since_latest + */ + NumFour = XK_KP_4, + + /** + * Numpad five + * @m_since_latest + */ + NumFive = XK_KP_5, + + /** + * Numpad six + * @m_since_latest + */ + NumSix = XK_KP_6, + + /** + * Numpad seven + * @m_since_latest + */ + NumSeven = XK_KP_7, + + /** + * Numpad eight + * @m_since_latest + */ + NumEight = XK_KP_8, + + /** + * Numpad nine + * @m_since_latest + */ + NumNine = XK_KP_9, + + /** + * Numpad decimal + * @m_since_latest + */ + NumDecimal = XK_KP_Decimal, + + /** + * Numpad divide + * @m_since_latest + */ + NumDivide = XK_KP_Divide, + + /** + * Numpad multiply + * @m_since_latest + */ + NumMultiply = XK_KP_Multiply, + + /** + * Numpad subtract + * @m_since_latest + */ + NumSubtract = XK_KP_Subtract, + + /** + * Numpad add + * @m_since_latest + */ + NumAdd = XK_KP_Add, + + /** + * Numpad enter + * @m_since_latest + */ + NumEnter = XK_KP_Enter, + + /** + * Numpad equal + * @m_since_latest + */ + NumEqual = XK_KP_Equal +}; + /** @brief Pointer event source @m_since_latest @@ -717,59 +1110,21 @@ class AbstractXApplication::ViewportEvent { */ class AbstractXApplication::InputEvent { public: + #ifdef MAGNUM_BUILD_DEPRECATED /** - * @brief Modifier - * - * @see @ref Modifiers, @ref modifiers() + * @brief @copybrief AbstractXApplication::Modifier + * @m_deprecated_since_latest Use @ref AbstractXApplication::Modifier + * instead. */ - enum class Modifier: unsigned int { - /** - * Shift - * - * @see @ref KeyEvent::Key::LeftShift, - * @ref KeyEvent::Key::RightShift - */ - Shift = ShiftMask, - - /** - * Ctrl - * - * @see @ref KeyEvent::Key::LeftCtrl, @ref KeyEvent::Key::RightCtrl - */ - Ctrl = ControlMask, - - /** - * Alt - * - * @see @ref KeyEvent::Key::LeftAlt, @ref KeyEvent::Key::RightAlt - */ - Alt = Mod1Mask, - - AltGr = Mod5Mask, /**< AltGr */ - - /** - * Caps lock - * - * @see @ref KeyEvent::Key::CapsLock - */ - CapsLock = LockMask, - - /** - * Num lock - * - * @see @ref KeyEvent::Key::NumLock - */ - NumLock = Mod2Mask - }; + typedef CORRADE_DEPRECATED("use AbstractXApplication::Modifier instead") AbstractXApplication::Modifier Modifier; /** - * @brief Set of modifiers - * - * @see @ref modifiers() + * @brief @copybrief AbstractXApplication::Modifiers + * @m_deprecated_since_latest Use @ref AbstractXApplication::Modifiers + * instead. */ - typedef Containers::EnumSet Modifiers; + typedef CORRADE_DEPRECATED("use AbstractXApplication::Modifiers instead") AbstractXApplication::Modifiers Modifiers; - #ifdef MAGNUM_BUILD_DEPRECATED /** * @brief Mouse button * @m_deprecated_since_latest Use @ref Pointer instead. @@ -808,8 +1163,8 @@ class AbstractXApplication::InputEvent { bool isAccepted() const { return _accepted; } /** @brief Modifiers */ - Modifiers modifiers() const { - return Modifiers(_modifiers & (ShiftMask|ControlMask|Mod1Mask|Mod5Mask|LockMask|Mod2Mask)); + AbstractXApplication::Modifiers modifiers() const { + return AbstractXApplication::Modifiers(_modifiers & (ShiftMask|ControlMask|Mod1Mask|Mod5Mask|LockMask|Mod2Mask)); } #ifdef MAGNUM_BUILD_DEPRECATED @@ -837,8 +1192,6 @@ class AbstractXApplication::InputEvent { bool _accepted; }; -CORRADE_ENUMSET_OPERATORS(AbstractXApplication::InputEvent::Modifiers) - #ifdef MAGNUM_BUILD_DEPRECATED CORRADE_IGNORE_DEPRECATED_PUSH CORRADE_ENUMSET_OPERATORS(AbstractXApplication::InputEvent::Buttons) @@ -852,343 +1205,17 @@ CORRADE_IGNORE_DEPRECATED_POP */ class AbstractXApplication::KeyEvent: public AbstractXApplication::InputEvent { public: + #ifdef MAGNUM_BUILD_DEPRECATED /** - * @brief Key - * - * @see @ref key() + * @brief @copybrief AbstractXApplication::Key + * @m_deprecated_since_latest Use @ref AbstractXApplication::Key + * instead. */ - enum class Key: KeySym { - /** - * Left Shift - * @m_since_latest - * - * @see @ref InputEvent::Modifier::Shift - */ - LeftShift = XK_Shift_L, - - /** - * Right Shift - * @m_since_latest - * - * @see @ref InputEvent::Modifier::Shift - */ - RightShift = XK_Shift_R, - - /** - * Left Ctrl - * @m_since_latest - * - * @see @ref InputEvent::Modifier::Ctrl - */ - LeftCtrl = XK_Control_L, - - /** - * Right Ctrl - * @m_since_latest - * - * @see @ref InputEvent::Modifier::Ctrl - */ - RightCtrl = XK_Control_R, - - /** - * Left Alt - * @m_since_latest - * - * @see @ref InputEvent::Modifier::Alt - */ - LeftAlt = XK_Alt_L, - - /** - * Right Alt - * @m_since_latest - * - * @see @ref InputEvent::Modifier::Alt - */ - RightAlt = XK_Alt_R, - - /** - * Left Super key (Windows/⌘) - * @m_since_latest - */ - LeftSuper = XK_Super_L, - - /** - * Right Super key (Windows/⌘) - * @m_since_latest - */ - RightSuper = XK_Super_R, - - /* AltGr missing */ - - Enter = XK_Return, /**< Enter */ - Esc = XK_Escape, /**< Escape */ - - Up = XK_Up, /**< Up arrow */ - Down = XK_Down, /**< Down arrow */ - Left = XK_Left, /**< Left arrow */ - Right = XK_Right, /**< Right arrow */ - Home = XK_Home, /**< Home */ - End = XK_End, /**< End */ - PageUp = XK_Page_Up, /**< Page up */ - PageDown = XK_Page_Down, /**< Page down */ - - /** - * Backspace - * @m_since_latest - */ - Backspace = XK_BackSpace, - - /** - * Insert - * @m_since_latest - */ - Insert = XK_Insert, - - /** - * Delete - * @m_since_latest - */ - Delete = XK_Delete, - - F1 = XK_F1, /**< F1 */ - F2 = XK_F2, /**< F2 */ - F3 = XK_F3, /**< F3 */ - F4 = XK_F4, /**< F4 */ - F5 = XK_F5, /**< F5 */ - F6 = XK_F6, /**< F6 */ - F7 = XK_F7, /**< F7 */ - F8 = XK_F8, /**< F8 */ - F9 = XK_F9, /**< F9 */ - F10 = XK_F10, /**< F10 */ - F11 = XK_F11, /**< F11 */ - F12 = XK_F12, /**< F12 */ - - Space = XK_space, /**< Space */ - - /** - * Tab - * @m_since_latest - */ - Tab = XK_Tab, - - /** - * Quote (') - * @m_since_latest - */ - Quote = XK_apostrophe, - - Comma = XK_comma, /**< Comma */ - Period = XK_period, /**< Period */ - Minus = XK_minus, /**< Minus */ - Plus = XK_plus, /**< Plus */ - Slash = XK_slash, /**< Slash */ - Percent = XK_percent, /**< Percent */ - - /** - * Semicolon (`;`) - * @m_since_latest - */ - Semicolon = XK_semicolon, - - Equal = XK_equal, /**< Equal */ - - /** - * Left bracket (`[`) - * @m_since_latest - */ - LeftBracket = XK_bracketleft, - - /** - * Right bracket (`]`) - * @m_since_latest - */ - RightBracket = XK_bracketright, - - /** - * Backslash (`\`) - * @m_since_latest - */ - Backslash = XK_backslash, - - /** - * Backquote (`) - * @m_since_latest - */ - Backquote = XK_grave, - - Zero = XK_0, /**< Zero */ - One = XK_1, /**< One */ - Two = XK_2, /**< Two */ - Three = XK_3, /**< Three */ - Four = XK_4, /**< Four */ - Five = XK_5, /**< Five */ - Six = XK_6, /**< Six */ - Seven = XK_7, /**< Seven */ - Eight = XK_8, /**< Eight */ - Nine = XK_9, /**< Nine */ - - A = XK_a, /**< Small letter A */ - B = XK_b, /**< Small letter B */ - C = XK_c, /**< Small letter C */ - D = XK_d, /**< Small letter D */ - E = XK_e, /**< Small letter E */ - F = XK_f, /**< Small letter F */ - G = XK_g, /**< Small letter G */ - H = XK_h, /**< Small letter H */ - I = XK_i, /**< Small letter I */ - J = XK_j, /**< Small letter J */ - K = XK_k, /**< Small letter K */ - L = XK_l, /**< Small letter L */ - M = XK_m, /**< Small letter M */ - N = XK_n, /**< Small letter N */ - O = XK_o, /**< Small letter O */ - P = XK_p, /**< Small letter P */ - Q = XK_q, /**< Small letter Q */ - R = XK_r, /**< Small letter R */ - S = XK_s, /**< Small letter S */ - T = XK_t, /**< Small letter T */ - U = XK_u, /**< Small letter U */ - V = XK_v, /**< Small letter V */ - W = XK_w, /**< Small letter W */ - X = XK_x, /**< Small letter X */ - Y = XK_y, /**< Small letter Y */ - Z = XK_z, /**< Small letter Z */ - - /** - * Caps lock - * - * @see @ref InputEvent::Modifier::CapsLock - * @m_since_latest - */ - CapsLock = XK_Caps_Lock, - - /** - * Scroll lock - * @m_since_latest - */ - ScrollLock = XK_Scroll_Lock, - - /** - * Num lock - * - * @see @ref InputEvent::Modifier::NumLock - * @m_since_latest - */ - NumLock = XK_Num_Lock, - - /** - * Print screen - * @m_since_latest - */ - PrintScreen = XK_Print, - - /* Pause, Menu missing */ - - /** - * Numpad zero - * @m_since_latest - */ - NumZero = XK_KP_0, - - /** - * Numpad one - * @m_since_latest - */ - NumOne = XK_KP_1, - - /** - * Numpad two - * @m_since_latest - */ - NumTwo = XK_KP_2, - - /** - * Numpad three - * @m_since_latest - */ - NumThree = XK_KP_3, - - /** - * Numpad four - * @m_since_latest - */ - NumFour = XK_KP_4, - - /** - * Numpad five - * @m_since_latest - */ - NumFive = XK_KP_5, - - /** - * Numpad six - * @m_since_latest - */ - NumSix = XK_KP_6, - - /** - * Numpad seven - * @m_since_latest - */ - NumSeven = XK_KP_7, - - /** - * Numpad eight - * @m_since_latest - */ - NumEight = XK_KP_8, - - /** - * Numpad nine - * @m_since_latest - */ - NumNine = XK_KP_9, - - /** - * Numpad decimal - * @m_since_latest - */ - NumDecimal = XK_KP_Decimal, - - /** - * Numpad divide - * @m_since_latest - */ - NumDivide = XK_KP_Divide, - - /** - * Numpad multiply - * @m_since_latest - */ - NumMultiply = XK_KP_Multiply, - - /** - * Numpad subtract - * @m_since_latest - */ - NumSubtract = XK_KP_Subtract, - - /** - * Numpad add - * @m_since_latest - */ - NumAdd = XK_KP_Add, - - /** - * Numpad enter - * @m_since_latest - */ - NumEnter = XK_KP_Enter, - - /** - * Numpad equal - * @m_since_latest - */ - NumEqual = XK_KP_Equal - }; + typedef CORRADE_DEPRECATED("use AbstractXApplication::Key instead") AbstractXApplication::Key Key; + #endif /** @brief Key */ - Key key() const { return _key; } + AbstractXApplication::Key key() const { return _key; } /** @brief Position */ Vector2i position() const { return _position; } @@ -1205,9 +1232,9 @@ class AbstractXApplication::KeyEvent: public AbstractXApplication::InputEvent { private: friend AbstractXApplication; - explicit KeyEvent(Key key, unsigned int modifiers, const Vector2i& position): InputEvent(modifiers), _key(key), _position(position) {} + explicit KeyEvent(AbstractXApplication::Key key, unsigned int modifiers, const Vector2i& position): InputEvent(modifiers), _key(key), _position(position) {} - const Key _key; + const AbstractXApplication::Key _key; const Vector2i _position; }; diff --git a/src/Magnum/Platform/EmscriptenApplication.cpp b/src/Magnum/Platform/EmscriptenApplication.cpp index c92b167d1..b536ab61c 100644 --- a/src/Magnum/Platform/EmscriptenApplication.cpp +++ b/src/Magnum/Platform/EmscriptenApplication.cpp @@ -69,7 +69,7 @@ enum class EmscriptenApplication::Flag: UnsignedByte { }; namespace { - typedef EmscriptenApplication::KeyEvent::Key Key; + typedef EmscriptenApplication::Key Key; /* Entry for key name to `Key` enum mapping */ struct Entry { @@ -552,16 +552,16 @@ EmscriptenApplication::Pointers buttonsToPointers(const std::uint32_t buttons) { return pointers; } -template EmscriptenApplication::InputEvent::Modifiers eventModifiers(const T& event) { - EmscriptenApplication::InputEvent::Modifiers modifiers; +template EmscriptenApplication::Modifiers eventModifiers(const T& event) { + EmscriptenApplication::Modifiers modifiers; if(event.ctrlKey) - modifiers |= EmscriptenApplication::InputEvent::Modifier::Ctrl; + modifiers |= EmscriptenApplication::Modifier::Ctrl; if(event.shiftKey) - modifiers |= EmscriptenApplication::InputEvent::Modifier::Shift; + modifiers |= EmscriptenApplication::Modifier::Shift; if(event.altKey) - modifiers |= EmscriptenApplication::InputEvent::Modifier::Alt; + modifiers |= EmscriptenApplication::Modifier::Alt; if(event.metaKey) - modifiers |= EmscriptenApplication::InputEvent::Modifier::Super; + modifiers |= EmscriptenApplication::Modifier::Super; return modifiers; } @@ -650,7 +650,7 @@ void EmscriptenApplication::setupCallbacks(bool resizable) { const Pointer pointer = buttonToPointer(event->button); const Pointers pointers = buttonsToPointers(event->buttons); - const InputEvent::Modifiers modifiers = eventModifiers(*event); + const Modifiers modifiers = eventModifiers(*event); const Vector2 position = eventTargetPosition(*event); /* If an additional mouse button was pressed, call a move event @@ -690,7 +690,7 @@ void EmscriptenApplication::setupCallbacks(bool resizable) { const Pointer pointer = buttonToPointer(event->button); const Pointers pointers = buttonsToPointers(event->buttons); - const InputEvent::Modifiers modifiers = eventModifiers(*event); + const Modifiers modifiers = eventModifiers(*event); const Vector2 position = eventTargetPosition(*event); /* If some buttons are still left pressed after a release, call a @@ -711,7 +711,7 @@ void EmscriptenApplication::setupCallbacks(bool resizable) { ([](int, const EmscriptenMouseEvent* event, void* userData) -> EM_BOOL { auto& app = *static_cast(userData); const Pointers pointers = buttonsToPointers(event->buttons); - const InputEvent::Modifiers modifiers = eventModifiers(*event); + const Modifiers modifiers = eventModifiers(*event); const Vector2 position = eventTargetPosition(*event); /* Avoid bogus offset at first -- report 0 when the event is called for the first time. */ @@ -745,7 +745,7 @@ void EmscriptenApplication::setupCallbacks(bool resizable) { events, is that a browser bug? Emscripten seems to fill them in https://github.com/emscripten-core/emscripten/blob/10cb9d46cdd17e7a96de68137c9649d9a630fbc7/src/library_html5.js#L1930-L1933 correctly. */ - const InputEvent::Modifiers modifiers = eventModifiers(*event); + const Modifiers modifiers = eventModifiers(*event); bool accepted = false; for(Int i = 0; i != event->numTouches; ++i) { @@ -789,7 +789,7 @@ void EmscriptenApplication::setupCallbacks(bool resizable) { auto& app = *static_cast(userData); /** @todo somehow desktop Chrome doesn't populate these for touch events, see above */ - const InputEvent::Modifiers modifiers = eventModifiers(*event); + const Modifiers modifiers = eventModifiers(*event); /* Remember the touch event timestamp. Chromium (at least) then fires the compatibility mouse press and release event with the @@ -841,7 +841,7 @@ void EmscriptenApplication::setupCallbacks(bool resizable) { auto& app = *static_cast(userData); /** @todo somehow desktop Chrome doesn't populate these for touch events, see above */ - const InputEvent::Modifiers modifiers = eventModifiers(*event); + const Modifiers modifiers = eventModifiers(*event); bool accepted = false; for(Int i = 0; i != event->numTouches; ++i) { @@ -1206,7 +1206,7 @@ Vector2i EmscriptenApplication::MouseEvent::position() const { return {Int(_event.targetX), Int(_event.targetY)}; } -EmscriptenApplication::MouseEvent::Modifiers EmscriptenApplication::MouseEvent::modifiers() const { +EmscriptenApplication::Modifiers EmscriptenApplication::MouseEvent::modifiers() const { return eventModifiers(_event); } CORRADE_IGNORE_DEPRECATED_POP @@ -1224,7 +1224,7 @@ Vector2i EmscriptenApplication::MouseMoveEvent::position() const { return {Int(_event.targetX), Int(_event.targetY)}; } -EmscriptenApplication::MouseMoveEvent::Modifiers EmscriptenApplication::MouseMoveEvent::modifiers() const { +EmscriptenApplication::Modifiers EmscriptenApplication::MouseMoveEvent::modifiers() const { return eventModifiers(_event); } #endif @@ -1248,7 +1248,7 @@ Vector2 EmscriptenApplication::ScrollEvent::position() const { return {Float(_event.mouse.targetX), Float(_event.mouse.targetY)}; } -EmscriptenApplication::InputEvent::Modifiers EmscriptenApplication::ScrollEvent::modifiers() const { +EmscriptenApplication::Modifiers EmscriptenApplication::ScrollEvent::modifiers() const { return eventModifiers(_event.mouse); } @@ -1267,12 +1267,12 @@ Vector2i EmscriptenApplication::MouseScrollEvent::position() const { return {Int(_event.mouse.targetX), Int(_event.mouse.targetY)}; } -EmscriptenApplication::InputEvent::Modifiers EmscriptenApplication::MouseScrollEvent::modifiers() const { +EmscriptenApplication::Modifiers EmscriptenApplication::MouseScrollEvent::modifiers() const { return eventModifiers(_event.mouse); } #endif -Key EmscriptenApplication::KeyEvent::key() const { +EmscriptenApplication::Key EmscriptenApplication::KeyEvent::key() const { return toKey(_event.key, _event.code); } @@ -1283,7 +1283,7 @@ Containers::StringView EmscriptenApplication::KeyEvent::keyName() const { return _event.code; } -EmscriptenApplication::InputEvent::Modifiers EmscriptenApplication::KeyEvent::modifiers() const { +EmscriptenApplication::Modifiers EmscriptenApplication::KeyEvent::modifiers() const { return eventModifiers(_event); } diff --git a/src/Magnum/Platform/EmscriptenApplication.h b/src/Magnum/Platform/EmscriptenApplication.h index 626a0cf23..fa62fe3d4 100644 --- a/src/Magnum/Platform/EmscriptenApplication.h +++ b/src/Magnum/Platform/EmscriptenApplication.h @@ -343,10 +343,22 @@ class EmscriptenApplication { /* The damn thing cannot handle forward enum declarations */ #ifndef DOXYGEN_GENERATING_OUTPUT + enum class Modifier: Int; + enum class Key: Int; enum class PointerEventSource: UnsignedByte; enum class Pointer: UnsignedByte; #endif + /** + * @brief Set of keyboard modifiers + * @m_since_latest + * + * @see @ref KeyEvent::modifiers(), @ref PointerEvent::modifiers(), + * @ref PointerMoveEvent::modifiers(), + * @ref ScrollEvent::modifiers() + */ + typedef Containers::EnumSet Modifiers; + /** * @brief Set of pointer types * @m_since_latest @@ -1099,6 +1111,242 @@ class EmscriptenApplication { int (*_callback)(void*); }; +/** +@brief Keyboard modifier +@m_since_latest + +@see @ref Modifiers, @ref KeyEvent::modifiers(), + @ref PointerEvent::modifiers(), @ref PointerMoveEvent::modifiers(), + @ref ScrollEvent::modifiers() +*/ +enum class EmscriptenApplication::Modifier: Int { + /** + * Shift + * + * @see @ref KeyEvent::Key::LeftShift, @ref KeyEvent::Key::RightShift + */ + Shift = 1 << 0, + + /** + * Ctrl + * + * @see @ref KeyEvent::Key::LeftCtrl, @ref KeyEvent::Key::RightCtrl + */ + Ctrl = 1 << 1, + + /** + * Alt + * + * @see @ref KeyEvent::Key::LeftAlt, @ref KeyEvent::Key::RightAlt + */ + Alt = 1 << 2, + + /** + * Super key (Windows/⌘) + * + * @see @ref KeyEvent::Key::LeftSuper, @ref KeyEvent::Key::RightSuper + */ + Super = 1 << 3 +}; + +CORRADE_ENUMSET_OPERATORS(EmscriptenApplication::Modifiers) + +/** +@brief Key +@m_since_latest + +@see @ref KeyEvent::key() +*/ +enum class EmscriptenApplication::Key: Int { + Unknown, /**< Unknown key */ + + /** + * Left Shift + * + * @see @ref InputEvent::Modifier::Shift + */ + LeftShift, + + /** + * Right Shift + * + * @see @ref InputEvent::Modifier::Shift + */ + RightShift, + + /** + * Left Ctrl + * + * @see @ref InputEvent::Modifier::Ctrl + */ + LeftCtrl, + + /** + * Right Ctrl + * + * @see @ref InputEvent::Modifier::Ctrl + */ + RightCtrl, + + /** + * Left Alt + * + * @see @ref InputEvent::Modifier::Alt + */ + LeftAlt, + + /** + * Right Alt + * + * @see @ref InputEvent::Modifier::Alt + */ + RightAlt, + + /** + * Left Super key (Windows/⌘) + * + * @see @ref InputEvent::Modifier::Super + */ + LeftSuper, + + /** + * Right Super key (Windows/⌘) + * + * @see @ref InputEvent::Modifier::Super + */ + RightSuper, + + /* no equivalent for Sdl2Application's AltGr */ + + Enter, /**< Enter */ + Esc, /**< Escape */ + + Up, /**< Up arrow */ + Down, /**< Down arrow */ + Left, /**< Left arrow */ + Right, /**< Right arrow */ + Home, /**< Home */ + End, /**< End */ + PageUp, /**< Page up */ + PageDown, /**< Page down */ + Backspace, /**< Backspace */ + Insert, /**< Insert */ + Delete, /**< Delete */ + + F1, /**< F1 */ + F2, /**< F2 */ + F3, /**< F3 */ + F4, /**< F4 */ + F5, /**< F5 */ + F6, /**< F6 */ + F7, /**< F7 */ + F8, /**< F8 */ + F9, /**< F9 */ + F10, /**< F10 */ + F11, /**< F11 */ + F12, /**< F12 */ + + Zero = '0', /**< Zero */ + One, /**< One */ + Two, /**< Two */ + Three, /**< Three */ + Four, /**< Four */ + Five, /**< Five */ + Six, /**< Six */ + Seven, /**< Seven */ + Eight, /**< Eight */ + Nine, /**< Nine */ + + A = 'a', /**< Letter A */ + B, /**< Letter B */ + C, /**< Letter C */ + D, /**< Letter D */ + E, /**< Letter E */ + F, /**< Letter F */ + G, /**< Letter G */ + H, /**< Letter H */ + I, /**< Letter I */ + J, /**< Letter J */ + K, /**< Letter K */ + L, /**< Letter L */ + M, /**< Letter M */ + N, /**< Letter N */ + O, /**< Letter O */ + P, /**< Letter P */ + Q, /**< Letter Q */ + R, /**< Letter R */ + S, /**< Letter S */ + T, /**< Letter T */ + U, /**< Letter U */ + V, /**< Letter V */ + W, /**< Letter W */ + X, /**< Letter X */ + Y, /**< Letter Y */ + Z, /**< Letter Z */ + + Space, /**< Space */ + Tab, /**< Tab */ + Quote, /**< Quote (') */ + Comma, /**< Comma */ + Period, /**< Period */ + Minus, /**< Minus */ + + /** + * Plus. On the US keyboard layout this may only be representable as + * @m_class{m-label m-warning} **Shift** @m_class{m-label m-default} **=**. + */ + Plus, + + Slash, /**< Slash */ + + /** + * Percent. On the US keyboard layout this may only be representable as + * @m_class{m-label m-warning} **Shift** @m_class{m-label m-default} **5**. + */ + Percent, + + /** + * Semicolon (`;`) + * @m_since{2020,06} + */ + Semicolon, + + Equal, /**< Equal */ + LeftBracket, /**< Left bracket (`[`) */ + RightBracket, /**< Right bracket (`]`) */ + Backslash, /**< Backslash (`\`) */ + Backquote, /**< Backquote (`) */ + + /* no equivalent for GlfwApplication's World1 / World2 */ + /** @todo there's IntlBackslash for World1, implement once there's + consensus about naming */ + + CapsLock, /**< Caps lock */ + ScrollLock, /**< Scroll lock */ + NumLock, /**< Num lock */ + PrintScreen, /**< Print screen */ + Pause, /**< Pause */ + Menu, /**< Menu */ + + NumZero, /**< Numpad zero */ + NumOne, /**< Numpad one */ + NumTwo, /**< Numpad two */ + NumThree, /**< Numpad three */ + NumFour, /**< Numpad four */ + NumFive, /**< Numpad five */ + NumSix, /**< Numpad six */ + NumSeven, /**< Numpad seven */ + NumEight, /**< Numpad eight */ + NumNine, /**< Numpad nine */ + NumDecimal, /**< Numpad decimal */ + NumDivide, /**< Numpad divide */ + NumMultiply, /**< Numpad multiply */ + NumSubtract, /**< Numpad subtract */ + NumAdd, /**< Numpad add */ + NumEnter, /**< Numpad enter */ + NumEqual /**< Numpad equal */ +}; + /** @brief Pointer event source @m_since_latest @@ -1712,52 +1960,21 @@ class EmscriptenApplication::ViewportEvent { */ class EmscriptenApplication::InputEvent { public: + #ifdef MAGNUM_BUILD_DEPRECATED /** - * @brief Modifier - * - * @see @ref Modifiers, @ref KeyEvent::modifiers(), - * @ref PointerEvent::modifiers(), - * @ref PointerMoveEvent::modifiers(), - * @ref ScrollEvent::modifiers() + * @brief @copybrief EmscriptenApplication::Modifier + * @m_deprecated_since_latest Use @ref EmscriptenApplication::Modifier + * instead. */ - enum class Modifier: Int { - /** - * Shift - * - * @see @ref KeyEvent::Key::LeftShift, @ref KeyEvent::Key::RightShift - */ - Shift = 1 << 0, - - /** - * Ctrl - * - * @see @ref KeyEvent::Key::LeftCtrl, @ref KeyEvent::Key::RightCtrl - */ - Ctrl = 1 << 1, - - /** - * Alt - * - * @see @ref KeyEvent::Key::LeftAlt, @ref KeyEvent::Key::RightAlt - */ - Alt = 1 << 2, - - /** - * Super key (Windows/⌘) - * - * @see @ref KeyEvent::Key::LeftSuper, @ref KeyEvent::Key::RightSuper - */ - Super = 1 << 3 - }; + typedef CORRADE_DEPRECATED("use EmscriptenApplication::Modifier instead") EmscriptenApplication::Modifier Modifier; /** - * @brief Set of modifiers - * - * @see @ref KeyEvent::modifiers(), @ref PointerEvent::modifiers(), - * @ref PointerMoveEvent::modifiers(), - * @ref ScrollEvent::modifiers() + * @brief @copybrief EmscriptenApplication::Modifiers + * @m_deprecated_since_latest Use @ref EmscriptenApplication::Modifiers + * instead. */ - typedef Containers::EnumSet Modifiers; + typedef CORRADE_DEPRECATED("use EmscriptenApplication::Modifiers instead") EmscriptenApplication::Modifiers Modifiers; + #endif /** @brief Copying is not allowed */ InputEvent(const InputEvent&) = delete; @@ -1792,8 +2009,6 @@ class EmscriptenApplication::InputEvent { bool _accepted; }; -CORRADE_ENUMSET_OPERATORS(EmscriptenApplication::InputEvent::Modifiers) - /** @brief Pointer event @m_since_latest @@ -1856,7 +2071,7 @@ class EmscriptenApplication::PointerEvent: public InputEvent { Vector2 position() const { return _position; } /** @brief Modifiers */ - Modifiers modifiers() const { return _modifiers; } + EmscriptenApplication::Modifiers modifiers() const { return _modifiers; } /** * @brief Underlying Emscripten event @@ -1874,16 +2089,16 @@ class EmscriptenApplication::PointerEvent: public InputEvent { private: friend EmscriptenApplication; - explicit PointerEvent(const EmscriptenMouseEvent& event, Pointer pointer, Modifiers modifiers, const Vector2& position): _event{&event}, _source{PointerEventSource::Mouse}, _primary{true}, _pointer{pointer}, _modifiers{modifiers}, _id{~Int{}}, _position{position} {} + explicit PointerEvent(const EmscriptenMouseEvent& event, Pointer pointer, EmscriptenApplication::Modifiers modifiers, const Vector2& position): _event{&event}, _source{PointerEventSource::Mouse}, _primary{true}, _pointer{pointer}, _modifiers{modifiers}, _id{~Int{}}, _position{position} {} #if __EMSCRIPTEN_major__*10000 + __EMSCRIPTEN_minor__*100 + __EMSCRIPTEN_tiny__ >= 20027 - explicit PointerEvent(const EmscriptenTouchEvent& event, bool primary, Int id, Modifiers modifiers, const Vector2& position): _event{&event}, _source{PointerEventSource::Touch}, _primary{primary}, _pointer{Pointer::Finger}, _modifiers{modifiers}, _id{id}, _position{position} {} + explicit PointerEvent(const EmscriptenTouchEvent& event, bool primary, Int id, EmscriptenApplication::Modifiers modifiers, const Vector2& position): _event{&event}, _source{PointerEventSource::Touch}, _primary{primary}, _pointer{Pointer::Finger}, _modifiers{modifiers}, _id{id}, _position{position} {} #endif const void* _event; const PointerEventSource _source; const bool _primary; const Pointer _pointer; - const Modifiers _modifiers; + const EmscriptenApplication::Modifiers _modifiers; const Int _id; const Vector2 _position; }; @@ -2038,7 +2253,7 @@ class EmscriptenApplication::PointerMoveEvent: public InputEvent { Vector2 relativePosition() const { return _relativePosition; } /** @brief Modifiers */ - Modifiers modifiers() const { return _modifiers; } + EmscriptenApplication::Modifiers modifiers() const { return _modifiers; } /** * @brief Underlying Emscripten event @@ -2056,9 +2271,9 @@ class EmscriptenApplication::PointerMoveEvent: public InputEvent { private: friend EmscriptenApplication; - explicit PointerMoveEvent(const EmscriptenMouseEvent& event, Containers::Optional pointer, Pointers pointers, Modifiers modifiers, const Vector2& position, const Vector2& relativePosition): _event{&event}, _source{PointerEventSource::Mouse}, _primary{true}, _pointer{pointer}, _pointers{pointers}, _modifiers{modifiers}, _id{~Int{}}, _position{position}, _relativePosition{relativePosition} {} + explicit PointerMoveEvent(const EmscriptenMouseEvent& event, Containers::Optional pointer, Pointers pointers, EmscriptenApplication::Modifiers modifiers, const Vector2& position, const Vector2& relativePosition): _event{&event}, _source{PointerEventSource::Mouse}, _primary{true}, _pointer{pointer}, _pointers{pointers}, _modifiers{modifiers}, _id{~Int{}}, _position{position}, _relativePosition{relativePosition} {} #if __EMSCRIPTEN_major__*10000 + __EMSCRIPTEN_minor__*100 + __EMSCRIPTEN_tiny__ >= 20027 - explicit PointerMoveEvent(const EmscriptenTouchEvent& event, bool primary, Int id, Modifiers modifiers, const Vector2& position, const Vector2& relativePosition): _event{&event}, _source{PointerEventSource::Touch}, _primary{primary}, _pointer{}, _pointers{Pointer::Finger}, _modifiers{modifiers}, _id{id}, _position{position}, _relativePosition{relativePosition} {} + explicit PointerMoveEvent(const EmscriptenTouchEvent& event, bool primary, Int id, EmscriptenApplication::Modifiers modifiers, const Vector2& position, const Vector2& relativePosition): _event{&event}, _source{PointerEventSource::Touch}, _primary{primary}, _pointer{}, _pointers{Pointer::Finger}, _modifiers{modifiers}, _id{id}, _position{position}, _relativePosition{relativePosition} {} #endif const void* _event; @@ -2066,7 +2281,7 @@ class EmscriptenApplication::PointerMoveEvent: public InputEvent { const bool _primary; const Containers::Optional _pointer; const Pointers _pointers; - const Modifiers _modifiers; + const EmscriptenApplication::Modifiers _modifiers; const Int _id; const Vector2 _position; const Vector2 _relativePosition; @@ -2140,7 +2355,7 @@ class CORRADE_DEPRECATED("use PointerMoveEvent and pointerMoveEvent() instead") Buttons buttons() const; /** @brief Modifiers */ - Modifiers modifiers() const; + EmscriptenApplication::Modifiers modifiers() const; /** @brief Underlying Emscripten event */ const EmscriptenMouseEvent& event() const { return _event; } @@ -2178,7 +2393,7 @@ class EmscriptenApplication::ScrollEvent: public EmscriptenApplication::InputEve Vector2 position() const; /** @brief Modifiers */ - Modifiers modifiers() const; + EmscriptenApplication::Modifiers modifiers() const; /** @brief Underlying Emscripten event */ const EmscriptenWheelEvent& event() const { return _event; } @@ -2208,7 +2423,7 @@ class CORRADE_DEPRECATED("use ScrollEvent and scrollEvent() instead") Emscripten Vector2i position() const; /** @brief Modifiers */ - Modifiers modifiers() const; + EmscriptenApplication::Modifiers modifiers() const; /** @brief Underlying Emscripten event */ const EmscriptenWheelEvent& event() const { return _event; } @@ -2229,202 +2444,14 @@ class CORRADE_DEPRECATED("use ScrollEvent and scrollEvent() instead") Emscripten */ class EmscriptenApplication::KeyEvent: public EmscriptenApplication::InputEvent { public: + #ifdef MAGNUM_BUILD_DEPRECATED /** - * @brief Key - * - * @see @ref key() + * @brief @copybrief EmscriptenApplication::Key + * @m_deprecated_since_latest Use @ref EmscriptenApplication::Key + * instead. */ - enum class Key: Int { - Unknown, /**< Unknown key */ - - /** - * Left Shift - * - * @see @ref InputEvent::Modifier::Shift - */ - LeftShift, - - /** - * Right Shift - * - * @see @ref InputEvent::Modifier::Shift - */ - RightShift, - - /** - * Left Ctrl - * - * @see @ref InputEvent::Modifier::Ctrl - */ - LeftCtrl, - - /** - * Right Ctrl - * - * @see @ref InputEvent::Modifier::Ctrl - */ - RightCtrl, - - /** - * Left Alt - * - * @see @ref InputEvent::Modifier::Alt - */ - LeftAlt, - - /** - * Right Alt - * - * @see @ref InputEvent::Modifier::Alt - */ - RightAlt, - - /** - * Left Super key (Windows/⌘) - * - * @see @ref InputEvent::Modifier::Super - */ - LeftSuper, - - /** - * Right Super key (Windows/⌘) - * - * @see @ref InputEvent::Modifier::Super - */ - RightSuper, - - /* no equivalent for Sdl2Application's AltGr */ - - Enter, /**< Enter */ - Esc, /**< Escape */ - - Up, /**< Up arrow */ - Down, /**< Down arrow */ - Left, /**< Left arrow */ - Right, /**< Right arrow */ - Home, /**< Home */ - End, /**< End */ - PageUp, /**< Page up */ - PageDown, /**< Page down */ - Backspace, /**< Backspace */ - Insert, /**< Insert */ - Delete, /**< Delete */ - - F1, /**< F1 */ - F2, /**< F2 */ - F3, /**< F3 */ - F4, /**< F4 */ - F5, /**< F5 */ - F6, /**< F6 */ - F7, /**< F7 */ - F8, /**< F8 */ - F9, /**< F9 */ - F10, /**< F10 */ - F11, /**< F11 */ - F12, /**< F12 */ - - Zero = '0', /**< Zero */ - One, /**< One */ - Two, /**< Two */ - Three, /**< Three */ - Four, /**< Four */ - Five, /**< Five */ - Six, /**< Six */ - Seven, /**< Seven */ - Eight, /**< Eight */ - Nine, /**< Nine */ - - A = 'a', /**< Letter A */ - B, /**< Letter B */ - C, /**< Letter C */ - D, /**< Letter D */ - E, /**< Letter E */ - F, /**< Letter F */ - G, /**< Letter G */ - H, /**< Letter H */ - I, /**< Letter I */ - J, /**< Letter J */ - K, /**< Letter K */ - L, /**< Letter L */ - M, /**< Letter M */ - N, /**< Letter N */ - O, /**< Letter O */ - P, /**< Letter P */ - Q, /**< Letter Q */ - R, /**< Letter R */ - S, /**< Letter S */ - T, /**< Letter T */ - U, /**< Letter U */ - V, /**< Letter V */ - W, /**< Letter W */ - X, /**< Letter X */ - Y, /**< Letter Y */ - Z, /**< Letter Z */ - - Space, /**< Space */ - Tab, /**< Tab */ - Quote, /**< Quote (') */ - Comma, /**< Comma */ - Period, /**< Period */ - Minus, /**< Minus */ - - /** - * Plus. On the US keyboard layout this may only be representable - * as @m_class{m-label m-warning} **Shift** - * @m_class{m-label m-default} **=**. - */ - Plus, - - Slash, /**< Slash */ - - /** - * Percent. On the US keyboard layout this may only be - * representable as @m_class{m-label m-warning} **Shift** - * @m_class{m-label m-default} **5**. - */ - Percent, - - /** - * Semicolon (`;`) - * @m_since{2020,06} - */ - Semicolon, - - Equal, /**< Equal */ - LeftBracket, /**< Left bracket (`[`) */ - RightBracket, /**< Right bracket (`]`) */ - Backslash, /**< Backslash (`\`) */ - Backquote, /**< Backquote (`) */ - - /* no equivalent for GlfwApplication's World1 / World2 */ - /** @todo there's IntlBackslash for World1, implement once there's - consensus about naming */ - - CapsLock, /**< Caps lock */ - ScrollLock, /**< Scroll lock */ - NumLock, /**< Num lock */ - PrintScreen, /**< Print screen */ - Pause, /**< Pause */ - Menu, /**< Menu */ - - NumZero, /**< Numpad zero */ - NumOne, /**< Numpad one */ - NumTwo, /**< Numpad two */ - NumThree, /**< Numpad three */ - NumFour, /**< Numpad four */ - NumFive, /**< Numpad five */ - NumSix, /**< Numpad six */ - NumSeven, /**< Numpad seven */ - NumEight, /**< Numpad eight */ - NumNine, /**< Numpad nine */ - NumDecimal, /**< Numpad decimal */ - NumDivide, /**< Numpad divide */ - NumMultiply, /**< Numpad multiply */ - NumSubtract, /**< Numpad subtract */ - NumAdd, /**< Numpad add */ - NumEnter, /**< Numpad enter */ - NumEqual /**< Numpad equal */ - }; + typedef CORRADE_DEPRECATED("use EmscriptenApplication::Key instead") EmscriptenApplication::Key Key; + #endif /** * @brief Key @@ -2435,7 +2462,7 @@ class EmscriptenApplication::KeyEvent: public EmscriptenApplication::InputEvent * @m_class{m-doc-external} [EmscriptenkeyboardEvent::key](https://emscripten.org/docs/api_reference/html5.h.html#c.EmscriptenKeyboardEvent.key), * which respects the keyboard layout. */ - Key key() const; + EmscriptenApplication::Key key() const; /** * @brief Key name @@ -2447,7 +2474,7 @@ class EmscriptenApplication::KeyEvent: public EmscriptenApplication::InputEvent Containers::StringView keyName() const; /** @brief Modifiers */ - Modifiers modifiers() const; + EmscriptenApplication::Modifiers modifiers() const; /** @brief Underlying Emscripten event */ const EmscriptenKeyboardEvent& event() const { return _event; } diff --git a/src/Magnum/Platform/GlfwApplication.cpp b/src/Magnum/Platform/GlfwApplication.cpp index acce4b083..d4556f7f0 100644 --- a/src/Magnum/Platform/GlfwApplication.cpp +++ b/src/Magnum/Platform/GlfwApplication.cpp @@ -382,23 +382,23 @@ bool GlfwApplication::tryCreate(const Configuration& configuration) { namespace { -GlfwApplication::InputEvent::Modifiers currentGlfwModifiers(GLFWwindow* window) { +GlfwApplication::Modifiers currentGlfwModifiers(GLFWwindow* window) { static_assert(GLFW_PRESS == true && GLFW_RELEASE == false, "GLFW press and release constants do not correspond to bool values"); - GlfwApplication::InputEvent::Modifiers mods; + GlfwApplication::Modifiers mods; if(glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) || glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT)) - mods |= GlfwApplication::InputEvent::Modifier::Shift; + mods |= GlfwApplication::Modifier::Shift; if(glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) || glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL)) - mods |= GlfwApplication::InputEvent::Modifier::Ctrl; + mods |= GlfwApplication::Modifier::Ctrl; if(glfwGetKey(window, GLFW_KEY_LEFT_ALT) || glfwGetKey(window, GLFW_KEY_RIGHT_ALT)) - mods |= GlfwApplication::InputEvent::Modifier::Alt; + mods |= GlfwApplication::Modifier::Alt; if(glfwGetKey(window, GLFW_KEY_LEFT_SUPER) || glfwGetKey(window, GLFW_KEY_RIGHT_SUPER)) - mods |= GlfwApplication::InputEvent::Modifier::Super; + mods |= GlfwApplication::Modifier::Super; return mods; } @@ -665,7 +665,7 @@ void GlfwApplication::setupCallbacks() { glfwSetKeyCallback(_window, [](GLFWwindow* const window, const int key, int, const int action, const int mods) { auto& app = *static_cast(glfwGetWindowUserPointer(window)); - KeyEvent e(static_cast(key), {static_cast(mods)}, action == GLFW_REPEAT); + KeyEvent e(Key(key), Modifiers{mods}, action == GLFW_REPEAT); if(action == GLFW_PRESS || action == GLFW_REPEAT) app.keyPressEvent(e); @@ -690,10 +690,10 @@ void GlfwApplication::setupCallbacks() { the callback, set them directly instead of having them lazily populated later */ e._pointers = pointers; - e._modifiers = InputEvent::Modifiers{mods}; + e._modifiers = Modifiers{mods}; app.pointerMoveEvent(e); } else { - PointerEvent e{pointer, position, InputEvent::Modifiers{mods}}; + PointerEvent e{pointer, position, Modifiers{mods}}; if(action == GLFW_PRESS) /* we don't handle GLFW_REPEAT */ app.pointerPressEvent(e); else if(action == GLFW_RELEASE) @@ -1107,7 +1107,7 @@ GlfwApplication::Configuration::Configuration(): GlfwApplication::Configuration::~Configuration() = default; -Containers::StringView GlfwApplication::KeyEvent::keyName(const Key key) { +Containers::StringView GlfwApplication::KeyEvent::keyName(const GlfwApplication::Key key) { return glfwGetKeyName(int(key), 0); } @@ -1122,7 +1122,7 @@ GlfwApplication::Pointers GlfwApplication::PointerMoveEvent::pointers() { return *_pointers; } -auto GlfwApplication::PointerMoveEvent::modifiers() -> Modifiers { +GlfwApplication::Modifiers GlfwApplication::PointerMoveEvent::modifiers() { if(!_modifiers) _modifiers = currentGlfwModifiers(_window); return *_modifiers; } @@ -1143,14 +1143,14 @@ auto GlfwApplication::MouseMoveEvent::buttons() -> Buttons { return *_buttons; } -auto GlfwApplication::MouseMoveEvent::modifiers() -> Modifiers { +GlfwApplication::Modifiers GlfwApplication::MouseMoveEvent::modifiers() { if(!_modifiers) _modifiers = currentGlfwModifiers(_window); return *_modifiers; } CORRADE_IGNORE_DEPRECATED_POP #endif -auto GlfwApplication::ScrollEvent::modifiers() -> Modifiers { +GlfwApplication::Modifiers GlfwApplication::ScrollEvent::modifiers() { if(!_modifiers) _modifiers = currentGlfwModifiers(_window); return *_modifiers; } @@ -1175,7 +1175,7 @@ Vector2i GlfwApplication::MouseScrollEvent::position() { return *_position; } -auto GlfwApplication::MouseScrollEvent::modifiers() -> Modifiers { +GlfwApplication::Modifiers GlfwApplication::MouseScrollEvent::modifiers() { if(!_modifiers) _modifiers = currentGlfwModifiers(_window); return *_modifiers; } diff --git a/src/Magnum/Platform/GlfwApplication.h b/src/Magnum/Platform/GlfwApplication.h index bf7089336..764ce802d 100644 --- a/src/Magnum/Platform/GlfwApplication.h +++ b/src/Magnum/Platform/GlfwApplication.h @@ -190,10 +190,22 @@ class GlfwApplication { /* The damn thing cannot handle forward enum declarations */ #ifndef DOXYGEN_GENERATING_OUTPUT + enum class Modifier: Int; + enum class Key: Int; enum class PointerEventSource: UnsignedByte; enum class Pointer: UnsignedByte; #endif + /** + * @brief Set of keyboard modifiers + * @m_since_latest + * + * @see @ref KeyEvent::modifiers(), @ref PointerEvent::modifiers(), + * @ref PointerMoveEvent::modifiers(), + * @ref ScrollEvent::modifiers() + */ + typedef Containers::EnumSet Modifiers; + /** * @brief Set of pointer types * @m_since_latest @@ -932,6 +944,286 @@ class GlfwApplication { Vector2 _previousMouseMovePosition{Constants::nan()}; }; +/** +@brief Keyboard modifier +@m_since_latest + +@see @ref Modifiers, @ref KeyEvent::modifiers(), + @ref PointerEvent::modifiers(), @ref PointerMoveEvent::modifiers(), + @ref ScrollEvent::modifiers() +*/ +enum class GlfwApplication::Modifier: Int { + /** + * Shift + * + * @see @ref KeyEvent::Key::LeftShift, @ref KeyEvent::Key::RightShift + */ + Shift = GLFW_MOD_SHIFT, + + /** + * Ctrl + * + * @see @ref KeyEvent::Key::LeftCtrl, @ref KeyEvent::Key::RightCtrl + */ + Ctrl = GLFW_MOD_CONTROL, + + /** + * Alt + * + * @see @ref KeyEvent::Key::LeftAlt, @ref KeyEvent::Key::RightAlt + */ + Alt = GLFW_MOD_ALT, + + /** + * Super key (Windows/⌘) + * + * @see @ref KeyEvent::Key::LeftSuper, @ref KeyEvent::Key::RightSuper + */ + Super = GLFW_MOD_SUPER +}; + +CORRADE_ENUMSET_OPERATORS(GlfwApplication::Modifiers) + +/** +@brief Key +@m_since_latest + +@see @ref KeyEvent::key() +*/ +enum class GlfwApplication::Key: Int { + Unknown = GLFW_KEY_UNKNOWN, /**< Unknown key */ + + /** + * Left Shift + * + * @see @ref InputEvent::Modifier::Shift + */ + LeftShift = GLFW_KEY_LEFT_SHIFT, + + /** + * Right Shift + * + * @see @ref InputEvent::Modifier::Shift + */ + RightShift = GLFW_KEY_RIGHT_SHIFT, + + /** + * Left Ctrl + * + * @see @ref InputEvent::Modifier::Ctrl + */ + LeftCtrl = GLFW_KEY_LEFT_CONTROL, + + /** + * Right Ctrl + * + * @see @ref InputEvent::Modifier::Ctrl + */ + RightCtrl = GLFW_KEY_RIGHT_CONTROL, + + /** + * Left Alt + * + * @see @ref InputEvent::Modifier::Alt + */ + LeftAlt = GLFW_KEY_LEFT_ALT, + + /** + * Right Alt + * + * @see @ref InputEvent::Modifier::Alt + */ + RightAlt = GLFW_KEY_RIGHT_ALT, + + /** + * Left Super key (Windows/⌘) + * + * @see @ref InputEvent::Modifier::Super + */ + LeftSuper = GLFW_KEY_LEFT_SUPER, + + /** + * Right Super key (Windows/⌘) + * + * @see @ref InputEvent::Modifier::Super + */ + RightSuper = GLFW_KEY_RIGHT_SUPER, + + /* no equivalent for Sdl2Application's AltGr */ + + Enter = GLFW_KEY_ENTER, /**< Enter */ + Esc = GLFW_KEY_ESCAPE, /**< Escape */ + + Up = GLFW_KEY_UP, /**< Up arrow */ + Down = GLFW_KEY_DOWN, /**< Down arrow */ + Left = GLFW_KEY_LEFT, /**< Left arrow */ + Right = GLFW_KEY_RIGHT, /**< Right arrow */ + Home = GLFW_KEY_HOME, /**< Home */ + End = GLFW_KEY_END, /**< End */ + PageUp = GLFW_KEY_PAGE_UP, /**< Page up */ + PageDown = GLFW_KEY_PAGE_DOWN, /**< Page down */ + Backspace = GLFW_KEY_BACKSPACE, /**< Backspace */ + Insert = GLFW_KEY_INSERT, /**< Insert */ + Delete = GLFW_KEY_DELETE, /**< Delete */ + + F1 = GLFW_KEY_F1, /**< F1 */ + F2 = GLFW_KEY_F2, /**< F2 */ + F3 = GLFW_KEY_F3, /**< F3 */ + F4 = GLFW_KEY_F4, /**< F4 */ + F5 = GLFW_KEY_F5, /**< F5 */ + F6 = GLFW_KEY_F6, /**< F6 */ + F7 = GLFW_KEY_F7, /**< F7 */ + F8 = GLFW_KEY_F8, /**< F8 */ + F9 = GLFW_KEY_F9, /**< F9 */ + F10 = GLFW_KEY_F10, /**< F10 */ + F11 = GLFW_KEY_F11, /**< F11 */ + F12 = GLFW_KEY_F12, /**< F12 */ + + Space = GLFW_KEY_SPACE, /**< Space */ + Tab = GLFW_KEY_TAB, /**< Tab */ + + /** + * Quote (') + * @m_since{2020,06} + */ + Quote = GLFW_KEY_APOSTROPHE, + + Comma = GLFW_KEY_COMMA, /**< Comma */ + Period = GLFW_KEY_PERIOD, /**< Period */ + Minus = GLFW_KEY_MINUS, /**< Minus */ + + /** + * Plus. On the US keyboard layout this may only be representable as + * @m_class{m-label m-warning} **Shift** @m_class{m-label m-default} **=**. + */ + Plus = '+', + + Slash = GLFW_KEY_SLASH, /**< Slash */ + + /** + * Percent. On the US keyboard layout this may only be representable as + * @m_class{m-label m-warning} **Shift** @m_class{m-label m-default} **5**. + */ + Percent = '%', + + Semicolon = GLFW_KEY_SEMICOLON, /**< Semicolon (`;`) */ + + #ifdef MAGNUM_BUILD_DEPRECATED + /** Semicolon (`;`) + * @m_deprecated_since{2019,01} Use @ref Key::Semicolon instead. + */ + Smicolon CORRADE_DEPRECATED_ENUM("use Key::Semicolon instead") = Semicolon, + #endif + + Equal = GLFW_KEY_EQUAL, /**< Equal */ + + /** + * Left bracket (`[`) + * @m_since{2020,06} + */ + LeftBracket = GLFW_KEY_LEFT_BRACKET, + + /** + * Right bracket (`]`) + * @m_since{2020,06} + */ + RightBracket = GLFW_KEY_RIGHT_BRACKET, + + /** + * Backslash (`\`) + * @see @ref Key::World1, @ref Key::World2 + * @m_since{2020,06} + */ + Backslash = GLFW_KEY_BACKSLASH, + + /** + * Backquote (`) + * @m_since{2020,06} + */ + Backquote = GLFW_KEY_GRAVE_ACCENT, + + /** + * Non-US \#1. Can be for example a backslash (`\`) next to left Shift. + * @see @ref Key::Backslash + * @m_since{2020,06} + * @todo Revisit / rename together with World2 once + * https://github.com/glfw/glfw/issues/2481 is resolved. SDL + * scancode for this key is SDL_SCANCODE_NONUSBACKSLASH, HTML5 + * names it IntlBackslash. + */ + World1 = GLFW_KEY_WORLD_1, + + /** + * Non-US \#2 + * @see @ref Key::Backslash + * @m_since{2020,06} + */ + World2 = GLFW_KEY_WORLD_2, + + Zero = GLFW_KEY_0, /**< Zero */ + One = GLFW_KEY_1, /**< One */ + Two = GLFW_KEY_2, /**< Two */ + Three = GLFW_KEY_3, /**< Three */ + Four = GLFW_KEY_4, /**< Four */ + Five = GLFW_KEY_5, /**< Five */ + Six = GLFW_KEY_6, /**< Six */ + Seven = GLFW_KEY_7, /**< Seven */ + Eight = GLFW_KEY_8, /**< Eight */ + Nine = GLFW_KEY_9, /**< Nine */ + + A = GLFW_KEY_A, /**< Letter A */ + B = GLFW_KEY_B, /**< Letter B */ + C = GLFW_KEY_C, /**< Letter C */ + D = GLFW_KEY_D, /**< Letter D */ + E = GLFW_KEY_E, /**< Letter E */ + F = GLFW_KEY_F, /**< Letter F */ + G = GLFW_KEY_G, /**< Letter G */ + H = GLFW_KEY_H, /**< Letter H */ + I = GLFW_KEY_I, /**< Letter I */ + J = GLFW_KEY_J, /**< Letter J */ + K = GLFW_KEY_K, /**< Letter K */ + L = GLFW_KEY_L, /**< Letter L */ + M = GLFW_KEY_M, /**< Letter M */ + N = GLFW_KEY_N, /**< Letter N */ + O = GLFW_KEY_O, /**< Letter O */ + P = GLFW_KEY_P, /**< Letter P */ + Q = GLFW_KEY_Q, /**< Letter Q */ + R = GLFW_KEY_R, /**< Letter R */ + S = GLFW_KEY_S, /**< Letter S */ + T = GLFW_KEY_T, /**< Letter T */ + U = GLFW_KEY_U, /**< Letter U */ + V = GLFW_KEY_V, /**< Letter V */ + W = GLFW_KEY_W, /**< Letter W */ + X = GLFW_KEY_X, /**< Letter X */ + Y = GLFW_KEY_Y, /**< Letter Y */ + Z = GLFW_KEY_Z, /**< Letter Z */ + + CapsLock = GLFW_KEY_CAPS_LOCK, /**< Caps lock */ + ScrollLock = GLFW_KEY_SCROLL_LOCK, /**< Scroll lock */ + NumLock = GLFW_KEY_NUM_LOCK, /**< Num lock */ + PrintScreen = GLFW_KEY_PRINT_SCREEN,/**< Print screen */ + Pause = GLFW_KEY_PAUSE, /**< Pause */ + Menu = GLFW_KEY_MENU, /**< Menu */ + + NumZero = GLFW_KEY_KP_0, /**< Numpad zero */ + NumOne = GLFW_KEY_KP_1, /**< Numpad one */ + NumTwo = GLFW_KEY_KP_2, /**< Numpad two */ + NumThree = GLFW_KEY_KP_3, /**< Numpad three */ + NumFour = GLFW_KEY_KP_4, /**< Numpad four */ + NumFive = GLFW_KEY_KP_5, /**< Numpad five */ + NumSix = GLFW_KEY_KP_6, /**< Numpad six */ + NumSeven = GLFW_KEY_KP_7, /**< Numpad seven */ + NumEight = GLFW_KEY_KP_8, /**< Numpad eight */ + NumNine = GLFW_KEY_KP_9, /**< Numpad nine */ + NumDecimal = GLFW_KEY_KP_DECIMAL, /**< Numpad decimal */ + NumDivide = GLFW_KEY_KP_DIVIDE, /**< Numpad divide */ + NumMultiply = GLFW_KEY_KP_MULTIPLY, /**< Numpad multiply */ + NumSubtract = GLFW_KEY_KP_SUBTRACT, /**< Numpad subtract */ + NumAdd = GLFW_KEY_KP_ADD, /**< Numpad add */ + NumEnter = GLFW_KEY_KP_ENTER, /**< Numpad enter */ + NumEqual = GLFW_KEY_KP_EQUAL /**< Numpad equal */ +}; + /** @brief Pointer event source @m_since_latest @@ -1742,52 +2034,21 @@ class GlfwApplication::ViewportEvent { */ class GlfwApplication::InputEvent { public: + #ifdef MAGNUM_BUILD_DEPRECATED /** - * @brief Modifier - * - * @see @ref Modifiers, @ref KeyEvent::modifiers(), - * @ref PointerEvent::modifiers(), - * @ref PointerMoveEvent::modifiers(), - * @ref ScrollEvent::modifiers() + * @brief @copybrief GlfwApplication::Modifier + * @m_deprecated_since_latest Use @ref GlfwApplication::Modifier + * instead. */ - enum class Modifier: Int { - /** - * Shift - * - * @see @ref KeyEvent::Key::LeftShift, @ref KeyEvent::Key::RightShift - */ - Shift = GLFW_MOD_SHIFT, - - /** - * Ctrl - * - * @see @ref KeyEvent::Key::LeftCtrl, @ref KeyEvent::Key::RightCtrl - */ - Ctrl = GLFW_MOD_CONTROL, - - /** - * Alt - * - * @see @ref KeyEvent::Key::LeftAlt, @ref KeyEvent::Key::RightAlt - */ - Alt = GLFW_MOD_ALT, - - /** - * Super key (Windows/⌘) - * - * @see @ref KeyEvent::Key::LeftSuper, @ref KeyEvent::Key::RightSuper - */ - Super = GLFW_MOD_SUPER - }; + typedef CORRADE_DEPRECATED("use GlfwApplication::Modifier instead") GlfwApplication::Modifier Modifier; /** - * @brief Set of modifiers - * - * @see @ref KeyEvent::modifiers(), @ref PointerEvent::modifiers(), - * @ref PointerMoveEvent::modifiers(), - * @ref ScrollEvent::modifiers() + * @brief @copybrief GlfwApplication::Modifiers + * @m_deprecated_since_latest Use @ref GlfwApplication::Modifiers + * instead. */ - typedef Containers::EnumSet Modifiers; + typedef CORRADE_DEPRECATED("use GlfwApplication::Modifiers instead") GlfwApplication::Modifiers Modifiers; + #endif /** @brief Copying is not allowed */ InputEvent(const InputEvent&) = delete; @@ -1816,8 +2077,6 @@ class GlfwApplication::InputEvent { bool _accepted; }; -CORRADE_ENUMSET_OPERATORS(GlfwApplication::InputEvent::Modifiers) - /** @brief Key event @@ -1825,247 +2084,13 @@ CORRADE_ENUMSET_OPERATORS(GlfwApplication::InputEvent::Modifiers) */ class GlfwApplication::KeyEvent: public GlfwApplication::InputEvent { public: + #ifdef MAGNUM_BUILD_DEPRECATED /** - * @brief Key - * - * @see @ref key() + * @brief @copybrief GlfwApplication::Key + * @m_deprecated_since_latest Use @ref GlfwApplication::Key instead. */ - enum class Key: Int { - Unknown = GLFW_KEY_UNKNOWN, /**< Unknown key */ - - /** - * Left Shift - * - * @see @ref InputEvent::Modifier::Shift - */ - LeftShift = GLFW_KEY_LEFT_SHIFT, - - /** - * Right Shift - * - * @see @ref InputEvent::Modifier::Shift - */ - RightShift = GLFW_KEY_RIGHT_SHIFT, - - /** - * Left Ctrl - * - * @see @ref InputEvent::Modifier::Ctrl - */ - LeftCtrl = GLFW_KEY_LEFT_CONTROL, - - /** - * Right Ctrl - * - * @see @ref InputEvent::Modifier::Ctrl - */ - RightCtrl = GLFW_KEY_RIGHT_CONTROL, - - /** - * Left Alt - * - * @see @ref InputEvent::Modifier::Alt - */ - LeftAlt = GLFW_KEY_LEFT_ALT, - - /** - * Right Alt - * - * @see @ref InputEvent::Modifier::Alt - */ - RightAlt = GLFW_KEY_RIGHT_ALT, - - /** - * Left Super key (Windows/⌘) - * - * @see @ref InputEvent::Modifier::Super - */ - LeftSuper = GLFW_KEY_LEFT_SUPER, - - /** - * Right Super key (Windows/⌘) - * - * @see @ref InputEvent::Modifier::Super - */ - RightSuper = GLFW_KEY_RIGHT_SUPER, - - /* no equivalent for Sdl2Application's AltGr */ - - Enter = GLFW_KEY_ENTER, /**< Enter */ - Esc = GLFW_KEY_ESCAPE, /**< Escape */ - - Up = GLFW_KEY_UP, /**< Up arrow */ - Down = GLFW_KEY_DOWN, /**< Down arrow */ - Left = GLFW_KEY_LEFT, /**< Left arrow */ - Right = GLFW_KEY_RIGHT, /**< Right arrow */ - Home = GLFW_KEY_HOME, /**< Home */ - End = GLFW_KEY_END, /**< End */ - PageUp = GLFW_KEY_PAGE_UP, /**< Page up */ - PageDown = GLFW_KEY_PAGE_DOWN, /**< Page down */ - Backspace = GLFW_KEY_BACKSPACE, /**< Backspace */ - Insert = GLFW_KEY_INSERT, /**< Insert */ - Delete = GLFW_KEY_DELETE, /**< Delete */ - - F1 = GLFW_KEY_F1, /**< F1 */ - F2 = GLFW_KEY_F2, /**< F2 */ - F3 = GLFW_KEY_F3, /**< F3 */ - F4 = GLFW_KEY_F4, /**< F4 */ - F5 = GLFW_KEY_F5, /**< F5 */ - F6 = GLFW_KEY_F6, /**< F6 */ - F7 = GLFW_KEY_F7, /**< F7 */ - F8 = GLFW_KEY_F8, /**< F8 */ - F9 = GLFW_KEY_F9, /**< F9 */ - F10 = GLFW_KEY_F10, /**< F10 */ - F11 = GLFW_KEY_F11, /**< F11 */ - F12 = GLFW_KEY_F12, /**< F12 */ - - Space = GLFW_KEY_SPACE, /**< Space */ - Tab = GLFW_KEY_TAB, /**< Tab */ - - /** - * Quote (') - * @m_since{2020,06} - */ - Quote = GLFW_KEY_APOSTROPHE, - - Comma = GLFW_KEY_COMMA, /**< Comma */ - Period = GLFW_KEY_PERIOD, /**< Period */ - Minus = GLFW_KEY_MINUS, /**< Minus */ - - /** - * Plus. On the US keyboard layout this may only be representable - * as @m_class{m-label m-warning} **Shift** - * @m_class{m-label m-default} **=**. - */ - Plus = '+', - - Slash = GLFW_KEY_SLASH, /**< Slash */ - - /** - * Percent. On the US keyboard layout this may only be - * representable as @m_class{m-label m-warning} **Shift** - * @m_class{m-label m-default} **5**. - */ - Percent = '%', - - Semicolon = GLFW_KEY_SEMICOLON, /**< Semicolon (`;`) */ - - #ifdef MAGNUM_BUILD_DEPRECATED - /** Semicolon (`;`) - * @m_deprecated_since{2019,01} Use @ref Key::Semicolon instead. - */ - Smicolon CORRADE_DEPRECATED_ENUM("use Key::Semicolon instead") = Semicolon, - #endif - - Equal = GLFW_KEY_EQUAL, /**< Equal */ - - /** - * Left bracket (`[`) - * @m_since{2020,06} - */ - LeftBracket = GLFW_KEY_LEFT_BRACKET, - - /** - * Right bracket (`]`) - * @m_since{2020,06} - */ - RightBracket = GLFW_KEY_RIGHT_BRACKET, - - /** - * Backslash (`\`) - * @see @ref Key::World1, @ref Key::World2 - * @m_since{2020,06} - */ - Backslash = GLFW_KEY_BACKSLASH, - - /** - * Backquote (`) - * @m_since{2020,06} - */ - Backquote = GLFW_KEY_GRAVE_ACCENT, - - /** - * Non-US \#1. Can be for example a backslash (`\`) next to left - * Shift. - * @see @ref Key::Backslash - * @m_since{2020,06} - * @todo Revisit / rename together with World2 once - * https://github.com/glfw/glfw/issues/2481 is resolved. SDL - * scancode for this key is SDL_SCANCODE_NONUSBACKSLASH, HTML5 - * names it IntlBackslash. - */ - World1 = GLFW_KEY_WORLD_1, - - /** - * Non-US \#2 - * @see @ref Key::Backslash - * @m_since{2020,06} - */ - World2 = GLFW_KEY_WORLD_2, - - Zero = GLFW_KEY_0, /**< Zero */ - One = GLFW_KEY_1, /**< One */ - Two = GLFW_KEY_2, /**< Two */ - Three = GLFW_KEY_3, /**< Three */ - Four = GLFW_KEY_4, /**< Four */ - Five = GLFW_KEY_5, /**< Five */ - Six = GLFW_KEY_6, /**< Six */ - Seven = GLFW_KEY_7, /**< Seven */ - Eight = GLFW_KEY_8, /**< Eight */ - Nine = GLFW_KEY_9, /**< Nine */ - - A = GLFW_KEY_A, /**< Letter A */ - B = GLFW_KEY_B, /**< Letter B */ - C = GLFW_KEY_C, /**< Letter C */ - D = GLFW_KEY_D, /**< Letter D */ - E = GLFW_KEY_E, /**< Letter E */ - F = GLFW_KEY_F, /**< Letter F */ - G = GLFW_KEY_G, /**< Letter G */ - H = GLFW_KEY_H, /**< Letter H */ - I = GLFW_KEY_I, /**< Letter I */ - J = GLFW_KEY_J, /**< Letter J */ - K = GLFW_KEY_K, /**< Letter K */ - L = GLFW_KEY_L, /**< Letter L */ - M = GLFW_KEY_M, /**< Letter M */ - N = GLFW_KEY_N, /**< Letter N */ - O = GLFW_KEY_O, /**< Letter O */ - P = GLFW_KEY_P, /**< Letter P */ - Q = GLFW_KEY_Q, /**< Letter Q */ - R = GLFW_KEY_R, /**< Letter R */ - S = GLFW_KEY_S, /**< Letter S */ - T = GLFW_KEY_T, /**< Letter T */ - U = GLFW_KEY_U, /**< Letter U */ - V = GLFW_KEY_V, /**< Letter V */ - W = GLFW_KEY_W, /**< Letter W */ - X = GLFW_KEY_X, /**< Letter X */ - Y = GLFW_KEY_Y, /**< Letter Y */ - Z = GLFW_KEY_Z, /**< Letter Z */ - - CapsLock = GLFW_KEY_CAPS_LOCK, /**< Caps lock */ - ScrollLock = GLFW_KEY_SCROLL_LOCK, /**< Scroll lock */ - NumLock = GLFW_KEY_NUM_LOCK, /**< Num lock */ - PrintScreen = GLFW_KEY_PRINT_SCREEN,/**< Print screen */ - Pause = GLFW_KEY_PAUSE, /**< Pause */ - Menu = GLFW_KEY_MENU, /**< Menu */ - - NumZero = GLFW_KEY_KP_0, /**< Numpad zero */ - NumOne = GLFW_KEY_KP_1, /**< Numpad one */ - NumTwo = GLFW_KEY_KP_2, /**< Numpad two */ - NumThree = GLFW_KEY_KP_3, /**< Numpad three */ - NumFour = GLFW_KEY_KP_4, /**< Numpad four */ - NumFive = GLFW_KEY_KP_5, /**< Numpad five */ - NumSix = GLFW_KEY_KP_6, /**< Numpad six */ - NumSeven = GLFW_KEY_KP_7, /**< Numpad seven */ - NumEight = GLFW_KEY_KP_8, /**< Numpad eight */ - NumNine = GLFW_KEY_KP_9, /**< Numpad nine */ - NumDecimal = GLFW_KEY_KP_DECIMAL, /**< Numpad decimal */ - NumDivide = GLFW_KEY_KP_DIVIDE, /**< Numpad divide */ - NumMultiply = GLFW_KEY_KP_MULTIPLY, /**< Numpad multiply */ - NumSubtract = GLFW_KEY_KP_SUBTRACT, /**< Numpad subtract */ - NumAdd = GLFW_KEY_KP_ADD, /**< Numpad add */ - NumEnter = GLFW_KEY_KP_ENTER, /**< Numpad enter */ - NumEqual = GLFW_KEY_KP_EQUAL /**< Numpad equal */ - }; + typedef CORRADE_DEPRECATED("use GlfwApplication::Key instead") GlfwApplication::Key Key; + #endif /** * @brief Name for given key @@ -2078,10 +2103,10 @@ class GlfwApplication::KeyEvent: public GlfwApplication::InputEvent { * exits. * @see @ref keyName(Key) */ - static Containers::StringView keyName(Key key); + static Containers::StringView keyName(GlfwApplication::Key key); /** @copydoc Sdl2Application::KeyEvent::key() */ - Key key() const { return _key; } + GlfwApplication::Key key() const { return _key; } /** * @brief Key name @@ -2098,7 +2123,7 @@ class GlfwApplication::KeyEvent: public GlfwApplication::InputEvent { Containers::StringView keyName() const; /** @brief Modifiers */ - Modifiers modifiers() const { return _modifiers; } + GlfwApplication::Modifiers modifiers() const { return _modifiers; } /** @copydoc Sdl2Application::KeyEvent::isRepeated() */ bool isRepeated() const { return _repeated; } @@ -2106,10 +2131,10 @@ class GlfwApplication::KeyEvent: public GlfwApplication::InputEvent { private: friend GlfwApplication; - explicit KeyEvent(Key key, Modifiers modifiers, bool repeated): _key{key}, _modifiers{modifiers}, _repeated{repeated} {} + explicit KeyEvent(GlfwApplication::Key key, GlfwApplication::Modifiers modifiers, bool repeated): _key{key}, _modifiers{modifiers}, _repeated{repeated} {} - const Key _key; - const Modifiers _modifiers; + const GlfwApplication::Key _key; + const GlfwApplication::Modifiers _modifiers; const bool _repeated; }; @@ -2174,16 +2199,16 @@ class GlfwApplication::PointerEvent: public InputEvent { Vector2 position() const { return _position; } /** @brief Modifiers */ - Modifiers modifiers() const { return _modifiers; } + GlfwApplication::Modifiers modifiers() const { return _modifiers; } private: friend GlfwApplication; - explicit PointerEvent(Pointer pointer, const Vector2& position, Modifiers modifiers): _pointer(pointer), _position{position}, _modifiers{modifiers} {} + explicit PointerEvent(Pointer pointer, const Vector2& position, GlfwApplication::Modifiers modifiers): _pointer(pointer), _position{position}, _modifiers{modifiers} {} const Pointer _pointer; const Vector2 _position; - const Modifiers _modifiers; + const GlfwApplication::Modifiers _modifiers; }; #ifdef MAGNUM_BUILD_DEPRECATED @@ -2224,16 +2249,16 @@ class CORRADE_DEPRECATED("use PointerEvent, pointerPressEvent() and pointerRelea Vector2i position() const { return _position; } /** @brief Modifiers */ - Modifiers modifiers() const { return _modifiers; } + GlfwApplication::Modifiers modifiers() const { return _modifiers; } private: friend GlfwApplication; - explicit MouseEvent(Button button, const Vector2i& position, Modifiers modifiers): _button{button}, _position{position}, _modifiers{modifiers} {} + explicit MouseEvent(Button button, const Vector2i& position, GlfwApplication::Modifiers modifiers): _button{button}, _position{position}, _modifiers{modifiers} {} const Button _button; const Vector2i _position; - const Modifiers _modifiers; + const GlfwApplication::Modifiers _modifiers; }; #endif @@ -2331,7 +2356,7 @@ class GlfwApplication::PointerMoveEvent: public InputEvent { * * Lazily populated on first request. */ - Modifiers modifiers(); + GlfwApplication::Modifiers modifiers(); private: friend GlfwApplication; @@ -2342,7 +2367,7 @@ class GlfwApplication::PointerMoveEvent: public InputEvent { const Containers::Optional _pointer; Containers::Optional _pointers; const Vector2 _position, _relativePosition; - Containers::Optional _modifiers; + Containers::Optional _modifiers; }; #ifdef MAGNUM_BUILD_DEPRECATED @@ -2400,7 +2425,7 @@ class CORRADE_DEPRECATED("use PointerMoveEvent and pointerMoveEvent() instead") * * Lazily populated on first request. */ - Modifiers modifiers(); + GlfwApplication::Modifiers modifiers(); private: friend GlfwApplication; @@ -2410,7 +2435,7 @@ class CORRADE_DEPRECATED("use PointerMoveEvent and pointerMoveEvent() instead") GLFWwindow* const _window; const Vector2i _position, _relativePosition; Containers::Optional _buttons; - Containers::Optional _modifiers; + Containers::Optional _modifiers; }; CORRADE_IGNORE_DEPRECATED_PUSH @@ -2444,7 +2469,7 @@ class GlfwApplication::ScrollEvent: public InputEvent { * * Lazily populated on first request. */ - Modifiers modifiers(); + GlfwApplication::Modifiers modifiers(); private: friend GlfwApplication; @@ -2454,7 +2479,7 @@ class GlfwApplication::ScrollEvent: public InputEvent { GLFWwindow* const _window; const Vector2 _offset; Containers::Optional _position; - Containers::Optional _modifiers; + Containers::Optional _modifiers; }; #ifdef MAGNUM_BUILD_DEPRECATED @@ -2482,7 +2507,7 @@ class CORRADE_DEPRECATED("use ScrollEvent and scrollEvent() instead") GlfwApplic * * Lazily populated on first request. */ - Modifiers modifiers(); + GlfwApplication::Modifiers modifiers(); private: friend GlfwApplication; @@ -2492,7 +2517,7 @@ class CORRADE_DEPRECATED("use ScrollEvent and scrollEvent() instead") GlfwApplic GLFWwindow* const _window; const Vector2 _offset; Containers::Optional _position; - Containers::Optional _modifiers; + Containers::Optional _modifiers; }; #endif diff --git a/src/Magnum/Platform/Screen.h b/src/Magnum/Platform/Screen.h index 3d1d4c290..5b9680a11 100644 --- a/src/Magnum/Platform/Screen.h +++ b/src/Magnum/Platform/Screen.h @@ -53,6 +53,9 @@ CORRADE_ENUMSET_OPERATORS(PropagatedScreenEvents) template class ScreenKeyEventMixin {}; template class ScreenKeyEventMixin { public: + typedef typename BasicScreenedApplication::Modifier Modifier; + typedef typename BasicScreenedApplication::Modifiers Modifiers; + typedef typename BasicScreenedApplication::Key Key; typedef typename BasicScreenedApplication::KeyEvent KeyEvent; private: @@ -192,6 +195,33 @@ template class BasicScreen: typedef typename BasicScreenedApplication::InputEvent InputEvent; #ifdef DOXYGEN_GENERATING_OUTPUT + /** + * @brief Keyboard modifier + * @m_since_latest + * + * Defined only if the application has a + * @relativeref{Sdl2Application,KeyEvent}. + */ + typedef typename BasicScreenedApplication::Modifier Modifier; + + /** + * @brief Set of keyboard modifiers + * @m_since_latest + * + * Defined only if the application has a + * @relativeref{Sdl2Application,KeyEvent}. + */ + typedef typename BasicScreenedApplication::Modifiers Modifiers; + + /** + * @brief Key + * @m_since_latest + * + * Defined only if the application has a + * @relativeref{Sdl2Application,KeyEvent}. + */ + typedef typename BasicScreenedApplication::Key Key; + /** * @brief Key event * diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index e4aaf6deb..1b0fa8539 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -91,12 +91,16 @@ namespace { * (modifiers >= Shift) would pass only if both left and right were pressed, * which is usually not what the developers wants. */ -Sdl2Application::InputEvent::Modifiers fixedModifiers(Uint16 mod) { - Sdl2Application::InputEvent::Modifiers modifiers(static_cast(mod)); - if(modifiers & Sdl2Application::InputEvent::Modifier::Shift) modifiers |= Sdl2Application::InputEvent::Modifier::Shift; - if(modifiers & Sdl2Application::InputEvent::Modifier::Ctrl) modifiers |= Sdl2Application::InputEvent::Modifier::Ctrl; - if(modifiers & Sdl2Application::InputEvent::Modifier::Alt) modifiers |= Sdl2Application::InputEvent::Modifier::Alt; - if(modifiers & Sdl2Application::InputEvent::Modifier::Super) modifiers |= Sdl2Application::InputEvent::Modifier::Super; +Sdl2Application::Modifiers fixedModifiers(Uint16 mod) { + Sdl2Application::Modifiers modifiers{mod}; + if(modifiers & Sdl2Application::Modifier::Shift) + modifiers |= Sdl2Application::Modifier::Shift; + if(modifiers & Sdl2Application::Modifier::Ctrl) + modifiers |= Sdl2Application::Modifier::Ctrl; + if(modifiers & Sdl2Application::Modifier::Alt) + modifiers |= Sdl2Application::Modifier::Alt; + if(modifiers & Sdl2Application::Modifier::Super) + modifiers |= Sdl2Application::Modifier::Super; return modifiers; } @@ -1037,7 +1041,7 @@ bool Sdl2Application::mainLoopIteration() { case SDL_KEYDOWN: case SDL_KEYUP: { - KeyEvent e{event, static_cast(event.key.keysym.sym), fixedModifiers(event.key.keysym.mod), event.key.repeat != 0}; + KeyEvent e{event, Key(event.key.keysym.sym), fixedModifiers(event.key.keysym.mod), event.key.repeat != 0}; event.type == SDL_KEYDOWN ? keyPressEvent(e) : keyReleaseEvent(e); } break; @@ -1594,7 +1598,7 @@ Sdl2Application::Configuration::Configuration(): Sdl2Application::Configuration::~Configuration() = default; -Containers::StringView Sdl2Application::KeyEvent::keyName(const Key key) { +Containers::StringView Sdl2Application::KeyEvent::keyName(const Sdl2Application::Key key) { return SDL_GetKeyName(SDL_Keycode(key)); } @@ -1602,7 +1606,7 @@ Containers::StringView Sdl2Application::KeyEvent::keyName() const { return keyName(_key); } -Sdl2Application::InputEvent::Modifiers Sdl2Application::PointerEvent::modifiers() { +Sdl2Application::Modifiers Sdl2Application::PointerEvent::modifiers() { if(!_modifiers) _modifiers = fixedModifiers(Uint16(SDL_GetModState())); return *_modifiers; @@ -1610,14 +1614,14 @@ Sdl2Application::InputEvent::Modifiers Sdl2Application::PointerEvent::modifiers( #ifdef MAGNUM_BUILD_DEPRECATED CORRADE_IGNORE_DEPRECATED_PUSH -Sdl2Application::InputEvent::Modifiers Sdl2Application::MouseEvent::modifiers() { +Sdl2Application::Modifiers Sdl2Application::MouseEvent::modifiers() { if(_modifiers) return *_modifiers; return *(_modifiers = fixedModifiers(Uint16(SDL_GetModState()))); } CORRADE_IGNORE_DEPRECATED_POP #endif -Sdl2Application::InputEvent::Modifiers Sdl2Application::PointerMoveEvent::modifiers() { +Sdl2Application::Modifiers Sdl2Application::PointerMoveEvent::modifiers() { if(!_modifiers) _modifiers = fixedModifiers(Uint16(SDL_GetModState())); return *_modifiers; @@ -1625,7 +1629,7 @@ Sdl2Application::InputEvent::Modifiers Sdl2Application::PointerMoveEvent::modifi #ifdef MAGNUM_BUILD_DEPRECATED CORRADE_IGNORE_DEPRECATED_PUSH -Sdl2Application::InputEvent::Modifiers Sdl2Application::MouseMoveEvent::modifiers() { +Sdl2Application::Modifiers Sdl2Application::MouseMoveEvent::modifiers() { if(_modifiers) return *_modifiers; return *(_modifiers = fixedModifiers(Uint16(SDL_GetModState()))); } @@ -1641,7 +1645,7 @@ Vector2 Sdl2Application::ScrollEvent::position() { return *_position; } -Sdl2Application::InputEvent::Modifiers Sdl2Application::ScrollEvent::modifiers() { +Sdl2Application::Modifiers Sdl2Application::ScrollEvent::modifiers() { if(!_modifiers) _modifiers = fixedModifiers(Uint16(SDL_GetModState())); return *_modifiers; @@ -1656,7 +1660,7 @@ Vector2i Sdl2Application::MouseScrollEvent::position() { return *_position; } -Sdl2Application::InputEvent::Modifiers Sdl2Application::MouseScrollEvent::modifiers() { +Sdl2Application::Modifiers Sdl2Application::MouseScrollEvent::modifiers() { if(_modifiers) return *_modifiers; return *(_modifiers = fixedModifiers(Uint16(SDL_GetModState()))); } diff --git a/src/Magnum/Platform/Sdl2Application.h b/src/Magnum/Platform/Sdl2Application.h index 645d3928b..59940c0f6 100644 --- a/src/Magnum/Platform/Sdl2Application.h +++ b/src/Magnum/Platform/Sdl2Application.h @@ -550,10 +550,22 @@ class Sdl2Application { /* The damn thing cannot handle forward enum declarations */ #ifndef DOXYGEN_GENERATING_OUTPUT + enum class Modifier: Uint16; + enum class Key: SDL_Keycode; enum class PointerEventSource: UnsignedByte; enum class Pointer: UnsignedByte; #endif + /** + * @brief Set of keyboard modifiers + * @m_since_latest + * + * @see @ref KeyEvent::modifiers(), @ref PointerEvent::modifiers(), + * @ref PointerMoveEvent::modifiers(), + * @ref ScrollEvent::modifiers() + */ + typedef Containers::EnumSet Modifiers; + /** * @brief Set of pointer types * @m_since_latest @@ -1431,6 +1443,322 @@ class Sdl2Application { int _exitCode = 0; }; +/** +@brief Keyboard modifier +@m_since_latest + +@see @ref Modifiers, @ref KeyEvent::modifiers(), + @ref PointerEvent::modifiers(), @ref PointerMoveEvent::modifiers(), + @ref ScrollEvent::modifiers() + */ +enum class Sdl2Application::Modifier: Uint16 { + /** + * Shift + * + * @see @ref KeyEvent::Key::LeftShift, @ref KeyEvent::Key::RightShift + */ + Shift = KMOD_SHIFT, + + /** + * Ctrl + * + * @see @ref KeyEvent::Key::LeftCtrl, @ref KeyEvent::Key::RightCtrl + */ + Ctrl = KMOD_CTRL, + + /** + * Alt + * + * @see @ref KeyEvent::Key::LeftAlt, @ref KeyEvent::Key::RightAlt + */ + Alt = KMOD_ALT, + + /** + * Super key (Windows/⌘) + * + * @see @ref KeyEvent::Key::LeftSuper, @ref KeyEvent::Key::RightSuper + */ + Super = KMOD_GUI, + + /** + * AltGr + * + * @see @ref KeyEvent::Key::AltGr + * @todo AltGr gets reported as RightAlt, what's this for? + */ + AltGr = KMOD_MODE, + + /** + * Caps lock + * + * @see @ref KeyEvent::Key::CapsLock + */ + CapsLock = KMOD_CAPS, + + /** + * Num lock + * + * @see @ref KeyEvent::Key::NumLock + */ + NumLock = KMOD_NUM +}; + +CORRADE_ENUMSET_OPERATORS(Sdl2Application::Modifiers) + +/** +@brief Key +@m_since_latest + +@see @ref KeyEvent::key() +*/ +enum class Sdl2Application::Key: SDL_Keycode { + Unknown = SDLK_UNKNOWN, /**< Unknown key */ + + /** + * Left Shift + * + * @see @ref InputEvent::Modifier::Shift + */ + LeftShift = SDLK_LSHIFT, + + /** + * Right Shift + * + * @see @ref InputEvent::Modifier::Shift + */ + RightShift = SDLK_RSHIFT, + + /** + * Left Ctrl + * + * @see @ref InputEvent::Modifier::Ctrl + */ + LeftCtrl = SDLK_LCTRL, + + /** + * Right Ctrl + * + * @see @ref InputEvent::Modifier::Ctrl + */ + RightCtrl = SDLK_RCTRL, + + /** + * Left Alt + * + * @see @ref InputEvent::Modifier::Alt + */ + LeftAlt = SDLK_LALT, + + /** + * Right Alt + * + * @see @ref InputEvent::Modifier::Alt + */ + RightAlt = SDLK_RALT, + + /** + * Left Super key (Windows/⌘) + * + * @see @ref InputEvent::Modifier::Super + */ + LeftSuper = SDLK_LGUI, + + /** + * Right Super key (Windows/⌘) + * + * @see @ref InputEvent::Modifier::Super + */ + RightSuper = SDLK_RGUI, + + /** + * AltGr + * + * @see @ref InputEvent::Modifier::AltGr + * @todo AltGr gets reported as RightAlt, what's this for? + */ + AltGr = SDLK_MODE, + + Enter = SDLK_RETURN, /**< Enter */ + Esc = SDLK_ESCAPE, /**< Escape */ + + Up = SDLK_UP, /**< Up arrow */ + Down = SDLK_DOWN, /**< Down arrow */ + Left = SDLK_LEFT, /**< Left arrow */ + Right = SDLK_RIGHT, /**< Right arrow */ + Home = SDLK_HOME, /**< Home */ + End = SDLK_END, /**< End */ + PageUp = SDLK_PAGEUP, /**< Page up */ + PageDown = SDLK_PAGEDOWN, /**< Page down */ + Backspace = SDLK_BACKSPACE, /**< Backspace */ + Insert = SDLK_INSERT, /**< Insert */ + Delete = SDLK_DELETE, /**< Delete */ + + F1 = SDLK_F1, /**< F1 */ + F2 = SDLK_F2, /**< F2 */ + F3 = SDLK_F3, /**< F3 */ + F4 = SDLK_F4, /**< F4 */ + F5 = SDLK_F5, /**< F5 */ + F6 = SDLK_F6, /**< F6 */ + F7 = SDLK_F7, /**< F7 */ + F8 = SDLK_F8, /**< F8 */ + F9 = SDLK_F9, /**< F9 */ + F10 = SDLK_F10, /**< F10 */ + F11 = SDLK_F11, /**< F11 */ + F12 = SDLK_F12, /**< F12 */ + + Space = SDLK_SPACE, /**< Space */ + Tab = SDLK_TAB, /**< Tab */ + + /** + * Quote (') + * @m_since{2020,06} + */ + Quote = SDLK_QUOTE, + + Comma = SDLK_COMMA, /**< Comma */ + Period = SDLK_PERIOD, /**< Period */ + Minus = SDLK_MINUS, /**< Minus */ + + /** + * Plus. On the US keyboard layout this may only be representable as + * @m_class{m-label m-warning} **Shift** @m_class{m-label m-default} **=**. + */ + Plus = SDLK_PLUS, + + Slash = SDLK_SLASH, /**< Slash */ + + /** + * Percent. On the US keyboard layout this may only be representable as + * @m_class{m-label m-warning} **Shift** @m_class{m-label m-default} **5**. + */ + Percent = SDLK_PERCENT, + + Semicolon = SDLK_SEMICOLON, /**< Semicolon (`;`) */ + Equal = SDLK_EQUALS, /**< Equal */ + + /** + * Left bracket (`[`) + * @m_since{2020,06} + */ + LeftBracket = SDLK_LEFTBRACKET, + + /** + * Right bracket (`]`) + * @m_since{2020,06} + */ + RightBracket = SDLK_RIGHTBRACKET, + + /** + * Backslash (`\`) + * @m_since{2020,06} + */ + Backslash = SDLK_BACKSLASH, + + /** + * Backquote (`) + * @m_since{2020,06} + */ + Backquote = SDLK_BACKQUOTE, + + /* no equivalent for GlfwApplication's World1 / World2 */ + + Zero = SDLK_0, /**< Zero */ + One = SDLK_1, /**< One */ + Two = SDLK_2, /**< Two */ + Three = SDLK_3, /**< Three */ + Four = SDLK_4, /**< Four */ + Five = SDLK_5, /**< Five */ + Six = SDLK_6, /**< Six */ + Seven = SDLK_7, /**< Seven */ + Eight = SDLK_8, /**< Eight */ + Nine = SDLK_9, /**< Nine */ + + A = SDLK_a, /**< Letter A */ + B = SDLK_b, /**< Letter B */ + C = SDLK_c, /**< Letter C */ + D = SDLK_d, /**< Letter D */ + E = SDLK_e, /**< Letter E */ + F = SDLK_f, /**< Letter F */ + G = SDLK_g, /**< Letter G */ + H = SDLK_h, /**< Letter H */ + I = SDLK_i, /**< Letter I */ + J = SDLK_j, /**< Letter J */ + K = SDLK_k, /**< Letter K */ + L = SDLK_l, /**< Letter L */ + M = SDLK_m, /**< Letter M */ + N = SDLK_n, /**< Letter N */ + O = SDLK_o, /**< Letter O */ + P = SDLK_p, /**< Letter P */ + Q = SDLK_q, /**< Letter Q */ + R = SDLK_r, /**< Letter R */ + S = SDLK_s, /**< Letter S */ + T = SDLK_t, /**< Letter T */ + U = SDLK_u, /**< Letter U */ + V = SDLK_v, /**< Letter V */ + W = SDLK_w, /**< Letter W */ + X = SDLK_x, /**< Letter X */ + Y = SDLK_y, /**< Letter Y */ + Z = SDLK_z, /**< Letter Z */ + + /** + * Caps lock + * + * @see @ref InputEvent::Modifier::CapsLock + * @m_since_latest + */ + CapsLock = SDLK_CAPSLOCK, + + /** + * Scroll lock + * @m_since_latest + */ + ScrollLock = SDLK_SCROLLLOCK, + + /** + * Num lock + * + * @see @ref InputEvent::Modifier::NumLock + * @m_since_latest + */ + NumLock = SDLK_NUMLOCKCLEAR, + + /** + * Print screen + * @m_since_latest + */ + PrintScreen = SDLK_PRINTSCREEN, + + /** + * Pause + * @m_since_latest + */ + Pause = SDLK_PAUSE, + + /** + * Menu + * @m_since_latest + */ + Menu = SDLK_APPLICATION, + + NumZero = SDLK_KP_0, /**< Numpad zero */ + NumOne = SDLK_KP_1, /**< Numpad one */ + NumTwo = SDLK_KP_2, /**< Numpad two */ + NumThree = SDLK_KP_3, /**< Numpad three */ + NumFour = SDLK_KP_4, /**< Numpad four */ + NumFive = SDLK_KP_5, /**< Numpad five */ + NumSix = SDLK_KP_6, /**< Numpad six */ + NumSeven = SDLK_KP_7, /**< Numpad seven */ + NumEight = SDLK_KP_8, /**< Numpad eight */ + NumNine = SDLK_KP_9, /**< Numpad nine */ + NumDecimal = SDLK_KP_DECIMAL, /**< Numpad decimal */ + NumDivide = SDLK_KP_DIVIDE, /**< Numpad divide */ + NumMultiply = SDLK_KP_MULTIPLY, /**< Numpad multiply */ + NumSubtract = SDLK_KP_MINUS, /**< Numpad subtract */ + NumAdd = SDLK_KP_PLUS, /**< Numpad add */ + NumEnter = SDLK_KP_ENTER, /**< Numpad enter */ + NumEqual = SDLK_KP_EQUALS /**< Numpad equal */ +}; + /** @brief Pointer event source @m_since_latest @@ -2363,74 +2691,21 @@ class Sdl2Application::ViewportEvent { */ class Sdl2Application::InputEvent { public: + #ifdef MAGNUM_BUILD_DEPRECATED /** - * @brief Modifier - * - * @see @ref Modifiers, @ref KeyEvent::modifiers(), - * @ref PointerEvent::modifiers(), - * @ref PointerMoveEvent::modifiers(), - * @ref ScrollEvent::modifiers() + * @brief @copybrief Sdl2Application::Modifier + * @m_deprecated_since_latest Use @ref Sdl2Application::Modifier + * instead. */ - enum class Modifier: Uint16 { - /** - * Shift - * - * @see @ref KeyEvent::Key::LeftShift, @ref KeyEvent::Key::RightShift - */ - Shift = KMOD_SHIFT, - - /** - * Ctrl - * - * @see @ref KeyEvent::Key::LeftCtrl, @ref KeyEvent::Key::RightCtrl - */ - Ctrl = KMOD_CTRL, - - /** - * Alt - * - * @see @ref KeyEvent::Key::LeftAlt, @ref KeyEvent::Key::RightAlt - */ - Alt = KMOD_ALT, - - /** - * Super key (Windows/⌘) - * - * @see @ref KeyEvent::Key::LeftSuper, @ref KeyEvent::Key::RightSuper - */ - Super = KMOD_GUI, - - /** - * AltGr - * - * @see @ref KeyEvent::Key::AltGr - * @todo AltGr gets reported as RightAlt, what's this for? - */ - AltGr = KMOD_MODE, - - /** - * Caps lock - * - * @see @ref KeyEvent::Key::CapsLock - */ - CapsLock = KMOD_CAPS, - - /** - * Num lock - * - * @see @ref KeyEvent::Key::NumLock - */ - NumLock = KMOD_NUM - }; + typedef CORRADE_DEPRECATED("use Sdl2Application::Modifier instead") Sdl2Application::Modifier Modifier; /** - * @brief Set of modifiers - * - * @see @ref KeyEvent::modifiers(), @ref PointerEvent::modifiers(), - * @ref PointerMoveEvent::modifiers(), - * @ref ScrollEvent::modifiers() + * @brief @copybrief Sdl2Application::Modifiers + * @m_deprecated_since_latest Use @ref Sdl2Application::Modifiers + * instead. */ - typedef Containers::EnumSet Modifiers; + typedef CORRADE_DEPRECATED("use Sdl2Application::Modifiers instead") Sdl2Application::Modifiers Modifiers; + #endif /** @brief Copying is not allowed */ InputEvent(const InputEvent&) = delete; @@ -2488,260 +2763,13 @@ class Sdl2Application::InputEvent { */ class Sdl2Application::KeyEvent: public Sdl2Application::InputEvent { public: + #ifdef MAGNUM_BUILD_DEPRECATED /** - * @brief Key - * - * @see @ref key() + * @brief @copybrief Sdl2Application::Key + * @m_deprecated_since_latest Use @ref Sdl2Application::Key instead. */ - enum class Key: SDL_Keycode { - Unknown = SDLK_UNKNOWN, /**< Unknown key */ - - /** - * Left Shift - * - * @see @ref InputEvent::Modifier::Shift - */ - LeftShift = SDLK_LSHIFT, - - /** - * Right Shift - * - * @see @ref InputEvent::Modifier::Shift - */ - RightShift = SDLK_RSHIFT, - - /** - * Left Ctrl - * - * @see @ref InputEvent::Modifier::Ctrl - */ - LeftCtrl = SDLK_LCTRL, - - /** - * Right Ctrl - * - * @see @ref InputEvent::Modifier::Ctrl - */ - RightCtrl = SDLK_RCTRL, - - /** - * Left Alt - * - * @see @ref InputEvent::Modifier::Alt - */ - LeftAlt = SDLK_LALT, - - /** - * Right Alt - * - * @see @ref InputEvent::Modifier::Alt - */ - RightAlt = SDLK_RALT, - - /** - * Left Super key (Windows/⌘) - * - * @see @ref InputEvent::Modifier::Super - */ - LeftSuper = SDLK_LGUI, - - /** - * Right Super key (Windows/⌘) - * - * @see @ref InputEvent::Modifier::Super - */ - RightSuper = SDLK_RGUI, - - /** - * AltGr - * - * @see @ref InputEvent::Modifier::AltGr - * @todo AltGr gets reported as RightAlt, what's this for? - */ - AltGr = SDLK_MODE, - - Enter = SDLK_RETURN, /**< Enter */ - Esc = SDLK_ESCAPE, /**< Escape */ - - Up = SDLK_UP, /**< Up arrow */ - Down = SDLK_DOWN, /**< Down arrow */ - Left = SDLK_LEFT, /**< Left arrow */ - Right = SDLK_RIGHT, /**< Right arrow */ - Home = SDLK_HOME, /**< Home */ - End = SDLK_END, /**< End */ - PageUp = SDLK_PAGEUP, /**< Page up */ - PageDown = SDLK_PAGEDOWN, /**< Page down */ - Backspace = SDLK_BACKSPACE, /**< Backspace */ - Insert = SDLK_INSERT, /**< Insert */ - Delete = SDLK_DELETE, /**< Delete */ - - F1 = SDLK_F1, /**< F1 */ - F2 = SDLK_F2, /**< F2 */ - F3 = SDLK_F3, /**< F3 */ - F4 = SDLK_F4, /**< F4 */ - F5 = SDLK_F5, /**< F5 */ - F6 = SDLK_F6, /**< F6 */ - F7 = SDLK_F7, /**< F7 */ - F8 = SDLK_F8, /**< F8 */ - F9 = SDLK_F9, /**< F9 */ - F10 = SDLK_F10, /**< F10 */ - F11 = SDLK_F11, /**< F11 */ - F12 = SDLK_F12, /**< F12 */ - - Space = SDLK_SPACE, /**< Space */ - Tab = SDLK_TAB, /**< Tab */ - - /** - * Quote (') - * @m_since{2020,06} - */ - Quote = SDLK_QUOTE, - - Comma = SDLK_COMMA, /**< Comma */ - Period = SDLK_PERIOD, /**< Period */ - Minus = SDLK_MINUS, /**< Minus */ - - /** - * Plus. On the US keyboard layout this may only be representable - * as @m_class{m-label m-warning} **Shift** - * @m_class{m-label m-default} **=**. - */ - Plus = SDLK_PLUS, - - Slash = SDLK_SLASH, /**< Slash */ - - /** - * Percent. On the US keyboard layout this may only be - * representable as @m_class{m-label m-warning} **Shift** - * @m_class{m-label m-default} **5**. - */ - Percent = SDLK_PERCENT, - - Semicolon = SDLK_SEMICOLON, /**< Semicolon (`;`) */ - Equal = SDLK_EQUALS, /**< Equal */ - - /** - * Left bracket (`[`) - * @m_since{2020,06} - */ - LeftBracket = SDLK_LEFTBRACKET, - - /** - * Right bracket (`]`) - * @m_since{2020,06} - */ - RightBracket = SDLK_RIGHTBRACKET, - - /** - * Backslash (`\`) - * @m_since{2020,06} - */ - Backslash = SDLK_BACKSLASH, - - /** - * Backquote (`) - * @m_since{2020,06} - */ - Backquote = SDLK_BACKQUOTE, - - /* no equivalent for GlfwApplication's World1 / World2 */ - - Zero = SDLK_0, /**< Zero */ - One = SDLK_1, /**< One */ - Two = SDLK_2, /**< Two */ - Three = SDLK_3, /**< Three */ - Four = SDLK_4, /**< Four */ - Five = SDLK_5, /**< Five */ - Six = SDLK_6, /**< Six */ - Seven = SDLK_7, /**< Seven */ - Eight = SDLK_8, /**< Eight */ - Nine = SDLK_9, /**< Nine */ - - A = SDLK_a, /**< Letter A */ - B = SDLK_b, /**< Letter B */ - C = SDLK_c, /**< Letter C */ - D = SDLK_d, /**< Letter D */ - E = SDLK_e, /**< Letter E */ - F = SDLK_f, /**< Letter F */ - G = SDLK_g, /**< Letter G */ - H = SDLK_h, /**< Letter H */ - I = SDLK_i, /**< Letter I */ - J = SDLK_j, /**< Letter J */ - K = SDLK_k, /**< Letter K */ - L = SDLK_l, /**< Letter L */ - M = SDLK_m, /**< Letter M */ - N = SDLK_n, /**< Letter N */ - O = SDLK_o, /**< Letter O */ - P = SDLK_p, /**< Letter P */ - Q = SDLK_q, /**< Letter Q */ - R = SDLK_r, /**< Letter R */ - S = SDLK_s, /**< Letter S */ - T = SDLK_t, /**< Letter T */ - U = SDLK_u, /**< Letter U */ - V = SDLK_v, /**< Letter V */ - W = SDLK_w, /**< Letter W */ - X = SDLK_x, /**< Letter X */ - Y = SDLK_y, /**< Letter Y */ - Z = SDLK_z, /**< Letter Z */ - - /** - * Caps lock - * - * @see @ref InputEvent::Modifier::CapsLock - * @m_since_latest - */ - CapsLock = SDLK_CAPSLOCK, - - /** - * Scroll lock - * @m_since_latest - */ - ScrollLock = SDLK_SCROLLLOCK, - - /** - * Num lock - * - * @see @ref InputEvent::Modifier::NumLock - * @m_since_latest - */ - NumLock = SDLK_NUMLOCKCLEAR, - - /** - * Print screen - * @m_since_latest - */ - PrintScreen = SDLK_PRINTSCREEN, - - /** - * Pause - * @m_since_latest - */ - Pause = SDLK_PAUSE, - - /** - * Menu - * @m_since_latest - */ - Menu = SDLK_APPLICATION, - - NumZero = SDLK_KP_0, /**< Numpad zero */ - NumOne = SDLK_KP_1, /**< Numpad one */ - NumTwo = SDLK_KP_2, /**< Numpad two */ - NumThree = SDLK_KP_3, /**< Numpad three */ - NumFour = SDLK_KP_4, /**< Numpad four */ - NumFive = SDLK_KP_5, /**< Numpad five */ - NumSix = SDLK_KP_6, /**< Numpad six */ - NumSeven = SDLK_KP_7, /**< Numpad seven */ - NumEight = SDLK_KP_8, /**< Numpad eight */ - NumNine = SDLK_KP_9, /**< Numpad nine */ - NumDecimal = SDLK_KP_DECIMAL, /**< Numpad decimal */ - NumDivide = SDLK_KP_DIVIDE, /**< Numpad divide */ - NumMultiply = SDLK_KP_MULTIPLY, /**< Numpad multiply */ - NumSubtract = SDLK_KP_MINUS, /**< Numpad subtract */ - NumAdd = SDLK_KP_PLUS, /**< Numpad add */ - NumEnter = SDLK_KP_ENTER, /**< Numpad enter */ - NumEqual = SDLK_KP_EQUALS /**< Numpad equal */ - }; + typedef CORRADE_DEPRECATED("use Sdl2Application::Key instead") Sdl2Application::Key Key; + #endif /** * @brief Name for given key @@ -2754,14 +2782,14 @@ class Sdl2Application::KeyEvent: public Sdl2Application::InputEvent { * @ref keyName() const or to the underlying @cpp SDL_GetKeyName() @ce * API. */ - static Containers::StringView keyName(Key key); + static Containers::StringView keyName(Sdl2Application::Key key); /** * @brief Key * * @see @ref keyName() */ - Key key() const { return _key; } + Sdl2Application::Key key() const { return _key; } /** * @brief Key name @@ -2777,7 +2805,7 @@ class Sdl2Application::KeyEvent: public Sdl2Application::InputEvent { Containers::StringView keyName() const; /** @brief Modifiers */ - Modifiers modifiers() const { return _modifiers; } + Sdl2Application::Modifiers modifiers() const { return _modifiers; } /** * @brief Whether the key press is repeated @@ -2790,10 +2818,10 @@ class Sdl2Application::KeyEvent: public Sdl2Application::InputEvent { private: friend Sdl2Application; - explicit KeyEvent(const SDL_Event& event, Key key, Modifiers modifiers, bool repeated): InputEvent{event}, _key{key}, _modifiers{modifiers}, _repeated{repeated} {} + explicit KeyEvent(const SDL_Event& event, Sdl2Application::Key key, Sdl2Application::Modifiers modifiers, bool repeated): InputEvent{event}, _key{key}, _modifiers{modifiers}, _repeated{repeated} {} - const Key _key; - const Modifiers _modifiers; + const Sdl2Application::Key _key; + const Sdl2Application::Modifiers _modifiers; const bool _repeated; }; @@ -2869,7 +2897,7 @@ class Sdl2Application::PointerEvent: public InputEvent { * * Lazily populated on first request. */ - Modifiers modifiers(); + Sdl2Application::Modifiers modifiers(); private: friend Sdl2Application; @@ -2886,7 +2914,7 @@ class Sdl2Application::PointerEvent: public InputEvent { const PointerEventSource _source; const Pointer _pointer; - Containers::Optional _modifiers; + Containers::Optional _modifiers; const bool _primary; const Long _id; const Vector2 _position; @@ -2944,7 +2972,7 @@ class CORRADE_DEPRECATED("use PointerEvent, pointerPressEvent() and pointerRelea * * Lazily populated on first request. */ - Modifiers modifiers(); + Sdl2Application::Modifiers modifiers(); private: friend Sdl2Application; @@ -2964,7 +2992,7 @@ class CORRADE_DEPRECATED("use PointerEvent, pointerPressEvent() and pointerRelea #ifndef CORRADE_TARGET_EMSCRIPTEN const Int _clickCount; #endif - Containers::Optional _modifiers; + Containers::Optional _modifiers; }; #endif @@ -3065,7 +3093,7 @@ class Sdl2Application::PointerMoveEvent: public InputEvent { * * Lazily populated on first request. */ - Modifiers modifiers(); + Sdl2Application::Modifiers modifiers(); private: friend Sdl2Application; @@ -3076,7 +3104,7 @@ class Sdl2Application::PointerMoveEvent: public InputEvent { const Containers::Optional _pointer; const Pointers _pointers; const bool _primary; - Containers::Optional _modifiers; + Containers::Optional _modifiers; const Long _id; const Vector2 _position, _relativePosition; }; @@ -3134,7 +3162,7 @@ class CORRADE_DEPRECATED("use PointerMoveEvent and pointerMoveEvent() instead") * * Lazily populated on first request. */ - Modifiers modifiers(); + Sdl2Application::Modifiers modifiers(); private: friend Sdl2Application; @@ -3143,7 +3171,7 @@ class CORRADE_DEPRECATED("use PointerMoveEvent and pointerMoveEvent() instead") const Vector2i _position, _relativePosition; const Buttons _buttons; - Containers::Optional _modifiers; + Containers::Optional _modifiers; }; CORRADE_IGNORE_DEPRECATED_PUSH @@ -3175,7 +3203,7 @@ class Sdl2Application::ScrollEvent: public Sdl2Application::InputEvent { * * Lazily populated on first request. */ - Modifiers modifiers(); + Sdl2Application::Modifiers modifiers(); private: friend Sdl2Application; @@ -3184,7 +3212,7 @@ class Sdl2Application::ScrollEvent: public Sdl2Application::InputEvent { const Vector2 _offset; Containers::Optional _position; - Containers::Optional _modifiers; + Containers::Optional _modifiers; }; #ifdef MAGNUM_BUILD_DEPRECATED @@ -3212,7 +3240,7 @@ class CORRADE_DEPRECATED("use ScrollEvent and scrollEvent() instead") Sdl2Applic * * Lazily populated on first request. */ - Modifiers modifiers(); + Sdl2Application::Modifiers modifiers(); private: friend Sdl2Application; @@ -3221,7 +3249,7 @@ class CORRADE_DEPRECATED("use ScrollEvent and scrollEvent() instead") Sdl2Applic const Vector2 _offset; Containers::Optional _position; - Containers::Optional _modifiers; + Containers::Optional _modifiers; }; #endif @@ -3483,7 +3511,6 @@ typedef BasicScreenedApplication ScreenedApplication; #endif CORRADE_ENUMSET_OPERATORS(Sdl2Application::Configuration::WindowFlags) -CORRADE_ENUMSET_OPERATORS(Sdl2Application::InputEvent::Modifiers) }} diff --git a/src/Magnum/Platform/Test/AbstractXApplicationTest.cpp b/src/Magnum/Platform/Test/AbstractXApplicationTest.cpp index de6d777d1..2fa86768d 100644 --- a/src/Magnum/Platform/Test/AbstractXApplicationTest.cpp +++ b/src/Magnum/Platform/Test/AbstractXApplicationTest.cpp @@ -40,11 +40,11 @@ namespace Magnum { namespace Platform { /* These cannot be in an anonymous namespace as enumSetDebugOutput() below wouldn't be able to pick them up */ -static Debug& operator<<(Debug& debug, Application::InputEvent::Modifier value) { +static Debug& operator<<(Debug& debug, Application::Modifier value) { debug << "Modifier" << Debug::nospace; switch(value) { - #define _c(value) case Application::InputEvent::Modifier::value: return debug << "::" #value; + #define _c(value) case Application::Modifier::value: return debug << "::" #value; _c(Shift) _c(Ctrl) _c(Alt) @@ -91,14 +91,14 @@ CORRADE_IGNORE_DEPRECATED_POP namespace Test { namespace { -Debug& operator<<(Debug& debug, Application::InputEvent::Modifiers value) { +Debug& operator<<(Debug& debug, Application::Modifiers value) { return Containers::enumSetDebugOutput(debug, value, "Modifiers{}", { - Application::InputEvent::Modifier::Shift, - Application::InputEvent::Modifier::Ctrl, - Application::InputEvent::Modifier::Alt, - Application::InputEvent::Modifier::AltGr, - Application::InputEvent::Modifier::CapsLock, - Application::InputEvent::Modifier::NumLock, + Application::Modifier::Shift, + Application::Modifier::Ctrl, + Application::Modifier::Alt, + Application::Modifier::AltGr, + Application::Modifier::CapsLock, + Application::Modifier::NumLock, }); } @@ -139,11 +139,11 @@ CORRADE_UNUSED Debug& operator<<(Debug& debug, Application::MouseMoveEvent::Butt CORRADE_IGNORE_DEPRECATED_POP #endif -Debug& operator<<(Debug& debug, const Application::KeyEvent::Key value) { +Debug& operator<<(Debug& debug, const Application::Key value) { debug << "Key" << Debug::nospace; switch(value) { - #define _c(value) case Application::KeyEvent::Key::value: return debug << "::" #value; + #define _c(value) case Application::Key::value: return debug << "::" #value; _c(LeftShift) _c(RightShift) _c(LeftCtrl) diff --git a/src/Magnum/Platform/Test/EmscriptenApplicationTest.cpp b/src/Magnum/Platform/Test/EmscriptenApplicationTest.cpp index 8239f317b..334bda353 100644 --- a/src/Magnum/Platform/Test/EmscriptenApplicationTest.cpp +++ b/src/Magnum/Platform/Test/EmscriptenApplicationTest.cpp @@ -51,11 +51,11 @@ namespace Magnum { namespace Platform { /* These cannot be in an anonymous namespace as enumSetDebugOutput() below wouldn't be able to pick them up */ -static Debug& operator<<(Debug& debug, Application::InputEvent::Modifier value) { +static Debug& operator<<(Debug& debug, Application::Modifier value) { debug << "Modifier" << Debug::nospace; switch(value) { - #define _c(value) case Application::InputEvent::Modifier::value: return debug << "::" #value; + #define _c(value) case Application::Modifier::value: return debug << "::" #value; _c(Shift) _c(Ctrl) _c(Alt) @@ -120,12 +120,12 @@ static Debug& operator<<(Debug& debug, Application::PointerEventSource value) { return debug << "(" << Debug::nospace << UnsignedInt(value) << Debug::nospace << ")"; } -Debug& operator<<(Debug& debug, Application::InputEvent::Modifiers value) { +Debug& operator<<(Debug& debug, Application::Modifiers value) { return Containers::enumSetDebugOutput(debug, value, "Modifiers{}", { - Application::InputEvent::Modifier::Shift, - Application::InputEvent::Modifier::Ctrl, - Application::InputEvent::Modifier::Alt, - Application::InputEvent::Modifier::Super + Application::Modifier::Shift, + Application::Modifier::Ctrl, + Application::Modifier::Alt, + Application::Modifier::Super }); } @@ -168,11 +168,11 @@ CORRADE_UNUSED Debug& operator<<(Debug& debug, Application::MouseMoveEvent::Butt CORRADE_IGNORE_DEPRECATED_POP #endif -Debug& operator<<(Debug& debug, const Application::KeyEvent::Key value) { +Debug& operator<<(Debug& debug, const Application::Key value) { debug << "Key" << Debug::nospace; switch(value) { - #define _c(value) case Application::KeyEvent::Key::value: return debug << "::" #value; + #define _c(value) case Application::Key::value: return debug << "::" #value; _c(Unknown) _c(LeftShift) _c(RightShift) @@ -370,23 +370,23 @@ struct EmscriptenApplicationTest: Platform::Application { void keyPressEvent(KeyEvent& event) override { Debug{} << "key press:" << event.key() << event.keyName() << event.modifiers(); - if(event.key() == KeyEvent::Key::F1) { + if(event.key() == Key::F1) { Debug{} << "starting text input"; startTextInput(); - } else if(event.key() == KeyEvent::Key::F2) { + } else if(event.key() == Key::F2) { _redraw = !_redraw; Debug{} << "redrawing" << (_redraw ? "enabled" : "disabled"); if(_redraw) redraw(); - } else if(event.key() == KeyEvent::Key::Esc) { + } else if(event.key() == Key::Esc) { Debug{} << "stopping text input"; stopTextInput(); - } else if(event.key() == KeyEvent::Key::F) { + } else if(event.key() == Key::F) { Debug{} << "toggling fullscreen"; setContainerCssClass((_fullscreen ^= true) ? "mn-fullsizeX"_s.exceptSuffix(1) : ""); - } else if(event.key() == KeyEvent::Key::T) { + } else if(event.key() == Key::T) { Debug{} << "setting window title"; setWindowTitle("This is a UTF-8 Window Title™ and it should have no exclamation mark!!"_s.exceptSuffix(2)); - } else if(event.key() == KeyEvent::Key::H) { + } else if(event.key() == Key::H) { Debug{} << "toggling hand cursor"; setCursor(cursor() == Cursor::Arrow ? Cursor::Hand : Cursor::Arrow); } diff --git a/src/Magnum/Platform/Test/GlfwApplicationTest.cpp b/src/Magnum/Platform/Test/GlfwApplicationTest.cpp index 0b2390146..781ca7717 100644 --- a/src/Magnum/Platform/Test/GlfwApplicationTest.cpp +++ b/src/Magnum/Platform/Test/GlfwApplicationTest.cpp @@ -42,11 +42,11 @@ namespace Magnum { namespace Platform { /* These cannot be in an anonymous namespace as enumSetDebugOutput() below wouldn't be able to pick them up */ -static Debug& operator<<(Debug& debug, Application::InputEvent::Modifier value) { +static Debug& operator<<(Debug& debug, Application::Modifier value) { debug << "Modifier" << Debug::nospace; switch(value) { - #define _c(value) case Application::InputEvent::Modifier::value: return debug << "::" #value; + #define _c(value) case Application::Modifier::value: return debug << "::" #value; _c(Shift) _c(Ctrl) _c(Alt) @@ -96,12 +96,12 @@ CORRADE_IGNORE_DEPRECATED_POP namespace Test { namespace { -Debug& operator<<(Debug& debug, Application::InputEvent::Modifiers value) { +Debug& operator<<(Debug& debug, Application::Modifiers value) { return Containers::enumSetDebugOutput(debug, value, "Modifiers{}", { - Application::InputEvent::Modifier::Shift, - Application::InputEvent::Modifier::Ctrl, - Application::InputEvent::Modifier::Alt, - Application::InputEvent::Modifier::Super + Application::Modifier::Shift, + Application::Modifier::Ctrl, + Application::Modifier::Alt, + Application::Modifier::Super }); } @@ -149,11 +149,11 @@ CORRADE_UNUSED Debug& operator<<(Debug& debug, Application::MouseMoveEvent::Butt CORRADE_IGNORE_DEPRECATED_POP #endif -Debug& operator<<(Debug& debug, const Application::KeyEvent::Key value) { +Debug& operator<<(Debug& debug, const Application::Key value) { debug << "Key" << Debug::nospace; switch(value) { - #define _c(value) case Application::KeyEvent::Key::value: return debug << "::" #value; + #define _c(value) case Application::Key::value: return debug << "::" #value; _c(Unknown) _c(LeftShift) _c(RightShift) @@ -301,36 +301,36 @@ struct GlfwApplicationTest: Platform::Application { void keyPressEvent(KeyEvent& event) override { Debug{} << "key press:" << event.key() << int(event.key()) << event.keyName() << event.modifiers(); - if(event.key() == KeyEvent::Key::F1) { + if(event.key() == Key::F1) { Debug{} << "starting text input"; startTextInput(); - } else if(event.key() == KeyEvent::Key::F2) { + } else if(event.key() == Key::F2) { _redraw = !_redraw; Debug{} << "redrawing" << (_redraw ? "enabled" : "disabled"); if(_redraw) redraw(); - } else if(event.key() == KeyEvent::Key::V) { + } else if(event.key() == Key::V) { _vsync = !_vsync; Debug{} << "vsync" << (_vsync? "on" : "off"); setSwapInterval(_vsync ? 1 : 0); - } else if(event.key() == KeyEvent::Key::Esc) { + } else if(event.key() == Key::Esc) { Debug{} << "stopping text input"; stopTextInput(); - } else if(event.key() == KeyEvent::Key::T) { + } else if(event.key() == Key::T) { Debug{} << "setting window title"; setWindowTitle("This is a UTF-8 Window Title™ and it should have no exclamation mark!!"_s.exceptSuffix(2)); - } else if(event.key() == KeyEvent::Key::S) { + } else if(event.key() == Key::S) { Debug{} << "setting window size, which should trigger a viewport event"; setWindowSize(Vector2i{300, 200}); - } else if(event.key() == KeyEvent::Key::W) { + } else if(event.key() == Key::W) { Debug{} << "setting max window size, which should trigger a viewport event if the size changes"; setMaxWindowSize(Vector2i{700, 500}); - } else if(event.key() == KeyEvent::Key::H) { + } else if(event.key() == Key::H) { Debug{} << "toggling hand cursor"; setCursor(cursor() == Cursor::Arrow ? Cursor::Hand : Cursor::Arrow); - } else if(event.key() == KeyEvent::Key::L) { + } else if(event.key() == Key::L) { Debug{} << "toggling locked mouse"; setCursor(cursor() == Cursor::Arrow ? Cursor::HiddenLocked : Cursor::Arrow); - } else if(event.key() == KeyEvent::Key::X) { + } else if(event.key() == Key::X) { Debug{} << "requesting an exit with code 5"; exit(5); } diff --git a/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp b/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp index ed7ecf5be..4e70faf1e 100644 --- a/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp +++ b/src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp @@ -59,11 +59,11 @@ namespace Magnum { namespace Platform { /* These cannot be in an anonymous namespace as enumSetDebugOutput() below wouldn't be able to pick them up */ -static Debug& operator<<(Debug& debug, Application::InputEvent::Modifier value) { +static Debug& operator<<(Debug& debug, Application::Modifier value) { debug << "Modifier" << Debug::nospace; switch(value) { - #define _c(value) case Application::InputEvent::Modifier::value: return debug << "::" #value; + #define _c(value) case Application::Modifier::value: return debug << "::" #value; _c(Shift) _c(Ctrl) _c(Alt) @@ -133,15 +133,15 @@ static Debug& operator<<(Debug& debug, Application::PointerEventSource value) { return debug << "(" << Debug::nospace << UnsignedInt(value) << Debug::nospace << ")"; } -Debug& operator<<(Debug& debug, Application::InputEvent::Modifiers value) { +Debug& operator<<(Debug& debug, Application::Modifiers value) { return Containers::enumSetDebugOutput(debug, value, "Modifiers{}", { - Application::InputEvent::Modifier::Shift, - Application::InputEvent::Modifier::Ctrl, - Application::InputEvent::Modifier::Alt, - Application::InputEvent::Modifier::Super, - Application::InputEvent::Modifier::AltGr, - Application::InputEvent::Modifier::CapsLock, - Application::InputEvent::Modifier::NumLock, + Application::Modifier::Shift, + Application::Modifier::Ctrl, + Application::Modifier::Alt, + Application::Modifier::Super, + Application::Modifier::AltGr, + Application::Modifier::CapsLock, + Application::Modifier::NumLock, }); } @@ -188,11 +188,11 @@ CORRADE_UNUSED Debug& operator<<(Debug& debug, Application::MouseMoveEvent::Butt CORRADE_IGNORE_DEPRECATED_POP #endif -Debug& operator<<(Debug& debug, Application::KeyEvent::Key value) { +Debug& operator<<(Debug& debug, Application::Key value) { debug << "Key" << Debug::nospace; switch(value) { - #define _c(value) case Application::KeyEvent::Key::value: return debug << "::" #value; + #define _c(value) case Application::Key::value: return debug << "::" #value; _c(Unknown) _c(LeftShift) _c(RightShift) @@ -392,53 +392,53 @@ struct Sdl2ApplicationTest: Platform::Application { #endif << event.modifiers(); - if(event.key() == KeyEvent::Key::F1) { + if(event.key() == Key::F1) { Debug{} << "starting text input"; startTextInput(); - } else if(event.key() == KeyEvent::Key::F2) { + } else if(event.key() == Key::F2) { _redraw = !_redraw; Debug{} << "redrawing" << (_redraw ? "enabled" : "disabled"); if(_redraw) redraw(); } #ifndef CORRADE_TARGET_EMSCRIPTEN - else if(event.key() == KeyEvent::Key::V) { + else if(event.key() == Key::V) { _vsync = !_vsync; Debug{} << "vsync" << (_vsync? "on" : "off"); setSwapInterval(_vsync ? 1 : 0); } #endif - else if(event.key() == KeyEvent::Key::Esc) { + else if(event.key() == Key::Esc) { Debug{} << "stopping text input"; stopTextInput(); - } else if(event.key() == KeyEvent::Key::T) { + } else if(event.key() == Key::T) { Debug{} << "setting window title"; setWindowTitle("This is a UTF-8 Window Title™ and it should have no exclamation mark!!"_s.exceptSuffix(2)); } #ifndef CORRADE_TARGET_EMSCRIPTEN - else if(event.key() == KeyEvent::Key::S) { + else if(event.key() == Key::S) { Debug{} << "setting window size, which should trigger a viewport event"; setWindowSize(Vector2i{300, 200}); - } else if(event.key() == KeyEvent::Key::W) { + } else if(event.key() == Key::W) { Debug{} << "setting max window size, which should trigger a viewport event"; setMaxWindowSize(Vector2i{700, 500}); } #endif - else if(event.key() == KeyEvent::Key::H) { + else if(event.key() == Key::H) { Debug{} << "toggling hand cursor"; setCursor(cursor() == Cursor::Arrow ? Cursor::Hand : Cursor::Arrow); } #ifndef CORRADE_TARGET_EMSCRIPTEN - else if(event.key() == KeyEvent::Key::L) { + else if(event.key() == Key::L) { Debug{} << "toggling locked mouse"; setCursor(cursor() == Cursor::Arrow ? Cursor::HiddenLocked : Cursor::Arrow); } #else - else if(event.key() == KeyEvent::Key::F) { + else if(event.key() == Key::F) { Debug{} << "toggling fullscreen"; setContainerCssClass((_fullscreen ^= true) ? "mn-fullsize" : ""); } #endif - else if(event.key() == KeyEvent::Key::X) { + else if(event.key() == Key::X) { Debug{} << "requesting an exit with code 5"; exit(5); }