panes.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "pch.h"
  2. /////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Gauge Pane
  5. //
  6. /////////////////////////////////////////////////////////////////////////////
  7. GaugePane::GaugePane(Surface* psurface,
  8. const Color& colorFlash,
  9. float minValue,
  10. float maxValue,
  11. const Color& colorEmpty)
  12. :
  13. m_psurface(psurface),
  14. m_colorFlash(colorFlash),
  15. m_colorEmpty(colorEmpty),
  16. m_minValue(minValue),
  17. m_maxValue(maxValue),
  18. m_value(0),
  19. m_valueOld(0),
  20. m_valueFlash(0),
  21. m_timeLastChange(Time::Now())
  22. {
  23. assert(m_psurface);
  24. assert(m_minValue < m_maxValue);
  25. InternalSetSize(m_psurface->GetRect().Size());
  26. }
  27. void GaugePane::Paint(Surface* psurface)
  28. {
  29. if (m_value != 0) {
  30. psurface->BitBlt(
  31. WinPoint(0, 0),
  32. m_psurface,
  33. WinRect(0, 0, m_value, YSize())
  34. );
  35. }
  36. if (m_value < m_valueFlash) {
  37. psurface->FillRect(
  38. WinRect(
  39. m_value,
  40. 0,
  41. m_valueFlash,
  42. YSize()
  43. ),
  44. m_colorFlash
  45. );
  46. }
  47. }
  48. void GaugePane::SetValue(float v, bool fFlash)
  49. {
  50. m_value =
  51. (int)bound(
  52. (v - m_minValue) * ((float)XSize()) / (m_maxValue - m_minValue),
  53. 0.0f,
  54. (float)XSize()
  55. );
  56. }
  57. void GaugePane::Update(Time time)
  58. {
  59. if (m_value != m_valueOld) {
  60. if (m_value < m_valueOld) {
  61. m_valueFlash = m_valueOld;
  62. } else {
  63. m_valueFlash = m_value;
  64. }
  65. m_timeLastChange = time;
  66. m_valueOld = m_value;
  67. NeedPaint();
  68. }
  69. if (m_value != m_valueFlash && time - m_timeLastChange > 0.25f) {
  70. m_valueFlash = m_value;
  71. NeedPaint();
  72. }
  73. }