stmm-games-doc  0.32.0
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
stmi::PointerEvent Class Reference

Event generated when the button state or the position of a pointer is changed. More...

Inheritance diagram for stmi::PointerEvent:
Inheritance graph
[legend]

Public Types

enum  POINTER_INPUT_TYPE {
  BUTTON_PRESS = 1, BUTTON_RELEASE = 2, POINTER_MOVE = 3, POINTER_HOVER = 4,
  BUTTON_RELEASE_CANCEL = 5
}
 The type of pointer event. More...
 
- Public Types inherited from stmi::XYEvent
enum  XY_GRAB_INPUT_TYPE {
  XY_HOVER = 0, XY_GRAB = 1, XY_MOVE = 2, XY_UNGRAB = 3,
  XY_UNGRAB_CANCEL = 4
}
 The type of grab the event represents. More...
 
- Public Types inherited from stmi::Event
enum  AS_KEY_INPUT_TYPE { AS_KEY_PRESS = 1, AS_KEY_RELEASE = 2, AS_KEY_RELEASE_CANCEL = 3 }
 Key simulation type. More...
 

Public Member Functions

 PointerEvent (int64_t nTimeUsec, const shared_ptr< Accessor > &refAccessor, const shared_ptr< PointerCapability > &refPointerCapability, double fX, double fY, POINTER_INPUT_TYPE eType, int32_t nButton, bool bAnyButtonPressed, bool bWasAnyButtonPressed) noexcept
 Constructor. More...
 
POINTER_INPUT_TYPE getType () const noexcept
 The type of event. More...
 
int32_t getButton () const noexcept
 The button involved. More...
 
shared_ptr< PointerCapabilitygetPointerCapability () const noexcept
 The pointer capability that generated the event. More...
 
shared_ptr< CapabilitygetCapability () const noexcept override
 Returns the capability that generated this event. More...
 
bool getAsKey (HARDWARE_KEY &eKey, AS_KEY_INPUT_TYPE &eType, bool &bMoreThanOne) const noexcept override
 If not hovering or moving returns the simulated keystroke. More...
 
- Public Member Functions inherited from stmi::XYEvent
double getX () const noexcept
 The main X coordinate. More...
 
double getY () const noexcept
 The main Y coordinate. More...
 
bool getIsModified () const noexcept
 Whether the event coordinates were modified. More...
 
XY_GRAB_INPUT_TYPE getXYGrabType () const noexcept
 Get the grab type of the event. More...
 
int64_t getXYGrabId () const noexcept
 Identifies what is grabbed. More...
 
virtual void translateXY (double fDX, double fDY) noexcept
 Translates the xy coordinates. More...
 
virtual void scaleXY (double fSX, double fSY) noexcept
 Scales the xy coordinates. More...
 
- Public Member Functions inherited from stmi::Event
virtual ~Event () noexcept=default
 
int64_t getTimeUsec () const noexcept
 Returns the time this event originated. More...
 
int32_t getCapabilityId () const noexcept
 Returns the id of the capability that generated this event. More...
 
const shared_ptr< Accessor > & getAccessor () const noexcept
 Returns the accessor that helped generate this event. More...
 
virtual std::vector< std::pair< HARDWARE_KEY, AS_KEY_INPUT_TYPE > > getAsKeys () const noexcept
 All the keys this event simulates. More...
 
const ClassgetEventClass () const noexcept
 Get the registered class of the event instance. More...
 

Static Public Member Functions

static const Event::ClassgetClass () noexcept
 
- Static Public Member Functions inherited from stmi::Event
static bool isEventClassIdRegistered (const std::string &sEventClassId) noexcept
 Tells whether the given event class id is registered. More...
 
static Class getEventClassIdClass (const std::string &sEventClassId) noexcept
 Gets the event class with given class id. More...
 

Static Public Attributes

static constexpr int32_t s_nFirstButton = 1
 Valid button numbers start from 1. More...
 
static constexpr int32_t s_nLastSimulatedButton = 9
 Last simulated button number. More...
 
static constexpr int32_t s_nNoButton = -1
 Value returned by getButton() when hovering or moving. More...
 
static constexpr int64_t s_nPointerGrabbedId = 1
 Means at least one button is pressed. More...
 
