GraphEdit.cpp
上传用户:hkb425
上传日期:2007-06-16
资源大小:34191k
文件大小:3k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. // GraphEdit.cpp: implementation of the CGraphEdit class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "GraphEdit.h"
  6. #include "gamesetting.h"
  7. //////////////////////////////////////////////////////////////////////
  8. // Construction/Destruction
  9. //////////////////////////////////////////////////////////////////////
  10. CGraphEdit::CGraphEdit()
  11. {
  12. m_bEditting=false;
  13. m_bEnableEdit=true;
  14. m_bHeightLight=false;
  15. }
  16. CGraphEdit::~CGraphEdit()
  17. {
  18. }
  19. void CGraphEdit::SetEdit(RECT rect,char *sText,int iMaxChar)
  20. {
  21. if(iMaxChar>31)iMaxChar=31;
  22. int len=strlen(sText);
  23. if(len>iMaxChar)
  24.     sText[iMaxChar]=NULL;
  25. CGraphButton::SetButton(rect,sText);
  26. m_iMaxChar=iMaxChar;
  27. }
  28. void CGraphEdit::RenderEdit()
  29. UpdateEdit();
  30. CGraphButton::RenderButton();
  31. }
  32. void CGraphEdit::UpdateEdit()
  33. {
  34. if(!m_bEnableEdit)return;
  35. static int flicker=0;
  36. flicker++;
  37. if(flicker>50)flicker=0;
  38. char cCursor[1];
  39. if(flicker<25)wsprintf(cCursor," ");
  40. else wsprintf(cCursor,"_");
  41. m_cInput.m_bAskTrans=true;
  42.     if(m_bSelected)
  43. {
  44. m_bSelected=false;
  45. int len=strlen(m_sText);
  46. if(len<m_iMaxChar)
  47.     strcat(m_sText, cCursor);
  48. else
  49. m_sText[m_iMaxChar-1]=cCursor[0];
  50. m_bEditting=true;
  51. m_cInput.m_bShowMouse=false;
  52. }
  53. if(m_bEditting)
  54. {
  55. //////////flicker
  56.         int len=strlen(m_sText);
  57. m_sText[len-1]=cCursor[0];
  58. //////////// mouse cling
  59. SetCursorPos((m_rect.left+m_rect.right)/2,(m_rect.top+m_rect.bottom)/2);
  60. if(m_cInput.m_keys[MOUSE_0] ||m_cInput.m_keys[13]) // enter 
  61. {
  62. m_cInput.m_keys[MOUSE_0]=false;
  63. m_cInput.m_keys[13]=false;
  64.             FinishEdit();
  65. return;
  66. }
  67.         if(m_cInput.m_keys[8])// BackSpace
  68. {
  69. m_cInput.m_keys[8]=false;
  70. if(len>1)
  71. {
  72. m_sText[len-2]=cCursor[0];
  73. m_sText[len-1]=NULL;
  74. }
  75. return;
  76. }
  77. /*
  78. for(int i=0;i<5;i++) // up down left right
  79. {
  80. if(m_cInput.m_keys[i])m_cInput.m_keys[i]=false;
  81. return;
  82. }*/
  83. for(int i=32;i<128;i++)
  84. {
  85. if(m_cInput.m_keys[i])
  86. {
  87. m_cInput.m_keys[i]=false;
  88. char a=i;
  89. int len=strlen(m_sText);
  90. m_sText[len-1]=a;
  91. strcat(m_sText, cCursor);
  92. len++;
  93. if((len)>m_iMaxChar)
  94. {
  95.                     FinishEdit();
  96. return;
  97. }
  98. }
  99. }
  100. }
  101. }
  102. void  CGraphEdit::SetEnableEdit(bool bEnableEdit)
  103. {
  104.     m_bEnableEdit=bEnableEdit;
  105. }
  106. void  CGraphEdit::SetHeightLight(bool bHLight)
  107. {
  108. m_bHeightLight=bHLight;
  109. }
  110. void  CGraphEdit::Clear()
  111. {
  112. CGraphButton::SetButtonText("");
  113. m_bEnableEdit=true;
  114. }
  115. void  CGraphEdit::SetText(char *sText)
  116. {
  117. CGraphButton::SetButtonText(sText);
  118. }
  119. void  CGraphEdit::GetFocus()
  120. {
  121.     SetCursorPos((m_rect.left+m_rect.right)/2,(m_rect.top+m_rect.bottom)/2);
  122. m_bSelected=true;
  123. m_bEnableEdit=true;
  124. }
  125. bool  CGraphEdit::IsEditting()
  126. {
  127. return m_bEditting;
  128. }
  129. void CGraphEdit::FinishEdit()
  130. {
  131. m_bEditting=false;
  132. m_cInput.m_bShowMouse=true;
  133.     SetCursorPos((m_rect.left+m_rect.right)/2,m_rect.bottom+5);
  134. int len=strlen(m_sText);
  135.     m_sText[len-1]=NULL;
  136. if(m_sText[0]!=NULL)m_bEnableEdit=false;
  137. }