// -----------------------------------------------------------------------
//
// Copyright 2015 MIT Licence. See licence.md for more information.
//
// -----------------------------------------------------------------------
namespace Perspex.Direct2D1.Media
{
using Perspex.Platform;
using SharpDX.Direct2D1;
using Splat;
///
/// The platform-specific interface for .
///
public abstract class GeometryImpl : IGeometryImpl
{
private TransformedGeometry transformed;
///
/// Gets the geometry's bounding rectangle.
///
public abstract Rect Bounds
{
get;
}
///
/// Gets the geomentry without any transforms applied.
///
public abstract Geometry DefiningGeometry
{
get;
}
///
/// Gets the Direct2D .
///
public Geometry Geometry
{
get { return this.transformed ?? this.DefiningGeometry; }
}
///
/// Gets or sets the transform for the geometry.
///
public Matrix Transform
{
get
{
return this.transformed != null ?
this.transformed.Transform.ToPerspex() :
Matrix.Identity;
}
set
{
if (value != this.Transform)
{
if (this.transformed != null)
{
this.transformed.Dispose();
this.transformed = null;
}
if (!value.IsIdentity)
{
Factory factory = Locator.Current.GetService();
this.transformed = new TransformedGeometry(
factory,
this.DefiningGeometry,
value.ToDirect2D());
}
}
}
}
///
/// Gets the geometry's bounding rectangle with the specified stroke thickness.
///
/// The stroke thickness.
/// The bounding rectangle.
public Rect GetRenderBounds(double strokeThickness)
{
if (this.transformed != null)
{
return this.transformed.GetWidenedBounds((float)strokeThickness).ToPerspex();
}
else
{
return this.DefiningGeometry.GetWidenedBounds((float)strokeThickness).ToPerspex();
}
}
}
}