Пример #1
0
        public void PathPointsAreCorrect()
        {
            using (var path = new SKPath ()) {
                // set up the xamagon
                path.MoveTo (71.4311121f, 56f);
                path.CubicTo (68.6763107f, 56.0058575f, 65.9796704f, 57.5737917f, 64.5928855f, 59.965729f);
                path.LineTo (43.0238921f, 97.5342563f);
                path.CubicTo (41.6587026f, 99.9325978f, 41.6587026f, 103.067402f, 43.0238921f, 105.465744f);
                path.LineTo (64.5928855f, 143.034271f);
                path.CubicTo (65.9798162f, 145.426228f, 68.6763107f, 146.994582f, 71.4311121f, 147f);
                path.LineTo (114.568946f, 147f);
                path.CubicTo (117.323748f, 146.994143f, 120.020241f, 145.426228f, 121.407172f, 143.034271f);
                path.LineTo (142.976161f, 105.465744f);
                path.CubicTo (144.34135f, 103.067402f, 144.341209f, 99.9325978f, 142.976161f, 97.5342563f);
                path.LineTo (121.407172f, 59.965729f);
                path.CubicTo (120.020241f, 57.5737917f, 117.323748f, 56.0054182f, 114.568946f, 56f);
                path.LineTo (71.4311121f, 56f);
                path.Close ();

                // the right number/count
                Assert.AreEqual (25, path.PointCount);
                Assert.AreEqual (25, path.Points.Length);

                // the right value
                Assert.AreEqual (new SKPoint (68.6763107f, 56.0058575f), path.GetPoint (1));
                Assert.AreEqual (new SKPoint (68.6763107f, 56.0058575f), path.Points [1]);
            }
        }
Пример #2
0
        public static SKPath ToRoundedRectPath(this SKRectI bounds, CornerRadius cornerRadius)
        {
            var path        = new SKPath();
            var skRoundRect = new SKRoundRect(bounds);

            SKPoint[] radii = new SKPoint[4]
            {
                new SKPoint((float)cornerRadius.TopLeft, (float)cornerRadius.TopLeft),
                new SKPoint((float)cornerRadius.TopRight, (float)cornerRadius.TopRight),
                new SKPoint((float)cornerRadius.BottomRight, (float)cornerRadius.BottomRight),
                new SKPoint((float)cornerRadius.BottomLeft, (float)cornerRadius.BottomLeft)
            };
            skRoundRect.SetRectRadii(skRoundRect.Rect, radii);
            path.AddRoundRect(skRoundRect);
            path.Close();
            return(path);
        }
Пример #3
0
        protected void DrawArea(SKCanvas canvas, SKPoint[] points, SKSize itemSize, float origin)
        {
            if (this.LineAreaAlpha > 0 && points.Length > 1)
            {
                using (var paint = new SKPaint
                {
                    Style = SKPaintStyle.Fill,
                    Color = SKColors.White,
                    IsAntialias = true,
                })
                {
                    using (var shaderX = this.CreateXGradient(points, (byte)(this.LineAreaAlpha * this.AnimationProgress)))
                        using (var shaderY = this.CreateYGradient(points, (byte)(this.LineAreaAlpha * this.AnimationProgress)))
                        {
                            paint.Shader = EnableYFadeOutGradient ? SKShader.CreateCompose(shaderY, shaderX, SKBlendMode.SrcOut) : shaderX;

                            var path = new SKPath();

                            path.MoveTo(points.First().X, origin);
                            path.LineTo(points.First());

                            var last = (this.LineMode == LineMode.Spline) ? points.Length - 1 : points.Length;
                            for (int i = 0; i < last; i++)
                            {
                                if (this.LineMode == LineMode.Spline)
                                {
                                    var entry     = this.Entries.ElementAt(i);
                                    var nextEntry = this.Entries.ElementAt(i + 1);
                                    var cubicInfo = this.CalculateCubicInfo(points, i, itemSize);
                                    path.CubicTo(cubicInfo.control, cubicInfo.nextControl, cubicInfo.nextPoint);
                                }
                                else if (this.LineMode == LineMode.Straight)
                                {
                                    path.LineTo(points[i]);
                                }
                            }

                            path.LineTo(points.Last().X, origin);

                            path.Close();

                            canvas.DrawPath(path, paint);
                        }
                }
            }
        }
Пример #4
0
        void UpdateShape()
        {
            if (_points != null && _points.Count > 1)
            {
                SKPath path = new SKPath();
                path.FillType = _fillMode ? SKPathFillType.Winding : SKPathFillType.EvenOdd;

                path.MoveTo(Forms.ConvertToScaledPixel(_points[0].X), Forms.ConvertToScaledPixel(_points[0].Y));
                for (int index = 1; index < _points.Count; index++)
                {
                    path.LineTo(Forms.ConvertToScaledPixel(_points[index].X), Forms.ConvertToScaledPixel(_points[index].Y));
                }
                path.Close();

                UpdateShape(path);
            }
        }
