All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
kanzi::FromToAnimation< TValueType, TEasingFunction > Class Template Reference

Template class for from-to animations. More...

#include <kanzi/animation/from_to_animation.hpp>

Inheritance diagram for kanzi::FromToAnimation< TValueType, TEasingFunction >:
kanzi::ValueAnimation< TValueType > kanzi::AbstractAnimation kanzi::Object

Public Member Functions

optional< TValueType > getFrom () const
 
void setFrom (optional< TValueType > from)
 
bool hasFrom () const
 
optional< TValueType > getTo () const
 
void setTo (optional< TValueType > to)
 
bool hasTo () const
 
void setDuration (chrono::milliseconds duration)
 
TEasingFunction getEasingFunction () const
 
void setEasingFunction (TEasingFunction easingFunction)
 
void setEasingMode (AnimationEasingMode mode)
 
AnimationEasingMode getEasingMode () const
 
virtual TValueType getValue (const TValueType &currentValue, chrono::milliseconds time) KZ_OVERRIDE
 Returns new animated value given current value and time. More...
 
- Public Member Functions inherited from kanzi::AbstractAnimation
virtual ~AbstractAnimation ()
 Destructor. More...
 
optional< chrono::milliseconds > getDuration ()
 Returns the duration of the animation. More...
 
- Public Member Functions inherited from kanzi::Object
 Object (Domain *domain)
 
virtual ~Object ()
 
DomaingetDomain () const
 Returns the domain the object belongs to. More...
 
KzuPropertyManager * getPropertyManager () const
 Returns the property manager of the object. More...
 
KzuTaskSchedulergetTaskScheduler () const
 Returns the task scheduler of the object. More...
 
KzuMessageDispatchergetMessageDispatcher () const
 Returns the message dispatcher of the object. More...
 
ResourceManagergetResourceManager () const
 Returns the resource manager of the object. More...
 
virtual const MetaclassgetDynamicMetaclass () const
 Returns the metaclass of the dynamic type of the object. More...
 
bool isTypeOf (const Metaclass *objectType) const
 Determines if the type of this object is the given type or derived from it. More...
 
template<typename DataType >
void setProperty (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::DataType value)
 Sets the local value of a property. More...
 
void setProperty (const PropertyType< ResourceID > &propertyType, ResourceSharedPtr value)
 Sets the local value of a resource id property with a resource pointer. More...
 
template<typename DataType >
DataType getProperty (const PropertyType< DataType > &propertyType) const
 Returns the current value of a property. More...
 
template<typename DataType >
bool getProperty (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::DataType &value) const
 Evaluates the property value in the same way as the overload above but does not default to the value in property metadata if there are no inputs to the property value. More...
 
template<typename DataType >
void setAbstractProperty (AbstractPropertyType abstractPropertyType, typename PropertyType< DataType >::DataType value)
 
void setAbstractProperty (AbstractPropertyType abstractPropertyType, ResourceSharedPtr value)
 
template<typename DataType >
DataType getAbstractProperty (AbstractPropertyType abstractPropertyType) const
 
template<typename DataType >
bool getAbstractProperty (AbstractPropertyType abstractPropertyType, typename PropertyType< DataType >::DataType &value) const
 
bool hasValue (AbstractPropertyType propertyType) const
 Evaluates whether there are any inputs into the property value. More...
 
bool hasLocalValue (AbstractPropertyType propertyType) const
 Evaluates whether there is a local value set for the property. More...
 
void removeLocalValue (AbstractPropertyType propertyType)
 Removes the local value associated with the property. More...
 
void copyLocalValues (const Object &other)
 Copies all local values from another object. More...
 
virtual void onPropertyChanged (AbstractPropertyType propertyType, KzuPropertyNotificationReason reason)
 Virtual function to handle property change notifications. More...
 
AppliedStyleEntryapplyObjectStyle (kanzi::StyleSharedPtr style)
 Applies a style to an object. More...
 
void unapplyObjectStyle (AppliedStyleEntry *appliedStyleEntry)
 
void applyObjectStyles ()
 Apply all styles for an object node. More...
 
void unapplyObjectStyles ()
 Unapplies and removes all applied styles. More...
 

Static Public Member Functions

static
PropertyTypeEditorInfoSharedPtr 
makeEditorInfo ()
 
