コード例 #1
0
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;
}
コード例 #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
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;
}
コード例 #4
0
    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;
    }
コード例 #5
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;
}
コード例 #6
0
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;
}