dinput: Reset axis and pov values on object property change.
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
1ae1744cb2
commit
c918234f71
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include "windef.h"
|
#include "windef.h"
|
||||||
#include "winbase.h"
|
#include "winbase.h"
|
||||||
|
@ -1037,6 +1038,39 @@ static BOOL CALLBACK set_object_property( const DIDEVICEOBJECTINSTANCEW *instanc
|
||||||
return DIENUM_CONTINUE;
|
return DIENUM_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static BOOL CALLBACK reset_object_value( const DIDEVICEOBJECTINSTANCEW *instance, void *context )
|
||||||
|
{
|
||||||
|
struct dinput_device *impl = context;
|
||||||
|
struct object_properties *properties;
|
||||||
|
LONG tmp = -1;
|
||||||
|
|
||||||
|
if (!impl->object_properties) return DIENUM_STOP;
|
||||||
|
properties = impl->object_properties + instance->dwOfs / sizeof(LONG);
|
||||||
|
|
||||||
|
if (instance->dwType & DIDFT_AXIS)
|
||||||
|
{
|
||||||
|
if (!properties->range_min) tmp = properties->range_max / 2;
|
||||||
|
else tmp = round( (properties->range_min + properties->range_max) / 2.0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
*(LONG *)(impl->device_state + instance->dwOfs) = tmp;
|
||||||
|
return DIENUM_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void reset_device_state( IDirectInputDevice8W *iface )
|
||||||
|
{
|
||||||
|
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
|
||||||
|
DIPROPHEADER filter =
|
||||||
|
{
|
||||||
|
.dwHeaderSize = sizeof(DIPROPHEADER),
|
||||||
|
.dwSize = sizeof(DIPROPHEADER),
|
||||||
|
.dwHow = DIPH_DEVICE,
|
||||||
|
.dwObj = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
impl->vtbl->enum_objects( iface, &filter, DIDFT_AXIS | DIDFT_POV, reset_object_value, impl );
|
||||||
|
}
|
||||||
|
|
||||||
static HRESULT WINAPI dinput_device_SetProperty( IDirectInputDevice8W *iface, const GUID *guid,
|
static HRESULT WINAPI dinput_device_SetProperty( IDirectInputDevice8W *iface, const GUID *guid,
|
||||||
const DIPROPHEADER *header )
|
const DIPROPHEADER *header )
|
||||||
{
|
{
|
||||||
|
@ -1065,6 +1099,7 @@ static HRESULT WINAPI dinput_device_SetProperty( IDirectInputDevice8W *iface, co
|
||||||
if (value->lMin > value->lMax) return DIERR_INVALIDPARAM;
|
if (value->lMin > value->lMax) return DIERR_INVALIDPARAM;
|
||||||
hr = impl->vtbl->enum_objects( iface, &filter, DIDFT_AXIS, set_object_property, ¶ms );
|
hr = impl->vtbl->enum_objects( iface, &filter, DIDFT_AXIS, set_object_property, ¶ms );
|
||||||
if (FAILED(hr)) return hr;
|
if (FAILED(hr)) return hr;
|
||||||
|
reset_device_state( iface );
|
||||||
return DI_OK;
|
return DI_OK;
|
||||||
}
|
}
|
||||||
case (DWORD_PTR)DIPROP_DEADZONE:
|
case (DWORD_PTR)DIPROP_DEADZONE:
|
||||||
|
@ -1075,6 +1110,7 @@ static HRESULT WINAPI dinput_device_SetProperty( IDirectInputDevice8W *iface, co
|
||||||
if (value->dwData > 10000) return DIERR_INVALIDPARAM;
|
if (value->dwData > 10000) return DIERR_INVALIDPARAM;
|
||||||
hr = impl->vtbl->enum_objects( iface, &filter, DIDFT_AXIS, set_object_property, ¶ms );
|
hr = impl->vtbl->enum_objects( iface, &filter, DIDFT_AXIS, set_object_property, ¶ms );
|
||||||
if (FAILED(hr)) return hr;
|
if (FAILED(hr)) return hr;
|
||||||
|
reset_device_state( iface );
|
||||||
return DI_OK;
|
return DI_OK;
|
||||||
}
|
}
|
||||||
case (DWORD_PTR)DIPROP_AUTOCENTER:
|
case (DWORD_PTR)DIPROP_AUTOCENTER:
|
||||||
|
@ -1922,6 +1958,9 @@ static BOOL CALLBACK enum_objects_init( const DIDEVICEOBJECTINSTANCEW *instance,
|
||||||
obj_format->dwFlags = instance->dwFlags;
|
obj_format->dwFlags = instance->dwFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (impl->object_properties && (instance->dwType & (DIDFT_AXIS | DIDFT_POV)))
|
||||||
|
reset_object_value( instance, impl );
|
||||||
|
|
||||||
format->dwNumObjs++;
|
format->dwNumObjs++;
|
||||||
return DIENUM_CONTINUE;
|
return DIENUM_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -789,17 +789,10 @@ static void set_extra_caps_range( struct hid_joystick *impl, const DIDEVICEOBJEC
|
||||||
properties->range_min = min;
|
properties->range_min = min;
|
||||||
properties->range_max = max;
|
properties->range_max = max;
|
||||||
|
|
||||||
if (instance->dwType & DIDFT_AXIS)
|
if (instance->dwType & DIDFT_POV)
|
||||||
{
|
|
||||||
if (!properties->range_min) tmp = properties->range_max / 2;
|
|
||||||
else tmp = round( (properties->range_min + properties->range_max) / 2.0 );
|
|
||||||
*(LONG *)(impl->base.device_state + instance->dwOfs) = tmp;
|
|
||||||
}
|
|
||||||
else if (instance->dwType & DIDFT_POV)
|
|
||||||
{
|
{
|
||||||
tmp = properties->logical_max - properties->logical_min;
|
tmp = properties->logical_max - properties->logical_min;
|
||||||
if (tmp > 0) properties->range_max -= max / (tmp + 1);
|
if (tmp > 0) properties->range_max -= max / (tmp + 1);
|
||||||
*(LONG *)(impl->base.device_state + instance->dwOfs) = -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue