Exemplo n.º 1
0
        public static SKPath CreateRegularPolygonPath(float radius, int points, SKPathDirection direction = SKPathDirection.Clockwise)
        {
            var path = new SKPath();

            float stepAngle = TotalAngle / points;

            if (direction == SKPathDirection.CounterClockwise)
            {
                stepAngle = -stepAngle;
            }

            for (int p = 0; p < points; p++)
            {
                float angle = stepAngle * p - UprightAngle;
                float x     = radius * (float)Math.Cos(angle);
                float y     = radius * (float)Math.Sin(angle);

                if (p == 0)
                {
                    path.MoveTo(x, y);
                }
                else
                {
                    path.LineTo(x, y);
                }
            }

            path.Close();
            return(path);
        }
Exemplo n.º 2
0
        public static SKPath CreateRectanglePath(float width, float height, SKPathDirection direction = SKPathDirection.Clockwise)
        {
            var path = new SKPath();

            path.AddRect(new SKRect(width / -2, height / -2, width / 2, height / 2), direction);
            path.Close();
            return(path);
        }
Exemplo n.º 3
0
 public void AddRoundRect(SKRoundRect rect, SKPathDirection direction = SKPathDirection.Clockwise)
 {
     if (rect == null)
     {
         throw new ArgumentNullException(nameof(rect));
     }
     SkiaApi.sk_path_add_rrect(Handle, rect.Handle, direction);
 }
Exemplo n.º 4
0
 public void AddRoundRect(SKRoundRect rect, SKPathDirection direction, uint startIndex)
 {
     if (rect == null)
     {
         throw new ArgumentNullException(nameof(rect));
     }
     SkiaApi.sk_path_add_rrect_start(Handle, rect.Handle, direction, startIndex);
 }
Exemplo n.º 5
0
        public void AddRect(SKRect rect, SKPathDirection direction, uint startIndex)
        {
            if (startIndex > 3)
            {
                throw new ArgumentOutOfRangeException(nameof(startIndex), "startIndex must be 0 - 3");
            }

            SkiaApi.sk_path_add_rect_start(Handle, ref rect, direction, startIndex);
        }
Exemplo n.º 6
0
        public void AddRect(SKRect rect, SKPathDirection direction, uint startIndex)
        {
            if (startIndex > 3)
            {
                throw new ArgumentOutOfRangeException(nameof(startIndex), "Starting index must be in the range of 0..3 (inclusive).");
            }

            SkiaApi.sk_path_add_rect_start(Handle, ref rect, direction, startIndex);
        }
Exemplo n.º 7
0
        public SKRect GetRect(out bool isClosed, out SKPathDirection direction)
        {
            var result = SkiaApi.sk_path_is_rect(Handle, out var rect, out isClosed, out direction);

            if (result)
            {
                return(rect);
            }
            else
            {
                return(SKRect.Empty);
            }
        }
Exemplo n.º 8
0
        public static SKPath CreateTrianglePath(float width, float height, SKPathDirection direction = SKPathDirection.Clockwise)
        {
            var path = new SKPath();

            path.MoveTo(0, height / -2);
            if (direction == SKPathDirection.Clockwise)
            {
                path.LineTo(width / -2, height / 2);
                path.LineTo(width / 2, height / 2);
            }
            else
            {
                path.LineTo(width / 2, height / 2);
                path.LineTo(width / -2, height / 2);
            }
            path.Close();
            return(path);
        }
Exemplo n.º 9
0
		public void RArcTo (SKPoint r, float xAxisRotate, SKPathArcSize largeArc, SKPathDirection sweep, SKPoint xy)
		{
			SkiaApi.sk_path_rarc_to (Handle, r.X, r.Y, xAxisRotate, largeArc, sweep, xy.X, xy.Y);
		}
Exemplo n.º 10
0
 public void AddRect(SKRect rect, SKPathDirection direction)
 {
     SkiaApi.sk_path_add_rect(Handle, ref rect, direction);
 }
Exemplo n.º 11
0
		public void RArcTo (float rx, float ry, float xAxisRotate, SKPathArcSize largeArc, SKPathDirection sweep, float x, float y)
		{
			SkiaApi.sk_path_rarc_to (Handle, rx, ry, xAxisRotate, largeArc, sweep, x, y);
		}
Exemplo n.º 12
0
		public void AddCircle (float x, float y, float radius, SKPathDirection dir = SKPathDirection.Clockwise)
		{
			SkiaApi.sk_path_add_circle (Handle, x, y, radius, dir);
		}
Exemplo n.º 13
0
 public static SKPath CreateSquarePath(float side, SKPathDirection direction = SKPathDirection.Clockwise)
 {
     return(CreateRectanglePath(side, side, direction));
 }
