コード例 #1
0
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;
}
コード例 #2
0
HRESULT CLayoutManager::Arrange(
    D2D1_SIZE_F sizeClient
    )
{
    DOUBLE widthRow = 0.0;
    DOUBLE yRow = PADDING;
    DOUBLE heightMax = 0.0;
    int iRowFirst = 0;

    // Create storyboard for all the thumbnail transitions    

    IUIAnimationStoryboard *pStoryboard;
    HRESULT hr = m_pAnimationManager->CreateStoryboard(
        &pStoryboard
        );
    if (SUCCEEDED(hr))
    {
        // Arrange the thumbnails into rows, adding transitions to move
        // each thumbnail to its new location once it is known
    
        for (UINT i = 0; i < m_uThumbCount; i++)
        {    
            D2D1_SIZE_F size = m_thumbs[i].GetSize();
            
            if ((PADDING + widthRow + size.width + PADDING > sizeClient.width) && (i > 0))
            {
                // This thumbnail won't fit on this row - arrange the current row and start a new one

                hr = ArrangeRow(
                    pStoryboard,
                    iRowFirst,
                    i, 
                    0.5 * (sizeClient.width - (widthRow - PADDING)),
                    yRow,
                    heightMax
                    );
                if (FAILED(hr))
                {
                    break;
                }
                
                iRowFirst = i;
                widthRow = 0.0;
                yRow += heightMax + PADDING;
                heightMax = 0.0;
            }
            
            if (heightMax < size.height)
            {
                heightMax = size.height;
            }

            widthRow += PADDING + size.width;
        }
        
        if (SUCCEEDED(hr))
        {
            // Arrange the last row

            hr = ArrangeRow(
                pStoryboard,
                iRowFirst,
                m_uThumbCount,
                0.5 * (sizeClient.width - (widthRow - PADDING)),
                yRow,
                heightMax
                );
            if (SUCCEEDED(hr))
            {
                // Get the current time and schedule the storyboard for play

                UI_ANIMATION_SECONDS timeNow;
                hr = m_pAnimationTimer->GetTime(
                    &timeNow
                    );
                if (SUCCEEDED(hr))
                {
                     hr = pStoryboard->Schedule(
                        timeNow
                        );
                }
            }
        }

        pStoryboard->Release();
    }

    return hr;
}
コード例 #3
0
// 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;
}