|
|
@@ -1,6 +1,7 @@
|
|
|
// Copyright (c) The Avalonia Project. All rights reserved.
|
|
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|
|
|
|
|
+using System;
|
|
|
using Avalonia.Platform;
|
|
|
using SharpDX.Direct2D1;
|
|
|
|
|
|
@@ -11,88 +12,49 @@ namespace Avalonia.Direct2D1.Media
|
|
|
/// </summary>
|
|
|
public abstract class GeometryImpl : IGeometryImpl
|
|
|
{
|
|
|
- private TransformedGeometry _transformed;
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Gets the geometry's bounding rectangle.
|
|
|
- /// </summary>
|
|
|
- public abstract Rect Bounds
|
|
|
- {
|
|
|
- get;
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Gets the geomentry without any transforms applied.
|
|
|
- /// </summary>
|
|
|
- public abstract Geometry DefiningGeometry
|
|
|
+ public GeometryImpl(Geometry geometry)
|
|
|
{
|
|
|
- get;
|
|
|
+ Geometry = geometry;
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Gets the Direct2D <see cref="Geometry"/>.
|
|
|
- /// </summary>
|
|
|
- public Geometry Geometry => _transformed ?? DefiningGeometry;
|
|
|
+ /// <inheritdoc/>
|
|
|
+ public Rect Bounds => Geometry.GetBounds().ToAvalonia();
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Gets or sets the transform for the geometry.
|
|
|
- /// </summary>
|
|
|
- public Matrix Transform
|
|
|
- {
|
|
|
- get
|
|
|
- {
|
|
|
- return _transformed != null ?
|
|
|
- _transformed.Transform.ToAvalonia() :
|
|
|
- Matrix.Identity;
|
|
|
- }
|
|
|
+ /// <inheritdoc/>
|
|
|
+ public Geometry Geometry { get; }
|
|
|
|
|
|
- set
|
|
|
- {
|
|
|
- if (value != Transform)
|
|
|
- {
|
|
|
- if (_transformed != null)
|
|
|
- {
|
|
|
- _transformed.Dispose();
|
|
|
- _transformed = null;
|
|
|
- }
|
|
|
+ /// <inheritdoc/>
|
|
|
+ public virtual Matrix Transform => Matrix.Identity;
|
|
|
|
|
|
- if (!value.IsIdentity)
|
|
|
- {
|
|
|
- Factory factory = AvaloniaLocator.Current.GetService<Factory>();
|
|
|
- _transformed = new TransformedGeometry(
|
|
|
- factory,
|
|
|
- DefiningGeometry,
|
|
|
- value.ToDirect2D());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Gets the geometry's bounding rectangle with the specified stroke thickness.
|
|
|
- /// </summary>
|
|
|
- /// <param name="strokeThickness">The stroke thickness.</param>
|
|
|
- /// <returns>The bounding rectangle.</returns>
|
|
|
+ /// <inheritdoc/>
|
|
|
public Rect GetRenderBounds(double strokeThickness)
|
|
|
{
|
|
|
- if (_transformed != null)
|
|
|
- {
|
|
|
- return _transformed.GetWidenedBounds((float)strokeThickness).ToAvalonia();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return DefiningGeometry.GetWidenedBounds((float)strokeThickness).ToAvalonia();
|
|
|
- }
|
|
|
+ return Geometry.GetWidenedBounds((float)strokeThickness).ToAvalonia();
|
|
|
}
|
|
|
|
|
|
+ /// <inheritdoc/>
|
|
|
public bool FillContains(Point point)
|
|
|
{
|
|
|
return Geometry.FillContainsPoint(point.ToSharpDX());
|
|
|
}
|
|
|
|
|
|
+ /// <inheritdoc/>
|
|
|
public bool StrokeContains(Avalonia.Media.Pen pen, Point point)
|
|
|
{
|
|
|
return Geometry.StrokeContainsPoint(point.ToSharpDX(), (float)pen.Thickness);
|
|
|
}
|
|
|
+
|
|
|
+ /// <inheritdoc/>
|
|
|
+ public IGeometryImpl WithTransform(Matrix transform)
|
|
|
+ {
|
|
|
+ var factory = AvaloniaLocator.Current.GetService<Factory>();
|
|
|
+ return new TransformedGeometryImpl(
|
|
|
+ new TransformedGeometry(
|
|
|
+ factory,
|
|
|
+ GetSourceGeometry(),
|
|
|
+ transform.ToDirect2D()));
|
|
|
+ }
|
|
|
+
|
|
|
+ protected virtual Geometry GetSourceGeometry() => Geometry;
|
|
|
}
|
|
|
}
|