OpenBarnyard
 
Loading...
Searching...
No Matches
TInputDXDeviceMouse Class Reference

#include <TInputDeviceMouse_Win.h>

Inheritance diagram for TInputDXDeviceMouse:
TInputDeviceMouse TInputDevice TObject TNodeList< T >::TNode

Public Member Functions

 TDECLARE_CLASS (TInputDXDeviceMouse, TInputDeviceMouse)
 
 TInputDXDeviceMouse ()
 
virtual ~TInputDXDeviceMouse ()
 
virtual TBOOL Acquire () override
 
virtual TBOOL Unacquire () override
 
virtual void Release () override
 
virtual void Update (TFLOAT a_fDeltaTime) override
 
virtual TBOOL Flush () override
 
virtual TINT ProcessEvents (EventEmitter &a_rEmitter, TFLOAT a_fDeltaTime) override
 
virtual TINT GetButtonCount () const override
 
virtual TINT GetAxisCount () const override
 
virtual TBOOL IsDown (Doodad a_iDoodad) const override
 
virtual TINT GetAxisInt (Doodad a_iDoodad, TINT axis) const override
 
virtual TFLOAT GetAxisFloat (Doodad a_iDoodad, TINT axis) const override
 
virtual TBOOL IsEnabled () const override
 
virtual TBOOL Initialise ()
 
virtual TBOOL Deinitialise ()
 
virtual void RefreshDirect ()
 
virtual TBOOL WasDown (Doodad a_iDoodad) const
 
TBOOL const BindToDIDevice (HWND a_hMainWindow, LPCDIDEVICEINSTANCEA a_poDeviceInstance, IDirectInputDevice8A *a_poDXInputDevice, TBOOL a_bExclusive)
 
void SetExclusive (HWND a_hWindow, TBOOL a_bExclusive)
 
void SetCurrentPosition (TINT a_iX, TINT a_iY)
 
const DIDEVICEINSTANCEA & GetDeviceInstance () const
 
- Public Member Functions inherited from TInputDeviceMouse
 TDECLARE_CLASS (TInputDeviceMouse, TInputDevice)
 
 TInputDeviceMouse ()
 
 ~TInputDeviceMouse ()
 
virtual TBOOL GetDoodadProperties (Doodad a_iDoodad, TInputDevice::DoodadProperties &props) const override
 
virtual const TCHARGetButtonFromDoodad (Doodad a_iDoodad) const override
 
- Public Member Functions inherited from TInputDevice
 TDECLARE_CLASS (TInputDevice, TObject)
 
 TInputDevice ()
 
 ~TInputDevice ()=default
 
virtual TBOOL StartRepeat (Doodad a_iDoodad, TFLOAT a_fFirstRepeatTime, TFLOAT a_fRepeatTime)
 
virtual void StopRepeat (Doodad a_iDoodad)
 
virtual void StopAllRepeats ()
 
virtual TBOOL IsForceFeedbackDevice ()
 
virtual TINT GetAxisInt2 (Doodad a_iDoodad, TINT axis) const
 
virtual TFLOAT GetAxisFloat2 (Doodad a_iDoodad, TINT axis) const
 
virtual void ThrowRepeatEvent (EventEmitter &emitter, RepeatInfo *repeatInfo, TFLOAT deltaTime)
 
TBOOL IsAcquired () const
 
void SetAcquired (TBOOL a_bAcquired)
 
TInputInterfaceGetInputInterface ()
 
void SetInputInterface (TInputInterface *a_pInterface)
 
- Public Member Functions inherited from TObject
virtual Toshi::TClass * GetClass ()
 
virtual void Delete ()
 
virtual ~TObject ()
 
TBOOL IsExactly (TClass *a_pClass)
 
TBOOL IsA (TClass *a_pClass)
 
- Public Member Functions inherited from TNodeList< T >::TNode
constexpr TNode ()
 
constexpr TNode (const TNode &a_rcNode)
 
 TNode (TNode &&a_rNode)
 
T * Next () const
 
T * Prev () const
 
void Remove ()
 
void SetList (TNodeList *list)
 
