00001 #include "../ZakiLib.hpp"
00002
00003
00004
00005
00006 CDirectInput::CDirectInput()
00007 {
00008 this->m_lpDInputDevice = NULL;
00009 this->m_dwBufferSize = 0;
00010 ZeroMemory(&this->m_DiInst,sizeof(this->m_DiInst));
00011 }
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 HRESULT CDirectInput::InitDevice(DIDEVICEINSTANCE DiDevInst,DWORD dwBufferSize,HWND hWindow,DWORD dwLevel)
00026 {
00027 HRESULT hr;
00028
00029 if(this->g_lpDInput == NULL)
00030 return E_FAIL;
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 this->m_DiInst = DiDevInst;
00046
00047
00048
00049
00050 if(this->CheckDeviceGuid(DiDevInst.guidInstance))
00051 return E_FAIL;
00052
00053
00054
00055
00056 this->SetGuid(DiDevInst.guidInstance);
00057
00058
00059
00060
00061 hr = g_lpDInput->CreateDevice(this->m_DiInst.guidInstance,&this->m_lpDInputDevice,NULL);
00062 if(FAILED(hr))
00063 return DXTRACE_ERR_MSGBOX("Input¥nInitDevice¥nCreateDevice",hr);
00064
00065
00066
00067
00068 hr = this->DeviceCondition(&DiDevInst);
00069 if(FAILED(hr))
00070 {
00071 this->Release();
00072 return DXTRACE_ERR_MSGBOX("Input¥nInitDevice¥nDeviceCondition",hr);
00073 }
00074
00075
00076
00077
00078 hr = this->m_lpDInputDevice->EnumObjects(EnumAxesCallback,(LPVOID)this,DIDFT_ALL);
00079 if(FAILED(hr))
00080 {
00081 this->Release();
00082 return DXTRACE_ERR_MSGBOX("Input¥nInitDevice¥nEumObjects",hr);
00083 }
00084
00085
00086
00087
00088 hr = this->m_lpDInputDevice->SetCooperativeLevel(hWindow,dwLevel);
00089 if(FAILED(hr))
00090 {
00091 this->Release();
00092 return DXTRACE_ERR_MSGBOX("Input¥nInitDevice¥nSetCooperativeLevel",hr);
00093 }
00094
00095
00096
00097
00098 switch(GET_DIDEVICE_TYPE(this->m_DiInst.dwDevType)) {
00099 case DI8DEVTYPE_MOUSE:
00100 hr = this->m_lpDInputDevice->SetDataFormat(&c_dfDIMouse2);
00101 break;
00102 case DI8DEVTYPE_KEYBOARD:
00103 hr = this->m_lpDInputDevice->SetDataFormat(&c_dfDIKeyboard);
00104 break;
00105
00106
00107 default:
00108 hr = this->m_lpDInputDevice->SetDataFormat(&c_dfDIJoystick2);
00109 break;
00110 }
00111
00112 this->m_dwBufferSize = dwBufferSize;
00113
00114
00115
00116 if(dwBufferSize)
00117 {
00118 DIPROPDWORD diprop;
00119 diprop.diph.dwSize = sizeof(diprop);
00120 diprop.diph.dwHeaderSize = sizeof(diprop.diph);
00121 diprop.diph.dwObj = 0;
00122 diprop.diph.dwHow = DIPH_DEVICE;
00123 diprop.dwData = dwBufferSize;
00124
00125
00126
00127
00128 hr = this->m_lpDInputDevice->SetProperty(DIPROP_BUFFERSIZE,&diprop.diph);
00129 if(FAILED(hr))
00130 {
00131 MessageBox(hWindow,"バッファサイズの設定に失敗","error",MB_OK);
00132 this->Release();
00133 return DXTRACE_ERR_MSGBOX("Input¥nInitDevice¥nSetProp¥nSetBufferSize",hr);
00134 }
00135 }
00136
00137 return D3D_OK;
00138 }
00139
00140
00141
00142
00143
00144
00145
00146
00147 VOID CDirectInput::Release()
00148 {
00149 this->RemoveGuid(this->m_DiInst.guidInstance);
00150 this->AcquireDevice(FALSE);
00151 SAFE_RELEASE(this->m_lpDInputDevice);
00152
00153 delete this;
00154 }
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 HRESULT CDirectInput::DeviceCondition(const DIDEVICEINSTANCE *lpDdInst)
00213 {
00214 HRESULT hr;
00215 DIDEVCAPS DiDevCaps;
00216
00217
00218 DiDevCaps.dwSize = sizeof(DiDevCaps);
00219 hr = this->m_lpDInputDevice->GetCapabilities(&DiDevCaps);
00220 if(FAILED(hr))
00221 return DXTRACE_ERR_MSGBOX("Input:DeviceCondition:DevCaps",hr);
00222
00223 return D3D_OK;
00224 }
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234 HRESULT CDirectInput::DeviceAxes(LPCDIDEVICEOBJECTINSTANCE lpDdoInst)
00235 {
00236 HRESULT hr;
00237 DIPROPRANGE diprp;
00238 DIPROPDWORD diprop;
00239
00240 ZeroMemory(&diprp,sizeof(diprp));
00241 ZeroMemory(&diprop,sizeof(diprop));
00242 if(GET_DIDEVICE_TYPE(this->m_DiInst.dwDevType) == DI8DEVTYPE_MOUSE)
00243 {
00244
00245
00246 diprop.diph.dwSize = sizeof(diprop);
00247 diprop.diph.dwHeaderSize = sizeof(diprop.diph);
00248 diprop.diph.dwObj = 0;
00249 diprop.diph.dwHow = DIPH_DEVICE;
00250
00251 diprop.dwData = DIPROPAXISMODE_REL;
00252 hr = this->m_lpDInputDevice->SetProperty(DIPROP_AXISMODE,&diprop.diph);
00253 if(FAILED(hr))
00254 return DXTRACE_ERR_MSGBOX("DeviceAxes¥nSetPrperty",hr);
00255 }
00256 else
00257 {
00258 if(
00259 lpDdoInst->guidType == GUID_XAxis ||
00260 lpDdoInst->guidType == GUID_YAxis ||
00261 lpDdoInst->guidType == GUID_ZAxis ||
00262 lpDdoInst->guidType == GUID_RxAxis ||
00263 lpDdoInst->guidType == GUID_RyAxis ||
00264 lpDdoInst->guidType == GUID_RzAxis
00265 )
00266 {
00267
00268
00269 diprp.diph.dwSize = sizeof(diprp);
00270 diprp.diph.dwHeaderSize = sizeof(diprp.diph);
00271 diprp.diph.dwObj = lpDdoInst->dwType;
00272 diprp.diph.dwHow = DIPH_BYID;
00273 diprp.lMin = -1000;
00274 diprp.lMax = 1000;
00275 hr = this->m_lpDInputDevice->SetProperty(DIPROP_RANGE,&diprp.diph);
00276 if(FAILED(hr))
00277 return DXTRACE_ERR_MSGBOX("DeviceAxes¥nSetPrperty",hr);
00278 }
00279 }
00280 return D3D_OK;
00281 }
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291 HRESULT CDirectInput::GetState(DIDEVICEOBJECTDATA *DiDevData,DWORD *dwItemNum)
00292 {
00293 HRESULT hr;
00294
00295
00296
00297 hr = this->m_lpDInputDevice->Poll();
00298 if (FAILED(hr))
00299 {
00300 hr = this->AcquireDevice(TRUE);
00301 while (hr == DIERR_INPUTLOST)
00302 hr = this->AcquireDevice(TRUE);
00303 }
00304
00305
00306
00307
00308 hr = this->m_lpDInputDevice->GetDeviceData(sizeof(DIDEVICEOBJECTDATA)*(*dwItemNum),DiDevData,dwItemNum,0);
00309 if(hr == DIERR_INPUTLOST)
00310 {
00311 while (hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED)
00312 hr = this->AcquireDevice(TRUE);
00313 }
00314 else if(FAILED(hr))
00315 {
00316 return DXTRACE_ERR_MSGBOX("Input¥nGetState¥nGetDeviceData",hr);
00317 }
00318
00319 return hr;
00320 }
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370