Clone of Akilla's ac2d @ https://github.com/deregtd/AC2D

cProgressBar.h 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #pragma once
  2. #include "WindowLib/cWindow.h"
  3. class cProgressBar : public CWindow, private IRenderEvent {
  4. public:
  5. cProgressBar()
  6. {
  7. m_fMin = 0;
  8. m_fMax = 1;
  9. m_fCurrent = 0.5f;
  10. m_dwColor = 0xFFFFFF;
  11. AddRenderEventHandler( *this );
  12. }
  13. private:
  14. bool OnRender( IWindow & Window, double TimeSlice )
  15. {
  16. float iLeft = GetAbsoluteLeft(),
  17. iRight = iLeft + GetWidth(),
  18. iTop = GetAbsoluteTop(),
  19. iBottom = iTop + GetHeight();
  20. glBindTexture(GL_TEXTURE_2D, 0);
  21. glBegin(GL_QUADS);
  22. glColor3ub((BYTE) (m_dwColor),(BYTE) (m_dwColor >> 8),(BYTE) (m_dwColor >> 16));
  23. glVertex2f(iLeft,iTop);
  24. glVertex2f(iLeft+(GetWidth()*((m_fCurrent - m_fMin)/(m_fMax - m_fMin))),iTop);
  25. glVertex2f(iLeft+(GetWidth()*((m_fCurrent - m_fMin)/(m_fMax - m_fMin))),iBottom);
  26. glVertex2f(iLeft,iBottom);
  27. glEnd();
  28. glBegin(GL_LINE_LOOP);
  29. glColor3f(0.5,0.5,0.5);
  30. glVertex2f(iLeft,iTop);
  31. glVertex2f(iRight,iTop);
  32. glVertex2f(iRight,iBottom);
  33. glVertex2f(iLeft,iBottom);
  34. glEnd();
  35. return true;
  36. }
  37. public:
  38. void SetColor(DWORD dwColor)
  39. {
  40. m_dwColor = dwColor;
  41. }
  42. void SetLimits(float fMin, float fMax)
  43. {
  44. m_fMin = fMin;
  45. m_fMax = fMax;
  46. }
  47. void SetCurrent(float fCurrent)
  48. {
  49. m_fCurrent = fCurrent;
  50. }
  51. private:
  52. float m_fMin, m_fMax, m_fCurrent;
  53. DWORD m_dwColor;
  54. };