Exemplo n.º 14
0
        public static SKPath CreateSectorPath(float start, float end, float outerRadius, float innerRadius = 0.0f, float margin = 0.0f, float explodeDistance = 0.0f, SKPathDirection direction = SKPathDirection.Clockwise)
        {
            var path = new SKPath();

            // if the sector has no size, then it has no path
            if (start == end)
            {
                return(path);
            }

            // the the sector is a full circle, then do that
            if (end - start == 1.0f)
            {
                path.AddCircle(0, 0, outerRadius, direction);
                path.AddCircle(0, 0, innerRadius, direction);
                path.FillType = SKPathFillType.EvenOdd;
                return(path);
            }

            // calculate the angles
            var startAngle        = TotalAngle * start - UprightAngle;
            var endAngle          = TotalAngle * end - UprightAngle;
            var large             = endAngle - startAngle > PI ? SKPathArcSize.Large : SKPathArcSize.Small;
            var sectorCenterAngle = (endAngle - startAngle) / 2f + startAngle;

            // get the radius bits
            var cectorCenterRadius = (outerRadius - innerRadius) / 2f + innerRadius;

            // move explosion around 90 degrees, since matrix use down as 0
            var explosionMatrix = SKMatrix.MakeRotation(sectorCenterAngle - (PI / 2f));
            var offset          = explosionMatrix.MapPoint(new SKPoint(0, explodeDistance));

            // calculate the angle for the margins
            margin = direction == SKPathDirection.Clockwise ? margin : -margin;
            var offsetR = outerRadius == 0 ? 0 : ((margin / (TotalAngle * outerRadius)) * TotalAngle);
            var offsetr = innerRadius == 0 ? 0 : ((margin / (TotalAngle * innerRadius)) * TotalAngle);

            // get the points
            var a = GetCirclePoint(outerRadius, startAngle + offsetR) + offset;
            var b = GetCirclePoint(outerRadius, endAngle - offsetR) + offset;
            var c = GetCirclePoint(innerRadius, endAngle - offsetr) + offset;
            var d = GetCirclePoint(innerRadius, startAngle + offsetr) + offset;

            // add the points to the path
            path.MoveTo(a);
            path.ArcTo(outerRadius, outerRadius, 0, large, direction, b.X, b.Y);
            path.LineTo(c);
            if (innerRadius == 0.0f)
            {
                // take a short cut
                path.LineTo(d);
            }
            else
            {
                var reverseDirection = direction == SKPathDirection.Clockwise ? SKPathDirection.CounterClockwise : SKPathDirection.Clockwise;
                path.ArcTo(innerRadius, innerRadius, 0, large, reverseDirection, d.X, d.Y);
            }
            path.Close();

            return(path);
        }
Exemplo n.º 15
0
		public void AddRect (SKRect rect, SKPathDirection direction, uint startIndex)
		{
			if (startIndex > 3)
				throw new ArgumentOutOfRangeException (nameof (startIndex), "startIndex must be 0 - 3");

			SkiaApi.sk_path_add_rect_start (Handle, ref rect, direction, startIndex);
		}
Exemplo n.º 16
0
		public void AddRect (SKRect rect, SKPathDirection direction, uint startIndex)
		{
			if (startIndex > 3)
				throw new ArgumentOutOfRangeException (nameof (startIndex), "Starting index must be in the range of 0..3 (inclusive).");

			SkiaApi.sk_path_add_rect_start (Handle, ref rect, direction, startIndex);
		}
Exemplo n.º 17
0
		public void AddOval (SKRect rect, SKPathDirection direction = SKPathDirection.Clockwise)
		{
			SkiaApi.sk_path_add_oval (Handle, ref rect, direction);
		}
Exemplo n.º 18
0
		public extern static void sk_path_add_circle (sk_path_t t, float x, float y, float radius, SKPathDirection dir);
Exemplo n.º 19
0
		public extern static void sk_path_add_rounded_rect (sk_path_t t, ref SKRect rect, float rx, float ry, SKPathDirection dir);
Exemplo n.º 20
0
		public extern static void sk_path_rarc_to (sk_path_t t, float rx, float ry, float xAxisRotate, SKPathArcSize largeArc, SKPathDirection sweep, float x, float y);
Exemplo n.º 21
0
		public extern static void sk_path_add_oval(sk_path_t t, ref SKRect rect, SKPathDirection direction);
Exemplo n.º 22
0
		public extern static void sk_path_add_rect_start(sk_path_t t, ref SKRect rect, SKPathDirection direction, uint startIndex);
Exemplo n.º 23
0
 public void AddRoundedRect(SKRect rect, float rx, float ry, SKPathDirection dir = SKPathDirection.Clockwise)
 {
     SkiaApi.sk_path_add_rounded_rect(Handle, ref rect, rx, ry, dir);
 }
Exemplo n.º 24
0
 public static SKPath CreateTrianglePath(float radius, SKPathDirection direction = SKPathDirection.Clockwise)
 {
     return(CreateRegularPolygonPath(radius, 3, direction));
 }
Exemplo n.º 25
0
		public void AddRect (SKRect rect, SKPathDirection direction)
		{
			SkiaApi.sk_path_add_rect (Handle, ref rect, direction);
		}
