Browse Source

Added RepeatBehavior, Direction and PlayState
enums and their respective properties in Animatable.cs

Jumar Macato 7 years ago
parent
commit
1116e92999

+ 9 - 5
samples/RenderTest/Pages/AnimationsPage.xaml

@@ -16,7 +16,8 @@
         <Setter Property="Child" Value="{StaticResource Acorn}"/>
         <Setter Property="Child" Value="{StaticResource Acorn}"/>
       </Style>
       </Style>
       <Style Selector="Border.Rect1:pointerover">
       <Style Selector="Border.Rect1:pointerover">
-         <Style.Animations>
+        <Setter Property="Opacity" Value="0.5"/>
+        <Style.Animations>
           <Animation Duration="0:0:2.5" Easing="SineEaseInOut">
           <Animation Duration="0:0:2.5" Easing="SineEaseInOut">
             <TransformKeyFrames Property="RotateTransform.Angle">
             <TransformKeyFrames Property="RotateTransform.Angle">
               <KeyFrame Cue="0%" Value="0"/>
               <KeyFrame Cue="0%" Value="0"/>
@@ -74,19 +75,22 @@
   <Grid>
   <Grid>
     <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" ClipToBounds="False">
     <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" ClipToBounds="False">
       <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
       <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
-        <TextBlock VerticalAlignment="Center">        
-          Hover to activate Transform Keyframe Animations.  
-        </TextBlock>
+        <TextBlock VerticalAlignment="Center">Hover to activate Transform Keyframe Animations.</TextBlock>
         <Button Content="{Binding PlayStateText}" Command="{Binding ToggleGlobalPlayState}"/>
         <Button Content="{Binding PlayStateText}" Command="{Binding ToggleGlobalPlayState}"/>
       </StackPanel>
       </StackPanel>
       <WrapPanel ClipToBounds="False">
       <WrapPanel ClipToBounds="False">
-        <Border Classes="Test Rect2" Background="DarkRed">
+        <Border Classes="Test Rect1" Background="DarkRed">
           <Border.RenderTransform>
           <Border.RenderTransform>
             <TransformGroup>
             <TransformGroup>
               <RotateTransform/>
               <RotateTransform/>
               <ScaleTransform/>
               <ScaleTransform/>
             </TransformGroup>
             </TransformGroup>
           </Border.RenderTransform>
           </Border.RenderTransform>
+          <Border.Transitions>
+            <Transitions>
+              <DoubleTransition Property="Border.Opacity" Duration="0:0:2.5"/>
+            </Transitions>
+          </Border.Transitions>
         </Border>
         </Border>
         <Border Classes="Test Rect2" Background="DarkMagenta">
         <Border Classes="Test Rect2" Background="DarkMagenta">
           <Border.RenderTransform>
           <Border.RenderTransform>

+ 4 - 4
samples/RenderTest/ViewModels/AnimationsPageViewModel.cs

@@ -17,14 +17,14 @@ namespace RenderTest.ViewModels
         {
         {
             switch (Timing.GetGlobalPlayState())
             switch (Timing.GetGlobalPlayState())
             {
             {
-                case AnimationPlayState.Running:
+                case PlayState.Running:
                     PlayStateText = "Resume all animations";
                     PlayStateText = "Resume all animations";
-                    Timing.SetGlobalPlayState(AnimationPlayState.Paused);
+                    Timing.SetGlobalPlayState(PlayState.Paused);
                     break;
                     break;
 
 
-                case AnimationPlayState.Paused:
+                case PlayState.Paused:
                     PlayStateText = "Pause all animations";
                     PlayStateText = "Pause all animations";
-                    Timing.SetGlobalPlayState(AnimationPlayState.Running);
+                    Timing.SetGlobalPlayState(PlayState.Running);
                     break;
                     break;
             }
             }
         }
         }

+ 4 - 4
src/Avalonia.Animation/Animatable.cs

