diff options
Diffstat (limited to 'source/in_dx.c')
-rw-r--r-- | source/in_dx.c | 78 |
1 files changed, 37 insertions, 41 deletions
diff --git a/source/in_dx.c b/source/in_dx.c index 684853a..3d7e508 100644 --- a/source/in_dx.c +++ b/source/in_dx.c @@ -37,12 +37,12 @@ typedef HRESULT (WINAPI *LPDIRECTINPUTCREATE)( HINSTANCE, DWORD, LPDIRECTINPUT * static LPDIRECTINPUTCREATE pDirectInputCreate; -static qboolean di_active; // qfalse when not focus app +static grab_t di_grabbed; // qfalse when not focus app static qboolean di_initialized; static LPDIRECTINPUT di; static LPDIRECTINPUTDEVICE di_mouse; -static DIOBJECTDATAFORMAT mouseObjectDataFormat[] = { +static const DIOBJECTDATAFORMAT mouseObjectDataFormat[] = { { &GUID_XAxis, DIMOFS_X, DIDFT_RELAXIS|DIDFT_ANYINSTANCE, 0 }, { &GUID_YAxis, DIMOFS_Y, DIDFT_RELAXIS|DIDFT_ANYINSTANCE, 0 }, { &GUID_ZAxis, DIMOFS_Z, DIDFT_RELAXIS|DIDFT_ANYINSTANCE|DIDFT_OPTIONAL, 0 }, @@ -56,7 +56,7 @@ static DIOBJECTDATAFORMAT mouseObjectDataFormat[] = { { NULL, DIMOFS_BUTTON7, DIDFT_BUTTON|DIDFT_ANYINSTANCE|DIDFT_OPTIONAL, 0 } }; -static DIDATAFORMAT mouseDataFormat = { +static const DIDATAFORMAT mouseDataFormat = { sizeof( DIDATAFORMAT ), sizeof( DIOBJECTDATAFORMAT ), DIDF_RELAXIS, @@ -65,7 +65,7 @@ static DIDATAFORMAT mouseDataFormat = { mouseObjectDataFormat }; -static DIPROPDWORD mouseBufferSize = { +static const DIPROPDWORD mouseBufferSize = { { sizeof( DIPROPDWORD ), sizeof( DIPROPHEADER ), @@ -80,7 +80,7 @@ static DIPROPDWORD mouseBufferSize = { #endif #define DEFINE_GUID( name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8 ) \ - const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } + static const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } DEFINE_GUID( GUID_SysMouse, 0x6F1D2B60, 0xD5A0, 0x11CF, 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 ); DEFINE_GUID( GUID_XAxis, 0xA36D02E0, 0xC9F3, 0x11CF, 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 ); @@ -89,22 +89,17 @@ DEFINE_GUID( GUID_ZAxis, 0xA36D02E2, 0xC9F3, 0x11CF, 0xBF, 0xC7, 0x44, 0x45, 0x5 /* =========== -DI_SendMouseMoveEvents +DI_GetMouseEvents =========== */ -void DI_SendMouseMoveEvents( void ) { +static void DI_GetMouseEvents( void ) { DIDEVICEOBJECTDATA data[16]; LPDIDEVICEOBJECTDATA p, last; - DIMOUSESTATE2 state; DWORD numElements, button; int value; HRESULT hr; - if( !di_initialized ) { - return; - } - - if( !di_active ) { + if( !di_initialized || !di_grabbed ) { return; } @@ -120,7 +115,7 @@ void DI_SendMouseMoveEvents( void ) { return; } last = data + numElements; - for( p = data; p != last; p++ ) { + for( p = data; p < last; p++ ) { switch( p->dwOfs ) { case DIMOFS_BUTTON0: case DIMOFS_BUTTON1: @@ -155,17 +150,30 @@ void DI_SendMouseMoveEvents( void ) { } } } while( hr == DI_BUFFEROVERFLOW ); +} + +/* +=========== +DI_GetMouseMotion +=========== +*/ +static qboolean DI_GetMouseMotion( int *dx, int *dy ) { + DIMOUSESTATE2 state; + HRESULT hr; + + if( !di_initialized || !di_grabbed ) { + return qfalse; + } hr = IDirectInputDevice_GetDeviceState( di_mouse, sizeof( state ), &state ); if( FAILED( hr ) ) { Com_EPrintf( "GetDeviceState failed with error 0x%lX\n", hr ); - return; - } - - if( state.lX || state.lY ) { - CL_MouseEvent( state.lX, state.lY ); + return qfalse; } + *dx = state.lX; + *dy = state.lY; + return qtrue; } /* @@ -177,7 +185,7 @@ static void DI_ShutdownMouse( void ) { Com_Printf( "Shutting down DirectInput\n" ); if( di_mouse ) { - if( di_active ) { + if( di_grabbed ) { IDirectInputDevice_Unacquire( di_mouse ); } IDirectInputDevice_Release( di_mouse ); @@ -187,7 +195,7 @@ static void DI_ShutdownMouse( void ) { IDirectInput_Release( di ); di = NULL; } - di_active = qfalse; + di_grabbed = qfalse; di_initialized = qfalse; } @@ -269,25 +277,21 @@ fail: /* =========== -DI_ActivateMouse - -Called when the main window gains or loses focus. -The window may have been destroyed and recreated -between a deactivate and an activate. +DI_GrabMouse =========== */ -static void DI_ActivateMouse( qboolean active ) { +static void DI_GrabMouse( grab_t grab ) { HRESULT hr; if( !di_initialized ) { return; } - if( di_active == active ) { + if( di_grabbed == grab ) { return; } - if( active ) { + if( grab ) { Com_DPrintf( "IDirectInputDevice_Acquire\n" ); hr = IDirectInputDevice_Acquire( di_mouse ); if( FAILED( hr ) ) { @@ -301,16 +305,8 @@ static void DI_ActivateMouse( qboolean active ) { } } - di_active = active; - -} + di_grabbed = grab; -/* -=================== -DI_ClearMouseStates -=================== -*/ -static void DI_ClearMouseStates( void ) { } /* @@ -321,8 +317,8 @@ DI_FillAPI void DI_FillAPI( inputAPI_t *api ) { api->Init = DI_InitMouse; api->Shutdown = DI_ShutdownMouse; - api->Activate = DI_ActivateMouse; - api->Frame = DI_SendMouseMoveEvents; - api->ClearStates = DI_ClearMouseStates; + api->Grab = DI_GrabMouse; + api->GetEvents = DI_GetMouseEvents; + api->GetMotion = DI_GetMouseMotion; } |