Exemplo n.º 26
0
        public static SKPath CreateRegularStarPath(float outerRadius, float innerRadius, int points, SKPathDirection direction = SKPathDirection.Clockwise)
        {
            var path = new SKPath();

            bool isInner = false;

            points *= 2;

            float stepAngle = TotalAngle / points;

            if (direction == SKPathDirection.CounterClockwise)
            {
                stepAngle = -stepAngle;
            }

            for (int p = 0; p < points; p++)
            {
                float radius = isInner ? innerRadius : outerRadius;

                float angle = stepAngle * p - UprightAngle;
                float x     = radius * (float)Math.Cos(angle);
                float y     = radius * (float)Math.Sin(angle);

                if (p == 0)
                {
                    path.MoveTo(x, y);
                }
                else
                {
                    path.LineTo(x, y);
                }

                isInner = !isInner;
            }

            path.Close();
            return(path);
        }
Exemplo n.º 27
0
 public extern static void sk_path_add_oval(sk_path_t t, ref SKRect rect, SKPathDirection direction);
Exemplo n.º 28
0
        public static SKPath CreatePiePath(IEnumerable <float> sectorSizes, float outerRadius, float innerRadius = 0.0f, float spacing = 0.0f, float explodeDistance = 0.0f, SKPathDirection direction = SKPathDirection.Clockwise)
        {
            var path = new SKPath();

            float cursor = 0;
            var   sum    = sectorSizes.Sum();

            foreach (var sectorSize in sectorSizes)
            {
                var sector = CreateSectorPath(cursor, cursor + sectorSize, outerRadius, innerRadius, spacing / 2f, explodeDistance, direction);

                cursor += sectorSize;

                path.AddPath(sector, SKPath.AddMode.Append);
            }

            return(path);
        }
Exemplo n.º 29
0
 public void RArcTo(SKPoint r, float xAxisRotate, SKPathArcSize largeArc, SKPathDirection sweep, SKPoint xy)
 {
     SkiaApi.sk_path_rarc_to(Handle, r.X, r.Y, xAxisRotate, largeArc, sweep, xy.X, xy.Y);
 }
Exemplo n.º 30
0
 public void RArcTo(float rx, float ry, float xAxisRotate, SKPathArcSize largeArc, SKPathDirection sweep, float x, float y)
 {
     SkiaApi.sk_path_rarc_to(Handle, rx, ry, xAxisRotate, largeArc, sweep, x, y);
 }
Exemplo n.º 31
0
		public void AddRoundedRect (SKRect rect, float rx, float ry, SKPathDirection dir = SKPathDirection.Clockwise)
		{
			SkiaApi.sk_path_add_rounded_rect (Handle, ref rect, rx, ry, dir);
		}
Exemplo n.º 32
0
 public void AddOval(SKRect rect, SKPathDirection direction = SKPathDirection.Clockwise)
 {
     SkiaApi.sk_path_add_oval(Handle, ref rect, direction);
 }
Exemplo n.º 33
0
 public void AddRoundedRect(SKRect rect, float rx, float ry, SKPathDirection dir = SKPathDirection.Clockwise)
 {
     AddRoundRect(rect, rx, ry, dir);
 }
Exemplo n.º 34
0
 public void AddCircle(float x, float y, float radius, SKPathDirection dir = SKPathDirection.Clockwise)
 {
     SkiaApi.sk_path_add_circle(Handle, x, y, radius, dir);
 }
Exemplo n.º 35
0
        public static void AddRoundedRect(this SKPath path, SKRect rectangleRect, float[] rectangleCornerRadii, SKPathDirection direction)
        {
            if (rectangleCornerRadii[0] == 0f)
            {
                path.MoveTo(rectangleRect.Left, rectangleRect.Top);
            }
            else
            {
                path.MoveTo(rectangleRect.Left, rectangleRect.Bottom);
                path.ArcTo(rectangleRect.Left, rectangleRect.Top, rectangleRect.Right, rectangleRect.Top, rectangleCornerRadii[0]);
            }

            if (rectangleCornerRadii[2] == 0f)
            {
                path.LineTo(rectangleRect.Right, rectangleRect.Top);
            }
            else
            {
                path.ArcTo(rectangleRect.Right, rectangleRect.Top, rectangleRect.Right, rectangleRect.Bottom, rectangleCornerRadii[2]);
            }

            if (rectangleCornerRadii[4] == 0f)
            {
                path.LineTo(rectangleRect.Right, rectangleRect.Bottom);
            }
            else
            {
                path.ArcTo(rectangleRect.Right, rectangleRect.Bottom, rectangleRect.Left, rectangleRect.Bottom, rectangleCornerRadii[4]);
            }

            if (rectangleCornerRadii[6] == 0f)
            {
                path.LineTo(rectangleRect.Left, rectangleRect.Bottom);
            }
            else
            {
                path.ArcTo(rectangleRect.Left, rectangleRect.Bottom, rectangleRect.Left, rectangleRect.Top, rectangleCornerRadii[6]);
            }
        }