GameWnd.cpp
上传用户:cydong117
上传日期:2009-11-10
资源大小:638k
文件大小:7k
源码类别:

模拟服务器

开发平台:

Visual C++

  1. /******************************************************************************************************************
  2.                                                                                                                    
  3. 葛碘疙:
  4. 累己磊:
  5. 累己老:
  6. [老磊][荐沥磊] : 荐沥 郴侩
  7.                                                                                                                    
  8. *******************************************************************************************************************/
  9. #include "StdAfx.h"
  10. VOID CGameWnd::CreateGameWnd(INT nID, CWHWilImageData* pxWndImage, INT nFrameImgIdx, BOOL bCanMove, INT nStartX, INT nStartY, INT nWidth, INT nHeight)
  11. {
  12. m_nID = nID;
  13. m_nFrameImgIdx = nFrameImgIdx;
  14. m_pxWndImage = pxWndImage;
  15. m_bCanMove = bCanMove;
  16. if ( m_pxWndImage->NewSetIndex(m_nFrameImgIdx) )
  17. {
  18. SetRect(&m_rcImgWnd, nStartX, nStartY, 
  19. nStartX+m_pxWndImage->m_lpstNewCurrWilImageInfo->shWidth,
  20. nStartY+m_pxWndImage->m_lpstNewCurrWilImageInfo->shHeight);
  21. }
  22. ( ! nWidth )  ? m_nWidth = m_rcImgWnd.right -m_rcImgWnd.left: m_nWidth  = nWidth;
  23. ( ! nHeight ) ? m_nHeight =m_rcImgWnd.bottom-m_rcImgWnd.top : m_nHeight = nHeight;
  24. SetRect(&m_rcWnd, nStartX, nStartY, nStartX+m_nWidth, nStartY+m_nHeight);
  25. // 3D抛胶飘
  26.   D3DVECTOR vNorm(0, 0, -1);
  27.     m_avBoard[0]  = D3DVERTEX(D3DVECTOR(-0.5f, 0.5f, 0), vNorm, 0, 0);
  28.     m_avBoard[1]  = D3DVERTEX(D3DVECTOR(-0.5f,-0.5f, 0), vNorm, 0, 1);
  29.     m_avBoard[2]  = D3DVERTEX(D3DVECTOR( 0.5f, 0.5f, 0), vNorm, 1, 0);
  30.     m_avBoard[3]  = D3DVERTEX(D3DVECTOR( 0.5f,-0.5f, 0), vNorm, 1, 1);
  31. }
  32. VOID CGameWnd::Init()
  33. {
  34. m_nID = 0; 
  35. m_nFrameImgIdx = 0;
  36. m_nWidth = 0;
  37. m_nHeight = 0;
  38. m_pxWndImage = NULL;
  39. m_bActive = FALSE;
  40. m_bFocused = FALSE;
  41. m_bMoving = FALSE;
  42. m_bCanMove = FALSE;
  43. SetRect(&m_rcWnd, 0, 0, 0, 0);
  44. SetRect(&m_rcImgWnd, 0, 0, 0, 0);
  45. ZeroMemory(&m_bGrabbedMousePos, sizeof(POINT));
  46. D3DVECTOR vNorm(0, 0, -1);
  47. m_avBoard[0] = D3DVERTEX(D3DVECTOR(-0.5f, 0.5f, 0), vNorm, 0, 0);
  48. m_avBoard[1] = D3DVERTEX(D3DVECTOR(-0.5f,-0.5f, 0), vNorm, 0, 1);
  49. m_avBoard[2] = D3DVERTEX(D3DVECTOR( 0.5f, 0.5f, 0), vNorm, 1, 0);
  50. m_avBoard[3] = D3DVERTEX(D3DVECTOR( 0.5f,-0.5f, 0), vNorm, 1, 1);
  51. }
  52. VOID CGameWnd::Destroy()
  53. {
  54. Init();
  55. }
  56. VOID CGameWnd::ShowGameWnd()
  57. {
  58. if ( m_bActive )
  59. {
  60. if ( m_pxWndImage->NewSetIndex(m_nFrameImgIdx) )
  61. {
  62.   g_xMainWnd.DrawWithImageForCompClipRgn(m_rcWnd.left, m_rcWnd.top, m_pxWndImage->m_lpstNewCurrWilImageInfo->shWidth, m_pxWndImage->m_lpstNewCurrWilImageInfo->shHeight,
  63.    (WORD*)m_pxWndImage->m_pbCurrImage, _CLIP_WIDTH, 600);
  64. }
  65. /* if ( g_xMainWnd.Get3DDevice() )
  66. {
  67. D3DVECTOR vTrans;
  68. D3DMATRIX matTrans;
  69. D3DMATRIX matScale;
  70. D3DMATRIX matWorld;
  71. D3DMATRIX matWorldOriginal;
  72. D3DMATERIAL7 mtrl;
  73. if( SUCCEEDED(g_xMainWnd.Get3DDevice()->BeginScene()) )
  74. {
  75. g_xMainWnd.Get3DDevice()->GetTransform(D3DTRANSFORMSTATE_WORLD, &matWorldOriginal);
  76. m_pxWndImage->NewSetIndex(m_nFrameImgIdx);
  77. vTrans.x = (FLOAT)m_rcWnd.left+(FLOAT)(m_rcImgWnd.right-m_rcImgWnd.left)/2-400;
  78. vTrans.y = (FLOAT)-m_rcWnd.top-(FLOAT)(m_rcImgWnd.bottom-m_rcImgWnd.top)/2+300;
  79. vTrans.z = 0;
  80. D3DUtil_SetTranslateMatrix(matTrans, vTrans);
  81. D3DUtil_SetScaleMatrix(matScale, (FLOAT)m_rcImgWnd.right-m_rcImgWnd.left, (FLOAT)m_rcImgWnd.bottom-m_rcImgWnd.top, 0.0f);
  82. D3DMath_MatrixMultiply(matWorld, matScale, matTrans);
  83. g_xMainWnd.Get3DDevice()->SetTransform(D3DTRANSFORMSTATE_WORLD, &matWorld);
  84. LPDIRECTDRAWSURFACE7 lpddsTextr = g_xGameProc.m_xImage.GetTextrImg(_TEXTR_FILE_INTER, _IMAGE_INTEREX, m_nFrameImgIdx);
  85. g_xMainWnd.Get3DDevice()->SetTexture(0, lpddsTextr);
  86. // g_xMainWnd.Get3DDevice()->SetTexture(0, D3DWILTextr_GetSurface(m_pxWndImage->m_szWilFileName, m_nFrameImgIdx));
  87. D3DUtil_InitMaterial(mtrl, 
  88.  (FLOAT)255/255.0f,
  89.  (FLOAT)255/255.0f, 
  90.  (FLOAT)255/255.0f);
  91. if ( m_bFocused )
  92. {
  93. mtrl.diffuse.a = 200/255.0f;
  94. }
  95. else
  96. {
  97. mtrl.diffuse.a = 170/255.0f;
  98. }
  99. g_xMainWnd.Get3DDevice()->SetMaterial(&mtrl);
  100. g_xMainWnd.Get3DDevice()->SetRenderState( D3DRENDERSTATE_ALPHABLENDENABLE, TRUE );
  101. g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE, TRUE);
  102. g_xMainWnd.Get3DDevice()->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
  103. g_xMainWnd.Get3DDevice()->SetTextureStageState(0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE);
  104. g_xMainWnd.Get3DDevice()->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
  105. g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE);
  106. g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
  107. g_xMainWnd.Get3DDevice()->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_VERTEX, m_avBoard, 4, NULL);
  108. g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
  109. g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE, FALSE);
  110. g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_SRCBLEND , D3DBLEND_ONE);
  111. g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO);
  112. g_xMainWnd.Get3DDevice()->SetTransform(D3DTRANSFORMSTATE_WORLD, &matWorldOriginal);
  113. g_xMainWnd.Get3DDevice()->EndScene();
  114. }
  115. }
  116. */ }
  117. }
  118. VOID CGameWnd::ResetWndImg(INT nIdx)
  119. {
  120. // D3DWILTextr_Invalidate(m_pxWndImage->m_szWilFileName, m_nFrameImgIdx);
  121. if ( m_pxWndImage->NewSetIndex(nIdx) )
  122. {
  123. m_nFrameImgIdx = nIdx;
  124. SetRect(&m_rcImgWnd, m_rcWnd.left, m_rcWnd.top, 
  125. m_rcWnd.left+m_pxWndImage->m_lpstNewCurrWilImageInfo->shWidth,
  126. m_rcWnd.top+m_pxWndImage->m_lpstNewCurrWilImageInfo->shHeight);
  127. m_nWidth = m_rcImgWnd.right-m_rcWnd.left;
  128. m_nHeight =m_rcImgWnd.bottom-m_rcWnd.top;
  129. m_rcWnd = m_rcImgWnd;
  130. }
  131. // g_xGameProc.m_xImage.AddTextr(_TEXTR_FILE_INTER, _IMAGE_INTEREX, m_nFrameImgIdx);
  132. // D3DWILTextr_Restore(m_pxWndImage->m_szWilFileName, m_nFrameImgIdx, g_xMainWnd.Get3DDevice());
  133. }
  134. // 扩档快甫 劝己拳 茄促.
  135. VOID CGameWnd::SetGameWndActive(BOOL bActive)
  136. {
  137. m_bActive = bActive;
  138. g_xGameProc.m_xImage.AddTextr(_TEXTR_FILE_INTER, _IMAGE_INTEREX, m_nFrameImgIdx);
  139. /* if ( m_bActive )
  140. {
  141. D3DWILTextr_Restore(m_pxWndImage->m_szWilFileName, m_nFrameImgIdx, g_xMainWnd.Get3DDevice());
  142. }
  143. else
  144. {
  145. D3DWILTextr_Invalidate(m_pxWndImage->m_szWilFileName, m_nFrameImgIdx);
  146. }
  147. */
  148. }
  149. // 扩档快俊 器目胶甫 霖促.
  150. VOID CGameWnd::SetGameWndFocused(BOOL bFocused)
  151. {
  152. m_bFocused = bFocused;
  153. }
  154. VOID CGameWnd::MoveGameWnd(POINT ptMouse)
  155. {
  156. if ( m_bActive && m_bFocused && m_bCanMove )
  157. {
  158. SetRect(&m_rcWnd, ptMouse.x-m_bGrabbedMousePos.x, ptMouse.y-m_bGrabbedMousePos.y, 
  159. ptMouse.x-m_bGrabbedMousePos.x+m_nWidth, ptMouse.y-m_bGrabbedMousePos.y+m_nHeight); 
  160. }
  161. }
  162. // 扩档快啊 框流捞扁 矫累且锭 付快胶客狼 Gap阑 掘绰促.
  163. VOID CGameWnd::SetReadyMove(POINT ptMouse)
  164. {
  165. if ( m_bActive && m_bFocused && m_bCanMove )
  166. {
  167. m_bGrabbedMousePos.x = ptMouse.x - m_rcWnd.left;
  168. m_bGrabbedMousePos.y = ptMouse.y - m_rcWnd.top;
  169. }
  170. }