Browse Source

Added RepeatBehavior, Direction and PlayState

enums and their respective properties in Animatable.cs
pull/1461/head
Jumar Macato 9 years ago
parent
commit
1116e92999
  1. 14
      samples/RenderTest/Pages/AnimationsPage.xaml
  2. 8
      samples/RenderTest/ViewModels/AnimationsPageViewModel.cs
  3. 8
      src/Avalonia.Animation/Animatable.cs
  4. 21
      src/Avalonia.Animation/Animation.cs
  5. 32
      src/Avalonia.Animation/Direction.cs
  6. 43
      src/Avalonia.Animation/Keyframes/KeyFramePair.cs
  7. 34
      src/Avalonia.Animation/Keyframes/KeyFrames.cs
  8. 2
      src/Avalonia.Animation/PlayState.cs
  9. 13
      src/Avalonia.Animation/RepeatBehavior.cs
  10. 8
      src/Avalonia.Animation/Timing.cs

14
samples/RenderTest/Pages/AnimationsPage.xaml

@ -16,7 +16,8 @@
<Setter Property="Child" Value="{StaticResource Acorn}"/>
</Style>
<Style Selector="Border.Rect1:pointerover">
<Style.Animations>
<Setter Property="Opacity" Value="0.5"/>
<Style.Animations>
<Animation Duration="0:0:2.5" Easing="SineEaseInOut">
<TransformKeyFrames Property="RotateTransform.Angle">
<KeyFrame Cue="0%" Value="0"/>
@ -74,19 +75,22 @@
<Grid>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" ClipToBounds="False">
<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}"/>
</StackPanel>
<WrapPanel ClipToBounds="False">
<Border Classes="Test Rect2" Background="DarkRed">
<Border Classes="Test Rect1" Background="DarkRed">
<Border.RenderTransform>
<TransformGroup>
<RotateTransform/>
<ScaleTransform/>
</TransformGroup>
</Border.RenderTransform>
<Border.Transitions>
<Transitions>
<DoubleTransition Property="Border.Opacity" Duration="0:0:2.5"/>
</Transitions>
</Border.Transitions>
</Border>
<Border Classes="Test Rect2" Background="DarkMagenta">
<Border.RenderTransform>

8
samples/RenderTest/ViewModels/AnimationsPageViewModel.cs

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

8
src/Avalonia.Animation/Animatable.cs

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

21
src/Avalonia.Animation/Animation.cs

@ -15,7 +15,7 @@ namespace Avalonia.Animation
/// </summary>
public class Animation : IDisposable, IAnimation
{
private List<IDisposable>_subscription = new List<IDisposable>();
private List<IDisposable> _subscription = new List<IDisposable>();
/// <summary>
/// Run time of this animation.
@ -23,10 +23,25 @@ namespace Avalonia.Animation
public TimeSpan Duration { get; set; }
/// <summary>
/// Delay time for animation.
/// Delay time for this animation.
/// </summary>
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>
/// Easing function to be used.
/// </summary>
@ -43,7 +58,7 @@ namespace Avalonia.Animation
/// </summary>
public void Dispose()
{
foreach(var sub in _subscription) sub.Dispose();
foreach (var sub in _subscription) sub.Dispose();
}
/// <inheritdocs/>

32
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
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; }
}
}

34
src/Avalonia.Animation/Keyframes/KeyFrames.cs

@ -38,7 +38,7 @@ namespace Avalonia.Animation.Keyframes
return obsMatch
.Where(p => p == true)
// Ignore triggers when global timers are paused.
.Where(p=> Timing.GetGlobalPlayState() != AnimationPlayState.Paused)
.Where(p=> Timing.GetGlobalPlayState() != PlayState.Paused)
.Subscribe(_ =>
{
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>
/// Get the nearest pair of cue-time ordered keyframes
/// according to the given time parameter.
/// </summary>
public KeyFramePair GetKeyFramePairByTime(double t)
public KeyFramePair<T> GetKeyFramePairByTime(double t)
{
KeyValuePair<double, T> firstCue, lastCue;
int kvCount = ConvertedKeyframes.Count();
@ -108,7 +80,7 @@ namespace Avalonia.Animation.Keyframes
firstCue = ConvertedKeyframes.First();
lastCue = ConvertedKeyframes.Last();
}
return new KeyFramePair(firstCue, lastCue);
return new KeyFramePair<T>(firstCue, lastCue);
}

2
src/Avalonia.Animation/AnimationPlayState.cs → src/Avalonia.Animation/PlayState.cs

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

13
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
}
}

8
src/Avalonia.Animation/Timing.cs

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

Loading…
Cancel
Save