JoyMapping class
#include <nCine/Input/JoyMapping.h>
Translation layer that maps raw gamepad and joystick inputs to a unified layout.
Parses SDL-style mapping strings, matches connected joysticks by GUID or name and converts their raw button/hat/axis events into JoyMappedState and mapped events using unified ButtonName and AxisName values.
Public static variables
-
static const std::
int32_t MaxNumJoysticks - Maximum number of joysticks that can be mapped at once.
Public static functions
-
static auto CreateJoystickGuid(std::
uint16_t bus, std:: uint16_t vendor, std:: uint16_t product, std:: uint16_t version, StringView name, std:: uint8_t driverSignature, std:: uint8_t driverData) -> JoystickGuid - Builds a joystick GUID from its descriptor fields.
Constructors, destructors, conversion operators
Public functions
- void Init(const IInputManager* inputManager)
- Initializes the mapping layer with the specified input manager and loads the built-in mappings.
- void SetHandler(IInputEventHandler* inputEventHandler)
- Sets the input event handler that receives mapped events.
- auto AddMappingsFromString(StringView mappingString) -> bool
- Adds mapping configurations from a string and returns
trueon success. - auto AddMappingsFromFile(StringView path) -> bool
- Adds mapping configurations from a text file and returns
trueon success. -
auto numMappings() const -> std::
int32_t - Returns the current number of loaded mappings.
- void OnJoyButtonPressed(const JoyButtonEvent& event)
- Translates a raw button press and dispatches the mapped event.
- void OnJoyButtonReleased(const JoyButtonEvent& event)
- Translates a raw button release and dispatches the mapped event.
- void OnJoyHatMoved(const JoyHatEvent& event)
- Translates a raw hat movement and dispatches the mapped events.
- void OnJoyAxisMoved(const JoyAxisEvent& event)
- Translates a raw axis movement and dispatches the mapped event.
- auto OnJoyConnected(const JoyConnectionEvent& event) -> bool
- Assigns a mapping to a newly connected joystick; returns
trueif a mapping was found. - void OnJoyDisconnected(const JoyConnectionEvent& event)
- Clears the mapping assigned to a disconnected joystick.
-
auto IsJoyMapped(std::
int32_t joyId) const -> bool - Returns
trueif the specified joystick has a valid mapping assigned. -
auto GetMappedState(std::
int32_t joyId) const -> const JoyMappedState& - Returns the unified mapped state of the specified joystick.
-
void DeadZoneNormalize(Vector2f& joyVector,
float deadZoneValue = IInputManager::
LeftStickDeadZone) const - Normalizes a joystick axis vector, clamping values within the dead zone to zero.
-
auto FindMappingByGuid(const JoystickGuid& guid) const -> std::
int32_t - Returns the index of the mapping matching the specified GUID, or -1 if none.
-
auto FindMappingByName(const char* name) const -> std::
int32_t - Returns the index of the mapping matching the specified name, or -1 if none.