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 CMainWindow::ChangeColor( DOUBLE red, DOUBLE green, DOUBLE blue ) { const UI_ANIMATION_SECONDS DURATION = 0.5; const DOUBLE ACCELERATION_RATIO = 0.5; const DOUBLE DECELERATION_RATIO = 0.5; // Create a storyboard IUIAnimationStoryboard *pStoryboard = NULL; HRESULT hr = m_pAnimationManager->CreateStoryboard( &pStoryboard ); if (SUCCEEDED(hr)) { // Create transitions for the RGB animation variables IUIAnimationTransition *pTransitionRed; hr = m_pTransitionLibrary->CreateAccelerateDecelerateTransition( DURATION, red, ACCELERATION_RATIO, DECELERATION_RATIO, &pTransitionRed ); if (SUCCEEDED(hr)) { IUIAnimationTransition *pTransitionGreen; hr = m_pTransitionLibrary->CreateAccelerateDecelerateTransition( DURATION, green, ACCELERATION_RATIO, DECELERATION_RATIO, &pTransitionGreen ); if (SUCCEEDED(hr)) { IUIAnimationTransition *pTransitionBlue; hr = m_pTransitionLibrary->CreateAccelerateDecelerateTransition( DURATION, blue, ACCELERATION_RATIO, DECELERATION_RATIO, &pTransitionBlue ); if (SUCCEEDED(hr)) { // Add transitions to the storyboard hr = pStoryboard->AddTransition( m_pAnimationVariableRed, pTransitionRed ); if (SUCCEEDED(hr)) { hr = pStoryboard->AddTransition( m_pAnimationVariableGreen, pTransitionGreen ); if (SUCCEEDED(hr)) { hr = pStoryboard->AddTransition( m_pAnimationVariableBlue, pTransitionBlue ); if (SUCCEEDED(hr)) { // Get the current time and schedule the storyboard for play UI_ANIMATION_SECONDS secondsNow; hr = m_pAnimationTimer->GetTime( &secondsNow ); if (SUCCEEDED(hr)) { hr = pStoryboard->Schedule( secondsNow ); } } } } pTransitionBlue->Release(); } pTransitionGreen->Release(); } pTransitionRed->Release(); } pStoryboard->Release(); } return hr; }
// Animates the angle HRESULT FirstTry::AcceleratingRotation() { //const UI_ANIMATION_SECONDS DURATION = 2; //const UI_ANIMATION_SECONDS PERIOD = 8; //const DOUBLE miniValue = -720; //const DOUBLE maxiValue = 720; const DOUBLE finalValue = 360; const DOUBLE finalVelocity = 720; const DOUBLE acceleration = 720; const DOUBLE speed = 720; const DOUBLE finalValue1 = 7200000; // Create a storyboard IUIAnimationStoryboard *pStoryboard = NULL; HRESULT hr = m_pAnimationManager->CreateStoryboard(&pStoryboard); // Create transition for the angle if (SUCCEEDED(hr)) { IUIAnimationTransition *pTransitionRPMAccelerating; hr = m_pTransitionLibrary->CreateParabolicTransitionFromAcceleration( finalValue, finalVelocity, acceleration, &pTransitionRPMAccelerating); if (SUCCEEDED(hr)) { IUIAnimationTransition *pTransitionRPMHolding; hr = m_pTransitionLibrary->CreateLinearTransitionFromSpeed( speed, finalValue1, &pTransitionRPMHolding); if (SUCCEEDED(hr)) { // Add the transition to the stroyboard. hr = pStoryboard->AddTransition(m_pAnimationVarAngle, pTransitionRPMAccelerating); if (SUCCEEDED(hr)) { hr = pStoryboard->AddTransition(m_pAnimationVarAngle, pTransitionRPMHolding); if (SUCCEEDED(hr)) { // Get the current time and schedule the storyboard for play UI_ANIMATION_SECONDS secondsNow; hr = m_pAnimationTimer->GetTime(&secondsNow); if (SUCCEEDED(hr)) hr = pStoryboard->Schedule(secondsNow); } pTransitionRPMHolding->Release(); } pTransitionRPMAccelerating->Release(); } } pStoryboard->Release(); } return hr; }