18 HRESULT hr = m_poDXInputDevice->Acquire();
39 HRESULT hr = m_poDXInputDevice->Unacquire();
40 return SUCCEEDED( hr );
45 if ( m_poDXInputDevice )
47 m_poDXInputDevice->Release();
48 m_poDXInputDevice = NULL;
56 m_iDeltaPositionX = 0;
57 m_iDeltaPositionY = 0;
58 m_iDeltaPositionZ = 0;
60 HRESULT hRes = m_poDXInputDevice->Poll();
62 if ( SUCCEEDED( hRes ) )
65 hRes = m_poDXInputDevice->GetDeviceState(
sizeof( state ), &state );
67 if ( SUCCEEDED( hRes ) )
69 m_iDeltaPositionX += state.lX;
70 m_iPositionX += state.lX;
71 m_iDeltaPositionY += state.lY;
72 m_iPositionY += state.lY;
73 m_iDeltaPositionZ += state.lZ;
74 m_iPositionZ += state.lZ;
80 if ( !pDisplayParams->bWindowed )
93 DWORD dwItems = INFINITE;
97 HRESULT hr = m_poDXInputDevice->GetDeviceData(
sizeof( DIDEVICEOBJECTDATA ), NULL, &dwItems, 0 );
99 if ( SUCCEEDED( hr ) )
111 m_dwButtonPrevious = m_dwButtonCurrent;
115 DIDEVICEOBJECTDATA dod[ 32 ];
118 HRESULT hRes = m_poDXInputDevice->GetDeviceData(
sizeof( DIDEVICEOBJECTDATA ), dod, &dwItems, 0 );
120 if ( FAILED( hRes ) && hRes == ( DIERR_NOTACQUIRED | DIERR_INPUTLOST ) )
125 hRes = m_poDXInputDevice->GetDeviceData(
sizeof( DIDEVICEOBJECTDATA ), dod, &dwItems, 0 );
133 for ( DWORD i = 0; i < dwItems; i++ )
135 switch ( dod[ i ].dwOfs )
142 ( dod[ i ].dwOfs == DIMOFS_BUTTON0 ) ? ( !m_bReverseButtons ? 0 : 1 ) :
143 ( dod[ i ].dwOfs == DIMOFS_BUTTON1 ) ? ( !m_bReverseButtons ? 1 : 0 ) :
146 TUINT uiButtonFlag = ( 1 << iButton );
150 if ( dod[ i ].dwData & 0x80 )
152 TASSERT( ( m_dwButtonCurrent & uiButtonFlag ) == 0 );
154 if ( ( m_dwButtonCurrent & uiButtonFlag ) == 0 )
157 m_dwButtonCurrent |= uiButtonFlag;
160 else if ( ( m_dwButtonCurrent & uiButtonFlag ) != 0 )
163 m_dwButtonCurrent &= ~uiButtonFlag;
172 if ( m_iDeltaPositionX != 0 || m_iDeltaPositionY != 0 )
187 if ( m_iDeltaPositionZ != 0 )
189 TTODO(
"Throw scroll events" );
192 return iNumProcessed;
197 return m_DIDevCaps.dwButtons;
202 return m_DIDevCaps.dwAxes;
207 if ( ( 0x30000 < a_iDoodad ) && ( a_iDoodad < 0x30009 ) )
209 return ( m_dwButtonCurrent & ( 1 << ( ( a_iDoodad - 1 ) & 0x1F ) ) );
221 return m_iDeltaPositionX;
226 return m_iDeltaPositionY;
239 return TFLOAT( m_iDeltaPositionX );
244 return TFLOAT( m_iDeltaPositionY );
249 return TFLOAT( m_iDeltaPositionZ );
262 m_bReverseButtons =
TFALSE;
263 m_dwButtonCurrent = 0;
264 m_dwButtonPrevious = 0;
267 GetCursorPos( &cursorPos );
269 m_iPositionX = cursorPos.x;
270 m_iPositionY = cursorPos.y;
272 m_iDeltaPositionX = 0;
273 m_iDeltaPositionY = 0;
274 m_iDeltaPositionZ = 0;
283 DIPROPDWORD dwordProperty;
284 dwordProperty.diph.dwSize =
sizeof( dwordProperty );
285 dwordProperty.diph.dwHeaderSize =
sizeof( DIPROPHEADER );
286 dwordProperty.diph.dwObj = DIMOFS_Z;
287 dwordProperty.diph.dwHow = DIPH_BYOFFSET;
289 HRESULT hr = m_poDXInputDevice->GetProperty( DIPROP_GRANULARITY, &dwordProperty.diph );
291 if ( hr != DIERR_OBJECTNOTFOUND )
293 m_bInitiliased = ( hr != DI_OK ) - 1 & dwordProperty.diph.dwHeaderSize;
297 m_bInitiliased = FALSE;
311 m_dwButtonPrevious = m_dwButtonCurrent;
312 m_dwButtonCurrent = 0;
314 if ( SUCCEEDED( m_poDXInputDevice->Poll() ) )
316 DIMOUSESTATE mouseState;
317 HRESULT hRes = m_poDXInputDevice->GetDeviceState(
sizeof( DIMOUSESTATE ), &mouseState );
319 if ( SUCCEEDED( hRes ) )
321 if ( mouseState.rgbButtons[ 0 ] & 0x80 )
322 m_dwButtonCurrent |= m_bReverseButtons ? 2 : 1;
324 if ( mouseState.rgbButtons[ 1 ] & 0x80 )
325 m_dwButtonCurrent |= m_bReverseButtons ? 1 : 2;
327 if ( mouseState.rgbButtons[ 2 ] & 0x80 )
336 if ( ( 0x30000 < a_iDoodad ) && ( a_iDoodad < 0x30009 ) )
338 return ( m_dwButtonPrevious & ( ( a_iDoodad - 1 ) & 0x1F ) );
346 m_poDXInputDevice->SetCooperativeLevel(
348 a_bExclusive ? ( DISCL_EXCLUSIVE | DISCL_FOREGROUND ) : ( DISCL_NONEXCLUSIVE | DISCL_FOREGROUND )
362 TASSERT( a_poDeviceInstance != NULL );
363 TASSERT( a_poDXInputDevice != NULL );
366 TUtil::MemCopy( &m_oDeviceInstance, a_poDeviceInstance,
sizeof( DIDEVICEINSTANCEA ) );
368 m_poDXInputDevice = a_poDXInputDevice;
370 m_DIDevCaps = {
sizeof( DIDEVCAPS ) };
371 m_poDXInputDevice->GetCapabilities( &m_DIDevCaps );
373 HRESULT hRes = m_poDXInputDevice->SetDataFormat( &c_dfDIMouse );
380 m_poDXInputDevice->SetCooperativeLevel( a_hMainWindow, DISCL_FOREGROUND | ( a_bExclusive ? DISCL_EXCLUSIVE : DISCL_NONEXCLUSIVE ) );
384 dipdw.diph.dwSize =
sizeof( DIPROPDWORD );
385 dipdw.diph.dwHeaderSize =
sizeof( DIPROPHEADER );
386 dipdw.diph.dwObj = 0;
387 dipdw.diph.dwHow = DIPH_DEVICE;
388 dipdw.dwData = DIPROPAXISMODE_REL;
389 hRes = m_poDXInputDevice->SetProperty( DIPROP_AXISMODE, &dipdw.diph );
391 return hRes == DI_OK;
#define TOSHI_NAMESPACE_START
#define TOSHI_NAMESPACE_END
#define TDEFINE_CLASS(...)
TFORCEINLINE void Clip(T &rVal, const T &Min, const T &Max)
static constexpr TINT INPUT_DEVICE_MOUSE_BUTTONS
TINT ProcessRepeats(EventEmitter &a_rEmitter, TFLOAT a_fDeltaTime)
static constexpr TINT INPUT_DEVICE_MOUSE_WHEEL
void SetAcquired(TBOOL a_bAcquired)
TInputInterface::EventEmitter EventEmitter
virtual TBOOL Initialise()
virtual TBOOL WasDown(Doodad a_iDoodad) const
virtual TBOOL Unacquire() override
virtual TBOOL Acquire() override
virtual TINT GetButtonCount() const override
virtual TINT GetAxisInt(Doodad a_iDoodad, TINT axis) const override
virtual TINT ProcessEvents(EventEmitter &a_rEmitter, TFLOAT a_fDeltaTime) override
TBOOL const BindToDIDevice(HWND a_hMainWindow, LPCDIDEVICEINSTANCEA a_poDeviceInstance, IDirectInputDevice8A *a_poDXInputDevice, TBOOL a_bExclusive)
void SetExclusive(HWND a_hWindow, TBOOL a_bExclusive)
virtual void Update(TFLOAT a_fDeltaTime) override
virtual void Release() override
virtual TBOOL Deinitialise()
virtual void RefreshDirect()
virtual TBOOL IsEnabled() const override
void SetCurrentPosition(TINT a_iX, TINT a_iY)
virtual TBOOL IsDown(Doodad a_iDoodad) const override
virtual TFLOAT GetAxisFloat(Doodad a_iDoodad, TINT axis) const override
virtual TBOOL Flush() override
virtual TINT GetAxisCount() const override
virtual DISPLAYPARAMS * GetCurrentDisplayParams()=0
static TFORCEINLINE TRenderInterface * GetSingleton()
static void MemClear(void *ptr, TSIZE size)
static void * MemCopy(void *dst, const void *src, TSIZE size)