@@ -27,8 +27,8 @@ namespace Avalonia.Animation
         /// <summary>
         /// <summary>
         /// Defines the <see cref="AnimationPlayState"/> property.
         /// Defines the <see cref="AnimationPlayState"/> property.
         /// </summary>
         /// </summary>
-        public static readonly DirectProperty<Animatable, AnimationPlayState> AnimationPlayStateProperty =
-            AvaloniaProperty.RegisterDirect<Animatable, AnimationPlayState>(
+        public static readonly DirectProperty<Animatable, PlayState> AnimationPlayStateProperty =
+            AvaloniaProperty.RegisterDirect<Animatable, PlayState>(
                 nameof(AnimationPlayState),
                 nameof(AnimationPlayState),
                 o => o.AnimationPlayState,
                 o => o.AnimationPlayState,
                 (o, v) => o.AnimationPlayState = v);
                 (o, v) => o.AnimationPlayState = v);
@@ -37,14 +37,14 @@ namespace Avalonia.Animation
         /// Gets or sets the state of the animation for this
         /// Gets or sets the state of the animation for this
         /// control.
         /// control.
         /// </summary>
         /// </summary>
-        public AnimationPlayState AnimationPlayState
+        public PlayState AnimationPlayState
         { 
         { 
             get { return _animationPlayState; }
             get { return _animationPlayState; }
             set { SetAndRaise(AnimationPlayStateProperty, ref _animationPlayState, value); }
             set { SetAndRaise(AnimationPlayStateProperty, ref _animationPlayState, value); }
         
         
         }
         }
 
 
-        private AnimationPlayState _animationPlayState;
+        private PlayState _animationPlayState;
 
 
         /// <summary>
         /// <summary>
         /// Defines the <see cref="Transitions"/> property.
         /// Defines the <see cref="Transitions"/> property.

+ 18 - 3
src/Avalonia.Animation/Animation.cs

