Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

317 lines
8.1 KiB

  1. /*****************************************************************************
  2. *
  3. * diqeeff.c
  4. *
  5. * Property sheet page for device "enumerate effects".
  6. *
  7. *****************************************************************************/
  8. #include "diquick.h"
  9. /*****************************************************************************
  10. *
  11. * EEff_AddGuid
  12. *
  13. * Add a GUID to the list, or -1 on error.
  14. *
  15. *****************************************************************************/
  16. int INLINE
  17. EEff_AddGuid(PDEVDLGINFO pddi, REFGUID rguid)
  18. {
  19. return Dary_Append(&pddi->daryGuid, rguid);
  20. }
  21. /*****************************************************************************
  22. *
  23. * EEff_EnumCallback
  24. *
  25. * Called once for each effect.
  26. *
  27. *****************************************************************************/
  28. typedef struct EFFENUMINFO {
  29. HWND hwndList;
  30. PDEVDLGINFO pddi;
  31. } EFFENUMINFO, *PEFFENUMINFO;
  32. BOOL CALLBACK
  33. EEff_EnumCallback(PCV pvEffi, LPVOID pv)
  34. {
  35. PEFFENUMINFO peei = pv;
  36. PDEVDLGINFO pddi = peei->pddi;
  37. DIEFFECTINFO ei;
  38. int iguid;
  39. ConvertEffi(pddi, &ei, pvEffi);
  40. iguid = EEff_AddGuid(pddi, &ei.guid);
  41. if (iguid >= 0) {
  42. int iItem;
  43. iItem = ListBox_AddString(peei->hwndList, ei.tszName);
  44. ListBox_SetItemData(peei->hwndList, iItem, iguid);
  45. }
  46. return DIENUM_CONTINUE;
  47. }
  48. /*****************************************************************************
  49. *
  50. * EEff_Enum
  51. *
  52. * Enumerate the objects in the device and populate the list box.
  53. *
  54. *****************************************************************************/
  55. BOOL INTERNAL
  56. EEff_Enum(HWND hdlg)
  57. {
  58. EFFENUMINFO eei;
  59. #ifdef DEBUG
  60. int iItem;
  61. #endif
  62. eei.pddi = GetDialogPtr(hdlg);
  63. eei.hwndList = GetDlgItem(hdlg, IDC_ENUMEFF_LIST);
  64. SetWindowRedraw(eei.hwndList, FALSE);
  65. ListBox_ResetContent(eei.hwndList);
  66. IDirectInputDevice8_EnumEffects(eei.pddi->pdid,
  67. EEff_EnumCallback, &eei, 0);
  68. #ifdef DEBUG
  69. iItem = ListBox_AddString(eei.hwndList, TEXT("<invalid>"));
  70. ListBox_SetItemData(eei.hwndList, iItem,
  71. EEff_AddGuid(eei.pddi, &IID_IDirectInputDevice8A));
  72. #endif
  73. SetWindowRedraw(eei.hwndList, TRUE);
  74. return 1;
  75. }
  76. /*****************************************************************************
  77. *
  78. * EEff_OnInitDialog
  79. *
  80. * Start out by enumerating everything.
  81. *
  82. *****************************************************************************/
  83. BOOL INTERNAL
  84. EEff_OnInitDialog(HWND hdlg, LPARAM lp)
  85. {
  86. PDEVDLGINFO pddi = (PV)(((LPPROPSHEETPAGE)lp)->lParam);
  87. SetDialogPtr(hdlg, pddi);
  88. EEff_Enum(hdlg);
  89. return 1;
  90. }
  91. /*****************************************************************************
  92. *
  93. * EEff_OnDestroy
  94. *
  95. * Clean up.
  96. *
  97. *****************************************************************************/
  98. BOOL INTERNAL
  99. EEff_OnDestroy(HWND hdlg)
  100. {
  101. PDEVDLGINFO pddi = GetDialogPtr(hdlg);
  102. if (pddi) {
  103. Dary_Term(&pddi->daryGuid);
  104. }
  105. return 1;
  106. }
  107. /*****************************************************************************
  108. *
  109. * EEff_OnDblClk
  110. *
  111. * An item in the list box was double-clicked. Show its properties.
  112. *
  113. *****************************************************************************/
  114. #if 0
  115. BOOL CALLBACK EnumCallback(LPDIRECTINPUTEFFECT peff, LPVOID pv)
  116. {
  117. peff;
  118. pv;
  119. OutputDebugString("Got an effect\r\n");
  120. peff->lpVtbl->Stop(peff);
  121. return DIENUM_CONTINUE;
  122. }
  123. void __cdecl Squirt(LPCSTR ptszFormat, ...)
  124. {
  125. TCHAR tsz[1024];
  126. va_list ap;
  127. va_start(ap, ptszFormat);
  128. wvsprintf(tsz, ptszFormat, ap);
  129. OutputDebugString(tsz);
  130. OutputDebugString(TEXT("\r\n"));
  131. }
  132. BOOL INTERNAL
  133. EEff_OnDblClk(HWND hdlg)
  134. {
  135. PDEVDLGINFO pddi = GetDialogPtr(hdlg);
  136. HWND hwndList = GetDlgItem(hdlg, IDC_ENUMEFF_LIST);
  137. int iItem;
  138. iItem = ListBox_GetCurSel(hwndList);
  139. if (iItem >= 0) {
  140. int iguid;
  141. iguid = ListBox_GetItemData(hwndList, iItem);
  142. if (iguid >= 0) {
  143. LPDIRECTINPUTDEVICE2 pdev2 = (PV)pddi->pdid;
  144. LPDIRECTINPUTEFFECT peff;
  145. REFGUID rguid = Dary_GetPtr(&pddi->daryGuid, iguid, GUID);
  146. DWORD rgdw[2] = { DIJOFS_X, DIJOFS_Y };
  147. LONG rgl[2] = { 100, 99 };
  148. DICONSTANTFORCE cf = { 0 };
  149. DICONDITION cond[2] = { { 0 } };
  150. HRESULT hres;
  151. DIEFFECT deff;
  152. DIENVELOPE env;
  153. hres = SetDwordProperty(pddi->pdid, DIPROP_AUTOCENTER, DIPROPAUTOCENTER_OFF);
  154. ZeroX(env);
  155. env.dwSize = cbX(env);
  156. ZeroX(deff);
  157. deff.dwSize = cbX(deff);
  158. deff.dwFlags = DIEFF_OBJECTOFFSETS | DIEFF_POLAR;
  159. deff.cAxes = 2;
  160. deff.rgdwAxes = rgdw;
  161. deff.rglDirection = rgl;
  162. deff.dwTriggerButton = DIEB_NOTRIGGER;//DIJOFS_BUTTON0;
  163. deff.cbTypeSpecificParams = cbX(cf);
  164. deff.lpvTypeSpecificParams = &cf;
  165. // deff.lpEnvelope = &env;
  166. pdev2->lpVtbl->Acquire(pdev2);
  167. hres = IDirectInputDevice8_CreateEffect(pdev2, rguid,
  168. &deff, &peff, 0);
  169. if (SUCCEEDED(hres)) {
  170. hres = IDirectInputDevice8_EnumCreatedEffectObjects(pdev2,
  171. EnumCallback, 0, 0);
  172. memset(&env, 0xCC, cbX(env));
  173. deff.lpEnvelope = &env;
  174. env.dwSize = cbX(env);
  175. //deff.cbTypeSpecificParams = 0;
  176. deff.dwFlags = DIEFF_OBJECTIDS |
  177. DIEFF_SPHERICAL | DIEFF_CARTESIAN | DIEFF_POLAR;
  178. hres = IDirectInputEffect_GetParameters(peff, &deff,
  179. DIEP_ALLPARAMS);
  180. Squirt("------------------------------------");
  181. Squirt("----- dwFlags = %08x", deff.dwFlags);
  182. Squirt("----- dwDuration = %d", deff.dwDuration);
  183. Squirt("----- dwSamplePeriod = %d", deff.dwSamplePeriod);
  184. Squirt("----- dwGain = %d", deff.dwGain);
  185. Squirt("----- dwTriggerButton = %08x", deff.dwTriggerButton);
  186. Squirt("----- dwTriggerRepeatInterval = %d", deff.dwTriggerRepeatInterval);
  187. Squirt("----- cAxes = %d", deff.cAxes);
  188. Squirt("----- rgdwAxes = %08x", deff.rgdwAxes);
  189. Squirt("----- rglDirection = %08x", deff.rglDirection);
  190. Squirt("----- rglDirection[0] = %d", rgl[0]);
  191. Squirt("----- rglDirection[1] = %d", rgl[1]);
  192. Squirt("----- cbTSP = %d", deff.cbTypeSpecificParams);
  193. Squirt("------------------------------------");
  194. hres = IDirectInputEffect_Start(peff, 1, 0);
  195. hres = IDirectInputEffect_Stop(peff);
  196. hres = IDirectInputEffect_GetEffectStatus(peff, rgdw);
  197. peff->lpVtbl->Release(peff);
  198. }
  199. pdev2->lpVtbl->Unacquire(pdev2);
  200. }
  201. }
  202. return 1;
  203. }
  204. #else
  205. BOOL INTERNAL
  206. EEff_OnDblClk(HWND hdlg)
  207. {
  208. PDEVDLGINFO pddi = GetDialogPtr(hdlg);
  209. HWND hwndList = GetDlgItem(hdlg, IDC_ENUMEFF_LIST);
  210. int iItem;
  211. iItem = ListBox_GetCurSel(hwndList);
  212. if (iItem >= 0) {
  213. int iguid;
  214. iguid = (int)(INT_PTR)ListBox_GetItemData(hwndList, iItem);
  215. if (iguid >= 0) {
  216. REFGUID rguid = Dary_GetPtr(&pddi->daryGuid, iguid, GUID);
  217. EffProp_Create(hdlg, pddi, rguid);
  218. }
  219. }
  220. return TRUE;
  221. }
  222. #endif
  223. /*****************************************************************************
  224. *
  225. * EEff_OnCommand
  226. *
  227. *****************************************************************************/
  228. BOOL INLINE
  229. EEff_OnCommand(HWND hdlg, int id, UINT cmd)
  230. {
  231. switch (id) {
  232. case IDC_ENUMEFF_LIST:
  233. if (cmd == LBN_DBLCLK) return EEff_OnDblClk(hdlg);
  234. break;
  235. }
  236. return 0;
  237. }
  238. /*****************************************************************************
  239. *
  240. * EEff_DlgProc
  241. *
  242. *****************************************************************************/
  243. INT_PTR CALLBACK
  244. EEff_DlgProc(HWND hdlg, UINT wm, WPARAM wp, LPARAM lp)
  245. {
  246. switch (wm) {
  247. case WM_INITDIALOG: return EEff_OnInitDialog(hdlg, lp);
  248. case WM_COMMAND:
  249. return EEff_OnCommand(hdlg,
  250. (int)GET_WM_COMMAND_ID(wp, lp),
  251. (UINT)GET_WM_COMMAND_CMD(wp, lp));
  252. case WM_DESTROY: return EEff_OnDestroy(hdlg);
  253. }
  254. return 0;
  255. }