mirror of
https://github.com/libretro/RetroArch
synced 2025-02-20 06:40:18 +00:00
Move more code to input_overlay.c
This commit is contained in:
parent
fd56d5c1b8
commit
1a4954ce55
@ -1421,3 +1421,177 @@ enum overlay_status input_overlay_status(input_overlay_t *ol)
|
||||
return OVERLAY_STATUS_NONE;
|
||||
return ol->state;
|
||||
}
|
||||
|
||||
/*
|
||||
* input_poll_overlay:
|
||||
*
|
||||
* Poll pressed buttons/keys on currently active overlay.
|
||||
**/
|
||||
void input_poll_overlay(float opacity)
|
||||
{
|
||||
input_overlay_state_t old_key_state;
|
||||
unsigned i, j, device;
|
||||
uint16_t key_mod = 0;
|
||||
bool polled = false;
|
||||
settings_t *settings = config_get_ptr();
|
||||
input_overlay_t *ol = input_overlay_get_ptr();
|
||||
input_overlay_state_t *ol_state = input_overlay_get_state_ptr();
|
||||
|
||||
if (!input_overlay_is_alive(ol) || !ol_state)
|
||||
return;
|
||||
|
||||
memcpy(old_key_state.keys, ol_state->keys,
|
||||
sizeof(ol_state->keys));
|
||||
memset(ol_state, 0, sizeof(*ol_state));
|
||||
|
||||
device = input_overlay_full_screen(ol) ?
|
||||
RARCH_DEVICE_POINTER_SCREEN : RETRO_DEVICE_POINTER;
|
||||
|
||||
for (i = 0;
|
||||
input_driver_state(NULL, 0, device, i,
|
||||
RETRO_DEVICE_ID_POINTER_PRESSED);
|
||||
i++)
|
||||
{
|
||||
input_overlay_state_t polled_data;
|
||||
int16_t x = input_driver_state(NULL, 0,
|
||||
device, i, RETRO_DEVICE_ID_POINTER_X);
|
||||
int16_t y = input_driver_state(NULL, 0,
|
||||
device, i, RETRO_DEVICE_ID_POINTER_Y);
|
||||
|
||||
input_overlay_poll(ol, &polled_data, x, y);
|
||||
|
||||
ol_state->buttons |= polled_data.buttons;
|
||||
|
||||
for (j = 0; j < ARRAY_SIZE(ol_state->keys); j++)
|
||||
ol_state->keys[j] |= polled_data.keys[j];
|
||||
|
||||
/* Fingers pressed later take prio and matched up
|
||||
* with overlay poll priorities. */
|
||||
for (j = 0; j < 4; j++)
|
||||
if (polled_data.analog[j])
|
||||
ol_state->analog[j] = polled_data.analog[j];
|
||||
|
||||
polled = true;
|
||||
}
|
||||
|
||||
if (OVERLAY_GET_KEY(ol_state, RETROK_LSHIFT) ||
|
||||
OVERLAY_GET_KEY(ol_state, RETROK_RSHIFT))
|
||||
key_mod |= RETROKMOD_SHIFT;
|
||||
|
||||
if (OVERLAY_GET_KEY(ol_state, RETROK_LCTRL) ||
|
||||
OVERLAY_GET_KEY(ol_state, RETROK_RCTRL))
|
||||
key_mod |= RETROKMOD_CTRL;
|
||||
|
||||
if (OVERLAY_GET_KEY(ol_state, RETROK_LALT) ||
|
||||
OVERLAY_GET_KEY(ol_state, RETROK_RALT))
|
||||
key_mod |= RETROKMOD_ALT;
|
||||
|
||||
if (OVERLAY_GET_KEY(ol_state, RETROK_LMETA) ||
|
||||
OVERLAY_GET_KEY(ol_state, RETROK_RMETA))
|
||||
key_mod |= RETROKMOD_META;
|
||||
|
||||
/* CAPSLOCK SCROLLOCK NUMLOCK */
|
||||
for (i = 0; i < ARRAY_SIZE(ol_state->keys); i++)
|
||||
{
|
||||
if (ol_state->keys[i] != old_key_state.keys[i])
|
||||
{
|
||||
uint32_t orig_bits = old_key_state.keys[i];
|
||||
uint32_t new_bits = ol_state->keys[i];
|
||||
|
||||
for (j = 0; j < 32; j++)
|
||||
if ((orig_bits & (1 << j)) != (new_bits & (1 << j)))
|
||||
input_keyboard_event(new_bits & (1 << j),
|
||||
i * 32 + j, 0, key_mod, RETRO_DEVICE_POINTER);
|
||||
}
|
||||
}
|
||||
|
||||
/* Map "analog" buttons to analog axes like regular input drivers do. */
|
||||
for (j = 0; j < 4; j++)
|
||||
{
|
||||
unsigned bind_plus = RARCH_ANALOG_LEFT_X_PLUS + 2 * j;
|
||||
unsigned bind_minus = bind_plus + 1;
|
||||
|
||||
if (ol_state->analog[j])
|
||||
continue;
|
||||
|
||||
if (ol_state->buttons & (1UL << bind_plus))
|
||||
ol_state->analog[j] += 0x7fff;
|
||||
if (ol_state->buttons & (1UL << bind_minus))
|
||||
ol_state->analog[j] -= 0x7fff;
|
||||
}
|
||||
|
||||
/* Check for analog_dpad_mode.
|
||||
* Map analogs to d-pad buttons when configured. */
|
||||
switch (settings->input.analog_dpad_mode[0])
|
||||
{
|
||||
case ANALOG_DPAD_LSTICK:
|
||||
case ANALOG_DPAD_RSTICK:
|
||||
{
|
||||
float analog_x, analog_y;
|
||||
unsigned analog_base = 2;
|
||||
|
||||
if (settings->input.analog_dpad_mode[0] == ANALOG_DPAD_LSTICK)
|
||||
analog_base = 0;
|
||||
|
||||
analog_x = (float)ol_state->analog[analog_base + 0] / 0x7fff;
|
||||
analog_y = (float)ol_state->analog[analog_base + 1] / 0x7fff;
|
||||
|
||||
if (analog_x <= -settings->input.axis_threshold)
|
||||
ol_state->buttons |= (1UL << RETRO_DEVICE_ID_JOYPAD_LEFT);
|
||||
if (analog_x >= settings->input.axis_threshold)
|
||||
ol_state->buttons |= (1UL << RETRO_DEVICE_ID_JOYPAD_RIGHT);
|
||||
if (analog_y <= -settings->input.axis_threshold)
|
||||
ol_state->buttons |= (1UL << RETRO_DEVICE_ID_JOYPAD_UP);
|
||||
if (analog_y >= settings->input.axis_threshold)
|
||||
ol_state->buttons |= (1UL << RETRO_DEVICE_ID_JOYPAD_DOWN);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (polled)
|
||||
input_overlay_post_poll(ol, opacity);
|
||||
else
|
||||
input_overlay_poll_clear(ol, opacity);
|
||||
}
|
||||
|
||||
void input_state_overlay(int16_t *ret, unsigned port, unsigned device, unsigned idx,
|
||||
unsigned id)
|
||||
{
|
||||
input_overlay_state_t *ol_state = input_overlay_get_state_ptr();
|
||||
|
||||
if (!ol_state)
|
||||
return;
|
||||
|
||||
if (port != 0)
|
||||
return;
|
||||
|
||||
switch (device)
|
||||
{
|
||||
case RETRO_DEVICE_JOYPAD:
|
||||
if (ol_state && ol_state->buttons & (UINT64_C(1) << id))
|
||||
*ret |= 1;
|
||||
break;
|
||||
case RETRO_DEVICE_KEYBOARD:
|
||||
if (id < RETROK_LAST)
|
||||
{
|
||||
if (OVERLAY_GET_KEY(ol_state, id))
|
||||
*ret |= 1;
|
||||
}
|
||||
break;
|
||||
case RETRO_DEVICE_ANALOG:
|
||||
{
|
||||
unsigned base = 0;
|
||||
|
||||
if (idx == RETRO_DEVICE_INDEX_ANALOG_RIGHT)
|
||||
base = 2;
|
||||
if (id == RETRO_DEVICE_ID_ANALOG_Y)
|
||||
base += 1;
|
||||
if (ol_state && ol_state->analog[base])
|
||||
*ret = ol_state->analog[base];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -232,6 +232,18 @@ bool input_overlay_is_alive(input_overlay_t *ol);
|
||||
|
||||
enum overlay_status input_overlay_status(input_overlay_t *ol);
|
||||
|
||||
/*
|
||||
* input_poll_overlay:
|
||||
* @ol : pointer to overlay
|
||||
*
|
||||
* Poll pressed buttons/keys on currently active overlay.
|
||||
**/
|
||||
void input_poll_overlay(float opacity);
|
||||
|
||||
void input_state_overlay(int16_t *ret,
|
||||
unsigned port, unsigned device, unsigned idx,
|
||||
unsigned id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -161,9 +161,6 @@ static int16_t input_state(unsigned port, unsigned device,
|
||||
settings_t *settings = config_get_ptr();
|
||||
driver_t *driver = driver_get_ptr();
|
||||
global_t *global = global_get_ptr();
|
||||
#ifdef HAVE_OVERLAY
|
||||
input_overlay_state_t *ol_state = input_overlay_get_state_ptr();
|
||||
#endif
|
||||
|
||||
for (i = 0; i < MAX_USERS; i++)
|
||||
libretro_input_binds[i] = settings->input.binds[i];
|
||||
@ -188,35 +185,7 @@ static int16_t input_state(unsigned port, unsigned device,
|
||||
res = input_driver_state(libretro_input_binds, port, device, idx, id);
|
||||
|
||||
#ifdef HAVE_OVERLAY
|
||||
if (port == 0)
|
||||
{
|
||||
switch (device)
|
||||
{
|
||||
case RETRO_DEVICE_JOYPAD:
|
||||
if (ol_state && ol_state->buttons & (UINT64_C(1) << id))
|
||||
res |= 1;
|
||||
break;
|
||||
case RETRO_DEVICE_KEYBOARD:
|
||||
if (id < RETROK_LAST)
|
||||
{
|
||||
if (OVERLAY_GET_KEY(ol_state, id))
|
||||
res |= 1;
|
||||
}
|
||||
break;
|
||||
case RETRO_DEVICE_ANALOG:
|
||||
{
|
||||
unsigned base = 0;
|
||||
|
||||
if (idx == RETRO_DEVICE_INDEX_ANALOG_RIGHT)
|
||||
base = 2;
|
||||
if (id == RETRO_DEVICE_ID_ANALOG_Y)
|
||||
base += 1;
|
||||
if (ol_state && ol_state->analog[base])
|
||||
res = ol_state->analog[base];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
input_state_overlay(&res, port, device, idx, id);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -235,145 +204,6 @@ static int16_t input_state(unsigned port, unsigned device,
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_OVERLAY
|
||||
/*
|
||||
* input_poll_overlay:
|
||||
* @ol : pointer to overlay
|
||||
*
|
||||
* Poll pressed buttons/keys on currently active overlay.
|
||||
**/
|
||||
static INLINE void input_poll_overlay(
|
||||
input_overlay_t *ol, float opacity)
|
||||
{
|
||||
input_overlay_state_t old_key_state;
|
||||
unsigned i, j, device;
|
||||
uint16_t key_mod = 0;
|
||||
bool polled = false;
|
||||
settings_t *settings = config_get_ptr();
|
||||
input_overlay_state_t *ol_state = input_overlay_get_state_ptr();
|
||||
|
||||
if (!input_overlay_is_alive(ol) || !ol_state)
|
||||
return;
|
||||
|
||||
memcpy(old_key_state.keys, ol_state->keys,
|
||||
sizeof(ol_state->keys));
|
||||
memset(ol_state, 0, sizeof(*ol_state));
|
||||
|
||||
device = input_overlay_full_screen(ol) ?
|
||||
RARCH_DEVICE_POINTER_SCREEN : RETRO_DEVICE_POINTER;
|
||||
|
||||
for (i = 0;
|
||||
input_driver_state(NULL, 0, device, i,
|
||||
RETRO_DEVICE_ID_POINTER_PRESSED);
|
||||
i++)
|
||||
{
|
||||
input_overlay_state_t polled_data;
|
||||
int16_t x = input_driver_state(NULL, 0,
|
||||
device, i, RETRO_DEVICE_ID_POINTER_X);
|
||||
int16_t y = input_driver_state(NULL, 0,
|
||||
device, i, RETRO_DEVICE_ID_POINTER_Y);
|
||||
|
||||
input_overlay_poll(ol, &polled_data, x, y);
|
||||
|
||||
ol_state->buttons |= polled_data.buttons;
|
||||
|
||||
for (j = 0; j < ARRAY_SIZE(ol_state->keys); j++)
|
||||
ol_state->keys[j] |= polled_data.keys[j];
|
||||
|
||||
/* Fingers pressed later take prio and matched up
|
||||
* with overlay poll priorities. */
|
||||
for (j = 0; j < 4; j++)
|
||||
if (polled_data.analog[j])
|
||||
ol_state->analog[j] = polled_data.analog[j];
|
||||
|
||||
polled = true;
|
||||
}
|
||||
|
||||
if (OVERLAY_GET_KEY(ol_state, RETROK_LSHIFT) ||
|
||||
OVERLAY_GET_KEY(ol_state, RETROK_RSHIFT))
|
||||
key_mod |= RETROKMOD_SHIFT;
|
||||
|
||||
if (OVERLAY_GET_KEY(ol_state, RETROK_LCTRL) ||
|
||||
OVERLAY_GET_KEY(ol_state, RETROK_RCTRL))
|
||||
key_mod |= RETROKMOD_CTRL;
|
||||
|
||||
if (OVERLAY_GET_KEY(ol_state, RETROK_LALT) ||
|
||||
OVERLAY_GET_KEY(ol_state, RETROK_RALT))
|
||||
key_mod |= RETROKMOD_ALT;
|
||||
|
||||
if (OVERLAY_GET_KEY(ol_state, RETROK_LMETA) ||
|
||||
OVERLAY_GET_KEY(ol_state, RETROK_RMETA))
|
||||
key_mod |= RETROKMOD_META;
|
||||
|
||||
/* CAPSLOCK SCROLLOCK NUMLOCK */
|
||||
for (i = 0; i < ARRAY_SIZE(ol_state->keys); i++)
|
||||
{
|
||||
if (ol_state->keys[i] != old_key_state.keys[i])
|
||||
{
|
||||
uint32_t orig_bits = old_key_state.keys[i];
|
||||
uint32_t new_bits = ol_state->keys[i];
|
||||
|
||||
for (j = 0; j < 32; j++)
|
||||
if ((orig_bits & (1 << j)) != (new_bits & (1 << j)))
|
||||
input_keyboard_event(new_bits & (1 << j),
|
||||
i * 32 + j, 0, key_mod, RETRO_DEVICE_POINTER);
|
||||
}
|
||||
}
|
||||
|
||||
/* Map "analog" buttons to analog axes like regular input drivers do. */
|
||||
for (j = 0; j < 4; j++)
|
||||
{
|
||||
unsigned bind_plus = RARCH_ANALOG_LEFT_X_PLUS + 2 * j;
|
||||
unsigned bind_minus = bind_plus + 1;
|
||||
|
||||
if (ol_state->analog[j])
|
||||
continue;
|
||||
|
||||
if (ol_state->buttons & (1UL << bind_plus))
|
||||
ol_state->analog[j] += 0x7fff;
|
||||
if (ol_state->buttons & (1UL << bind_minus))
|
||||
ol_state->analog[j] -= 0x7fff;
|
||||
}
|
||||
|
||||
/* Check for analog_dpad_mode.
|
||||
* Map analogs to d-pad buttons when configured. */
|
||||
switch (settings->input.analog_dpad_mode[0])
|
||||
{
|
||||
case ANALOG_DPAD_LSTICK:
|
||||
case ANALOG_DPAD_RSTICK:
|
||||
{
|
||||
float analog_x, analog_y;
|
||||
unsigned analog_base = 2;
|
||||
|
||||
if (settings->input.analog_dpad_mode[0] == ANALOG_DPAD_LSTICK)
|
||||
analog_base = 0;
|
||||
|
||||
analog_x = (float)ol_state->analog[analog_base + 0] / 0x7fff;
|
||||
analog_y = (float)ol_state->analog[analog_base + 1] / 0x7fff;
|
||||
|
||||
if (analog_x <= -settings->input.axis_threshold)
|
||||
ol_state->buttons |= (1UL << RETRO_DEVICE_ID_JOYPAD_LEFT);
|
||||
if (analog_x >= settings->input.axis_threshold)
|
||||
ol_state->buttons |= (1UL << RETRO_DEVICE_ID_JOYPAD_RIGHT);
|
||||
if (analog_y <= -settings->input.axis_threshold)
|
||||
ol_state->buttons |= (1UL << RETRO_DEVICE_ID_JOYPAD_UP);
|
||||
if (analog_y >= settings->input.axis_threshold)
|
||||
ol_state->buttons |= (1UL << RETRO_DEVICE_ID_JOYPAD_DOWN);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (polled)
|
||||
input_overlay_post_poll(ol, opacity);
|
||||
else
|
||||
input_overlay_poll_clear(ol, opacity);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* input_poll:
|
||||
*
|
||||
@ -383,18 +213,13 @@ static void input_poll(void)
|
||||
{
|
||||
driver_t *driver = driver_get_ptr();
|
||||
settings_t *settings = config_get_ptr();
|
||||
#ifdef HAVE_OVERLAY
|
||||
input_overlay_t *overlay = input_overlay_get_ptr();
|
||||
#endif
|
||||
|
||||
input_driver_poll();
|
||||
|
||||
(void)driver;
|
||||
|
||||
#ifdef HAVE_OVERLAY
|
||||
if (overlay)
|
||||
input_poll_overlay(overlay,
|
||||
settings->input.overlay_opacity);
|
||||
input_poll_overlay(settings->input.overlay_opacity);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_COMMAND
|
||||
|
@ -293,7 +293,8 @@ void rarch_main_data_iterate(void)
|
||||
|
||||
static data_runloop_t *rarch_main_data_new(void)
|
||||
{
|
||||
data_runloop_t *runloop = (data_runloop_t*)calloc(1, sizeof(data_runloop_t));
|
||||
data_runloop_t *runloop = (data_runloop_t*)
|
||||
calloc(1, sizeof(data_runloop_t));
|
||||
|
||||
if (!runloop)
|
||||
return NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user