UIAnimationTabLayout.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #include "StdAfx.h"
  2. #include "UIAnimationTabLayout.h"
  3. namespace DuiLib {
  4. IMPLEMENT_DUICONTROL(CAnimationTabLayoutUI)
  5. CAnimationTabLayoutUI::CAnimationTabLayoutUI() :
  6. m_bIsVerticalDirection( false ),
  7. m_nPositiveDirection( 1 ),
  8. m_pCurrentControl( NULL ),
  9. m_bControlVisibleFlag( false )
  10. {
  11. Attach(this);
  12. }
  13. LPCTSTR CAnimationTabLayoutUI::GetClass() const
  14. {
  15. return _T("AnimationTabLayoutUI");
  16. }
  17. LPVOID CAnimationTabLayoutUI::GetInterface(LPCTSTR pstrName)
  18. {
  19. if( _tcsicmp(pstrName, _T("AnimationTabLayout")) == 0 )
  20. return static_cast<CAnimationTabLayoutUI*>(this);
  21. return CTabLayoutUI::GetInterface(pstrName);
  22. }
  23. bool CAnimationTabLayoutUI::SelectItem( int iIndex )
  24. {
  25. if( iIndex < 0 || iIndex >= m_items.GetSize() ) return false;
  26. if( iIndex == m_iCurSel ) return true;
  27. if( iIndex > m_iCurSel ) m_nPositiveDirection = -1;
  28. if( iIndex < m_iCurSel ) m_nPositiveDirection = 1;
  29. int iOldSel = m_iCurSel;
  30. m_iCurSel = iIndex;
  31. for( int it = 0; it < m_items.GetSize(); it++ ) {
  32. if( it == iIndex ) {
  33. GetItemAt(it)->SetVisible(true);
  34. GetItemAt(it)->SetFocus();
  35. m_bControlVisibleFlag = false;
  36. m_pCurrentControl = static_cast<CControlUI*>(m_items[it]);
  37. }
  38. else GetItemAt(it)->SetVisible(false);
  39. }
  40. NeedParentUpdate();
  41. if( NULL != m_pCurrentControl ) m_pCurrentControl->SetVisible( false );
  42. AnimationSwitch();
  43. if( m_pManager != NULL ) {
  44. m_pManager->SetNextTabControl();
  45. m_pManager->SendNotify(this, _T("tabselect"), m_iCurSel, iOldSel);
  46. }
  47. return true;
  48. }
  49. void CAnimationTabLayoutUI::AnimationSwitch()
  50. {
  51. m_rcItemOld = m_rcItem;
  52. if( !m_bIsVerticalDirection )
  53. {
  54. m_rcCurPos.top = m_rcItem.top;
  55. m_rcCurPos.bottom = m_rcItem.bottom;
  56. m_rcCurPos.left = m_rcItem.left - ( m_rcItem.right - m_rcItem.left ) * m_nPositiveDirection + 52 * m_nPositiveDirection;
  57. m_rcCurPos.right = m_rcItem.right - ( m_rcItem.right - m_rcItem.left ) * m_nPositiveDirection+ 52 * m_nPositiveDirection;
  58. }
  59. else
  60. {
  61. m_rcCurPos.left = m_rcItem.left;
  62. m_rcCurPos.right = m_rcItem.right;
  63. m_rcCurPos.top = m_rcItem.top - ( m_rcItem.bottom - m_rcItem.top ) * m_nPositiveDirection;
  64. m_rcCurPos.bottom = m_rcItem.bottom - ( m_rcItem.bottom - m_rcItem.top ) * m_nPositiveDirection;
  65. }
  66. StopAnimation( TAB_ANIMATION_ID );
  67. StartAnimation( TAB_ANIMATION_ELLAPSE, TAB_ANIMATION_FRAME_COUNT, TAB_ANIMATION_ID );
  68. }
  69. void CAnimationTabLayoutUI::DoEvent(TEventUI& event)
  70. {
  71. if( event.Type == UIEVENT_TIMER )
  72. {
  73. OnTimer( event.wParam );
  74. }
  75. __super::DoEvent( event );
  76. }
  77. void CAnimationTabLayoutUI::OnTimer( int nTimerID )
  78. {
  79. OnAnimationElapse( nTimerID );
  80. }
  81. void CAnimationTabLayoutUI::OnAnimationStep(INT nTotalFrame, INT nCurFrame, INT nAnimationID)
  82. {
  83. if( !m_bControlVisibleFlag ) {
  84. m_bControlVisibleFlag = true;
  85. m_pCurrentControl->SetVisible( true );
  86. }
  87. int iStepLen = 0;
  88. if( !m_bIsVerticalDirection )
  89. {
  90. iStepLen = ( m_rcItemOld.right - m_rcItemOld.left ) * m_nPositiveDirection / nTotalFrame;
  91. if( nCurFrame != nTotalFrame )
  92. {
  93. m_rcCurPos.left = m_rcCurPos.left + iStepLen;
  94. m_rcCurPos.right = m_rcCurPos.right +iStepLen;
  95. }
  96. else
  97. {
  98. m_rcItem = m_rcCurPos = m_rcItemOld;
  99. }
  100. }
  101. else
  102. {
  103. iStepLen = ( m_rcItemOld.bottom - m_rcItemOld.top ) * m_nPositiveDirection / nTotalFrame;
  104. if( nCurFrame != nTotalFrame )
  105. {
  106. m_rcCurPos.top = m_rcCurPos.top + iStepLen;
  107. m_rcCurPos.bottom = m_rcCurPos.bottom +iStepLen;
  108. }
  109. else
  110. {
  111. m_rcItem = m_rcCurPos = m_rcItemOld;
  112. }
  113. }
  114. SetPos(m_rcCurPos);
  115. }
  116. void CAnimationTabLayoutUI::OnAnimationStop(INT nAnimationID)
  117. {
  118. SetPos(m_rcItemOld);
  119. NeedParentUpdate();
  120. }
  121. void CAnimationTabLayoutUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
  122. {
  123. if( _tcsicmp(pstrName, _T("animation_direction")) == 0 && _tcsicmp( pstrValue, _T("vertical")) == 0 ) m_bIsVerticalDirection = true; // pstrValue = "vertical" or "horizontal"
  124. return CTabLayoutUI::SetAttribute(pstrName, pstrValue);
  125. }
  126. } // namespace DuiLib