public LinkedChainPage()
        {
            Title = "Linked Chain";

            SKCanvasView canvasView = new SKCanvasView();

            canvasView.PaintSurface += OnCanvasViewPaintSurface;
            Content = canvasView;

            // Create the path for the individual links
            SKRect outer = new SKRect(-linkRadius, -linkRadius, linkRadius, linkRadius);
            SKRect inner = outer;

            inner.Inflate(-linkThickness, -linkThickness);

            using (SKPath linkPath = new SKPath())
            {
                linkPath.AddArc(outer, 55, 160);
                linkPath.ArcTo(inner, 215, -160, false);
                linkPath.Close();

                linkPath.AddArc(outer, 235, 160);
                linkPath.ArcTo(inner, 395, -160, false);
                linkPath.Close();

                // Set that path as the 1D path effect for linksPaint
                linksPaint.PathEffect =
                    SKPathEffect.Create1DPath(linkPath, 1.3f * linkRadius, 0,
                                              SKPath1DPathEffectStyle.Rotate);
            }
        }
Пример #2
0
        private static void MoneyRing_PaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            SKPoint midPoint = new SKPoint(
                e.Info.Rect.MidX,
                e.Info.Rect.MidY
                );

            float Rad = 1f * (float)Math.Min(e.Info.Rect.MidX, e.Info.Rect.MidY);

            e.Surface.Canvas.Clear();
            e.Surface.Canvas.DrawCircle(midPoint, Rad, new SKPaint()
            {
                Color = SKColors.Black
            });
            e.Surface.Canvas.DrawCircle(midPoint, Rad - 2f, new SKPaint()
            {
                Color = SKColors.Purple
            });

            //
            SKPaint painter = new SKPaint()
            {
                Color       = SKColors.Black,
                IsStroke    = true,
                StrokeWidth = 3f,
            };

            using (SKPath path = new SKPath())
            {
                SKRect SmileBox = new SKRect(
                    midPoint.X - Rad * .7f,
                    midPoint.Y - Rad * .7f,
                    midPoint.X + Rad * .7f,
                    midPoint.Y + Rad * .7f
                    );

                SKRect EyeBoxLeft = new SKRect(
                    midPoint.X - Rad * .7f,
                    midPoint.Y - Rad * .5f,
                    midPoint.X - Rad * .2f,
                    midPoint.Y - Rad * .1f
                    );
                SKRect EyeBoxRight = new SKRect(
                    midPoint.X + Rad * .2f,
                    midPoint.Y - Rad * .5f,
                    midPoint.X + Rad * .7f,
                    midPoint.Y - Rad * .1f
                    );

                path.AddArc(SmileBox, 0f, 180f);
                path.AddArc(EyeBoxLeft, 180f, 180f);
                path.AddArc(EyeBoxRight, 180f, 180f);

                e.Surface.Canvas.DrawPath(path, painter);
            }
        }
Пример #3
0
        // Draws a gauge at the specified coordinates with the specified color
        void DrawGauge(float x, float y, Color color, short sensorData, SKCanvas canvas)
        {
            // Bounding box for containing the arcs
            SKRect boundingBox = new SKRect(x - 200, y - 200, x + 200, y + 200);

            // This patch will hold the outline arcs for the meter
            SKPath outlinePath = new SKPath();
            // This one holds the arc that actually changes based on the sensors
            SKPath gaugePath = new SKPath();

            // Add the first outline arc
            outlinePath.AddArc(boundingBox, 135, 270);

            // Decrease the bounding box because the other outline arc is smaller
            DeflateRect(ref boundingBox, 23);
            outlinePath.AddArc(boundingBox, 135, 270);

            // Increase the bounding box for the main arc
            InflateRect(ref boundingBox, 12);
            // Add the main arc based on the data from the sensor
            gaugePath.AddArc(boundingBox, 135, 270 * sensorData / 4095);

            SKPaint outlineArcPaint = new SKPaint
            {
                Style       = SKPaintStyle.Stroke,
                StrokeCap   = SKStrokeCap.Butt,
                Color       = Color.SlateGray.ToSKColor(),
                StrokeWidth = 3
            };

            // Draw the outline arcs
            canvas.DrawPath(outlinePath, outlineArcPaint);

            // Draw the outline cap lines
            canvas.DrawLine(x - (float)Math.Cos(Math.PI / 4) * 177, y + (float)Math.Sin(Math.PI / 4) * 177, x - (float)Math.Cos(Math.PI / 4) * 200, y + (float)Math.Sin(Math.PI / 4) * 200, outlineArcPaint);
            canvas.DrawLine(x + (float)Math.Cos(Math.PI / 4) * 177, y + (float)Math.Sin(Math.PI / 4) * 177, x + (float)Math.Cos(Math.PI / 4) * 200, y + (float)Math.Sin(Math.PI / 4) * 200, outlineArcPaint);

            // Draw the sensor data gauge
            canvas.DrawPath(gaugePath, new SKPaint
            {
                Style       = SKPaintStyle.Stroke,
                StrokeCap   = SKStrokeCap.Butt,
                Color       = color.ToSKColor(),
                StrokeWidth = 21
            });

            // Draw the text based on the sensor data
            canvas.DrawText($"{Math.Round((float)(100 * sensorData / 4095))}%", x, y, new SKPaint
            {
                Style     = SKPaintStyle.Fill,
                Color     = Color.Black.ToSKColor(),
                TextSize  = 70,
                TextAlign = SKTextAlign.Center
            });
        }
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
        {
            base.OnPaintSurface(e);

            var canvas = e.Surface.Canvas;

            var size = Math.Min(e.Info.Width, e.Info.Height) - ProgressThickness;

            canvas.Clear();

            using var paint = new SKPaint();

            paint.Style       = SKPaintStyle.Stroke;
            paint.StrokeCap   = SKStrokeCap.Round;
            paint.StrokeWidth = ProgressThickness;
            paint.IsAntialias = true;

            if (Jagged)
            {
                paint.PathEffect = SKPathEffect.CreateDiscrete(12f, 4f, (uint)Guid.NewGuid().GetHashCode());
            }

            using var path = new SKPath();

            var left   = (e.Info.Width - size) / 2f;
            var top    = (e.Info.Height - size) / 2f;
            var right  = left + size;
            var bottom = top + size;

            path.AddArc(new SKRect(left, top, right, bottom), 0, 360);

            paint.Color = ProgressColor.AddLuminosity(-.3d).ToSKColor();

            canvas.DrawPath(path, paint);

            path.Reset();

            path.AddArc(new SKRect(left, top, right, bottom), StartingDegrees, EndingDegrees);

            paint.Color = SKColors.Black;

            paint.ImageFilter = SKImageFilter.CreateBlur(3f, 3f);
            paint.BlendMode   = SKBlendMode.SrcATop;
            canvas.DrawPath(path, paint);

            paint.ImageFilter = null;
            paint.BlendMode   = SKBlendMode.SrcOver;
            paint.Color       = ProgressColor.ToSKColor();
            canvas.DrawPath(path, paint);
        }
Пример #5
0
        private void UpdateCurrentInterval(SKRect rect, SKCanvas canvas, float startAngle, float sweepAngle)
        {
            var currentInterval = ViewModel.Intervals.FirstOrDefault(t => t.IsRunning);

            if (currentInterval is null)
            {
                throw new NullReferenceException($"Timer = {ViewModel.Name} doesnt have a interval that is running");
            }

            using (var path = new SKPath())
                using (var textPaint = new SKPaint())
                    using (var transparentStrokePaint = new SKPaint
                    {
                        Color = GetTransparentColor(),
                        Style = SKPaintStyle.Stroke,
                        StrokeWidth = (float)Device.GetNamedSize(NamedSize.Medium, typeof(Entry)) + 1f,
                        StrokeCap = SKStrokeCap.Butt
                    })
                    {
                        transparentStrokePaint.StrokeWidth *= Device.RuntimePlatform == Device.Android
                    ? 2.5f
                    : 1f;
                        path.AddArc(rect, startAngle, sweepAngle);
                        canvas.DrawPath(path, transparentStrokePaint);
                    }
            DrawIntervalDuration(rect, canvas, currentInterval);
        }
        private void Draw_Arc(SKCanvas skCanvas)
        {
            // Draw Arc
            SKPaint skPaint = new SKPaint()
            {
                Style       = SKPaintStyle.Stroke,
                Color       = SKColors.BlueViolet,
                StrokeWidth = 10,
                IsAntialias = true,
            };

            SKRect skRectangle = new SKRect();

            skRectangle.Size     = new SKSize(150, 150);
            skRectangle.Location = new SKPoint(-150f / 2, -150f / 2);

            float startAngle = -90;
            float sweepAngle = 230; // (75 / 100) * 360

            SKPath skPath = new SKPath();

            skPath.AddArc(skRectangle, startAngle, sweepAngle);

            skCanvas.DrawPath(skPath, skPaint);
        }
Пример #7
0
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            // Initialize
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            // Clear
            canvas.Clear(Color.Transparent.ToSKColor());

            var rect = new SKRect(0, (info.Height) * -1, info.Width, info.Height);

            SKPaint arcPaint = new SKPaint
            {
                Color = Color.FromHex("#FF6063").ToSKColor().WithAlpha(0xEE)
            };

            using (SKPath path = new SKPath())
            {
                path.AddArc(rect, 0, 180);
                canvas.DrawPath(path, arcPaint);
            }

            SKPaint inversePaint = new SKPaint
            {
                Color = Color.FromHex("#CCCCCCCC").ToSKColor()
            };

            using (SKPath path = new SKPath())
            {
                path.AddArc(rect, 0, 180);
                path.FillType = SKPathFillType.InverseEvenOdd;
                canvas.DrawPath(path, inversePaint);
            }
        }
Пример #8
0
        public void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            /*
             * 500 is the diameter of the outer arc
             * each inner arc from the outer arc will get reduced by 50
             * you can change the value according to make the arc smaller or bigger
             * */

            float left, right;
            float top, bottom;

            right = left = (info.Width - 200) / 2;    //get the left and right postions to support all the devices
            top   = bottom = (info.Height - 200) / 2; //get the top and bottom postions to support all the devices

            //first Arc
            SKRect rect = new SKRect(left, top, info.Width - right, info.Height - bottom);

            canvas.DrawCircle(info.Width / 2, info.Height / 2, 100, firstArcPaint);
            using (SKPath path = new SKPath())
            {
                path.AddArc(rect, OvalStartAngle, OvalSweepAngle);
                canvas.DrawPath(path, secondArcPaint);
            }
        }
        public void DrawPie(Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle)
        {
            var path = new SKPath();

            path.AddArc(new SKRect(x, y, x + width, y + height), startAngle, sweepAngle);
            _image.DrawPath(path, pen.ToSKPaint());
        }
        public void FillPie(Brush brush, int x, int y, int width, int height, int startAngle, int sweepAngle)
        {
            var path = new SKPath();

            path.AddArc(new SKRect(x, y, x + width, y + height), startAngle, sweepAngle);
            _image.DrawPath(path, brush.ToSKPaint());
        }
Пример #11
0
        protected override void OnPaintSurface(SKPaintGLSurfaceEventArgs e)
        {
            base.OnPaintSurface(e);

            var canvas = e.Surface.Canvas;

            var size = Math.Min(e.RenderTarget.Width, e.RenderTarget.Height) - ProgressThickness;

            using (var paint = new SKPaint())
                using (var path = new SKPath()) {
                    var left   = (e.RenderTarget.Width - size) / 2f;
                    var top    = (e.RenderTarget.Height - size) / 2f;
                    var right  = left + size;
                    var bottom = top + size;

                    path.AddArc(new SKRect(left, top, right, bottom), StartingDegrees, EndingDegrees);

                    paint.IsAntialias = true;
                    paint.StrokeCap   = SKStrokeCap.Round;
                    paint.Style       = SKPaintStyle.Stroke;
                    paint.Color       = ProgressColor.ToSKColor();
                    paint.StrokeWidth = ProgressThickness;

                    paint.PathEffect = SKPathEffect.CreateDiscrete(12f, 4f, (uint)Guid.NewGuid().GetHashCode());

                    canvas.Clear(Color.White.ToSKColor());
                    canvas.DrawPath(path, paint);
                }
        }
Пример #12
0
        void OnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            SKImageInfo info   = e.Info;
            SKCanvas    canvas = e.Surface.Canvas;

            canvas.Clear();

            float startAngle = -90;
            float sweepAngle = 360 * (float)(PercentageComplete * .01);

            var arcPaint = new SKPaint();

            arcPaint.IsStroke    = true;
            arcPaint.StrokeCap   = SKStrokeCap.Round;
            arcPaint.StrokeWidth = 8;

            var padding = 10;
            var paint   = new SKPaint();

            paint.IsStroke    = true;
            paint.StrokeWidth = 3;
            paint.IsAntialias = true;
            paint.ColorFilter = SKColorFilter.CreateBlendMode(Color.FromHex("#7FFF").ToSKColor(), SKBlendMode.SrcIn);
            canvas.DrawCircle(info.Width / 2, info.Height / 2, info.Height / 2 - padding, paint);

            using (SKPath path = new SKPath())
            {
                var rect = new SKRect(padding, padding, info.Width - padding, info.Height - padding);
                arcPaint.ColorFilter = SKColorFilter.CreateBlendMode(Color.ToSKColor(), SKBlendMode.SrcIn);
                arcPaint.IsAntialias = true;
                path.AddArc(rect, startAngle, sweepAngle);
                canvas.DrawPath(path, arcPaint);
            }
        }
