OpenBarnyard
 
Loading...
Searching...
No Matches
TInputInterface_Win.cpp
Go to the documentation of this file.
1#include "ToshiPCH.h"
7
8//-----------------------------------------------------------------------------
9// Enables memory debugging.
10// Note: Should be the last include!
11//-----------------------------------------------------------------------------
12#include "Core/TMemoryDebugOn.h"
13
15
17
19{
20 TASSERT( TNULL == m_poDirectInput8 );
21 HRESULT hRes = DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION, IID_IDirectInput8, (LPVOID*)&m_poDirectInput8, NULL );
22
23 if ( SUCCEEDED( hRes ) )
24 {
25 if ( m_hMainWindow == NULL )
26 {
27 m_hMainWindow = FindWindowA( "TRenderD3DInterface", NULL );
28 }
29
30 hRes = m_poDirectInput8->EnumDevices( DI8DEVCLASS_ALL, TInputDXInterface::EnumerateDeviceCallback, this, DIEDFL_ATTACHEDONLY );
31
32 if ( hRes == DI_OK )
33 {
34 return TTRUE;
35 }
36 else
37 {
39 }
40 }
41
42 return TFALSE;
43}
44
46{
48
49 if ( m_poDirectInput8 != NULL )
50 {
51 m_poDirectInput8->Release();
52 m_poDirectInput8 = NULL;
53 }
54
55 return TTRUE;
56}
57
59{
61 pMouse->Unacquire();
62 pMouse->SetExclusive( m_hMainWindow, a_bIsExclusive );
63 pMouse->Acquire();
64 TInputInterface::SetExclusiveMode( a_bIsExclusive );
65}
66
68{
69 auto input = GetDirectInput();
70
71 if ( input != NULL )
72 {
73 return input->EnumDevices( DI8DEVCLASS_ALL, EnumerateDeviceCallback, this, DIEDFL_ATTACHEDONLY ) != DI_OK;
74 }
75
76 return TFALSE;
77}
78
79BOOL TInputDXInterface::EnumerateDeviceCallback( LPCDIDEVICEINSTANCEA a_poDeviceInstance, LPVOID poDXInputInterface )
80{
81 TInputDXInterface* pInputInterface = TSTATICCAST( TInputDXInterface, poDXInputInterface );
82
83 TASSERT( poDXInputInterface != NULL );
84 TASSERT( a_poDeviceInstance != NULL );
85
86 auto pInput8 = pInputInterface->m_poDirectInput8;
87
88 switch ( GET_DIDEVICE_TYPE( a_poDeviceInstance->dwDevType ) )
89 {
90 case DI8DEVTYPE_KEYBOARD:
91 {
92 LPDIRECTINPUTDEVICE8A pInputDevice;
93 HRESULT hRes = pInputInterface->m_poDirectInput8->CreateDevice( a_poDeviceInstance->guidInstance, &pInputDevice, NULL );
94
95 if ( hRes == DI_OK )
96 {
98
99 if ( pKeyboard )
100 {
101 TBOOL bRes = pKeyboard->BindToDIDevice( pInputInterface->GetMainWindow(), a_poDeviceInstance, pInputDevice );
102
103 if ( bRes )
104 {
105 DIPROPDWORD oProperty;
106 oProperty.dwData = 0x20;
107 oProperty.diph.dwSize = sizeof( DIPROPDWORD );
108 oProperty.diph.dwHeaderSize = sizeof( DIPROPHEADER );
109 oProperty.diph.dwObj = 0;
110 oProperty.diph.dwHow = DIPH_DEVICE;
111
112 HRESULT hRes = pInputDevice->SetProperty( DIPROP_BUFFERSIZE, &oProperty.diph );
113
114 if ( FAILED( hRes ) )
115 return DIENUM_STOP;
116
117 hRes = pInputDevice->SetCooperativeLevel(
118 pInputInterface->GetMainWindow(),
119 pInputInterface->GetExclusiveMode() ? ( DISCL_NOWINKEY | DISCL_FOREGROUND | DISCL_EXCLUSIVE ) : ( DISCL_NONEXCLUSIVE | DISCL_BACKGROUND )
120 );
121
122 if ( hRes == DI_OK )
123 {
124 pKeyboard->Initialise();
125 pKeyboard->Acquire();
126 pInputInterface->AddDevice( pKeyboard );
127 }
128 else
129 {
130 delete pKeyboard;
131 return DIENUM_CONTINUE;
132 }
133 }
134 }
135 }
136 break;
137 }
138 case DI8DEVTYPE_MOUSE:
139 {
140 LPDIRECTINPUTDEVICE8A pInputDevice;
141 auto pMouse = pInputInterface->GetDeviceByIndex<TInputDXDeviceMouse>( 0 );
142 auto hRes = pInput8->CreateDevice( GUID_SysMouse, &pInputDevice, NULL );
143
144 TBOOL bIsNewMouse = TFALSE;
145
146 if ( hRes == DI_OK )
147 {
148 if ( pMouse == TNULL )
149 {
150 pMouse = new TInputDXDeviceMouse;
151 bIsNewMouse = TTRUE;
152
153 if ( pMouse == TNULL )
154 {
155 pInputDevice->Release();
156 return DIENUM_CONTINUE;
157 }
158 }
159 else if ( pMouse->GetDeviceInstance().dwDevType & DIDEVTYPE_HID )
160 {
161 pInputDevice->Release();
162 return DIENUM_CONTINUE;
163 }
164
165 if ( !pMouse->BindToDIDevice( pInputInterface->m_hMainWindow, a_poDeviceInstance, pInputDevice, pInputInterface->m_bExclusive ) )
166 {
167 if ( !bIsNewMouse )
168 {
169 pInputInterface->RemoveDevice( pMouse );
170 }
171
172 delete pMouse;
173 return DIENUM_CONTINUE;
174 }
175
176 DIPROPDWORD oProperty;
177 oProperty.diph.dwSize = sizeof( DIPROPDWORD );
178 oProperty.diph.dwHeaderSize = sizeof( DIPROPHEADER );
179 oProperty.diph.dwObj = 0;
180 oProperty.diph.dwHow = DIPH_DEVICE;
181 oProperty.dwData = 0x20;
182 hRes = pInputDevice->SetProperty( DIPROP_BUFFERSIZE, &oProperty.diph );
183
184 if ( FAILED( hRes ) )
185 {
186 return DIENUM_STOP;
187 }
188
189 if ( bIsNewMouse )
190 {
191 pMouse->Initialise();
192 pMouse->Acquire();
193 pInputInterface->AddDevice( pMouse );
194 return DIENUM_CONTINUE;
195 }
196 }
197
198 break;
199 /*inputMouse = pInputInterface->GetDeviceByIndex<TInputDXDeviceMouse>();
200
201 HRESULT hRes = pInputInterface->m_poDirectInput8->CreateDevice(GUID_SysMouse, &inputDevice, NULL);
202
203 if (hRes != DI_OK)
204 return DIENUM_CONTINUE;
205
206 if (inputMouse == TNULL)
207 {
208 inputMouse = new TInputDXDeviceMouse();
209 addMouse = TTRUE;
210 TBOOL bRes = inputMouse->BindToDIDevice(pInputInterface->GetMainWindow(), a_poDeviceInstance, inputDevice, pInputInterface->m_bExclusive);
211
212 if (bRes)
213 {
214 DIPROPDWORD oProperty;
215 oProperty.diph.dwSize = sizeof(DIPROPDWORD);
216 oProperty.diph.dwHeaderSize = sizeof(DIPROPHEADER);
217 oProperty.diph.dwObj = 0;
218 oProperty.diph.dwHow = DIPH_DEVICE;
219 oProperty.dwData = TInputDXDeviceMouse::sm_ciMouseBufferSize;
220
221 HRESULT hr = inputDevice->SetProperty(DIPROP_BUFFERSIZE, &oProperty.diph);
222
223 if (FAILED(hr))
224 return DIENUM_STOP;
225
226 if (addMouse)
227 {
228 inputMouse->Initialise();
229 inputMouse->Acquire();
230 pInputInterface->AddDevice(inputMouse);
231 }
232 }
233 if (!addMouse)
234 {
235 pInputInterface->RemoveDevice(inputMouse);
236 }
237 }
238 TIMPLEMENT();
239 break;*/
240 }
241 //case DI8DEVTYPE_JOYSTICK:
242 //case DI8DEVTYPE_GAMEPAD:
243 //case DI8DEVTYPE_1STPERSON:
244 //{
245 // TIMPLEMENT();
246
247 // TCHAR fmtStr[37];
248 // Toshi::T2String8::Format(fmtStr, "%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX",
249 // a_poDeviceInstance->guidProduct.Data1, a_poDeviceInstance->guidProduct.Data2,
250 // a_poDeviceInstance->guidProduct.Data3, a_poDeviceInstance->guidProduct.Data4[0],
251 // a_poDeviceInstance->guidProduct.Data4[1], a_poDeviceInstance->guidProduct.Data4[2],
252 // a_poDeviceInstance->guidProduct.Data4[3], a_poDeviceInstance->guidProduct.Data4[4],
253 // a_poDeviceInstance->guidProduct.Data4[5], a_poDeviceInstance->guidProduct.Data4[6],
254 // a_poDeviceInstance->guidProduct.Data4[7]);
255
256 // if (!TInputDXDeviceController::IsDirectInputController(a_poDeviceInstance))
257 // {
258 // TUtil::Log("Added XInput Controller: \'%s\' (%s) - NON-PSX", a_poDeviceInstance->tszProductName, fmtStr);
259 // return DIENUM_CONTINUE;
260 // }
261
262 // TUtil::Log("Added Direct Input Controller: \'%s\' (%s) - NON-PSX", a_poDeviceInstance->tszProductName, fmtStr);
263
264 // inputController = pInputInterface->GetDeviceByIndex<TInputDXDeviceController>();
265 // HRESULT hRes = pInputInterface->m_poDirectInput8->CreateDevice(a_poDeviceInstance->guidInstance, &inputDevice, NULL);
266
267 // if (hRes != DI_OK)
268 // return DIENUM_CONTINUE;
269
270 // if (inputController == TNULL)
271 // {
272 // // new DXController
273 // //inputController = new TInputDXDeviceController();
274 // //inputController->BindToDIDevice(pInputInterface->GetMainWindow(), a_poDeviceInstance, inputDevice);
275 // }
276
277 // break;
278 //}
279 default:
280 break;
281 }
282
283 return DIENUM_CONTINUE;
284}
285
#define DIRECTINPUT_VERSION
Definition Includes.h:1
#define TASSERT(X,...)
Definition Defines.h:138
#define TSTATICCAST(POINTERTYPE, VALUE)
Definition Defines.h:69
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
#define TDEFINE_CLASS(...)
Definition TObject.h:120
#define TNULL
Definition Typedefs.h:23
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
TInputDevice * GetDeviceByIndex(TClass *a_pClass, TUINT a_uiIndex)
virtual TBOOL GetExclusiveMode() const
virtual void SetExclusiveMode(TBOOL a_bIsExclusive)
void RemoveDevice(TInputDevice *device)
void AddDevice(TInputDevice *device)
virtual TBOOL Acquire() override
const TBOOL BindToDIDevice(HWND a_hMainWindow, LPCDIDEVICEINSTANCEA a_poDeviceInstance, IDirectInputDevice8A *a_poDXInputDevice)
virtual TBOOL Deinitialise() override
virtual void SetExclusiveMode(TBOOL a_bIsExclusive) override
virtual TBOOL Initialise() override