TNodeListGetList () const
 
TBOOL IsLinked () const
 

Additional Inherited Members

- Public Types inherited from TInputDeviceMouse
enum  : Doodad {
  BUTTON_1 = 0x30001 , BUTTON_2 = 0x30002 , BUTTON_3 = 0x30003 , BUTTON_4 = 0x30004 ,
  BUTTON_5 = 0x30005 , BUTTON_6 = 0x30006 , BUTTON_7 = 0x30007 , BUTTON_8 = 0x30008 ,
  BUTTON_WHEEL_FORWARD = 0x30009 , BUTTON_WHEEL_BACKWARD = 0x3000A , AXIS_CURSOR = 0x3000B , AXIS_WHEEL = 0x3000C
}
 
- Public Types inherited from TInputDevice
using EventEmitter = TInputInterface::EventEmitter
 
using Doodad = TINT
 
- Public Types inherited from TObject
enum  { IsTObject = TTRUE }
 
- Static Public Member Functions inherited from TInputDevice
static TInputDevice ** GetRegisteredDevices ()
 
static TUINT GetNumRegisteredDevices ()
 
- Static Public Member Functions inherited from TObject
static Toshi::TObject * CreateTObject ()
 
static Toshi::TObject * CreateTObjectInPlace (void *a_pPtr)
 
static void InitialiseClass ()
 
static void DeinitialiseClass ()
 
static TFORCEINLINE TClassGetClassStatic ()
 
- Static Public Attributes inherited from TInputDevice
static constexpr TINT INPUT_DEVICE_MOUSE_BUTTONS = 3
 
static constexpr TINT INPUT_DEVICE_MOUSE_WHEEL = 4
 
- Static Public Attributes inherited from TObject
static constexpr Toshi::TClass * PARENTCLASS = TNULL
 
static constinit Toshi::TClass ms_oClass = Toshi::TClass( "TObject", TObject::CreateTObject, TObject::CreateTObjectInPlace, TObject::InitialiseClass, TObject::DeinitialiseClass, 0, 2, sizeof( TObject ), alignof( TObject ) )
 
- Protected Member Functions inherited from TInputDevice
TINT ProcessRepeats (EventEmitter &a_rEmitter, TFLOAT a_fDeltaTime)
 
- Protected Attributes inherited from TInputDevice
TUINT m_uiDeviceIndex
 
TArray< RepeatInfom_Repeats
 
TArray< void * > m_Array2
 
TBOOL m_bUnknown
 
TBOOL m_bIsAcquired
 
TInputInterfacem_pInputInterface
 
- Protected Attributes inherited from TNodeList< T >::TNode
friend TNodeList
 
TNodeListm_pList
 
T * m_pNext
 
T * m_pPrev
 
- Static Protected Attributes inherited from TInputDevice
static constexpr TUINT MAX_DEVICE_COUNT = 14
 
static TInputDevices_aDevices [MAX_DEVICE_COUNT]
 
static TUINT s_uiDeviceCount
 

Detailed Description

Definition at line 7 of file TInputDeviceMouse_Win.h.

Constructor & Destructor Documentation

◆ TInputDXDeviceMouse()

TInputDXDeviceMouse::TInputDXDeviceMouse ( )
inline

Definition at line 13 of file TInputDeviceMouse_Win.h.

14 {
15 m_poDXInputDevice = NULL;
16 }

◆ ~TInputDXDeviceMouse()

virtual TInputDXDeviceMouse::~TInputDXDeviceMouse ( )
inlinevirtual

Definition at line 18 of file TInputDeviceMouse_Win.h.

19 {
21 }

Member Function Documentation

◆ Acquire()

TBOOL TInputDXDeviceMouse::Acquire ( )
overridevirtual

Implements TInputDevice.

Definition at line 16 of file TInputDeviceMouse_Win.cpp.

17{
18 HRESULT hr = m_poDXInputDevice->Acquire();
19
20 if ( FAILED( hr ) )
21 {
23 return TFALSE;
24 }
25
27
28 if ( hr != S_FALSE )
29 {
31 }
32
33 return TTRUE;
34}
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
void SetAcquired(TBOOL a_bAcquired)

