From 27829e4337ed667f6f5ef851e19c71d29d5ce844 Mon Sep 17 00:00:00 2001 From: Lionel Ulmer Date: Sat, 24 Oct 1998 11:04:07 +0000 Subject: [PATCH] Beginning of mouse support in DirectInput (only "standard" mouse configuration supported for now). --- include/dinput.h | 16 ++++++++ windows/dinput.c | 103 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 116 insertions(+), 3 deletions(-) diff --git a/include/dinput.h b/include/dinput.h index de79972c8ab..784840e60b7 100644 --- a/include/dinput.h +++ b/include/dinput.h @@ -59,6 +59,7 @@ DEFINE_GUID(GUID_CustomForce, 0x13541C2B,0x8E33,0x11D0,0x9A,0xD0,0x00,0xA0,0xC9, typedef struct IDirectInput32A IDirectInput32A,*LPDIRECTINPUT32A; typedef struct IDirectInputDevice32A IDirectInputDevice32A,*LPDIRECTINPUTDEVICE32A; typedef struct SysKeyboard32A SysKeyboard32A,*LPSYSKEYBOARD32A; +typedef struct SysMouse32A SysMouse32A,*LPSYSMOUSE32A; #define DI_OK S_OK #define DI_NOTATTACHED S_FALSE @@ -522,6 +523,21 @@ struct IDirectInputDevice32A { GUID guid; }; +/* "Standard" Mouse report... */ +struct DIMOUSESTATE { + LONG lX; + LONG lY; + LONG lZ; + BYTE rgbButtons[4]; +}; +struct SysMouse32A { + LPDIRECTINPUTDEVICEA_VTABLE lpvtbl; + DWORD ref; + GUID guid; + BYTE absolute; + struct DIMOUSESTATE prevpos; +}; + struct SysKeyboard32A { LPDIRECTINPUTDEVICEA_VTABLE lpvtbl; DWORD ref; diff --git a/windows/dinput.c b/windows/dinput.c index c2c72d4170c..f382425c599 100644 --- a/windows/dinput.c +++ b/windows/dinput.c @@ -92,7 +92,7 @@ static HRESULT WINAPI IDirectInputA_CreateDevice( return 0; } if (!memcmp(&GUID_SysMouse,rguid,sizeof(GUID_SysMouse))) { - *pdev = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectInputDevice32A)); + *pdev = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysMouse32A)); (*pdev)->ref = 1; (*pdev)->lpvtbl = &SysMouseAvt; memcpy(&((*pdev)->guid),rguid,sizeof(*rguid)); @@ -353,6 +353,103 @@ static HRESULT WINAPI IDirectInputDeviceA_QueryInterface( return E_FAIL; } +/****************************************************************************** + * SysMouseA (DInput Mouse support) + */ +static HRESULT WINAPI SysMouseA_SetDataFormat( + LPDIRECTINPUTDEVICE32A this,LPCDIDATAFORMAT df +) { + int i; + LPSYSMOUSE32A mthis = (LPSYSMOUSE32A) this; + + TRACE(dinput,"(this=%p,%p)\n",this,df); + + TRACE(dinput,"(df.dwSize=%ld)\n",df->dwSize); + TRACE(dinput,"(df.dwObjsize=%ld)\n",df->dwObjSize); + TRACE(dinput,"(df.dwFlags=0x%08lx)\n",df->dwFlags); + TRACE(dinput,"(df.dwDataSize=%ld)\n",df->dwDataSize); + TRACE(dinput,"(df.dwNumObjs=%ld)\n",df->dwNumObjs); + + for (i=0;idwNumObjs;i++) { + char xbuf[50]; + + if (df->rgodf[i].pguid) + WINE_StringFromCLSID(df->rgodf[i].pguid,xbuf); + else + strcpy(xbuf,""); + TRACE(dinput,"df.rgodf[%d].guid %s\n",i,xbuf); + TRACE(dinput,"df.rgodf[%d].dwOfs %ld\n",i,df->rgodf[i].dwOfs); + TRACE(dinput,"dwType 0x%02lx,dwInstance %ld\n",DIDFT_GETTYPE(df->rgodf[i].dwType),DIDFT_GETINSTANCE(df->rgodf[i].dwType)); + TRACE(dinput,"df.rgodf[%d].dwFlags 0x%08lx\n",i,df->rgodf[i].dwFlags); + } + + /* For the moment, ignore these fields and return always as if + c_dfDIMouse was passed as format... */ + if (df->dwFlags == DIDF_ABSAXIS) + mthis->absolute = 1; + else { + Window rw, cr; + int rx, ry, cx, cy; + unsigned int mask; + + /* We need to get the initial "previous" position to be able + to return deltas */ + mthis->absolute = 0; + + /* Get the mouse position */ + TSXQueryPointer(display, rootWindow, &rw, &cr, + &rx, &ry, &cx, &cy, &mask); + /* Fill the initial mouse state structure */ + mthis->prevpos.lX = rx; + mthis->prevpos.lY = ry; + mthis->prevpos.lZ = 0; + mthis->prevpos.rgbButtons[0] = (mask & Button1Mask ? 0xFF : 0x00); + mthis->prevpos.rgbButtons[1] = (mask & Button2Mask ? 0xFF : 0x00); + mthis->prevpos.rgbButtons[2] = (mask & Button3Mask ? 0xFF : 0x00); + mthis->prevpos.rgbButtons[3] = (mask & Button4Mask ? 0xFF : 0x00); + } + + return 0; +} + +static HRESULT WINAPI SysMouseA_GetDeviceState( + LPDIRECTINPUTDEVICE32A this,DWORD len,LPVOID ptr +) { + Window rw, cr; + int rx, ry, cx, cy; + unsigned int mask; + struct DIMOUSESTATE *mstate = (struct DIMOUSESTATE *) ptr; + LPSYSMOUSE32A mthis = (LPSYSMOUSE32A) this; + + TRACE(dinput,"(this=%p,0x%08lx,%p): \n",this,len,ptr); + + /* Get the mouse position */ + TSXQueryPointer(display, rootWindow, &rw, &cr, + &rx, &ry, &cx, &cy, &mask); + TRACE(dinput,"(X:%d - Y:%d)\n", rx, ry); + + /* Fill the mouse state structure */ + if (mthis->absolute) { + mstate->lX = rx; + mstate->lY = ry; + } else { + mstate->lX = rx - mthis->prevpos.lX; + mstate->lY = ry - mthis->prevpos.lY; + /* Fill the previous position structure */ + mthis->prevpos.lX = rx; + mthis->prevpos.lY = ry; + } + mstate->lZ = 0; + mstate->rgbButtons[0] = (mask & Button1Mask ? 0xFF : 0x00); + mstate->rgbButtons[1] = (mask & Button2Mask ? 0xFF : 0x00); + mstate->rgbButtons[2] = (mask & Button3Mask ? 0xFF : 0x00); + mstate->rgbButtons[3] = (mask & Button4Mask ? 0xFF : 0x00); + + return 0; +} + + + static IDirectInputDeviceA_VTable SysKeyboardAvt={ IDirectInputDeviceA_QueryInterface, (void*)2, @@ -384,9 +481,9 @@ static IDirectInputDeviceA_VTable SysMouseAvt={ IDirectInputDeviceA_SetProperty, IDirectInputDeviceA_Acquire, IDirectInputDeviceA_Unacquire, - IDirectInputDeviceA_GetDeviceState, + SysMouseA_GetDeviceState, IDirectInputDeviceA_GetDeviceData, - IDirectInputDeviceA_SetDataFormat, + SysMouseA_SetDataFormat, IDirectInputDeviceA_SetEventNotification, IDirectInputDeviceA_SetCooperativeLevel, (void*)15,