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. 1017
      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. 891
      src/Magnum/Platform/GlfwApplication.h
  8. 30
      src/Magnum/Platform/Screen.h
  9. 32
      src/Magnum/Platform/Sdl2Application.cpp
  10. 973
      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::BasicScreenedApplication / @ref Platform::BasicScreen
wrappers as well.
- @cpp Platform::Sdl2Application::InputEvent::Modifier @ce,
@cpp Modifiers @ce and @cpp Platform::Sdl2Application::KeyEvent::Key @ce
enums are deprecated in favor of @ref Platform::Sdl2Application::Modifier,
@relativeref{Platform::Sdl2Application,Modifiers} and
@relativeref{Platform::Sdl2Application,Key} enums contained directly in
the application class. Besides the obvious advantage of them being shorter
to type, this allows them to be used outside of the event class scope. The
same change is done in @ref Platform::AbstractXApplication,
@ref Platform::EmscriptenApplication and @ref Platform::GlfwApplication.
- @cpp Platform::AbstractXApplication::MouseEvent::Button::WheelUp @ce and
`WheelDown` members are deprecated in favor of a dedicated
@ref Platform::AbstractXApplication::scrollEvent(). Similar change was done

2
src/Magnum/Platform/AbstractXApplication.cpp

@ -197,7 +197,7 @@ bool AbstractXApplication::mainLoopIteration() {
/* Key/mouse events */
case KeyPress:
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);
} break;
case ButtonPress:

1017
src/Magnum/Platform/AbstractXApplication.h

File diff suppressed because it is too large Load Diff

38
src/Magnum/Platform/EmscriptenApplication.cpp

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

527
src/Magnum/Platform/EmscriptenApplication.h

