TransformedGeometryImpl.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Avalonia.Platform;
  2. using SkiaSharp;
  3. namespace Avalonia.Skia
  4. {
  5. /// <summary>
  6. /// A Skia implementation of a <see cref="ITransformedGeometryImpl"/>.
  7. /// </summary>
  8. internal class TransformedGeometryImpl : GeometryImpl, ITransformedGeometryImpl
  9. {
  10. /// <summary>
  11. /// Initializes a new instance of the <see cref="TransformedGeometryImpl"/> class.
  12. /// </summary>
  13. /// <param name="source">Source geometry.</param>
  14. /// <param name="transform">Transform of new geometry.</param>
  15. public TransformedGeometryImpl(GeometryImpl source, Matrix transform)
  16. {
  17. SourceGeometry = source;
  18. Transform = transform;
  19. var matrix = transform.ToSKMatrix();
  20. var transformedPath = StrokePath = source.StrokePath.Clone();
  21. transformedPath?.Transform(matrix);
  22. Bounds = transformedPath?.TightBounds.ToAvaloniaRect() ?? default;
  23. if (ReferenceEquals(source.StrokePath, source.FillPath))
  24. FillPath = transformedPath;
  25. else if (source.FillPath != null)
  26. {
  27. FillPath = transformedPath = source.FillPath.Clone();
  28. transformedPath.Transform(matrix);
  29. }
  30. }
  31. /// <inheritdoc />
  32. public override SKPath? StrokePath { get; }
  33. /// <inheritdoc />
  34. public override SKPath? FillPath { get; }
  35. /// <inheritdoc />
  36. public IGeometryImpl SourceGeometry { get; }
  37. /// <inheritdoc />
  38. public Matrix Transform { get; }
  39. /// <inheritdoc />
  40. public override Rect Bounds { get; }
  41. }
  42. }