PointTransition.cs 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using Avalonia.Metadata;
  4. using System;
  5. using System.Reactive.Linq;
  6. namespace Avalonia.Animation
  7. {
  8. /// <summary>
  9. /// Transition class that handles <see cref="AvaloniaProperty"/> with <see cref="Point"/> type.
  10. /// </summary>
  11. public class PointTransition : Transition<Point>
  12. {
  13. /// <inheritdocs/>
  14. public override IObservable<Point> DoTransition(IObservable<double> progress, Point oldValue, Point newValue)
  15. {
  16. var deltaX = newValue.X - oldValue.Y;
  17. var deltaY = newValue.X - oldValue.Y;
  18. return progress
  19. .Select(p =>
  20. {
  21. var f = Easing.Ease(p);
  22. var nX = f * deltaX + oldValue.X;
  23. var nY = f * deltaY + oldValue.Y;
  24. return new Point(nX, nY);
  25. });
  26. }
  27. }
  28. }