UIRing.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include "StdAfx.h"
  2. #include "UIRing.h"
  3. namespace DuiLib
  4. {
  5. IMPLEMENT_DUICONTROL(CRingUI)
  6. CRingUI::CRingUI() : m_fCurAngle(0.0f), m_pBkimage(NULL)
  7. {
  8. }
  9. CRingUI::~CRingUI()
  10. {
  11. if(m_pManager) m_pManager->KillTimer(this, RING_TIMERID);
  12. DeleteImage();
  13. }
  14. LPCTSTR CRingUI::GetClass() const
  15. {
  16. return _T("RingUI");
  17. }
  18. LPVOID CRingUI::GetInterface( LPCTSTR pstrName )
  19. {
  20. if( _tcscmp(pstrName, _T("Ring")) == 0 ) return static_cast<CRingUI*>(this);
  21. return CLabelUI::GetInterface(pstrName);
  22. }
  23. void CRingUI::SetAttribute( LPCTSTR pstrName, LPCTSTR pstrValue )
  24. {
  25. if( _tcscmp(pstrName, _T("bkimage")) == 0 ) SetBkImage(pstrValue);
  26. else CLabelUI::SetAttribute(pstrName, pstrValue);
  27. }
  28. void CRingUI::SetBkImage( LPCTSTR pStrImage )
  29. {
  30. if (m_sBkImage == pStrImage) return;
  31. m_sBkImage = pStrImage;
  32. DeleteImage();
  33. Invalidate();
  34. }
  35. void CRingUI::PaintBkImage( HDC hDC )
  36. {
  37. if(m_pBkimage == NULL) {
  38. InitImage();
  39. }
  40. if(m_pBkimage != NULL) {
  41. RECT rcItem = m_rcItem;
  42. int iWidth = rcItem.right - rcItem.left;
  43. int iHeight = rcItem.bottom - rcItem.top;
  44. Gdiplus::PointF centerPos(rcItem.left + iWidth/2, rcItem.top + iHeight/2);
  45. // 解决偶数时抖动问题
  46. if ((iWidth % 2) == 0) centerPos.X -= 0.5;
  47. if ((iHeight % 2) == 0) centerPos.Y -= 0.5;
  48. Gdiplus::Graphics graphics(hDC);
  49. graphics.TranslateTransform(centerPos.X,centerPos.Y);
  50. graphics.RotateTransform(m_fCurAngle);
  51. graphics.TranslateTransform(-centerPos.X, -centerPos.Y);//»¹Ô­Ô´µã
  52. graphics.DrawImage(m_pBkimage,rcItem.left,rcItem.top,iWidth,iHeight);
  53. }
  54. }
  55. void CRingUI::DoEvent( TEventUI& event )
  56. {
  57. if( event.Type == UIEVENT_TIMER && event.wParam == RING_TIMERID ) {
  58. if(m_fCurAngle > 359) {
  59. m_fCurAngle = 0;
  60. }
  61. m_fCurAngle += 36.0;
  62. //Invalidate();
  63. NeedParentUpdate();
  64. }
  65. else {
  66. CLabelUI::DoEvent(event);
  67. }
  68. }
  69. void CRingUI::InitImage()
  70. {
  71. TImageInfo* pImageInfo = CRenderEngine::GdiplusLoadImage(GetBkImage());
  72. if(pImageInfo == NULL) return;
  73. m_pBkimage = pImageInfo->pImage;
  74. if ( NULL == m_pBkimage ) return;
  75. if(m_pManager) m_pManager->SetTimer(this, RING_TIMERID, 100);
  76. }
  77. void CRingUI::DeleteImage()
  78. {
  79. if ( m_pBkimage != NULL )
  80. {
  81. delete m_pBkimage;
  82. m_pBkimage = NULL;
  83. }
  84. }
  85. }