ClipNode.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using Avalonia.Platform;
  2. namespace Avalonia.Rendering.SceneGraph
  3. {
  4. /// <summary>
  5. /// A node in the scene graph which represents a clip push or pop.
  6. /// </summary>
  7. internal class ClipNode : IDrawOperation
  8. {
  9. /// <summary>
  10. /// Initializes a new instance of the <see cref="ClipNode"/> class that represents a
  11. /// clip push.
  12. /// </summary>
  13. /// <param name="transform">The current transform.</param>
  14. /// <param name="clip">The clip to push.</param>
  15. public ClipNode(Matrix transform, Rect clip)
  16. {
  17. Transform = transform;
  18. Clip = clip;
  19. }
  20. /// <summary>
  21. /// Initializes a new instance of the <see cref="ClipNode"/> class that represents a
  22. /// clip push.
  23. /// </summary>
  24. /// <param name="transform">The current transform.</param>
  25. /// <param name="clip">The clip to push.</param>
  26. public ClipNode(Matrix transform, RoundedRect clip)
  27. {
  28. Transform = transform;
  29. Clip = clip;
  30. }
  31. /// <summary>
  32. /// Initializes a new instance of the <see cref="ClipNode"/> class that represents a
  33. /// clip pop.
  34. /// </summary>
  35. public ClipNode()
  36. {
  37. }
  38. /// <inheritdoc/>
  39. public Rect Bounds => default;
  40. /// <summary>
  41. /// Gets the clip to be pushed or null if the operation represents a pop.
  42. /// </summary>
  43. public RoundedRect? Clip { get; }
  44. /// <summary>
  45. /// Gets the transform with which the node will be drawn.
  46. /// </summary>
  47. public Matrix Transform { get; }
  48. /// <inheritdoc/>
  49. public bool HitTest(Point p) => false;
  50. /// <summary>
  51. /// Determines if this draw operation equals another.
  52. /// </summary>
  53. /// <param name="transform">The transform of the other draw operation.</param>
  54. /// <param name="clip">The clip of the other draw operation.</param>
  55. /// <returns>True if the draw operations are the same, otherwise false.</returns>
  56. /// <remarks>
  57. /// The properties of the other draw operation are passed in as arguments to prevent
  58. /// allocation of a not-yet-constructed draw operation object.
  59. /// </remarks>
  60. public bool Equals(Matrix transform, RoundedRect? clip) => Transform == transform && Clip == clip;
  61. /// <inheritdoc/>
  62. public void Render(IDrawingContextImpl context)
  63. {
  64. context.Transform = Transform;
  65. if (Clip.HasValue)
  66. {
  67. context.PushClip(Clip.Value);
  68. }
  69. else
  70. {
  71. context.PopClip();
  72. }
  73. }
  74. public void Dispose()
  75. {
  76. }
  77. }
  78. }