1
0

skinnedprogressbar.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #include "api__gen_ml.h"
  2. #include "main.h"
  3. #include "./skinnedprogressbar.h"
  4. #include "./skinning.h"
  5. #include "../winamp/wa_dlg.h"
  6. #include "./colors.h"
  7. #include <strsafe.h>
  8. SkinnedProgressBar::SkinnedProgressBar(void)
  9. : SkinnedWnd(FALSE), skinCursor(NULL)
  10. {
  11. }
  12. SkinnedProgressBar::~SkinnedProgressBar(void)
  13. {
  14. }
  15. BOOL SkinnedProgressBar::Attach(HWND hProgressBar)
  16. {
  17. if(!__super::Attach(hProgressBar)) return FALSE;
  18. SetType(SKINNEDWND_TYPE_PROGRESSBAR);
  19. return TRUE;
  20. }
  21. void SkinnedProgressBar::OnSkinChanged(BOOL bNotifyChildren, BOOL bRedraw)
  22. {
  23. skinCursor = (0 != (SWS_USESKINCURSORS & style)) ?
  24. (HCURSOR)SENDWAIPC(plugin.hwndParent, IPC_GETSKINCURSORS, WACURSOR_NORMAL) : NULL;
  25. HFONT hfOld = (HFONT)CallPrevWndProc(WM_GETFONT, 0, 0L);
  26. __super::OnSkinChanged(bNotifyChildren, bRedraw);
  27. if (hfOld != (HFONT)CallPrevWndProc(WM_GETFONT, 0, 0L))
  28. CallPrevWndProc(TTM_UPDATE, 0, 0L);
  29. }
  30. void SkinnedProgressBar::OnPaint()
  31. {
  32. PAINTSTRUCT ps;
  33. HDC hdc = BeginPaint(hwnd, &ps);
  34. if (NULL == hdc) return;
  35. int radius = (ps.rcPaint.bottom - ps.rcPaint.top - WASABI_API_APP->getScaleY(1)) / WASABI_API_APP->getScaleY(2);
  36. int radius2 = WASABI_API_APP->getScaleY(5);
  37. RECT r;
  38. CopyRect(&r, &ps.rcPaint);
  39. // fill the background accordingly
  40. FillRect(hdc, &r, (HBRUSH)MlStockObjects_Get(WNDBCK_BRUSH));
  41. r.right -= WASABI_API_APP->getScaleX(1);
  42. r.bottom -= WASABI_API_APP->getScaleY(1);
  43. OffsetRect(&r, 1, 1);
  44. HPEN oldPen = SelectPen(hdc, MlStockObjects_Get(HILITE_PEN));
  45. HBRUSH oldBrush = SelectBrush(hdc, MlStockObjects_Get(WNDBCK_BRUSH));
  46. // draw the border edge offset to add a 'shadow'
  47. RoundRect(hdc, r.left, r.top, r.right, r.bottom, radius2, radius);
  48. ps.rcPaint.bottom -= WASABI_API_APP->getScaleY(1);
  49. SelectObject(hdc, MlStockObjects_Get(ITEMBCK_PEN));
  50. SelectObject(hdc, MlStockObjects_Get(ITEMBCK_BRUSH));
  51. // draw the 'empty' part of the bar with a slight overlap of the 'shadow'
  52. RoundRect(hdc, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom, radius2, radius);
  53. int pos = (DWORD)CallPrevWndProc(PBM_GETPOS, 0, 0L);
  54. if (pos > 0)
  55. {
  56. int range = (DWORD)CallPrevWndProc(PBM_GETRANGE, 0, 0L);
  57. int val = (((ps.rcPaint.right) * pos) / range);
  58. if (val > 0)
  59. {
  60. if ((ps.rcPaint.left + val + radius) > ps.rcPaint.right)
  61. {
  62. SelectObject(hdc, MlStockObjects_Get(ITEMTEXT_PEN));
  63. SelectObject(hdc, MlStockObjects_Get(ITEMTEXT_BRUSH));
  64. // draws the 'filled' part of the bar with a slight overlap of the 'shadow'
  65. RoundRect(hdc, ps.rcPaint.left - WASABI_API_APP->getScaleX(10), ps.rcPaint.top,
  66. val + (radius * WASABI_API_APP->getScaleY(2)) - WASABI_API_APP->getScaleY(10), ps.rcPaint.bottom, radius2, radius);
  67. }
  68. else
  69. {
  70. ps.rcPaint.right = ps.rcPaint.left + val;
  71. FillRect(hdc, &ps.rcPaint, (HBRUSH)MlStockObjects_Get(ITEMTEXT_BRUSH));
  72. }
  73. }
  74. // not keen on this at all but it sorts out the progress overlap
  75. SelectObject(hdc, MlStockObjects_Get(WNDBCK_PEN));
  76. MoveToEx(hdc, ps.rcPaint.left, ps.rcPaint.bottom, NULL);
  77. LineTo(hdc, ps.rcPaint.left + ((radius)/ 2), ps.rcPaint.bottom);
  78. LineTo(hdc, ps.rcPaint.left, ps.rcPaint.bottom - ((radius)/ WASABI_API_APP->getScaleY(2)));
  79. LineTo(hdc, ps.rcPaint.left, ps.rcPaint.bottom);
  80. MoveToEx(hdc, ps.rcPaint.left, ps.rcPaint.top, NULL);
  81. LineTo(hdc, ps.rcPaint.left, ps.rcPaint.top + ((radius)/ WASABI_API_APP->getScaleY(2)));
  82. MoveToEx(hdc, ps.rcPaint.left, ps.rcPaint.top, NULL);
  83. LineTo(hdc, ps.rcPaint.left + ((radius)/ WASABI_API_APP->getScaleY(2)), ps.rcPaint.top);
  84. }
  85. SelectPen(hdc, oldPen);
  86. SelectBrush(hdc, oldBrush);
  87. }
  88. UINT SkinnedProgressBar::GetBorderType(void)
  89. {
  90. return BORDER_NONE;
  91. }
  92. LRESULT SkinnedProgressBar::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  93. {
  94. switch(uMsg)
  95. {
  96. case WM_PAINT:
  97. OnPaint();
  98. return 0;
  99. case WM_SETCURSOR:
  100. if (NULL != skinCursor)
  101. {
  102. if (skinCursor != GetCursor())
  103. SetCursor(skinCursor);
  104. return TRUE;
  105. }
  106. break;
  107. }
  108. return __super::WindowProc(uMsg, wParam, lParam);
  109. }