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

游戏引擎

开发平台:

Visual C++

  1. // CtrlSetBox.cpp: implementation of the CCtrlSetBox class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "CtrlSetBox.h"
  6. #include "gamesetting.h"
  7. //////////////////////////////////////////////////////////////////////
  8. // Construction/Destruction
  9. //////////////////////////////////////////////////////////////////////
  10. CCtrlSetBox::CCtrlSetBox()
  11. {
  12. }
  13. CCtrlSetBox::~CCtrlSetBox()
  14. {
  15. }
  16. void CCtrlSetBox::SetCtrlSetBox(RECT rect)
  17. {
  18. int width=rect.right-rect.left;
  19. int height=rect.bottom-rect.top;
  20. int itemH=30;
  21. m_numShow=height/itemH;
  22. rect.bottom=rect.top+ m_numShow*itemH;
  23. m_rectBox=rect;
  24.     
  25.   ////////// scroll bar   
  26. if((CTRL_ITEM-m_numShow)>0)
  27. {
  28. m_bShowScroll=true;
  29.      rect.left=rect.right-22; // 25 is scrollbar's width
  30.      m_cScrollBar.SetScrollBar(rect,false,CTRL_ITEM-m_numShow,0);
  31.      m_cScrollBar.SetBlockWidth(16);
  32. }
  33. else
  34. {
  35.         m_numShow=CTRL_ITEM;
  36. m_bShowScroll=false;
  37. }
  38. m_iHead=0;
  39. ////////// edit item
  40.     rect.left=m_rectBox.left+int(width*0.45f);
  41.     rect.right=m_rectBox.left+int(width*0.75f);
  42.     rect.top=m_rectBox.top+5;
  43. rect.bottom=rect.top+20;
  44. CGameSetting cGSet;
  45. m_cEdit[0].SetKeyValueEdit(rect,cGSet.m_iKeyForward);
  46. m_cEdit[1].SetKeyValueEdit(rect,cGSet.m_iKeyBackward);
  47.   m_cEdit[2].SetKeyValueEdit(rect,cGSet.m_iKeyLeft);
  48.   m_cEdit[3].SetKeyValueEdit(rect,cGSet.m_iKeyRight);
  49. m_cEdit[4].SetKeyValueEdit(rect,cGSet.m_iKeyFire);
  50. m_cEdit[5].SetKeyValueEdit(rect,cGSet.m_iKeyJump);
  51. m_cEdit[6].SetKeyValueEdit(rect,cGSet.m_iKeyZoom);
  52. m_cEdit[7].SetKeyValueEdit(rect,cGSet.m_iKeyHelp);
  53.   m_cEdit[8].SetKeyValueEdit(rect,cGSet.m_iKeyDrawFPS);
  54. m_cEdit[9].SetKeyValueEdit(rect,cGSet.m_iKeyMute);
  55.     /////////// m_sTitle[CTRL_ITEM][46]
  56. strcpy(m_sTitle[0],"Forward");
  57. strcpy(m_sTitle[1],"Backward");
  58. strcpy(m_sTitle[2],"Left");
  59. strcpy(m_sTitle[3],"Right");
  60. strcpy(m_sTitle[4],"Fire");
  61. strcpy(m_sTitle[5],"Jump");
  62. strcpy(m_sTitle[6],"Zoom");
  63. strcpy(m_sTitle[7],"Help");
  64. strcpy(m_sTitle[8],"Draw FPS");
  65. strcpy(m_sTitle[9],"Mute");
  66. }
  67. void CCtrlSetBox::RenderCtrlSetBox()
  68. {
  69. UpdateCtrlSetBox();
  70.     if(m_bShowScroll)
  71. {
  72. m_cScrollBar.RenderScrollBar();
  73. }
  74. int itemH=30;
  75. RECT rect=m_rectBox;
  76. rect.left=m_rectBox.left+int((m_rectBox.right-m_rectBox.left)*0.50f);
  77.     rect.right=m_rectBox.left+int((m_rectBox.right-m_rectBox.left)*0.85f);
  78. rect.top=m_rectBox.top+5; 
  79.     rect.bottom=rect.top+20;
  80. for(int i=0;i<m_numShow;i++)
  81. {
  82. m_cEdit[m_iHead+i].SetButtonRect(rect);
  83.         m_cEdit[m_iHead+i].RenderKeyValueEdit();
  84. glColor3f(0,1,0);
  85. CImgText::PrintString(m_rectBox.left+35,rect.top,m_sTitle[m_iHead+i]);
  86.         rect.top += itemH;
  87. rect.bottom=rect.top +20;
  88. }
  89. //////////////////////////background
  90. /////// draw rectangle
  91. glBegin(GL_LINE_LOOP);
  92.     glVertex3i(m_rectBox.left-400 , 300-m_rectBox.top , -520);
  93.     glVertex3i(m_rectBox.right-400 , 300-m_rectBox.top , -520);
  94.     glVertex3i(m_rectBox.right-400 , 300-m_rectBox.bottom ,-520);
  95.     glVertex3i(m_rectBox.left-400 , 300-m_rectBox.bottom , -520);
  96. glEnd();
  97. }
  98. void CCtrlSetBox::UpdateCtrlSetBox()
  99. {
  100. ///////avoid share key
  101.     for(int i=0;i<CTRL_ITEM;i++)
  102. {
  103. if(m_cEdit[i].IsValueChanged())
  104. {
  105. int value=m_cEdit[i].GetKeyValue();
  106. for(int k=0;k<CTRL_ITEM;k++)
  107. {
  108. if(k!=i && value==m_cEdit[k].GetKeyValue() )
  109. m_cEdit[k].SetKeyValue(0);
  110. }
  111. }
  112. }
  113. //////////////////////////////
  114.     if(!m_bShowScroll)return;
  115. m_iHead=m_cScrollBar.GetValue();
  116. }
  117. void  CCtrlSetBox::LoadSetting()
  118. {
  119. CGameSetting cGSet;
  120. m_cEdit[0].SetKeyValue(cGSet.m_iKeyForward);
  121. m_cEdit[1].SetKeyValue(cGSet.m_iKeyBackward);
  122.   m_cEdit[2].SetKeyValue(cGSet.m_iKeyLeft);
  123.   m_cEdit[3].SetKeyValue(cGSet.m_iKeyRight);
  124. m_cEdit[4].SetKeyValue(cGSet.m_iKeyFire);
  125. m_cEdit[5].SetKeyValue(cGSet.m_iKeyJump);
  126. m_cEdit[6].SetKeyValue(cGSet.m_iKeyZoom);
  127. m_cEdit[7].SetKeyValue(cGSet.m_iKeyHelp);
  128.   m_cEdit[8].SetKeyValue(cGSet.m_iKeyDrawFPS);
  129. m_cEdit[9].SetKeyValue(cGSet.m_iKeyMute);
  130. }
  131. void  CCtrlSetBox::SaveSetting()
  132. {
  133. CGameSetting cGSet;
  134. cGSet.m_iKeyForward=m_cEdit[0].GetKeyValue();
  135. cGSet.m_iKeyBackward=m_cEdit[1].GetKeyValue();
  136.   cGSet.m_iKeyLeft=m_cEdit[2].GetKeyValue();
  137.   cGSet.m_iKeyRight=m_cEdit[3].GetKeyValue();
  138. cGSet.m_iKeyFire=m_cEdit[4].GetKeyValue();
  139. cGSet.m_iKeyJump=m_cEdit[5].GetKeyValue();
  140. cGSet.m_iKeyZoom=m_cEdit[6].GetKeyValue();
  141. cGSet.m_iKeyHelp=m_cEdit[7].GetKeyValue();
  142.   cGSet.m_iKeyDrawFPS=m_cEdit[8].GetKeyValue();
  143. cGSet.m_iKeyMute=m_cEdit[9].GetKeyValue();
  144. }