Пример #13
0
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs eventArgs)
        {
            var givenCanvas = eventArgs.Surface.Canvas;

            givenCanvas.Clear();

            this.canvasWidth  = eventArgs.Info.Width;
            this.canvasHeight = eventArgs.Info.Height;

            SKPaint loaderPaint = new SKPaint()
            {
                Color       = Color.LightGray.ToSKColor(),
                Style       = SKPaintStyle.Stroke,
                StrokeWidth = 30,
                IsAntialias = true
            };
            SKRect loaderRect = new SKRect();

            loaderRect.Size     = new SKSize(this.canvasWidth - 35, this.canvasHeight - 35);
            loaderRect.Location = new SKPoint(15, 15);
            SKPath loaderPath = new SKPath();

            loaderPath.AddArc(loaderRect, this.sweepAngleLoader, 270);
            givenCanvas.DrawPath(loaderPath, loaderPaint);

            SKPaint loaderIndicatorPaint = new SKPaint()
            {
                Color       = this.ColorPrimary.ToSKColor(),
                StrokeCap   = SKStrokeCap.Round,
                Style       = SKPaintStyle.Stroke,
                StrokeWidth = 30,
                IsAntialias = true
            };

            if (this.IsGradient)
            {
                loaderIndicatorPaint.Shader = SKShader.CreateLinearGradient(
                    new SKPoint(0, this.canvasWidth),
                    new SKPoint(this.canvasHeight, 0),
                    new SKColor[] {
                    this.ColorPrimary.ToSKColor(),
                    this.ColorSecondary.ToSKColor()
                },
                    new float[] {
                    0,
                    1
                },
                    SKShaderTileMode.Repeat
                    );
            }

            SKRect loaderIndicatorRect = new SKRect();

            loaderIndicatorRect.Size     = new SKSize(this.canvasWidth - 35, this.canvasHeight - 35);
            loaderIndicatorRect.Location = new SKPoint(15, 15);
            SKPath loaderIndicatorPath = new SKPath();

            loaderIndicatorPath.AddArc(loaderIndicatorRect, this.sweepAngleIndicator, 90);
            givenCanvas.DrawPath(loaderIndicatorPath, loaderIndicatorPaint);
        }
        void DrawBottomLabel(SKCanvas canvas, SKRect oval, float angle, SKColor fontColor, string mainText, string subText)
        {
            using (var mainFontPaint = new SKPaint
            {
                IsAntialias = true,
                Color = fontColor,
                TextSize = _mainTextSize,
            })
                using (var subFontPaint = new SKPaint
                {
                    IsAntialias = true,
                    Color = fontColor,
                    TextSize = _subTextSize,
                })
                {
                    var mainTextWidth = mainFontPaint.MeasureText(mainText);
                    var subTextWidth  = subFontPaint.MeasureText(subText);

                    var diffAngle = (float)((mainTextWidth + subTextWidth + _unitSpacing) / (Math.PI * oval.Width) * 360) / 2.0f;
                    using (var path = new SKPath())
                    {
                        path.AddArc(oval, 90 + diffAngle + angle, -45);
                        canvas.DrawTextOnPath(mainText, path, 0, -0.1f * mainFontPaint.TextSize, mainFontPaint);
                        canvas.DrawTextOnPath(subText, path, mainTextWidth + (float)_unitSpacing, -0.1f * subFontPaint.TextSize, subFontPaint);
                    }
                }
        }
Пример #15
0
        public static SKPath CreateArc(SKPoint start, SKPoint end, SKPoint center, bool cw)
        {
            float radius = DistanceBetween(start, center);

            float startAngle = (float)Math.Atan2(start.Y - center.Y,
                                                 start.X - center.X);

            float sweepAngle = (float)Math.Atan2(end.Y - center.Y,
                                                 end.X - center.X);

            if (!cw)
            {
                startAngle += (float)Math.PI;
                sweepAngle += (float)Math.PI;
            }

            startAngle = RadianToDegree(startAngle);
            sweepAngle = RadianToDegree(sweepAngle);
            Console.WriteLine("Start angle: " + startAngle + "Sweep angle: " + sweepAngle);

            SKRect rect = new SKRect(center.X - radius, center.Y - radius, center.X + radius, center.Y + radius);
            SKPath p    = new SKPath();

            p.AddArc(rect, startAngle, sweepAngle);

            return(p);
        }
