Browse Source

Finish rough implementation of the new syntax.

pull/1461/head
Jumar Macato 9 years ago
parent
commit
ed7b875561
  1. 2
      samples/RenderTest/Pages/AnimationsPage.xaml
  2. 44
      src/Avalonia.Animation/Animation.cs
  3. 21
      src/Avalonia.Animation/AnimatorKeyFrame.cs
  4. 4
      src/Avalonia.Animation/Animator`1.cs
  5. 10
      src/Avalonia.Animation/IAnimator.cs
  6. 8
      src/Avalonia.Animation/KeyFrame.cs
  7. 2
      src/Avalonia.Visuals/Animation/TransformAnimator.cs

2
samples/RenderTest/Pages/AnimationsPage.xaml

@ -52,6 +52,8 @@
</KeyFrame>
<KeyFrame Cue="0%">
<TransformSetter Property="RotateTransform.Angle" Value="360"/>
<TransformSetter Property="ScaleTransform.ScaleX" Value="2"/>
<TransformSetter Property="ScaleTransform.ScaleY" Value="2"/>
</KeyFrame>
<KeyFrame Cue="100%">
<DoubleSetter Property="Opacity" Value="1"/>

44
src/Avalonia.Animation/Animation.cs

@ -74,9 +74,12 @@ namespace Avalonia.Animation
this.CollectionChanged += delegate { _isChildrenChanged = true; };
}
private void InterpretKeyframes()
{
var handlerList = new List<Type>();
var handlerList = new List<(Type, AvaloniaProperty)>();
var kfList = new List<AnimatorKeyFrame>();
foreach (var keyframe in this)
{
@ -90,12 +93,45 @@ namespace Avalonia.Animation
if (!custAttr.Any())
throw new InvalidProgramException($"Type {setter.GetType()} doesn't have Animator attribute.");
var match = (AnimatorAttribute)custAttr.First();
if (!handlerList.Contains(match.HandlerType))
handlerList.Add(match.HandlerType);
var handler = ((AnimatorAttribute)custAttr.First()).HandlerType;
if (!handlerList.Contains((handler, setter.Property)))
handlerList.Add((handler, setter.Property));
var newKF = new AnimatorKeyFrame()
{
Handler = handler,
Property = setter.Property,
Cue = keyframe.Cue,
KeyTime = keyframe.KeyTime,
timeSpanSet = keyframe.timeSpanSet,
cueSet = keyframe.cueSet,
Value = setter.Value
};
kfList.Add(newKF);
}
}
var newAnimatorInstances = new List<(Type handler, AvaloniaProperty prop, IAnimator inst)>();
foreach (var handler in handlerList)
{
var newInstance = (IAnimator)Activator.CreateInstance(handler.Item1);
newInstance.Property = handler.Item2;
newAnimatorInstances.Add((handler.Item1, handler.Item2, newInstance));
}
foreach (var kf in kfList)
{
var parent = newAnimatorInstances.Where(p=>p.handler == kf.Handler &&
p.prop == kf.Property)
.First();
parent.inst.Add(kf);
}
foreach(var instance in newAnimatorInstances)
_animators.Add(instance.inst);
}
/// <summary>

21
src/Avalonia.Animation/AnimatorKeyFrame.cs

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using Avalonia.Metadata;
using Avalonia.Collections;
namespace Avalonia.Animation
{
public class AnimatorKeyFrame
{
public Type Handler;
public Cue Cue;
public TimeSpan KeyTime;
internal bool timeSpanSet, cueSet;
internal AvaloniaProperty Property;
public object Value;
}
}

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

@ -14,7 +14,7 @@ namespace Avalonia.Animation
/// <summary>
/// Base class for KeyFrames objects
/// </summary>
public abstract class Animator<T> : AvaloniaList<InternalKeyFrame>, IAnimator
public abstract class Animator<T> : AvaloniaList<AnimatorKeyFrame>, IAnimator
{
/// <summary>
/// List of type-converted keyframes.
@ -117,7 +117,7 @@ namespace Avalonia.Animation
{
var typeConv = TypeDescriptor.GetConverter(type);
foreach (InternalKeyFrame k in this)
foreach (AnimatorKeyFrame k in this)
{
if (k.Value == null)
{

10
src/Avalonia.Animation/IAnimator.cs

@ -5,13 +5,19 @@ using System.Text;
namespace Avalonia.Animation
{
/// <summary>
/// Interface for Keyframe group object
/// Interface for Animator objects
/// </summary>
public interface IAnimator
public interface IAnimator : IList<AnimatorKeyFrame>
{
/// <summary>
/// The target property.
/// </summary>
AvaloniaProperty Property {get; set;}
/// <summary>
/// Applies the current KeyFrame group to the specified control.
/// </summary>
IDisposable Apply(Animation animation, Animatable control, IObservable<bool> obsMatch);
}
}

8
src/Avalonia.Animation/KeyFrame.cs

@ -75,12 +75,4 @@ namespace Avalonia.Animation
}
public class InternalKeyFrame
{
public Cue Cue { get; set; }
public TimeSpan KeyTime { get; set; }
internal bool timeSpanSet, cueSet;
public object Value { get; set; }
}
}

2
src/Avalonia.Visuals/Animation/TransformAnimator.cs

@ -84,7 +84,7 @@ namespace Avalonia.Animation
{
childKeyFrames = new DoubleAnimator();
foreach (InternalKeyFrame keyframe in this)
foreach (AnimatorKeyFrame keyframe in this)
{
childKeyFrames.Add(keyframe);
}

Loading…
Cancel
Save