@@ -15,7 +15,7 @@ namespace Avalonia.Animation
     /// </summary>
     /// </summary>
     public class Animation : IDisposable, IAnimation
     public class Animation : IDisposable, IAnimation
     {
     {
-        private List<IDisposable>_subscription = new List<IDisposable>();
+        private List<IDisposable> _subscription = new List<IDisposable>();
 
 
         /// <summary>
         /// <summary>
         /// Run time of this animation.
         /// Run time of this animation.
@@ -23,10 +23,25 @@ namespace Avalonia.Animation
         public TimeSpan Duration { get; set; }
         public TimeSpan Duration { get; set; }
 
 
         /// <summary>
         /// <summary>
-        /// Delay time for animation.
+        /// Delay time for this animation.
         /// </summary>
         /// </summary>
         public TimeSpan Delay { get; set; }
         public TimeSpan Delay { get; set; }
 
 
+        /// <summary>
+        /// The repeat behavor for this animation.
+        /// </summary>
+        public RepeatBehavior RepeatBehavior { get; set; }
+
+        /// <summary>
+        /// The playback direction for this animation.
+        /// </summary>
+        public Direction Direction { get; set; }
+
+        /// <summary>
+        /// Number of repeat iteration for this animation.
+        /// </summary>
+        public int? RepeatCount { get; set; }
+
         /// <summary>
         /// <summary>
         /// Easing function to be used.
         /// Easing function to be used.
         /// </summary> 
         /// </summary> 
@@ -43,7 +58,7 @@ namespace Avalonia.Animation
         /// </summary>
         /// </summary>
         public void Dispose()
         public void Dispose()
         {
         {
-            foreach(var sub in _subscription) sub.Dispose();
+            foreach (var sub in _subscription) sub.Dispose();
         }
         }
 
 
         /// <inheritdocs/>
         /// <inheritdocs/>

+ 32 - 0
src/Avalonia.Animation/Direction.cs

@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Avalonia.Animation
+{
+    /// <summary>
+    /// Determines the playback direction of an animation.
+    /// </summary>
+    public enum Direction
+    {
+        /// <summary>
+        /// The animation is played normally.
+        /// </summary>
+        Normal,
+
+        /// <summary>
+        /// The animation is played in reverse direction.
+        /// </summary>
+        Reverse,
+
+        /// <summary>
+        /// The animation is played forwards first, then backwards.
+        /// </summary>
+        Alternate,
+
+        /// <summary>
+        /// The animation is played backwards first, then forwards.
+        /// </summary>
+        AlternateReverse
+    }
+}

+ 43 - 0
src/Avalonia.Animation/Keyframes/KeyFramePair.cs

@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Avalonia.Collections;
+using System.ComponentModel;
+using Avalonia.Animation.Utils;
+using System.Reactive.Linq;
+using System.Linq;
+using Avalonia.Data;
+using System.Reactive.Disposables;
+
+namespace Avalonia.Animation.Keyframes
+{
+    /// <summary>
+    /// Represents a pair of keyframe, usually the
+    /// Start and End keyframes of a <see cref="KeyFrames{T}"/> object.
+    /// </summary>
+    public struct KeyFramePair<T>
+    {
+
+        /// <summary>
+        /// Initializes this <see cref="KeyFramePair{T}"/>
+        /// </summary>
+        /// <param name="FirstKeyFrame"></param>
+        /// <param name="LastKeyFrame"></param>
+        public KeyFramePair(KeyValuePair<double, T> FirstKeyFrame, KeyValuePair<double, T> LastKeyFrame) : this()
+        {
+            this.FirstKeyFrame = FirstKeyFrame;
+            this.SecondKeyFrame = LastKeyFrame;
+        }
+
+        /// <summary>
+        /// First <see cref="KeyFrame"/> object.
+        /// </summary>
+        public KeyValuePair<double, T> FirstKeyFrame { get; private set; }
+
+        /// <summary>
+        /// Second <see cref="KeyFrame"/> object.
+        /// </summary>
+        public KeyValuePair<double, T> SecondKeyFrame { get; private set; }
+
+    }
+}

+ 3 - 31
src/Avalonia.Animation/Keyframes/KeyFrames.cs

@@ -38,7 +38,7 @@ namespace Avalonia.Animation.Keyframes
             return obsMatch
             return obsMatch
                 .Where(p => p == true)
                 .Where(p => p == true)
                 // Ignore triggers when global timers are paused.
                 // Ignore triggers when global timers are paused.
-                .Where(p=> Timing.GetGlobalPlayState() != AnimationPlayState.Paused)
+                .Where(p=> Timing.GetGlobalPlayState() != PlayState.Paused)
                 .Subscribe(_ =>
                 .Subscribe(_ =>
                 {
                 {
                     var interp = DoInterpolation(animation, control)
                     var interp = DoInterpolation(animation, control)
@@ -47,41 +47,13 @@ namespace Avalonia.Animation.Keyframes
                 });
                 });
         }
         }
 
 
-        /// <summary>
-        /// Represents a pair of keyframe, usually the
-        /// Start and End keyframes of a <see cref="KeyFrames{T}"/> object.
-        /// </summary>
-        public struct KeyFramePair
-        { 
-
-            /// <summary>
-            /// Initializes this <see cref="KeyFramePair"/>
-            /// </summary>
-            /// <param name="FirstKeyFrame"></param>
-            /// <param name="LastKeyFrame"></param>
-            public KeyFramePair(KeyValuePair<double, T> FirstKeyFrame, KeyValuePair<double, T> LastKeyFrame) : this()
-            {
-                this.FirstKeyFrame = FirstKeyFrame;
-                this.SecondKeyFrame = LastKeyFrame;
-            }
 
 
-            /// <summary>
-            /// First <see cref="KeyFrame"/> object.
-            /// </summary>
-            public KeyValuePair<double, T> FirstKeyFrame { get; private set; }
-
-            /// <summary>
-            /// Second <see cref="KeyFrame"/> object.
-            /// </summary>
-            public KeyValuePair<double, T> SecondKeyFrame { get; private set; }
-
-        }
 
 
         /// <summary>
         /// <summary>
         /// Get the nearest pair of cue-time ordered keyframes 
         /// Get the nearest pair of cue-time ordered keyframes 
         /// according to the given time parameter.  
         /// according to the given time parameter.  
         /// </summary>
         /// </summary>
