(Cocoa) Create cocoa_is_pressed

This commit is contained in:
Twinaphex 2020-06-11 18:40:14 +02:00
parent 204f705b35
commit dc967f41ec

View File

@ -290,6 +290,33 @@ static int16_t cocoa_pointer_state(cocoa_input_data_t *apple,
return 0;
}
static bool cocoa_is_pressed(cocoa_input_data_t *apple,
rarch_joypad_info_t *joypad_info,
const struct retro_keybind *binds,
unsigned port, unsigned id)
{
/* Auto-binds are per joypad, not per user. */
const uint64_t joykey = (binds[id].joykey != NO_BTN)
? binds[id].joykey : joypad_info->auto_binds[id].joykey;
const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE)
? binds[id].joyaxis : joypad_info->auto_binds[id].joyaxis;
if (id < RARCH_BIND_LIST_END)
if (apple_key_state[rarch_keysym_lut[binds[id].key]])
return true;
if ((uint16_t)joykey != NO_BTN && apple->joypad->button(
joypad_info->joy_idx, (uint16_t)joykey))
return true;
if (((float)abs(apple->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold)
return true;
#ifdef HAVE_MFI
if ((uint16_t)joykey != NO_BTN && apple->sec_joypad->button(joypad_info->joy_idx, (uint16_t)joykey))
return true;
if (((float)abs(apple->sec_joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold)
return true;
#endif
return false;
}
static int16_t cocoa_input_state(void *data,
rarch_joypad_info_t *joypad_info,
const struct retro_keybind **binds, unsigned port,
@ -306,64 +333,14 @@ static int16_t cocoa_input_state(void *data,
int16_t ret = 0;
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
{
/* Auto-binds are per joypad, not per user. */
const uint64_t joykey = (binds[port][i].joykey != NO_BTN)
? binds[port][i].joykey : joypad_info->auto_binds[i].joykey;
const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE)
? binds[port][i].joyaxis : joypad_info->auto_binds[i].joyaxis;
if (apple_key_state[rarch_keysym_lut[binds[port][i].key]])
{
ret |= (1 << i);
continue;
}
if ((uint16_t)joykey != NO_BTN && apple->joypad->button(joypad_info->joy_idx, (uint16_t)joykey))
{
ret |= (1 << i);
continue;
}
if (((float)abs(apple->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold)
{
ret |= (1 << i);
continue;
}
#ifdef HAVE_MFI
if ((uint16_t)joykey != NO_BTN && apple->sec_joypad->button(joypad_info->joy_idx, (uint16_t)joykey))
{
ret |= (1 << i);
continue;
}
if (((float)abs(apple->sec_joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold)
{
ret |= (1 << i);
continue;
}
#endif
if (cocoa_is_pressed(apple, joypad_info, binds[port], port, i))
ret |= (1 << i);
}
return ret;
}
else
{
/* Auto-binds are per joypad, not per user. */
const uint64_t joykey = (binds[port][id].joykey != NO_BTN)
? binds[port][id].joykey : joypad_info->auto_binds[id].joykey;
const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE)
? binds[port][id].joyaxis : joypad_info->auto_binds[id].joyaxis;
if (id < RARCH_BIND_LIST_END)
if (apple_key_state[rarch_keysym_lut[binds[port][id].key]])
return 1;
if ((uint16_t)joykey != NO_BTN && apple->joypad->button(
joypad_info->joy_idx, (uint16_t)joykey))
return 1;
if (((float)abs(apple->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold)
return 1;
#ifdef HAVE_MFI
if ((uint16_t)joykey != NO_BTN && apple->sec_joypad->button(joypad_info->joy_idx, (uint16_t)joykey))
return 1;
if (((float)abs(apple->sec_joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold)
return 1;
#endif
return cocoa_is_pressed(apple, joypad_info, binds[port], port, id);
}
break;
case RETRO_DEVICE_ANALOG: