Browse Source

Fix SCBAnimator to finally make color animations work.

pull/2163/head
Jumar Macato 8 years ago
parent
commit
58c2394547
No known key found for this signature in database GPG Key ID: B19884DAC3A5BF3F
  1. 55
      src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs

55
src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs

@ -14,56 +14,55 @@ namespace Avalonia.Animation.Animators
{ {
ColorAnimator colorAnimator; ColorAnimator colorAnimator;
void InitializeColorAnimator()
{
colorAnimator = new ColorAnimator();
foreach (AnimatorKeyFrame keyframe in this)
{
colorAnimator.Add(keyframe);
}
}
public override IDisposable Apply(Animation animation, Animatable control, IClock clock, IObservable<bool> match, Action onComplete) public override IDisposable Apply(Animation animation, Animatable control, IClock clock, IObservable<bool> match, Action onComplete)
{ {
var ctrl = (Visual)control; var ctrl = (Visual)control;
foreach (var keyframe in this) foreach (var keyframe in this)
{ {
// Return if the keyframe value is not a SolidColorBrush
if (keyframe.Value as ISolidColorBrush == null) if (keyframe.Value as ISolidColorBrush == null)
{
return Disposable.Empty; return Disposable.Empty;
}
// Preprocess values to Color if the xaml parser converts them to ISCB
if (keyframe.Value.GetType() == typeof(ImmutableSolidColorBrush))
{
keyframe.Value = ((ImmutableSolidColorBrush)keyframe.Value).Color;
}
} }
if (control.GetValue(Property) == null) // Make sure that the target property has SCB instead of the immutable one nor null.
control.SetValue(Property, new SolidColorBrush(Colors.Transparent));
var targetVal = control.GetValue(Property); var targetVal = control.GetValue(Property);
if (typeof(ISolidColorBrush).IsAssignableFrom(targetVal.GetType())) SolidColorBrush targetSCB = null;
{
if (colorAnimator == null)
InitializeColorAnimator();
SolidColorBrush finalTarget = new SolidColorBrush(); if (targetVal == null)
targetSCB = new SolidColorBrush(Colors.Transparent);
else if (typeof(ISolidColorBrush).IsAssignableFrom(targetVal.GetType()))
targetSCB = new SolidColorBrush(((ISolidColorBrush)targetVal).Color);
else
return Disposable.Empty;
if (targetVal.GetType() == typeof(ImmutableSolidColorBrush)) control.SetValue(Property, targetSCB);
{
var k = (ImmutableSolidColorBrush)targetVal; if (colorAnimator == null)
finalTarget.Color = k.Color; {
} colorAnimator = new ColorAnimator();
else
foreach (AnimatorKeyFrame keyframe in this)
{ {
finalTarget = targetVal as SolidColorBrush; colorAnimator.Add(keyframe);
} }
colorAnimator.Property = SolidColorBrush.ColorProperty; colorAnimator.Property = SolidColorBrush.ColorProperty;
return colorAnimator.Apply(animation, finalTarget, clock ?? control.Clock, match, onComplete);
} }
return Disposable.Empty; return colorAnimator.Apply(animation, targetSCB, clock ?? control.Clock, match, onComplete);
} }
public override SolidColorBrush Interpolate(double p, SolidColorBrush o, SolidColorBrush n) => null; public override SolidColorBrush Interpolate(double p, SolidColorBrush o, SolidColorBrush n) => null;
} }
} }

Loading…
Cancel
Save