예제 #1
0
void Timer::Reset(double seconds)
{
	m_duration = seconds;
	DOUBLE currentVal;
	m_pVariable->GetValue(&currentVal);

	if(currentVal == seconds)
		return;

	// Instant transition to 'seconds'
	CComPtr<IUIAnimationTransition> instant;
	CORt(g_manager->get_IUIAnimationTransitionLibrary()->CreateInstantaneousTransition(seconds, &instant));

	// Linear transition to zero
	CComPtr<IUIAnimationTransition> linear;
	if(seconds != 0.0)
	{
		CORt(g_manager->get_IUIAnimationTransitionLibrary()->CreateLinearTransition(seconds, 0.0, &linear));
	}

	// Build up storyboard
	CComPtr<IUIAnimationStoryboard> sb;
	CORt(g_manager->get_IUIAnimationManager()->CreateStoryboard(&sb));

	sb->AddTransition(m_pVariable, instant);
	if(linear)
		sb->AddTransition(m_pVariable, linear);

	UI_ANIMATION_SECONDS secondsNow;
	CORt(g_manager->get_IUIAnimationTimer()->GetTime(&secondsNow));
	CORt(sb->Schedule(secondsNow));

	g_manager->Update();
}
예제 #2
0
void CAnimatedAlphaWindow::AnimateSweepTo( double newSweep_I )
{
	// Create a storyboard
	CComPtr<IUIAnimationStoryboard> storyboard;
	ASSERT_SUCCEEDED(mAnimMgr->CreateStoryboard(&storyboard));

	// Create transitions
	CComPtr<IUIAnimationTransition> stopTransition;
	ASSERT_SUCCEEDED(mTransLib->CreateSmoothStopTransition(0.25,
		newSweep_I, &stopTransition));

	// Add the stopTransition
	ASSERT_SUCCEEDED(storyboard->AddTransition(mSweepVar, stopTransition));

	// Schedule the storyboard to animate now
	UI_ANIMATION_SECONDS timeNow;
	ASSERT_SUCCEEDED(mAnimTimer->GetTime(&timeNow));
	ASSERT_SUCCEEDED(storyboard->Schedule(timeNow));
}
예제 #3
0
void CAnimatedAlphaWindow::OnLButtonUp( UINT nFlags, CPoint point )
{
	// Create a storyboard
	CComPtr<IUIAnimationStoryboard> storyboard;
	ASSERT_SUCCEEDED(mAnimMgr->CreateStoryboard(&storyboard));

	// Create transitions
	CComPtr<IUIAnimationTransition> stopTransition;
	//ATLTRACE("Animating to %.0f\n", mNextAlphaValue);
	ASSERT_SUCCEEDED(mTransLib->CreateSmoothStopTransition(0.5,
		mNextAlphaValue, &stopTransition));
	mNextAlphaValue = (mNextAlphaValue == LARGE ? SMALL : LARGE);

	// Add the stopTransition
	ASSERT_SUCCEEDED(storyboard->AddTransition(mAlphaVar, stopTransition));

	// Schedule the storyboard to animate now
	UI_ANIMATION_SECONDS timeNow;
	ASSERT_SUCCEEDED(mAnimTimer->GetTime(&timeNow));
	ASSERT_SUCCEEDED(storyboard->Schedule(timeNow));
}
//-------------------------------------------------------------------------------
// Use WAM to generate and propagate the appropriate animation curves to DirectComposition when 
// keypress is detected
//-------------------------------------------------------------------------------
HRESULT CApplication::CreateSlideAnimation(DIRECTION dir, IDCompositionAnimation **slideAnimation)
{    
    HRESULT hr = (slideAnimation == nullptr) ? E_POINTER : S_OK;

    float rightMargin = 27 * TILE_SPACING * -1;  //where the tiles end. Note forward direction is represented by a negative value.
    float leftMargin = 0; // where the tiles begin

    if (SUCCEEDED(hr))
    {
        *slideAnimation = nullptr;
        hr = ((_device == nullptr) || (_animationVariable == nullptr)) ? E_UNEXPECTED : S_OK;
    }

    //WAM propagates curves to DirectComposition using the IDCompositionAnimation object
    CComPtr<IDCompositionAnimation> animation;

    if (SUCCEEDED(hr))
    {
        hr = _device->CreateAnimation(&animation);
    }

    //Create a storyboard for the slide animation
    CComPtr<IUIAnimationStoryboard2> storyboard;

    if (SUCCEEDED(hr))
    {
        hr = _manager->CreateStoryboard(&storyboard);
    }

    // Synchronizing WAM and DirectComposition time such that when WAM Update is called, 
    // the value reflects the DirectComposition value at the given time.
    DCOMPOSITION_FRAME_STATISTICS frameStatistics = { 0 };

    if (SUCCEEDED(hr))
    {
        hr = _device->GetFrameStatistics(&frameStatistics);
    }

    UI_ANIMATION_SECONDS nextEstimatedFrameTime = 0.0;

    if (SUCCEEDED(hr))
    {
        nextEstimatedFrameTime = static_cast<double>(frameStatistics.nextEstimatedFrameTime.QuadPart) / static_cast<double>(frameStatistics.timeFrequency.QuadPart);
    }

    //Upating the WAM time 
    if (SUCCEEDED(hr))
    {
        hr = _manager->Update(nextEstimatedFrameTime);
    }

    CComPtr<IUIAnimationTransition2> transition;
    double curValue = 0;    //current value of the animation variable
    int velocity = 500;     //arbitrary fix velocity for the slide animation
    
    if (SUCCEEDED(hr))
    {
        hr = _animationVariable->GetValue(&curValue);

        switch (dir)
        {
            case stopForward:
            case stopBackward:
                // Stopping the animation smoothly when key is let go
                if (curValue != leftMargin && curValue != rightMargin)
                    hr = _transitionLibrary->CreateSmoothStopTransition(0.5, curValue + dir * 50, &transition);
                break;
            case forward:
                // slide the tiles forward using a linear curve upon left button press
                hr = _transitionLibrary->CreateLinearTransition(-1 * (rightMargin - curValue)/velocity, rightMargin, &transition);
                break;
            case backward:
                // slide the tiles backward using a linear cruve upon right button press
                hr = _transitionLibrary->CreateLinearTransition(-1 * curValue/velocity, leftMargin, &transition);
                break;
         }
    }

    //Add above transition to storyboard
    if (SUCCEEDED(hr))
    {
        hr = storyboard->AddTransition(_animationVariable, transition);
    }

    //schedule the storyboard for play at the next estimate vblank
    if (SUCCEEDED(hr))
    {
        hr = storyboard->Schedule(nextEstimatedFrameTime);
    }

    //Giving WAM varialbe the IDCompositionAnimation object to recieve the animation curves
    if (SUCCEEDED(hr))
    {
        hr = _animationVariable->GetCurve(animation);
    }

    if (SUCCEEDED(hr))
    {
        *slideAnimation = animation.Detach();
    }

    return hr;
}