//////////////////////////////////////////////////////////////////////////////////////////////////// // NoesisGUI - http://www.noesisengine.com // Copyright (c) 2013 Noesis Technologies S.L. All Rights Reserved. //////////////////////////////////////////////////////////////////////////////////////////////////// #ifndef __GUI_TIMELINE_H__ #define __GUI_TIMELINE_H__ #include #include #include #include #include #include #include #include namespace Noesis { class TimeSpan; class RepeatBehavior; class Clock; class FrameworkElement; class TimeManager; template class Nullable; //////////////////////////////////////////////////////////////////////////////////////////////////// /// Specifies how a Timeline behaves when it is outside its active period but its parent is /// inside its active or hold period //////////////////////////////////////////////////////////////////////////////////////////////////// enum FillBehavior { /// After it reaches the end of its active period, the timeline holds its progress until the /// end of its parent's active and hold periods FillBehavior_HoldEnd, /// The timeline stops if it is outside its active period while its parent is inside its /// active period FillBehavior_Stop }; //////////////////////////////////////////////////////////////////////////////////////////////////// /// Arguments to be passed in timeline Complete event //////////////////////////////////////////////////////////////////////////////////////////////////// struct TimelineEventArgs: public EventArgs { DependencyObject* target; TimelineEventArgs(DependencyObject* t = 0): target(t) { } }; typedef Delegate TimelineEventHandler; NS_WARNING_PUSH NS_MSVC_WARNING_DISABLE(4251 4275) //////////////////////////////////////////////////////////////////////////////////////////////////// /// Defines a segment of time. /// /// A timeline represents a segment of time. It provides properties that enable you to specify the /// length of that segment, when it should start, how many times it will repeat, how fast time /// progresses in that segment, and more. /// /// http://msdn.microsoft.com/en-us/library/system.windows.media.animation.timeline.aspx //////////////////////////////////////////////////////////////////////////////////////////////////// class NS_GUI_ANIMATION_API Timeline: public Animatable { public: Timeline(); Timeline(const Nullable& beginTime); Timeline(const Nullable& beginTime, const Duration& duration); Timeline(const Nullable& beginTime, const Duration& duration, const RepeatBehavior& repeatBehavior); virtual ~Timeline() = 0; /// Gets or sets the desired frame rate for this timeline and its child timelines //@{ static int GetDesiredFrameRate(const DependencyObject* timeline); static void SetDesiredFrameRate(DependencyObject* timeline, int rate); //@} /// Gets or sets a value specifying the percentage of the timeline's Duration spent /// accelerating the passage of time from zero to its maximum rate //@{ float GetAccelerationRatio() const; void SetAccelerationRatio(float value); //@} /// Gets or sets a value that indicates whether the timeline plays in reverse after it /// completes a forward iteration //@{ bool GetAutoReverse() const; void SetAutoReverse(bool value); //@} /// Gets or sets the time at which this Timeline should begin. /// A timeline's own *SpeedRatio* setting does not affect its BeginTime. For example, a /// timeline with a *BeginTime* of 5 seconds, a *SpeedRatio* of 2, and a parent timeline /// with a *SpeedRatio* of 1 starts after 5 seconds, not 2.5. //@{ const Nullable& GetBeginTime() const; void SetBeginTime(const Nullable& time); //@} /// Gets or sets a value specifying the percentage of the timeline's Duration spent /// decelerating the passage of time from its maximum rate to zero //@{ float GetDecelerationRatio() const; void SetDecelerationRatio(float value); //@} /// Gets or sets the length of time for which this timeline plays, not counting repetitions //@{ const Duration& GetDuration() const; void SetDuration(const Duration& duration); //@} /// Gets or sets a value that specifies how the animation behaves after it reaches the end of /// its active period //@{ FillBehavior GetFillBehavior() const; void SetFillBehavior(FillBehavior behavior); //@} /// Gets or sets the name of this Timeline //@{ const char* GetName() const; void SetName(const char* name); //@} /// Gets or sets the repeating behavior of this timeline //@{ const RepeatBehavior& GetRepeatBehavior() const; void SetRepeatBehavior(const RepeatBehavior& behavior); //@} /// Gets or sets the rate, relative to its parent, at which time progresses for this Timeline //@{ float GetSpeedRatio() const; void SetSpeedRatio(float value); //@} /// Occurs when the Storyboard object has completed playing DelegateEvent_ Completed(); /// Creates a new Clock from this Timeline and specifies whether the new Clock is controllable. /// If this Timeline has children, a tree of clocks is created with this Timeline as the root. Ptr CreateClock(TimeManager* timeManager, bool hasControllableRoot); /// Gets the duration of the timeline when duration is set to automatic virtual Duration GetNaturalDuration(Clock* clock) const; /// Gets duration of a single pass (without the reverse) const Duration& GetSinglePassDuration() const; /// Gets duration of a complete pass (with the reverse, if applicable) const Duration& GetIterationDuration() const; /// Gets total duration of the animation (with repetitions and autoreverse, but without /// BeginTime nor SpeedRatio) const Duration& GetTotalDuration() const; /// Indicates that the total duration is not affected by SpeedRatio bool IsTotalDurationAbsolute() const; const Duration& GetNormalizedDuration() const; /// Computes the effective durations of the timeline void CalculateEffectiveDurations(); /// Calculated as TotalDuration / SpeedRatio + BeginTime virtual Duration GetEffectiveDuration() const = 0; // Called when an owner clock is being destroyed virtual void OnClockDestroyed(const Clock* clock); // Hides Freezable methods for convenience //@{ Ptr Clone() const; Ptr CloneCurrentValue() const; //@} public: /// Dependency properties //@{ static const DependencyProperty* AccelerationRatioProperty; static const DependencyProperty* AutoReverseProperty; static const DependencyProperty* BeginTimeProperty; static const DependencyProperty* DecelerationRatioProperty; static const DependencyProperty* DesiredFrameRateProperty; static const DependencyProperty* DurationProperty; static const DependencyProperty* FillBehaviorProperty; static const DependencyProperty* NameProperty; static const DependencyProperty* RepeatBehaviorProperty; static const DependencyProperty* SpeedRatioProperty; //@} protected: /// Creates a Clock for this Timeline virtual Ptr CreateClockCore(TimeManager* timeManager, bool hasControllableRoot) = 0; // From Freezable //@{ void CloneCommonCore(const Freezable* source) override; //@} private: void RaiseCompleted(const TimelineEventArgs& args); private: friend class Storyboard; friend class TimeManager; Duration mSinglePassDurationInternal; Duration mIterationDurationInternal; Duration mTotalDurationInternal; Duration mNormalizedDurationInternal; TimelineEventHandler mCompleted; // Cached dependency properties Nullable mBeginTime; float mSpeedRatio; float mAccelerationRatio; float mDecelerationRatio; bool mAutoReverse; bool mTotalDurationAbsolute; NS_DECLARE_REFLECTION(Timeline, Animatable) }; NS_WARNING_POP } NS_DECLARE_REFLECTION_ENUM_EXPORT(NS_GUI_ANIMATION_API, Noesis::FillBehavior) #endif