// -----------------------------------------------------------------------
//
// Copyright 2015 MIT Licence. See licence.md for more information.
//
// -----------------------------------------------------------------------
namespace Perspex.Direct2D1.Media
{
using Perspex.Media;
using Perspex.Platform;
using SharpDX.Direct2D1;
using Splat;
using D2DGeometry = SharpDX.Direct2D1.Geometry;
///
/// A Direct2D implementation of a .
///
public class StreamGeometryImpl : GeometryImpl, IStreamGeometryImpl
{
private PathGeometry path;
///
/// Initializes a new instance of the class.
///
public StreamGeometryImpl()
{
Factory factory = Locator.Current.GetService();
this.path = new PathGeometry(factory);
}
///
/// Initializes a new instance of the class.
///
/// An existing Direct2D .
protected StreamGeometryImpl(PathGeometry geometry)
{
this.path = geometry;
}
///
public override Rect Bounds
{
get { return this.path.GetBounds().ToPerspex(); }
}
///
public override D2DGeometry DefiningGeometry
{
get { return this.path; }
}
///
/// Clones the geometry.
///
/// A cloned geometry.
public IStreamGeometryImpl Clone()
{
Factory factory = Locator.Current.GetService();
var result = new PathGeometry(factory);
var sink = result.Open();
this.path.Stream(sink);
sink.Close();
return new StreamGeometryImpl(result);
}
///
/// Opens the geometry to start defining it.
///
///
/// A which can be used to define the geometry.
///
public IStreamGeometryContextImpl Open()
{
return new StreamGeometryContextImpl(this.path.Open());
}
}
}