|
|
|
@ -14,56 +14,55 @@ namespace Avalonia.Animation.Animators |
|
|
|
{ |
|
|
|
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) |
|
|
|
{ |
|
|
|
var ctrl = (Visual)control; |
|
|
|
|
|
|
|
foreach (var keyframe in this) |
|
|
|
{ |
|
|
|
// Return if the keyframe value is not a SolidColorBrush
|
|
|
|
if (keyframe.Value as ISolidColorBrush == null) |
|
|
|
{ |
|
|
|
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) |
|
|
|
control.SetValue(Property, new SolidColorBrush(Colors.Transparent)); |
|
|
|
// Make sure that the target property has SCB instead of the immutable one nor null.
|
|
|
|
|
|
|
|
var targetVal = control.GetValue(Property); |
|
|
|
|
|
|
|
if (typeof(ISolidColorBrush).IsAssignableFrom(targetVal.GetType())) |
|
|
|
{ |
|
|
|
if (colorAnimator == null) |
|
|
|
InitializeColorAnimator(); |
|
|
|
SolidColorBrush targetSCB = null; |
|
|
|
|
|
|
|
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)) |
|
|
|
{ |
|
|
|
var k = (ImmutableSolidColorBrush)targetVal; |
|
|
|
finalTarget.Color = k.Color; |
|
|
|
} |
|
|
|
else |
|
|
|
control.SetValue(Property, targetSCB); |
|
|
|
|
|
|
|
if (colorAnimator == null) |
|
|
|
{ |
|
|
|
colorAnimator = new ColorAnimator(); |
|
|
|
|
|
|
|
foreach (AnimatorKeyFrame keyframe in this) |
|
|
|
{ |
|
|
|
finalTarget = targetVal as SolidColorBrush; |
|
|
|
colorAnimator.Add(keyframe); |
|
|
|
} |
|
|
|
|
|
|
|
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; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|