mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-24 16:39:43 +00:00
(dinput/xinput) Simplifications
This commit is contained in:
parent
2626282757
commit
20e8dfcba5
@ -217,8 +217,11 @@ static void dinput_poll(void *data)
|
||||
|
||||
if (di->mouse)
|
||||
{
|
||||
POINT point;
|
||||
DIMOUSESTATE2 mouse_state;
|
||||
POINT point = {0};
|
||||
|
||||
point.x = 0;
|
||||
point.y = 0;
|
||||
|
||||
memset(&mouse_state, 0, sizeof(mouse_state));
|
||||
|
||||
@ -257,13 +260,8 @@ static void dinput_poll(void *data)
|
||||
di->joypad->poll();
|
||||
}
|
||||
|
||||
static bool dinput_keyboard_pressed(struct dinput_input *di, unsigned key)
|
||||
{
|
||||
unsigned sym = rarch_keysym_lut[(enum retro_key)key];
|
||||
return di->state[sym] & 0x80;
|
||||
}
|
||||
|
||||
static bool dinput_mbutton_pressed(struct dinput_input *di, unsigned port, unsigned key)
|
||||
static bool dinput_mouse_button_pressed(
|
||||
struct dinput_input *di, unsigned port, unsigned key)
|
||||
{
|
||||
bool result;
|
||||
settings_t *settings = config_get_ptr();
|
||||
@ -272,45 +270,43 @@ static bool dinput_mbutton_pressed(struct dinput_input *di, unsigned port, unsig
|
||||
return false;
|
||||
|
||||
/* the driver only supports one mouse */
|
||||
if ( settings->uints.input_mouse_index[ port ] != 0 ) {
|
||||
if ( settings->uints.input_mouse_index[ port ] != 0 )
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ( key )
|
||||
{
|
||||
{
|
||||
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
||||
return di->mouse_l;
|
||||
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
||||
return di->mouse_r;
|
||||
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
|
||||
return di->mouse_m;
|
||||
case RETRO_DEVICE_ID_MOUSE_BUTTON_4:
|
||||
return di->mouse_b4;
|
||||
case RETRO_DEVICE_ID_MOUSE_BUTTON_5:
|
||||
return di->mouse_b5;
|
||||
|
||||
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
||||
return di->mouse_l;
|
||||
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
||||
return di->mouse_r;
|
||||
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
|
||||
return di->mouse_m;
|
||||
case RETRO_DEVICE_ID_MOUSE_BUTTON_4:
|
||||
return di->mouse_b4;
|
||||
case RETRO_DEVICE_ID_MOUSE_BUTTON_5:
|
||||
return di->mouse_b5;
|
||||
case RETRO_DEVICE_ID_MOUSE_WHEELUP:
|
||||
result = di->mouse_wu;
|
||||
di->mouse_wu = false;
|
||||
return result;
|
||||
|
||||
case RETRO_DEVICE_ID_MOUSE_WHEELUP:
|
||||
result = di->mouse_wu;
|
||||
di->mouse_wu = false;
|
||||
return result;
|
||||
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
|
||||
result = di->mouse_wd;
|
||||
di->mouse_wd = false;
|
||||
return result;
|
||||
|
||||
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
|
||||
result = di->mouse_wd;
|
||||
di->mouse_wd = false;
|
||||
return result;
|
||||
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP:
|
||||
result = di->mouse_hwu;
|
||||
di->mouse_hwu = false;
|
||||
return result;
|
||||
|
||||
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP:
|
||||
result = di->mouse_hwu;
|
||||
di->mouse_hwu = false;
|
||||
return result;
|
||||
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN:
|
||||
result = di->mouse_hwd;
|
||||
di->mouse_hwd = false;
|
||||
return result;
|
||||
|
||||
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN:
|
||||
result = di->mouse_hwd;
|
||||
di->mouse_hwd = false;
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -322,13 +318,17 @@ static bool dinput_is_pressed(struct dinput_input *di,
|
||||
{
|
||||
const struct retro_keybind *bind = &binds[id];
|
||||
|
||||
if ((bind->key < RETROK_LAST) && dinput_keyboard_pressed(di, bind->key))
|
||||
if ((id == RARCH_GAME_FOCUS_TOGGLE) || !di->blocked)
|
||||
return true;
|
||||
if (bind->key < RETROK_LAST)
|
||||
{
|
||||
unsigned sym = rarch_keysym_lut[(enum retro_key)bind->key];
|
||||
if (di->state[sym] & 0x80)
|
||||
if ((id == RARCH_GAME_FOCUS_TOGGLE) || !di->blocked)
|
||||
return true;
|
||||
}
|
||||
|
||||
if (binds && binds[id].valid)
|
||||
{
|
||||
if (dinput_mbutton_pressed(di, port, bind->mbutton))
|
||||
if (dinput_mouse_button_pressed(di, port, bind->mbutton))
|
||||
return true;
|
||||
if (input_joypad_pressed(di->joypad, joypad_info, port, binds, id))
|
||||
return true;
|
||||
@ -353,10 +353,18 @@ static int16_t dinput_pressed_analog(struct dinput_input *di,
|
||||
if (!bind_minus->valid || !bind_plus->valid)
|
||||
return 0;
|
||||
|
||||
if ((bind_minus->key < RETROK_LAST) && dinput_keyboard_pressed(di, bind_minus->key))
|
||||
pressed_minus = -0x7fff;
|
||||
if ((bind_plus->key < RETROK_LAST) && dinput_keyboard_pressed(di, bind_plus->key))
|
||||
pressed_plus = 0x7fff;
|
||||
if (bind_minus->key < RETROK_LAST)
|
||||
{
|
||||
unsigned sym = rarch_keysym_lut[(enum retro_key)bind_minus->key];
|
||||
if (di->state[sym] & 0x80)
|
||||
pressed_minus = -0x7fff;
|
||||
}
|
||||
if (bind_plus->key < RETROK_LAST)
|
||||
{
|
||||
unsigned sym = rarch_keysym_lut[(enum retro_key)bind_plus->key];
|
||||
if (di->state[sym] & 0x80)
|
||||
pressed_plus = 0x7fff;
|
||||
}
|
||||
|
||||
return pressed_plus + pressed_minus;
|
||||
}
|
||||
@ -591,7 +599,10 @@ static int16_t dinput_input_state(void *data,
|
||||
return dinput_is_pressed(di, joypad_info, binds[port], port, id);
|
||||
break;
|
||||
case RETRO_DEVICE_KEYBOARD:
|
||||
return (id < RETROK_LAST) && dinput_keyboard_pressed(di, id);
|
||||
{
|
||||
unsigned sym = rarch_keysym_lut[(enum retro_key)id];
|
||||
return (id < RETROK_LAST) && di->state[sym] & 0x80;
|
||||
}
|
||||
case RETRO_DEVICE_ANALOG:
|
||||
if (binds[port])
|
||||
{
|
||||
|
@ -139,14 +139,11 @@ static XINPUT_VIBRATION g_xinput_rumble_states[4];
|
||||
|
||||
static xinput_joypad_state g_xinput_states[4];
|
||||
|
||||
static INLINE int pad_index_to_xuser_index(unsigned pad)
|
||||
{
|
||||
#ifdef HAVE_DINPUT
|
||||
return g_xinput_pad_indexes[pad];
|
||||
#define pad_index_to_xuser_index(pad) g_xinput_pad_indexes[(pad)]
|
||||
#else
|
||||
return pad < MAX_PADS && g_xinput_states[pad].connected ? pad : -1;
|
||||
#define pad_index_to_xuser_index(pad) ((pad) < MAX_PADS && g_xinput_states[(pad)].connected ? (pad) : -1)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Generic "XInput" instead of "Xbox 360", because there are
|
||||
* some other non-xbox third party PC controllers.
|
||||
@ -445,7 +442,7 @@ static bool xinput_joypad_button(unsigned port_num, uint16_t joykey)
|
||||
return false;
|
||||
}
|
||||
|
||||
static int16_t xinput_joypad_axis (unsigned port_num, uint32_t joyaxis)
|
||||
static int16_t xinput_joypad_axis(unsigned port_num, uint32_t joyaxis)
|
||||
{
|
||||
int xuser;
|
||||
int16_t val = 0;
|
||||
@ -504,13 +501,12 @@ static int16_t xinput_joypad_axis (unsigned port_num, uint32_t joyaxis)
|
||||
}
|
||||
|
||||
if (is_neg && val > 0)
|
||||
val = 0;
|
||||
return 0;
|
||||
else if (is_pos && val < 0)
|
||||
val = 0;
|
||||
|
||||
return 0;
|
||||
/* Clamp to avoid overflow error. */
|
||||
if (val == -32768)
|
||||
val = -32767;
|
||||
else if (val == -32768)
|
||||
return -32767;
|
||||
|
||||
return val;
|
||||
}
|
||||
@ -546,9 +542,7 @@ static void xinput_joypad_poll(void)
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_xinput_states[i].connected = new_connected;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user