stmm-input-doc  0.17.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
stmi::JoystickHatEvent Class Reference

Event generated when the state of a joystick's hat is changed. More...

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

Public Member Functions

 JoystickHatEvent (int64_t nTimeUsec, const shared_ptr< Accessor > &refAccessor, const shared_ptr< JoystickCapability > &refJoystickCapability, int32_t nHat, JoystickCapability::HAT_VALUE eValue, JoystickCapability::HAT_VALUE ePreviousValue) noexcept
 Constructor. More...
 
 JoystickHatEvent (int64_t nTimeUsec, const shared_ptr< Accessor > &refAccessor, const shared_ptr< JoystickCapability > &refJoystickCapability, int32_t nHat, JoystickCapability::HAT_VALUE eValue) noexcept
 Constructs instance without key simulation. More...
 
int32_t getHat () const noexcept
 The hat that has changed. More...
 
JoystickCapability::HAT_VALUE getValue () const noexcept
 The value of the hat. More...
 
std::pair< int32_t, int32_t > getDeltaXY () const noexcept
 The value of the hat in unary coordinates. More...
 
shared_ptr< JoystickCapabilitygetJoystickCapability () const noexcept
 The joystick capability. 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
 The first of one or more simulated keys. More...
 
std::vector< std::pair< HARDWARE_KEY, AS_KEY_INPUT_TYPE > > getAsKeys () const noexcept override
 The generated simulated keys. 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...
 
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 const char *const s_sClassId
 

Protected Member Functions

void setHat (int32_t nHat) noexcept
 Sets the hat. More...
 
void setValue (JoystickCapability::HAT_VALUE eValue) noexcept
 Sets the value of the hat. More...
 
void setValue (JoystickCapability::HAT_VALUE eValue, JoystickCapability::HAT_VALUE ePreviousValue) noexcept
 Sets the value of the hat for key simulation. More...
 
void setJoystickCapability (const shared_ptr< JoystickCapability > &refJoystickCapability) noexcept
 Sets the capability. 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

- 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...
 
- 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 state of a joystick's hat is changed.

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

Constructor & Destructor Documentation

◆ JoystickHatEvent() [1/2]

stmi::JoystickHatEvent::JoystickHatEvent ( int64_t  nTimeUsec,
const shared_ptr< Accessor > &  refAccessor,
const shared_ptr< JoystickCapability > &  refJoystickCapability,
int32_t  nHat,
JoystickCapability::HAT_VALUE  eValue,
JoystickCapability::HAT_VALUE  ePreviousValue 
)
noexcept

Constructor.

If the previous value of the hat is not JoystickCapability::HAT_VALUE_NOT_SET this event simulates keys, but only for hats 0, 1, 2 and 3.

  • hat 0: HK_UP, HK_DOWN, HK_LEFT, HK_RIGHT.
  • hat 1: HK_BTN_DPAD_UP, HK_BTN_DPAD_DOWN, HK_BTN_DPAD_LEFT, HK_BTN_DPAD_RIGHT.
  • hat 2: HK_BTN_TRIGGER_HAPPY1, HK_BTN_TRIGGER_HAPPY2, HK_BTN_TRIGGER_HAPPY3, HK_BTN_TRIGGER_HAPPY4.
  • hat 3: HK_BTN_TRIGGER_HAPPY5, HK_BTN_TRIGGER_HAPPY6, HK_BTN_TRIGGER_HAPPY7, HK_BTN_TRIGGER_HAPPY8.
Parameters
nTimeUsecTime from epoch in microseconds.
refAccessorThe accessor used to generate the event. Can be null.
refJoystickCapabilityThe capability that generated this event. Cannot be null.
nHatThe hat that changed its state. Must be >= 0.
eValueThe new value for the hat. Can't be JoystickCapability::HAT_VALUE_NOT_SET.
ePreviousValueThe previous value for the hat. Can be JoystickCapability::HAT_VALUE_NOT_SET. Can't be HAT_CENTER_CANCEL.

◆ JoystickHatEvent() [2/2]

stmi::JoystickHatEvent::JoystickHatEvent ( int64_t  nTimeUsec,
const shared_ptr< Accessor > &  refAccessor,
const shared_ptr< JoystickCapability > &  refJoystickCapability,
int32_t  nHat,
JoystickCapability::HAT_VALUE  eValue 
)
noexcept