static constexpr int64_t s_nPointerNotGrabbedId = -1
 Means no button is pressed (POINTER_HOVER). More...
 
static const char *const s_sClassId
 

Protected Member Functions

void setPointer (POINTER_INPUT_TYPE eType, int32_t nButton, bool bAnyButtonPressed, bool bWasAnyButtonPressed) noexcept
 Sets pointer and grab fields. More...
 
void setPointerCapability (const shared_ptr< PointerCapability > &refPointerCapability) noexcept
 Sets the capability. More...
 
- Protected Member Functions inherited from stmi::XYEvent
 XYEvent (const Class &oClass, int64_t nTimeUsec, int32_t nCapabilityId, const shared_ptr< Accessor > &refAccessor, double fX, double fY) noexcept
 Constructor without grab info. More...
 
 XYEvent (const Class &oClass, int64_t nTimeUsec, int32_t nCapabilityId, const shared_ptr< Accessor > &refAccessor, double fX, double fY, XY_GRAB_INPUT_TYPE eXYGrabType, int64_t nGrabId) noexcept
 Constructor. More...
 
void setX (double fX) noexcept
 Sets X. More...
 
void setY (double fY) noexcept
 Sets Y. More...
 
void setIsModified (bool bIsModified) noexcept
 Sets the modified flag. More...
 
void setXYGrab (XY_GRAB_INPUT_TYPE eXYGrabType, int64_t nGrabId) noexcept
 Sets the grab type and id. More...
 
- Protected Member Functions inherited from stmi::Event
 Event (const Class &oClass, int64_t nTimeUsec, int32_t nCapabilityId, const shared_ptr< Accessor > &refAccessor) noexcept
 Constructor to be called from subclasses. More...
 
 Event (const Class &oClass, int64_t nTimeUsec, int32_t nCapabilityId) noexcept
 Constructor to be called from subclasses (with empty accessor). More...
 
void setTimeUsec (int64_t nTimeUsec) noexcept
 Set the event time. More...
 
void setCapabilityId (int32_t nCapabilityId) noexcept
 Set the capability id. More...
 
void setAccessor (const shared_ptr< Accessor > &refAccessor) noexcept
 Set the accessor. More...
 

Additional Inherited Members

- Static Protected Member Functions inherited from stmi::Event
static bool isEventTypeRegistered (const std::type_info &oEventType) noexcept
 Tells whether an event type was registered. More...
 
static const std::type_info & getEventClassIdType (const std::string &sEventClassId, bool &bRegistered) noexcept
 Gets the type of the registered event subclass associated with class id. More...
 
static std::string getEventTypeClassId (const std::type_info &oType) noexcept
 Gets the class id of the given type. More...
 

Detailed Description

Event generated when the button state or the position of a pointer is changed.

Note that the reference to the capability that generated this event is weak.

Member Enumeration Documentation

◆ POINTER_INPUT_TYPE

The type of pointer event.

Enumerator
BUTTON_PRESS 

A button is pressed.

BUTTON_RELEASE 

A button is released.

POINTER_MOVE 

Pointer is moved (while at least one button is pressed)

POINTER_HOVER 

Pointer is hovered (while no button is pressed).

BUTTON_RELEASE_CANCEL 

A button release is canceled.

Constructor & Destructor Documentation

◆ PointerEvent()

stmi::PointerEvent::PointerEvent ( int64_t  nTimeUsec,
const shared_ptr< Accessor > &  refAccessor,
const shared_ptr< PointerCapability > &  refPointerCapability,
double  fX,
double  fY,
POINTER_INPUT_TYPE  eType,
int32_t  nButton,
bool  bAnyButtonPressed,
bool  bWasAnyButtonPressed 
)
noexcept

Constructor.

When moving or hovering the pointer, the passed button must be -1.

The grab state of the pointer is defined using bAnyButtonPressed and bWasAnyButtonPressed, see XYEvent::getXYGrabType(). If the grab state is XY_HOVER then XYEvent::getXYGrabId() returns -1, 1 otherwise.

