mirror of
https://github.com/libretro/RetroArch
synced 2025-02-22 12:40:09 +00:00
Support for RETRO_DEVICE_INDEX_ANALOG_BUTTON
This commit is contained in:
parent
668cc01c5c
commit
795057bacf
@ -1609,8 +1609,52 @@ int16_t input_joypad_analog(const input_device_driver_t *drv,
|
|||||||
unsigned port, unsigned idx, unsigned ident,
|
unsigned port, unsigned idx, unsigned ident,
|
||||||
const struct retro_keybind *binds)
|
const struct retro_keybind *binds)
|
||||||
{
|
{
|
||||||
|
int16_t res;
|
||||||
|
|
||||||
|
if ( idx == RETRO_DEVICE_INDEX_ANALOG_BUTTON )
|
||||||
|
{
|
||||||
|
/* A RETRO_DEVICE_JOYPAD button? */
|
||||||
|
if ( ident < RARCH_FIRST_CUSTOM_BIND )
|
||||||
|
{
|
||||||
|
uint32_t axis = 0;
|
||||||
|
const struct retro_keybind *bind = NULL;
|
||||||
|
|
||||||
|
bind = &binds[ ident ];
|
||||||
|
if (!bind->valid)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
axis = bind->joyaxis;
|
||||||
|
if ( axis == AXIS_NONE )
|
||||||
|
axis = joypad_info.auto_binds[ ident ].joyaxis;
|
||||||
|
|
||||||
|
/* Analog button. */
|
||||||
|
res = abs( drv->axis( joypad_info.joy_idx, axis ) );
|
||||||
|
|
||||||
|
/* If the result is zero, it's got a digital button attached to it */
|
||||||
|
if ( res == 0 )
|
||||||
|
{
|
||||||
|
uint64_t key = bind->joykey;
|
||||||
|
|
||||||
|
if ( key == NO_BTN )
|
||||||
|
key = joypad_info.auto_binds[ ident ].joykey;
|
||||||
|
|
||||||
|
if ( drv->button(joypad_info.joy_idx, (uint16_t)key))
|
||||||
|
res = 0x7fff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* not a suitable button */
|
||||||
|
res = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Analog sticks. Either RETRO_DEVICE_INDEX_ANALOG_LEFT
|
||||||
|
* or RETRO_DEVICE_INDEX_ANALOG_RIGHT */
|
||||||
|
|
||||||
uint32_t axis_minus, axis_plus;
|
uint32_t axis_minus, axis_plus;
|
||||||
int16_t pressed_minus, pressed_plus, res;
|
int16_t pressed_minus, pressed_plus;
|
||||||
unsigned ident_minus = 0;
|
unsigned ident_minus = 0;
|
||||||
unsigned ident_plus = 0;
|
unsigned ident_plus = 0;
|
||||||
const struct retro_keybind *bind_minus = NULL;
|
const struct retro_keybind *bind_minus = NULL;
|
||||||
@ -1652,8 +1696,10 @@ int16_t input_joypad_analog(const input_device_driver_t *drv,
|
|||||||
digital_left = -0x7fff;
|
digital_left = -0x7fff;
|
||||||
if (drv->button(joypad_info.joy_idx, (uint16_t)key_plus))
|
if (drv->button(joypad_info.joy_idx, (uint16_t)key_plus))
|
||||||
digital_right = 0x7fff;
|
digital_right = 0x7fff;
|
||||||
|
|
||||||
return digital_right + digital_left;
|
return digital_right + digital_left;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -520,6 +520,7 @@ static INLINE bool input_joypad_pressed(
|
|||||||
* E.g.:
|
* E.g.:
|
||||||
* - RETRO_DEVICE_INDEX_ANALOG_LEFT
|
* - RETRO_DEVICE_INDEX_ANALOG_LEFT
|
||||||
* - RETRO_DEVICE_INDEX_ANALOG_RIGHT
|
* - RETRO_DEVICE_INDEX_ANALOG_RIGHT
|
||||||
|
* - RETRO_DEVICE_INDEX_ANALOG_BUTTON
|
||||||
* @ident : Analog key identifier.
|
* @ident : Analog key identifier.
|
||||||
* E.g.:
|
* E.g.:
|
||||||
* - RETRO_DEVICE_ID_ANALOG_X
|
* - RETRO_DEVICE_ID_ANALOG_X
|
||||||
|
Loading…
x
Reference in New Issue
Block a user