Пример #5
0
        void UpdateShape()
        {
            if (_points != null && _points.Count > 1)
            {
                SKPath path = new SKPath();
                path.FillType = _fillMode ? SKPathFillType.Winding : SKPathFillType.EvenOdd;

                path.MoveTo((float)_points[0].X, (float)_points[0].Y);
                for (int index = 1; index < _points.Count; index++)
                {
                    path.LineTo((float)_points[index].X, (float)_points[index].Y);
                }
                path.Close();

                UpdateShape(path);
            }
        }
Пример #6
0
        protected void DrawArea(SKCanvas canvas, SKPoint[] points, SKSize itemSize, float origin, List <Entry> entries)
        {
            if (this.LineAreaAlpha > 0 && points.Length > 1)
            {
                using (var paint = new SKPaint
                {
                    Style = SKPaintStyle.Fill,
                    Color = SKColors.White,
                    IsAntialias = true,
                })
                {
                    using (var shader = this.CreateGradient(points, entries, this.LineAreaAlpha))
                    {
                        paint.Shader = shader;

                        var path = new SKPath();

                        path.MoveTo(points.First().X, origin);
                        path.LineTo(points.First());

                        var last = (this.LineMode == LineMode.Spline) ? points.Length - 1 : points.Length;
                        for (int i = 0; i < last; i++)
                        {
                            if (this.LineMode == LineMode.Spline)
                            {
                                var entry     = entries.ElementAt(i);
                                var nextEntry = entries.ElementAt(i + 1);
                                var cubicInfo = this.CalculateCubicInfo(points, i, itemSize);
                                path.CubicTo(cubicInfo.control, cubicInfo.nextControl, cubicInfo.nextPoint);
                            }
                            else if (this.LineMode == LineMode.Straight)
                            {
                                path.LineTo(points[i]);
                            }
                        }

                        path.LineTo(points.Last().X, origin);

                        path.Close();

                        canvas.DrawPath(path, paint);
                    }
                }
            }
        }
Пример #7
0
 public /*interface ChartPainter*/ void DrawCourseFill(List <KChartEntry> list, int seriesIndex, float bottom, SKColor color, Swipe pinchPan)
 {
     if (list.Count > 1)
     {
         using (var paint = FillPaint(color)) {
             var path = new SKPath();
             path.MoveTo(pinchPan % new SKPoint(list[0].Ypoint[seriesIndex].X, bottom));
             path.LineTo(pinchPan % list[0].Ypoint[seriesIndex]);
             for (int i = 0; i < list.Count; i++)
             {
                 path.LineTo(pinchPan % list[i].Ypoint[seriesIndex]);
             }
             path.LineTo(pinchPan % new SKPoint(list[list.Count - 1].Ypoint[seriesIndex].X, bottom));
             path.Close();
             canvas.DrawPath(path, paint);
         }
     }
 }
Пример #8
0
        private static SKPath ToSKPath(this PathFigure figure)
        {
            SKPath sk = new SKPath();

            sk.MoveTo(figure.StartPoint.ToSKPoint());

            foreach (var segment in figure.Segments)
            {
                sk.AddSegment(segment);
            }

            if (figure.IsClosed)
            {
                sk.Close();
            }

            return(sk);
        }
Пример #9
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);
        }
Пример #10
0
        public async Task CreateLeftAnnotation(FishModel fish)
        {
            SKBitmap bitmap = await CreateBaseAnnotation(fish);

            using (SKCanvas canvas = new SKCanvas(bitmap))
            {
                // draw the arrow
                SKPath path       = new SKPath();
                var    halfHeight = (float)(bitmap.Height * .5);
                path.MoveTo(0, halfHeight);
                path.LineTo(padding, halfHeight - padding);
                path.LineTo(padding, halfHeight + padding);
                path.LineTo(0, halfHeight);
                path.Close();
                canvas.DrawPath(path, annotationBackground);
            }
            LeftAnnotation = bitmap;
        }
Пример #11
0
        private void SkCanvasView_OnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            // Init skcanvas
            SKImageInfo skImageInfo = e.Info;
            SKSurface   skSurface   = e.Surface;
            SKCanvas    skCanvas    = skSurface.Canvas;

            skCanvas.Clear(SKColors.White);

            var skCanvasWidth  = skImageInfo.Width;
            var skCanvasHeight = skImageInfo.Height;


            // move canvas X,Y to center of screen
            skCanvas.Translate((float)skCanvasWidth / 2, (float)skCanvasHeight / 2);

            // move canvas X,Y to center of screen
            skCanvas.Scale((float)skCanvasWidth / 200);


            // Draw any kind of Shape
            SKPaint strokePaint = new SKPaint
            {
                Style       = SKPaintStyle.Stroke,
                Color       = SKColors.Black,
                StrokeWidth = 10,
                IsAntialias = true,
            };

            // Create the path
            SKPath path = new SKPath();

            // Define the drawing path points
            path.MoveTo(+50, 0);   // start point
            path.LineTo(+50, -50); // first move to this point
            path.LineTo(-30, -80); // move to this point
            path.LineTo(-70, 0);   // then move to this point
            path.LineTo(-10, +90); // then move to this point
            path.LineTo(+50, 0);   // end point

            path.Close();          // make sure path is closed
            // Fill and stroke the path
            skCanvas.DrawPath(path, strokePaint);
        }
