VSTGUI  4.10
Graphical User Interface Framework not only for VST plugins
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Animations

VSTGUI version 4 adds simple to use view animation support.

The source can be found under /lib/animation/

The Animator

Every CFrame object can have one Animator object which runs animations at 60 Hz.

The animator is responsible for running animations. You can add and remove animations. Animations are identified by a view and a name.

To add an animation you just call CView::addAnimation (name, target, timing). The animation will start immediately and will automatically be removed if it has finished. If you want to stop it before it has finished you can use CView::removeAnimation (name). You can also stop all animations for a view with CView::removeAllAnimations ().

The animator is the owner of the target and timing function objects and will destroy these objects when the animation has finished. This means that the animator will call delete on these objects or if they are inherited from CBaseObject it will call forget() on them.

The Animation

An animation is made up by an IAnimationTarget and an ITimingFunction object.

The Animation Target

The animation target is responsible for changing the view from one state to another state.

The animation target interface consists of 3 methods:

All these methods have the view and the animation name as arguments to identify the animation within the target. The animationTick method in addition has the normalized animation position as argument and the animationFinished method has a bool argument indicating if the animation was canceled.

see included animation target classes

The Animation Timing Function

the animation timing function maps elapsed time to a normalized position.

see included animation timing function classes

Simple Usage Example

In this example the custom view animates it's alpha value when the mouse moves inside or outside the view.

using namespace VSTGUI::Animation;
class MyView : public CView
{
public:
MyView (const CRect& r) : CView (r) { setAlphaValue (0.5f); }
CMouseEventResult onMouseEntered (CPoint &where, const CButtonState& buttons)
{
// this adds an animation which takes 200 ms to make a linear alpha fade from the current value to 1
addAnimation ("AlphaValueAnimation", new AlphaValueAnimation (1.f), new LinearTimingFunction (200));
}
CMouseEventResult onMouseExited (CPoint &where, const CButtonState& buttons)
{
// this adds an animation which takes 200 ms to make a linear alpha fade from the current value to 0.5
addAnimation ("AlphaValueAnimation", new AlphaValueAnimation (0.5f), new LinearTimingFunction (200));
}
void draw (CDrawContext* context)
{
// ... any drawing code here
}
};