◆ BindToDIDevice()

TBOOL const TInputDXDeviceMouse::BindToDIDevice ( HWND a_hMainWindow,
LPCDIDEVICEINSTANCEA a_poDeviceInstance,
IDirectInputDevice8A * a_poDXInputDevice,
TBOOL a_bExclusive )

Definition at line 360 of file TInputDeviceMouse_Win.cpp.

361{
362 TASSERT( a_poDeviceInstance != NULL );
363 TASSERT( a_poDXInputDevice != NULL );
364
365 Release();
366 TUtil::MemCopy( &m_oDeviceInstance, a_poDeviceInstance, sizeof( DIDEVICEINSTANCEA ) );
367
368 m_poDXInputDevice = a_poDXInputDevice;
369
370 m_DIDevCaps = { sizeof( DIDEVCAPS ) };
371 m_poDXInputDevice->GetCapabilities( &m_DIDevCaps );
372
373 HRESULT hRes = m_poDXInputDevice->SetDataFormat( &c_dfDIMouse );
374
375 if ( hRes != DI_OK )
376 return TFALSE;
377
378 if ( a_hMainWindow )
379 {
380 m_poDXInputDevice->SetCooperativeLevel( a_hMainWindow, DISCL_FOREGROUND | ( a_bExclusive ? DISCL_EXCLUSIVE : DISCL_NONEXCLUSIVE ) );
381 }
382
383 DIPROPDWORD dipdw{};
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 );
390
391 return hRes == DI_OK;
392}
#define TASSERT(X,...)
Definition Defines.h:138
virtual void Release() override
static void * MemCopy(void *dst, const void *src, TSIZE size)
Definition TUtil.h:90

◆ Deinitialise()

TBOOL TInputDXDeviceMouse::Deinitialise ( )
virtual

Definition at line 301 of file TInputDeviceMouse_Win.cpp.

302{
303 Release();
304 return TTRUE;
305}

◆ Flush()

TBOOL TInputDXDeviceMouse::Flush ( )
overridevirtual

Reimplemented from TInputDevice.

Definition at line 91 of file TInputDeviceMouse_Win.cpp.

92{
93 DWORD dwItems = INFINITE;
94
95 if ( IsAcquired() )
96 {
97 HRESULT hr = m_poDXInputDevice->GetDeviceData( sizeof( DIDEVICEOBJECTDATA ), NULL, &dwItems, 0 );
98
99 if ( SUCCEEDED( hr ) )
100 {
102 return TTRUE;
103 }
104 }
105
106 return TFALSE;
107}
TBOOL IsAcquired() const

◆ GetAxisCount()

TINT TInputDXDeviceMouse::GetAxisCount ( ) const
overridevirtual

Implements TInputDevice.

Definition at line 200 of file TInputDeviceMouse_Win.cpp.

201{
202 return m_DIDevCaps.dwAxes;
203}

◆ GetAxisFloat()

TFLOAT TInputDXDeviceMouse::GetAxisFloat ( Doodad a_iDoodad,
TINT axis ) const
overridevirtual

Implements TInputDevice.

Definition at line 233 of file TInputDeviceMouse_Win.cpp.

234{
235 if ( a_iDoodad == AXIS_CURSOR )
236 {
237 if ( coord == 0 )
238 {
239 return TFLOAT( m_iDeltaPositionX );
240 }
241
242 if ( coord == 1 )
243 {
244 return TFLOAT( m_iDeltaPositionY );
245 }
246 }
247 else if ( a_iDoodad == AXIS_WHEEL )
248 {
249 return TFLOAT( m_iDeltaPositionZ );
250 }
251
252 return 0.0f;
253}
float TFLOAT
Definition Typedefs.h:4

◆ GetAxisInt()

TINT TInputDXDeviceMouse::GetAxisInt ( Doodad a_iDoodad,
TINT axis ) const
overridevirtual

Implements TInputDevice.

Definition at line 215 of file TInputDeviceMouse_Win.cpp.