Пример #16
0
        public void DrawArc(Pen penn, RectangleF rect, float start, float degrees)
        {
            var path = new SKPath();

            path.AddArc(new SKRect(rect.Left, rect.Top, rect.Right, rect.Bottom), start, degrees);
            _image.DrawPath(path, penn.SKPaint());
        }
Пример #17
0
        public override void DrawArc(Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle)
        {
            var path = new SKPath();

            path.AddArc(new SKRect(x, y, x + width, y + height), startAngle, sweepAngle);
            _image.DrawPath(path, pen.SKPaint());
        }
Пример #18
0
        private void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            var info    = e.Info;
            var surface = e.Surface;
            var canvas  = surface.Canvas;


            canvas.Clear();

            SKRect rect       = new SKRect(100, 100, info.Width - 100, info.Height - 100);
            float  startAngle = (float)startSlider.Value;
            float  sweepAngle = (float)sweepSlider.Value;

            canvas.DrawOval(rect, new SKPaint {
                Color = Color.DimGray.ToSKColor(), StrokeWidth = 25, Style = SKPaintStyle.Stroke
            });

            using (SKPath path = new SKPath())
            {
                path.AddArc(rect, startAngle, sweepAngle);
                canvas.DrawPath(path, new SKPaint {
                    Color = Color.AliceBlue.ToSKColor(), StrokeWidth = 50, Style = SKPaintStyle.Stroke
                });
            }
        }
Пример #19
0
        private void DrawBridge(SKCanvas canvas, int unit, Zone zoneUp, Zone zoneDown)
        {
            SKRect rect = new SKRect(
                (float)(zoneUp.X * unit - zoneUp.W * unit / 2),
                (float)(zoneUp.Y * unit - zoneUp.W * unit / 2),
                (float)(zoneUp.X * unit + zoneUp.W * unit / 2),
                (float)(zoneUp.Y * unit + zoneUp.W * unit / 2));
            float startAngle = 180;
            float sweepAngle = 180;



            //canvas.DrawOval(rect, circleBorder);

            using (SKPath path = new SKPath())
            {
                path.AddArc(rect, startAngle, sweepAngle);
                canvas.DrawPath(path, outlinePaint);
            }
            canvas.DrawLine((float)(zoneUp.X * unit - zoneUp.W * unit / 2),
                            (float)(zoneUp.Y * unit),
                            (float)(zoneDown.X * unit - zoneDown.W * unit / 2),
                            (float)(zoneDown.Y * unit - 35), outlinePaint);

            canvas.DrawLine((float)(zoneUp.X * unit + zoneUp.W * unit / 2),
                            (float)(zoneUp.Y * unit),
                            (float)(zoneDown.X * unit + zoneDown.W * unit / 2),
                            (float)(zoneDown.Y * unit - 35), outlinePaint);

            string str       = $"{rnd.Next(1, 100)} °C";
            var    textWidth = textPaint.MeasureText(str);

            textPaint.TextSize = 0.9f * (zoneUp.W.Value * unit / 2) * textPaint.TextSize / textWidth;
            canvas.DrawText(str, (zoneUp.X.Value * unit) - textPaint.MeasureText(str) / 2, zoneUp.Y.Value * unit + textPaint.TextSize / 2, textPaint);
        }
Пример #20
0
 void AppendArcProgressPath(SKPath path, float progress, SKRect oval, float startAngle, float sweepAngle)
 {
     if (progress > 1)
     {
         progress = 1;
     }
     sweepAngle = progress * sweepAngle;
     path.AddArc(oval, startAngle, sweepAngle);
 }
