HRESULT CLayoutManager::Attract( DOUBLE finalYValue ) { const DOUBLE ACCELERATION = 2500.0; // Create storyboard for all the thumbnail transitions IUIAnimationStoryboard *pStoryboard; HRESULT hr = m_pAnimationManager->CreateStoryboard( &pStoryboard ); if (SUCCEEDED(hr)) { // Add transitions to move each thumbnail to the final y value for (UINT i = 0; i < m_uThumbCount; i++) { // Compute an offset to align the thumbnail's edge with the final value, // rather than its center D2D1_SIZE_F size = m_thumbs[i].GetSize(); DOUBLE offset = (finalYValue > 0.0 ? -1.0 : 1.0) * size.height * 0.5; IUIAnimationTransition *pTransition; hr = CAttractInterpolator::CreateTransition( m_pTransitionFactory, finalYValue + offset, ACCELERATION, &pTransition ); if (SUCCEEDED(hr)) { hr = pStoryboard->AddTransition( m_thumbs[i].m_pAnimationVariableY, pTransition ); pTransition->Release(); } if (FAILED(hr)) { break; } } if (SUCCEEDED(hr)) { hr = ScheduleStoryboard(pStoryboard); } pStoryboard->Release(); } return hr; }
HRESULT CUiAnimationIconLayout::Arrange( const CSize & sz, int iModal ) { if(iModal >= (int)m_arrCharBits.GetCount()) return E_NOTIMPL; if(iModal <0) iModal = m_iModal; if(iModal <0) iModal = 0; IUIAnimationStoryboard *pStoryboard; HRESULT hr = m_pAnimationManager->CreateStoryboard( &pStoryboard ); if (SUCCEEDED(hr)) { // Arrange the thumbnails, adding transitions to move each thumbnail to a random new location POINT *pts = new POINT[m_nIcons]; GetIconsPos(iModal,pts); SIZE szModel = m_arrCharBits[iModal]->sz; CSize szClient = sz-m_plstIcon[0].GetSize(); double fScale=1.0; if(szModel.cx * szClient.cy > szModel.cy* szClient.cx) { fScale = szClient.cx*1.0/szModel.cx; }else { fScale = szClient.cy*1.0/szModel.cy; } int xOffset=0, yOffset=0; int nWid=(int)(szModel.cx*fScale); int nHei=(int)(szModel.cy*fScale); xOffset = (szClient.cx-nWid)/2; yOffset = (szClient.cy-nHei)/2; for (int i = 0; i < m_nIcons; i++) { CSize sizeIcon = m_plstIcon[i].GetSize(); DOUBLE xDest, yDest; xDest = xOffset + pts[i].x * fScale; yDest = yOffset + pts[i].y * fScale; // Get the current position // Note that this technique is valid only when the storyboard will begin playing immediately DOUBLE xCur; hr = m_plstIcon[i].m_pAnimationVariableX->GetValue(&xCur); if (SUCCEEDED(hr)) { DOUBLE yCur; hr = m_plstIcon[i].m_pAnimationVariableY->GetValue(&yCur); if (SUCCEEDED(hr)) { // Add transitions for x and y movement if (fabs(xDest - xCur) > fabs(yDest - yCur)) { // If the thumbnail has further to travel horizontally than vertically, use a parabolic transition // on X that will determine the duration of the storyboard, and stretch an accelerate-decelerate // transition on Y to have the same duration. hr = AddIconTransitions( pStoryboard, m_plstIcon[i].m_pAnimationVariableX, xDest, m_plstIcon[i].m_pAnimationVariableY, yDest ); } else { // If the thumbnail has further to travel vertically than horizontally, use a parabolic transition // on Y that will determine the duration of the storyboard, and stretch an accelerate-decelerate // transition on X to have the same duration. hr = AddIconTransitions( pStoryboard, m_plstIcon[i].m_pAnimationVariableY, yDest, m_plstIcon[i].m_pAnimationVariableX, xDest ); } } } if (FAILED(hr)) { break; } } if (SUCCEEDED(hr)) { hr = ScheduleStoryboard(pStoryboard); } delete []pts; pStoryboard->Release(); m_iModal = iModal; } return hr; }
HRESULT CLayoutManager::Arrange( D2D1_SIZE_F sizeClient ) { // Create storyboard for all the thumbnail transitions IUIAnimationStoryboard *pStoryboard; HRESULT hr = m_pAnimationManager->CreateStoryboard( &pStoryboard ); if (SUCCEEDED(hr)) { // Arrange the thumbnails, adding transitions to move each thumbnail to a random new location for (UINT i = 0; i < m_uThumbCount; i++) { D2D1_SIZE_F size = m_thumbs[i].GetSize(); DOUBLE xDest = RandomFromRange( size.width * 0.5, sizeClient.width - size.width * 0.5 ); DOUBLE yDest = RandomFromRange( sizeClient.height * 0.25 + size.height * 0.5, sizeClient.height * 0.75 - size.height * 0.5 ); // Get the current position // Note that this technique is valid only when the storyboard will begin playing immediately DOUBLE xCur; hr = m_thumbs[i].m_pAnimationVariableX->GetValue(&xCur); if (SUCCEEDED(hr)) { DOUBLE yCur; hr = m_thumbs[i].m_pAnimationVariableY->GetValue(&yCur); if (SUCCEEDED(hr)) { // Add transitions for x and y movement if (fabs(xDest - xCur) > fabs(yDest - yCur)) { // If the thumbnail has further to travel horizontally than vertically, use a parabolic transition // on X that will determine the duration of the storyboard, and stretch an accelerate-decelerate // transition on Y to have the same duration. hr = AddThumbnailTransitions( pStoryboard, m_thumbs[i].m_pAnimationVariableX, xDest, m_thumbs[i].m_pAnimationVariableY, yDest ); } else { // If the thumbnail has further to travel vertically than horizontally, use a parabolic transition // on Y that will determine the duration of the storyboard, and stretch an accelerate-decelerate // transition on X to have the same duration. hr = AddThumbnailTransitions( pStoryboard, m_thumbs[i].m_pAnimationVariableY, yDest, m_thumbs[i].m_pAnimationVariableX, xDest ); } } } if (FAILED(hr)) { break; } } if (SUCCEEDED(hr)) { hr = ScheduleStoryboard(pStoryboard); } pStoryboard->Release(); } return hr; }