216{
217 if ( a_iDoodad == AXIS_CURSOR )
218 {
219 if ( coord == 0 )
220 {
221 return m_iDeltaPositionX;
222 }
223
224 if ( coord == 1 )
225 {
226 return m_iDeltaPositionY;
227 }
228 }
229
230 return 0;
231}

◆ GetButtonCount()

TINT TInputDXDeviceMouse::GetButtonCount ( ) const
overridevirtual

Implements TInputDevice.

Definition at line 195 of file TInputDeviceMouse_Win.cpp.

196{
197 return m_DIDevCaps.dwButtons;
198}

◆ GetDeviceInstance()

const DIDEVICEINSTANCEA & TInputDXDeviceMouse::GetDeviceInstance ( ) const
inline

Definition at line 46 of file TInputDeviceMouse_Win.h.

47 {
48 return m_oDeviceInstance;
49 }

◆ Initialise()

TBOOL TInputDXDeviceMouse::Initialise ( )
virtual

Definition at line 260 of file TInputDeviceMouse_Win.cpp.

261{
262 m_bReverseButtons = TFALSE;
263 m_dwButtonCurrent = 0;
264 m_dwButtonPrevious = 0;
265
266 POINT cursorPos;
267 GetCursorPos( &cursorPos );
268
269 m_iPositionX = cursorPos.x;
270 m_iPositionY = cursorPos.y;
271 m_iPositionZ = 0;
272 m_iDeltaPositionX = 0;
273 m_iDeltaPositionY = 0;
274 m_iDeltaPositionZ = 0;
275 m_iUnk1 = 0;
276 m_iUnk2 = 0;
277 m_iUnk3 = 0;
278 m_iUnk4 = 0;
279 m_iUnk5 = 0;
280 m_iUnk6 = -1;
281 m_iUnk7 = -1;
282
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;
288
289 HRESULT hr = m_poDXInputDevice->GetProperty( DIPROP_GRANULARITY, &dwordProperty.diph );
290
291 if ( hr != DIERR_OBJECTNOTFOUND )
292 {
293 m_bInitiliased = ( hr != DI_OK ) - 1 & dwordProperty.diph.dwHeaderSize;
294 return TTRUE;
295 }
296
297 m_bInitiliased = FALSE;
298 return TTRUE;
299}

◆ IsDown()

TBOOL TInputDXDeviceMouse::IsDown ( Doodad a_iDoodad) const
overridevirtual

Implements TInputDevice.

Definition at line 205 of file TInputDeviceMouse_Win.cpp.

206{
207 if ( ( 0x30000 < a_iDoodad ) && ( a_iDoodad < 0x30009 ) )
208 {
209 return ( m_dwButtonCurrent & ( 1 << ( ( a_iDoodad - 1 ) & 0x1F ) ) );
210 }
211
212 return TFALSE;
213}

◆ IsEnabled()

TBOOL TInputDXDeviceMouse::IsEnabled ( ) const
overridevirtual

Implements TInputDevice.

Definition at line 255 of file TInputDeviceMouse_Win.cpp.

256{
257 return TTRUE;
258}

◆ ProcessEvents()

TINT TInputDXDeviceMouse::ProcessEvents ( EventEmitter & a_rEmitter,
TFLOAT a_fDeltaTime )
overridevirtual

Implements TInputDevice.

Definition at line 109 of file TInputDeviceMouse_Win.cpp.

