Browse Source

Platform: move Modifier and Key enums directly to the Application class.

There's the obvious advantage of them now being shorter to type, as one
no longer needs to prefix them with KeyEvent::. But the main reason I
did this was to allow various direct keyboard state queries to be
implemented, such as isKeyPressed(). With them being hidden in the event
class the only way would be to put the query directly there as well,
which isn't nice and is also not very discoverable.

A similar case was with mouse buttons, but that was already fixed with
the PointerEvent rework that happened in earlier commits. There the
additional complication was that MouseEvent::Button and
MouseMoveEvent::Button were incompatible enums. Application::Pointer
fixes that now as well.
pull/651/head
Vladimír Vondruš 2 years ago
parent
commit
14a7ecaf7f
  1. 9
      doc/changelog.dox
  2. 2
      src/Magnum/Platform/AbstractXApplication.cpp
  3. 799
      src/Magnum/Platform/AbstractXApplication.h
  4. 38
      src/Magnum/Platform/EmscriptenApplication.cpp
  5. 527
      src/Magnum/Platform/EmscriptenApplication.h
  6. 28
      src/Magnum/Platform/GlfwApplication.cpp
  7. 629
      src/Magnum/Platform/GlfwApplication.h
  8. 30
      src/Magnum/Platform/Screen.h
  9. 32
      src/Magnum/Platform/Sdl2Application.cpp
  10. 695
      src/Magnum/Platform/Sdl2Application.h
  11. 22
      src/Magnum/Platform/Test/AbstractXApplicationTest.cpp
  12. 30
      src/Magnum/Platform/Test/EmscriptenApplicationTest.cpp
  13. 38
      src/Magnum/Platform/Test/GlfwApplicationTest.cpp
  14. 46
      src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp

9
doc/changelog.dox

@ -1421,6 +1421,15 @@ See also:
@ref Platform::GlfwApplication and the @ref Platform::GlfwApplication and the
@ref Platform::BasicScreenedApplication / @ref Platform::BasicScreen @ref Platform::BasicScreenedApplication / @ref Platform::BasicScreen
wrappers as well. 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 - @cpp Platform::AbstractXApplication::MouseEvent::Button::WheelUp @ce and
`WheelDown` members are deprecated in favor of a dedicated `WheelDown` members are deprecated in favor of a dedicated
@ref Platform::AbstractXApplication::scrollEvent(). Similar change was done @ref Platform::AbstractXApplication::scrollEvent(). Similar change was done

2
src/Magnum/Platform/AbstractXApplication.cpp