@ -343,10 +343,22 @@ class EmscriptenApplication {
/* The damn thing cannot handle forward enum declarations */
#ifndef DOXYGEN_GENERATING_OUTPUT
enum class Modifier: Int;
enum class Key: Int;
enum class PointerEventSource: UnsignedByte;
enum class Pointer: UnsignedByte;
#endif
/**
* @brief Set of keyboard modifiers
* @m_since_latest
*
* @see @ref KeyEvent::modifiers(), @ref PointerEvent::modifiers(),
* @ref PointerMoveEvent::modifiers(),
* @ref ScrollEvent::modifiers()
*/
typedef Containers::EnumSet<Modifier> Modifiers;
/**
* @brief Set of pointer types
* @m_since_latest
@ -1099,6 +1111,242 @@ class EmscriptenApplication {
int (*_callback)(void*);
};
/**
@brief Keyboard modifier
@m_since_latest
@see @ref Modifiers, @ref KeyEvent::modifiers(),
@ref PointerEvent::modifiers(), @ref PointerMoveEvent::modifiers(),
@ref ScrollEvent::modifiers()
*/
enum class EmscriptenApplication::Modifier: Int {
/**
* Shift
*
* @see @ref KeyEvent::Key::LeftShift, @ref KeyEvent::Key::RightShift
*/
Shift = 1 << 0,
/**
* Ctrl
*
* @see @ref KeyEvent::Key::LeftCtrl, @ref KeyEvent::Key::RightCtrl
*/
Ctrl = 1 << 1,
/**
* Alt
*
* @see @ref KeyEvent::Key::LeftAlt, @ref KeyEvent::Key::RightAlt
*/
Alt = 1 << 2,
/**
* Super key (Windows/)
*
* @see @ref KeyEvent::Key::LeftSuper, @ref KeyEvent::Key::RightSuper
*/
Super = 1 << 3
};
CORRADE_ENUMSET_OPERATORS(EmscriptenApplication::Modifiers)
/**
@brief Key
@m_since_latest
@see @ref KeyEvent::key()
*/
enum class EmscriptenApplication::Key: Int {
Unknown, /**< Unknown key */
/**
* Left Shift
*
* @see @ref InputEvent::Modifier::Shift
*/
LeftShift,
/**
* Right Shift
*
* @see @ref InputEvent::Modifier::Shift
*/
RightShift,
/**
* Left Ctrl
*
* @see @ref InputEvent::Modifier::Ctrl
*/
LeftCtrl,
/**
* Right Ctrl
*
* @see @ref InputEvent::Modifier::Ctrl
*/
RightCtrl,
/**
* Left Alt
*
* @see @ref InputEvent::Modifier::Alt
*/
LeftAlt,
/**
* Right Alt
*
* @see @ref InputEvent::Modifier::Alt
*/
RightAlt,
/**
* Left Super key (Windows/)
*
* @see @ref InputEvent::Modifier::Super
*/
LeftSuper,
/**
* Right Super key (Windows/)
*
* @see @ref InputEvent::Modifier::Super
*/
RightSuper,
/* no equivalent for Sdl2Application's AltGr */
Enter, /**< Enter */
Esc, /**< Escape */
Up, /**< Up arrow */
Down, /**< Down arrow */
Left, /**< Left arrow */
Right, /**< Right arrow */
Home, /**< Home */
End, /**< End */
PageUp, /**< Page up */
PageDown, /**< Page down */
Backspace, /**< Backspace */
Insert, /**< Insert */
Delete, /**< Delete */
F1, /**< F1 */
F2, /**< F2 */
F3, /**< F3 */
F4, /**< F4 */
F5, /**< F5 */
F6, /**< F6 */
F7, /**< F7 */
F8, /**< F8 */
F9, /**< F9 */
F10, /**< F10 */
F11, /**< F11 */
F12, /**< F12 */
Zero = '0', /**< Zero */
One, /**< One */
Two, /**< Two */
Three, /**< Three */
Four, /**< Four */
Five, /**< Five */
Six, /**< Six */
Seven, /**< Seven */
Eight, /**< Eight */
Nine, /**< Nine */
A = 'a', /**< Letter A */
B, /**< Letter B */
C, /**< Letter C */
D, /**< Letter D */
E, /**< Letter E */
F, /**< Letter F */
G, /**< Letter G */
H, /**< Letter H */
I, /**< Letter I */
J, /**< Letter J */
K, /**< Letter K */
L, /**< Letter L */
M, /**< Letter M */
N, /**< Letter N */
O, /**< Letter O */
P, /**< Letter P */
Q, /**< Letter Q */
R, /**< Letter R */
S, /**< Letter S */
T, /**< Letter T */
U, /**< Letter U */
V, /**< Letter V */
W, /**< Letter W */
X, /**< Letter X */
Y, /**< Letter Y */
Z, /**< Letter Z */
Space, /**< Space */
Tab, /**< Tab */
Quote, /**< Quote (<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
@m_since_latest
@ -1712,52 +1960,21 @@ class EmscriptenApplication::ViewportEvent {
*/
class EmscriptenApplication::InputEvent {
public:
#ifdef MAGNUM_BUILD_DEPRECATED
/**
* @brief Modifier
*
* @see @ref Modifiers, @ref KeyEvent::modifiers(),
* @ref PointerEvent::modifiers(),
* @ref PointerMoveEvent::modifiers(),
* @ref ScrollEvent::modifiers()
*/
enum class Modifier: Int {
/**
* Shift
*
* @see @ref KeyEvent::Key::LeftShift, @ref KeyEvent::Key::RightShift
*/
Shift = 1 << 0,
/**
* Ctrl
*
* @see @ref KeyEvent::Key::LeftCtrl, @ref KeyEvent::Key::RightCtrl
*/
Ctrl = 1 << 1,
/**
* Alt
*
* @see @ref KeyEvent::Key::LeftAlt, @ref KeyEvent::Key::RightAlt
* @brief @copybrief EmscriptenApplication::Modifier
* @m_deprecated_since_latest Use @ref EmscriptenApplication::Modifier
* instead.
*/
Alt = 1 << 2,
typedef CORRADE_DEPRECATED("use EmscriptenApplication::Modifier instead") EmscriptenApplication::Modifier Modifier;
/**
* Super key (Windows/)
*
* @see @ref KeyEvent::Key::LeftSuper, @ref KeyEvent::Key::RightSuper
*/
Super = 1 << 3
};
/**
* @brief Set of modifiers
*
* @see @ref KeyEvent::modifiers(), @ref PointerEvent::modifiers(),
* @ref PointerMoveEvent::modifiers(),
* @ref ScrollEvent::modifiers()
* @brief @copybrief EmscriptenApplication::Modifiers
* @m_deprecated_since_latest Use @ref EmscriptenApplication::Modifiers
* instead.
*/
typedef Containers::EnumSet<Modifier> Modifiers;
typedef CORRADE_DEPRECATED("use EmscriptenApplication::Modifiers instead") EmscriptenApplication::Modifiers Modifiers;
#endif
/** @brief Copying is not allowed */
InputEvent(const InputEvent&) = delete;
@ -1792,8 +2009,6 @@ class EmscriptenApplication::InputEvent {
bool _accepted;
};
CORRADE_ENUMSET_OPERATORS(EmscriptenApplication::InputEvent::Modifiers)
/**
@brief Pointer event
@m_since_latest
@ -1856,7 +2071,7 @@ class EmscriptenApplication::PointerEvent: public InputEvent {
Vector2 position() const { return _position; }
/** @brief Modifiers */
Modifiers modifiers() const { return _modifiers; }
EmscriptenApplication::Modifiers modifiers() const { return _modifiers; }
/**
* @brief Underlying Emscripten event
@ -1874,16 +2089,16 @@ class EmscriptenApplication::PointerEvent: public InputEvent {
private:
friend EmscriptenApplication;
explicit PointerEvent(const EmscriptenMouseEvent& event, Pointer pointer, Modifiers modifiers, const Vector2& position): _event{&event}, _source{PointerEventSource::Mouse}, _primary{true}, _pointer{pointer}, _modifiers{modifiers}, _id{~Int{}}, _position{position} {}
explicit PointerEvent(const EmscriptenMouseEvent& event, Pointer pointer, EmscriptenApplication::Modifiers modifiers, const Vector2& position): _event{&event}, _source{PointerEventSource::Mouse}, _primary{true}, _pointer{pointer}, _modifiers{modifiers}, _id{~Int{}}, _position{position} {}
#if __EMSCRIPTEN_major__*10000 + __EMSCRIPTEN_minor__*100 + __EMSCRIPTEN_tiny__ >= 20027
explicit PointerEvent(const EmscriptenTouchEvent& event, bool primary, Int id, Modifiers modifiers, const Vector2& position): _event{&event}, _source{PointerEventSource::Touch}, _primary{primary}, _pointer{Pointer::Finger}, _modifiers{modifiers}, _id{id}, _position{position} {}
explicit PointerEvent(const EmscriptenTouchEvent& event, bool primary, Int id, EmscriptenApplication::Modifiers modifiers, const Vector2& position): _event{&event}, _source{PointerEventSource::Touch}, _primary{primary}, _pointer{Pointer::Finger}, _modifiers{modifiers}, _id{id}, _position{position} {}
#endif
const void* _event;
const PointerEventSource _source;
const bool _primary;
const Pointer _pointer;
const Modifiers _modifiers;
const EmscriptenApplication::Modifiers _modifiers;
const Int _id;
const Vector2 _position;
};
@ -2038,7 +2253,7 @@ class EmscriptenApplication::PointerMoveEvent: public InputEvent {
Vector2 relativePosition() const { return _relativePosition; }
/** @brief Modifiers */
Modifiers modifiers() const { return _modifiers; }
EmscriptenApplication::Modifiers modifiers() const { return _modifiers; }
/**
* @brief Underlying Emscripten event
@ -2056,9 +2271,9 @@ class EmscriptenApplication::PointerMoveEvent: public InputEvent {
private:
friend EmscriptenApplication;
explicit PointerMoveEvent(const EmscriptenMouseEvent& event, Containers::Optional<Pointer> 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
explicit PointerMoveEvent(const EmscriptenTouchEvent& event, bool primary, Int id, Modifiers modifiers, const Vector2& position, const Vector2& relativePosition): _event{&event}, _source{PointerEventSource::Touch}, _primary{primary}, _pointer{}, _pointers{Pointer::Finger}, _modifiers{modifiers}, _id{id}, _position{position}, _relativePosition{relativePosition} {}
explicit PointerMoveEvent(const EmscriptenTouchEvent& event, bool primary, Int id, EmscriptenApplication::Modifiers modifiers, const Vector2& position, const Vector2& relativePosition): _event{&event}, _source{PointerEventSource::Touch}, _primary{primary}, _pointer{}, _pointers{Pointer::Finger}, _modifiers{modifiers}, _id{id}, _position{position}, _relativePosition{relativePosition} {}
#endif
const void* _event;
@ -2066,7 +2281,7 @@ class EmscriptenApplication::PointerMoveEvent: public InputEvent {
const bool _primary;
const Containers::Optional<Pointer> _pointer;
const Pointers _pointers;
const Modifiers _modifiers;
const EmscriptenApplication::Modifiers _modifiers;
const Int _id;
const Vector2 _position;
const Vector2 _relativePosition;
@ -2140,7 +2355,7 @@ class CORRADE_DEPRECATED("use PointerMoveEvent and pointerMoveEvent() instead")
Buttons buttons() const;
/** @brief Modifiers */
Modifiers modifiers() const;
EmscriptenApplication::Modifiers modifiers() const;
/** @brief Underlying Emscripten event */
const EmscriptenMouseEvent& event() const { return _event; }
@ -2178,7 +2393,7 @@ class EmscriptenApplication::ScrollEvent: public EmscriptenApplication::InputEve
Vector2 position() const;
/** @brief Modifiers */
Modifiers modifiers() const;
EmscriptenApplication::Modifiers modifiers() const;
/** @brief Underlying Emscripten event */
const EmscriptenWheelEvent& event() const { return _event; }
@ -2208,7 +2423,7 @@ class CORRADE_DEPRECATED("use ScrollEvent and scrollEvent() instead") Emscripten
Vector2i position() const;
/** @brief Modifiers */
Modifiers modifiers() const;
EmscriptenApplication::Modifiers modifiers() const;
/** @brief Underlying Emscripten event */
const EmscriptenWheelEvent& event() const { return _event; }
@ -2229,202 +2444,14 @@ class CORRADE_DEPRECATED("use ScrollEvent and scrollEvent() instead") Emscripten
*/
class EmscriptenApplication::KeyEvent: public EmscriptenApplication::InputEvent {
public:
#ifdef MAGNUM_BUILD_DEPRECATED
/**
* @brief Key
*
* @see @ref key()
*/
enum class Key: Int {
Unknown, /**< Unknown key */
/**
* Left Shift
*
* @see @ref InputEvent::Modifier::Shift
*/
LeftShift,
/**
* Right Shift
*
* @see @ref InputEvent::Modifier::Shift
*/
RightShift,
/**
* Left Ctrl
*
* @see @ref InputEvent::Modifier::Ctrl
*/
LeftCtrl,
/**
* Right Ctrl
*
* @see @ref InputEvent::Modifier::Ctrl
*/
RightCtrl,
/**
* Left Alt
*
* @see @ref InputEvent::Modifier::Alt
*/
LeftAlt,
/**
* Right Alt
*
* @see @ref InputEvent::Modifier::Alt
*/
RightAlt,
/**
* Left Super key (Windows/)
*
* @see @ref InputEvent::Modifier::Super
*/
LeftSuper,
/**
* Right Super key (Windows/)
*
* @see @ref InputEvent::Modifier::Super
*/
RightSuper,
/* no equivalent for Sdl2Application's AltGr */
Enter, /**< Enter */
Esc, /**< Escape */
Up, /**< Up arrow */
Down, /**< Down arrow */
Left, /**< Left arrow */
Right, /**< Right arrow */
Home, /**< Home */
End, /**< End */
PageUp, /**< Page up */
PageDown, /**< Page down */
Backspace, /**< Backspace */
Insert, /**< Insert */
Delete, /**< Delete */
F1, /**< F1 */
F2, /**< F2 */
F3, /**< F3 */
F4, /**< F4 */
F5, /**< F5 */
F6, /**< F6 */
F7, /**< F7 */
F8, /**< F8 */
F9, /**< F9 */
F10, /**< F10 */
F11, /**< F11 */
F12, /**< F12 */
Zero = '0', /**< Zero */
One, /**< One */
Two, /**< Two */
Three, /**< Three */
Four, /**< Four */
Five, /**< Five */
Six, /**< Six */
Seven, /**< Seven */
Eight, /**< Eight */
Nine, /**< Nine */
A = 'a', /**< Letter A */
B, /**< Letter B */
C, /**< Letter C */
D, /**< Letter D */
E, /**< Letter E */
F, /**< Letter F */
G, /**< Letter G */
H, /**< Letter H */
I, /**< Letter I */
J, /**< Letter J */
K, /**< Letter K */
L, /**< Letter L */
M, /**< Letter M */
N, /**< Letter N */
O, /**< Letter O */
P, /**< Letter P */
Q, /**< Letter Q */
R, /**< Letter R */
S, /**< Letter S */
T, /**< Letter T */
U, /**< Letter U */
V, /**< Letter V */
W, /**< Letter W */
X, /**< Letter X */
Y, /**< Letter Y */
Z, /**< Letter Z */
Space, /**< Space */
Tab, /**< Tab */
Quote, /**< Quote (<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}
* @brief @copybrief EmscriptenApplication::Key
* @m_deprecated_since_latest Use @ref EmscriptenApplication::Key
* instead.
*/
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 */
};
typedef CORRADE_DEPRECATED("use EmscriptenApplication::Key instead") EmscriptenApplication::Key Key;
#endif
/**
* @brief Key
@ -2435,7 +2462,7 @@ class EmscriptenApplication::KeyEvent: public EmscriptenApplication::InputEvent
* @m_class{m-doc-external} [EmscriptenkeyboardEvent::key](https://emscripten.org/docs/api_reference/html5.h.html#c.EmscriptenKeyboardEvent.key),
* which respects the keyboard layout.
*/
Key key() const;
EmscriptenApplication::Key key() const;
/**
* @brief Key name
@ -2447,7 +2474,7 @@ class EmscriptenApplication::KeyEvent: public EmscriptenApplication::InputEvent
Containers::StringView keyName() const;
/** @brief Modifiers */
Modifiers modifiers() const;
EmscriptenApplication::Modifiers modifiers() const;
/** @brief Underlying Emscripten event */
const EmscriptenKeyboardEvent& event() const { return _event; }

28
src/Magnum/Platform/GlfwApplication.cpp

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

891
src/Magnum/Platform/GlfwApplication.h

File diff suppressed because it is too large Load Diff

30
src/Magnum/Platform/Screen.h

@ -53,6 +53,9 @@ CORRADE_ENUMSET_OPERATORS(PropagatedScreenEvents)
template<class Application, bool> class ScreenKeyEventMixin {};
template<class Application> class ScreenKeyEventMixin<Application, true> {
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;
private:
@ -192,6 +195,33 @@ template<class Application> class BasicScreen:
typedef typename BasicScreenedApplication<Application>::InputEvent InputEvent;
#ifdef DOXYGEN_GENERATING_OUTPUT
/**
* @brief Keyboard modifier
* @m_since_latest
*
* Defined only if the application has a
* @relativeref{Sdl2Application,KeyEvent}.
*/
typedef typename BasicScreenedApplication<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
*

32
src/Magnum/Platform/Sdl2Application.cpp

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

973
src/Magnum/Platform/Sdl2Application.h

File diff suppressed because it is too large Load Diff

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

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

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

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

Loading…
Cancel
Save