Exemple #1
0
        /// <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;
        }
Exemple #2
0
        /// <inheritdoc/>
        protected override IGeometryImpl CreateDefiningGeometry()
        {
            if (_impl == null)
            {
                var factory = AvaloniaLocator.Current.GetService <IPlatformRenderInterface>();
                _impl = factory.CreateStreamGeometry();
            }

            return(_impl);
        }
Exemple #3
0
 public void SetPath(Path path)
 {
     _path                 = path;
     _geometry             = null;
     _geometry             = _path.GetGeometry();
     _originalPathIterator = new CachedPathIteratorFactory(new FullPathIterator(path));
     Length                = _geometry.ContourLength;
     if (Length > 0)
     {
     }
 }
        /// <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;
        }
Exemple #5
0
        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;
        }
Exemple #6
0
        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;
        }
Exemple #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StreamGeometry"/> class.
 /// </summary>
 /// <param name="impl">The platform-specific implementation.</param>
 private StreamGeometry(IStreamGeometryImpl impl)
 {
     _impl = impl;
 }