Пример #21
0
        private void DrawDistanceCard(SKCanvas canvas, string str_Text, SKRect rect_Card)
        {
            SKPath  gp_Card;
            SKPaint pn_Card;
            SKPaint textBorder;
            SKColor clr_Text   = SKColors.Black;
            SKColor clr_Border = SKColors.Red;
            SKPaint textPaint;

            switch (str_Text)
            {
            case "25":
            {
                clr_Text   = SKColors.Red;
                clr_Border = SKColors.Green;
                break;
            }

            case "50":
            {
                clr_Text   = SKColors.Red;
                clr_Border = SKColors.Blue;
                break;
            }

            case "75":
            {
                clr_Text   = SKColors.Green;
                clr_Border = SKColors.Red;
                break;
            }

            case "100":
            {
                clr_Text   = SKColors.Green;
                clr_Border = SKColors.Blue;
                break;
            }

            case "200":
            {
                clr_Text   = SKColors.Blue;
                clr_Border = SKColors.Green;
                break;
            }
            }
            pn_Card = MiscHelpers.GetStrokePaint(clr_Border, rect_Card.Width / 20);
            gp_Card = new SKPath();
            gp_Card.AddArc(SKRect.Create(System.Convert.ToInt32((rect_Card.Left + (rect_Card.Width / 10))), System.Convert.ToInt32((rect_Card.Top + (rect_Card.Height / 10))), System.Convert.ToInt32(((rect_Card.Width * 4) / 5)), System.Convert.ToInt32(((rect_Card.Height * 3) / 7))), 180, 180);
            gp_Card.AddLine(System.Convert.ToInt32((rect_Card.Left + ((rect_Card.Width * 9) / 10))), System.Convert.ToInt32((rect_Card.Top + ((rect_Card.Height * 9) / 10))), System.Convert.ToInt32((rect_Card.Left + (rect_Card.Width / 10))), System.Convert.ToInt32((rect_Card.Top + ((rect_Card.Height * 9) / 10))));
            gp_Card.Close();
            canvas.DrawPath(gp_Card, pn_Card);
            textPaint              = MiscHelpers.GetTextPaint(clr_Text, rect_Card.Height / 3);
            textBorder             = MiscHelpers.GetStrokePaint(SKColors.Black, 1); // for speed limit, 1 is fine
            textPaint.FakeBoldText = true;
            canvas.DrawBorderText(str_Text, TextExtensions.EnumLayoutOptions.Center, TextExtensions.EnumLayoutOptions.Center, textPaint, textBorder, rect_Card);
        }
Пример #22
0
        private void DefaultCanvas_PaintSurface(object sender, SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs e)
        {
            // Skia stuff happens
            SKImageInfo info    = e.Info;
            SKSurface   surface = e.Surface;
            SKCanvas    canvas  = surface.Canvas;

            var minSize       = Math.Min(info.Size.Height / 2, info.Size.Width / 2);
            var rulesDistance = 5;

            canvas.Clear();

            SKRect containerRectangle = new SKRect(0, 0, minSize, minSize);

            canvas.Translate((e.Info.Width / 2) - containerRectangle.MidX, (e.Info.Height / 2) - containerRectangle.MidY);

            using (SKPath path = new SKPath())
            {
                path.AddArc(containerRectangle, startDegree, endDegree);
                canvas.DrawPath(path, gaugleDefaultColor);
            }

            using (SKPath path = new SKPath())
            {
                var anglePercent = (endDegree * Percent) / 100;
                path.AddArc(containerRectangle, startDegree, (float)anglePercent);
                canvas.DrawPath(path, gaugleFillColor);
            }

            circleMidX = containerRectangle.MidX;
            circleMidY = containerRectangle.MidY;

            canvas.Translate(circleMidX, circleMidY);

            canvas.DrawCircle(0, 0, 8, rectFillColor);

            canvas.RotateDegrees(360);
            if (usePercentage)
            {
                angle = Math.PI * (startDegree + (endDegree * Percent) / 100) / 180.0;
            }

            radius = containerRectangle.Height / 2;
            cx     = (float)(radius * Math.Cos(angle));
            cy     = (float)(radius * Math.Sin(angle));

            canvas.DrawCircle(cx, cy, 35, rectFillColor); // x=cos(angle)*rayon et y =sin(angle)*rayon

            canvas.RotateDegrees(startDegree - 45);
            for (int angle = 0; angle <= endDegree; angle += 5)
            {
                var size = (float)(containerRectangle.Height / 2.5) + rulesDistance;
                canvas.DrawLine(size, size, size + 10, size + 10, blackFillColor);
                canvas.RotateDegrees(5);
            }
        }
Пример #23
0
 void DrawRightBGPart(SKCanvas canvas, SKPaint paint, SKPaint shadowPaint)
 {
     using (var rightArcPath = new SKPath())
     {
         rightArcPath.MoveTo(RightLines.Start);
         rightArcPath.LineTo(RightLines.Point1);
         rightArcPath.AddArc(RightLines.Arc, -135, 180);
         canvas.DrawPath(rightArcPath, paint);
     }
 }