-        public KeyFramePair GetKeyFramePairByTime(double t)
+        public KeyFramePair<T> GetKeyFramePairByTime(double t)
         {
         {
             KeyValuePair<double, T> firstCue, lastCue;
             KeyValuePair<double, T> firstCue, lastCue;
             int kvCount = ConvertedKeyframes.Count();
             int kvCount = ConvertedKeyframes.Count();
@@ -108,7 +80,7 @@ namespace Avalonia.Animation.Keyframes
                 firstCue = ConvertedKeyframes.First();
                 firstCue = ConvertedKeyframes.First();
                 lastCue = ConvertedKeyframes.Last();
                 lastCue = ConvertedKeyframes.Last();
             }
             }
-            return new KeyFramePair(firstCue, lastCue);
+            return new KeyFramePair<T>(firstCue, lastCue);
         }
         }
 
 
 
 

+ 1 - 1
src/Avalonia.Animation/AnimationPlayState.cs → src/Avalonia.Animation/PlayState.cs

@@ -4,7 +4,7 @@ using System.Text;
 
 
 namespace Avalonia.Animation
 namespace Avalonia.Animation
 {
 {
-    public enum AnimationPlayState
+    public enum PlayState
     {
     {
         Running,
         Running,
         Paused
         Paused

+ 13 - 0
src/Avalonia.Animation/RepeatBehavior.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Avalonia.Animation
+{
+    public enum RepeatBehavior
+    {
+        None,
+        Repeat,
+        Loop
+    }
+}

+ 4 - 4
src/Avalonia.Animation/Timing.cs

@@ -16,7 +16,7 @@ namespace Avalonia.Animation
     public static class Timing
     public static class Timing
     {
     {
         static ulong _animationsFrameCount, _transitionsFrameCount;
         static ulong _animationsFrameCount, _transitionsFrameCount;
-        static AnimationPlayState _globalState = AnimationPlayState.Running;
+        static PlayState _globalState = PlayState.Running;
 
 
         /// <summary>
         /// <summary>
         /// The number of frames per second.
         /// The number of frames per second.
@@ -38,7 +38,7 @@ namespace Avalonia.Animation
                 {
                 {
                     switch (_globalState)
                     switch (_globalState)
                     {
                     {
-                        case AnimationPlayState.Paused:
+                        case PlayState.Paused:
                             break;
                             break;
                         default:
                         default:
                             _animationsFrameCount += 1;
                             _animationsFrameCount += 1;
@@ -59,7 +59,7 @@ namespace Avalonia.Animation
         /// <summary>
         /// <summary>
         /// Sets the animation play state for all animations
         /// Sets the animation play state for all animations
         /// </summary>
         /// </summary>
-        public static void SetGlobalPlayState(AnimationPlayState playState)
+        public static void SetGlobalPlayState(PlayState playState)
         {
         {
             Dispatcher.UIThread.VerifyAccess();
             Dispatcher.UIThread.VerifyAccess();
             _globalState = playState;
             _globalState = playState;
@@ -68,7 +68,7 @@ namespace Avalonia.Animation
         /// <summary>
         /// <summary>
         /// Gets the animation play state for all animations
         /// Gets the animation play state for all animations
         /// </summary>
         /// </summary>
-        public static AnimationPlayState GetGlobalPlayState()
+        public static PlayState GetGlobalPlayState()
         {
         {
             Dispatcher.UIThread.VerifyAccess();
             Dispatcher.UIThread.VerifyAccess();
             return _globalState;
             return _globalState;