Browse Source

Platform: make XApp, GlfwApp, ScreenedApp touch-compatible.

AbstractXApplication and GlfwApplication don't implement touch events,
but for painless portability now expose also source(), isPrimary() and
id() like the touch-aware app implementations. The Screen abstraction
now exposes also the PointerEventSource enum.
pull/651/head
Vladimír Vondruš 2 years ago
parent
commit
82e9c6e5ab
  1. 77
      src/Magnum/Platform/AbstractXApplication.h
  2. 98
      src/Magnum/Platform/GlfwApplication.h
  3. 6
      src/Magnum/Platform/Screen.h

77
src/Magnum/Platform/AbstractXApplication.h

@ -115,6 +115,7 @@ class AbstractXApplication {
/* The damn thing cannot handle forward enum declarations */
#ifndef DOXYGEN_GENERATING_OUTPUT
enum class PointerEventSource: UnsignedByte;
enum class Pointer: UnsignedByte;
#endif
@ -453,6 +454,21 @@ class AbstractXApplication {
Flags _flags;
};
/**
@brief Pointer event source
@m_since_latest
@see @ref PointerEvent::source(), @ref PointerMoveEvent::source()
*/
enum class AbstractXApplication::PointerEventSource: UnsignedByte {
/**
* The event is coming from a mouse
* @see @ref Pointer::MouseLeft, @ref Pointer::MouseMiddle,
* @ref Pointer::MouseRight
*/
Mouse,
};
/**
@brief Pointer type
@m_since_latest
@ -462,16 +478,21 @@ class AbstractXApplication {
@ref ScrollEvent::pointers()
*/
enum class AbstractXApplication::Pointer: UnsignedByte {
/** Left mouse button. Corresponds to `Button1` / `Button1Mask`. */
/**
* Left mouse button. Corresponds to `Button1` / `Button1Mask`.
* @see @ref PointerEventSource::Mouse
*/
MouseLeft = 1 << 0,
/**
* Middle mouse button. Corresponds to `Button2` / `Button2Mask`.
* @see @ref PointerEventSource::Mouse
*/
MouseMiddle = 1 << 1,
/**
* Right mouse button. Corresponds to `Button3` / `Button3Mask`.
* @see @ref PointerEventSource::Mouse
*/
MouseRight = 1 << 2
};
@ -1211,9 +1232,36 @@ class AbstractXApplication::PointerEvent: public InputEvent {
/** @brief Moving is not allowed */
PointerEvent& operator=(PointerEvent&&) = delete;
/**
* @brief Pointer event source
*
* Included mainly for compatibility with touch-aware application
* implementations such as @ref Sdl2Application, returns always
* @ref PointerEventSource::Mouse.
*/
PointerEventSource source() const { return PointerEventSource::Mouse; }
/** @brief Pointer type that was pressed or released */
Pointer pointer() const { return _pointer; }
/**
* @brief Whether the pointer is primary
*
* Included mainly for compatibility with touch-aware application
* implementations such as @ref Sdl2Application, returns always
* @cpp true @ce.
*/
bool isPrimary() const { return true; }
/**
* @brief Pointer ID
*
* Included mainly for compatibility with touch-aware application
* implementations such as @ref Sdl2Application, returns always
* @cpp 0 @ce.
*/
Long id() const { return 0; }
/**
* @brief Position
*
@ -1303,6 +1351,15 @@ class AbstractXApplication::PointerMoveEvent: public InputEvent {
/** @brief Moving is not allowed */
PointerMoveEvent& operator=(PointerMoveEvent&&) = delete;
/**
* @brief Pointer event source
*
* Included mainly for compatibility with touch-aware application
* implementations such as @ref Sdl2Application, returns always
* @ref PointerEventSource::Mouse.
*/
PointerEventSource source() const { return PointerEventSource::Mouse; }
/**
* @brief Pointer type that was added or removed from the set of pressed pointers
*
@ -1323,6 +1380,24 @@ class AbstractXApplication::PointerMoveEvent: public InputEvent {
*/
Pointers pointers() const { return _pointers; }
/**
* @brief Whether the pointer is primary
*
* Included mainly for compatibility with touch-aware application
* implementations such as @ref Sdl2Application, returns always
* @cpp true @ce.
*/
bool isPrimary() const { return true; }
/**
* @brief Pointer ID
*
* Included mainly for compatibility with touch-aware application
* implementations such as @ref Sdl2Application, returns always
* @cpp 0 @ce.
*/
Long id() const { return 0; }
/**
* @brief Position
*

98
src/Magnum/Platform/GlfwApplication.h

@ -190,6 +190,7 @@ class GlfwApplication {
/* The damn thing cannot handle forward enum declarations */
#ifndef DOXYGEN_GENERATING_OUTPUT
enum class PointerEventSource: UnsignedByte;
enum class Pointer: UnsignedByte;
#endif
@ -937,6 +938,23 @@ class GlfwApplication {
Vector2 _previousMouseMovePosition{Constants::nan()};
};
/**
@brief Pointer event source
@m_since_latest
@see @ref PointerEvent::source(), @ref PointerMoveEvent::source()
*/
enum class GlfwApplication::PointerEventSource: UnsignedByte {
/**
* The event is coming from a mouse
* @see @ref Pointer::MouseLeft, @ref Pointer::MouseMiddle,
* @ref Pointer::MouseRight, @ref Pointer::MouseButton4,
* @ref Pointer::MouseButton5, @ref Pointer::MouseButton6,
* @ref Pointer::MouseButton7, @ref Pointer::MouseButton8
*/
Mouse
};
/**
@brief Pointer type
@m_since_latest
@ -948,41 +966,61 @@ enum class GlfwApplication::Pointer: UnsignedByte {
/**
* Left mouse button. Corresponds to `GLFW_MOUSE_BUTTON_LEFT` or
* `GLFW_MOUSE_BUTTON_1`.
* @see @ref PointerEventSource::Mouse
*/
MouseLeft = 1 << 0,
/**
* Middle mouse button. Corresponds to `GLFW_MOUSE_BUTTON_MIDDLE` or
* `GLFW_MOUSE_BUTTON_2`.
* @see @ref PointerEventSource::Mouse
*/
MouseMiddle = 1 << 1,
/**
* Right mouse button. Corresponds to `GLFW_MOUSE_BUTTON_RIGHT` or
* `GLFW_MOUSE_BUTTON_3`.
* @see @ref PointerEventSource::Mouse
*/
MouseRight = 1 << 2,
/**
* Fourth mouse button, such as wheel left. Corresponds to
* `GLFW_MOUSE_BUTTON_4`.
* @see @ref PointerEventSource::Mouse
*/
MouseButton4 = 1 << 3,
/**
* Fifth mouse button, such as wheel right. Corresponds to
* `GLFW_MOUSE_BUTTON_5`.
* @see @ref PointerEventSource::Mouse
*/
MouseButton5 = 1 << 4,
/** Sixth mouse button. Corresponds to `GLFW_MOUSE_BUTTON_6`. */
/**
* Sixth mouse button. Corresponds to `GLFW_MOUSE_BUTTON_6`.
* @see @ref PointerEventSource::Mouse
*/
MouseButton6 = 1 << 5,
/** Seventh mouse button. Corresponds to `GLFW_MOUSE_BUTTON_7`. */
/**
* Seventh mouse button. Corresponds to `GLFW_MOUSE_BUTTON_7`.
* @see @ref PointerEventSource::Mouse
*/
MouseButton7 = 1 << 6,
/** Eighth mouse button. Corresponds to `GLFW_MOUSE_BUTTON_8`. */
/**
* Eighth mouse button. Corresponds to `GLFW_MOUSE_BUTTON_8`.
* @see @ref PointerEventSource::Mouse
*/
MouseButton8 = 1 << 7
/** @todo look into touch / pen input once anything from
https://github.com/glfw/glfw/issues/42
https://github.com/glfw/glfw/issues/403
https://github.com/glfw/glfw/pull/1445
https://github.com/glfw/glfw/pull/1736 gets any updates */
};
CORRADE_ENUMSET_OPERATORS(GlfwApplication::Pointers)
@ -2132,9 +2170,36 @@ class GlfwApplication::PointerEvent: public InputEvent {
/** @brief Moving is not allowed */
PointerEvent& operator=(PointerEvent&&) = delete;
/**
* @brief Pointer event source
*
* Included mainly for compatibility with touch-aware application
* implementations such as @ref Sdl2Application, returns always
* @ref PointerEventSource::Mouse.
*/
PointerEventSource source() const { return PointerEventSource::Mouse; }
/** @brief Pointer type that was pressed or released */
Pointer pointer() const { return _pointer; }
/**
* @brief Whether the pointer is primary
*
* Included mainly for compatibility with touch-aware application
* implementations such as @ref Sdl2Application, returns always
* @cpp true @ce.
*/
bool isPrimary() const { return true; }
/**
* @brief Pointer ID
*
* Included mainly for compatibility with touch-aware application
* implementations such as @ref Sdl2Application, returns always
* @cpp 0 @ce.
*/
Long id() const { return 0; }
/**
* @brief Position
*
@ -2228,6 +2293,15 @@ class GlfwApplication::PointerMoveEvent: public InputEvent {
/** @brief Moving is not allowed */
PointerMoveEvent& operator=(PointerMoveEvent&&) = delete;
/**
* @brief Pointer event source
*
* Included mainly for compatibility with touch-aware application
* implementations such as @ref Sdl2Application, returns always
* @ref PointerEventSource::Mouse.
*/
PointerEventSource source() const { return PointerEventSource::Mouse; }
/**
* @brief Pointer type that was added or removed from the set of pressed pointers
*
@ -2249,6 +2323,24 @@ class GlfwApplication::PointerMoveEvent: public InputEvent {
*/
Pointers pointers();
/**
* @brief Whether the pointer is primary
*
* Included mainly for compatibility with touch-aware application
* implementations such as @ref Sdl2Application, returns always
* @cpp true @ce.
*/
bool isPrimary() const { return true; }
/**
* @brief Pointer ID
*
* Included mainly for compatibility with touch-aware application
* implementations such as @ref Sdl2Application, returns always
* @cpp 0 @ce.
*/
Long id() const { return 0; }
/**
* @brief Position
*

6
src/Magnum/Platform/Screen.h

@ -201,6 +201,12 @@ template<class Application> class BasicScreen:
typedef typename BasicScreenedApplication<Application>::KeyEvent KeyEvent;
#endif
/**
* @brief Pointer event source
* @m_since_latest
*/
typedef typename BasicScreenedApplication<Application>::PointerEventSource PointerEventSource;
/**
* @brief Pointer type
* @m_since_latest

Loading…
Cancel
Save