Parameters
nTimeUsecTime from epoch in microseconds.
refAccessorThe accessor used to generate the event. Can be null.
refPointerCapabilityThe capability that generated this event. Cannot be null.
fXThe X position of the pointer.
fYThe Y position of the pointer.
eTypeThe type of pointer event.
nButtonThe button (>= 1) or -1.
bAnyButtonPressedWhether any button is pressed.
bWasAnyButtonPressedWhether any button was pressed before this event.

Member Function Documentation

◆ getAsKey()

bool stmi::PointerEvent::getAsKey ( HARDWARE_KEY eKey,
AS_KEY_INPUT_TYPE eType,
bool &  bMoreThanOne 
) const
overridevirtualnoexcept

If not hovering or moving returns the simulated keystroke.

  • Button 1 simulates key HK_BTN_LEFT.
  • Button 2 simulates key HK_BTN_RIGHT.
  • Button 3 simulates key HK_BTN_MIDDLE.
  • Buttons 4 to 9 simulate keys from HK_BTN_4 to HK_BTN_9.
  • Buttons from 10 are not simulated with a key.

The event type BUTTON_PRESS simulates AS_KEY_PRESS, BUTTON_RELEASE simulates AS_KEY_RELEASE and BUTTON_RELEASE_CANCEL simulates AS_KEY_RELEASE_CANCEL.

Parameters
eKeyThe simulated key.
eTypeThe type of simulated key action.
bMoreThanOneAlways false.
Returns
Whether the pointer event type simulates a key.

Reimplemented from stmi::Event.

◆ getButton()

int32_t stmi::PointerEvent::getButton ( ) const
inlinenoexcept

The button involved.

Returns
The button or -1 if hovering or moving the pointer.

◆ getCapability()

shared_ptr<Capability> stmi::PointerEvent::getCapability ( ) const
inlineoverridevirtualnoexcept

Returns the capability that generated this event.

The Event subclass implementation keeps only a weak_ptr on the capability to avoid reference cycles.

Returns
The capability or null if the capability was deleted.

Implements stmi::Event.

◆ getClass()

static const Event::Class& stmi::PointerEvent::getClass ( )
inlinestaticnoexcept

◆ getPointerCapability()

shared_ptr<PointerCapability> stmi::PointerEvent::getPointerCapability ( ) const
inlinenoexcept

The pointer capability that generated the event.

Returns
The capability or null if the capability was deleted.

◆ getType()

POINTER_INPUT_TYPE stmi::PointerEvent::getType ( ) const
inlinenoexcept

The type of event.

◆ setPointer()

void stmi::PointerEvent::setPointer ( POINTER_INPUT_TYPE  eType,
int32_t  nButton,
bool  bAnyButtonPressed,
bool  bWasAnyButtonPressed 
)
protectednoexcept

Sets pointer and grab fields.

This method also calls XYEvent::setXYGrab().

Parameters
eTypeThe type of pointer event.
nButtonThe button (>= 1) or -1.
bAnyButtonPressedWhether any button is pressed.
bWasAnyButtonPressedWhether any button was pressed before this event.

◆ setPointerCapability()

void stmi::PointerEvent::setPointerCapability ( const shared_ptr< PointerCapability > &  refPointerCapability)
inlineprotectednoexcept

Sets the capability.

Parameters
refPointerCapabilityThe capability that generated this event. Cannot be null.

Member Data Documentation

◆ s_nFirstButton

constexpr int32_t stmi::PointerEvent::s_nFirstButton = 1
static

Valid button numbers start from 1.

◆ s_nLastSimulatedButton

constexpr int32_t stmi::PointerEvent::s_nLastSimulatedButton = 9
static

Last simulated button number.

◆ s_nNoButton

constexpr int32_t stmi::PointerEvent::s_nNoButton = -1
static

Value returned by getButton() when hovering or moving.

◆ s_nPointerGrabbedId

constexpr int64_t stmi::PointerEvent::s_nPointerGrabbedId = 1
static

Means at least one button is pressed.

◆ s_nPointerNotGrabbedId

constexpr int64_t stmi::PointerEvent::s_nPointerNotGrabbedId = -1
static

Means no button is pressed (POINTER_HOVER).

◆ s_sClassId

const char* const stmi::PointerEvent::s_sClassId
static