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

Base class for pointer-like events that hold coordinates. More...

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

Public Types

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

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...
 
virtual shared_ptr< CapabilitygetCapability () const noexcept=0
 Returns the capability that generated this event. 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 bool getAsKey (HARDWARE_KEY &eKey, AS_KEY_INPUT_TYPE &eType, bool &bMoreThanOne) const noexcept
 Tells whether the event can simulate hardware keys. 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...
 

Protected Member Functions

 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 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 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

Base class for pointer-like events that hold coordinates.

This class provides an interface (that is independent from the actual registered event class) for grabbing a pointer (mouse, touch finger, etc.). It also allows to change the coordinates of the event.

If a subclass of XYEvent has, in addition to (fX,fY), more coordinates (fX2,fY2), (fX3,fY3), ... it should keep (fX,fY) as the main coordinates, and override translateXY(double fDX, double fDY) and scaleXY(double fSX, double fSY) to change the additional coordinates and call setIsModified(true) to mark the instance as modified.

Usage example within a callback:

void SomeListener::handleEvent(const std::shared_ptr<stmi::Event>& refEvent) {
    ...
    const stmi::Event::Class& oC = refEvent->getEventClass();
    if (oC.isXYEvent()) {
        auto pXYEvent = static_cast<stmi::XYEvent*>(refEvent.get());
        if (pXYEvent->getX() >= 100) {
            pXYEvent->translateXY(-100, 0);
            pXYEvent->scaleXY(0.5, 0.5);
    ...
}

Member Enumeration Documentation

◆ XY_GRAB_INPUT_TYPE

The type of grab the event represents.

If the event has no grab representation then XY_HOVER should be used.

Enumerator
XY_HOVER 

Example: mouse: it might mean 'no button is pressed'.

XY_GRAB 

Example: mouse: first button pressed.

Touch: finger pressed.

XY_MOVE 

Example: mouse: pointer move with one or more pressed buttons.

XY_UNGRAB 

Example: mouse: 'last pressed button released`.

XY_UNGRAB_CANCEL 

Example: mouse: sent when an event listener is removed while buttons are pressed.

Constructor & Destructor Documentation

◆ XYEvent() [1/2]

stmi::XYEvent::XYEvent ( const Class oClass,
int64_t  nTimeUsec,
int32_t  nCapabilityId,
const shared_ptr< Accessor > &  refAccessor,
double  fX,
double  fY 
)
protectednoexcept

Constructor without grab info.

Sets grab type to XY_HOVER and the modified flag to false.

Parameters
oClassSee Event::Event(const Class&, int64_t, const shared_ptr<Accessor>&)
nTimeUsecSee Event::Event(const Class&, int64_t, const shared_ptr<Accessor>&)
nCapabilityIdThe id of the capability that generated this event. Must be >= 0.
refAccessorSee Event::Event(const Class&, int64_t, const shared_ptr<Accessor>&)
fXThe X coordinate.
fYThe Y coordinate.

◆ XYEvent() [2/2]

stmi::XYEvent::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 
)
protectednoexcept

Constructor.

The modified flag is set to false.

Parameters
oClassSee Event::Event(const Class&, int64_t, const shared_ptr<Accessor>&)
nTimeUsecSee Event::Event(const Class&, int64_t, const shared_ptr<Accessor>&)
nCapabilityIdThe id of the capability that generated this event. Must be >= 0.
refAccessorSee Event::Event(const Class&, int64_t, const shared_ptr<Accessor>&)
fXThe X coordinate.
fYThe Y coordinate.
eXYGrabTypeThe grab type.
nGrabIdThe grab id.

Member Function Documentation

◆ getIsModified()

bool stmi::XYEvent::getIsModified ( ) const
inlinenoexcept

Whether the event coordinates were modified.

Tells whether translateXY(double, double) or scaleXY(double, double) were called and modified the event's coordinates.

Returns
The modified state.

◆ getX()

double stmi::XYEvent::getX ( ) const
inlinenoexcept

The main X coordinate.

Returns
X coordinate.

◆ getXYGrabId()

int64_t stmi::XYEvent::getXYGrabId ( ) const
inlinenoexcept

Identifies what is grabbed.

Ex. For a touch device it could be a finger.

Returns
The id or undefined if getXYGrabType() == XY_HOVER.

◆ getXYGrabType()

XY_GRAB_INPUT_TYPE stmi::XYEvent::getXYGrabType ( ) const
inlinenoexcept

Get the grab type of the event.

If no grab or don't care about it returns XY_HOVER. Example: When a touch is started type is XY_GRAB, when it moves it's XY_MOVE and when it's ended it's XY_UNGRAB.

Returns
The grab type.

◆ getY()

double stmi::XYEvent::getY ( ) const
inlinenoexcept

The main Y coordinate.

Returns
Y coordinate.

◆ scaleXY()

virtual void stmi::XYEvent::scaleXY ( double  fSX,
double  fSY 
)
virtualnoexcept

Scales the xy coordinates.

Can be overridden if the event subclass contains additional coords. If any of the values is changed sets the modified flag to true.

Parameters
fSXValue multiplied to the Xs of the event.
fSYValue multiplied to the Ys of the event.

◆ setIsModified()

void stmi::XYEvent::setIsModified ( bool  bIsModified)
inlineprotectednoexcept

Sets the modified flag.

Listeners receiving the event should only call this function with argument true. Device managers owning and recycling the event call this function with argument false.

Parameters
bIsModifiedThe new flag value.

◆ setX()

void stmi::XYEvent::setX ( double  fX)
inlineprotectednoexcept

Sets X.

The modified flag is not changed by this function.

Parameters
fXThe new value.

◆ setXYGrab()

void stmi::XYEvent::setXYGrab ( XY_GRAB_INPUT_TYPE  eXYGrabType,
int64_t  nGrabId 
)
inlineprotectednoexcept

Sets the grab type and id.

The modified flag is not changed by this function.

Parameters
eXYGrabTypeThe new grab type.
nGrabIdThe new id.

◆ setY()

void stmi::XYEvent::setY ( double  fY)
inlineprotectednoexcept

Sets Y.

The modified flag is not changed by this function.

Parameters
fYThe new value.

◆ translateXY()

virtual void stmi::XYEvent::translateXY ( double  fDX,
double  fDY 
)
virtualnoexcept

Translates the xy coordinates.

Can be overridden if the event subclass contains additional coords. If any of the values is changed sets the modified flag to true.

Parameters
fDXValue added to the Xs of the event.
fDYValue added to the Ys of the event.