Leaked source code of windows server 2003
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.

168 lines
4.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: dinputeffectobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #define DIRECTINPUT_VERSION 0x0500
  11. #include "stdafx.h"
  12. #include "Direct.h"
  13. #include "dms.h"
  14. #include "dInputEffectObj.h"
  15. extern HRESULT FixUpCoverEffect(GUID g, DIEffect *cover,DIEFFECT *realEffect);
  16. extern HRESULT FixUpRealEffect(GUID g,DIEFFECT *realEffect,DIEffect *cover);
  17. extern BSTR DINPUTGUIDtoBSTR(LPGUID g);
  18. CONSTRUCTOR(_dxj_DirectInputEffect, {});
  19. DESTRUCTOR(_dxj_DirectInputEffect, {});
  20. GETSET_OBJECT(_dxj_DirectInputEffect);
  21. STDMETHODIMP C_dxj_DirectInputEffectObject::download()
  22. {
  23. HRESULT hr;
  24. hr=m__dxj_DirectInputEffect->Download();
  25. return hr;
  26. }
  27. STDMETHODIMP C_dxj_DirectInputEffectObject::getEffectGuid(BSTR *guid)
  28. {
  29. HRESULT hr;
  30. GUID g;
  31. if (!guid) return E_INVALIDARG;
  32. hr=m__dxj_DirectInputEffect->GetEffectGuid(&g);
  33. *guid=DINPUTGUIDtoBSTR(&g);
  34. return hr;
  35. }
  36. STDMETHODIMP C_dxj_DirectInputEffectObject::getEffectStatus(long *ret)
  37. {
  38. HRESULT hr;
  39. if (!ret) return E_INVALIDARG;
  40. hr=m__dxj_DirectInputEffect->GetEffectStatus((DWORD*)ret);
  41. return hr;
  42. }
  43. STDMETHODIMP C_dxj_DirectInputEffectObject::start(
  44. /* [in] */ long iterations,
  45. /* [in] */ long flags)
  46. {
  47. HRESULT hr;
  48. hr=m__dxj_DirectInputEffect->Start((DWORD)iterations,(DWORD)flags);
  49. return hr;
  50. }
  51. STDMETHODIMP C_dxj_DirectInputEffectObject::stop()
  52. {
  53. HRESULT hr;
  54. hr=m__dxj_DirectInputEffect->Stop();
  55. return hr;
  56. }
  57. STDMETHODIMP C_dxj_DirectInputEffectObject::unload()
  58. {
  59. HRESULT hr;
  60. hr=m__dxj_DirectInputEffect->Unload();
  61. return hr;
  62. }
  63. STDMETHODIMP C_dxj_DirectInputEffectObject::setParameters(
  64. /* [in] */ DIEffect __RPC_FAR *effectInfo, long flags)
  65. {
  66. DIEFFECT realEffect;
  67. HRESULT hr;
  68. GUID g;
  69. m__dxj_DirectInputEffect->GetEffectGuid(&g);
  70. hr=FixUpRealEffect(g,&realEffect,effectInfo);
  71. if FAILED(hr) return hr;
  72. hr=m__dxj_DirectInputEffect->SetParameters(&realEffect,(DWORD) flags);
  73. return hr;
  74. }
  75. #define DICONDITION_USE_BOTH_AXIS 1
  76. #define DICONDITION_USE_DIRECTION 2
  77. STDMETHODIMP C_dxj_DirectInputEffectObject::getParameters(
  78. /* [in] */ DIEffect __RPC_FAR *effectInfo)
  79. {
  80. HRESULT hr;
  81. GUID g;
  82. DIEFFECT *pRealEffect=(DIEFFECT*)effectInfo;
  83. DWORD dwFlags= DIEP_ALLPARAMS;
  84. if (!effectInfo) return E_INVALIDARG;
  85. ZeroMemory(pRealEffect,sizeof(DIEffect));
  86. if (!pRealEffect->dwFlags) pRealEffect->dwFlags = DIEFF_OBJECTOFFSETS | DIEFF_POLAR;
  87. pRealEffect->dwSize =sizeof(DIEFFECT);
  88. pRealEffect->lpEnvelope =(DIENVELOPE*)&(effectInfo->envelope);
  89. pRealEffect->lpEnvelope->dwSize=sizeof(DIENVELOPE);
  90. pRealEffect->cAxes = 2;
  91. pRealEffect->rglDirection =(long*)&(effectInfo->x);
  92. hr=m__dxj_DirectInputEffect->GetEffectGuid(&g);
  93. if FAILED(hr) return hr;
  94. if (g==GUID_ConstantForce)
  95. {
  96. pRealEffect->lpvTypeSpecificParams =&(effectInfo->constantForce);
  97. pRealEffect->cbTypeSpecificParams =sizeof(DICONSTANTFORCE);
  98. }
  99. else if ((g==GUID_Square)||(g==GUID_Triangle)||(g==GUID_SawtoothUp)||(g==GUID_SawtoothDown)||(g==GUID_Sine))
  100. {
  101. pRealEffect->lpvTypeSpecificParams =&(effectInfo->periodicForce);
  102. pRealEffect->cbTypeSpecificParams =sizeof(DIPERIODIC);
  103. }
  104. else if ((g==GUID_Spring)|| (g==GUID_Damper)|| (g==GUID_Inertia)|| (g==GUID_Friction)){
  105. pRealEffect->cbTypeSpecificParams =sizeof(DICONDITION)*2;
  106. pRealEffect->lpvTypeSpecificParams =&(effectInfo->conditionX);
  107. }
  108. else if (g==GUID_RampForce){
  109. pRealEffect->lpvTypeSpecificParams =&(effectInfo->rampForce);
  110. pRealEffect->cbTypeSpecificParams =sizeof(DIRAMPFORCE);
  111. }
  112. else {
  113. pRealEffect->lpvTypeSpecificParams =NULL;
  114. pRealEffect->cbTypeSpecificParams =0;
  115. dwFlags= dwFlags -DIEP_TYPESPECIFICPARAMS;
  116. }
  117. effectInfo->axisOffsets.x=DIJOFS_X;
  118. effectInfo->axisOffsets.y=DIJOFS_Y;
  119. pRealEffect->rgdwAxes=(DWORD*)&(effectInfo->axisOffsets);
  120. hr=m__dxj_DirectInputEffect->GetParameters(pRealEffect, dwFlags);
  121. if FAILED(hr) return hr;
  122. if (pRealEffect->cbTypeSpecificParams == sizeof(DICONDITION)*2)
  123. effectInfo->conditionFlags=DICONDITION_USE_BOTH_AXIS;
  124. else
  125. effectInfo->conditionFlags=DICONDITION_USE_DIRECTION;
  126. if (pRealEffect->lpEnvelope){
  127. effectInfo->bUseEnvelope=VARIANT_TRUE;
  128. }
  129. return hr;
  130. }