Пример #12
0
        void OnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            var geometry = ContentNativeView == null ? NativeView.Geometry : ContentNativeView.Geometry;
            var canvas = e.Surface.Canvas;
            canvas.Clear();

            var path = new SKPath();
            var left = geometry.Left - _canvasView.Geometry.Left;
            var top = geometry.Top - _canvasView.Geometry.Top;
            var rect = new SKRect(left, top, left + geometry.Width, top + geometry.Height);
            var scaledRadius = Forms.ConvertToScaledPixel(ShadowsElement.CornerRadius) * 2;
            var topLeft = new SKRect(rect.Left, rect.Top, rect.Left + scaledRadius, rect.Top + scaledRadius);
            var topRight = new SKRect(rect.Right - scaledRadius, rect.Top, rect.Right, rect.Top + scaledRadius);
            var bottomLeft = new SKRect(rect.Left, rect.Bottom - scaledRadius, rect.Left + scaledRadius, rect.Bottom);
            var bottomRight = new SKRect(rect.Right - scaledRadius, rect.Bottom - scaledRadius, rect.Right, rect.Bottom);
            path.ArcTo(topLeft, 180, 90, false);
            path.ArcTo(topRight, 270, 90, false);
            path.ArcTo(bottomRight, 0, 90, false);
            path.ArcTo(bottomLeft, 90, 90, false);
            path.Close();

            using (var paint = new SKPaint())
            {
                paint.IsAntialias = true;
                paint.Style = SKPaintStyle.StrokeAndFill;
                foreach (var shade in _shadesSource)
                {
                    var scaledOffsetX = Forms.ConvertToScaledPixel(shade.Offset.X);
                    var scaledOffsetY = Forms.ConvertToScaledPixel(shade.Offset.Y);
                    var scaledBlurRadius = Forms.ConvertToScaledPixel(shade.BlurRadius);

                    canvas.Save();
                    canvas.ClipPath(path, SKClipOperation.Difference, true);
                    paint.ImageFilter = SKImageFilter.CreateDropShadow(scaledOffsetX, scaledOffsetY, scaledBlurRadius, scaledBlurRadius, shade.Color.ToSK(), SKDropShadowImageFilterShadowMode.DrawShadowOnly);
                    canvas.DrawPath(path, paint);
                    canvas.Restore();

                    canvas.Save();
                    canvas.ClipPath(path, SKClipOperation.Intersect, true);
                    canvas.DrawPath(path, paint);
                    canvas.Restore();
                }
            }
        }
Пример #13
0
        protected void DrawArea(IEnumerable <Entry> serie, SKCanvas canvas, SKPoint[] points, SKSize itemSize, float origin)
        {
            if (LineAreaAlpha > 0 && points.Length > 1)
            {
                using (var paint = new SKPaint
                {
                    Style = SKPaintStyle.Fill,
                    Color = SKColors.White,
                    IsAntialias = true,
                })
                {
                    var entries = serie as Entry[] ?? serie.ToArray();
                    using (var shader = CreateGradient(entries, points, LineAreaAlpha))
                    {
                        paint.Shader = shader;

                        var path = new SKPath();

                        path.MoveTo(points.First().X, origin);
                        path.LineTo(points.First());

                        var last = LineMode == LineMode.Spline ? points.Length - 1 : points.Length;
                        for (int i = 0; i < last; i++)
                        {
                            if (LineMode == LineMode.Spline)
                            {
                                var cubicInfo = CalculateCubicInfo(points, i, itemSize);
                                path.CubicTo(cubicInfo.control, cubicInfo.nextControl, cubicInfo.nextPoint);
                            }
                            else if (LineMode == LineMode.Straight)
                            {
                                path.LineTo(points[i]);
                            }
                        }

                        path.LineTo(points.Last().X, origin);

                        path.Close();

                        canvas.DrawPath(path, paint);
                    }
                }
            }
        }