@ -197,7 +197,7 @@ bool AbstractXApplication::mainLoopIteration() {
/* Key/mouse events */ /* Key/mouse events */
case KeyPress: case KeyPress:
case KeyRelease: { case KeyRelease: {
KeyEvent e(static_cast<KeyEvent::Key>(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); event.type == KeyPress ? keyPressEvent(e) : keyReleaseEvent(e);
} break; } break;
case ButtonPress: case ButtonPress:

799
src/Magnum/Platform/AbstractXApplication.h

@ -115,10 +115,20 @@ class AbstractXApplication {
/* The damn thing cannot handle forward enum declarations */ /* The damn thing cannot handle forward enum declarations */
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
enum class Modifier: unsigned int;
enum class Key: KeySym;
enum class PointerEventSource: UnsignedByte; enum class PointerEventSource: UnsignedByte;
enum class Pointer: UnsignedByte; enum class Pointer: UnsignedByte;
#endif #endif
/**
* @brief Set of keyboard modifiers
* @m_since_latest
*
* @see @ref InputEvent::modifiers()
*/
typedef Containers::EnumSet<Modifier> Modifiers;
/** /**
* @brief Set of pointer types * @brief Set of pointer types
* @m_since_latest * @m_since_latest
@ -454,6 +464,389 @@ class AbstractXApplication {
Flags _flags; 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 (<tt>'</tt>)
* @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 (<tt>`</tt>)
* @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 @brief Pointer event source
@m_since_latest @m_since_latest
@ -717,59 +1110,21 @@ class AbstractXApplication::ViewportEvent {
*/ */
class AbstractXApplication::InputEvent { class AbstractXApplication::InputEvent {
public: public:
#ifdef MAGNUM_BUILD_DEPRECATED
/** /**
* @brief Modifier * @brief @copybrief AbstractXApplication::Modifier
* * @m_deprecated_since_latest Use @ref AbstractXApplication::Modifier
* @see @ref Modifiers, @ref modifiers() * instead.
*/ */
enum class Modifier: unsigned int { typedef CORRADE_DEPRECATED("use AbstractXApplication::Modifier instead") AbstractXApplication::Modifier Modifier;
/**
* 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
};
/** /**
* @brief Set of modifiers * @brief @copybrief AbstractXApplication::Modifiers
* * @m_deprecated_since_latest Use @ref AbstractXApplication::Modifiers
* @see @ref modifiers() * instead.
*/ */
typedef Containers::EnumSet<Modifier> Modifiers; typedef CORRADE_DEPRECATED("use AbstractXApplication::Modifiers instead") AbstractXApplication::Modifiers Modifiers;
#ifdef MAGNUM_BUILD_DEPRECATED
/** /**
* @brief Mouse button * @brief Mouse button
* @m_deprecated_since_latest Use @ref Pointer instead. * @m_deprecated_since_latest Use @ref Pointer instead.
@ -808,8 +1163,8 @@ class AbstractXApplication::InputEvent {
bool isAccepted() const { return _accepted; } bool isAccepted() const { return _accepted; }
/** @brief Modifiers */ /** @brief Modifiers */
Modifiers modifiers() const { AbstractXApplication::Modifiers modifiers() const {
return Modifiers(_modifiers & (ShiftMask|ControlMask|Mod1Mask|Mod5Mask|LockMask|Mod2Mask)); return AbstractXApplication::Modifiers(_modifiers & (ShiftMask|ControlMask|Mod1Mask|Mod5Mask|LockMask|Mod2Mask));
} }
#ifdef MAGNUM_BUILD_DEPRECATED #ifdef MAGNUM_BUILD_DEPRECATED
@ -837,8 +1192,6 @@ class AbstractXApplication::InputEvent {
bool _accepted; bool _accepted;
}; };
CORRADE_ENUMSET_OPERATORS(AbstractXApplication::InputEvent::Modifiers)
#ifdef MAGNUM_BUILD_DEPRECATED #ifdef MAGNUM_BUILD_DEPRECATED
CORRADE_IGNORE_DEPRECATED_PUSH CORRADE_IGNORE_DEPRECATED_PUSH
CORRADE_ENUMSET_OPERATORS(AbstractXApplication::InputEvent::Buttons) CORRADE_ENUMSET_OPERATORS(AbstractXApplication::InputEvent::Buttons)
@ -852,343 +1205,17 @@ CORRADE_IGNORE_DEPRECATED_POP
*/ */
class AbstractXApplication::KeyEvent: public AbstractXApplication::InputEvent { class AbstractXApplication::KeyEvent: public AbstractXApplication::InputEvent {
public: public:
#ifdef MAGNUM_BUILD_DEPRECATED
/** /**
* @brief Key * @brief @copybrief AbstractXApplication::Key
* * @m_deprecated_since_latest Use @ref AbstractXApplication::Key
* @see @ref key() * instead.
*/ */
enum class Key: KeySym { typedef CORRADE_DEPRECATED("use AbstractXApplication::Key instead") AbstractXApplication::Key Key;
/** #endif
* 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 (<tt>'</tt>)
* @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 (<tt>`</tt>)
* @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 Key */ /** @brief Key */
Key key() const { return _key; } AbstractXApplication::Key key() const { return _key; }
/** @brief Position */ /** @brief Position */
Vector2i position() const { return _position; } Vector2i position() const { return _position; }
@ -1205,9 +1232,9 @@ class AbstractXApplication::KeyEvent: public AbstractXApplication::InputEvent {
private: private:
friend AbstractXApplication; 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; const Vector2i _position;
}; };

38
src/Magnum/Platform/EmscriptenApplication.cpp

@ -69,7 +69,7 @@ enum class EmscriptenApplication::Flag: UnsignedByte {
}; };
namespace { namespace {
typedef EmscriptenApplication::KeyEvent::Key Key; typedef EmscriptenApplication::Key Key;
/* Entry for key name to `Key` enum mapping */ /* Entry for key name to `Key` enum mapping */
struct Entry { struct Entry {
@ -552,16 +552,16 @@ EmscriptenApplication::Pointers buttonsToPointers(const std::uint32_t buttons) {
return pointers; return pointers;
} }
template<class T> EmscriptenApplication::InputEvent::Modifiers eventModifiers(const T& event) { template<class T> EmscriptenApplication::Modifiers eventModifiers(const T& event) {
EmscriptenApplication::InputEvent::Modifiers modifiers; EmscriptenApplication::Modifiers modifiers;
if(event.ctrlKey) if(event.ctrlKey)
modifiers |= EmscriptenApplication::InputEvent::Modifier::Ctrl; modifiers |= EmscriptenApplication::Modifier::Ctrl;
if(event.shiftKey) if(event.shiftKey)
modifiers |= EmscriptenApplication::InputEvent::Modifier::Shift; modifiers |= EmscriptenApplication::Modifier::Shift;
if(event.altKey) if(event.altKey)
modifiers |= EmscriptenApplication::InputEvent::Modifier::Alt; modifiers |= EmscriptenApplication::Modifier::Alt;
if(event.metaKey) if(event.metaKey)
modifiers |= EmscriptenApplication::InputEvent::Modifier::Super; modifiers |= EmscriptenApplication::Modifier::Super;
return modifiers; return modifiers;
} }
@ -650,7 +650,7 @@ void EmscriptenApplication::setupCallbacks(bool resizable) {
const Pointer pointer = buttonToPointer(event->button); const Pointer pointer = buttonToPointer(event->button);
const Pointers pointers = buttonsToPointers(event->buttons); const Pointers pointers = buttonsToPointers(event->buttons);
const InputEvent::Modifiers modifiers = eventModifiers(*event); const Modifiers modifiers = eventModifiers(*event);
const Vector2 position = eventTargetPosition(*event); const Vector2 position = eventTargetPosition(*event);
/* If an additional mouse button was pressed, call a move 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 Pointer pointer = buttonToPointer(event->button);
const Pointers pointers = buttonsToPointers(event->buttons); const Pointers pointers = buttonsToPointers(event->buttons);
const InputEvent::Modifiers modifiers = eventModifiers(*event); const Modifiers modifiers = eventModifiers(*event);
const Vector2 position = eventTargetPosition(*event); const Vector2 position = eventTargetPosition(*event);
/* If some buttons are still left pressed after a release, call a /* 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 { ([](int, const EmscriptenMouseEvent* event, void* userData) -> EM_BOOL {
auto& app = *static_cast<EmscriptenApplication*>(userData); auto& app = *static_cast<EmscriptenApplication*>(userData);
const Pointers pointers = buttonsToPointers(event->buttons); const Pointers pointers = buttonsToPointers(event->buttons);
const InputEvent::Modifiers modifiers = eventModifiers(*event); const Modifiers modifiers = eventModifiers(*event);
const Vector2 position = eventTargetPosition(*event); const Vector2 position = eventTargetPosition(*event);
/* Avoid bogus offset at first -- report 0 when the event is called /* Avoid bogus offset at first -- report 0 when the event is called
for the first time. */ 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 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 https://github.com/emscripten-core/emscripten/blob/10cb9d46cdd17e7a96de68137c9649d9a630fbc7/src/library_html5.js#L1930-L1933
correctly. */ correctly. */
const InputEvent::Modifiers modifiers = eventModifiers(*event); const Modifiers modifiers = eventModifiers(*event);
bool accepted = false; bool accepted = false;
for(Int i = 0; i != event->numTouches; ++i) { for(Int i = 0; i != event->numTouches; ++i) {
@ -789,7 +789,7 @@ void EmscriptenApplication::setupCallbacks(bool resizable) {
auto& app = *static_cast<EmscriptenApplication*>(userData); auto& app = *static_cast<EmscriptenApplication*>(userData);
/** @todo somehow desktop Chrome doesn't populate these for touch /** @todo somehow desktop Chrome doesn't populate these for touch
events, see above */ events, see above */
const InputEvent::Modifiers modifiers = eventModifiers(*event); const Modifiers modifiers = eventModifiers(*event);
/* Remember the touch event timestamp. Chromium (at least) then /* Remember the touch event timestamp. Chromium (at least) then
fires the compatibility mouse press and release event with the fires the compatibility mouse press and release event with the
@ -841,7 +841,7 @@ void EmscriptenApplication::setupCallbacks(bool resizable) {
auto& app = *static_cast<EmscriptenApplication*>(userData); auto& app = *static_cast<EmscriptenApplication*>(userData);
/** @todo somehow desktop Chrome doesn't populate these for touch /** @todo somehow desktop Chrome doesn't populate these for touch
events, see above */ events, see above */
const InputEvent::Modifiers modifiers = eventModifiers(*event); const Modifiers modifiers = eventModifiers(*event);
bool accepted = false; bool accepted = false;
for(Int i = 0; i != event->numTouches; ++i) { for(Int i = 0; i != event->numTouches; ++i) {
@ -1206,7 +1206,7 @@ Vector2i EmscriptenApplication::MouseEvent::position() const {
return {Int(_event.targetX), Int(_event.targetY)}; return {Int(_event.targetX), Int(_event.targetY)};
} }
EmscriptenApplication::MouseEvent::Modifiers EmscriptenApplication::MouseEvent::modifiers() const { EmscriptenApplication::Modifiers EmscriptenApplication::MouseEvent::modifiers() const {
return eventModifiers(_event); return eventModifiers(_event);
} }
CORRADE_IGNORE_DEPRECATED_POP CORRADE_IGNORE_DEPRECATED_POP
@ -1224,7 +1224,7 @@ Vector2i EmscriptenApplication::MouseMoveEvent::position() const {
return {Int(_event.targetX), Int(_event.targetY)}; return {Int(_event.targetX), Int(_event.targetY)};
} }
EmscriptenApplication::MouseMoveEvent::Modifiers EmscriptenApplication::MouseMoveEvent::modifiers() const { EmscriptenApplication::Modifiers EmscriptenApplication::MouseMoveEvent::modifiers() const {
return eventModifiers(_event); return eventModifiers(_event);
} }
#endif #endif
@ -1248,7 +1248,7 @@ Vector2 EmscriptenApplication::ScrollEvent::position() const {
return {Float(_event.mouse.targetX), Float(_event.mouse.targetY)}; 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); return eventModifiers(_event.mouse);
} }
@ -1267,12 +1267,12 @@ Vector2i EmscriptenApplication::MouseScrollEvent::position() const {
return {Int(_event.mouse.targetX), Int(_event.mouse.targetY)}; 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); return eventModifiers(_event.mouse);
} }
#endif #endif
Key EmscriptenApplication::KeyEvent::key() const { EmscriptenApplication::Key EmscriptenApplication::KeyEvent::key() const {
return toKey(_event.key, _event.code); return toKey(_event.key, _event.code);
} }
@ -1283,7 +1283,7 @@ Containers::StringView EmscriptenApplication::KeyEvent::keyName() const {
return _event.code; return _event.code;
} }
EmscriptenApplication::InputEvent::Modifiers EmscriptenApplication::KeyEvent::modifiers() const { EmscriptenApplication::Modifiers EmscriptenApplication::KeyEvent::modifiers() const {
return eventModifiers(_event); return eventModifiers(_event);
} }

527
src/Magnum/Platform/EmscriptenApplication.h

@ -343,10 +343,22 @@ class EmscriptenApplication {
/* The damn thing cannot handle forward enum declarations */ /* The damn thing cannot handle forward enum declarations */
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
enum class Modifier: Int;
enum class Key: Int;
enum class PointerEventSource: UnsignedByte; enum class PointerEventSource: UnsignedByte;
enum class Pointer: UnsignedByte; enum class Pointer: UnsignedByte;
#endif #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<Modifier> Modifiers;
/** /**
* @brief Set of pointer types * @brief Set of pointer types
* @m_since_latest * @m_since_latest
@ -1099,6 +1111,242 @@ class EmscriptenApplication {
int (*_callback)(void*); 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 (<tt>'</tt>) */
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 (<tt>`</tt>) */
/* 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 @brief Pointer event source
@m_since_latest @m_since_latest
@ -1712,52 +1960,21 @@ class EmscriptenApplication::ViewportEvent {
*/ */
class EmscriptenApplication::InputEvent { class EmscriptenApplication::InputEvent {
public: public:
#ifdef MAGNUM_BUILD_DEPRECATED
/** /**
* @brief Modifier * @brief @copybrief EmscriptenApplication::Modifier
* * @m_deprecated_since_latest Use @ref EmscriptenApplication::Modifier
* @see @ref Modifiers, @ref KeyEvent::modifiers(), * instead.
* @ref PointerEvent::modifiers(),
* @ref PointerMoveEvent::modifiers(),
* @ref ScrollEvent::modifiers()
*/ */
enum class Modifier: Int { typedef CORRADE_DEPRECATED("use EmscriptenApplication::Modifier instead") EmscriptenApplication::Modifier Modifier;
/**
* 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
};
/** /**
* @brief Set of modifiers * @brief @copybrief EmscriptenApplication::Modifiers
* * @m_deprecated_since_latest Use @ref EmscriptenApplication::Modifiers
* @see @ref KeyEvent::modifiers(), @ref PointerEvent::modifiers(), * instead.
* @ref PointerMoveEvent::modifiers(),
* @ref ScrollEvent::modifiers()
*/ */
typedef Containers::EnumSet<Modifier> Modifiers; typedef CORRADE_DEPRECATED("use EmscriptenApplication::Modifiers instead") EmscriptenApplication::Modifiers Modifiers;
#endif
/** @brief Copying is not allowed */ /** @brief Copying is not allowed */
InputEvent(const InputEvent&) = delete; InputEvent(const InputEvent&) = delete;
@ -1792,8 +2009,6 @@ class EmscriptenApplication::InputEvent {
bool _accepted; bool _accepted;
}; };
CORRADE_ENUMSET_OPERATORS(EmscriptenApplication::InputEvent::Modifiers)
/** /**
@brief Pointer event @brief Pointer event
@m_since_latest @m_since_latest
@ -1856,7 +2071,7 @@ class EmscriptenApplication::PointerEvent: public InputEvent {
Vector2 position() const { return _position; } Vector2 position() const { return _position; }
/** @brief Modifiers */ /** @brief Modifiers */
Modifiers modifiers() const { return _modifiers; } EmscriptenApplication::Modifiers modifiers() const { return _modifiers; }
/** /**
* @brief Underlying Emscripten event * @brief Underlying Emscripten event
@ -1874,16 +2089,16 @@ class EmscriptenApplication::PointerEvent: public InputEvent {
private: private:
friend EmscriptenApplication; 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 #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 #endif
const void* _event; const void* _event;
const PointerEventSource _source; const PointerEventSource _source;
const bool _primary; const bool _primary;
const Pointer _pointer; const Pointer _pointer;
const Modifiers _modifiers; const EmscriptenApplication::Modifiers _modifiers;
const Int _id; const Int _id;
const Vector2 _position; const Vector2 _position;
}; };
@ -2038,7 +2253,7 @@ class EmscriptenApplication::PointerMoveEvent: public InputEvent {
Vector2 relativePosition() const { return _relativePosition; } Vector2 relativePosition() const { return _relativePosition; }
/** @brief Modifiers */ /** @brief Modifiers */
Modifiers modifiers() const { return _modifiers; } EmscriptenApplication::Modifiers modifiers() const { return _modifiers; }
/** /**
* @brief Underlying Emscripten event * @brief Underlying Emscripten event
@ -2056,9 +2271,9 @@ class EmscriptenApplication::PointerMoveEvent: public InputEvent {
private: private:
friend EmscriptenApplication; friend EmscriptenApplication;
explicit PointerMoveEvent(const EmscriptenMouseEvent& event, Containers::Optional<Pointer> 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> 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 #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 #endif
const void* _event; const void* _event;
@ -2066,7 +2281,7 @@ class EmscriptenApplication::PointerMoveEvent: public InputEvent {
const bool _primary; const bool _primary;
const Containers::Optional<Pointer> _pointer; const Containers::Optional<Pointer> _pointer;
const Pointers _pointers; const Pointers _pointers;
const Modifiers _modifiers; const EmscriptenApplication::Modifiers _modifiers;
const Int _id; const Int _id;
const Vector2 _position; const Vector2 _position;
const Vector2 _relativePosition; const Vector2 _relativePosition;
@ -2140,7 +2355,7 @@ class CORRADE_DEPRECATED("use PointerMoveEvent and pointerMoveEvent() instead")
Buttons buttons() const; Buttons buttons() const;
/** @brief Modifiers */ /** @brief Modifiers */
Modifiers modifiers() const; EmscriptenApplication::Modifiers modifiers() const;
/** @brief Underlying Emscripten event */ /** @brief Underlying Emscripten event */
const EmscriptenMouseEvent& event() const { return _event; } const EmscriptenMouseEvent& event() const { return _event; }
@ -2178,7 +2393,7 @@ class EmscriptenApplication::ScrollEvent: public EmscriptenApplication::InputEve
Vector2 position() const; Vector2 position() const;
/** @brief Modifiers */ /** @brief Modifiers */
Modifiers modifiers() const; EmscriptenApplication::Modifiers modifiers() const;
/** @brief Underlying Emscripten event */ /** @brief Underlying Emscripten event */
const EmscriptenWheelEvent& event() const { return _event; } const EmscriptenWheelEvent& event() const { return _event; }
@ -2208,7 +2423,7 @@ class CORRADE_DEPRECATED("use ScrollEvent and scrollEvent() instead") Emscripten
Vector2i position() const; Vector2i position() const;
/** @brief Modifiers */ /** @brief Modifiers */
Modifiers modifiers() const; EmscriptenApplication::Modifiers modifiers() const;
/** @brief Underlying Emscripten event */ /** @brief Underlying Emscripten event */
const EmscriptenWheelEvent& event() const { return _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 { class EmscriptenApplication::KeyEvent: public EmscriptenApplication::InputEvent {
public: public:
#ifdef MAGNUM_BUILD_DEPRECATED
/** /**
* @brief Key * @brief @copybrief EmscriptenApplication::Key
* * @m_deprecated_since_latest Use @ref EmscriptenApplication::Key
* @see @ref key() * instead.
*/ */
enum class Key: Int { typedef CORRADE_DEPRECATED("use EmscriptenApplication::Key instead") EmscriptenApplication::Key Key;
Unknown, /**< Unknown key */ #endif
/**
* 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 (<tt>'</tt>) */
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 (<tt>`</tt>) */
/* 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 Key * @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), * @m_class{m-doc-external} [EmscriptenkeyboardEvent::key](https://emscripten.org/docs/api_reference/html5.h.html#c.EmscriptenKeyboardEvent.key),
* which respects the keyboard layout. * which respects the keyboard layout.
*/ */
Key key() const; EmscriptenApplication::Key key() const;
/** /**
* @brief Key name * @brief Key name
@ -2447,7 +2474,7 @@ class EmscriptenApplication::KeyEvent: public EmscriptenApplication::InputEvent
Containers::StringView keyName() const; Containers::StringView keyName() const;
/** @brief Modifiers */ /** @brief Modifiers */
Modifiers modifiers() const; EmscriptenApplication::Modifiers modifiers() const;
/** @brief Underlying Emscripten event */ /** @brief Underlying Emscripten event */
const EmscriptenKeyboardEvent& event() const { return _event; } const EmscriptenKeyboardEvent& event() const { return _event; }

28
src/Magnum/Platform/GlfwApplication.cpp

@ -382,23 +382,23 @@ bool GlfwApplication::tryCreate(const Configuration& configuration) {
namespace { namespace {
GlfwApplication::InputEvent::Modifiers currentGlfwModifiers(GLFWwindow* window) { GlfwApplication::Modifiers currentGlfwModifiers(GLFWwindow* window) {
static_assert(GLFW_PRESS == true && GLFW_RELEASE == false, static_assert(GLFW_PRESS == true && GLFW_RELEASE == false,
"GLFW press and release constants do not correspond to bool values"); "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) || if(glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) ||
glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT)) glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT))
mods |= GlfwApplication::InputEvent::Modifier::Shift; mods |= GlfwApplication::Modifier::Shift;
if(glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) || if(glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) ||
glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL)) glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL))
mods |= GlfwApplication::InputEvent::Modifier::Ctrl; mods |= GlfwApplication::Modifier::Ctrl;
if(glfwGetKey(window, GLFW_KEY_LEFT_ALT) || if(glfwGetKey(window, GLFW_KEY_LEFT_ALT) ||
glfwGetKey(window, GLFW_KEY_RIGHT_ALT)) glfwGetKey(window, GLFW_KEY_RIGHT_ALT))
mods |= GlfwApplication::InputEvent::Modifier::Alt; mods |= GlfwApplication::Modifier::Alt;
if(glfwGetKey(window, GLFW_KEY_LEFT_SUPER) || if(glfwGetKey(window, GLFW_KEY_LEFT_SUPER) ||
glfwGetKey(window, GLFW_KEY_RIGHT_SUPER)) glfwGetKey(window, GLFW_KEY_RIGHT_SUPER))
mods |= GlfwApplication::InputEvent::Modifier::Super; mods |= GlfwApplication::Modifier::Super;
return mods; return mods;
} }
@ -665,7 +665,7 @@ void GlfwApplication::setupCallbacks() {
glfwSetKeyCallback(_window, [](GLFWwindow* const window, const int key, int, const int action, const int mods) { glfwSetKeyCallback(_window, [](GLFWwindow* const window, const int key, int, const int action, const int mods) {
auto& app = *static_cast<GlfwApplication*>(glfwGetWindowUserPointer(window)); auto& app = *static_cast<GlfwApplication*>(glfwGetWindowUserPointer(window));
KeyEvent e(static_cast<KeyEvent::Key>(key), {static_cast<InputEvent::Modifier>(mods)}, action == GLFW_REPEAT); KeyEvent e(Key(key), Modifiers{mods}, action == GLFW_REPEAT);
if(action == GLFW_PRESS || action == GLFW_REPEAT) if(action == GLFW_PRESS || action == GLFW_REPEAT)
app.keyPressEvent(e); app.keyPressEvent(e);
@ -690,10 +690,10 @@ void GlfwApplication::setupCallbacks() {
the callback, set them directly instead of having them lazily the callback, set them directly instead of having them lazily
populated later */ populated later */
e._pointers = pointers; e._pointers = pointers;
e._modifiers = InputEvent::Modifiers{mods}; e._modifiers = Modifiers{mods};
app.pointerMoveEvent(e); app.pointerMoveEvent(e);
} else { } else {
PointerEvent e{pointer, position, InputEvent::Modifiers{mods}}; PointerEvent e{pointer, position, Modifiers{mods}};
if(action == GLFW_PRESS) /* we don't handle GLFW_REPEAT */ if(action == GLFW_PRESS) /* we don't handle GLFW_REPEAT */
app.pointerPressEvent(e); app.pointerPressEvent(e);
else if(action == GLFW_RELEASE) else if(action == GLFW_RELEASE)
@ -1107,7 +1107,7 @@ GlfwApplication::Configuration::Configuration():
GlfwApplication::Configuration::~Configuration() = default; 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); return glfwGetKeyName(int(key), 0);
} }
@ -1122,7 +1122,7 @@ GlfwApplication::Pointers GlfwApplication::PointerMoveEvent::pointers() {
return *_pointers; return *_pointers;
} }
auto GlfwApplication::PointerMoveEvent::modifiers() -> Modifiers { GlfwApplication::Modifiers GlfwApplication::PointerMoveEvent::modifiers() {
if(!_modifiers) _modifiers = currentGlfwModifiers(_window); if(!_modifiers) _modifiers = currentGlfwModifiers(_window);
return *_modifiers; return *_modifiers;
} }
@ -1143,14 +1143,14 @@ auto GlfwApplication::MouseMoveEvent::buttons() -> Buttons {
return *_buttons; return *_buttons;
} }
auto GlfwApplication::MouseMoveEvent::modifiers() -> Modifiers { GlfwApplication::Modifiers GlfwApplication::MouseMoveEvent::modifiers() {
if(!_modifiers) _modifiers = currentGlfwModifiers(_window); if(!_modifiers) _modifiers = currentGlfwModifiers(_window);
return *_modifiers; return *_modifiers;
} }
CORRADE_IGNORE_DEPRECATED_POP CORRADE_IGNORE_DEPRECATED_POP
#endif #endif
auto GlfwApplication::ScrollEvent::modifiers() -> Modifiers { GlfwApplication::Modifiers GlfwApplication::ScrollEvent::modifiers() {
if(!_modifiers) _modifiers = currentGlfwModifiers(_window); if(!_modifiers) _modifiers = currentGlfwModifiers(_window);
return *_modifiers; return *_modifiers;
} }
@ -1175,7 +1175,7 @@ Vector2i GlfwApplication::MouseScrollEvent::position() {
return *_position; return *_position;
} }
auto GlfwApplication::MouseScrollEvent::modifiers() -> Modifiers { GlfwApplication::Modifiers GlfwApplication::MouseScrollEvent::modifiers() {
if(!_modifiers) _modifiers = currentGlfwModifiers(_window); if(!_modifiers) _modifiers = currentGlfwModifiers(_window);
return *_modifiers; return *_modifiers;
} }

629
src/Magnum/Platform/GlfwApplication.h

@ -190,10 +190,22 @@ class GlfwApplication {
/* The damn thing cannot handle forward enum declarations */ /* The damn thing cannot handle forward enum declarations */
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
enum class Modifier: Int;
enum class Key: Int;
enum class PointerEventSource: UnsignedByte; enum class PointerEventSource: UnsignedByte;
enum class Pointer: UnsignedByte; enum class Pointer: UnsignedByte;
#endif #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<Modifier> Modifiers;
/** /**
* @brief Set of pointer types * @brief Set of pointer types
* @m_since_latest * @m_since_latest
@ -932,6 +944,286 @@ class GlfwApplication {
Vector2 _previousMouseMovePosition{Constants::nan()}; 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 (<tt>'</tt>)
* @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 (<tt>`</tt>)
* @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 @brief Pointer event source
@m_since_latest @m_since_latest
@ -1742,52 +2034,21 @@ class GlfwApplication::ViewportEvent {
*/ */
class GlfwApplication::InputEvent { class GlfwApplication::InputEvent {
public: public:
#ifdef MAGNUM_BUILD_DEPRECATED
/** /**
* @brief Modifier * @brief @copybrief GlfwApplication::Modifier
* * @m_deprecated_since_latest Use @ref GlfwApplication::Modifier
* @see @ref Modifiers, @ref KeyEvent::modifiers(), * instead.
* @ref PointerEvent::modifiers(),
* @ref PointerMoveEvent::modifiers(),
* @ref ScrollEvent::modifiers()
*/ */
enum class Modifier: Int { typedef CORRADE_DEPRECATED("use GlfwApplication::Modifier instead") GlfwApplication::Modifier Modifier;
/**
* 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
};
/** /**
* @brief Set of modifiers * @brief @copybrief GlfwApplication::Modifiers
* * @m_deprecated_since_latest Use @ref GlfwApplication::Modifiers
* @see @ref KeyEvent::modifiers(), @ref PointerEvent::modifiers(), * instead.
* @ref PointerMoveEvent::modifiers(),
* @ref ScrollEvent::modifiers()
*/ */
typedef Containers::EnumSet<Modifier> Modifiers; typedef CORRADE_DEPRECATED("use GlfwApplication::Modifiers instead") GlfwApplication::Modifiers Modifiers;
#endif
/** @brief Copying is not allowed */ /** @brief Copying is not allowed */
InputEvent(const InputEvent&) = delete; InputEvent(const InputEvent&) = delete;
@ -1816,8 +2077,6 @@ class GlfwApplication::InputEvent {
bool _accepted; bool _accepted;
}; };
CORRADE_ENUMSET_OPERATORS(GlfwApplication::InputEvent::Modifiers)
/** /**
@brief Key event @brief Key event
@ -1825,247 +2084,13 @@ CORRADE_ENUMSET_OPERATORS(GlfwApplication::InputEvent::Modifiers)
*/ */
class GlfwApplication::KeyEvent: public GlfwApplication::InputEvent { class GlfwApplication::KeyEvent: public GlfwApplication::InputEvent {
public: public:
#ifdef MAGNUM_BUILD_DEPRECATED
/** /**
* @brief Key * @brief @copybrief GlfwApplication::Key
* * @m_deprecated_since_latest Use @ref GlfwApplication::Key instead.
* @see @ref key()
*/ */
enum class Key: Int { typedef CORRADE_DEPRECATED("use GlfwApplication::Key instead") GlfwApplication::Key Key;
Unknown = GLFW_KEY_UNKNOWN, /**< Unknown key */ #endif
/**
* 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 (<tt>'</tt>)
* @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 (<tt>`</tt>)
* @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 Name for given key * @brief Name for given key
@ -2078,10 +2103,10 @@ class GlfwApplication::KeyEvent: public GlfwApplication::InputEvent {
* exits. * exits.
* @see @ref keyName(Key) * @see @ref keyName(Key)
*/ */
static Containers::StringView keyName(Key key); static Containers::StringView keyName(GlfwApplication::Key key);
/** @copydoc Sdl2Application::KeyEvent::key() */ /** @copydoc Sdl2Application::KeyEvent::key() */
Key key() const { return _key; } GlfwApplication::Key key() const { return _key; }
/** /**
* @brief Key name * @brief Key name
@ -2098,7 +2123,7 @@ class GlfwApplication::KeyEvent: public GlfwApplication::InputEvent {
Containers::StringView keyName() const; Containers::StringView keyName() const;
/** @brief Modifiers */ /** @brief Modifiers */
Modifiers modifiers() const { return _modifiers; } GlfwApplication::Modifiers modifiers() const { return _modifiers; }
/** @copydoc Sdl2Application::KeyEvent::isRepeated() */ /** @copydoc Sdl2Application::KeyEvent::isRepeated() */
bool isRepeated() const { return _repeated; } bool isRepeated() const { return _repeated; }
@ -2106,10 +2131,10 @@ class GlfwApplication::KeyEvent: public GlfwApplication::InputEvent {
private: private:
friend GlfwApplication; 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 GlfwApplication::Key _key;
const Modifiers _modifiers; const GlfwApplication::Modifiers _modifiers;
const bool _repeated; const bool _repeated;
}; };
@ -2174,16 +2199,16 @@ class GlfwApplication::PointerEvent: public InputEvent {
Vector2 position() const { return _position; } Vector2 position() const { return _position; }
/** @brief Modifiers */ /** @brief Modifiers */
Modifiers modifiers() const { return _modifiers; } GlfwApplication::Modifiers modifiers() const { return _modifiers; }
private: private:
friend GlfwApplication; 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 Pointer _pointer;
const Vector2 _position; const Vector2 _position;
const Modifiers _modifiers; const GlfwApplication::Modifiers _modifiers;
}; };
#ifdef MAGNUM_BUILD_DEPRECATED #ifdef MAGNUM_BUILD_DEPRECATED
@ -2224,16 +2249,16 @@ class CORRADE_DEPRECATED("use PointerEvent, pointerPressEvent() and pointerRelea
Vector2i position() const { return _position; } Vector2i position() const { return _position; }
/** @brief Modifiers */ /** @brief Modifiers */
Modifiers modifiers() const { return _modifiers; } GlfwApplication::Modifiers modifiers() const { return _modifiers; }
private: private:
friend GlfwApplication; 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 Button _button;
const Vector2i _position; const Vector2i _position;
const Modifiers _modifiers; const GlfwApplication::Modifiers _modifiers;
}; };
#endif #endif
@ -2331,7 +2356,7 @@ class GlfwApplication::PointerMoveEvent: public InputEvent {
* *
* Lazily populated on first request. * Lazily populated on first request.
*/ */
Modifiers modifiers(); GlfwApplication::Modifiers modifiers();
private: private:
friend GlfwApplication; friend GlfwApplication;
@ -2342,7 +2367,7 @@ class GlfwApplication::PointerMoveEvent: public InputEvent {
const Containers::Optional<Pointer> _pointer; const Containers::Optional<Pointer> _pointer;
Containers::Optional<Pointers> _pointers; Containers::Optional<Pointers> _pointers;
const Vector2 _position, _relativePosition; const Vector2 _position, _relativePosition;
Containers::Optional<Modifiers> _modifiers; Containers::Optional<GlfwApplication::Modifiers> _modifiers;
}; };
#ifdef MAGNUM_BUILD_DEPRECATED #ifdef MAGNUM_BUILD_DEPRECATED
@ -2400,7 +2425,7 @@ class CORRADE_DEPRECATED("use PointerMoveEvent and pointerMoveEvent() instead")
* *
* Lazily populated on first request. * Lazily populated on first request.
*/ */
Modifiers modifiers(); GlfwApplication::Modifiers modifiers();
private: private:
friend GlfwApplication; friend GlfwApplication;
@ -2410,7 +2435,7 @@ class CORRADE_DEPRECATED("use PointerMoveEvent and pointerMoveEvent() instead")
GLFWwindow* const _window; GLFWwindow* const _window;
const Vector2i _position, _relativePosition; const Vector2i _position, _relativePosition;
Containers::Optional<Buttons> _buttons; Containers::Optional<Buttons> _buttons;
Containers::Optional<Modifiers> _modifiers; Containers::Optional<GlfwApplication::Modifiers> _modifiers;
}; };
CORRADE_IGNORE_DEPRECATED_PUSH CORRADE_IGNORE_DEPRECATED_PUSH
@ -2444,7 +2469,7 @@ class GlfwApplication::ScrollEvent: public InputEvent {
* *
* Lazily populated on first request. * Lazily populated on first request.
*/ */
Modifiers modifiers(); GlfwApplication::Modifiers modifiers();
private: private:
friend GlfwApplication; friend GlfwApplication;
@ -2454,7 +2479,7 @@ class GlfwApplication::ScrollEvent: public InputEvent {
GLFWwindow* const _window; GLFWwindow* const _window;
const Vector2 _offset; const Vector2 _offset;
Containers::Optional<Vector2> _position; Containers::Optional<Vector2> _position;
Containers::Optional<Modifiers> _modifiers; Containers::Optional<GlfwApplication::Modifiers> _modifiers;
}; };
#ifdef MAGNUM_BUILD_DEPRECATED #ifdef MAGNUM_BUILD_DEPRECATED
@ -2482,7 +2507,7 @@ class CORRADE_DEPRECATED("use ScrollEvent and scrollEvent() instead") GlfwApplic
* *
* Lazily populated on first request. * Lazily populated on first request.
*/ */
Modifiers modifiers(); GlfwApplication::Modifiers modifiers();
private: private:
friend GlfwApplication; friend GlfwApplication;
@ -2492,7 +2517,7 @@ class CORRADE_DEPRECATED("use ScrollEvent and scrollEvent() instead") GlfwApplic
GLFWwindow* const _window; GLFWwindow* const _window;
const Vector2 _offset; const Vector2 _offset;
Containers::Optional<Vector2i> _position; Containers::Optional<Vector2i> _position;
Containers::Optional<Modifiers> _modifiers; Containers::Optional<GlfwApplication::Modifiers> _modifiers;
}; };
#endif #endif

30
src/Magnum/Platform/Screen.h

@ -53,6 +53,9 @@ CORRADE_ENUMSET_OPERATORS(PropagatedScreenEvents)
template<class Application, bool> class ScreenKeyEventMixin {}; template<class Application, bool> class ScreenKeyEventMixin {};
template<class Application> class ScreenKeyEventMixin<Application, true> { template<class Application> class ScreenKeyEventMixin<Application, true> {
public: public:
typedef typename BasicScreenedApplication<Application>::Modifier Modifier;
typedef typename BasicScreenedApplication<Application>::Modifiers Modifiers;
typedef typename BasicScreenedApplication<Application>::Key Key;
typedef typename BasicScreenedApplication<Application>::KeyEvent KeyEvent; typedef typename BasicScreenedApplication<Application>::KeyEvent KeyEvent;
private: private:
@ -192,6 +195,33 @@ template<class Application> class BasicScreen:
typedef typename BasicScreenedApplication<Application>::InputEvent InputEvent; typedef typename BasicScreenedApplication<Application>::InputEvent InputEvent;
#ifdef DOXYGEN_GENERATING_OUTPUT #ifdef DOXYGEN_GENERATING_OUTPUT
/**
* @brief Keyboard modifier
* @m_since_latest
*
* Defined only if the application has a
* @relativeref{Sdl2Application,KeyEvent}.
*/
typedef typename BasicScreenedApplication<Application>::Modifier Modifier;
/**
* @brief Set of keyboard modifiers
* @m_since_latest
*
* Defined only if the application has a
* @relativeref{Sdl2Application,KeyEvent}.
*/
typedef typename BasicScreenedApplication<Application>::Modifiers Modifiers;
/**
* @brief Key
* @m_since_latest
*
* Defined only if the application has a
* @relativeref{Sdl2Application,KeyEvent}.
*/
typedef typename BasicScreenedApplication<Application>::Key Key;
/** /**
* @brief Key event * @brief Key event
* *

32
src/Magnum/Platform/Sdl2Application.cpp

@ -91,12 +91,16 @@ namespace {
* (modifiers >= Shift) would pass only if both left and right were pressed, * (modifiers >= Shift) would pass only if both left and right were pressed,
* which is usually not what the developers wants. * which is usually not what the developers wants.
*/ */
Sdl2Application::InputEvent::Modifiers fixedModifiers(Uint16 mod) { Sdl2Application::Modifiers fixedModifiers(Uint16 mod) {
Sdl2Application::InputEvent::Modifiers modifiers(static_cast<Sdl2Application::InputEvent::Modifier>(mod)); Sdl2Application::Modifiers modifiers{mod};
if(modifiers & Sdl2Application::InputEvent::Modifier::Shift) modifiers |= Sdl2Application::InputEvent::Modifier::Shift; if(modifiers & Sdl2Application::Modifier::Shift)
if(modifiers & Sdl2Application::InputEvent::Modifier::Ctrl) modifiers |= Sdl2Application::InputEvent::Modifier::Ctrl; modifiers |= Sdl2Application::Modifier::Shift;
if(modifiers & Sdl2Application::InputEvent::Modifier::Alt) modifiers |= Sdl2Application::InputEvent::Modifier::Alt; if(modifiers & Sdl2Application::Modifier::Ctrl)
if(modifiers & Sdl2Application::InputEvent::Modifier::Super) modifiers |= Sdl2Application::InputEvent::Modifier::Super; modifiers |= Sdl2Application::Modifier::Ctrl;
if(modifiers & Sdl2Application::Modifier::Alt)
modifiers |= Sdl2Application::Modifier::Alt;
if(modifiers & Sdl2Application::Modifier::Super)
modifiers |= Sdl2Application::Modifier::Super;
return modifiers; return modifiers;
} }
@ -1037,7 +1041,7 @@ bool Sdl2Application::mainLoopIteration() {
case SDL_KEYDOWN: case SDL_KEYDOWN:
case SDL_KEYUP: { case SDL_KEYUP: {
KeyEvent e{event, static_cast<KeyEvent::Key>(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); event.type == SDL_KEYDOWN ? keyPressEvent(e) : keyReleaseEvent(e);
} break; } break;
@ -1594,7 +1598,7 @@ Sdl2Application::Configuration::Configuration():
Sdl2Application::Configuration::~Configuration() = default; 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)); return SDL_GetKeyName(SDL_Keycode(key));
} }
@ -1602,7 +1606,7 @@ Containers::StringView Sdl2Application::KeyEvent::keyName() const {
return keyName(_key); return keyName(_key);
} }
Sdl2Application::InputEvent::Modifiers Sdl2Application::PointerEvent::modifiers() { Sdl2Application::Modifiers Sdl2Application::PointerEvent::modifiers() {
if(!_modifiers) if(!_modifiers)
_modifiers = fixedModifiers(Uint16(SDL_GetModState())); _modifiers = fixedModifiers(Uint16(SDL_GetModState()));
return *_modifiers; return *_modifiers;
@ -1610,14 +1614,14 @@ Sdl2Application::InputEvent::Modifiers Sdl2Application::PointerEvent::modifiers(
#ifdef MAGNUM_BUILD_DEPRECATED #ifdef MAGNUM_BUILD_DEPRECATED
CORRADE_IGNORE_DEPRECATED_PUSH CORRADE_IGNORE_DEPRECATED_PUSH
Sdl2Application::InputEvent::Modifiers Sdl2Application::MouseEvent::modifiers() { Sdl2Application::Modifiers Sdl2Application::MouseEvent::modifiers() {
if(_modifiers) return *_modifiers; if(_modifiers) return *_modifiers;
return *(_modifiers = fixedModifiers(Uint16(SDL_GetModState()))); return *(_modifiers = fixedModifiers(Uint16(SDL_GetModState())));
} }
CORRADE_IGNORE_DEPRECATED_POP CORRADE_IGNORE_DEPRECATED_POP
#endif #endif
Sdl2Application::InputEvent::Modifiers Sdl2Application::PointerMoveEvent::modifiers() { Sdl2Application::Modifiers Sdl2Application::PointerMoveEvent::modifiers() {
if(!_modifiers) if(!_modifiers)
_modifiers = fixedModifiers(Uint16(SDL_GetModState())); _modifiers = fixedModifiers(Uint16(SDL_GetModState()));
return *_modifiers; return *_modifiers;
@ -1625,7 +1629,7 @@ Sdl2Application::InputEvent::Modifiers Sdl2Application::PointerMoveEvent::modifi
#ifdef MAGNUM_BUILD_DEPRECATED #ifdef MAGNUM_BUILD_DEPRECATED
CORRADE_IGNORE_DEPRECATED_PUSH CORRADE_IGNORE_DEPRECATED_PUSH
Sdl2Application::InputEvent::Modifiers Sdl2Application::MouseMoveEvent::modifiers() { Sdl2Application::Modifiers Sdl2Application::MouseMoveEvent::modifiers() {
if(_modifiers) return *_modifiers; if(_modifiers) return *_modifiers;
return *(_modifiers = fixedModifiers(Uint16(SDL_GetModState()))); return *(_modifiers = fixedModifiers(Uint16(SDL_GetModState())));
} }
@ -1641,7 +1645,7 @@ Vector2 Sdl2Application::ScrollEvent::position() {
return *_position; return *_position;
} }
Sdl2Application::InputEvent::Modifiers Sdl2Application::ScrollEvent::modifiers() { Sdl2Application::Modifiers Sdl2Application::ScrollEvent::modifiers() {
if(!_modifiers) if(!_modifiers)
_modifiers = fixedModifiers(Uint16(SDL_GetModState())); _modifiers = fixedModifiers(Uint16(SDL_GetModState()));
return *_modifiers; return *_modifiers;
@ -1656,7 +1660,7 @@ Vector2i Sdl2Application::MouseScrollEvent::position() {
return *_position; return *_position;
} }
Sdl2Application::InputEvent::Modifiers Sdl2Application::MouseScrollEvent::modifiers() { Sdl2Application::Modifiers Sdl2Application::MouseScrollEvent::modifiers() {
if(_modifiers) return *_modifiers; if(_modifiers) return *_modifiers;
return *(_modifiers = fixedModifiers(Uint16(SDL_GetModState()))); return *(_modifiers = fixedModifiers(Uint16(SDL_GetModState())));
} }

695
src/Magnum/Platform/Sdl2Application.h

@ -550,10 +550,22 @@ class Sdl2Application {
/* The damn thing cannot handle forward enum declarations */ /* The damn thing cannot handle forward enum declarations */
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
enum class Modifier: Uint16;
enum class Key: SDL_Keycode;
enum class PointerEventSource: UnsignedByte; enum class PointerEventSource: UnsignedByte;
enum class Pointer: UnsignedByte; enum class Pointer: UnsignedByte;
#endif #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<Modifier> Modifiers;
/** /**
* @brief Set of pointer types * @brief Set of pointer types
* @m_since_latest * @m_since_latest
@ -1431,6 +1443,322 @@ class Sdl2Application {
int _exitCode = 0; 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 (<tt>'</tt>)
* @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 (<tt>`</tt>)
* @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 @brief Pointer event source
@m_since_latest @m_since_latest
@ -2363,74 +2691,21 @@ class Sdl2Application::ViewportEvent {
*/ */
class Sdl2Application::InputEvent { class Sdl2Application::InputEvent {
public: public:
#ifdef MAGNUM_BUILD_DEPRECATED
/** /**
* @brief Modifier * @brief @copybrief Sdl2Application::Modifier
* * @m_deprecated_since_latest Use @ref Sdl2Application::Modifier
* @see @ref Modifiers, @ref KeyEvent::modifiers(), * instead.
* @ref PointerEvent::modifiers(),
* @ref PointerMoveEvent::modifiers(),
* @ref ScrollEvent::modifiers()
*/ */
enum class Modifier: Uint16 { typedef CORRADE_DEPRECATED("use Sdl2Application::Modifier instead") Sdl2Application::Modifier Modifier;
/**
* 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
};
/** /**
* @brief Set of modifiers * @brief @copybrief Sdl2Application::Modifiers
* * @m_deprecated_since_latest Use @ref Sdl2Application::Modifiers
* @see @ref KeyEvent::modifiers(), @ref PointerEvent::modifiers(), * instead.
* @ref PointerMoveEvent::modifiers(),
* @ref ScrollEvent::modifiers()
*/ */
typedef Containers::EnumSet<Modifier> Modifiers; typedef CORRADE_DEPRECATED("use Sdl2Application::Modifiers instead") Sdl2Application::Modifiers Modifiers;
#endif
/** @brief Copying is not allowed */ /** @brief Copying is not allowed */
InputEvent(const InputEvent&) = delete; InputEvent(const InputEvent&) = delete;
@ -2488,260 +2763,13 @@ class Sdl2Application::InputEvent {
*/ */
class Sdl2Application::KeyEvent: public Sdl2Application::InputEvent { class Sdl2Application::KeyEvent: public Sdl2Application::InputEvent {
public: public:
#ifdef MAGNUM_BUILD_DEPRECATED
/** /**
* @brief Key * @brief @copybrief Sdl2Application::Key
* * @m_deprecated_since_latest Use @ref Sdl2Application::Key instead.
* @see @ref key()
*/ */
enum class Key: SDL_Keycode { typedef CORRADE_DEPRECATED("use Sdl2Application::Key instead") Sdl2Application::Key Key;
Unknown = SDLK_UNKNOWN, /**< Unknown key */ #endif
/**
* 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 (<tt>'</tt>)
* @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 (<tt>`</tt>)
* @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 Name for given key * @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 * @ref keyName() const or to the underlying @cpp SDL_GetKeyName() @ce
* API. * API.
*/ */
static Containers::StringView keyName(Key key); static Containers::StringView keyName(Sdl2Application::Key key);
/** /**
* @brief Key * @brief Key
* *
* @see @ref keyName() * @see @ref keyName()
*/ */
Key key() const { return _key; } Sdl2Application::Key key() const { return _key; }
/** /**
* @brief Key name * @brief Key name
@ -2777,7 +2805,7 @@ class Sdl2Application::KeyEvent: public Sdl2Application::InputEvent {
Containers::StringView keyName() const; Containers::StringView keyName() const;
/** @brief Modifiers */ /** @brief Modifiers */
Modifiers modifiers() const { return _modifiers; } Sdl2Application::Modifiers modifiers() const { return _modifiers; }
/** /**
* @brief Whether the key press is repeated * @brief Whether the key press is repeated
@ -2790,10 +2818,10 @@ class Sdl2Application::KeyEvent: public Sdl2Application::InputEvent {
private: private:
friend Sdl2Application; 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 Sdl2Application::Key _key;
const Modifiers _modifiers; const Sdl2Application::Modifiers _modifiers;
const bool _repeated; const bool _repeated;
}; };
@ -2869,7 +2897,7 @@ class Sdl2Application::PointerEvent: public InputEvent {
* *
* Lazily populated on first request. * Lazily populated on first request.
*/ */
Modifiers modifiers(); Sdl2Application::Modifiers modifiers();
private: private:
friend Sdl2Application; friend Sdl2Application;
@ -2886,7 +2914,7 @@ class Sdl2Application::PointerEvent: public InputEvent {
const PointerEventSource _source; const PointerEventSource _source;
const Pointer _pointer; const Pointer _pointer;
Containers::Optional<Modifiers> _modifiers; Containers::Optional<Sdl2Application::Modifiers> _modifiers;
const bool _primary; const bool _primary;
const Long _id; const Long _id;
const Vector2 _position; const Vector2 _position;
@ -2944,7 +2972,7 @@ class CORRADE_DEPRECATED("use PointerEvent, pointerPressEvent() and pointerRelea
* *
* Lazily populated on first request. * Lazily populated on first request.
*/ */
Modifiers modifiers(); Sdl2Application::Modifiers modifiers();
private: private:
friend Sdl2Application; friend Sdl2Application;
@ -2964,7 +2992,7 @@ class CORRADE_DEPRECATED("use PointerEvent, pointerPressEvent() and pointerRelea
#ifndef CORRADE_TARGET_EMSCRIPTEN #ifndef CORRADE_TARGET_EMSCRIPTEN
const Int _clickCount; const Int _clickCount;
#endif #endif
Containers::Optional<Modifiers> _modifiers; Containers::Optional<Sdl2Application::Modifiers> _modifiers;
}; };
#endif #endif
@ -3065,7 +3093,7 @@ class Sdl2Application::PointerMoveEvent: public InputEvent {
* *
* Lazily populated on first request. * Lazily populated on first request.
*/ */
Modifiers modifiers(); Sdl2Application::Modifiers modifiers();
private: private:
friend Sdl2Application; friend Sdl2Application;
@ -3076,7 +3104,7 @@ class Sdl2Application::PointerMoveEvent: public InputEvent {
const Containers::Optional<Pointer> _pointer; const Containers::Optional<Pointer> _pointer;
const Pointers _pointers; const Pointers _pointers;
const bool _primary; const bool _primary;
Containers::Optional<Modifiers> _modifiers; Containers::Optional<Sdl2Application::Modifiers> _modifiers;
const Long _id; const Long _id;
const Vector2 _position, _relativePosition; const Vector2 _position, _relativePosition;
}; };
@ -3134,7 +3162,7 @@ class CORRADE_DEPRECATED("use PointerMoveEvent and pointerMoveEvent() instead")
* *
* Lazily populated on first request. * Lazily populated on first request.
*/ */
Modifiers modifiers(); Sdl2Application::Modifiers modifiers();
private: private:
friend Sdl2Application; friend Sdl2Application;
@ -3143,7 +3171,7 @@ class CORRADE_DEPRECATED("use PointerMoveEvent and pointerMoveEvent() instead")
const Vector2i _position, _relativePosition; const Vector2i _position, _relativePosition;
const Buttons _buttons; const Buttons _buttons;
Containers::Optional<Modifiers> _modifiers; Containers::Optional<Sdl2Application::Modifiers> _modifiers;
}; };
CORRADE_IGNORE_DEPRECATED_PUSH CORRADE_IGNORE_DEPRECATED_PUSH
@ -3175,7 +3203,7 @@ class Sdl2Application::ScrollEvent: public Sdl2Application::InputEvent {
* *
* Lazily populated on first request. * Lazily populated on first request.
*/ */
Modifiers modifiers(); Sdl2Application::Modifiers modifiers();
private: private:
friend Sdl2Application; friend Sdl2Application;
@ -3184,7 +3212,7 @@ class Sdl2Application::ScrollEvent: public Sdl2Application::InputEvent {
const Vector2 _offset; const Vector2 _offset;
Containers::Optional<Vector2> _position; Containers::Optional<Vector2> _position;
Containers::Optional<Modifiers> _modifiers; Containers::Optional<Sdl2Application::Modifiers> _modifiers;
}; };
#ifdef MAGNUM_BUILD_DEPRECATED #ifdef MAGNUM_BUILD_DEPRECATED
@ -3212,7 +3240,7 @@ class CORRADE_DEPRECATED("use ScrollEvent and scrollEvent() instead") Sdl2Applic
* *
* Lazily populated on first request. * Lazily populated on first request.
*/ */
Modifiers modifiers(); Sdl2Application::Modifiers modifiers();
private: private:
friend Sdl2Application; friend Sdl2Application;
@ -3221,7 +3249,7 @@ class CORRADE_DEPRECATED("use ScrollEvent and scrollEvent() instead") Sdl2Applic
const Vector2 _offset; const Vector2 _offset;
Containers::Optional<Vector2i> _position; Containers::Optional<Vector2i> _position;
Containers::Optional<Modifiers> _modifiers; Containers::Optional<Sdl2Application::Modifiers> _modifiers;
}; };
#endif #endif
@ -3483,7 +3511,6 @@ typedef BasicScreenedApplication<Sdl2Application> ScreenedApplication;
#endif #endif
CORRADE_ENUMSET_OPERATORS(Sdl2Application::Configuration::WindowFlags) CORRADE_ENUMSET_OPERATORS(Sdl2Application::Configuration::WindowFlags)
CORRADE_ENUMSET_OPERATORS(Sdl2Application::InputEvent::Modifiers)
}} }}

22
src/Magnum/Platform/Test/AbstractXApplicationTest.cpp

@ -40,11 +40,11 @@ namespace Magnum { namespace Platform {
/* These cannot be in an anonymous namespace as enumSetDebugOutput() below /* These cannot be in an anonymous namespace as enumSetDebugOutput() below
wouldn't be able to pick them up */ 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; debug << "Modifier" << Debug::nospace;
switch(value) { 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(Shift)
_c(Ctrl) _c(Ctrl)
_c(Alt) _c(Alt)
@ -91,14 +91,14 @@ CORRADE_IGNORE_DEPRECATED_POP
namespace Test { namespace { namespace Test { namespace {
Debug& operator<<(Debug& debug, Application::InputEvent::Modifiers value) { Debug& operator<<(Debug& debug, Application::Modifiers value) {
return Containers::enumSetDebugOutput(debug, value, "Modifiers{}", { return Containers::enumSetDebugOutput(debug, value, "Modifiers{}", {
Application::InputEvent::Modifier::Shift, Application::Modifier::Shift,
Application::InputEvent::Modifier::Ctrl, Application::Modifier::Ctrl,
Application::InputEvent::Modifier::Alt, Application::Modifier::Alt,
Application::InputEvent::Modifier::AltGr, Application::Modifier::AltGr,
Application::InputEvent::Modifier::CapsLock, Application::Modifier::CapsLock,
Application::InputEvent::Modifier::NumLock, Application::Modifier::NumLock,
}); });
} }
@ -139,11 +139,11 @@ CORRADE_UNUSED Debug& operator<<(Debug& debug, Application::MouseMoveEvent::Butt
CORRADE_IGNORE_DEPRECATED_POP CORRADE_IGNORE_DEPRECATED_POP
#endif #endif
Debug& operator<<(Debug& debug, const Application::KeyEvent::Key value) { Debug& operator<<(Debug& debug, const Application::Key value) {
debug << "Key" << Debug::nospace; debug << "Key" << Debug::nospace;
switch(value) { 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(LeftShift)
_c(RightShift) _c(RightShift)
_c(LeftCtrl) _c(LeftCtrl)

30
src/Magnum/Platform/Test/EmscriptenApplicationTest.cpp

@ -51,11 +51,11 @@ namespace Magnum { namespace Platform {
/* These cannot be in an anonymous namespace as enumSetDebugOutput() below /* These cannot be in an anonymous namespace as enumSetDebugOutput() below
wouldn't be able to pick them up */ 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; debug << "Modifier" << Debug::nospace;
switch(value) { 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(Shift)
_c(Ctrl) _c(Ctrl)
_c(Alt) _c(Alt)
@ -120,12 +120,12 @@ static Debug& operator<<(Debug& debug, Application::PointerEventSource value) {
return debug << "(" << Debug::nospace << UnsignedInt(value) << Debug::nospace << ")"; 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{}", { return Containers::enumSetDebugOutput(debug, value, "Modifiers{}", {
Application::InputEvent::Modifier::Shift, Application::Modifier::Shift,
Application::InputEvent::Modifier::Ctrl, Application::Modifier::Ctrl,
Application::InputEvent::Modifier::Alt, Application::Modifier::Alt,
Application::InputEvent::Modifier::Super Application::Modifier::Super
}); });
} }
@ -168,11 +168,11 @@ CORRADE_UNUSED Debug& operator<<(Debug& debug, Application::MouseMoveEvent::Butt
CORRADE_IGNORE_DEPRECATED_POP CORRADE_IGNORE_DEPRECATED_POP
#endif #endif
Debug& operator<<(Debug& debug, const Application::KeyEvent::Key value) { Debug& operator<<(Debug& debug, const Application::Key value) {
debug << "Key" << Debug::nospace; debug << "Key" << Debug::nospace;
switch(value) { 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(Unknown)
_c(LeftShift) _c(LeftShift)
_c(RightShift) _c(RightShift)
@ -370,23 +370,23 @@ struct EmscriptenApplicationTest: Platform::Application {
void keyPressEvent(KeyEvent& event) override { void keyPressEvent(KeyEvent& event) override {
Debug{} << "key press:" << event.key() << event.keyName() << event.modifiers(); Debug{} << "key press:" << event.key() << event.keyName() << event.modifiers();
if(event.key() == KeyEvent::Key::F1) { if(event.key() == Key::F1) {
Debug{} << "starting text input"; Debug{} << "starting text input";
startTextInput(); startTextInput();
} else if(event.key() == KeyEvent::Key::F2) { } else if(event.key() == Key::F2) {
_redraw = !_redraw; _redraw = !_redraw;
Debug{} << "redrawing" << (_redraw ? "enabled" : "disabled"); Debug{} << "redrawing" << (_redraw ? "enabled" : "disabled");
if(_redraw) redraw(); if(_redraw) redraw();
} else if(event.key() == KeyEvent::Key::Esc) { } else if(event.key() == Key::Esc) {
Debug{} << "stopping text input"; Debug{} << "stopping text input";
stopTextInput(); stopTextInput();
} else if(event.key() == KeyEvent::Key::F) { } else if(event.key() == Key::F) {
Debug{} << "toggling fullscreen"; Debug{} << "toggling fullscreen";
setContainerCssClass((_fullscreen ^= true) ? "mn-fullsizeX"_s.exceptSuffix(1) : ""); 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"; Debug{} << "setting window title";
setWindowTitle("This is a UTF-8 Window Title™ and it should have no exclamation mark!!"_s.exceptSuffix(2)); 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"; Debug{} << "toggling hand cursor";
setCursor(cursor() == Cursor::Arrow ? Cursor::Hand : Cursor::Arrow); setCursor(cursor() == Cursor::Arrow ? Cursor::Hand : Cursor::Arrow);
} }

38
src/Magnum/Platform/Test/GlfwApplicationTest.cpp

@ -42,11 +42,11 @@ namespace Magnum { namespace Platform {
/* These cannot be in an anonymous namespace as enumSetDebugOutput() below /* These cannot be in an anonymous namespace as enumSetDebugOutput() below
wouldn't be able to pick them up */ 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; debug << "Modifier" << Debug::nospace;
switch(value) { 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(Shift)
_c(Ctrl) _c(Ctrl)
_c(Alt) _c(Alt)
@ -96,12 +96,12 @@ CORRADE_IGNORE_DEPRECATED_POP
namespace Test { namespace { namespace Test { namespace {
Debug& operator<<(Debug& debug, Application::InputEvent::Modifiers value) { Debug& operator<<(Debug& debug, Application::Modifiers value) {
return Containers::enumSetDebugOutput(debug, value, "Modifiers{}", { return Containers::enumSetDebugOutput(debug, value, "Modifiers{}", {
Application::InputEvent::Modifier::Shift, Application::Modifier::Shift,
Application::InputEvent::Modifier::Ctrl, Application::Modifier::Ctrl,
Application::InputEvent::Modifier::Alt, Application::Modifier::Alt,
Application::InputEvent::Modifier::Super Application::Modifier::Super
}); });
} }
@ -149,11 +149,11 @@ CORRADE_UNUSED Debug& operator<<(Debug& debug, Application::MouseMoveEvent::Butt
CORRADE_IGNORE_DEPRECATED_POP CORRADE_IGNORE_DEPRECATED_POP
#endif #endif
Debug& operator<<(Debug& debug, const Application::KeyEvent::Key value) { Debug& operator<<(Debug& debug, const Application::Key value) {
debug << "Key" << Debug::nospace; debug << "Key" << Debug::nospace;
switch(value) { 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(Unknown)
_c(LeftShift) _c(LeftShift)
_c(RightShift) _c(RightShift)
@ -301,36 +301,36 @@ struct GlfwApplicationTest: Platform::Application {
void keyPressEvent(KeyEvent& event) override { void keyPressEvent(KeyEvent& event) override {
Debug{} << "key press:" << event.key() << int(event.key()) << event.keyName() << event.modifiers(); 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"; Debug{} << "starting text input";
startTextInput(); startTextInput();
} else if(event.key() == KeyEvent::Key::F2) { } else if(event.key() == Key::F2) {
_redraw = !_redraw; _redraw = !_redraw;
Debug{} << "redrawing" << (_redraw ? "enabled" : "disabled"); Debug{} << "redrawing" << (_redraw ? "enabled" : "disabled");
if(_redraw) redraw(); if(_redraw) redraw();
} else if(event.key() == KeyEvent::Key::V) { } else if(event.key() == Key::V) {
_vsync = !_vsync; _vsync = !_vsync;
Debug{} << "vsync" << (_vsync? "on" : "off"); Debug{} << "vsync" << (_vsync? "on" : "off");
setSwapInterval(_vsync ? 1 : 0); setSwapInterval(_vsync ? 1 : 0);
} else if(event.key() == KeyEvent::Key::Esc) { } else if(event.key() == Key::Esc) {
Debug{} << "stopping text input"; Debug{} << "stopping text input";
stopTextInput(); stopTextInput();
} else if(event.key() == KeyEvent::Key::T) { } else if(event.key() == Key::T) {
Debug{} << "setting window title"; Debug{} << "setting window title";
setWindowTitle("This is a UTF-8 Window Title™ and it should have no exclamation mark!!"_s.exceptSuffix(2)); 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"; Debug{} << "setting window size, which should trigger a viewport event";
setWindowSize(Vector2i{300, 200}); 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"; Debug{} << "setting max window size, which should trigger a viewport event if the size changes";
setMaxWindowSize(Vector2i{700, 500}); setMaxWindowSize(Vector2i{700, 500});
} else if(event.key() == KeyEvent::Key::H) { } else if(event.key() == Key::H) {
Debug{} << "toggling hand cursor"; Debug{} << "toggling hand cursor";
setCursor(cursor() == Cursor::Arrow ? Cursor::Hand : Cursor::Arrow); 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"; Debug{} << "toggling locked mouse";
setCursor(cursor() == Cursor::Arrow ? Cursor::HiddenLocked : Cursor::Arrow); 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"; Debug{} << "requesting an exit with code 5";
exit(5); exit(5);
} }

46
src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp

@ -59,11 +59,11 @@ namespace Magnum { namespace Platform {
/* These cannot be in an anonymous namespace as enumSetDebugOutput() below /* These cannot be in an anonymous namespace as enumSetDebugOutput() below
wouldn't be able to pick them up */ 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; debug << "Modifier" << Debug::nospace;
switch(value) { 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(Shift)
_c(Ctrl) _c(Ctrl)
_c(Alt) _c(Alt)
@ -133,15 +133,15 @@ static Debug& operator<<(Debug& debug, Application::PointerEventSource value) {
return debug << "(" << Debug::nospace << UnsignedInt(value) << Debug::nospace << ")"; 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{}", { return Containers::enumSetDebugOutput(debug, value, "Modifiers{}", {
Application::InputEvent::Modifier::Shift, Application::Modifier::Shift,
Application::InputEvent::Modifier::Ctrl, Application::Modifier::Ctrl,
Application::InputEvent::Modifier::Alt, Application::Modifier::Alt,
Application::InputEvent::Modifier::Super, Application::Modifier::Super,
Application::InputEvent::Modifier::AltGr, Application::Modifier::AltGr,
Application::InputEvent::Modifier::CapsLock, Application::Modifier::CapsLock,
Application::InputEvent::Modifier::NumLock, Application::Modifier::NumLock,
}); });
} }
@ -188,11 +188,11 @@ CORRADE_UNUSED Debug& operator<<(Debug& debug, Application::MouseMoveEvent::Butt
CORRADE_IGNORE_DEPRECATED_POP CORRADE_IGNORE_DEPRECATED_POP
#endif #endif
Debug& operator<<(Debug& debug, Application::KeyEvent::Key value) { Debug& operator<<(Debug& debug, Application::Key value) {
debug << "Key" << Debug::nospace; debug << "Key" << Debug::nospace;
switch(value) { 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(Unknown)
_c(LeftShift) _c(LeftShift)
_c(RightShift) _c(RightShift)
@ -392,53 +392,53 @@ struct Sdl2ApplicationTest: Platform::Application {
#endif #endif
<< event.modifiers(); << event.modifiers();
if(event.key() == KeyEvent::Key::F1) { if(event.key() == Key::F1) {
Debug{} << "starting text input"; Debug{} << "starting text input";
startTextInput(); startTextInput();
} else if(event.key() == KeyEvent::Key::F2) { } else if(event.key() == Key::F2) {
_redraw = !_redraw; _redraw = !_redraw;
Debug{} << "redrawing" << (_redraw ? "enabled" : "disabled"); Debug{} << "redrawing" << (_redraw ? "enabled" : "disabled");
if(_redraw) redraw(); if(_redraw) redraw();
} }
#ifndef CORRADE_TARGET_EMSCRIPTEN #ifndef CORRADE_TARGET_EMSCRIPTEN
else if(event.key() == KeyEvent::Key::V) { else if(event.key() == Key::V) {
_vsync = !_vsync; _vsync = !_vsync;
Debug{} << "vsync" << (_vsync? "on" : "off"); Debug{} << "vsync" << (_vsync? "on" : "off");
setSwapInterval(_vsync ? 1 : 0); setSwapInterval(_vsync ? 1 : 0);
} }
#endif #endif
else if(event.key() == KeyEvent::Key::Esc) { else if(event.key() == Key::Esc) {
Debug{} << "stopping text input"; Debug{} << "stopping text input";
stopTextInput(); stopTextInput();
} else if(event.key() == KeyEvent::Key::T) { } else if(event.key() == Key::T) {
Debug{} << "setting window title"; Debug{} << "setting window title";
setWindowTitle("This is a UTF-8 Window Title™ and it should have no exclamation mark!!"_s.exceptSuffix(2)); setWindowTitle("This is a UTF-8 Window Title™ and it should have no exclamation mark!!"_s.exceptSuffix(2));
} }
#ifndef CORRADE_TARGET_EMSCRIPTEN #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"; Debug{} << "setting window size, which should trigger a viewport event";
setWindowSize(Vector2i{300, 200}); 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"; Debug{} << "setting max window size, which should trigger a viewport event";
setMaxWindowSize(Vector2i{700, 500}); setMaxWindowSize(Vector2i{700, 500});
} }
#endif #endif
else if(event.key() == KeyEvent::Key::H) { else if(event.key() == Key::H) {
Debug{} << "toggling hand cursor"; Debug{} << "toggling hand cursor";
setCursor(cursor() == Cursor::Arrow ? Cursor::Hand : Cursor::Arrow); setCursor(cursor() == Cursor::Arrow ? Cursor::Hand : Cursor::Arrow);
} }
#ifndef CORRADE_TARGET_EMSCRIPTEN #ifndef CORRADE_TARGET_EMSCRIPTEN
else if(event.key() == KeyEvent::Key::L) { else if(event.key() == Key::L) {
Debug{} << "toggling locked mouse"; Debug{} << "toggling locked mouse";
setCursor(cursor() == Cursor::Arrow ? Cursor::HiddenLocked : Cursor::Arrow); setCursor(cursor() == Cursor::Arrow ? Cursor::HiddenLocked : Cursor::Arrow);
} }
#else #else
else if(event.key() == KeyEvent::Key::F) { else if(event.key() == Key::F) {
Debug{} << "toggling fullscreen"; Debug{} << "toggling fullscreen";
setContainerCssClass((_fullscreen ^= true) ? "mn-fullsize" : ""); setContainerCssClass((_fullscreen ^= true) ? "mn-fullsize" : "");
} }
#endif #endif
else if(event.key() == KeyEvent::Key::X) { else if(event.key() == Key::X) {
Debug{} << "requesting an exit with code 5"; Debug{} << "requesting an exit with code 5";
exit(5); exit(5);
} }

Loading…
Cancel
Save