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

模拟服务器

开发平台:

Visual C++

  1. /******************************************************************************************************************
  2.                                                                                                                    
  3. 葛碘疙:
  4. 累己磊:
  5. 累己老:
  6. [老磊][荐沥磊] : 荐沥 郴侩
  7.                                                                                                                    
  8. *******************************************************************************************************************/
  9. #include "StdAfx.h"
  10. VOID CGameBtn::CreateGameBtn(CWHWilImageData* pxBtnImage, INT nFocusImgIdx, INT nClickImgIdx, INT nStartX, INT nStartY, BYTE bBtnType)
  11. {
  12. m_bBtnType = bBtnType;
  13. m_bBtnState = _BTN_STATE_NORMAL;
  14. m_pxBtnImage = pxBtnImage;
  15. m_nFocusImgIdx = nFocusImgIdx;
  16. m_nClickImgIdx = nClickImgIdx;
  17. m_pxBtnImage->NewSetIndex(nFocusImgIdx);
  18. SetRect(&m_rcBtn, nStartX, nStartY, 
  19. nStartX+m_pxBtnImage->m_lpstNewCurrWilImageInfo->shWidth,
  20. nStartY+m_pxBtnImage->m_lpstNewCurrWilImageInfo->shHeight);
  21. }
  22. VOID CGameBtn::Init()
  23. {
  24. m_bBtnType = _BTN_TYPE_FOCUS;
  25. m_bBtnState = _BTN_STATE_FOCUS;
  26. m_pxBtnImage = NULL;
  27. m_nFocusImgIdx = 0;
  28. m_nClickImgIdx = 0;
  29. SetRect(&m_rcBtn, 0, 0, 0, 0);
  30. }
  31. VOID CGameBtn::Destroy()
  32. {
  33. Init();
  34. }
  35. VOID CGameBtn::ShowGameBtn()
  36. {
  37. if ( m_bBtnState == _BTN_STATE_FOCUS && m_bBtnType == _BTN_TYPE_FOCUS )
  38. {
  39. m_pxBtnImage->NewSetIndex(m_nFocusImgIdx);
  40.   g_xMainWnd.DrawWithImageForCompClipRgn(m_rcBtn.left, m_rcBtn.top, m_rcBtn.right-m_rcBtn.left, m_rcBtn.bottom-m_rcBtn.top,
  41.    (WORD*)m_pxBtnImage->m_pbCurrImage, _CLIP_WIDTH, 600);
  42. }
  43. else if ( m_bBtnState == _BTN_STATE_CLICK )
  44. {
  45. m_pxBtnImage->NewSetIndex(m_nClickImgIdx);
  46.   g_xMainWnd.DrawWithImageForCompClipRgn(m_rcBtn.left, m_rcBtn.top, m_rcBtn.right-m_rcBtn.left, m_rcBtn.bottom-m_rcBtn.top,
  47.    (WORD*)m_pxBtnImage->m_pbCurrImage, _CLIP_WIDTH, 600);
  48. }
  49. }
  50. VOID CGameBtn::OnMouseMove(POINT ptMouse)
  51. {
  52. if ( PtInRect(&m_rcBtn, ptMouse) && (m_bBtnState != _BTN_STATE_CLICK) )
  53. {
  54. m_bBtnState = _BTN_STATE_FOCUS;
  55. return;
  56. }
  57. else if ( m_bBtnState == _BTN_STATE_CLICK )
  58. {
  59. return;
  60. }
  61. m_bBtnState = _BTN_STATE_NORMAL;
  62. }
  63. BOOL CGameBtn::OnLButtonDown(POINT ptMouse)
  64. {
  65. if ( PtInRect(&m_rcBtn, ptMouse) )
  66. {
  67. m_bBtnState = _BTN_STATE_CLICK;
  68. return TRUE;
  69. }
  70. return FALSE;
  71. }
  72. BOOL CGameBtn::OnLButtonUp(POINT ptMouse)
  73. {
  74. m_bBtnState = _BTN_STATE_NORMAL;
  75. if ( PtInRect(&m_rcBtn, ptMouse) )
  76. {
  77. return TRUE;
  78. }
  79. return FALSE;
  80. }
  81. VOID CGameBtn::ChangeRect(INT nStartX, INT nStartY)
  82. {
  83. m_pxBtnImage->NewSetIndex(m_nFocusImgIdx);
  84. SetRect(&m_rcBtn, nStartX, nStartY, 
  85. nStartX+m_pxBtnImage->m_lpstNewCurrWilImageInfo->shWidth,
  86. nStartY+m_pxBtnImage->m_lpstNewCurrWilImageInfo->shHeight);
  87. }
  88. VOID CGameBtn::ResetGameBtn(INT nFocusImgIdx, INT nClickImgIdx)
  89. {
  90. m_bBtnState = _BTN_STATE_NORMAL;
  91. m_nFocusImgIdx = nFocusImgIdx;
  92. m_nClickImgIdx = nClickImgIdx;
  93. if ( m_pxBtnImage->NewSetIndex(nFocusImgIdx) )
  94. {
  95. INT nStartX = m_rcBtn.left;
  96. INT nStartY = m_rcBtn.top;
  97. SetRect(&m_rcBtn, nStartX, nStartY, 
  98. nStartX+m_pxBtnImage->m_lpstNewCurrWilImageInfo->shWidth,
  99. nStartY+m_pxBtnImage->m_lpstNewCurrWilImageInfo->shHeight);
  100. }
  101. }
  102. CMsgBoxBtn::CMsgBoxBtn():CGameBtn()
  103. {
  104. }
  105. CMsgBoxBtn::~CMsgBoxBtn()
  106. {
  107. }
  108. VOID CMsgBoxBtn::ShowGameBtn()
  109. {
  110. if ( m_bBtnState != _BTN_STATE_CLICK)
  111. {
  112. m_pxBtnImage->NewSetIndex(m_nFocusImgIdx);
  113.   g_xMainWnd.DrawWithImageForCompClipRgn(m_rcBtn.left, m_rcBtn.top, m_rcBtn.right-m_rcBtn.left, m_rcBtn.bottom-m_rcBtn.top,
  114.    (WORD*)m_pxBtnImage->m_pbCurrImage, _CLIP_WIDTH, 600);
  115. }
  116. else
  117. {
  118. m_pxBtnImage->NewSetIndex(m_nClickImgIdx);
  119.   g_xMainWnd.DrawWithImageForCompClipRgn(m_rcBtn.left, m_rcBtn.top, m_rcBtn.right-m_rcBtn.left, m_rcBtn.bottom-m_rcBtn.top,
  120.    (WORD*)m_pxBtnImage->m_pbCurrImage, _CLIP_WIDTH, 600);
  121. }
  122. }
  123. CScrlBar::CScrlBar()
  124. {
  125. Init();
  126. }
  127. CScrlBar::~CScrlBar()
  128. {
  129. }
  130. VOID CScrlBar::CreateScrlBar(CWHWilImageData* pxImage, INT ImgIdx, INT nPageLine, WORD wScrlWidth, WORD wScrlHeight, WORD wScrlBtnHeight)
  131. {
  132. m_pxScrlImage = pxImage;
  133. m_nScrlImgIdx = ImgIdx;
  134. m_nPageLine = nPageLine;
  135. m_wScrlWidth = wScrlWidth;
  136. m_wScrlHeight = wScrlHeight;
  137. m_wScrlBtnHeight= wScrlBtnHeight;
  138. }
  139. VOID CScrlBar::ShowScrlBar(INT nX, INT nY, INT nFstPos, INT nCounter)
  140. {
  141. RECT rcImg;
  142. if ( m_pxScrlImage->NewSetIndex(m_nScrlImgIdx) )
  143. {
  144. INT nImgHeight = m_pxScrlImage->m_lpstNewCurrWilImageInfo->shHeight;
  145. INT nImgWidth  = m_pxScrlImage->m_lpstNewCurrWilImageInfo->shWidth;
  146. m_fScrlRate = (FLOAT)nFstPos/(FLOAT)(nCounter-1);
  147. m_fPageRate = (FLOAT)m_nPageLine/(FLOAT)(nCounter);
  148. SetRect(&m_rcScrlRgn, 
  149. nX, nY+nImgHeight-m_wScrlHeight, nX+m_wScrlWidth, nY+nImgHeight);
  150. SetRect(&m_rcScrlBtnRgn, 
  151. nX, nY+nImgHeight-m_wScrlHeight+(m_wScrlHeight*m_fScrlRate),
  152. nX+m_wScrlWidth, nY+nImgHeight-m_wScrlHeight+(m_wScrlHeight*m_fScrlRate)+m_wScrlBtnHeight);
  153. SetRect(&rcImg,
  154. 0, nImgHeight-m_wScrlHeight-m_fScrlRate*m_wScrlHeight,
  155. m_wScrlWidth, nImgHeight-m_fScrlRate*m_wScrlHeight);
  156. // g_xMainWnd.DrawWithGDI(m_rcScrlRgn, NULL, RGB(255, 250, 180), 1);
  157. // g_xMainWnd.DrawWithGDI(m_rcScrlBtnRgn, NULL, RGB(255, 250, 180), 2);
  158. RECT rc = {nX+10, nY, nX+10+nImgWidth, nY+nImgHeight};
  159. // g_xMainWnd.DrawWithGDI(rc, NULL, RGB(255, 250, 180), 2);
  160. //  g_xMainWnd.DrawWithImageForComp(nX, nY+m_fScrlRate*m_wScrlHeight, nImgWidth, nImgHeight, (WORD*)m_pxScrlImage->m_pbCurrImage);
  161.   g_xMainWnd.DrawWithImageForComp(nX, nY+m_fScrlRate*m_wScrlHeight, rcImg, (WORD*)m_pxScrlImage->m_pbCurrImage);
  162. }
  163. }
  164. BOOL CScrlBar::OnMouseMove(POINT ptMouse)
  165. {
  166. if ( m_bGrapsed )
  167. {
  168. if ( ptMouse.y <= m_rcScrlRgn.top )
  169. {
  170. m_fScrlRate = 0.0f;
  171. }
  172. else if ( ptMouse.y >= m_rcScrlRgn.bottom )
  173. {
  174. m_fScrlRate = 1.0f;
  175. }
  176. else
  177. m_fScrlRate = (FLOAT)(ptMouse.y-m_rcScrlRgn.top)/(FLOAT)(m_rcScrlRgn.bottom-m_rcScrlRgn.top);
  178. return TRUE;
  179. }
  180. return FALSE;
  181. }
  182. BOOL CScrlBar::OnLButtonDown(POINT ptMouse)
  183. {
  184. if ( PtInRect(&m_rcScrlBtnRgn, ptMouse)  )
  185. {
  186. m_bGrapsed = TRUE;
  187. }
  188. else if ( PtInRect(&m_rcScrlRgn, ptMouse) )
  189. {
  190. // 困肺 茄其捞瘤 胶农费.
  191. if ( m_rcScrlBtnRgn.top+m_wScrlBtnHeight/2 > ptMouse.y )
  192. {
  193. m_fScrlRate -= m_fPageRate;
  194. if ( m_fScrlRate < 0.0f )
  195. {
  196. m_fScrlRate = 0.0f;
  197. }
  198. }
  199. // 酒贰肺 茄其捞瘤 胶农费.
  200. else if ( m_rcScrlBtnRgn.top+m_wScrlBtnHeight/2 <= ptMouse.y )
  201. {
  202. m_fScrlRate += m_fPageRate;
  203. if ( m_fScrlRate > 1.0f )
  204. {
  205. m_fScrlRate = 1.0f;
  206. }
  207. }
  208. return TRUE;
  209. }
  210. return FALSE;
  211. }
  212. BOOL CScrlBar::OnLButtonUp(POINT ptMouse)
  213. {
  214. if ( m_bGrapsed )
  215. {
  216. m_bGrapsed = FALSE;
  217. return TRUE;
  218. }
  219. else
  220. return FALSE;
  221. }