Пример #14
0
        internal static SKPath BuildEllipseGeometry(Vector2 center, Vector2 radius)
        {
            SKRect rect = SKRect.Create(center.X - radius.X, center.Y - radius.Y, radius.X * 2, radius.Y * 2);

            float bezierX = (float)((1.0 - CIRCLE_BEZIER_KAPPA) * radius.X);
            float bezierY = (float)((1.0 - CIRCLE_BEZIER_KAPPA) * radius.Y);

            // IMPORTANT:
            // - The order of following operations is important for dashed strokes.
            // - Stroke might get merged in the end.
            // - WPF starts with bottom right ellipse arc.
            // - TODO: Verify UWP behavior

            SKPath path = new SKPath();

            path.MoveTo(new SKPoint(rect.Right, rect.Top + radius.Y));
            // Bottom-right Arc
            path.CubicTo(
                new SKPoint(rect.Right, rect.Bottom - bezierY),                  // 1st control point
                new SKPoint(rect.Right - bezierX, rect.Bottom),                  // 2nd control point
                new SKPoint(rect.Right - radius.X, rect.Bottom));                // End point

            // Bottom-left Arc
            path.CubicTo(
                new SKPoint(rect.Left + bezierX, rect.Bottom),                      // 1st control point
                new SKPoint(rect.Left, rect.Bottom - bezierY),                      // 2nd control point
                new SKPoint(rect.Left, rect.Bottom - radius.Y));                    // End point

            // Top-left Arc
            path.CubicTo(
                new SKPoint(rect.Left, rect.Top + bezierY),                           // 1st control point
                new SKPoint(rect.Left + bezierX, rect.Top),                           // 2nd control point
                new SKPoint(rect.Left + radius.X, rect.Top));                         // End point

            // Top-right Arc
            path.CubicTo(
                new SKPoint(rect.Right - bezierX, rect.Top),                       // 1st control point
                new SKPoint(rect.Right, rect.Top + bezierY),                       // 2nd control point
                new SKPoint(rect.Right, rect.Top + radius.Y));                     // End point

            path.Close();

            return(path);
        }
Пример #15
0
        public override void DrawImage(SKCanvas dc)
        {
            if (NeedsToClear == true)
            {
                dc.Clear();
            }
            SKRect rect_Piece;

            rect_Piece = GetMainRect();
            SKRect rect_Base;

            rect_Base = SKRect.Create(rect_Piece.Left, (rect_Piece.Top + rect_Piece.Height) - (rect_Piece.Height / 8), rect_Piece.Width, rect_Piece.Height / 8);
            SKPath gp_Temp;

            SKPoint[] pts_Curve;
            gp_Temp      = new SKPath();
            pts_Curve    = new SKPoint[3];
            pts_Curve[0] = new SKPoint(rect_Piece.Left + (rect_Piece.Width / 2), rect_Piece.Top + (rect_Piece.Height / 8));
            pts_Curve[1] = new SKPoint(rect_Piece.Left + (rect_Piece.Width / 3), rect_Piece.Top + ((rect_Piece.Height * 8) / 11));
            pts_Curve[2] = new SKPoint(rect_Piece.Left, (rect_Piece.Top + rect_Piece.Height) - rect_Base.Height);
            gp_Temp.MoveTo(pts_Curve[0]);
            gp_Temp.LineTo(pts_Curve[1]);
            gp_Temp.LineTo(pts_Curve[2]);
            pts_Curve    = new SKPoint[3];
            pts_Curve[0] = new SKPoint(rect_Piece.Left + rect_Piece.Width, (rect_Piece.Top + rect_Piece.Height) - rect_Base.Height);
            pts_Curve[1] = new SKPoint((rect_Piece.Left + rect_Piece.Width) - (rect_Piece.Width / 3), rect_Piece.Top + ((rect_Piece.Height * 8) / 11));
            pts_Curve[2] = new SKPoint(rect_Piece.Left + (rect_Piece.Width / 2), rect_Piece.Top + (rect_Piece.Height / 8));
            SKRect rect_Temp;
            float  int_Temp;

            int_Temp  = rect_Piece.Width / 3;
            rect_Temp = SKRect.Create(rect_Piece.Left + (rect_Piece.Width / 2) - (int_Temp / 2), rect_Piece.Top, int_Temp, int_Temp);
            gp_Temp.LineTo(pts_Curve[0]);
            gp_Temp.LineTo(pts_Curve[1]);
            gp_Temp.LineTo(pts_Curve[2]);
            gp_Temp.Close();
            dc.DrawPath(gp_Temp, MainPaint);
            dc.DrawPath(gp_Temp, _borderPaint);
            dc.DrawOval(rect_Temp, _borderPaint);
            dc.DrawOval(rect_Temp, MainPaint);
            dc.DrawRect(rect_Base, MainPaint);
            dc.DrawRect(rect_Base, _borderPaint);
        }
Пример #16
0
        private void drawSlice(double startAngle, double angleAmount, SKCanvas canvas, SKColor color, int width, int height, SKRect chartRect /*string label*/)
        {
            SKPoint center     = new SKPoint(chartRect.MidX, chartRect.MidY);
            var     finalAngle = startAngle + angleAmount;

            using (var path = new SKPath())
            {
                using (var paint = new SKPaint())
                {
                    path.MoveTo(center);
                    path.ArcTo(chartRect, (float)startAngle, (float)angleAmount, false);
                    path.Close();
                    paint.Style       = SKPaintStyle.Fill;
                    paint.Color       = color;
                    paint.IsAntialias = true;
                    canvas.DrawPath(path, paint);
                }
            }
        }
