Add jstick member functions missing on Windows implementation.

This commit is contained in:
2025-06-12 03:49:54 -04:00
parent c9e64c5fe6
commit 9117f778b3
2 changed files with 36 additions and 9 deletions

View File

@@ -49,8 +49,7 @@ namespace jstick {
enum class XBoxButton : uint8_t
{
enum class XBoxButton : uint8_t {
ButtonA = 0,
ButtonB = 1,
ButtonX = 2,
@@ -62,7 +61,6 @@ namespace jstick {
TheBigOne = 8,
ThumbL = 9,
ThumbR = 10,
DPadDown = 11,
DPadRight = 12,
DPadUp = 13,
@@ -72,27 +70,26 @@ namespace jstick {
/// This event is fired when a new joystick device is detected.
// TODO: Call JoystickConnected for each device found on library runtime start.
inline Event<int> JoystickConnected;
/// This event is fired when a joystick device is unplugged or otherwise dropped.
inline Event<int> JoystickDisconnected;
/// This event is fired when a joystick button is pressed.
inline Event<XBoxButton> ButtonPressed;
/// This event is fired when a xbox button is pressed.
inline Event<XBoxButton> ButtonReleased;
///
inline Event<Vector2> LeftThumbstickMoved;
///
inline Event<Vector2> RightThumbstickMoved;
///
inline Event<Vector2> DPadMoved;
///
inline Event<short> LeftTriggerMoved;
///
inline Event<short> RightTriggerMoved;
//Event<int, JoystickAxis> AxisMoved;
bool Initialize();
bool Cleanup();
/// @return true if the input system treats the DPad as a Vector2 axis, or false if treated as four buttons.
bool GetDPadIsAxisOrButtons();

View File

@@ -22,6 +22,25 @@ bool jstick::Cleanup() { return true; }
void jstick::JoystickServiceUpdate() { }
// XInput cannot tell us what type of device it is, so assume it's a legitimate Microsoft XB360 controller.
std::string jstick::GetDeviceName(int hwid) { return "Microsoft X-Box 360 pad"; }
jstick::ControllerType jstick::GetDeviceTypeFromName(const std::string &name) {
// On Windows, we assume the standard controller, we have no way of knowing specifics currently.
// ~josh.
return ControllerType::XBox;
}
int jstick::NumJoysticksDetected() {
// TODO: Check it properly!!
if (JoystickDetected())
return 1;
return 0;
}
Vector2 jstick::GetDPadAxis(float deadzone, int hwid)
{
// "Synthesize" a DPad vector based upon whether the buttons are pressed.
@@ -150,6 +169,17 @@ Vector2 jstick::GetRightThumbstickAxis(float deadzone, int hwid)
return Vector2(state.Gamepad.sThumbRX, state.Gamepad.sThumbRY);
}
int jstick::Connect(int hwid)
{
return hwid;
}
bool jstick::Disconnect(int hwid) {
return true;
}
bool jstick::Connected(int hwid) { return true; }
Vector2 jstick::GetRightThumbstickAxisNormalized(float deadzone, int hwid)
{
Vector2 axisL = jstick::GetLeftThumbstickAxis(deadzone, hwid);