static shared_ptr
< FromToAnimation
create (Domain *domain, chrono::milliseconds duration, optional< TValueType > from, optional< TValueType > to)
 
- Static Public Member Functions inherited from kanzi::Object
static const MetaclassgetStaticMetaclass ()
 Returns the metaclass of Object class. More...
 
static
PropertyTypeEditorInfoSharedPtr 
makeEditorInfo ()
 Default implementation that returns empty editor info. More...
 

Protected Member Functions

 FromToAnimation (Domain *domain, chrono::milliseconds duration, optional< TValueType > from, optional< TValueType > to)
 Constructor. More...
 
virtual optional
< chrono::milliseconds > 
getDurationOverride () KZ_OVERRIDE
 Virtual function the derived classes should overload to return duration. More...
 
float easeTime (float normalizedTime) const
 
- Protected Member Functions inherited from kanzi::ValueAnimation< TValueType >
 ValueAnimation (Domain *domain)
 Constructor. More...
 
- Protected Member Functions inherited from kanzi::AbstractAnimation
 AbstractAnimation (Domain *domain)
 Constructor. More...
 
- Protected Member Functions inherited from kanzi::Object
void initialize ()
 
void onCopy (const Object &other)
 

Additional Inherited Members

- Protected Types inherited from kanzi::Object
typedef vector
< AppliedStyleEntry * > 
AppliedStyleContainer
 Applied style container. More...
 
- Protected Attributes inherited from kanzi::Object
AppliedStyleContainer m_appliedStyles
 Listing of applied styles applied to this object. More...
 

Detailed Description

template<typename TValueType, typename TEasingFunction>
class kanzi::FromToAnimation< TValueType, TEasingFunction >

Template class for from-to animations.

Template Parameters
TValueTypeDefines the type of the value you want to animate. For example, float, bool, int, ColorRGBA.
TEasingFunctiondefines the type of the easing function used for the animation. For example, LinearEasingFunction, SmoothStepEasingFunction, BackEasingFunction. For a full list of easing functions see easing_curve.hpp

The Kanzi animation system consists animations and timelines: animations define how to animate a property, and timelines map the animations to time and to objects you want to animate.

From-to animation defines from which to which value to change the value of a property. You can omit either of these values to animate either from the current value or to the current value of the property.

From-to animations use an easing curve that defines the rate of change for the animation. You can use one of the easing curves that comes with Kanzi, or define your own. With the easing mode you can control how the easing function is applied to the animation:

  • Ease in easing mode applies to the transition the easing function as it is.
  • Ease out easing mode applies to the transition the negative value of the easing function.
  • Ease in-out easing mode applies to the first half of the transition the easing function as it is, and to the second half of the transition the negative value of the easing function.

Examples

To create a from-to animation:

// Create a from-to animation that uses the linear easing function and is two seconds long.
// As a starting value, the animation takes the current value of the property in the node you want to animate.
// The animation sets the final value of the property in the node you animate to 200.
// You set which node this animation animates in the timeline.
FloatLinearFromToAnimationSharedPtr linearAnimation = FloatLinearFromToAnimation::create(domain, chrono::seconds(2), nullopt, 200.0f);

To animate a property value in a node using a from-to animation:

// Create a property timeline and apply the linearAnimation from-to animation to the Layout Width property
// to animate the width of the current node.

To animate a property field value in a node using a from-to animation:

// Create a property field animation timeline and apply it to the Render Transformation property of the current node.
// Scale the current node on the x axis by animating the Scale X property field of the Render Transformation property
// with the linearAnimation from-to animation.
propertyFieldTimeline->addEntry(PropertyFieldScaleX, linearAnimation);

To create a float from-to animation that uses the back easing curve and the ease out easing mode:

// Define the FloatBackFromToAnimation to use float values and Back easing function.
typedef FromToAnimation<float, BackEasingFunction> FloatBackFromToAnimation;
typedef shared_ptr<FloatBackFromToAnimation> FloatBackFromToAnimationSharedPtr;
// Create a from-to animation that uses the back easing function and is 5000 milliseconds long.
// The animation sets the starting value of the property in the node you want to animate to 100,
// and the final value of that property to 300.
FloatBackFromToAnimationSharedPtr backAnimation = FloatBackFromToAnimation::create(domain, chrono::milliseconds(5000), nullopt, 300.0f);
// Set the easing mode of the backAnimation from-to animation to Ease out.
backAnimation->setEasingMode(AnimationEaseOut);

