UIProgress.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #include "stdafx.h"
  2. #include "UIProgress.h"
  3. namespace DuiLib
  4. {
  5. CProgressUI::CProgressUI() : m_bHorizontal(true), m_nMin(0), m_nMax(100), m_nValue(0)
  6. {
  7. m_uTextStyle = DT_SINGLELINE | DT_CENTER;
  8. SetFixedHeight(12);
  9. }
  10. LPCTSTR CProgressUI::GetClass() const
  11. {
  12. return _T("ProgressUI");
  13. }
  14. LPVOID CProgressUI::GetInterface(LPCTSTR pstrName)
  15. {
  16. if( _tcscmp(pstrName, DUI_CTR_PROGRESS) == 0 ) return static_cast<CProgressUI*>(this);
  17. return CLabelUI::GetInterface(pstrName);
  18. }
  19. bool CProgressUI::IsHorizontal()
  20. {
  21. return m_bHorizontal;
  22. }
  23. void CProgressUI::SetHorizontal(bool bHorizontal)
  24. {
  25. if( m_bHorizontal == bHorizontal ) return;
  26. m_bHorizontal = bHorizontal;
  27. Invalidate();
  28. }
  29. int CProgressUI::GetMinValue() const
  30. {
  31. return m_nMin;
  32. }
  33. void CProgressUI::SetMinValue(int nMin)
  34. {
  35. m_nMin = nMin;
  36. Invalidate();
  37. }
  38. int CProgressUI::GetMaxValue() const
  39. {
  40. return m_nMax;
  41. }
  42. void CProgressUI::SetMaxValue(int nMax)
  43. {
  44. m_nMax = nMax;
  45. Invalidate();
  46. }
  47. int CProgressUI::GetValue() const
  48. {
  49. return m_nValue;
  50. }
  51. void CProgressUI::SetValue(int nValue)
  52. {
  53. m_nValue = nValue;
  54. Invalidate();
  55. }
  56. LPCTSTR CProgressUI::GetForeImage() const
  57. {
  58. return m_diFore.sDrawString;
  59. }
  60. void CProgressUI::SetForeImage(LPCTSTR pStrImage)
  61. {
  62. if( m_diFore.sDrawString == pStrImage && m_diFore.pImageInfo != NULL ) return;
  63. m_diFore.Clear();
  64. m_diFore.sDrawString = pStrImage;
  65. Invalidate();
  66. }
  67. void CProgressUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
  68. {
  69. if( _tcscmp(pstrName, _T("foreimage")) == 0 ) SetForeImage(pstrValue);
  70. else if( _tcscmp(pstrName, _T("hor")) == 0 ) SetHorizontal(_tcscmp(pstrValue, _T("true")) == 0);
  71. else if( _tcscmp(pstrName, _T("min")) == 0 ) SetMinValue(_ttoi(pstrValue));
  72. else if( _tcscmp(pstrName, _T("max")) == 0 ) SetMaxValue(_ttoi(pstrValue));
  73. else if( _tcscmp(pstrName, _T("value")) == 0 ) SetValue(_ttoi(pstrValue));
  74. else CLabelUI::SetAttribute(pstrName, pstrValue);
  75. }
  76. void CProgressUI::PaintStatusImage(HDC hDC)
  77. {
  78. if( m_nMax <= m_nMin ) m_nMax = m_nMin + 1;
  79. if( m_nValue > m_nMax ) m_nValue = m_nMax;
  80. if( m_nValue < m_nMin ) m_nValue = m_nMin;
  81. RECT rc = {0};
  82. if( m_bHorizontal ) {
  83. rc.right = (m_nValue - m_nMin) * (m_rcItem.right - m_rcItem.left) / (m_nMax - m_nMin);
  84. rc.bottom = m_rcItem.bottom - m_rcItem.top;
  85. }
  86. else {
  87. rc.top = (m_rcItem.bottom - m_rcItem.top) * (m_nMax - m_nValue) / (m_nMax - m_nMin);
  88. rc.right = m_rcItem.right - m_rcItem.left;
  89. rc.bottom = m_rcItem.bottom - m_rcItem.top;
  90. }
  91. m_diFore.rcDestOffset = rc;
  92. if( DrawImage(hDC, m_diFore) ) return;
  93. }
  94. }