110{
111 m_dwButtonPrevious = m_dwButtonCurrent;
112 TINT iNumProcessed = ProcessRepeats( a_rEmitter, a_fDeltaTime );
113
114 DWORD dwItems = 32;
115 DIDEVICEOBJECTDATA dod[ 32 ];
116 TUtil::MemClear( dod, sizeof( dod ) );
117
118 HRESULT hRes = m_poDXInputDevice->GetDeviceData( sizeof( DIDEVICEOBJECTDATA ), dod, &dwItems, 0 );
119
120 if ( FAILED( hRes ) && hRes == ( DIERR_NOTACQUIRED | DIERR_INPUTLOST ) )
121 {
122 Unacquire();
123 Acquire();
124
125 hRes = m_poDXInputDevice->GetDeviceData( sizeof( DIDEVICEOBJECTDATA ), dod, &dwItems, 0 );
126
127 if ( hRes != DI_OK )
128 {
129 return 0;
130 }
131 }
132
133 for ( DWORD i = 0; i < dwItems; i++ )
134 {
135 switch ( dod[ i ].dwOfs )
136 {
137 case DIMOFS_BUTTON0:
138 case DIMOFS_BUTTON1:
139 case DIMOFS_BUTTON2:
140 {
141 TINT iButton =
142 ( dod[ i ].dwOfs == DIMOFS_BUTTON0 ) ? ( !m_bReverseButtons ? 0 : 1 ) :
143 ( dod[ i ].dwOfs == DIMOFS_BUTTON1 ) ? ( !m_bReverseButtons ? 1 : 0 ) :
144 2;
145
146 TUINT uiButtonFlag = ( 1 << iButton );
147
149
150 if ( dod[ i ].dwData & 0x80 )
151 {
152 TASSERT( ( m_dwButtonCurrent & uiButtonFlag ) == 0 );
153
154 if ( ( m_dwButtonCurrent & uiButtonFlag ) == 0 )
155 {
156 a_rEmitter.Throw( TInputInterface::InputEvent( this, BUTTON_1 + iButton, TInputInterface::EVENT_TYPE_GONE_DOWN ) );
157 m_dwButtonCurrent |= uiButtonFlag;
158 }
159 }
160 else if ( ( m_dwButtonCurrent & uiButtonFlag ) != 0 )
161 {
162 a_rEmitter.Throw( TInputInterface::InputEvent( this, BUTTON_1 + iButton, TInputInterface::EVENT_TYPE_GONE_UP ) );
163 m_dwButtonCurrent &= ~uiButtonFlag;
164 }
165
166 iNumProcessed += 1;
167 break;
168 }
169 }
170 }
171
172 if ( m_iDeltaPositionX != 0 || m_iDeltaPositionY != 0 )
173 {
174 a_rEmitter.Throw(
175 TInputInterface::InputEvent(
176 this,
177 0x3000b,
179 m_iDeltaPositionX,
180 m_iDeltaPositionY
181 )
182 );
183
184 iNumProcessed += 1;
185 }
186
187 if ( m_iDeltaPositionZ != 0 )
188 {
189 TTODO( "Throw scroll events" );
190 }
191
192 return iNumProcessed;
193}
#define TTODO(DESC)
Definition Defines.h:134
unsigned int TUINT
Definition Typedefs.h:8
int TINT
Definition Typedefs.h:7
static constexpr TINT INPUT_DEVICE_MOUSE_BUTTONS
TINT ProcessRepeats(EventEmitter &a_rEmitter, TFLOAT a_fDeltaTime)
virtual TBOOL Unacquire() override
virtual TBOOL Acquire() override
static void MemClear(void *ptr, TSIZE size)
Definition TUtil.h:91

◆ RefreshDirect()

void TInputDXDeviceMouse::RefreshDirect ( )
virtual

Definition at line 307 of file TInputDeviceMouse_Win.cpp.

308{
309 if ( IsAcquired() )
310 {
311 m_dwButtonPrevious = m_dwButtonCurrent;
312 m_dwButtonCurrent = 0;
313
314 if ( SUCCEEDED( m_poDXInputDevice->Poll() ) )
315 {
316 DIMOUSESTATE mouseState;
317 HRESULT hRes = m_poDXInputDevice->GetDeviceState( sizeof( DIMOUSESTATE ), &mouseState );
318
319 if ( SUCCEEDED( hRes ) )
320 {
321 if ( mouseState.rgbButtons[ 0 ] & 0x80 ) // LeftClick
322 m_dwButtonCurrent |= m_bReverseButtons ? 2 : 1;
323
324 if ( mouseState.rgbButtons[ 1 ] & 0x80 ) // RightClick
325 m_dwButtonCurrent |= m_bReverseButtons ? 1 : 2;
326
327 if ( mouseState.rgbButtons[ 2 ] & 0x80 ) // Wheeling yeeet
328 m_dwButtonCurrent |= INPUT_DEVICE_MOUSE_WHEEL;
329 }
330 }
331 }
332}
static constexpr TINT INPUT_DEVICE_MOUSE_WHEEL