To play an animation regardless of the timeline type:

// Create the playback context and the timeline playback for the node defined in the item2d.
ScenegraphTimelinePlaybackContext context(*item2d);
// Create the playback for the timeline defined in the propertyFieldTimeline.
TimelinePlaybackSharedPtr playback = propertyFieldTimeline->createPlayback(context);
// Start the animation.
domain->getRootTimelineClock()->addTimelinePlayback(playback);

Constructor & Destructor Documentation

template<typename TValueType , typename TEasingFunction >
kanzi::FromToAnimation< TValueType, TEasingFunction >::FromToAnimation ( Domain domain,
chrono::milliseconds  duration,
optional< TValueType >  from,
optional< TValueType >  to 
)
inlineexplicitprotected

Constructor.

Member Function Documentation

template<typename TValueType , typename TEasingFunction >
static PropertyTypeEditorInfoSharedPtr kanzi::FromToAnimation< TValueType, TEasingFunction >::makeEditorInfo ( )
inlinestatic
template<typename TValueType , typename TEasingFunction >
static shared_ptr<FromToAnimation> kanzi::FromToAnimation< TValueType, TEasingFunction >::create ( Domain domain,
chrono::milliseconds  duration,
optional< TValueType >  from,
optional< TValueType >  to 
)
inlinestatic
template<typename TValueType , typename TEasingFunction >
optional<TValueType> kanzi::FromToAnimation< TValueType, TEasingFunction >::getFrom ( ) const
inline
template<typename TValueType , typename TEasingFunction >
void kanzi::FromToAnimation< TValueType, TEasingFunction >::setFrom ( optional< TValueType >  from)
inline
template<typename TValueType , typename TEasingFunction >
bool kanzi::FromToAnimation< TValueType, TEasingFunction >::hasFrom ( ) const
inline
template<typename TValueType , typename TEasingFunction >
optional<TValueType> kanzi::FromToAnimation< TValueType, TEasingFunction >::getTo ( ) const
inline
template<typename TValueType , typename TEasingFunction >
void kanzi::FromToAnimation< TValueType, TEasingFunction >::setTo ( optional< TValueType >  to)
inline
template<typename TValueType , typename TEasingFunction >
bool kanzi::FromToAnimation< TValueType, TEasingFunction >::hasTo ( ) const
inline
template<typename TValueType , typename TEasingFunction >
void kanzi::FromToAnimation< TValueType, TEasingFunction >::setDuration ( chrono::milliseconds  duration)
inline
template<typename TValueType , typename TEasingFunction >
TEasingFunction kanzi::FromToAnimation< TValueType, TEasingFunction >::getEasingFunction ( ) const
inline
template<typename TValueType , typename TEasingFunction >
void kanzi::FromToAnimation< TValueType, TEasingFunction >::setEasingFunction ( TEasingFunction  easingFunction)
inline
template<typename TValueType , typename TEasingFunction >
void kanzi::FromToAnimation< TValueType, TEasingFunction >::setEasingMode ( AnimationEasingMode  mode)
inline
template<typename TValueType , typename TEasingFunction >
AnimationEasingMode kanzi::FromToAnimation< TValueType, TEasingFunction >::getEasingMode ( ) const
inline
template<typename TValueType , typename TEasingFunction >
virtual TValueType kanzi::FromToAnimation< TValueType, TEasingFunction >::getValue ( const TValueType &  currentValue,
chrono::milliseconds  time 
)
inlinevirtual

Returns new animated value given current value and time.

Classes derived from ValueAnimation define data and algorithms to calculate the value returned by this function.

Parameters
currentValueCurrent value that is used as basis for animation calculations.

Implements kanzi::ValueAnimation< TValueType >.

template<typename TValueType , typename TEasingFunction >
virtual optional<chrono::milliseconds> kanzi::FromToAnimation< TValueType, TEasingFunction >::getDurationOverride ( )
inlineprotectedvirtual

Virtual function the derived classes should overload to return duration.

Default implementation returns nullopt to indicate infinite animation.

Reimplemented from kanzi::AbstractAnimation.

template<typename TValueType , typename TEasingFunction >
float kanzi::FromToAnimation< TValueType, TEasingFunction >::easeTime ( float  normalizedTime) const
inlineprotected

The documentation for this class was generated from the following file: