@ -178,11 +178,28 @@ class GlfwApplication {
class ViewportEvent ;
class InputEvent ;
class KeyEvent ;
class PointerEvent ;
class PointerMoveEvent ;
# ifdef MAGNUM_BUILD_DEPRECATED
class MouseEvent ;
class MouseMoveEvent ;
# endif
class MouseScrollEvent ;
class TextInputEvent ;
/* The damn thing cannot handle forward enum declarations */
# ifndef DOXYGEN_GENERATING_OUTPUT
enum class Pointer : UnsignedByte ;
# endif
/**
* @ brief Set of pointer types
* @ m_since_latest
*
* @ see @ ref PointerMoveEvent : : pointers ( )
*/
typedef Containers : : EnumSet < Pointer > Pointers ;
# ifdef MAGNUM_TARGET_GL
/**
* @ brief Construct with an OpenGL context
@ -596,7 +613,7 @@ class GlfwApplication {
* @ }
*/
/** @{ @name Mouse handling */
/** @{ @name Pointer handling */
public :
/**
@ -674,19 +691,90 @@ class GlfwApplication {
}
private :
/** @copydoc Sdl2Application::mousePressEvent() */
virtual void mousePressEvent ( MouseEvent & event ) ;
/**
* @ brief Pointer press event
* @ m_since_latest
*
* Called when a mouse is pressed . Note that if at least one mouse
* button is already pressed and another button gets pressed in
* addition , @ ref pointerMoveEvent ( ) with the new combination is
* called , not this function .
*
* On builds with @ ref MAGNUM_BUILD_DEPRECATED enabled , default
* implementation delegates to @ ref mousePressEvent ( ) . On builds with
* deprecated functionality disabled , default implementation does
* nothing .
*/
virtual void pointerPressEvent ( PointerEvent & event ) ;
# ifdef MAGNUM_BUILD_DEPRECATED
/**
* @ brief Mouse press event
* @ m_deprecated_since_latest Use @ ref pointerPressEvent ( ) instead ,
* which is a better abstraction for covering both mouse and touch
* / pen input .
*
* Default implementation does nothing .
*/
virtual CORRADE_DEPRECATED ( " use pointerPressEvent() instead " ) void mousePressEvent(MouseEvent& event) ;
# endif
/**
* @ brief Pointer release event
* @ m_since_latest
*
* Called when a mouse is released . Note that if multiple mouse buttons
* are pressed and one of these is released , @ ref pointerMoveEvent ( )
* with the new combination is called , not this function .
*
* On builds with @ ref MAGNUM_BUILD_DEPRECATED enabled , default
* implementation delegates to @ ref mouseReleaseEvent ( ) . On builds with
* deprecated functionality disabled , default implementation does
* nothing .
*/
virtual void pointerReleaseEvent ( PointerEvent & event ) ;
/** @copydoc Sdl2Application::mouseReleaseEvent() */
virtual void mouseReleaseEvent ( MouseEvent & event ) ;
# ifdef MAGNUM_BUILD_DEPRECATED
/**
* @ brief Mouse release event
* @ m_deprecated_since_latest Use @ ref pointerReleaseEvent ( ) instead ,
* which is a better abstraction for covering both mouse and touch
* / pen input .
*
* Default implementation does nothing .
*/
virtual CORRADE_DEPRECATED ( " use pointerReleaseEvent() instead " ) void mouseReleaseEvent(MouseEvent& event) ;
# endif
/**
* @ brief Pointer move event
* @ m_since_latest
*
* Called when any of the currently pressed pointers is moved or
* changes its properties . Gets called also if the set of pressed mouse
* buttons changes .
*
* On builds with @ ref MAGNUM_BUILD_DEPRECATED enabled , default
* implementation delegates to @ ref mouseMoveEvent ( ) , or if
* @ ref PointerMoveEvent : : pointer ( ) is not
* @ relativeref { Corrade , Containers : : NullOpt } , to either
* @ ref mousePressEvent ( ) or @ ref mouseReleaseEvent ( ) . On builds with
* deprecated functionality disabled , default implementation does
* nothing .
*/
virtual void pointerMoveEvent ( PointerMoveEvent & event ) ;
# ifdef MAGNUM_BUILD_DEPRECATED
/**
* @ brief Mouse move event
* @ m_deprecated_since_latest Use @ ref pointerMoveEvent ( ) instead ,
* which is a better abstraction for covering both mouse and touch
* / pen input .
*
* Called when any mouse button is pressed and mouse is moved . Default
* implementation does nothing .
* Default implementation does nothing .
*/
virtual void mouseMoveEvent ( MouseMoveEvent & event ) ;
virtual CORRADE_DEPRECATED ( " use pointerMoveEvent() instead " ) void mouseMoveEvent(MouseMoveEvent& event) ;
# endif
/** @copydoc Sdl2Application::mouseScrollEvent() */
virtual void mouseScrollEvent ( MouseScrollEvent & event ) ;
@ -816,9 +904,59 @@ class GlfwApplication {
int _exitCode = 0 ;
Vector2i _minWindowSize , _maxWindowSize ;
Vector2i _previousMouseMovePosition { - 1 } ;
Vector2 _previousMouseMovePosition { Constants : : nan ( ) } ;
} ;
/**
@ brief Pointer type
@ m_since_latest
@ see @ ref Pointers , @ ref PointerEvent : : pointer ( ) ,
@ ref PointerMoveEvent : : pointer ( ) , @ ref PointerMoveEvent : : pointers ( )
*/
enum class GlfwApplication : : Pointer : UnsignedByte {
/**
* Left mouse button . Corresponds to ` GLFW_MOUSE_BUTTON_LEFT ` or
* ` GLFW_MOUSE_BUTTON_1 ` .
*/
MouseLeft = 1 < < 0 ,
/**
* Middle mouse button . Corresponds to ` GLFW_MOUSE_BUTTON_MIDDLE ` or
* ` GLFW_MOUSE_BUTTON_2 ` .
*/
MouseMiddle = 1 < < 1 ,
/**
* Right mouse button . Corresponds to ` GLFW_MOUSE_BUTTON_RIGHT ` or
* ` GLFW_MOUSE_BUTTON_3 ` .
*/
MouseRight = 1 < < 2 ,
/**
* Fourth mouse button , such as wheel left . Corresponds to
* ` GLFW_MOUSE_BUTTON_4 ` .
*/
MouseButton4 = 1 < < 3 ,
/**
* Fifth mouse button , such as wheel right . Corresponds to
* ` GLFW_MOUSE_BUTTON_5 ` .
*/
MouseButton5 = 1 < < 4 ,
/** Sixth mouse button. Corresponds to `GLFW_MOUSE_BUTTON_6`. */
MouseButton6 = 1 < < 5 ,
/** Seventh mouse button. Corresponds to `GLFW_MOUSE_BUTTON_7`. */
MouseButton7 = 1 < < 6 ,
/** Eighth mouse button. Corresponds to `GLFW_MOUSE_BUTTON_8`. */
MouseButton8 = 1 < < 7
} ;
CORRADE_ENUMSET_OPERATORS ( GlfwApplication : : Pointers )
# ifdef MAGNUM_TARGET_GL
/**
@ brief OpenGL context configuration
@ -1552,8 +1690,10 @@ class GlfwApplication::ViewportEvent {
/**
@ brief Base for input events
@ see @ ref KeyEvent , @ ref MouseEvent , @ ref MouseMoveEvent , @ ref keyPressEvent ( ) ,
@ ref mousePressEvent ( ) , @ ref mouseReleaseEvent ( ) , @ ref mouseMoveEvent ( )
@ see @ ref KeyEvent , @ ref PointerEvent , @ ref PointerMoveEvent ,
@ ref MouseScrollEvent , @ ref keyPressEvent ( ) , @ ref keyReleaseEvent ( ) ,
@ ref pointerPressEvent ( ) , @ ref pointerReleaseEvent ( ) ,
@ ref pointerMoveEvent ( ) , @ ref mouseScrollEvent ( )
*/
class GlfwApplication : : InputEvent {
public :
@ -1561,7 +1701,9 @@ class GlfwApplication::InputEvent {
* @ brief Modifier
*
* @ see @ ref Modifiers , @ ref KeyEvent : : modifiers ( ) ,
* @ ref MouseEvent : : modifiers ( )
* @ ref PointerEvent : : modifiers ( ) ,
* @ ref PointerMoveEvent : : modifiers ( ) ,
* @ ref MouseScrollEvent : : modifiers ( )
*/
enum class Modifier : Int {
/**
@ -1596,8 +1738,9 @@ class GlfwApplication::InputEvent {
/**
* @ brief Set of modifiers
*
* @ see @ ref KeyEvent : : modifiers ( ) , @ ref MouseEvent : : modifiers ( ) ,
* @ ref MouseMoveEvent : : modifiers ( )
* @ see @ ref KeyEvent : : modifiers ( ) , @ ref PointerEvent : : modifiers ( ) ,
* @ ref PointerMoveEvent : : modifiers ( ) ,
* @ ref MouseScrollEvent : : modifiers ( )
*/
typedef Containers : : EnumSet < Modifier > Modifiers ;
@ -1939,13 +2082,63 @@ class GlfwApplication::KeyEvent: public GlfwApplication::InputEvent {
const bool _repeated ;
} ;
/**
@ brief Pointer event
@ m_since_latest
@ see @ ref PointerMoveEvent , @ ref MouseScrollEvent , @ ref pointerPressEvent ( ) ,
@ ref pointerReleaseEvent ( )
*/
class GlfwApplication : : PointerEvent : public InputEvent {
public :
/** @brief Copying is not allowed */
PointerEvent ( const PointerEvent & ) = delete ;
/** @brief Moving is not allowed */
PointerEvent ( PointerEvent & & ) = delete ;
/** @brief Copying is not allowed */
PointerEvent & operator = ( const PointerEvent & ) = delete ;
/** @brief Moving is not allowed */
PointerEvent & operator = ( PointerEvent & & ) = delete ;
/** @brief Pointer type that was pressed or released */
Pointer pointer ( ) const { return _pointer ; }
/**
* @ brief Position
*
* May return fractional values for example on HiDPI systems where
* window size is smaller than actual framebuffer size . Use
* @ ref Math : : round ( ) to snap them to the nearest window pixel .
*/
Vector2 position ( ) const { return _position ; }
/** @brief Modifiers */
Modifiers modifiers ( ) const { return _modifiers ; }
private :
friend GlfwApplication ;
explicit PointerEvent ( Pointer pointer , const Vector2 & position , Modifiers modifiers ) : _pointer ( pointer ) , _position { position } , _modifiers { modifiers } { }
const Pointer _pointer ;
const Vector2 _position ;
const Modifiers _modifiers ;
} ;
# ifdef MAGNUM_BUILD_DEPRECATED
/**
@ brief Mouse event
@ m_deprecated_since_latest Use @ ref PointerEvent , @ ref pointerPressEvent ( ) and
@ ref pointerReleaseEvent ( ) instead , which is a better abstraction for
covering both mouse and touch input .
@ see @ ref MouseMoveEvent , @ ref MouseScrollEvent , @ ref mousePressEvent ( ) ,
@ ref mouseReleaseEvent ( )
*/
class GlfwApplication : : MouseEvent : public GlfwApplication : : InputEvent {
class CORRADE_DEPRECATED ( " use PointerEvent, pointerPressEvent() and pointerReleaseEvent ( ) instead " ) GlfwApplication::MouseEvent: public InputEvent {
public :
/**
* @ brief Mouse button
@ -1984,13 +2177,99 @@ class GlfwApplication::MouseEvent: public GlfwApplication::InputEvent {
const Vector2i _position ;
const Modifiers _modifiers ;
} ;
# endif
/**
@ brief Pointer move event
@ m_since_latest
@ see @ ref PointerEvent , @ ref MouseScrollEvent , @ ref pointerMoveEvent ( )
*/
class GlfwApplication : : PointerMoveEvent : public InputEvent {
public :
/** @brief Copying is not allowed */
PointerMoveEvent ( const PointerMoveEvent & ) = delete ;
/** @brief Moving is not allowed */
PointerMoveEvent ( PointerMoveEvent & & ) = delete ;
/** @brief Copying is not allowed */
PointerMoveEvent & operator = ( const PointerMoveEvent & ) = delete ;
/** @brief Moving is not allowed */
PointerMoveEvent & operator = ( PointerMoveEvent & & ) = delete ;
/**
* @ brief Pointer type that was added or removed from the set of pressed pointers
*
* Is non - empty only in case a mouse button was pressed in addition to
* an already pressed button , or if one mouse button from multiple
* pressed buttons was released . If non - empty and @ ref pointers ( ) don ' t
* contain given @ ref Pointer value , the button was released , if they
* contain given value , the button was pressed .
*/
Containers : : Optional < Pointer > pointer ( ) const { return _pointer ; }
/**
* @ brief Pointer types pressed in this event
*
* Returns an empty set if no pointers are pressed , which happens for
* example when a mouse is just moved around . Lazily populated on first
* request .
* @ see @ ref pointer ( )
*/
Pointers pointers ( ) ;
/**
* @ brief Position
*
* May return fractional values for example on HiDPI systems where
* window size is smaller than actual framebuffer size . Use
* @ ref Math : : round ( ) to snap them to the nearest window pixel .
*/
Vector2 position ( ) const { return _position ; }
/**
* @ brief Position relative to the previous touch event
*
* May return fractional values for example on HiDPI systems where
* window size is smaller than actual framebuffer size . Use
* @ ref Math : : round ( ) to snap them to the nearest window pixel . Unlike
* @ ref Sdl2Application , GLFW doesn ' t provide relative position
* directly , so this is calculated explicitly as a delta from previous
* move event position .
*/
Vector2 relativePosition ( ) const { return _relativePosition ; }
/**
* @ brief Modifiers
*
* Lazily populated on first request .
*/
Modifiers modifiers ( ) ;
private :
friend GlfwApplication ;
explicit PointerMoveEvent ( GLFWwindow * window , Containers : : Optional < Pointer > pointer , const Vector2 & position , const Vector2 & relativePosition ) : _window { window } , _pointer { pointer } , _position { position } , _relativePosition { relativePosition } { }
GLFWwindow * const _window ;
const Containers : : Optional < Pointer > _pointer ;
Containers : : Optional < Pointers > _pointers ;
const Vector2 _position , _relativePosition ;
Containers : : Optional < Modifiers > _modifiers ;
} ;
# ifdef MAGNUM_BUILD_DEPRECATED
/**
@ brief Mouse move event
@ m_deprecated_since_latest Use @ ref PointerMoveEvent and
@ ref pointerMoveEvent ( ) instead , which is a better abstraction for covering
both mouse and touch / pen input .
@ see @ ref MouseEvent , @ ref MouseScrollEvent , @ ref mouseMoveEvent ( )
*/
class GlfwApplication : : MouseMoveEvent : public GlfwApplication : : InputEvent {
class CORRADE_DEPRECATED ( " use PointerMoveEvent and pointerMoveEvent() instead " ) GlfwApplication::MouseMoveEvent: public GlfwApplication::InputEvent {
public :
/**
* @ brief Mouse button
@ -2049,12 +2328,15 @@ class GlfwApplication::MouseMoveEvent: public GlfwApplication::InputEvent {
Containers : : Optional < Modifiers > _modifiers ;
} ;
CORRADE_IGNORE_DEPRECATED_PUSH
CORRADE_ENUMSET_OPERATORS ( GlfwApplication : : MouseMoveEvent : : Buttons )
CORRADE_IGNORE_DEPRECATED_POP
# endif
/**
@ brief Mouse scroll event
@ see @ ref Mouse Event, @ ref Mouse MoveEvent, @ ref mouseScrollEvent ( )
@ see @ ref Pointer Event, @ ref Pointer MoveEvent, @ ref mouseScrollEvent ( )
*/
class GlfwApplication : : MouseScrollEvent : public GlfwApplication : : InputEvent {
public :