Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches
KODI::JOYSTICK::CButtonMapping Class Reference

Generic implementation of a class that provides button mapping by translating driver events to button mapping commands. More...

#include <ButtonMapping.h>

Inheritance diagram for KODI::JOYSTICK::CButtonMapping:
KODI::JOYSTICK::IDriverHandler KODI::KEYBOARD::IKeyboardDriverHandler KODI::MOUSE::IMouseDriverHandler KODI::JOYSTICK::IButtonMapCallback

Public Member Functions

 CButtonMapping (IButtonMapper *buttonMapper, IButtonMap *buttonMap, KEYMAP::IKeymap *keymap)
 Constructor for CButtonMapping.
 
 ~CButtonMapping () override=default
 
bool OnButtonMotion (unsigned int buttonIndex, bool bPressed) override
 Handle button motion.
 
bool OnHatMotion (unsigned int hatIndex, HAT_STATE state) override
 Handle hat motion.
 
bool OnAxisMotion (unsigned int axisIndex, float position, int center, unsigned int range) override
 Handle axis motion.
 
void OnInputFrame () override
 Handle buffered input motion for features that require multiple axes.
 
bool OnKeyPress (const CKey &key) override
 A key has been pressed.
 
void OnKeyRelease (const CKey &key) override
 A key has been released.
 
bool OnPosition (int x, int y) override
 Handle mouse position updates.
 
bool OnButtonPress (MOUSE::BUTTON_ID button) override
 A mouse button has been pressed.
 
void OnButtonRelease (MOUSE::BUTTON_ID button) override
 A mouse button has been released.
 
void SaveButtonMap () override
 Save the button map.
 
void ResetIgnoredPrimitives () override
 Clear the list of ignored driver primitives.
 
void RevertButtonMap () override
 Revert changes to the button map since the last time it was loaded or committed to disk.
 
bool MapPrimitive (const CDriverPrimitive &primitive)
 Process the primitive mapping command.
 
- Public Member Functions inherited from KODI::JOYSTICK::IDriverHandler
virtual ~IDriverHandler ()=default
 
- Public Member Functions inherited from KODI::KEYBOARD::IKeyboardDriverHandler
virtual ~IKeyboardDriverHandler ()=default
 
- Public Member Functions inherited from KODI::MOUSE::IMouseDriverHandler
virtual ~IMouseDriverHandler (void)=default
 
- Public Member Functions inherited from KODI::JOYSTICK::IButtonMapCallback
virtual ~IButtonMapCallback ()=default
 

Detailed Description

Generic implementation of a class that provides button mapping by translating driver events to button mapping commands.

Button mapping commands are invoked instantly for buttons and hats.

Button mapping commands are deferred for a short while after an axis is activated, and only one button mapping command will be invoked per activation.

Constructor & Destructor Documentation

◆ CButtonMapping()

CButtonMapping::CButtonMapping ( IButtonMapper * buttonMapper,
IButtonMap * buttonMap,
KEYMAP::IKeymap * keymap )

Constructor for CButtonMapping.

Parameters
buttonMapperCarries out button-mapping commands using <buttonMap>
buttonMapThe button map given to <buttonMapper> on each command

◆ ~CButtonMapping()

KODI::JOYSTICK::CButtonMapping::~CButtonMapping ( )
overridedefault

Member Function Documentation

◆ MapPrimitive()

bool CButtonMapping::MapPrimitive ( const CDriverPrimitive & primitive)

Process the primitive mapping command.

First, this function checks if the input should be dropped. This can happen if the input is ignored or the cooldown period is active. If the input is dropped, this returns true with no effect, effectively absorbing the input. Otherwise, the mapping command is sent to m_buttonMapper.

Parameters
primitiveThe primitive being mapped
Returns
True if the mapping command was handled, false otherwise

◆ OnAxisMotion()

bool CButtonMapping::OnAxisMotion ( unsigned int axisIndex,
float position,
int center,
unsigned int range )
overridevirtual

Handle axis motion.

If a joystick feature requires multiple axes (analog sticks, accelerometers), they can be buffered for later processing.

