/// <summary> /// Initializes a new instance of the <see cref="EllipseGeometry"/> class. /// </summary> /// <param name="rect">The rectangle that the ellipse should fill.</param> public EllipseGeometry(Rect rect) { IPlatformRenderInterface factory = PerspexLocator.Current.GetService <IPlatformRenderInterface>(); IStreamGeometryImpl impl = factory.CreateStreamGeometry(); using (IStreamGeometryContextImpl ctx = impl.Open()) { double controlPointRatio = (Math.Sqrt(2) - 1) * 4 / 3; var center = rect.Center; var radius = new Vector(rect.Width / 2, rect.Height / 2); var x0 = center.X - radius.X; var x1 = center.X - (radius.X * controlPointRatio); var x2 = center.X; var x3 = center.X + (radius.X * controlPointRatio); var x4 = center.X + radius.X; var y0 = center.Y - radius.Y; var y1 = center.Y - (radius.Y * controlPointRatio); var y2 = center.Y; var y3 = center.Y + (radius.Y * controlPointRatio); var y4 = center.Y + radius.Y; ctx.BeginFigure(new Point(x2, y0), true); ctx.BezierTo(new Point(x3, y0), new Point(x4, y1), new Point(x4, y2)); ctx.BezierTo(new Point(x4, y3), new Point(x3, y4), new Point(x2, y4)); ctx.BezierTo(new Point(x1, y4), new Point(x0, y3), new Point(x0, y2)); ctx.BezierTo(new Point(x0, y1), new Point(x1, y0), new Point(x2, y0)); ctx.EndFigure(true); } PlatformImpl = impl; }
/// <summary> /// Initializes a new instance of the <see cref="LineGeometry"/> class. /// </summary> /// <param name="startPoint">The start point.</param> /// <param name="endPoint">The end point.</param> public LineGeometry(Point startPoint, Point endPoint) { _startPoint = startPoint; _endPoint = endPoint; IPlatformRenderInterface factory = AvaloniaLocator.Current.GetService <IPlatformRenderInterface>(); IStreamGeometryImpl impl = factory.CreateStreamGeometry(); using (IStreamGeometryContextImpl context = impl.Open()) { context.BeginFigure(_startPoint, false); context.LineTo(_endPoint); context.EndFigure(false); } PlatformImpl = impl; }
public RectangleGeometry(Rect rect) { IPlatformRenderInterface factory = Locator.Current.GetService <IPlatformRenderInterface>(); IStreamGeometryImpl impl = factory.CreateStreamGeometry(); using (IStreamGeometryContextImpl context = impl.Open()) { context.BeginFigure(rect.TopLeft, true); context.LineTo(rect.TopRight); context.LineTo(rect.BottomRight); context.LineTo(rect.BottomLeft); context.EndFigure(true); } this.PlatformImpl = impl; }
public PolylineGeometry(IList <Point> points, bool isFilled) { _points = points; _isFilled = isFilled; IPlatformRenderInterface factory = PerspexLocator.Current.GetService <IPlatformRenderInterface>(); IStreamGeometryImpl impl = factory.CreateStreamGeometry(); using (IStreamGeometryContextImpl context = impl.Open()) { if (points.Count > 0) { context.BeginFigure(points[0], isFilled); for (int i = 1; i < points.Count; i++) { context.LineTo(points[i]); } context.EndFigure(isFilled); } } PlatformImpl = impl; }
/// <summary> /// Ends the figure started by <see cref="BeginFigure(Point, bool)"/>. /// </summary> /// <param name="isClosed">Whether the figure is closed.</param> public void EndFigure(bool isClosed) { _impl.EndFigure(isClosed); }