[PATCH 6/6] windows.gaming.input: Implement GetCurrentReading for the Gamepad runtimeclass.
Rémi Bernon
rbernon at codeweavers.com
Thu Mar 10 03:38:44 CST 2022
Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
dlls/windows.gaming.input/gamepad.c | 70 ++++++++++++++++++++++++++++-
1 file changed, 68 insertions(+), 2 deletions(-)
diff --git a/dlls/windows.gaming.input/gamepad.c b/dlls/windows.gaming.input/gamepad.c
index fbb439d3fec..2f17f5ba752 100644
--- a/dlls/windows.gaming.input/gamepad.c
+++ b/dlls/windows.gaming.input/gamepad.c
@@ -65,6 +65,7 @@ struct gamepad
LONG ref;
IGameControllerProvider *provider;
+ IWineGameControllerProvider *wine_provider;
};
static inline struct gamepad *impl_from_IGameControllerImpl( IGameControllerImpl *iface )
@@ -120,6 +121,7 @@ static ULONG WINAPI controller_Release( IGameControllerImpl *iface )
if (!ref)
{
+ IWineGameControllerProvider_Release( impl->wine_provider );
IGameControllerProvider_Release( impl->provider );
free( impl );
}
@@ -157,6 +159,10 @@ static HRESULT WINAPI controller_Initialize( IGameControllerImpl *iface, IGameCo
impl->IGameController_outer = outer;
IGameControllerProvider_AddRef( (impl->provider = provider) );
+ hr = IGameControllerProvider_QueryInterface( provider, &IID_IWineGameControllerProvider,
+ (void **)&impl->wine_provider );
+ if (FAILED(hr)) return hr;
+
EnterCriticalSection( &gamepad_cs );
if (SUCCEEDED(hr = init_gamepads()))
hr = IVector_Gamepad_Append( gamepads, &impl->IGamepad_iface );
@@ -222,8 +228,68 @@ static HRESULT WINAPI gamepad_put_Vibration( IGamepad *iface, struct GamepadVibr
static HRESULT WINAPI gamepad_GetCurrentReading( IGamepad *iface, struct GamepadReading *value )
{
- FIXME( "iface %p, value %p stub!\n", iface, value );
- return E_NOTIMPL;}
+ struct gamepad *impl = impl_from_IGamepad( iface );
+ struct WineGameControllerState state;
+ HRESULT hr;
+
+ TRACE( "iface %p, value %p.\n", iface, value );
+
+ if (FAILED(hr = IWineGameControllerProvider_get_State( impl->wine_provider, &state ))) return hr;
+
+ if (state.buttons[0]) value->Buttons |= GamepadButtons_A;
+ if (state.buttons[1]) value->Buttons |= GamepadButtons_B;
+ if (state.buttons[2]) value->Buttons |= GamepadButtons_X;
+ if (state.buttons[3]) value->Buttons |= GamepadButtons_Y;
+ if (state.buttons[4]) value->Buttons |= GamepadButtons_LeftShoulder;
+ if (state.buttons[5]) value->Buttons |= GamepadButtons_RightShoulder;
+ if (state.buttons[6]) value->Buttons |= GamepadButtons_Menu;
+ if (state.buttons[7]) value->Buttons |= GamepadButtons_View;
+ if (state.buttons[8]) value->Buttons |= GamepadButtons_LeftThumbstick;
+ if (state.buttons[9]) value->Buttons |= GamepadButtons_RightThumbstick;
+
+ switch (state.switches[0])
+ {
+ case GameControllerSwitchPosition_Up:
+ case GameControllerSwitchPosition_UpRight:
+ case GameControllerSwitchPosition_UpLeft:
+ value->Buttons |= GamepadButtons_DPadUp;
+ break;
+ case GameControllerSwitchPosition_Down:
+ case GameControllerSwitchPosition_DownRight:
+ case GameControllerSwitchPosition_DownLeft:
+ value->Buttons |= GamepadButtons_DPadDown;
+ break;
+ default:
+ break;
+ }
+
+ switch (state.switches[0])
+ {
+ case GameControllerSwitchPosition_Right:
+ case GameControllerSwitchPosition_UpRight:
+ case GameControllerSwitchPosition_DownRight:
+ value->Buttons |= GamepadButtons_DPadRight;
+ break;
+ case GameControllerSwitchPosition_Left:
+ case GameControllerSwitchPosition_UpLeft:
+ case GameControllerSwitchPosition_DownLeft:
+ value->Buttons |= GamepadButtons_DPadLeft;
+ break;
+ default:
+ break;
+ }
+
+ value->LeftThumbstickX = 2. * state.axes[0] - 1.;
+ value->LeftThumbstickY = 1. - 2. * state.axes[1];
+ value->LeftTrigger = state.axes[2];
+ value->RightThumbstickX = 2. * state.axes[3] - 1.;
+ value->RightThumbstickY = 1. - 2. * state.axes[4];
+ value->RightTrigger = state.axes[5];
+
+ value->Timestamp = state.timestamp;
+
+ return hr;
+}
static const struct IGamepadVtbl gamepad_vtbl =
{
--
2.35.1
More information about the wine-devel
mailing list