Parameters
axisIndexThe index of the axis as reported by the driver
positionThe position of the axis in the closed interval [-1.0, 1.0]
centerThe center point of the axis (either -1, 0 or 1)
rangeThe maximum distance the axis can move (either 1 or 2)
Returns
True if the motion was handled, false otherwise

Implements KODI::JOYSTICK::IDriverHandler.

◆ OnButtonMotion()

bool CButtonMapping::OnButtonMotion ( unsigned int buttonIndex,
bool bPressed )
overridevirtual

Handle button motion.

Parameters
buttonIndexThe index of the button as reported by the driver
bPressedtrue for press motion, false for release motion
Returns
True if a press was handled, false otherwise

Implements KODI::JOYSTICK::IDriverHandler.

◆ OnButtonPress()

bool CButtonMapping::OnButtonPress ( MOUSE::BUTTON_ID button)
overridevirtual

A mouse button has been pressed.

Parameters
buttonThe index of the pressed button
Returns
True if the event was handled, otherwise false

Implements KODI::MOUSE::IMouseDriverHandler.

◆ OnButtonRelease()

void CButtonMapping::OnButtonRelease ( MOUSE::BUTTON_ID button)
overridevirtual

A mouse button has been released.

Parameters
buttonThe index of the released button

Implements KODI::MOUSE::IMouseDriverHandler.

◆ OnHatMotion()

bool CButtonMapping::OnHatMotion ( unsigned int hatIndex,
HAT_STATE state )
overridevirtual

Handle hat motion.

Parameters
hatIndexThe index of the hat as reported by the driver
stateThe direction the hat is now being pressed
Returns
True if the new direction was handled, false otherwise

Implements KODI::JOYSTICK::IDriverHandler.

◆ OnInputFrame()

void CButtonMapping::OnInputFrame ( )
overridevirtual

Handle buffered input motion for features that require multiple axes.

OnInputFrame() is called at the end of the frame when all axis motions have been reported. This has several uses, including:

  • Combining multiple axes into a single analog stick or accelerometer event
  • Imitating an analog feature with a digital button so that events can be dispatched every frame.

Implements KODI::JOYSTICK::IDriverHandler.

◆ OnKeyPress()

bool CButtonMapping::OnKeyPress ( const CKey & key)
overridevirtual

A key has been pressed.

Parameters
keyThe pressed key
Returns
True if the event was handled, false otherwise

Implements KODI::KEYBOARD::IKeyboardDriverHandler.

◆ OnKeyRelease()

void KODI::JOYSTICK::CButtonMapping::OnKeyRelease ( const CKey & key)
inlineoverridevirtual

A key has been released.

Parameters
keyThe released key

Implements KODI::KEYBOARD::IKeyboardDriverHandler.

◆ OnPosition()

bool CButtonMapping::OnPosition ( int x,
int y )
overridevirtual

Handle mouse position updates.

Parameters
xThe new x coordinate of the pointer
yThe new y coordinate of the pointer

The mouse uses a left-handed (graphics) cartesian coordinate system. Positive X is right, positive Y is down.

Returns
True if the event was handled, false otherwise

Implements KODI::MOUSE::IMouseDriverHandler.

◆ ResetIgnoredPrimitives()

void CButtonMapping::ResetIgnoredPrimitives ( )
overridevirtual

Clear the list of ignored driver primitives.

Called if the user begins capturing primitives to be ignored, and no primitives are captured before the dialog is accepted by the user.

In this case, the button mapper won't have been given access to the button map, so a callback is needed to indicate that no primitives were captured and the user accepted this.

Implements KODI::JOYSTICK::IButtonMapCallback.

◆ RevertButtonMap()

void CButtonMapping::RevertButtonMap ( )
overridevirtual

Revert changes to the button map since the last time it was loaded or committed to disk.

Implements KODI::JOYSTICK::IButtonMapCallback.

◆ SaveButtonMap()

void CButtonMapping::SaveButtonMap ( )
overridevirtual

Save the button map.

Implements KODI::JOYSTICK::IButtonMapCallback.


The documentation for this class was generated from the following files: