mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2025-01-18 06:25:37 +00:00
DInputControllerInterface: Support diagonals in hat
This commit is contained in:
parent
03905b8f2e
commit
f1fb7383b7
|
@ -222,19 +222,24 @@ void DInputControllerInterface::PollEvents()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 DInputControllerInterface::GetHatDirection(DWORD hat)
|
std::array<bool, ControllerInterface::NUM_HAT_DIRECTIONS> DInputControllerInterface::GetHatButtons(DWORD hat)
|
||||||
{
|
{
|
||||||
|
std::array<bool, NUM_HAT_DIRECTIONS> buttons = {};
|
||||||
|
|
||||||
const WORD hv = LOWORD(hat);
|
const WORD hv = LOWORD(hat);
|
||||||
if (hv == 0xFFFF)
|
if (hv != 0xFFFF)
|
||||||
return NUM_HAT_DIRECTIONS;
|
{
|
||||||
else if (hv < 9000)
|
if ((hv >= 0 && hv < 9000) || hv >= 31500)
|
||||||
return HAT_DIRECTION_UP;
|
buttons[HAT_DIRECTION_UP] = true;
|
||||||
else if (hv < 18000)
|
if (hv >= 4500 && hv < 18000)
|
||||||
return HAT_DIRECTION_RIGHT;
|
buttons[HAT_DIRECTION_RIGHT] = true;
|
||||||
else if (hv < 27000)
|
if (hv >= 13500 && hv < 27000)
|
||||||
return HAT_DIRECTION_DOWN;
|
buttons[HAT_DIRECTION_DOWN] = true;
|
||||||
else
|
if (hv >= 22500)
|
||||||
return HAT_DIRECTION_LEFT;
|
buttons[HAT_DIRECTION_LEFT] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return buttons;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DInputControllerInterface::CheckForStateChanges(u32 index, const DIJOYSTATE& new_state)
|
void DInputControllerInterface::CheckForStateChanges(u32 index, const DIJOYSTATE& new_state)
|
||||||
|
@ -268,14 +273,16 @@ void DInputControllerInterface::CheckForStateChanges(u32 index, const DIJOYSTATE
|
||||||
{
|
{
|
||||||
if (last_state.rgdwPOV[0] != new_state.rgdwPOV[0])
|
if (last_state.rgdwPOV[0] != new_state.rgdwPOV[0])
|
||||||
{
|
{
|
||||||
|
Log_InfoPrintf("Hat %u", LOWORD(new_state.rgdwPOV[0]));
|
||||||
// map hats to the last buttons
|
// map hats to the last buttons
|
||||||
const u32 old_direction = GetHatDirection(last_state.rgdwPOV[0]);
|
const std::array<bool, NUM_HAT_DIRECTIONS> old_buttons(GetHatButtons(last_state.rgdwPOV[0]));
|
||||||
if (old_direction != NUM_HAT_DIRECTIONS)
|
const std::array<bool, NUM_HAT_DIRECTIONS> new_buttons(GetHatButtons(new_state.rgdwPOV[0]));
|
||||||
HandleButtonEvent(index, cd.num_buttons + old_direction, false);
|
for (u32 i = 0; i < NUM_HAT_DIRECTIONS; i++)
|
||||||
|
{
|
||||||
|
if (old_buttons[i] != new_buttons[i])
|
||||||
|
HandleButtonEvent(index, cd.num_buttons + i, new_buttons[i]);
|
||||||
|
}
|
||||||
|
|
||||||
const u32 new_direction = GetHatDirection(new_state.rgdwPOV[0]);
|
|
||||||
if (new_direction != NUM_HAT_DIRECTIONS)
|
|
||||||
HandleButtonEvent(index, cd.num_buttons + new_direction, true);
|
|
||||||
last_state.rgdwPOV[0] = new_state.rgdwPOV[0];
|
last_state.rgdwPOV[0] = new_state.rgdwPOV[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ private:
|
||||||
void AddDevices();
|
void AddDevices();
|
||||||
bool AddDevice(ControllerData& cd, const char* name);
|
bool AddDevice(ControllerData& cd, const char* name);
|
||||||
|
|
||||||
static u32 GetHatDirection(DWORD hat);
|
static std::array<bool, NUM_HAT_DIRECTIONS> GetHatButtons(DWORD hat);
|
||||||
|
|
||||||
void CheckForStateChanges(u32 index, const DIJOYSTATE& new_state);
|
void CheckForStateChanges(u32 index, const DIJOYSTATE& new_state);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue