Browse Source

Start of syntax rework

pull/1461/head
Jumar Macato 8 years ago
parent
commit
c04a368bad
  1. 24
      src/Avalonia.Animation/Animation.cs
  2. 17
      src/Avalonia.Animation/AnimationSetter.cs
  3. 14
      src/Avalonia.Animation/AnimatorAttribute.cs
  4. 8
      src/Avalonia.Animation/AnimatorStateMachine`1.cs
  5. 4
      src/Avalonia.Animation/Animator`1.cs
  6. 4
      src/Avalonia.Animation/DoubleAnimator.cs
  7. 17
      src/Avalonia.Animation/DoubleSetter.cs
  8. 9
      src/Avalonia.Animation/IAnimationSetter.cs
  9. 2
      src/Avalonia.Animation/IAnimator.cs
  10. 5
      src/Avalonia.Animation/KeyFrame.cs
  11. 2
      src/Avalonia.Animation/KeyFramePair`1.cs
  12. 8
      src/Avalonia.Visuals/Animation/TransformAnimator.cs

24
src/Avalonia.Animation/Animation.cs

@ -7,6 +7,7 @@ using Avalonia.Collections;
using Avalonia.Metadata;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
namespace Avalonia.Animation
{
@ -16,6 +17,7 @@ namespace Avalonia.Animation
public class Animation : IDisposable, IAnimation
{
private List<IDisposable> _subscription = new List<IDisposable>();
public AvaloniaList<IAnimator> _animators { get; set; } = new AvaloniaList<IAnimator>();
/// <summary>
/// Run time of this animation.
@ -53,17 +55,30 @@ namespace Avalonia.Animation
public Easing Easing { get; set; } = new LinearEasing();
/// <summary>
/// A list of <see cref="IKeyFrames"/> objects.
/// A list of <see cref="KeyFrame"/> objects.
/// </summary>
[Content]
public AvaloniaList<IKeyFrames> Children { get; set; } = new AvaloniaList<IKeyFrames>();
public AvaloniaList<KeyFrame> Children { get; set; } = new AvaloniaList<KeyFrame>();
public Animation()
{
InterpretKeyframes();
}
private void InterpretKeyframes()
{
foreach (var keyframe in Children)
{
}
}
/// <summary>
/// Cancels the animation.
/// </summary>
public void Dispose()
{
foreach (var sub in _subscription)
foreach (var sub in _subscription)
{
sub.Dispose();
}
@ -72,12 +87,11 @@ namespace Avalonia.Animation
/// <inheritdocs/>
public IDisposable Apply(Animatable control, IObservable<bool> matchObs)
{
foreach (IKeyFrames keyframes in Children)
foreach (IAnimator keyframes in _animators)
{
_subscription.Add(keyframes.Apply(this, control, matchObs));
}
return this;
}
}
}

17
src/Avalonia.Animation/AnimationSetter.cs

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Reactive.Linq;
using System.Diagnostics;
using Avalonia.Animation.Utils;
using Avalonia.Data;
namespace Avalonia.Animation
{
public abstract class Setter : IAnimationSetter
{
public AvaloniaProperty Property { get; set; }
public object Value { get; set; }
}
}

14
src/Avalonia.Animation/AnimatorAttribute.cs

@ -0,0 +1,14 @@
using System;
namespace Avalonia.Animation
{
public class AnimatorAttribute : Attribute
{
public Type HandlerType;
public AnimatorAttribute(Type handler)
{
this.HandlerType = handler;
}
}
}

8
src/Avalonia.Animation/KeyFramesStateMachine`1.cs → src/Avalonia.Animation/AnimatorStateMachine`1.cs

@ -5,9 +5,9 @@ using Avalonia.Data;
namespace Avalonia.Animation
{
/// <summary>
/// Provides statefulness for an iteration of a keyframe group animation.
/// Provides statefulness for an iteration of a keyframe animation.
/// </summary>
internal class KeyFramesStateMachine<T> : IObservable<object>, IDisposable
internal class AnimatorStateMachine<T> : IObservable<object>, IDisposable
{
object _lastInterpValue;
object _firstKFValue;
@ -29,7 +29,7 @@ namespace Avalonia.Animation
private PlaybackDirection _animationDirection;
private KeyFramesStates _currentState;
private KeyFramesStates _savedState;
private KeyFrames<T> _parent;
private Animator<T> _parent;
private Animation _targetAnimation;
private Animatable _targetControl;
private T _neutralValue;
@ -51,7 +51,7 @@ namespace Avalonia.Animation
Disposed
}
public void Initialize(Animation animation, Animatable control, KeyFrames<T> keyframes)
public void Initialize(Animation animation, Animatable control, Animator<T> keyframes)
{
_parent = keyframes;
_targetAnimation = animation;

4
src/Avalonia.Animation/KeyFrames`1.cs → src/Avalonia.Animation/Animator`1.cs

@ -14,7 +14,7 @@ namespace Avalonia.Animation
/// <summary>
/// Base class for KeyFrames objects
/// </summary>
public abstract class KeyFrames<T> : AvaloniaList<KeyFrame>, IKeyFrames
public abstract class Animator<T> : AvaloniaList<KeyFrame>, IAnimator
{
/// <summary>
/// List of type-converted keyframes.
@ -92,7 +92,7 @@ namespace Avalonia.Animation
/// </summary>
private IDisposable RunKeyFrames(Animation animation, Animatable control)
{
var _kfStateMach = new KeyFramesStateMachine<T>();
var _kfStateMach = new AnimatorStateMachine<T>();
_kfStateMach.Initialize(animation, control, this);
Timing.AnimationStateTimer

4
src/Avalonia.Animation/DoubleKeyFrames.cs → src/Avalonia.Animation/DoubleAnimator.cs

@ -10,9 +10,9 @@ using Avalonia.Data;
namespace Avalonia.Animation
{
/// <summary>
/// Key frames that handles <see cref="double"/> properties.
/// Animator that handles <see cref="double"/> properties.
/// </summary>
public class DoubleKeyFrames : KeyFrames<double>
public class DoubleAnimator : Animator<double>
{
/// <inheritdocs/>

17
src/Avalonia.Animation/DoubleSetter.cs

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Reactive.Linq;
using System.Diagnostics;
using Avalonia.Animation.Utils;
using Avalonia.Data;
namespace Avalonia.Animation
{
[Animator(typeof(DoubleAnimator))]
public class DoubleSetter : Setter
{
}
}

9
src/Avalonia.Animation/IAnimationSetter.cs

@ -0,0 +1,9 @@
namespace Avalonia.Animation
{
public interface IAnimationSetter
{
AvaloniaProperty Property { get; set; }
object Value { get; set; }
}
}

2
src/Avalonia.Animation/IKeyFrames.cs → src/Avalonia.Animation/IAnimator.cs

@ -7,7 +7,7 @@ namespace Avalonia.Animation
/// <summary>
/// Interface for Keyframe group object
/// </summary>
public interface IKeyFrames
public interface IAnimator
{
/// <summary>
/// Applies the current KeyFrame group to the specified control.

5
src/Avalonia.Animation/KeyFrame.cs

@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using Avalonia.Metadata;
using Avalonia.Collections;
namespace Avalonia.Animation
{
@ -63,5 +65,8 @@ namespace Avalonia.Animation
/// </summary>
public object Value { get; set; }
[Content]
public AvaloniaList<IAnimationSetter> Children { get; set; } = new AvaloniaList<IAnimationSetter>();
}
}

2
src/Avalonia.Animation/KeyFramePair`1.cs

@ -13,7 +13,7 @@ namespace Avalonia.Animation
{
/// <summary>
/// Represents a pair of keyframe, usually the
/// Start and End keyframes of a <see cref="KeyFrames{T}"/> object.
/// Start and End keyframes of a <see cref="Animator{T}"/> object.
/// </summary>
public struct KeyFramePair<T>
{

8
src/Avalonia.Visuals/Animation/TransformKeyFrames.cs → src/Avalonia.Visuals/Animation/TransformAnimator.cs

@ -12,11 +12,11 @@ using Avalonia.Logging;
namespace Avalonia.Animation
{
/// <summary>
/// Keyframes that handles <see cref="Transform"/> properties.
/// Animator that handles <see cref="Transform"/> properties.
/// </summary>
public class TransformKeyFrames : KeyFrames<double>
public class TransformAnimator : Animator<double>
{
DoubleKeyFrames childKeyFrames;
DoubleAnimator childKeyFrames;
/// <inheritdoc/>
public override IDisposable Apply(Animation animation, Animatable control, IObservable<bool> obsMatch)
@ -82,7 +82,7 @@ namespace Avalonia.Animation
void InitializeChildKeyFrames()
{
childKeyFrames = new DoubleKeyFrames();
childKeyFrames = new DoubleAnimator();
foreach (KeyFrame keyframe in this)
{
Loading…
Cancel
Save