using System.Collections.Generic; using Avalonia.Media; using Avalonia.Media.Immutable; using Avalonia.Platform; using Avalonia.VisualTree; namespace Avalonia.Rendering.SceneGraph { /// /// A node in the scene graph which represents a geometry draw. /// internal class GeometryNode : BrushDrawOperation { /// /// Initializes a new instance of the class. /// /// The transform. /// The fill brush. /// The stroke pen. /// The geometry. /// Child scenes for drawing visual brushes. public GeometryNode(Matrix transform, IBrush brush, IPen pen, IGeometryImpl geometry, IDictionary childScenes = null) : base(geometry.GetRenderBounds(pen), transform, null) { Transform = transform; Brush = brush?.ToImmutable(); Pen = pen?.ToImmutable(); Geometry = geometry; ChildScenes = childScenes; } /// /// Gets the transform with which the node will be drawn. /// public Matrix Transform { get; } /// /// Gets the fill brush. /// public IBrush Brush { get; } /// /// Gets the stroke pen. /// public ImmutablePen Pen { get; } /// /// Gets the geometry to draw. /// public IGeometryImpl Geometry { get; } /// public override IDictionary ChildScenes { get; } /// /// Determines if this draw operation equals another. /// /// The transform of the other draw operation. /// The fill of the other draw operation. /// The stroke of the other draw operation. /// The geometry of the other draw operation. /// The box shadow parameters /// 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(Matrix transform, IBrush brush, IPen pen, IGeometryImpl geometry) { return transform == Transform && Equals(brush, Brush) && Equals(Pen, pen) && Equals(geometry, Geometry); } /// public override void Render(IDrawingContextImpl context) { context.Transform = Transform; context.DrawGeometry(Brush, Pen, Geometry); } /// public override bool HitTest(Point p) { if (Transform.HasInverse) { p *= Transform.Invert(); return (Brush != null && Geometry.FillContains(p)) || (Pen != null && Geometry.StrokeContains(Pen, p)); } return false; } } }