PolylineGeometry.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Avalonia.Platform;
  9. namespace Avalonia.Media
  10. {
  11. /// <summary>
  12. /// Represents the geometry of an polyline or polygon.
  13. /// </summary>
  14. public class PolylineGeometry : Geometry
  15. {
  16. private IList<Point> _points;
  17. private bool _isFilled;
  18. public PolylineGeometry(IList<Point> points, bool isFilled)
  19. {
  20. _points = points;
  21. _isFilled = isFilled;
  22. IPlatformRenderInterface factory = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>();
  23. IStreamGeometryImpl impl = factory.CreateStreamGeometry();
  24. using (IStreamGeometryContextImpl context = impl.Open())
  25. {
  26. if (points.Count > 0)
  27. {
  28. context.BeginFigure(points[0], isFilled);
  29. for (int i = 1; i < points.Count; i++)
  30. {
  31. context.LineTo(points[i]);
  32. }
  33. context.EndFigure(isFilled);
  34. }
  35. }
  36. PlatformImpl = impl;
  37. }
  38. /// <inheritdoc/>
  39. public override Geometry Clone()
  40. {
  41. return new PolylineGeometry(new List<Point>(_points), _isFilled);
  42. }
  43. }
  44. }