button_guide: support for PlayStation controller icons

This commit is contained in:
Hyper
2024-12-07 17:05:12 +00:00
parent 0d1a5e1fa1
commit d9d4ca2196
8 changed files with 74 additions and 38 deletions

View File

@@ -15,9 +15,14 @@ public:
SDL_JoystickID id{ -1 };
XAMINPUT_GAMEPAD state{};
XAMINPUT_VIBRATION vibration{ 0, 0 };
int index{};
Controller() = default;
explicit Controller(int index) : Controller(SDL_GameControllerOpen(index)) {}
explicit Controller(int index) : Controller(SDL_GameControllerOpen(index))
{
this->index = index;
}
Controller(SDL_GameController* controller) : controller(controller)
{
@@ -28,6 +33,24 @@ public:
id = SDL_JoystickInstanceID(joystick);
}
SDL_GameControllerType GetControllerType() const
{
return SDL_GameControllerTypeForIndex(index);
}
hid::detail::EInputDevice GetInputDevice() const
{
switch (GetControllerType())
{
case SDL_CONTROLLER_TYPE_PS3:
case SDL_CONTROLLER_TYPE_PS4:
case SDL_CONTROLLER_TYPE_PS5:
return hid::detail::EInputDevice::PlayStation;
}
return hid::detail::EInputDevice::Xbox;
}
void Close()
{
if (!controller)
@@ -167,7 +190,7 @@ int HID_OnSDLEvent(void*, SDL_Event* event)
controller->Poll();
}
hid::detail::g_inputDevice = hid::detail::EInputDevice::Controller;
hid::detail::g_inputDevice = controller->GetInputDevice();
}
}
}

View File

@@ -23,3 +23,9 @@ uint32_t hid::GetCapabilities(uint32_t dwUserIndex, XAMINPUT_CAPABILITIES* pCaps
{
return detail::GetCapabilities(dwUserIndex, pCaps);
}
bool hid::detail::IsInputDeviceController()
{
return hid::detail::g_inputDevice != hid::detail::EInputDevice::Keyboard &&
hid::detail::g_inputDevice != hid::detail::EInputDevice::Mouse;
}

View File

@@ -6,7 +6,8 @@ namespace hid::detail
{
Keyboard,
Mouse,
Controller
Xbox,
PlayStation
};
extern EInputDevice g_inputDevice;
@@ -16,4 +17,6 @@ namespace hid::detail
uint32_t GetState(uint32_t dwUserIndex, XAMINPUT_STATE* pState);
uint32_t SetState(uint32_t dwUserIndex, XAMINPUT_VIBRATION* pVibration);
uint32_t GetCapabilities(uint32_t dwUserIndex, XAMINPUT_CAPABILITIES* pCaps);
bool IsInputDeviceController();
}