StreamGeometryContext.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 Avalonia.Platform;
  5. namespace Avalonia.Media
  6. {
  7. /// <summary>
  8. /// Describes a geometry using drawing commands.
  9. /// </summary>
  10. /// <remarks>
  11. /// This class is used to define the geometry of a <see cref="StreamGeometry"/>. An instance
  12. /// of <see cref="StreamGeometryContext"/> is obtained by calling
  13. /// <see cref="StreamGeometry.Open"/>.
  14. /// </remarks>
  15. /// TODO: This class is just a wrapper around IStreamGeometryContextImpl: is it needed?
  16. public class StreamGeometryContext : IDisposable
  17. {
  18. private readonly IStreamGeometryContextImpl _impl;
  19. /// <summary>
  20. /// Initializes a new instance of the <see cref="StreamGeometryContext"/> class.
  21. /// </summary>
  22. /// <param name="impl">The platform-specific implementation.</param>
  23. public StreamGeometryContext(IStreamGeometryContextImpl impl)
  24. {
  25. _impl = impl;
  26. }
  27. /// <summary>
  28. /// Sets path's winding rule (default is EvenOdd). You should call this method before any calls to BeginFigure. If you wonder why, ask Direct2D guys about their design decisions.
  29. /// </summary>
  30. /// <param name="fillRule"></param>
  31. public void SetFillRule(FillRule fillRule)
  32. {
  33. _impl.SetFillRule(fillRule);
  34. }
  35. /// <summary>
  36. /// Draws an arc to the specified point.
  37. /// </summary>
  38. /// <param name="point">The destination point.</param>
  39. /// <param name="size">The radii of an oval whose perimeter is used to draw the angle.</param>
  40. /// <param name="rotationAngle">The rotation angle of the oval that specifies the curve.</param>
  41. /// <param name="isLargeArc">true to draw the arc greater than 180 degrees; otherwise, false.</param>
  42. /// <param name="sweepDirection">
  43. /// A value that indicates whether the arc is drawn in the Clockwise or Counterclockwise direction.
  44. /// </param>
  45. public void ArcTo(Point point, Size size, double rotationAngle, bool isLargeArc, SweepDirection sweepDirection)
  46. {
  47. _impl.ArcTo(point, size, rotationAngle, isLargeArc, sweepDirection);
  48. }
  49. /// <summary>
  50. /// Begins a new figure.
  51. /// </summary>
  52. /// <param name="startPoint">The starting point for the figure.</param>
  53. /// <param name="isFilled">Whether the figure is filled.</param>
  54. public void BeginFigure(Point startPoint, bool isFilled)
  55. {
  56. _impl.BeginFigure(startPoint, isFilled);
  57. }
  58. /// <summary>
  59. /// Draws a Bezier curve to the specified point.
  60. /// </summary>
  61. /// <param name="point1">The first control point used to specify the shape of the curve.</param>
  62. /// <param name="point2">The second control point used to specify the shape of the curve.</param>
  63. /// <param name="point3">The destination point for the end of the curve.</param>
  64. public void CubicBezierTo(Point point1, Point point2, Point point3)
  65. {
  66. _impl.CubicBezierTo(point1, point2, point3);
  67. }
  68. /// <summary>
  69. /// Draws a quadratic Bezier curve to the specified point
  70. /// </summary>
  71. /// <param name="control">The control point used to specify the shape of the curve.</param>
  72. /// <param name="endPoint">The destination point for the end of the curve.</param>
  73. public void QuadraticBezierTo(Point control, Point endPoint)
  74. {
  75. _impl.QuadraticBezierTo(control, endPoint);
  76. }
  77. /// <summary>
  78. /// Draws a line to the specified point.
  79. /// </summary>
  80. /// <param name="point">The destination point.</param>
  81. public void LineTo(Point point)
  82. {
  83. _impl.LineTo(point);
  84. }
  85. /// <summary>
  86. /// Ends the figure started by <see cref="BeginFigure(Point, bool)"/>.
  87. /// </summary>
  88. /// <param name="isClosed">Whether the figure is closed.</param>
  89. public void EndFigure(bool isClosed)
  90. {
  91. _impl.EndFigure(isClosed);
  92. }
  93. /// <summary>
  94. /// Finishes the drawing session.
  95. /// </summary>
  96. public void Dispose()
  97. {
  98. _impl.Dispose();
  99. }
  100. }
  101. }