Пример #17
0
        public MainPage()
        {
            InitializeComponent();

            // Make cat ear path
            catEarPath.MoveTo(0, 0);
            catEarPath.LineTo(0, 75);
            catEarPath.LineTo(100, 75);
            catEarPath.Close();

            // Make cat eye path
            catEyePath.MoveTo(0, 0);
            catEyePath.ArcTo(50, 50, 0, SKPathArcSize.Small, SKPathDirection.Clockwise, 50, 0);
            catEyePath.ArcTo(50, 50, 0, SKPathArcSize.Small, SKPathDirection.Clockwise, 0, 0);
            catEyePath.Close();

            // Make eye pupil path
            catPupilPath.MoveTo(25, -5);
            catPupilPath.ArcTo(6, 6, 0, SKPathArcSize.Small, SKPathDirection.Clockwise, 25, 5);
            catPupilPath.ArcTo(6, 6, 0, SKPathArcSize.Small, SKPathDirection.Clockwise, 25, -5);
            catPupilPath.Close();

            // Make cat tail path
            catTailPath.MoveTo(0, 100);
            catTailPath.CubicTo(50, 200, 0, 250, -50, 200);

            // Create Shader
            Assembly assembly = GetType().GetTypeInfo().Assembly;

            using (Stream stream = assembly.GetManifestResourceStream("SkiaWithXamarin.WoodGrain.png"))
                using (SKManagedStream skStream = new SKManagedStream(stream))
                    using (SKBitmap bitmap = SKBitmap.Decode(skStream))
                        using (SKShader shader = SKShader.CreateBitmap(bitmap, SKShaderTileMode.Mirror, SKShaderTileMode.Mirror))
                        {
                            backgroundFillPaint.Shader = shader;
                        }

            Device.StartTimer(TimeSpan.FromSeconds(1f / 60), () =>
            {
                canvasView.InvalidateSurface();
                return(true);
            });
        }
        SKPath GetRoundRectPath(bool isShadow)
        {
            var geometry = NativeView.Geometry;

            if (ShadowElement.Content != null)
            {
                var contentNativeView = Platform.GetOrCreateRenderer(ShadowElement.Content)?.NativeView;
                if (contentNativeView != null)
                {
                    geometry = contentNativeView.Geometry;
                }
            }

            var canvasViewGeometry = !UseShadowClipping && isShadow ? _shadowCanvasView.Geometry : BackgroundCanvas.Geometry;
            var path    = new SKPath();
            var padding = Convert.ToSingle(ShadowElement.BorderWidth);

            // Set margin for shadow in case of using shadow clip.
            if (UseShadowClipping)
            {
                padding += Forms.ConvertToScaledPixel(ShadowElement.ShadowClippingWidth);
            }
            var left           = geometry.Left - canvasViewGeometry.Left + padding;
            var top            = geometry.Top - canvasViewGeometry.Top + padding;
            var right          = left + geometry.Width - (padding * 2);
            var bottom         = top + geometry.Height - (padding * 2);
            var rect           = new SKRect(left, top, right, bottom);
            var scaledTLRadius = Forms.ConvertToScaledPixel(ShadowElement.CornerRadius.TopLeft) * 2;
            var scaledTRRadius = Forms.ConvertToScaledPixel(ShadowElement.CornerRadius.TopRight) * 2;
            var scaledBLRadius = Forms.ConvertToScaledPixel(ShadowElement.CornerRadius.BottomLeft) * 2;
            var scaledBRRadius = Forms.ConvertToScaledPixel(ShadowElement.CornerRadius.BottomRight) * 2;
            var topLeft        = new SKRect(rect.Left, rect.Top, rect.Left + scaledTLRadius, rect.Top + scaledTLRadius);
            var topRight       = new SKRect(rect.Right - scaledTRRadius, rect.Top, rect.Right, rect.Top + scaledTRRadius);
            var bottomLeft     = new SKRect(rect.Left, rect.Bottom - scaledBLRadius, rect.Left + scaledBLRadius, rect.Bottom);
            var bottomRight    = new SKRect(rect.Right - scaledBRRadius, rect.Bottom - scaledBRRadius, rect.Right, rect.Bottom);

            path.ArcTo(topLeft, 180, 90, false);
            path.ArcTo(topRight, 270, 90, false);
            path.ArcTo(bottomRight, 0, 90, false);
            path.ArcTo(bottomLeft, 90, 90, false);
            path.Close();
            return(path);
        }
