Exemple #1
0
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info = args.Info;

            //determine find smallet axis length
            MinorAxisLength = info.Width > info.Height ? info.Height : info.Width;
            arcWidth        = MinorAxisLength / 30;
            arcPadding      = MinorAxisLength / 15;
            KnobRadius      = MinorAxisLength / 30;
            float radius = (MinorAxisLength / 2);

            //update center
            Center = new SKPoint(info.Width / 2, info.Height / 2);
            SKSurface surface = args.Surface;
            SKCanvas  canvas  = surface.Canvas;

            canvas.Clear();
            // canvas.Scale((float)(canvasView.CanvasSize.Width / canvasView.Width));


            //  SKPaint BackgroundPaint = new SKPaint
            //  {
            //      Style = SKPaintStyle.Fill,
            //      Shader = SKShader.CreateColor(BackgroundColor.ToSKColor()),
            //  };
            //
            //  canvas.DrawRect(new SKRect(Center.X-(MinorAxisLength/2), Center.Y - (MinorAxisLength / 2), Center.X + (MinorAxisLength / 2), Center.Y + (MinorAxisLength / 2)), BackgroundPaint);

            SKPaint arcPaint = new SKPaint
            {
                Style       = SKPaintStyle.Stroke,
                Shader      = SKShader.CreateColor(ArcColor.ToSKColor()),
                StrokeCap   = SKStrokeCap.Round,
                StrokeWidth = arcWidth + 1,
                IsAntialias = true,
            };
            SKPaint arcBackgroundPaint = new SKPaint
            {
                Style       = SKPaintStyle.Stroke,
                Shader      = SKShader.CreateColor(ArcBackgroundColor.ToSKColor()),
                StrokeCap   = SKStrokeCap.Round,
                StrokeWidth = arcWidth,
                IsAntialias = true,
                // ImageFilter = SKImageFilter.CreateDropShadow(0, 0, 2, 2, Color.Black.ToSKColor(), SKDropShadowImageFilterShadowMode.DrawShadowAndForeground)
            };
            SKPaint KnobPaint = new SKPaint
            {
                Style       = SKPaintStyle.Fill,
                Shader      = SKShader.CreateColor(KnobColor.ToSKColor()),
                IsAntialias = true,
                ImageFilter = SKImageFilter.CreateDropShadow(0, 0, 3, 3, ArcColor.MultiplyAlpha(.5).ToSKColor())
            };
            SKPaint TextPaint = new SKPaint
            {
                Style       = SKPaintStyle.Fill,
                Shader      = SKShader.CreateColor(TextColor.ToSKColor()),
                IsAntialias = true,
                TextSize    = 40f,
                IsStroke    = false,
                TextAlign   = SKTextAlign.Center,
            };

            //create the rectangle that contains the arc
            //SKRect rect = new SKRect(arcPadding, arcPadding, MinorAxisLength - arcPadding, MinorAxisLength - arcPadding);
            SKRect rect = new SKRect(arcPadding + Center.X - (MinorAxisLength / 2), arcPadding + Center.Y - (MinorAxisLength / 2), Center.X + (MinorAxisLength / 2) - arcPadding, Center.Y + (MinorAxisLength / 2) - arcPadding);


            //var point = LastTouchedPoint;

            //calcualte the angle of the last touched point realtive to the center of the arc



            var   sweepAngle = getsweepangle();
            float realAngle  = startAngle + sweepAngle;

            //Debug.WriteLine($"realAngle:{realAngle % 360}");



            float arcRadius = (MinorAxisLength / 2) - arcPadding;;

            //get x and y compoents o the point on ther arc
            float x = arcRadius * (float)Math.Cos(DegreeToRadian(realAngle));
            float y = arcRadius * (float)Math.Sin(DegreeToRadian(realAngle));

            //move the points realitve to the center of the chart
            // SKRect rect = new SKRect(arcPadding + Center.X - (MinorAxisLength / 2), arcPadding + Center.Y - (MinorAxisLength / 2), Center.X + (MinorAxisLength / 2) - arcPadding, Center.Y + (MinorAxisLength / 2) - arcPadding);

            float realtiveX = x + Center.X;
            float realtiveY = y + Center.Y;


            using (SKPath path = new SKPath())
            {
                //draw background arc
                path.AddArc(rect, startAngle, 300);
                canvas.DrawPath(path, arcBackgroundPaint);
            }
            using (SKPath path = new SKPath())
            {
                //draw arc showing value
                path.AddArc(rect, startAngle, sweepAngle);
                canvas.DrawPath(path, arcPaint);
            }
            //draw current postion
            var TextBounds  = new SKRect();
            var ValueString = String.Format("{0:F" + Precision + "}", Value);

            TextPaint.MeasureText(ValueString, ref TextBounds);

            canvas.DrawOval(new SKRect(realtiveX - KnobRadius, realtiveY - KnobRadius, realtiveX + KnobRadius, realtiveY + KnobRadius), KnobPaint);
            if (ShowValue)
            {
                canvas.DrawText(ValueString, Center.X, Center.Y + (TextBounds.Height / 2), TextPaint);
            }
        }
Exemple #2
0
        void SKCanvasView_PaintSurface(System.Object sender, SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs e)
        {
            SKPaint arcColor = new SKPaint
            {
                Color       = ArcColor.ToSKColor(),
                StrokeWidth = 2,
                Style       = SKPaintStyle.StrokeAndFill
            };

            var w = e.Info.Width;
            var h = e.Info.Height;

            var canvas = e.Surface.Canvas;

            canvas.Clear();

            var   h1     = h / 3.33f;
            float xDelta = w / 165;
            float yDelta = h / 6;
            var   h2     = h1 + yDelta;

            var p1 = new SKPoint(0, h1);
            var p2 = new SKPoint(xDelta, h2);
            var p3 = new SKPoint(w / 3 - xDelta, h2);
            var p4 = new SKPoint(w / 3, h1);
            var p5 = new SKPoint(2 * w / 3, h1);
            var p6 = new SKPoint(2 * w / 3 + xDelta, h2);
            var p7 = new SKPoint(w - xDelta, h2);
            var p8 = new SKPoint(w, h1);

            var e1Xr = (p3.X - p2.X) / 2;
            var e2Xr = (p5.X - p4.X) / 2;
            var e3Xr = (p7.X - p6.X) / 2;

            float e1Yr = h / 2.5f;
            float e2Yr = h1;

            using (var path = new SKPath())
            {
                path.MoveTo(0, 0);

                path.LineTo(p1);
                path.LineTo(p2);

                path.ArcTo(e1Xr, e1Yr, 0, SKPathArcSize.Large, SKPathDirection.CounterClockwise, p3.X, p3.Y);

                path.LineTo(p4);

                path.ArcTo(e2Xr, e2Yr, 0, SKPathArcSize.Large, SKPathDirection.Clockwise, p5.X, p5.Y);

                path.LineTo(p6);

                path.ArcTo(e3Xr, e1Yr, 0, SKPathArcSize.Large, SKPathDirection.CounterClockwise, p7.X, p7.Y);

                path.LineTo(p8);

                path.LineTo(w, 0);

                canvas.DrawPath(path, arcColor);
            }
        }