◆ Release()

void TInputDXDeviceMouse::Release ( )
overridevirtual

Implements TInputDevice.

Definition at line 43 of file TInputDeviceMouse_Win.cpp.

44{
45 if ( m_poDXInputDevice )
46 {
47 m_poDXInputDevice->Release();
48 m_poDXInputDevice = NULL;
49 }
50}

◆ SetCurrentPosition()

void TInputDXDeviceMouse::SetCurrentPosition ( TINT a_iX,
TINT a_iY )

Definition at line 352 of file TInputDeviceMouse_Win.cpp.

353{
355
356 TMath::Clip( m_iPositionX, 0, TINT( pDisplayParams->uiWidth ) );
357 TMath::Clip( m_iPositionY, 0, TINT( pDisplayParams->uiHeight ) );
358}
TFORCEINLINE void Clip(T &rVal, const T &Min, const T &Max)
virtual DISPLAYPARAMS * GetCurrentDisplayParams()=0
static TFORCEINLINE TRenderInterface * GetSingleton()
Definition TSingleton.h:49

◆ SetExclusive()

void TInputDXDeviceMouse::SetExclusive ( HWND a_hWindow,
TBOOL a_bExclusive )

Definition at line 344 of file TInputDeviceMouse_Win.cpp.

345{
346 m_poDXInputDevice->SetCooperativeLevel(
347 a_hWindow,
348 a_bExclusive ? ( DISCL_EXCLUSIVE | DISCL_FOREGROUND ) : ( DISCL_NONEXCLUSIVE | DISCL_FOREGROUND )
349 );
350}

◆ TDECLARE_CLASS()

TInputDXDeviceMouse::TDECLARE_CLASS ( TInputDXDeviceMouse ,
TInputDeviceMouse  )

◆ Unacquire()

TBOOL TInputDXDeviceMouse::Unacquire ( )
overridevirtual

Implements TInputDevice.

Definition at line 36 of file TInputDeviceMouse_Win.cpp.

37{
39 HRESULT hr = m_poDXInputDevice->Unacquire();
40 return SUCCEEDED( hr );
41}

◆ Update()

void TInputDXDeviceMouse::Update ( TFLOAT a_fDeltaTime)
overridevirtual

Implements TInputDevice.

Definition at line 52 of file TInputDeviceMouse_Win.cpp.

53{
54 if ( IsAcquired() )
55 {
56 m_iDeltaPositionX = 0;
57 m_iDeltaPositionY = 0;
58 m_iDeltaPositionZ = 0;
59
60 HRESULT hRes = m_poDXInputDevice->Poll();
61
62 if ( SUCCEEDED( hRes ) )
63 {
64 DIMOUSESTATE state;
65 hRes = m_poDXInputDevice->GetDeviceState( sizeof( state ), &state );
66
67 if ( SUCCEEDED( hRes ) )
68 {
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;
75
77 {
79
80 if ( !pDisplayParams->bWindowed )
81 {
82 TMath::Clip( m_iPositionX, 0, TINT( pDisplayParams->uiWidth ) );
83 TMath::Clip( m_iPositionY, 0, TINT( pDisplayParams->uiHeight ) );
84 }
85 }
86 }
87 }
88 }
89}

◆ WasDown()

TBOOL TInputDXDeviceMouse::WasDown ( Doodad a_iDoodad) const
virtual

Definition at line 334 of file TInputDeviceMouse_Win.cpp.

335{
336 if ( ( 0x30000 < a_iDoodad ) && ( a_iDoodad < 0x30009 ) )
337 {
338 return ( m_dwButtonPrevious & ( ( a_iDoodad - 1 ) & 0x1F ) );
339 }
340
341 return TFALSE;
342}

The documentation for this class was generated from the following files: