diff --git a/src/Avalonia.Animation/Animation.cs b/src/Avalonia.Animation/Animation.cs index f2226cd704..d06f1d2dbc 100644 --- a/src/Avalonia.Animation/Animation.cs +++ b/src/Avalonia.Animation/Animation.cs @@ -199,7 +199,17 @@ namespace Avalonia.Animation private readonly static List<(Func Condition, Type Animator)> Animators = new List<(Func, Type)> { - ( prop => typeof(double).IsAssignableFrom(prop.PropertyType), typeof(DoubleAnimator) ) + ( prop => typeof(bool).IsAssignableFrom(prop.PropertyType), typeof(BoolAnimator) ), + ( prop => typeof(byte).IsAssignableFrom(prop.PropertyType), typeof(ByteAnimator) ), + ( prop => typeof(Int16).IsAssignableFrom(prop.PropertyType), typeof(Int16Animator) ), + ( prop => typeof(Int32).IsAssignableFrom(prop.PropertyType), typeof(Int32Animator) ), + ( prop => typeof(Int64).IsAssignableFrom(prop.PropertyType), typeof(Int64Animator) ), + ( prop => typeof(UInt16).IsAssignableFrom(prop.PropertyType), typeof(UInt16Animator) ), + ( prop => typeof(UInt32).IsAssignableFrom(prop.PropertyType), typeof(UInt32Animator) ), + ( prop => typeof(UInt64).IsAssignableFrom(prop.PropertyType), typeof(UInt64Animator) ), + ( prop => typeof(float).IsAssignableFrom(prop.PropertyType), typeof(FloatAnimator) ), + ( prop => typeof(double).IsAssignableFrom(prop.PropertyType), typeof(DoubleAnimator) ), + ( prop => typeof(decimal).IsAssignableFrom(prop.PropertyType), typeof(DecimalAnimator) ), }; public static void RegisterAnimator(Func condition) diff --git a/src/Avalonia.Animation/Animators/BoolAnimator.cs b/src/Avalonia.Animation/Animators/BoolAnimator.cs new file mode 100644 index 0000000000..63ff4933d6 --- /dev/null +++ b/src/Avalonia.Animation/Animators/BoolAnimator.cs @@ -0,0 +1,21 @@ +// Copyright (c) The Avalonia Project. All rights reserved. +// Licensed under the MIT license. See licence.md file in the project root for full license information. + +namespace Avalonia.Animation.Animators +{ + /// + /// Animator that handles properties. + /// + public class BoolAnimator : Animator + { + /// + public override bool Interpolate(double progress, bool oldValue, bool newValue) + { + if(progress >= 1d) + return newValue; + if(progress >= 0) + return oldValue; + return oldValue; + } + } +} diff --git a/src/Avalonia.Animation/Animators/ByteAnimator.cs b/src/Avalonia.Animation/Animators/ByteAnimator.cs new file mode 100644 index 0000000000..952df9de36 --- /dev/null +++ b/src/Avalonia.Animation/Animators/ByteAnimator.cs @@ -0,0 +1,24 @@ +// Copyright (c) The Avalonia Project. All rights reserved. +// Licensed under the MIT license. See licence.md file in the project root for full license information. + +using System; + +namespace Avalonia.Animation.Animators +{ + /// + /// Animator that handles properties. + /// + public class ByteAnimator : Animator + { + static double maxVal = (double)byte.MaxValue; + + /// + public override byte Interpolate(double progress, byte oldValue, byte newValue) + { + var normOV = oldValue / maxVal; + var normNV = newValue / maxVal; + var deltaV = normNV - normOV; + return (byte)Math.Round(maxVal * ((deltaV * progress) + normOV)); + } + } +} diff --git a/src/Avalonia.Animation/Animators/DecimalAnimator.cs b/src/Avalonia.Animation/Animators/DecimalAnimator.cs new file mode 100644 index 0000000000..b5fae7990c --- /dev/null +++ b/src/Avalonia.Animation/Animators/DecimalAnimator.cs @@ -0,0 +1,17 @@ +// Copyright (c) The Avalonia Project. All rights reserved. +// Licensed under the MIT license. See licence.md file in the project root for full license information. + +namespace Avalonia.Animation.Animators +{ + /// + /// Animator that handles properties. + /// + public class DecimalAnimator : Animator + { + /// + public override decimal Interpolate(double progress, decimal oldValue, decimal newValue) + { + return ((newValue - oldValue) * (decimal)progress) + oldValue; + } + } +} diff --git a/src/Avalonia.Animation/Animators/FloatAnimator.cs b/src/Avalonia.Animation/Animators/FloatAnimator.cs new file mode 100644 index 0000000000..140b453ddf --- /dev/null +++ b/src/Avalonia.Animation/Animators/FloatAnimator.cs @@ -0,0 +1,17 @@ +// Copyright (c) The Avalonia Project. All rights reserved. +// Licensed under the MIT license. See licence.md file in the project root for full license information. + +namespace Avalonia.Animation.Animators +{ + /// + /// Animator that handles properties. + /// + public class FloatAnimator : Animator + { + /// + public override float Interpolate(double progress, float oldValue, float newValue) + { + return ((newValue - oldValue) * (float)progress) + oldValue; + } + } +} diff --git a/src/Avalonia.Animation/Animators/Int16Animator.cs b/src/Avalonia.Animation/Animators/Int16Animator.cs new file mode 100644 index 0000000000..60b324552b --- /dev/null +++ b/src/Avalonia.Animation/Animators/Int16Animator.cs @@ -0,0 +1,24 @@ +// Copyright (c) The Avalonia Project. All rights reserved. +// Licensed under the MIT license. See licence.md file in the project root for full license information. + +using System; + +namespace Avalonia.Animation.Animators +{ + /// + /// Animator that handles properties. + /// + public class Int16Animator : Animator + { + static double maxVal = (double)Int16.MaxValue; + + /// + public override Int16 Interpolate(double progress, Int16 oldValue, Int16 newValue) + { + var normOV = oldValue / maxVal; + var normNV = newValue / maxVal; + var deltaV = normNV - normOV; + return (Int16)Math.Round(maxVal * ((deltaV * progress) + normOV)); + } + } +} diff --git a/src/Avalonia.Animation/Animators/Int32Animator.cs b/src/Avalonia.Animation/Animators/Int32Animator.cs new file mode 100644 index 0000000000..21520e2fe3 --- /dev/null +++ b/src/Avalonia.Animation/Animators/Int32Animator.cs @@ -0,0 +1,24 @@ +// Copyright (c) The Avalonia Project. All rights reserved. +// Licensed under the MIT license. See licence.md file in the project root for full license information. + +using System; + +namespace Avalonia.Animation.Animators +{ + /// + /// Animator that handles properties. + /// + public class Int32Animator : Animator + { + static double maxVal = (double)Int32.MaxValue; + + /// + public override Int32 Interpolate(double progress, Int32 oldValue, Int32 newValue) + { + var normOV = oldValue / maxVal; + var normNV = newValue / maxVal; + var deltaV = normNV - normOV; + return (Int32)Math.Round(maxVal * ((deltaV * progress) + normOV)); + } + } +} diff --git a/src/Avalonia.Animation/Animators/Int64Animator.cs b/src/Avalonia.Animation/Animators/Int64Animator.cs new file mode 100644 index 0000000000..b6c495796d --- /dev/null +++ b/src/Avalonia.Animation/Animators/Int64Animator.cs @@ -0,0 +1,24 @@ +// Copyright (c) The Avalonia Project. All rights reserved. +// Licensed under the MIT license. See licence.md file in the project root for full license information. + +using System; + +namespace Avalonia.Animation.Animators +{ + /// + /// Animator that handles properties. + /// + public class Int64Animator : Animator + { + static double maxVal = (double)Int64.MaxValue; + + /// + public override Int64 Interpolate(double progress, Int64 oldValue, Int64 newValue) + { + var normOV = oldValue / maxVal; + var normNV = newValue / maxVal; + var deltaV = normNV - normOV; + return (Int64)Math.Round(maxVal * ((deltaV * progress) + normOV)); + } + } +} diff --git a/src/Avalonia.Animation/Animators/UInt16Animator.cs b/src/Avalonia.Animation/Animators/UInt16Animator.cs new file mode 100644 index 0000000000..486fd7218f --- /dev/null +++ b/src/Avalonia.Animation/Animators/UInt16Animator.cs @@ -0,0 +1,24 @@ +// Copyright (c) The Avalonia Project. All rights reserved. +// Licensed under the MIT license. See licence.md file in the project root for full license information. + +using System; + +namespace Avalonia.Animation.Animators +{ + /// + /// Animator that handles properties. + /// + public class UInt16Animator : Animator + { + static double maxVal = (double)UInt16.MaxValue; + + /// + public override UInt16 Interpolate(double progress, UInt16 oldValue, UInt16 newValue) + { + var normOV = oldValue / maxVal; + var normNV = newValue / maxVal; + var deltaV = normNV - normOV; + return (UInt16)Math.Round(maxVal * ((deltaV * progress) + normOV)); + } + } +} diff --git a/src/Avalonia.Animation/Animators/UInt32Animator.cs b/src/Avalonia.Animation/Animators/UInt32Animator.cs new file mode 100644 index 0000000000..19df9e5929 --- /dev/null +++ b/src/Avalonia.Animation/Animators/UInt32Animator.cs @@ -0,0 +1,24 @@ +// Copyright (c) The Avalonia Project. All rights reserved. +// Licensed under the MIT license. See licence.md file in the project root for full license information. + +using System; + +namespace Avalonia.Animation.Animators +{ + /// + /// Animator that handles properties. + /// + public class UInt32Animator : Animator + { + static double maxVal = (double)UInt32.MaxValue; + + /// + public override UInt32 Interpolate(double progress, UInt32 oldValue, UInt32 newValue) + { + var normOV = oldValue / maxVal; + var normNV = newValue / maxVal; + var deltaV = normNV - normOV; + return (UInt32)Math.Round(maxVal * ((deltaV * progress) + normOV)); + } + } +} diff --git a/src/Avalonia.Animation/Animators/UInt64Animator.cs b/src/Avalonia.Animation/Animators/UInt64Animator.cs new file mode 100644 index 0000000000..5303e164c9 --- /dev/null +++ b/src/Avalonia.Animation/Animators/UInt64Animator.cs @@ -0,0 +1,24 @@ +// Copyright (c) The Avalonia Project. All rights reserved. +// Licensed under the MIT license. See licence.md file in the project root for full license information. + +using System; + +namespace Avalonia.Animation.Animators +{ + /// + /// Animator that handles properties. + /// + public class UInt64Animator : Animator + { + static double maxVal = (double)UInt64.MaxValue; + + /// + public override UInt64 Interpolate(double progress, UInt64 oldValue, UInt64 newValue) + { + var normOV = oldValue / maxVal; + var normNV = newValue / maxVal; + var deltaV = normNV - normOV; + return (UInt64)Math.Round(maxVal * ((deltaV * progress) + normOV)); + } + } +}