using System.Collections.Generic; using Avalonia.Media; using Avalonia.Platform; using Avalonia.VisualTree; namespace Avalonia.Rendering.SceneGraph { /// /// A node in the scene graph which represents an opacity mask push or pop. /// internal class OpacityMaskNode : BrushDrawOperation { /// /// Initializes a new instance of the class that represents an /// opacity mask push. /// /// The opacity mask to push. /// The bounds of the mask. /// Child scenes for drawing visual brushes. public OpacityMaskNode(IBrush mask, Rect bounds, IDictionary childScenes = null) : base(Rect.Empty, Matrix.Identity) { Mask = mask?.ToImmutable(); MaskBounds = bounds; ChildScenes = childScenes; } /// /// Initializes a new instance of the class that represents an /// opacity mask pop. /// public OpacityMaskNode() : base(Rect.Empty, Matrix.Identity) { } /// /// Gets the mask to be pushed or null if the operation represents a pop. /// public IBrush Mask { get; } /// /// Gets the bounds of the opacity mask or null if the operation represents a pop. /// public Rect? MaskBounds { get; } /// public override IDictionary ChildScenes { get; } /// public override bool HitTest(Point p) => false; /// /// Determines if this draw operation equals another. /// /// The opacity mask of the other draw operation. /// The opacity mask bounds of the other draw operation. /// True if the draw operations are the same, otherwise false. /// /// The properties of the other draw operation are passed in as arguments to prevent /// allocation of a not-yet-constructed draw operation object. /// public bool Equals(IBrush mask, Rect? bounds) => Mask == mask && MaskBounds == bounds; /// public override void Render(IDrawingContextImpl context) { if (Mask != null) { context.PushOpacityMask(Mask, MaskBounds.Value); } else { context.PopOpacityMask(); } } } }