Пример #19
0
        public void DrawTriangle(Color color, Point point, int rotationDegrees = 0)
        {
            SKPaint paint = new SKPaint {
                Color = FromColor(color), Style = SKPaintStyle.Fill, IsAntialias = true
            };

            SKPath path = new SKPath();

            // TODO - Make the triangle variable size
            path.MoveTo(new SKPoint(point.X, point.Y));
            path.LineTo(new SKPoint(point.X + 100, point.Y));
            path.LineTo(new SKPoint(point.X + 50f, point.Y + 86.6f));
            path.MoveTo(new SKPoint(point.X, point.Y));
            path.Close();
            CurrentCanvas.Save();
            CurrentCanvas.RotateDegrees(rotationDegrees, point.X + 50, point.Y + 28.86f);
            CurrentCanvas.DrawPath(path, paint);
            CurrentCanvas.Restore();
        }
Пример #20
0
        private static SKPath ToPath(IEnumerable <SKPoint> points)
        {
            var path = new SKPath();

            foreach (var point in points)
            {
                if (path.Points.Length == 0)
                {
                    path.MoveTo(point);
                }
                else
                {
                    path.LineTo(point);
                }
            }
            path.Close();

            return(path);
        }
Пример #21
0
        private void CanvasView_OnPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            var skCanvas = args.Surface.Canvas;

            float width  = args.Info.Width;
            float height = args.Info.Height;

            skCanvas.Clear(SKColors.White);
            SKPaint strokePaint = new SKPaint
            {
                Style       = SKPaintStyle.Fill,
                Color       = SKColors.LightPink,
                StrokeWidth = 25,
            };

            //SKColor shadowColor = new SKColor(0, 0, 0, 70);
            //strokePaint.ImageFilter = SKImageFilter.CreateDropShadow(
            //    0f, 20f, 0f, 20f, shadowColor, SKDropShadowImageFilterShadowMode.DrawShadowAndForeground, null, null);

            SKPath path = new SKPath();

            //top left point, has x = 0 and y = 0
            path.MoveTo(25, 0); // start point
            path.LineTo(width - 25, 0);
            path.LineTo(width, 25);
            path.LineTo(width, height - 25);
            path.LineTo(width - 25, height);
            path.LineTo(25, height);
            path.LineTo(0, height - 25);
            path.LineTo(0, 25);
            path.LineTo(25, 0);


            //path.MoveTo(250, 250); // start point
            //path.LineTo(300,300);



            path.Close();

            skCanvas.DrawPath(path, strokePaint);
        }
Пример #22
0
        private static void DrawCard(float xOffset, float yOffset, SKCanvas canvas)
        {
            SKPaint paintCard = new SKPaint
            {
                Style       = SKPaintStyle.Stroke,
                Color       = Color.Black.ToSKColor(),
                StrokeWidth = 2,
            };
            var path = new SKPath();

            var cardWith   = 120.0f;
            var cardHeight = 180.0f;

            path.MoveTo(0.0f, 0.0f);
            path.LineTo(0.0f, 1.0f);
            path.LineTo(0.7f, 1.0f);
            path.LineTo(0.7f, 0.0f);
            path.Close();
            path.Transform(SKMatrix.MakeRotation((float)(45.0f * Math.PI / 180), 0.7f, 1.0f));
            path.Transform(SKMatrix.MakeScale(cardWith, cardHeight));
            path.Offset(xOffset, yOffset);

            canvas.DrawPath(path, paintCard);


            var pathHeart = new SKPath();

            pathHeart.MoveTo(0.5f, 1.0f);
            pathHeart.LineTo(0.0f, 0.4f);
            pathHeart.CubicTo(0.0f, 0.0f,
                              0.5f, 0.0f,
                              0.5f, 0.4f);
            pathHeart.CubicTo(0.5f, 0.0f,
                              1.0f, 0.0f,
                              1.0f, 0.4f);
            pathHeart.LineTo(0.5f, 1.0f);
            pathHeart.Close();
            pathHeart.Transform(SKMatrix.MakeScale(cardWith, cardHeight));
            pathHeart.Offset(xOffset, yOffset);

            canvas.DrawPath(pathHeart, paintCard);
        }
Пример #23
0
        SKPath pathtopintfarr(GraphicsPath path)
        {
            var ans = new SKPath();

            var cubic = new List <PointF>();

            for (int i = 0; i < path.PointCount; i++)
            {
                if (path.PathTypes[i] == 0)
                {
                    ans.MoveTo(path.PathPoints[i].X, path.PathPoints[i].Y);
                    continue;
                }

                if ((path.PathTypes[i] & 0x7) == 1)
                {
                    ans.LineTo(path.PathPoints[i].X, path.PathPoints[i].Y);
                }

                if ((path.PathTypes[i] & 0x7) == 3)
                {
                    /* first bezier requires 4 points, other 3 more points */
                    cubic.Add(path.PathPoints[i]);
                    if (cubic.Count == 3)
                    {
                        ans.CubicTo(cubic[0].X, cubic[0].Y, cubic[1].X, cubic[1].Y, cubic[2].X, cubic[2].Y);
                        cubic.Clear();
                    }
                }

                //if ((path.PathTypes[i] & 0x20) > 0)
                //list.Add(path.PathPoints[i]);

                if ((path.PathTypes[i] & 0x80) > 0)
                {
                    ans.LineTo(path.PathPoints[i].X, path.PathPoints[i].Y);
                    ans.Close();
                }
            }

            return(ans);
        }