Пример #24
0
        public void FillArc(float cx, float cy, float radius, float startAngle, float endAngle)
        {
            var sa = -startAngle * RadiansToDegrees;
            var ea = -endAngle * RadiansToDegrees;

            using (var p = new SKPath()) {
                p.AddArc(new SKRect(cx - radius, cy - radius, cx + radius, cy + radius), sa, ea - sa);
                _c.DrawPath(p, _paints.Fill);
            }
        }
Пример #25
0
        private static SKPath Segment(SKRect rect, int index, uint segmentCount, float progress = 1f)
        {
            var spacing  = segmentCount > 1 ? 16 : 0;
            var path     = new SKPath();
            var distance = (360f / segmentCount) - spacing;
            var start    = spacing / 2f + index * (spacing + distance);

            path.AddArc(rect, -90 + start, distance * progress);
            return(path);
        }
Пример #26
0
        public override void RenderChart(CanvasWrapper canvasWrapper, Axis axis, IMinMax minMax)
        {
            var divisor     = 2.5f;
            var strokeWidth = 30;

            if (canvasWrapper.NumberOfCharts > 6)
            {
                switch (Device.RuntimePlatform)
                {
                case Device.WPF:
                case Device.GTK:
                case Device.macOS:
                case Device.UWP: {
                    divisor     = 2.0f;
                    strokeWidth = 15;
                    break;
                }

                default: {
                    divisor     = 1.5f;
                    strokeWidth = 30;
                    break;
                }
                }
                ;
            }


            var chartArea = canvasWrapper.ChartArea;
            var canvas    = canvasWrapper.Canvas;

            var radius = Math.Min(chartArea.MidX, chartArea.MidY) / divisor;

            radius = radius - (canvasWrapper.NumberPlottedChart * strokeWidth);

            _chartPaint.StrokeWidth = strokeWidth;
            _chartPaint.Style       = SKPaintStyle.Stroke;

            var teta = 360 - ((minMax.Ymax - OriginalData.ElementAt(0).Y) / (minMax.Ymax - minMax.Ymin) * 360);

            var rect = new SKRect(chartArea.MidX - radius, chartArea.MidY - radius, chartArea.MidX + radius, chartArea.MidY + radius);
            var path = new SKPath();

            path.AddArc(rect, 90, -teta);
            canvas.DrawPath(path, _chartPaint);

            _chartPaint.Color = ChartColor.WithAlpha(70);
            canvas.DrawCircle(chartArea.MidX, chartArea.MidY, radius, _chartPaint);
            canvasWrapper.NumberPlottedChart += 1;

            _chartPaint.Color = ChartColor;
            ChartName         = $"{Label} : {Value}";
            RenderLegend(canvasWrapper, axis, canvas, PointPlotVariant.ScatterChart);
        }
Пример #27
0
        public static void DrawCone(SKCanvas thisCanvas, SKRect thisRect) // done
        {
            CreatePaints();
            SKPath thisPath = new SKPath();

            thisPath.MoveTo(new SKPoint(thisRect.Location.X + (thisRect.Width / 2), thisRect.Location.Y));
            thisPath.LineTo(new SKPoint(thisRect.Location.X + ((thisRect.Width * 3) / 4), thisRect.Location.Y + ((thisRect.Height * 3) / 4)));
            thisPath.AddArc(new SKPoint(thisRect.Location.X + (thisRect.Width / 4), thisRect.Location.Y + ((thisRect.Height * 3) / 4)), new SKSize(thisRect.Width / 2, thisRect.Height), 180, false, SKPathDirection.Clockwise);
            thisPath.Close();
            thisCanvas.DrawPath(thisPath, _darkOrangePaint);
            thisCanvas.DrawPath(thisPath, _penUsed);
        }
