Read the Animation Variable Values

Each time your application paints, it should read the current values of the animation variables that represent the visual characteristics to be animated.

Overview

When drawing a frame, an application can use the IUIAnimationVariable::GetValue or IUIAnimationVariable::GetIntegerValue method to request the values of any animation variables that will affect visuals within the frame. It is possible to clip an animation variable to a range of values (SetLowerBound and SetUpperBound), and to request its value be rounded to an integer using a specified rounding scheme (SetRoundingMode).

Instead of reading the values of all variables for every frame, an application can use the IUIAnimationVariable::SetVariableChangeHandler or IUIAnimationVariable::SetVariableIntegerChangeHandler method to register one or more variable change handlers to receive notifications only when there is a change to the variables' value (IUIAnimationVariableChangeHandler::OnValueChanged) or rounded value (IUIAnimationVariableIntegerChangeHandler::OnIntegerValueChanged). To identify the variables passed to variable change handlers, an application can apply tags to variables using the IUIAnimationVariable::SetTag method. These are object (IUnknown*), integer pairs that are interpreted by the application.

Example Code

The following example code is taken from Thumbnail.cpp in the Windows Animation sample Grid Layout; see the CMainWindow::Render method. It uses the GetValue method to read the values as floating-point values.

// Get the x-coordinate and y-coordinate animation variable values

DOUBLE x=0;
hr = m_pAnimationVariableX->GetValue(&x);
if (SUCCEEDED(hr))
{
    DOUBLE y=0;
    hr = m_pAnimationVariableY->GetValue(&y);
    if (SUCCEEDED(hr))
    {
        // Draw the object

        ...

    }
}

The following example code is taken from MainWindow.cpp in the Windows Animation sample Timer-Driven Animation; see the CMainWindow::DrawBackground method. It uses the GetIntegerValue method to read the values as integer values.

// Get the RGB animation variable values

INT32 red;
HRESULT hr = m_pAnimationVariableRed->GetIntegerValue(
    &red
    );
if (SUCCEEDED(hr))
{
    INT32 green;
    hr = m_pAnimationVariableGreen->GetIntegerValue(
        &green
        );
    if (SUCCEEDED(hr))
    {
        INT32 blue;
        hr = m_pAnimationVariableBlue->GetIntegerValue(
            &blue
            );
        if (SUCCEEDED(hr))
        {
            // Set the RGB of the background brush to the new animated value

            ...
                
            // Paint the background

            ...

        }
    }

    ...

}

Previous Step

Before starting this step, you should have completed this step: Update the Animation Manager and Draw Frames.

Next Step

After completing this step, the next step is: Create a Storyboard and Add Transitions.

IUIAnimationVariable::GetIntegerValue

IUIAnimationVariable::GetValue

Windows Animation Overview