Пример #24
0
        private void CanvasView_PaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            SKImageInfo imageInfo = e.Info;
            SKSurface   surface   = e.Surface;
            SKCanvas    canvas    = surface.Canvas;

            canvas.Clear();

            SKPath path = new SKPath();

            path.MoveTo(100, 100);
            path.LineTo(160, 100);
            path.LineTo(160, 150);
            path.LineTo(100, 150);

            var centerX = imageInfo.Width / 2;
            var centerY = imageInfo.Height / 2;

            path.MoveTo(centerX, centerY);
            path.LineTo(centerX - 50, centerY + 50);
            path.LineTo(centerX + 100, centerY + 50);
            path.Close();

            float[] array = { 10, 10 };
            SKPaint paint = new SKPaint
            {
                Style       = SKPaintStyle.Stroke,
                Color       = Color.Aqua.ToSKColor(),
                StrokeWidth = 40,
                PathEffect  = SKPathEffect.CreateDash(array, 10)
            };

            SKPaint fillPaint = new SKPaint
            {
                Style = SKPaintStyle.Fill,
                Color = Color.Red.ToSKColor()
            };

            paint.StrokeJoin = SKStrokeJoin.Miter;
            canvas.DrawPath(path, paint);
            canvas.DrawPath(path, fillPaint);
        }
Пример #25
0
        /// <summary>
        /// Creates a polygon, whichs corners trace a circle.
        /// </summary>
        /// <param name="radius">The distance of the corners to the center.</param>
        /// <param name="steps">How many corners are traced. Minumum 3.</param>
        /// <returns></returns>
        internal static SKPath GetPolygonPath(float radius, int steps)
        {
            var path = new SKPath()
            {
                FillType  = SKPathFillType.EvenOdd,
                Convexity = SKPathConvexity.Convex
            };

            //Cant have less than 3 steps
            steps = Math.Max(3, steps);

            //Move to the starting points and then go along the corners.
            path.MoveTo(PolarCoordinates(radius, _startRad));
            for (int i = 0; i < steps; i++)
            {
                path.LineTo(PolarCoordinates(radius, _startRad + _fullRad * i / steps));
            }
            path.Close();
            return(path);
        }
 static HendecagramArrayPage()
 {
     // Create 11-pointed star
     HendecagramPath = new SKPath();
     for (int i = 0; i < 11; i++)
     {
         double  angle = 5 * i * 2 * Math.PI / 11;
         SKPoint pt    = new SKPoint(100 * (float)Math.Sin(angle),
                                     -100 * (float)Math.Cos(angle));
         if (i == 0)
         {
             HendecagramPath.MoveTo(pt);
         }
         else
         {
             HendecagramPath.LineTo(pt);
         }
     }
     HendecagramPath.Close();
 }
Пример #27
0
        //public void beginShape(int kind) { NotImpl(nameof(beginShape)); } // POINTS, LINES, TRIANGLES, TRIANGLE_FAN, TRIANGLE_STRIP, QUADS, and QUAD_STRIP
        //public void bezierVertex() { NotImpl(nameof(bezierVertex)); }
        //public void curveVertex() { NotImpl(nameof(curveVertex)); }
        //public void endContour() { NotImpl(nameof(endContour)); }
        public void endShape(int mode = -1)
        {
            SKPoint[] points = _vertexes.ToArray();

            if (mode == -1) // Not closed - draw lines.
            {
                _canvas.DrawPoints(SKPointMode.Lines, points, _pen);
            }
            else if (mode == CLOSE)
            {
                using (var path = new SKPath())
                {
                    for (int i = 0; i < _vertexes.Count; i++)
                    {
                        if (i == 0)
                        {
                            path.MoveTo(_vertexes[i]);
                        }
                        else
                        {
                            path.LineTo(_vertexes[i]);
                        }
                    }
                    path.Close();

                    if (_fill.Color != SKColors.Transparent)
                    {
                        _canvas.DrawPath(path, _fill);
                    }

                    if (_pen.StrokeWidth != 0)
                    {
                        _canvas.DrawPath(path, _pen);
                    }
                }
            }
            else
            {
                NotImpl(nameof(endShape));
            }
        }