Constructs instance without key simulation.

See also
JoystickHatEvent::JoystickHatEvent(int64_t, const shared_ptr<Accessor>& , const shared_ptr<JoystickCapability>&, int32_t , JoystickCapability::HAT_VALUE, JoystickCapability::HAT_VALUE);

Member Function Documentation

◆ getAsKey()

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

The first of one or more simulated keys.

See also
JoystickHatEvent::getAsKeys()

Reimplemented from stmi::Event.

◆ getAsKeys()

std::vector< std::pair<HARDWARE_KEY, AS_KEY_INPUT_TYPE> > stmi::JoystickHatEvent::getAsKeys ( ) const
overridevirtualnoexcept

The generated simulated keys.

See also
JoystickHatEvent(int64_t, const shared_ptr<JoystickCapability>&, int32_t, JoystickCapability::HAT_VALUE, JoystickCapability::HAT_VALUE, bool) to know which keys are generated by which hats.

Example 1: A hat 0 transition from HAT_CENTER to HAT_LEFT simulates the key { {HK_LEFT, AS_KEY_PRESS} }

Example 2: A hat 0 transition with canceling from HAT_LEFTUP to HAT_CENTER simulates the keys { {HK_UP, AS_KEY_RELEASE_CANCEL}, {HK_LEFT, AS_KEY_RELEASE_CANCEL} }

Example 3: A (physically very unlikely) hat 0 transition from HAT_LEFTUP to HAT_RIGHTDOWN simulates the keys { {HK_UP, AS_KEY_RELEASE}, {HK_LEFT, AS_KEY_RELEASE}, {HK_DOWN, AS_KEY_PRESS}, {HK_RIGHT, AS_KEY_PRESS} }

Reimplemented from stmi::Event.

◆ getCapability()

shared_ptr<Capability> stmi::JoystickHatEvent::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::JoystickHatEvent::getClass ( )
inlinestaticnoexcept

◆ getDeltaXY()

std::pair<int32_t,int32_t> stmi::JoystickHatEvent::getDeltaXY ( ) const
inlinenoexcept

The value of the hat in unary coordinates.

Examples:

Returns
Pair containing X and Y with possible values -1, 0, 1.

◆ getHat()

int32_t stmi::JoystickHatEvent::getHat ( ) const
inlinenoexcept

The hat that has changed.

Returns
The hat (>= 0).

◆ getJoystickCapability()

shared_ptr<JoystickCapability> stmi::JoystickHatEvent::getJoystickCapability ( ) const
inlinenoexcept

The joystick capability.

Returns
The capability or null if the capability was deleted.

◆ getValue()

JoystickCapability::HAT_VALUE stmi::JoystickHatEvent::getValue ( ) const
inlinenoexcept

The value of the hat.

Returns
The new value. Cannot be JoystickCapability::HAT_VALUE_NOT_SET.

◆ setHat()

void stmi::JoystickHatEvent::setHat ( int32_t  nHat)
inlineprotectednoexcept

Sets the hat.

Parameters
nHatThe hat that changed its state. Must be >= 0.

◆ setJoystickCapability()

void stmi::JoystickHatEvent::setJoystickCapability ( const shared_ptr< JoystickCapability > &  refJoystickCapability)
inlineprotectednoexcept

Sets the capability.

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

◆ setValue() [1/2]

void stmi::JoystickHatEvent::setValue ( JoystickCapability::HAT_VALUE  eValue)
inlineprotectednoexcept

Sets the value of the hat.

Parameters
eValueThe new value for the hat. Can't be JoystickCapability::HAT_VALUE_NOT_SET.

◆ setValue() [2/2]

void stmi::JoystickHatEvent::setValue ( JoystickCapability::HAT_VALUE  eValue,
JoystickCapability::HAT_VALUE  ePreviousValue 
)
inlineprotectednoexcept

Sets the value of the hat for key simulation.

Parameters
eValueThe new value for the hat. Can't be JoystickCapability::HAT_VALUE_NOT_SET.
ePreviousValueThe previous value for the hat. Can be JoystickCapability::HAT_VALUE_NOT_SET. Can't be HAT_CENTER_CANCEL.

Member Data Documentation

◆ s_sClassId

const char* const stmi::JoystickHatEvent::s_sClassId
static