Пример #28
0
        // https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/graphics/skiasharp/curves/effects
        private void OnPainting(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            var circleFill = new SKPaint {
                IsAntialias = true,
                Style       = SKPaintStyle.Fill,
                Color       = SKColors.LightBlue
            };

            canvas.DrawCircle((float)(info.Width / 2), (float)(info.Height / 2), (float)(info.Height / 4), circleFill);

            var paintCapacity = new SKPaint {
                IsAntialias = true,
                Style       = SKPaintStyle.Stroke,
                Color       = SKColors.Yellow,
                StrokeWidth = 10
            };

            var pathCapacity = new SKPath();

            pathCapacity.AddArc(new SKRect(15, 15, info.Width - 15, info.Height - 15), 180, 180);

            canvas.DrawPath(pathCapacity, paintCapacity);

            var paintTotal = new SKPaint {
                IsAntialias = true,
                Style       = SKPaintStyle.Stroke,
                Color       = SKColors.YellowGreen,
                StrokeWidth = 10
            };

            var pathTotal = new SKPath();

            pathTotal.AddArc(new SKRect(15, 15, info.Width - 15, info.Height - 15), 180, 90);

            canvas.DrawPath(pathTotal, paintTotal);

            var paintText = new SKPaint {
                IsAntialias = true,
                Style       = SKPaintStyle.Fill,
                Color       = SKColors.Blue,
                TextSize    = 20
            };

            var pathText = new SKPath();

            pathText.AddArc(new SKRect(40, 40, info.Width - 40, info.Height - 40), 190, 160);

            canvas.DrawTextOnPath("Loren bacon ipsum", pathText, 0, 0, paintText);
        }
Пример #29
0
        private static void AddSegment(this SKPath path, PathSegment segment)
        {
            if (segment is LineSegment)
            {
                var s = segment as LineSegment;
                path.LineTo(s.Point.ToSKPoint());
            }
            else if (segment is PolyLineSegment)
            {
                var s = segment as PolyLineSegment;
                path.AddPoly(s.Points.Select(x => x.ToSKPoint()).Reverse().ToArray(), false);
            }
            else if (segment is ArcSegment)
            {
                var s = segment as ArcSegment;
                path.AddArc(new Rect(s.Point, s.Size).ToSKRect(), 180 + -s.RotationAngle.ToFloat(), -180);
            }
            else if (segment is BezierSegment)
            {
                var s = segment as BezierSegment;
                path.CubicTo(s.Point1.ToSKPoint(), s.Point2.ToSKPoint(), s.Point3.ToSKPoint());
            }
            else if (segment is PolyBezierSegment)
            {
                var s = segment as PolyBezierSegment;

                if (s.Points.Count % 3 != 0)
                {
                    throw new ArgumentException("Number of PolyBezierSegment points must be divisable by 3.");
                }

                for (int i = 0; i < s.Points.Count; i += 3)
                {
                    var p1 = s.Points[i];
                    var p2 = s.Points[i + 1];
                    var p3 = s.Points[i + 2];

                    path.CubicTo(p1.ToSKPoint(), p2.ToSKPoint(), p3.ToSKPoint());
                }
            }
            else if (segment is PolyQuadraticBezierSegment)
            {
                var s = segment as PolyQuadraticBezierSegment;

                for (int i = 0; i < s.Points.Count; i += 2)
                {
                    var p1 = s.Points[i];
                    var p2 = s.Points[i + 1];

                    path.CubicTo(p1.ToSKPoint(), p2.ToSKPoint(), p2.ToSKPoint());
                }
            }
        }
Пример #30
0
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            var info    = e.Info;
            var surface = e.Surface;
            var canvas  = surface.Canvas;

            canvas.Clear();

            int totalValues = 0;

            foreach (ChartData item in chartData)
            {
                totalValues += item.Value;
            }

            SKPoint center        = new SKPoint(info.Width / 2, info.Height / 2);
            float   explodeOffset = explodeSwitch.IsToggled ? (float)offsetSlider.Value : 0f;
            float   radius        = Math.Min(info.Width / 3, info.Height / 3) - 2 * explodeOffset;
            SKRect  rect          = new SKRect(center.X - radius, center.Y - radius,
                                               center.X + radius, center.Y + radius);

            float startAngle = 0;

            foreach (ChartData item in chartData)
            {
                float sweepAngle = 360f * item.Value / totalValues;

                using (SKPath path = new SKPath())
                    using (SKPaint strokePaint = new SKPaint())
                    {
                        path.AddArc(rect, startAngle, sweepAngle);

                        strokePaint.Style       = SKPaintStyle.Stroke;
                        strokePaint.Color       = item.Color;
                        strokePaint.StrokeWidth = radius * .9f;

                        // Calculate "explode" transform
                        float angle = startAngle + 0.5f * sweepAngle;
                        float x     = explodeOffset * (float)Math.Cos(Math.PI * angle / 180);
                        float y     = explodeOffset * (float)Math.Sin(Math.PI * angle / 180);

                        canvas.Save();
                        canvas.Translate(x, y);

                        // Fill and stroke the path
                        canvas.DrawPath(path, strokePaint);
                        canvas.Restore();
                    }

                startAngle += sweepAngle;
            }
        }