Пример #28
0
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
        {
            base.OnPaintSurface(e);


            var surface = e.Surface;
            var canvas  = surface.Canvas;

            canvas.Clear(SKColors.Transparent);

            // set up drawing tools
            using (var paint = new SKPaint())
            {
                paint.IsAntialias = true;
                paint.Color       = new SKColor(0x2c, 0x3e, 0x50);
                paint.StrokeCap   = SKStrokeCap.Round;

                // create the Xamagon path
                using (var path = new SKPath())
                {
                    path.MoveTo(71.4311121f, 56f);
                    path.CubicTo(68.6763107f, 56.0058575f, 65.9796704f, 57.5737917f, 64.5928855f, 59.965729f);
                    path.LineTo(43.0238921f, 97.5342563f);
                    path.CubicTo(41.6587026f, 99.9325978f, 41.6587026f, 103.067402f, 43.0238921f, 105.465744f);
                    path.LineTo(64.5928855f, 143.034271f);
                    path.CubicTo(65.9798162f, 145.426228f, 68.6763107f, 146.994582f, 71.4311121f, 147f);
                    path.LineTo(114.568946f, 147f);
                    path.CubicTo(117.323748f, 146.994143f, 120.020241f, 145.426228f, 121.407172f, 143.034271f);
                    path.LineTo(142.976161f, 105.465744f);
                    path.CubicTo(144.34135f, 103.067402f, 144.341209f, 99.9325978f, 142.976161f, 97.5342563f);
                    path.LineTo(121.407172f, 59.965729f);
                    path.CubicTo(120.020241f, 57.5737917f, 117.323748f, 56.0054182f, 114.568946f, 56f);
                    path.LineTo(71.4311121f, 56f);
                    path.Close();


                    // draw the Xamagon path
                    canvas.DrawPath(path, paint);
                }
            }
        }
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            // Create the path
            SKPath path = new SKPath();

            // Define the first contour
            path.MoveTo(0.5f * info.Width, 0.1f * info.Height);
            path.LineTo(0.2f * info.Width, 0.4f * info.Height);
            path.LineTo(0.8f * info.Width, 0.4f * info.Height);
            path.LineTo(0.5f * info.Width, 0.1f * info.Height);

            // Define the second contour
            path.MoveTo(0.5f * info.Width, 0.6f * info.Height);
            path.LineTo(0.2f * info.Width, 0.9f * info.Height);
            path.LineTo(0.8f * info.Width, 0.9f * info.Height);
            path.Close();

            // Create two SKPaint objects
            SKPaint strokePaint = new SKPaint
            {
                Style       = SKPaintStyle.Stroke,
                Color       = SKColors.Magenta,
                StrokeWidth = 50
            };

            SKPaint fillPaint = new SKPaint
            {
                Style = SKPaintStyle.Fill,
                Color = SKColors.Cyan
            };

            // Fill and stroke the path
            canvas.DrawPath(path, fillPaint);
            canvas.DrawPath(path, strokePaint);
        }
Пример #30
0
        void DrawArrowhead(SKCanvas canvas, Point from, Point to, SKPaint paint)
        {
            Point dir = to - from;
            Point h   = new Point(-dir.Y, dir.X);

            h /= h.Length;
            Point p1 = from + h * 5;
            Point p2 = from - h * 5;

            using (SKPath path = new SKPath {
                FillType = SKPathFillType.EvenOdd
            })
            {
                path.MoveTo(P(to));
                path.LineTo(P(p1));
                path.LineTo(P(p2));
                path.LineTo(P(to));
                path.Close();
                canvas.DrawPath(path, paint);
            }
        }
Пример #31
0
        public void DrawCoordinationSystem(ModelViewSurface surface, SKCanvas canvas)
        {
            float h = surface.ViewHeight / 20;
            float w = h / 5;

            SKPath arrow = new SKPath();

            arrow.MoveTo(-w, -2 * w);
            arrow.LineTo(-w, 4 * w);
            arrow.LineTo(-2 * w, 4 * w);
            arrow.LineTo(0, 6 * w);
            arrow.LineTo(2 * w, 4 * w);
            arrow.LineTo(w, 4 * w);
            arrow.LineTo(w, -2 * w);
            arrow.Close();

            SKPaint arrowPaint = new SKPaint()
            {
                Style       = SKPaintStyle.StrokeAndFill,
                Color       = Color.FromRgb(30, 30, 40).ToSKColor(),
                IsAntialias = true,
                BlendMode   = SKBlendMode.Lighten,
                StrokeWidth = 1,
                TextAlign   = SKTextAlign.Center,
                TextSize    = 2 * w
            };

            float px = 3 * w;
            float py = surface.ViewHeight - 3 * w;

            arrow.Transform(SKMatrix.MakeTranslation(px, py));
            arrow.Transform(SKMatrix.MakeRotation((float)Math.PI, px, py));
            canvas.DrawPath(arrow, arrowPaint);
            arrow.Transform(SKMatrix.MakeRotation((float)Math.PI / 2, px, py));
            canvas.DrawPath(arrow, arrowPaint);

            arrowPaint.Color = Color.White.ToSKColor();
            canvas.DrawText("Y", px, py - 8 * w, arrowPaint);
            canvas.DrawText("X", px + 8 * w, py + w / 2, arrowPaint);
        }