Browse Source

Fix SCBA.

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

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

@ -13,53 +13,62 @@ namespace Avalonia.Animation.Animators
{ {
ColorAnimator colorAnimator; ColorAnimator colorAnimator;
void InitializeColorAnimator()
{
colorAnimator = new ColorAnimator();
foreach (AnimatorKeyFrame keyframe in this)
{
colorAnimator.Add(keyframe);
}
colorAnimator.Property = SolidColorBrush.ColorProperty;
}
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 // Preprocess keyframe values to Color if the xaml parser converts them to ISCB.
if (keyframe.Value.GetType() == typeof(ImmutableSolidColorBrush)) if (keyframe.Value.GetType() == typeof(ImmutableSolidColorBrush))
{ {
keyframe.Value = ((ImmutableSolidColorBrush)keyframe.Value).Color; keyframe.Value = ((ImmutableSolidColorBrush)keyframe.Value).Color;
} }
} }
// Make sure that the target property has SCB instead of the immutable one nor null. // Add SCB if the target prop is empty.
if (control.GetValue(Property) == null)
control.SetValue(Property, new SolidColorBrush(Colors.Transparent));
var targetVal = control.GetValue(Property); var targetVal = control.GetValue(Property);
SolidColorBrush targetSCB = null; // Continue if target prop is not empty & is a SolidColorBrush derivative.
if (typeof(ISolidColorBrush).IsAssignableFrom(targetVal.GetType()))
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;
control.SetValue(Property, targetSCB);
if (colorAnimator == null)
{ {
colorAnimator = new ColorAnimator(); if (colorAnimator == null)
InitializeColorAnimator();
SolidColorBrush finalTarget;
foreach (AnimatorKeyFrame keyframe in this) // If it's ISCB, change it back to SCB.
if (targetVal.GetType() == typeof(ImmutableSolidColorBrush))
{ {
colorAnimator.Add(keyframe); var col = (ImmutableSolidColorBrush)targetVal;
targetVal = new SolidColorBrush(col.Color);
control.SetValue(Property, targetVal);
} }
colorAnimator.Property = SolidColorBrush.ColorProperty; finalTarget = targetVal as SolidColorBrush;
return colorAnimator.Apply(animation, finalTarget, clock ?? control.Clock, match, onComplete);
} }
return colorAnimator.Apply(animation, targetSCB, clock ?? control.Clock, match, onComplete); return Disposable.Empty;
} }
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