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

游戏引擎

开发平台:

Visual C++

  1. // GraphSpin.cpp: implementation of the CGraphSpin class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "GraphSpin.h"
  6. //////////////////////////////////////////////////////////////////////
  7. // Construction/Destruction
  8. //////////////////////////////////////////////////////////////////////
  9. CGraphSpin::CGraphSpin()
  10. {
  11.     m_bHorz=true;
  12. }
  13. CGraphSpin::~CGraphSpin()
  14. {
  15. }
  16. void CGraphSpin::SetSpin(RECT rect,bool bFirst,bool bHorizontal)
  17. {
  18. CGraphButton::SetButtonRect(rect);
  19. m_bFirstSpin=bFirst;
  20. m_bHorz=bHorizontal;
  21. }
  22. void CGraphSpin::RenderSpin()
  23. {
  24. CGraphButton::UpdateButton();
  25. UpdateSpin();
  26. int width=m_rect.right-m_rect.left;
  27. int height=m_rect.bottom-m_rect.top;
  28. //////// draw spin
  29. glDisable(GL_TEXTURE_2D);
  30. /////// set color
  31. if(m_iState==BUTTON_NORMAL)glColor3f(0.0f,0.4f,0.0f);
  32. else if(m_iState==BUTTON_ACTIVATE)glColor3f(0,0.6f,0);
  33. else if(m_iState==BUTTON_PUSHED)glColor3f(0.6f,0.6f,0);
  34.     else glColor3f(0.35f,0.35f,0.35f);
  35. glBegin(GL_TRIANGLES);
  36.     if(m_bFirstSpin)
  37. {
  38. if(m_bHorz)
  39. {
  40.             glVertex3f(m_rect.left+width*0.1f-400 , 300-m_rect.top-height*0.5f , -520);
  41.             glVertex3f(m_rect.right-width*0.1f-400 , 300-m_rect.bottom+ height*0.1f, -520);
  42.             glVertex3f(m_rect.right-width*0.1f-400 , 300-m_rect.top- height*0.1f, -520);
  43. }
  44. else
  45. {
  46.             glVertex3f(m_rect.left+width*0.1f-400 , 300-m_rect.top-height*0.9f , -520);
  47.             glVertex3f(m_rect.right-width*0.1f-400 , 300-m_rect.bottom+ height*0.1f, -520);
  48.             glVertex3f(m_rect.left+width*0.5f-400 , 300-m_rect.top- height*0.1f, -520);
  49. }
  50. }else
  51. {
  52. if(m_bHorz)
  53. {
  54.             glVertex3f(m_rect.left+width*0.1f-400 , 300-m_rect.top-height*0.1f , -520);
  55.             glVertex3f(m_rect.left+width*0.1f-400 , 300-m_rect.bottom+ height*0.1f, -520);
  56.             glVertex3f(m_rect.right-width*0.1f-400 , 300-m_rect.top-height*0.5f, -520);
  57. }
  58. else
  59. {
  60.                 glVertex3f(m_rect.left+width*0.1f-400 , 300-m_rect.top-height*0.1f , -520);
  61.             glVertex3f(m_rect.left+width*0.5f-400 , 300-m_rect.bottom+ height*0.1f, -520);
  62.             glVertex3f(m_rect.right-width*0.1f-400 , 300-m_rect.top-height*0.1f, -520);
  63. }
  64. }
  65. glEnd();
  66. /////// set color
  67. if(m_iState==BUTTON_NORMAL)glColor3f(0.0f,0.6f,0.0f);
  68. else if(m_iState==BUTTON_ACTIVATE)glColor3f(0,1.0f,0);
  69. else if(m_iState==BUTTON_PUSHED)glColor3f(1,1.0f,0);
  70.     else glColor3f(0.6f,0.6f,0.6f);
  71. /////// draw rectangle
  72. glBegin(GL_LINE_LOOP);
  73.     glVertex3i(m_rect.left-400 , 300-m_rect.top , -520);
  74.     glVertex3i(m_rect.right-400 , 300-m_rect.top , -520);
  75.     glVertex3i(m_rect.right-400 , 300-m_rect.bottom ,-520);
  76.     glVertex3i(m_rect.left-400 , 300-m_rect.bottom , -520);
  77. glEnd();
  78. /////// draw triangle
  79. glBegin(GL_LINE_LOOP);
  80.     if(m_bFirstSpin)
  81. {
  82. if(m_bHorz)
  83. {
  84.             glVertex3f(m_rect.left+width*0.1f-400 , 300-m_rect.top-height*0.5f , -520);
  85.             glVertex3f(m_rect.right-width*0.1f-400 , 300-m_rect.bottom+ height*0.1f, -520);
  86.             glVertex3f(m_rect.right-width*0.1f-400 , 300-m_rect.top- height*0.1f, -520);
  87. }
  88. else
  89. {
  90.             glVertex3f(m_rect.left+width*0.1f-400 , 300-m_rect.top-height*0.9f , -520);
  91.             glVertex3f(m_rect.right-width*0.1f-400 , 300-m_rect.bottom+ height*0.1f, -520);
  92.             glVertex3f(m_rect.left+width*0.5f-400 , 300-m_rect.top- height*0.1f, -520);
  93. }
  94. }else
  95. {
  96. if(m_bHorz)
  97. {
  98.             glVertex3f(m_rect.left+width*0.1f-400 , 300-m_rect.top-height*0.1f , -520);
  99.             glVertex3f(m_rect.left+width*0.1f-400 , 300-m_rect.bottom+ height*0.1f, -520);
  100.             glVertex3f(m_rect.right-width*0.1f-400 , 300-m_rect.top-height*0.5f, -520);
  101. }
  102. else
  103. {
  104.                   glVertex3f(m_rect.left+width*0.1f-400 , 300-m_rect.top-height*0.1f , -520);
  105.             glVertex3f(m_rect.left+width*0.5f-400 , 300-m_rect.bottom+ height*0.1f, -520);
  106.             glVertex3f(m_rect.right-width*0.1f-400 , 300-m_rect.top-height*0.1f, -520);
  107. }
  108. }
  109. glEnd();
  110.     glColor3f(1,1,1);
  111. }
  112. void CGraphSpin::UpdateSpin()
  113. {
  114. if(m_iState==BUTTON_PUSHED)m_iPushedTime++;
  115. else m_iPushedTime=0;
  116.     if(m_iPushedTime==1 || m_iPushedTime>30 )m_bChangValue=true;
  117. else m_bChangValue=false;
  118. }