示例#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 void GetLastPoint()
        {
            using (var path = new SKPath ()) {
                path.MoveTo (0, 0);
                path.LineTo (10, 20);

                Assert.AreEqual (new SKPoint(10, 20), path.LastPoint);
            }
        }
示例#3
0
        public void PathContainsPoint()
        {
            using (var path = new SKPath ()) {
                path.AddRect (SKRect.Create (10, 10, 100, 100), SKPathDirection.Clockwise);

                Assert.IsTrue (path.Contains (30, 30));
                Assert.IsFalse (path.Contains (5, 30));
            }
        }
示例#4
0
        public static SKPath AsSkiaPath(
            this PathF path,
            float ppu,
            float ox,
            float oy,
            float fx,
            float fy)
        {
            var nativePath = new SKPath();

            var ppux = ppu * fx;
            var ppuy = ppu * fy;

            var pointIndex        = 0;
            var arcAngleIndex     = 0;
            var arcClockwiseIndex = 0;

            foreach (var type in path.SegmentTypes)
            {
                if (type == PathOperation.Move)
                {
                    var point = path[pointIndex++];
                    nativePath.MoveTo((ox + point.X * ppux), (oy + point.Y * ppuy));
                }
                else if (type == PathOperation.Line)
                {
                    var point = path[pointIndex++];
                    nativePath.LineTo((ox + point.X * ppux), (oy + point.Y * ppuy));
                }

                else if (type == PathOperation.Quad)
                {
                    var controlPoint = path[pointIndex++];
                    var point        = path[pointIndex++];
                    nativePath.QuadTo((ox + controlPoint.X * ppux), (oy + controlPoint.Y * ppuy), (ox + point.X * ppux), (oy + point.Y * ppuy));
                }
                else if (type == PathOperation.Cubic)
                {
                    var controlPoint1 = path[pointIndex++];
                    var controlPoint2 = path[pointIndex++];
                    var point         = path[pointIndex++];
                    nativePath.CubicTo((ox + controlPoint1.X * ppux), (oy + controlPoint1.Y * ppuy), (ox + controlPoint2.X * ppux), (oy + controlPoint2.Y * ppuy), (ox + point.X * ppux),
                                       (oy + point.Y * ppuy));
                }
                else if (type == PathOperation.Arc)
                {
                    var topLeft     = path[pointIndex++];
                    var bottomRight = path[pointIndex++];
                    var startAngle  = path.GetArcAngle(arcAngleIndex++);
                    var endAngle    = path.GetArcAngle(arcAngleIndex++);
                    var clockwise   = path.GetArcClockwise(arcClockwiseIndex++);

                    while (startAngle < 0)
                    {
                        startAngle += 360;
                    }

                    while (endAngle < 0)
                    {
                        endAngle += 360;
                    }

                    var rect  = new SKRect(topLeft.X, topLeft.Y, bottomRight.X, bottomRight.Y);
                    var sweep = Geometry.GetSweep(startAngle, endAngle, clockwise);

                    startAngle *= -1;
                    if (!clockwise)
                    {
                        sweep *= -1;
                    }

                    nativePath.AddArc(rect, startAngle, sweep);
                }
                else if (type == PathOperation.Close)
                {
                    nativePath.Close();
                }
            }

            return(nativePath);
        }
示例#5
0
        public GraphicsPath Clone()
        {
            var newPath = new SKPath(skPath);

            return(new GraphicsPath(newPath));
        }
示例#6
0
 public static void DrawPath(SKCanvas g, SKPath p, SKPaint stroke)
 {
     g.DrawPath(p, stroke);
 }
示例#7
0
        public void DrawPad(SKCanvas canvas, SKPoint center, float radius, SKPaint strokePaint, float strokePaintStrokeWidth, SKPaint fillPaint, SKPaint holePaint, SKPaint strokeAccentPaint, float strokeAccentPaintStrokeWidth, SKPaint holeAccentPaint, Swipe swipe)
        {
            float step       = radius / 7.0f;
            float holeRadius = radius / 7.0f;
            float orthShift  = (strokePaintStrokeWidth + strokeAccentPaintStrokeWidth) / 2.0f;
            float diagShift  = orthShift / 1.41f;

            var path = new SKPath();

            path.MoveTo(swipe % new SKPoint(center.X - radius, center.Y - radius));
            path.LineTo(swipe % new SKPoint(center.X - radius, center.Y - radius + 1 * step));
            path.LineTo(swipe % new SKPoint(center.X - radius + 1 * step, center.Y - radius + 2 * step));
            path.LineTo(swipe % new SKPoint(center.X - radius - 1 * step, center.Y - radius + 4 * step));
            path.LineTo(swipe % new SKPoint(center.X - radius + 1 * step, center.Y - radius + 6 * step));
            path.LineTo(swipe % new SKPoint(center.X - radius - 1 * step, center.Y - radius + 8 * step));
            path.LineTo(swipe % new SKPoint(center.X - radius + 1 * step, center.Y - radius + 10 * step));
            path.LineTo(swipe % new SKPoint(center.X - radius - 1 * step, center.Y - radius + 12 * step));
            path.LineTo(swipe % new SKPoint(center.X - radius, center.Y - radius + 13 * step));

            path.LineTo(swipe % new SKPoint(center.X - radius, center.Y + radius));
            path.LineTo(swipe % new SKPoint(center.X - radius + 1 * step, center.Y + radius));
            path.LineTo(swipe % new SKPoint(center.X - radius + 2 * step, center.Y + radius - 1 * step));
            path.LineTo(swipe % new SKPoint(center.X - radius + 4 * step, center.Y + radius + 1 * step));
            path.LineTo(swipe % new SKPoint(center.X - radius + 6 * step, center.Y + radius - 1 * step));
            path.LineTo(swipe % new SKPoint(center.X - radius + 8 * step, center.Y + radius + 1 * step));
            path.LineTo(swipe % new SKPoint(center.X - radius + 10 * step, center.Y + radius - 1 * step));
            path.LineTo(swipe % new SKPoint(center.X - radius + 12 * step, center.Y + radius + 1 * step));
            path.LineTo(swipe % new SKPoint(center.X - radius + 13 * step, center.Y + radius));

            path.LineTo(swipe % new SKPoint(center.X + radius, center.Y + radius));
            path.LineTo(swipe % new SKPoint(center.X + radius, center.Y + radius - 1 * step));
            path.LineTo(swipe % new SKPoint(center.X + radius - 1 * step, center.Y + radius - 2 * step));
            path.LineTo(swipe % new SKPoint(center.X + radius + 1 * step, center.Y + radius - 4 * step));
            path.LineTo(swipe % new SKPoint(center.X + radius - 1 * step, center.Y + radius - 6 * step));
            path.LineTo(swipe % new SKPoint(center.X + radius + 1 * step, center.Y + radius - 8 * step));
            path.LineTo(swipe % new SKPoint(center.X + radius - 1 * step, center.Y + radius - 10 * step));
            path.LineTo(swipe % new SKPoint(center.X + radius + 1 * step, center.Y + radius - 12 * step));
            path.LineTo(swipe % new SKPoint(center.X + radius, center.Y + radius - 13 * step));

            path.LineTo(swipe % new SKPoint(center.X + radius, center.Y - radius));
            path.LineTo(swipe % new SKPoint(center.X + radius - 1 * step, center.Y - radius));
            path.LineTo(swipe % new SKPoint(center.X + radius - 2 * step, center.Y - radius + 1 * step));
            path.LineTo(swipe % new SKPoint(center.X + radius - 4 * step, center.Y - radius - 1 * step));
            path.LineTo(swipe % new SKPoint(center.X + radius - 6 * step, center.Y - radius + 1 * step));
            path.LineTo(swipe % new SKPoint(center.X + radius - 8 * step, center.Y - radius - 1 * step));
            path.LineTo(swipe % new SKPoint(center.X + radius - 10 * step, center.Y - radius + 1 * step));
            path.LineTo(swipe % new SKPoint(center.X + radius - 12 * step, center.Y - radius - 1 * step));
            path.LineTo(swipe % new SKPoint(center.X + radius - 13 * step, center.Y - radius));

            path.LineTo(swipe % new SKPoint(center.X - radius, center.Y - radius));
            path.Close();

            var accPathLft = new SKPath();

            accPathLft.MoveTo(swipe % new SKPoint(center.X - radius + orthShift, center.Y - radius + orthShift));
            accPathLft.LineTo(swipe % new SKPoint(center.X - radius + orthShift, center.Y - radius + orthShift + 1 * step));
            accPathLft.MoveTo(swipe % new SKPoint(center.X - radius + diagShift + 1 * step, center.Y - radius + diagShift + 2 * step));
            accPathLft.LineTo(swipe % new SKPoint(center.X - radius + diagShift - 1 * step, center.Y - radius + diagShift + 4 * step));
            accPathLft.MoveTo(swipe % new SKPoint(center.X - radius + diagShift + 1 * step, center.Y - radius + diagShift + 6 * step));
            accPathLft.LineTo(swipe % new SKPoint(center.X - radius + diagShift - 1 * step, center.Y - radius + diagShift + 8 * step));
            accPathLft.MoveTo(swipe % new SKPoint(center.X - radius + diagShift + 1 * step, center.Y - radius + diagShift + 10 * step));
            accPathLft.LineTo(swipe % new SKPoint(center.X - radius + diagShift - 1 * step, center.Y - radius + diagShift + 12 * step));
            accPathLft.MoveTo(swipe % new SKPoint(center.X - radius + orthShift, center.Y - radius + 13 * step));
            accPathLft.LineTo(swipe % new SKPoint(center.X - radius + orthShift, center.Y - radius + 14 * step));

            var accPathTop = new SKPath();

            accPathTop.MoveTo(swipe % new SKPoint(center.X + radius, center.Y - radius + orthShift));
            accPathTop.LineTo(swipe % new SKPoint(center.X + radius + diagShift / 2 - 1 * step, center.Y - radius + orthShift));
            accPathTop.LineTo(swipe % new SKPoint(center.X + radius + diagShift - 2 * step, center.Y - radius + diagShift + 1 * step));
            accPathTop.MoveTo(swipe % new SKPoint(center.X + radius + diagShift - 4 * step, center.Y - radius + diagShift - 1 * step));
            accPathTop.LineTo(swipe % new SKPoint(center.X + radius + diagShift - 6 * step, center.Y - radius + diagShift + 1 * step));
            accPathTop.MoveTo(swipe % new SKPoint(center.X + radius + diagShift - 8 * step, center.Y - radius + diagShift - 1 * step));
            accPathTop.LineTo(swipe % new SKPoint(center.X + radius + diagShift - 10 * step, center.Y - radius + diagShift + 1 * step));
            accPathTop.MoveTo(swipe % new SKPoint(center.X + radius + diagShift - 12 * step, center.Y - radius + diagShift - 1 * step));
            accPathTop.LineTo(swipe % new SKPoint(center.X + radius + diagShift / 2 - 13 * step, center.Y - radius + orthShift));
            accPathTop.LineTo(swipe % new SKPoint(center.X + radius + orthShift - 14 * step, center.Y - radius + orthShift));

            canvas.DrawPath(path, fillPaint);

            canvas.DrawPath(accPathLft, strokeAccentPaint);
            canvas.DrawPath(accPathTop, strokeAccentPaint);
            canvas.DrawPath(path, strokePaint);
            canvas.DrawCircle(swipe % new SKPoint(center.X + diagShift / 2, center.Y + diagShift / 2), swipe % (holeRadius + diagShift / 2), holeAccentPaint);
            canvas.DrawCircle(swipe % center, swipe % holeRadius, holePaint);
        }
示例#8
0
        public override void DrawContent(SKCanvas canvas, int width, int height)
        {
            var total = this.Entries?.Count() ?? 0;

            if (total > 0)
            {
                var captionHeight = this.Entries.Max(x =>
                {
                    var result = 0.0f;

                    var hasLabel      = !string.IsNullOrEmpty(x.Label);
                    var hasValueLabel = !string.IsNullOrEmpty(x.ValueLabel);
                    if (hasLabel || hasValueLabel)
                    {
                        var hasOffset     = hasLabel && hasValueLabel;
                        var captionMargin = this.LabelTextSize * 0.60f;
                        var space         = hasOffset ? captionMargin : 0;

                        if (hasLabel)
                        {
                            result += this.LabelTextSize;
                        }

                        if (hasValueLabel)
                        {
                            result += this.LabelTextSize;
                        }
                    }

                    return(result);
                });

                var center     = new SKPoint(width / 2, height / 2);
                var radius     = ((Math.Min(width, height) - (2 * Margin)) / 2) - captionHeight;
                var rangeAngle = (float)((Math.PI * 2) / total);
                var startAngle = (float)Math.PI;

                var nextEntry = this.Entries.First();
                var nextAngle = startAngle;
                var nextPoint = this.GetPoint(nextEntry.Value * this.AnimationProgress, center, nextAngle, radius);

                this.DrawBorder(canvas, center, radius);

                using (var clip = new SKPath())
                {
                    clip.AddCircle(center.X, center.Y, radius);

                    for (int i = 0; i < total; i++)
                    {
                        var angle = nextAngle;
                        var entry = nextEntry;
                        var point = nextPoint;

                        var nextIndex = (i + 1) % total;
                        nextAngle = startAngle + (rangeAngle * nextIndex);
                        nextEntry = this.Entries.ElementAt(nextIndex);
                        nextPoint = this.GetPoint(nextEntry.Value * this.AnimationProgress, center, nextAngle, radius);

                        canvas.Save();
                        canvas.ClipPath(clip);

                        // Border center bars
                        using (var paint = new SKPaint()
                        {
                            Style = SKPaintStyle.Stroke,
                            StrokeWidth = this.BorderLineSize,
                            Color = this.BorderLineColor,
                            IsAntialias = true,
                        })
                        {
                            var borderPoint = this.GetPoint(this.MaxValue, center, angle, radius);
                            canvas.DrawLine(point.X, point.Y, borderPoint.X, borderPoint.Y, paint);
                        }

                        // Values points and lines
                        using (var paint = new SKPaint()
                        {
                            Style = SKPaintStyle.Stroke,
                            StrokeWidth = this.BorderLineSize,
                            Color = entry.Color.WithAlpha((byte)(entry.Color.Alpha * 0.75f * this.AnimationProgress)),
                            PathEffect = SKPathEffect.CreateDash(new[] { this.BorderLineSize, this.BorderLineSize * 2 }, 0),
                            IsAntialias = true,
                        })
                        {
                            var amount = Math.Abs(entry.Value - this.AbsoluteMinimum) / this.ValueRange;
                            canvas.DrawCircle(center.X, center.Y, radius * amount, paint);
                        }

                        canvas.DrawGradientLine(center, entry.Color.WithAlpha(0), point, entry.Color.WithAlpha((byte)(entry.Color.Alpha * 0.75f)), this.LineSize);
                        canvas.DrawGradientLine(point, entry.Color, nextPoint, nextEntry.Color, this.LineSize);
                        canvas.DrawPoint(point, entry.Color, this.PointSize, this.PointMode);

                        canvas.Restore();

                        // Labels
                        var labelPoint = new SKPoint(0, radius + this.LabelTextSize + (this.PointSize / 2));
                        var rotation   = SKMatrix.MakeRotation(angle);
                        labelPoint = center + rotation.MapPoint(labelPoint);
                        var alignment = SKTextAlign.Left;

                        if ((Math.Abs(angle - (startAngle + Math.PI)) < Epsilon) || (Math.Abs(angle - Math.PI) < Epsilon))
                        {
                            alignment = SKTextAlign.Center;
                        }
                        else if (angle > (float)(startAngle + Math.PI))
                        {
                            alignment = SKTextAlign.Right;
                        }

                        canvas.DrawCaptionLabels(entry.Label, entry.TextColor, entry.ValueLabel, entry.Color.WithAlpha((byte)(255 * this.AnimationProgress)), this.LabelTextSize, labelPoint, alignment, base.Typeface, out var _);
                    }
                }
            }
        }
示例#9
0
 public ParticlePathShape(SKPath path)
 {
     Path = path ?? throw new ArgumentNullException(nameof(path));
     Path.Transform(SKMatrix.CreateTranslation(Path.Bounds.Left * -1 + Path.Bounds.Width / 2f * -1, Path.Bounds.Top * -1 + Path.Bounds.Height / 2f * -1));
 }
 public FingerPaintPolyline()
 {
     Path = new SKPath();
 }
示例#11
0
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            SKImageInfo info    = e.Info;
            SKSurface   surface = e.Surface;
            SKCanvas    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 = 50;
            float   radius        = Math.Min(info.Width / 2, info.Height / 2) - 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 fillPaint = new SKPaint())
                        using (SKPaint outlinePaint = new SKPaint())
                        {
                            path.MoveTo(center);
                            path.ArcTo(rect, startAngle, sweepAngle, false);
                            path.Close();

                            Random r = new Random();

                            fillPaint.Style = SKPaintStyle.Fill;
                            fillPaint.Color = Color.FromRgb(r.Next(255), r.Next(255), r.Next(255)).ToSKColor();


                            outlinePaint.Style       = SKPaintStyle.Stroke;
                            outlinePaint.StrokeWidth = 5;
                            outlinePaint.Color       = SKColors.Black;

                            // 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, fillPaint);
                            //canvas.DrawPath(path, outlinePaint);
                            canvas.Restore();
                        }

                startAngle += sweepAngle;
            }
        }
示例#12
0
 /// <summary>
 /// Draw arrow to path
 /// </summary>
 /// <param name="path">The arrow path</param>
 /// <param name="start">Start of arrow at bubble</param>
 /// <param name="center">Center of arrow</param>
 /// <param name="end">End of arrow at bubble</param>
 private static void DrawArrow(SKPath path, SKPoint start, SKPoint center, SKPoint end)
 {
     path.LineTo(start);
     path.LineTo(center);
     path.LineTo(end);
 }
示例#13
0
        /// <summary>
        /// Update path
        /// </summary>
        private static (SKPath, SKPoint) CreateCalloutPath(CalloutStyle callout, double contentWidth, double contentHeight)
        {
            var strokeWidth   = callout.StrokeWidth < 1 ? 1 : callout.StrokeWidth;
            var paddingLeft   = callout.Padding.Left < callout.RectRadius * 0.5 ? callout.RectRadius * 0.5 : callout.Padding.Left;
            var paddingTop    = callout.Padding.Top < callout.RectRadius * 0.5 ? callout.RectRadius * 0.5 : callout.Padding.Top;
            var paddingRight  = callout.Padding.Right < callout.RectRadius * 0.5 ? callout.RectRadius * 0.5 : callout.Padding.Right;
            var paddingBottom = callout.Padding.Bottom < callout.RectRadius * 0.5 ? callout.RectRadius * 0.5 : callout.Padding.Bottom;
            var width         = (float)contentWidth + (float)paddingLeft + (float)paddingRight;
            var height        = (float)contentHeight + (float)paddingTop + (float)paddingBottom;
            var halfWidth     = width * callout.ArrowPosition;
            var halfHeight    = height * callout.ArrowPosition;
            var bottom        = height + callout.ShadowWidth + strokeWidth * 2;
            var left          = callout.ShadowWidth + strokeWidth;
            var top           = callout.ShadowWidth + strokeWidth;
            var right         = width + callout.ShadowWidth + strokeWidth * 2;
            var start         = new SKPoint();
            var center        = new SKPoint();
            var end           = new SKPoint();

            // Check, if we are to near at corners
            if (halfWidth - callout.ArrowWidth * 0.5f - left < callout.RectRadius)
            {
                halfWidth = callout.ArrowWidth * 0.5f + left + callout.RectRadius;
            }
            else if (halfWidth + callout.ArrowWidth * 0.5f > width - callout.RectRadius)
            {
                halfWidth = width - callout.ArrowWidth * 0.5f - callout.RectRadius;
            }
            if (halfHeight - callout.ArrowWidth * 0.5f - top < callout.RectRadius)
            {
                halfHeight = callout.ArrowWidth * 0.5f + top + callout.RectRadius;
            }
            else if (halfHeight + callout.ArrowWidth * 0.5f > height - callout.RectRadius)
            {
                halfHeight = height - callout.ArrowWidth * 0.5f - callout.RectRadius;
            }

            switch (callout.ArrowAlignment)
            {
            case ArrowAlignment.Bottom:
                start  = new SKPoint(halfWidth + callout.ArrowWidth * 0.5f, bottom);
                center = new SKPoint(halfWidth, bottom + callout.ArrowHeight);
                end    = new SKPoint(halfWidth - callout.ArrowWidth * 0.5f, bottom);
                break;

            case ArrowAlignment.Top:
                top    += callout.ArrowHeight;
                bottom += callout.ArrowHeight;
                start   = new SKPoint(halfWidth - callout.ArrowWidth * 0.5f, top);
                center  = new SKPoint(halfWidth, top - callout.ArrowHeight);
                end     = new SKPoint(halfWidth + callout.ArrowWidth * 0.5f, top);
                break;

            case ArrowAlignment.Left:
                left  += callout.ArrowHeight;
                right += callout.ArrowHeight;
                start  = new SKPoint(left, halfHeight + callout.ArrowWidth * 0.5f);
                center = new SKPoint(left - callout.ArrowHeight, halfHeight);
                end    = new SKPoint(left, halfHeight - callout.ArrowWidth * 0.5f);
                break;

            case ArrowAlignment.Right:
                start  = new SKPoint(right, halfHeight - callout.ArrowWidth * 0.5f);
                center = new SKPoint(right + callout.ArrowHeight, halfHeight);
                end    = new SKPoint(right, halfHeight + callout.ArrowWidth * 0.5f);
                break;
            }

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

            // Move to start point at left/top
            path.MoveTo(left + callout.RectRadius, top);

            // Top horizontal line
            if (callout.ArrowAlignment == ArrowAlignment.Top)
            {
                DrawArrow(path, start, center, end);
            }

            // Top right arc
            path.ArcTo(new SKRect(right - callout.RectRadius, top, right, top + callout.RectRadius), 270, 90, false);

            // Right vertical line
            if (callout.ArrowAlignment == ArrowAlignment.Right)
            {
                DrawArrow(path, start, center, end);
            }

            // Bottom right arc
            path.ArcTo(new SKRect(right - callout.RectRadius, bottom - callout.RectRadius, right, bottom), 0, 90, false);

            // Bottom horizontal line
            if (callout.ArrowAlignment == ArrowAlignment.Bottom)
            {
                DrawArrow(path, start, center, end);
            }

            // Bottom left arc
            path.ArcTo(new SKRect(left, bottom - callout.RectRadius, left + callout.RectRadius, bottom), 90, 90, false);

            // Left vertical line
            if (callout.ArrowAlignment == ArrowAlignment.Left)
            {
                DrawArrow(path, start, center, end);
            }

            // Top left arc
            path.ArcTo(new SKRect(left, top, left + callout.RectRadius, top + callout.RectRadius), 180, 90, false);

            path.Close();

            return(path, center);
        }
示例#14
0
 public PaintedPath(SKPath path, SKColor color)
 {
     Path  = path;
     Color = color;
 }
示例#15
0
        public static SKPath AsRotatedAndroidPath(this PathF target, PointF center, float ppu, float zoom, float angle)
        {
            ppu = zoom * ppu;

            var path = new SKPath();

            var pointIndex        = 0;
            var arcAngleIndex     = 0;
            var arcClockwiseIndex = 0;

            foreach (var type in target.SegmentTypes)
            {
                if (type == PathOperation.Move)
                {
                    var point = target.GetRotatedPoint(pointIndex++, center, angle);
                    path.MoveTo(point.X * ppu, point.Y * ppu);
                }
                else if (type == PathOperation.Line)
                {
                    var endPoint = target.GetRotatedPoint(pointIndex++, center, angle);
                    path.LineTo(endPoint.X * ppu, endPoint.Y * ppu);
                }
                else if (type == PathOperation.Quad)
                {
                    var controlPoint1 = target.GetRotatedPoint(pointIndex++, center, angle);
                    var endPoint      = target.GetRotatedPoint(pointIndex++, center, angle);
                    path.QuadTo(
                        controlPoint1.X * ppu,
                        controlPoint1.Y * ppu,
                        endPoint.X * ppu,
                        endPoint.Y * ppu);
                }
                else if (type == PathOperation.Cubic)
                {
                    var controlPoint1 = target.GetRotatedPoint(pointIndex++, center, angle);
                    var controlPoint2 = target.GetRotatedPoint(pointIndex++, center, angle);
                    var endPoint      = target.GetRotatedPoint(pointIndex++, center, angle);
                    path.CubicTo(
                        controlPoint1.X * ppu,
                        controlPoint1.Y * ppu,
                        controlPoint2.X * ppu,
                        controlPoint2.Y * ppu,
                        endPoint.X * ppu,
                        endPoint.Y * ppu);
                }
                else if (type == PathOperation.Arc)
                {
                    var topLeft     = target[pointIndex++];
                    var bottomRight = target[pointIndex++];
                    var startAngle  = target.GetArcAngle(arcAngleIndex++);
                    var endAngle    = target.GetArcAngle(arcAngleIndex++);
                    var clockwise   = target.GetArcClockwise(arcClockwiseIndex++);

                    while (startAngle < 0)
                    {
                        startAngle += 360;
                    }

                    while (endAngle < 0)
                    {
                        endAngle += 360;
                    }

                    var rect  = new SKRect(topLeft.X, topLeft.Y, bottomRight.X, bottomRight.Y);
                    var sweep = Geometry.GetSweep(startAngle, endAngle, clockwise);

                    startAngle *= -1;
                    if (!clockwise)
                    {
                        sweep *= -1;
                    }

                    path.AddArc(rect, startAngle, sweep);
                }
                else if (type == PathOperation.Close)
                {
                    path.Close();
                }
            }

            return(path);
        }
示例#16
0
        public static SKPath AsSkiaPathFromSegment(this PathF target, int segmentIndex, float ppu, float zoom)
        {
            ppu = zoom * ppu;

            var path = new SKPath();

            var type = target.GetSegmentType(segmentIndex);

            if (type == PathOperation.Line)
            {
                var pointIndex = target.GetSegmentPointIndex(segmentIndex);
                var startPoint = target[pointIndex - 1];
                path.MoveTo(startPoint.X * ppu, startPoint.Y * ppu);

                var endPoint = target[pointIndex];
                path.LineTo(endPoint.X * ppu, endPoint.Y * ppu);
            }
            else if (type == PathOperation.Quad)
            {
                var pointIndex = target.GetSegmentPointIndex(segmentIndex);
                var startPoint = target[pointIndex - 1];
                path.MoveTo(startPoint.X * ppu, startPoint.Y * ppu);

                var controlPoint = target[pointIndex++];
                var endPoint     = target[pointIndex];
                path.QuadTo(controlPoint.X * ppu, controlPoint.Y * ppu, endPoint.X * ppu, endPoint.Y * ppu);
            }
            else if (type == PathOperation.Cubic)
            {
                var pointIndex = target.GetSegmentPointIndex(segmentIndex);
                var startPoint = target[pointIndex - 1];
                path.MoveTo(startPoint.X * ppu, startPoint.Y * ppu);

                var controlPoint1 = target[pointIndex++];
                var controlPoint2 = target[pointIndex++];
                var endPoint      = target[pointIndex];
                path.CubicTo(controlPoint1.X * ppu, controlPoint1.Y * ppu, controlPoint2.X * ppu, controlPoint2.Y * ppu, endPoint.X * ppu, endPoint.Y * ppu);
            }
            else if (type == PathOperation.Arc)
            {
                target.GetSegmentInfo(segmentIndex, out var pointIndex, out var arcAngleIndex, out var arcClockwiseIndex);

                var topLeft     = target[pointIndex++];
                var bottomRight = target[pointIndex];
                var startAngle  = target.GetArcAngle(arcAngleIndex++);
                var endAngle    = target.GetArcAngle(arcAngleIndex);
                var clockwise   = target.GetArcClockwise(arcClockwiseIndex);

                while (startAngle < 0)
                {
                    startAngle += 360;
                }

                while (endAngle < 0)
                {
                    endAngle += 360;
                }

                var rect  = new SKRect(topLeft.X, topLeft.Y, bottomRight.X, bottomRight.Y);
                var sweep = Geometry.GetSweep(startAngle, endAngle, clockwise);

                startAngle *= -1;
                if (!clockwise)
                {
                    sweep *= -1;
                }

                path.AddArc(rect, startAngle, sweep);
            }

            return(path);
        }
示例#17
0
        private void DrawGraph(SKCanvas Canvas, SKPoint[] Points, object[] Parameters, SKPoint[] PrevPoints, object[] PrevParameters,
                               DrawingArea DrawingArea)
        {
            SKPaint Brush = null;
            SKPath  Path  = null;
            bool    First = true;

            try
            {
                Brush = new SKPaint()
                {
                    Style = SKPaintStyle.Fill,
                    Color = Graph.ToColor(Parameters[0])
                };
                Path = new SKPath();

                foreach (SKPoint Point in Points)
                {
                    if (First)
                    {
                        First = false;
                        Path.MoveTo(Point);
                    }
                    else
                    {
                        Path.LineTo(Point);
                    }
                }

                if (PrevPoints == null)
                {
                    IElement Zero;
                    ISet     Set   = DrawingArea.MinY.AssociatedSet;
                    IGroup   Group = Set as IGroup;

                    if (Group == null)
                    {
                        Zero = new DoubleNumber(0);
                    }
                    else
                    {
                        Zero = Group.AdditiveIdentity;
                    }

                    IVector XAxis = VectorDefinition.Encapsulate(new IElement[] { DrawingArea.MinX, DrawingArea.MaxX }, false, this) as IVector;
                    IVector YAxis = VectorDefinition.Encapsulate(new IElement[] { Zero, Zero }, false, this) as IVector;

                    PrevPoints = DrawingArea.Scale(XAxis, YAxis);

                    if (DrawingArea.MinX is StringValue && DrawingArea.MaxX is StringValue)
                    {
                        PrevPoints[0].X = Points[0].X;
                        PrevPoints[1].X = Points[Points.Length - 1].X;
                    }
                }

                int i = PrevPoints.Length;

                while (--i >= 0)
                {
                    Path.LineTo(PrevPoints[i]);
                }

                Path.LineTo(Points[0]);

                Canvas.DrawPath(Path, Brush);
            }
            finally
            {
                if (Brush != null)
                {
                    Brush.Dispose();
                }

                if (Path != null)
                {
                    Path.Dispose();
                }
            }
        }
示例#18
0
        public static void Draw(SKCanvas canvas, IReadOnlyViewport viewport, IStyle style, IFeature feature, IGeometry geometry,
                                float opacity, SymbolCache symbolCache = null)
        {
            if (style is LabelStyle labelStyle)
            {
                var worldCenter = geometry.BoundingBox.Centroid;
                var center      = viewport.WorldToScreen(worldCenter);
                LabelRenderer.Draw(canvas, labelStyle, feature, (float)center.X, (float)center.Y, opacity);
            }
            else if (style is StyleCollection styleCollection)
            {
                foreach (var s in styleCollection)
                {
                    Draw(canvas, viewport, s, feature, geometry, opacity, symbolCache);
                }
            }
            else if (style is VectorStyle vectorStyle)
            {
                var polygon = (Polygon)geometry;

                float   lineWidth        = 1;
                var     lineColor        = Color.Black;       // default
                var     fillColor        = Color.Gray;        // default
                var     strokeCap        = PenStrokeCap.Butt; // default
                var     strokeJoin       = StrokeJoin.Miter;  // default
                var     strokeMiterLimit = 4f;                // default
                var     strokeStyle      = PenStyle.Solid;    // default
                float[] dashArray        = null;              // default

                if (vectorStyle.Outline != null)
                {
                    lineWidth        = (float)vectorStyle.Outline.Width;
                    lineColor        = vectorStyle.Outline.Color;
                    strokeCap        = vectorStyle.Outline.PenStrokeCap;
                    strokeJoin       = vectorStyle.Outline.StrokeJoin;
                    strokeMiterLimit = vectorStyle.Outline.StrokeMiterLimit;
                    strokeStyle      = vectorStyle.Outline.PenStyle;
                    dashArray        = vectorStyle.Outline.DashArray;
                }

                if (vectorStyle.Fill != null)
                {
                    fillColor = vectorStyle.Fill?.Color;
                }

                using (var path = polygon.ToSkiaPath(viewport, canvas.LocalClipBounds, lineWidth))
                    using (var paintFill = new SKPaint {
                        IsAntialias = true
                    })
                    {
                        // Is there a FillStyle?
                        if (vectorStyle.Fill?.FillStyle == FillStyle.Solid)
                        {
                            paintFill.StrokeWidth = 0;
                            paintFill.Style       = SKPaintStyle.Fill;
                            paintFill.PathEffect  = null;
                            paintFill.Shader      = null;
                            paintFill.Color       = fillColor.ToSkia(opacity);
                            canvas.DrawPath(path, paintFill);
                        }
                        else
                        {
                            paintFill.StrokeWidth = 1;
                            paintFill.Style       = SKPaintStyle.Stroke;
                            paintFill.Shader      = null;
                            paintFill.Color       = fillColor.ToSkia(opacity);
                            var scale    = 10.0f;
                            var fillPath = new SKPath();
                            var matrix   = SKMatrix.MakeScale(scale, scale);

                            switch (vectorStyle.Fill?.FillStyle)
                            {
                            case FillStyle.Cross:
                                fillPath.MoveTo(scale * 0.8f, scale * 0.8f);
                                fillPath.LineTo(0, 0);
                                fillPath.MoveTo(0, scale * 0.8f);
                                fillPath.LineTo(scale * 0.8f, 0);
                                paintFill.PathEffect = SKPathEffect.Create2DPath(matrix, fillPath);
                                break;

                            case FillStyle.DiagonalCross:
                                fillPath.MoveTo(scale, scale);
                                fillPath.LineTo(0, 0);
                                fillPath.MoveTo(0, scale);
                                fillPath.LineTo(scale, 0);
                                paintFill.PathEffect = SKPathEffect.Create2DPath(matrix, fillPath);
                                break;

                            case FillStyle.BackwardDiagonal:
                                fillPath.MoveTo(0, scale);
                                fillPath.LineTo(scale, 0);
                                paintFill.PathEffect = SKPathEffect.Create2DPath(matrix, fillPath);
                                break;

                            case FillStyle.ForwardDiagonal:
                                fillPath.MoveTo(scale, scale);
                                fillPath.LineTo(0, 0);
                                paintFill.PathEffect = SKPathEffect.Create2DPath(matrix, fillPath);
                                break;

                            case FillStyle.Dotted:
                                paintFill.Style = SKPaintStyle.StrokeAndFill;
                                fillPath.AddCircle(scale * 0.5f, scale * 0.5f, scale * 0.35f);
                                paintFill.PathEffect = SKPathEffect.Create2DPath(matrix, fillPath);
                                break;

                            case FillStyle.Horizontal:
                                fillPath.MoveTo(0, scale * 0.5f);
                                fillPath.LineTo(scale, scale * 0.5f);
                                paintFill.PathEffect = SKPathEffect.Create2DPath(matrix, fillPath);
                                break;

                            case FillStyle.Vertical:
                                fillPath.MoveTo(scale * 0.5f, 0);
                                fillPath.LineTo(scale * 0.5f, scale);
                                paintFill.PathEffect = SKPathEffect.Create2DPath(matrix, fillPath);
                                break;

                            case FillStyle.Bitmap:
                                paintFill.Style = SKPaintStyle.Fill;
                                var image = GetImage(symbolCache, vectorStyle.Fill.BitmapId);
                                if (image != null)
                                {
                                    paintFill.Shader = image.ToShader(SKShaderTileMode.Repeat, SKShaderTileMode.Repeat);
                                }
                                break;

                            case FillStyle.BitmapRotated:
                                paintFill.Style = SKPaintStyle.Fill;
                                image           = GetImage(symbolCache, vectorStyle.Fill.BitmapId);
                                if (image != null)
                                {
                                    paintFill.Shader = image.ToShader(SKShaderTileMode.Repeat,
                                                                      SKShaderTileMode.Repeat,
                                                                      SKMatrix.MakeRotation((float)(viewport.Rotation * System.Math.PI / 180.0f), image.Width >> 1, image.Height >> 1));
                                }
                                break;

                            default:
                                paintFill.PathEffect = null;
                                break;
                            }

                            // Do this, because if not, path isn't filled complete
                            using (new SKAutoCanvasRestore(canvas))
                            {
                                canvas.ClipPath(path);
                                var bounds = path.Bounds;
                                // Make sure, that the brush starts with the correct position
                                var inflate = ((int)path.Bounds.Width * 0.3f / scale) * scale;
                                bounds.Inflate(inflate, inflate);
                                // Draw rect with bigger size, which is clipped by path
                                canvas.DrawRect(bounds, paintFill);
                            }
                        }

                        if (vectorStyle.Outline != null)
                        {
                            using (var paintStroke = new SKPaint {
                                IsAntialias = true
                            })
                            {
                                paintStroke.Style       = SKPaintStyle.Stroke;
                                paintStroke.StrokeWidth = lineWidth;
                                paintStroke.Color       = lineColor.ToSkia(opacity);
                                paintStroke.StrokeCap   = strokeCap.ToSkia();
                                paintStroke.StrokeJoin  = strokeJoin.ToSkia();
                                paintStroke.StrokeMiter = strokeMiterLimit;
                                if (strokeStyle != PenStyle.Solid)
                                {
                                    paintStroke.PathEffect = strokeStyle.ToSkia(lineWidth, dashArray);
                                }
                                else
                                {
                                    paintStroke.PathEffect = null;
                                }
                                canvas.DrawPath(path, paintStroke);
                            }
                        }
                    }
            }
        }
示例#19
0
        private void Painted(object sender, SKPaintSurfaceEventArgs args)
        {
            var surface = args.Surface;
            var canvas  = surface.Canvas;
            var info    = args.Info;

            if (!_shouldAnimate)
            {
                _edges.Clear();
            }

            canvas = null;
            var john = new
            {
                canvas
            };

            canvas.Clear();

            var pointsPaint = new SKPaint
            {
                Style       = SKPaintStyle.StrokeAndFill,
                StrokeWidth = 8,
                Color       = SKColors.Black,
                StrokeCap   = SKStrokeCap.Round,
                IsAntialias = true
            };

            var pathsPaint = new SKPaint
            {
                Color       = SKColors.Black.WithAlpha(150),
                Style       = SKPaintStyle.Stroke,
                StrokeCap   = SKStrokeCap.Round,
                StrokeWidth = 2,
                IsAntialias = true
            };

            for (var i = 0; i < _origins.Count; i++)
            {
                canvas.DrawPoint(_origins[i], pointsPaint);

                if (i < _origins.Count - 1)
                {
                    var path = new SKPath();
                    path.MoveTo(_origins[i]);
                    path.LineTo(_origins[i + 1]);
                    canvas.DrawPath(path, pathsPaint);

                    if (!_shouldAnimate)
                    {
                        _edges.Add(new PathPoint
                        {
                            Path  = path,
                            Point = path.Points[0]
                        });
                    }
                }
            }

            if (!_shouldAnimate)
            {
                foreach (var edge in _edges)
                {
                    if (edge != _edges.Last())
                    {
                        edge.SubPath = new PathPoint
                        {
                            Point = edge.Path.Points[0],
                            Path  = edge.Path
                        }
                    }
                    ;
                }
            }

            if (_shouldAnimate)
            {
                pointsPaint.Color = SKColors.Red;

                foreach (var point in _edges)
                {
                    canvas.DrawPoint(point.Point, pointsPaint);
                }

                for (var i = 0; i < _edges.Count - 1; i++)
                {
                    var unitingPath = new SKPath();

                    unitingPath.MoveTo(_edges[i].Point);
                    unitingPath.LineTo(_edges[i + 1].Point);
                    pathsPaint.Color = SKColors.Blue;

                    _edges[i].SubPath.Path = unitingPath;

                    canvas.DrawPath(unitingPath, pathsPaint);
                }

                var subPaths  = _edges.Select(x => x.SubPath).Where(x => x != null);
                var subPoints = subPaths.Select(x => x.Point);

                foreach (var point in subPoints)
                {
                    var paint = pointsPaint;
                    paint.Color       = SKColors.Brown;
                    paint.StrokeWidth = 15;

                    _bezierCurve.LineTo(point);

                    canvas.DrawPoint(point, paint);
                }

                var bPaint = pathsPaint;
                bPaint.Color = SKColors.Red;
                canvas.DrawPath(_bezierCurve, bPaint);
            }
        }

        void StackTapped(object sender, SKPoint args)
        {
            _origins.Add(args);
            canvasView.InvalidateSurface();
        }

        void DoubleTapped(object sender, EventArgs e)
        {
            _shouldAnimate = false;
            _origins.Clear();
            _edges.Clear();

            canvasView.InvalidateSurface();
        }
示例#20
0
        private void OnPaint(object sender, SKPaintSurfaceEventArgs e)
        {
            Debug.WriteLine("PAINTING");

            // get the current surface from the event args
            var surface = e.Surface;
            // get the canvas that we can draw on
            var canvas = surface.Canvas;

            // clear the canvas / view
            canvas.Clear(SKColors.Transparent);

            // create the paint for drawing the triangle
            var trianglePaint = new SKPaint
            {
                IsAntialias = true,
                Style       = SKPaintStyle.Stroke,
                Color       = SKColors.DarkRed,
                StrokeWidth = 35
            };

            // create the paint for drawing the debug lines
            var linePaint = new SKPaint
            {
                IsAntialias = true,
                Style       = SKPaintStyle.Stroke,
                Color       = SKColors.Black,
                StrokeWidth = 10
            };

            //test vars
            //float mental = .9f, physical = .9f, spiritual = .9f;


            int centerX  = e.Info.Width / 2;
            int centerY  = e.Info.Height / 2;
            int maxwidth = e.Info.Width - 200;

            //calculate maximum point locations
            SKPoint maxMP = new SKPoint(centerX, centerY - maxwidth / 2);
            SKPoint maxSP = new SKPoint(centerX + (maxwidth / 2), centerY + (maxwidth / 2 * (float)Math.Tan(Math.PI / 6)));
            SKPoint maxMS = new SKPoint(centerX - (maxwidth / 2), centerY + (maxwidth / 2 * (float)Math.Tan(Math.PI / 6)));


            //calculate point offsets based on MEPS inputs
            float mpOffset = (mental + physical) / 20f;
            float spOffset = (spiritual + physical) / 20f;
            float msOffset = (mental + spiritual) / 20f;


            //calculate actual point locations
            SKPoint actualMP = new SKPoint(centerX, centerY - (maxwidth * mpOffset) / 2);
            SKPoint actualSP = new SKPoint((centerX + (maxwidth * spOffset / 2)), (centerY + (maxwidth * spOffset / 2 * (float)Math.Tan(Math.PI / 6))));
            SKPoint actualMS = new SKPoint((centerX - (maxwidth * msOffset / 2)), (centerY + (maxwidth * msOffset / 2 * (float)Math.Tan(Math.PI / 6))));

            //create paths
            SKPath guidePath    = new SKPath();
            SKPath trianglePath = new SKPath();
            SKPath emptyPath    = new SKPath();

            //path out guidePath
            guidePath.MoveTo(centerX, centerY);
            guidePath.LineTo(maxMP);
            guidePath.LineTo(maxMS);
            guidePath.LineTo(centerX, centerY);
            guidePath.MoveTo(maxMS);
            guidePath.LineTo(maxSP);
            guidePath.LineTo(centerX, centerY);
            guidePath.MoveTo(maxSP);
            guidePath.LineTo(maxMP);
            guidePath.Close();

            //path out trianglePath
            trianglePath.MoveTo(actualMS);
            trianglePath.LineTo(actualMP);
            trianglePath.LineTo(actualSP);
            trianglePath.LineTo(actualMS);
            trianglePath.Close();

            emptyPath.MoveTo(centerX, centerY);
            emptyPath.Close();

            trianglePath.FillType = SKPathFillType.Winding;

            //draw both paths
            canvas.DrawPath(guidePath, linePaint);
            canvas.DrawPath(trianglePath, trianglePaint);



            #region tenCircles

            ////get centerX, centerY, circleDiameter10, and interval
            //int centerX = e.Info.Width / 2;
            //int centerY = e.Info.Height / 2;
            //int circleDiameter10 = e.Info.Width - 100;
            //int interval = circleDiameter10 / 18;

            //SKRect MakeRect(int i)
            //{
            //    SKRect tempRect = new SKRect(50 + (i * interval),
            //                                 (e.Info.Height / 2) - (circleDiameter10 / 2) + (i * interval),
            //                                 (e.Info.Width - 50) - (i * interval),
            //                                 (e.Info.Height / 2) + (circleDiameter10 / 2) - (i * interval));
            //    return tempRect;
            //}



            //// create the paint for the circle border
            //var testPaint = new SKPaint
            //{
            //    IsAntialias = true,
            //    Style = SKPaintStyle.Stroke,
            //    Color = SKColors.Black,
            //    StrokeWidth = 1
            //};


            //SKRect rect10 = MakeRect(0);
            //SKRect rect9 = MakeRect(1);
            //SKRect rect8 = MakeRect(2);
            //SKRect rect7 = MakeRect(3);
            //SKRect rect6 = MakeRect(4);
            //SKRect rect5 = MakeRect(5);
            //SKRect rect4 = MakeRect(6);
            //SKRect rect3 = MakeRect(7);
            //SKRect rect2 = MakeRect(8);
            //SKRect rect1 = MakeRect(9);



            //float startAngle = 0;
            //float sweepAngle = 360;



            //using (SKPath path = new SKPath())
            //{
            //    path.AddArc(rect10, startAngle, sweepAngle);
            //    path.AddArc(rect9, startAngle, sweepAngle);
            //    path.AddArc(rect8, startAngle, sweepAngle);
            //    path.AddArc(rect7, startAngle, sweepAngle);
            //    path.AddArc(rect6, startAngle, sweepAngle);
            //    path.AddArc(rect5, startAngle, sweepAngle);
            //    path.AddArc(rect4, startAngle, sweepAngle);
            //    path.AddArc(rect3, startAngle, sweepAngle);
            //    path.AddArc(rect2, startAngle, sweepAngle);
            //    path.AddArc(rect1, startAngle, sweepAngle);

            //    canvas.DrawPath(path, testPaint);
            //}

            #endregion
        }
示例#21
0
 public static void PathStroke(SKCanvas canvas, SKPaint paint, SKColor strokeColor, SKPath path)
 {
     paint.Style = SKPaintStyle.Stroke;
     paint.Color = strokeColor;
     canvas.DrawPath(path, paint);
 }
示例#22
0
 public Path(SKPath path, SKStrokeCap cap, SKStrokeJoin join)
 {
     source    = path;
     this.cap  = cap;
     this.join = join;
 }
示例#23
0
 public static void PathFill(SKCanvas canvas, SKPaint paint, SKColor fillColor, SKPath path)
 {
     paint.Style = SKPaintStyle.Fill;
     paint.Color = fillColor;
     canvas.DrawPath(path, paint);
 }
示例#24
0
        public void DrawDropletPulledVer(SKCanvas canvas, string label, bool biggie, SKPoint c1, SKPoint c2, KDeviceHandler.Direction dir, float r, float r1, float neckX, float r2, float textStrokeWidth, SKPaint fillPaint, float strokeWidth, float accentStrokeWidth, Swipe swipe)
        {
            float ratio = ((r1 + r2) / 2) / r;

            //strokeWidth = strokeWidth * ratio;
            textStrokeWidth   = textStrokeWidth * ratio;
            accentStrokeWidth = accentStrokeWidth * ratio;

            float lr = r1 - (strokeWidth + accentStrokeWidth) / 2.0f;
            float dr = r2 - (strokeWidth + accentStrokeWidth) / 2.0f;

            // place the neck in an Y-position proportional to the rate between r1 and r2, with m1+r1Y to the top leading to c1.Y, and m2+r2Y to the bot leading to c2.Y
            float m1 = (2 * r - (r1 + r2)) / (1 + r2 / r1);
            float m2 = m1 * r2 / r1;
            // position of the neck
            float nY = c1.Y + r1 + m1;
            float nX = c1.X;
            // Control points: a1*2 is on a line from nY,nX-neckX to c1.Y,c.X-r1 where it intersects c1.Y+r1; we divide it by 2 to make the curve smoother
            float a1 = (m1 * (r1 - neckX) / (r1 + m1)) / 2;
            float a2 = (m2 * (r2 - neckX) / (r2 + m2)) / 2;

            var path = new SKPath();

            path.MoveTo(swipe % new SKPoint(c1.X - r1, c1.Y));
            path.CubicTo(swipe % new SKPoint(c1.X - r1, c1.Y + 0.5f * r1), swipe % new SKPoint(nX - (neckX + a1), c1.Y + r1), swipe % new SKPoint(nX - neckX, nY));
            path.CubicTo(swipe % new SKPoint(nX - (neckX + a2), c2.Y - r2), swipe % new SKPoint(c2.X - r2, c2.Y - 0.5f * r2), swipe % new SKPoint(c2.X - r2, c2.Y));

            path.CubicTo(swipe % new SKPoint(c2.X - r2, c2.Y + 0.75f * r2), swipe % new SKPoint(c2.X - 0.75f * r2, c2.Y + r2), swipe % new SKPoint(c2.X, c2.Y + r2));
            path.CubicTo(swipe % new SKPoint(c2.X + 0.75f * r2, c2.Y + r2), swipe % new SKPoint(c2.X + r2, c2.Y + 0.75f * r2), swipe % new SKPoint(c2.X + r2, c2.Y));

            path.CubicTo(swipe % new SKPoint(c2.X + r2, c2.Y - 0.5f * r2), swipe % new SKPoint(nX + (neckX + a2), c2.Y - r2), swipe % new SKPoint(nX + neckX, nY));
            path.CubicTo(swipe % new SKPoint(nX + (neckX + a1), c1.Y + r1), swipe % new SKPoint(c1.X + r1, c1.Y + 0.5f * r1), swipe % new SKPoint(c1.X + r1, c1.Y));

            path.CubicTo(swipe % new SKPoint(c1.X + r1, c1.Y - 0.75f * r1), swipe % new SKPoint(c1.X + 0.75f * r1, c1.Y - r1), swipe % new SKPoint(c1.X, c1.Y - r1));
            path.CubicTo(swipe % new SKPoint(c1.X - 0.75f * r1, c1.Y - r1), swipe % new SKPoint(c1.X - r1, c1.Y - 0.75f * r1), swipe % new SKPoint(c1.X - r1, c1.Y));
            path.Close();

            var darkPath = new SKPath();

            darkPath.MoveTo(swipe % new SKPoint(c2.X, c2.Y + dr));
            darkPath.CubicTo(swipe % new SKPoint(c2.X + 0.75f * dr, c2.Y + dr), swipe % new SKPoint(c2.X + dr, c2.Y + 0.75f * dr), swipe % new SKPoint(c2.X + dr, c2.Y));

            var lightPath = new SKPath();

            lightPath.MoveTo(swipe % new SKPoint(c1.X, c1.Y - lr));
            lightPath.CubicTo(swipe % new SKPoint(c1.X - 0.75f * lr, c1.Y - lr), swipe % new SKPoint(c1.X - lr, c1.Y - 0.75f * lr), swipe % new SKPoint(c1.X - lr, c1.Y));

            using (var strokePaint = new SKPaint {
                Style = SKPaintStyle.Stroke, Color = new SKColor(0, 0, 0, 191), StrokeWidth = swipe % strokeWidth, IsAntialias = true
            })
                using (var accentLightPaint = new SKPaint {
                    Style = SKPaintStyle.Stroke, Color = new SKColor(255, 255, 255, 191), StrokeWidth = swipe % accentStrokeWidth, StrokeCap = SKStrokeCap.Round, IsAntialias = true
                })
                    using (var accentDarkPaint = new SKPaint {
                        Style = SKPaintStyle.Stroke, Color = new SKColor(0, 0, 0, 95), StrokeWidth = swipe % accentStrokeWidth, StrokeCap = SKStrokeCap.Round, IsAntialias = true
                    }) {
                        canvas.DrawPath(path, fillPaint);
                        canvas.DrawPath(darkPath, accentDarkPaint);
                        canvas.DrawPath(lightPath, accentLightPaint);
                        canvas.DrawPath(path, strokePaint);
                    }

            float   rYtext = (r1 == r2) ? ((dir == KDeviceHandler.Direction.Top) ? r1 : r2) : (r1 > r2) ? r1 : r2;
            SKPoint cText  = (r1 == r2) ? ((dir == KDeviceHandler.Direction.Top) ? c1 : c2) : (r1 > r2) ? c1 : c2;

            DrawDropletLabel(canvas, label, cText, rYtext, textStrokeWidth, biggie, swipe);
        }
示例#25
0
        public static void OnPainting(object sender, SKPaintSurfaceEventArgs e)
        {
            // CLEARING THE SURFACE

            // we get the current surface from the event args
            var surface = e.Surface;
            // then we get the canvas that we can draw on
            var canvas = surface.Canvas;

            // clear the canvas / view
            canvas.Clear(SKColors.White);


            // DRAWING SHAPES

            // create the paint for the filled circle
            var circleFill = new SKPaint
            {
                IsAntialias = true,
                Style       = SKPaintStyle.Fill,
                Color       = SKColors.Blue
            };

            // draw the circle fill
            canvas.DrawCircle(100, 100, 40, circleFill);

            // create the paint for the circle border
            var circleBorder = new SKPaint
            {
                IsAntialias = true,
                Style       = SKPaintStyle.Stroke,
                Color       = SKColors.Red,
                StrokeWidth = 5
            };

            // draw the circle border
            canvas.DrawCircle(100, 100, 40, circleBorder);


            // DRAWING PATHS

            // create the paint for the path
            var pathStroke = new SKPaint
            {
                IsAntialias = true,
                Style       = SKPaintStyle.Stroke,
                Color       = SKColors.Green,
                StrokeWidth = 5
            };

            // create a path
            var path = new SKPath();

            path.MoveTo(160, 60);
            path.LineTo(240, 140);
            path.MoveTo(240, 60);
            path.LineTo(160, 140);

            // draw the path
            canvas.DrawPath(path, pathStroke);


            // DRAWING TEXT

            // create the paint for the text
            var textPaint = new SKPaint
            {
                IsAntialias = true,
                Style       = SKPaintStyle.Fill,
                Color       = SKColors.Orange,
                TextSize    = 80
            };

            // draw the text (from the baseline)
            canvas.DrawText("SkiaSharp", 60, 160 + 80, textPaint);
        }
示例#26
0
 public static void FillPath(SKCanvas g, SKPath p, SKPaint fill)
 {
     g.DrawPath(p, fill);
 }
示例#27
0
        private void DrawSeriesLine(SKCanvas canvas, SKSize itemSize)
        {
            if (pointsPerSerie.Any() && pointsPerSerie.Values.First().Count > 1 && LineMode != LineMode.None)
            {
                foreach (var s in Series)
                {
                    var points = pointsPerSerie[s].ToArray();
                    using (var paint = new SKPaint
                    {
                        Style = SKPaintStyle.Stroke,
                        Color = s.Color ?? SKColors.White,
                        StrokeWidth = LineSize,
                        IsAntialias = true,
                    })
                    {
                        if (s.Color == null)
                        {
                            using (var shader = CreateXGradient(points, s.Entries, s.Color))
                                paint.Shader = shader;
                        }

                        var path = new SKPath();
                        //path.MoveTo(points.First());

                        var isFirst  = true;
                        var entries  = s.Entries;
                        var lineMode = LineMode;
                        var last     = (lineMode == LineMode.Spline) ? points.Length - 1 : points.Length;
                        for (int i = 0; i < last; i++)
                        {
                            if (!entries.ElementAt(i).Value.HasValue)
                            {
                                continue;
                            }
                            if (isFirst)
                            {
                                path.MoveTo(points[i]);
                                isFirst = false;
                            }


                            if (lineMode == LineMode.Spline)
                            {
                                int next = i + 1;
                                while (next < last && !entries.ElementAt(next).Value.HasValue)
                                {
                                    next++;
                                }

                                if (next == last && !entries.ElementAt(next).Value.HasValue)
                                {
                                    break;
                                }

                                var cubicInfo = CalculateCubicInfo(points, i, next, itemSize);
                                path.CubicTo(cubicInfo.control, cubicInfo.nextControl, cubicInfo.nextPoint);
                            }
                            else if (lineMode == LineMode.Straight)
                            {
                                path.LineTo(points[i]);
                            }
                        }

                        canvas.DrawPath(path, paint);
                    }
                }
            }
        }
示例#28
0
 private GraphicsPath(SKPath from)
 {
     skPath = from;
 }
示例#29
0
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs eventArgs)
        {
            var givenCanvas = eventArgs.Surface.Canvas;

            givenCanvas.Clear();

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

            SKBitmap backgroundImageBitmap = new SKBitmap();

            //// Background image
            //if (this.imageBackground != "")
            //{
            //    string resourceID = this.imageBackground;
            //    Assembly assembly = GetType().GetTypeInfo().Assembly;

            //    using (Stream stream = assembly.GetManifestResourceStream(resourceID))
            //    {
            //        backgroundImageBitmap = SKBitmap.Decode(stream);
            //    }
            //}

            // Background progress circle
            SKPaint progressPaint = new SKPaint()
            {
                Color       = this.ColorBackground.ToSKColor(),
                Style       = SKPaintStyle.Stroke,
                StrokeJoin  = SKStrokeJoin.Round,
                IsStroke    = true,
                StrokeWidth = 30,
                IsAntialias = true
            };
            SKRect progressRect = new SKRect();

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

            progressPath.AddArc(progressRect, -90, 360);

            // Current progress circle
            SKPaint progressCurrentPaint = new SKPaint()
            {
                Color       = this.ColorPrimary.ToSKColor(),
                Style       = SKPaintStyle.Stroke,
                StrokeJoin  = SKStrokeJoin.Round,
                IsStroke    = true,
                StrokeCap   = SKStrokeCap.Round,
                StrokeWidth = 30,
                IsAntialias = true
            };

            if (this.IsGradient)
            {
                progressCurrentPaint.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 progressCurrentRect = new SKRect();

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

            progressCurrentPath.AddArc(progressCurrentRect, -90, this.progressCurrentSweepAngle);

            // Current progress text
            SKPaint progrssCurrentTextPaint = new SKPaint()
            {
                Color       = this.ColorPrimary.ToSKColor(),
                TextAlign   = SKTextAlign.Center,
                TextSize    = TextSize,
                IsAntialias = true
            };

            givenCanvas.ClipPath(progressPath, SKClipOperation.Intersect, true);

            //if(this.imageBackground != "")
            //{
            //    givenCanvas.DrawBitmap(
            //        backgroundImageBitmap,
            //        new SKRect(
            //            0,
            //            0,
            //            this.canvasWidth,
            //            this.canvasHeight
            //        )
            //    );
            //}

            givenCanvas.DrawPath(progressPath, progressPaint);
            givenCanvas.DrawPath(progressCurrentPath, progressCurrentPaint);
            var percentageIndicator = DisplayAsPercentage ? "%" : "";

            if (DisplayValue)
            {
                if (FormatProvider == null || CustomFormat == null)
                {
                    givenCanvas.DrawText(string.Format("{0}" + $"{percentageIndicator}", this.progressCurrentTextValue), (canvasWidth + 20) / 2, (canvasHeight + 20 + 35) / 2, progrssCurrentTextPaint);
                }

                if (FormatProvider != null && CustomFormat != null)
                {
                    givenCanvas.DrawText(string.Format(FormatProvider, CustomFormat, this.progressCurrentTextValue), (canvasWidth + 20) / 2, (canvasHeight + 20 + 35) / 2, progrssCurrentTextPaint);
                }
            }
        }
示例#30
0
        private void DrawLineArea(SKCanvas canvas, ChartSerie serie, 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,
                })
                {
                    using (var shaderX = CreateXGradient(points, serie.Entries, serie.Color, (byte)(LineAreaAlpha * AnimationProgress)))
                        using (var shaderY = CreateYGradient(points, (byte)(LineAreaAlpha * AnimationProgress)))
                        {
                            paint.Shader = EnableYFadeOutGradient ? SKShader.CreateCompose(shaderY, shaderX, SKBlendMode.SrcOut) : shaderX;

                            var path = new SKPath();

                            var     isFirst   = true;
                            var     entries   = serie.Entries;
                            var     lineMode  = LineMode;
                            var     last      = (lineMode == LineMode.Spline) ? points.Length - 1 : points.Length;
                            SKPoint lastPoint = points.First();
                            for (int i = 0; i < last; i++)
                            {
                                if (!entries.ElementAt(i).Value.HasValue)
                                {
                                    continue;
                                }

                                if (isFirst)
                                {
                                    path.MoveTo(points[i].X, origin);
                                    path.LineTo(points[i]);
                                    isFirst = false;
                                }

                                if (lineMode == LineMode.Spline)
                                {
                                    int next = i + 1;
                                    while (next < last && !entries.ElementAt(next).Value.HasValue)
                                    {
                                        next++;
                                    }

                                    if (next == last && !entries.ElementAt(next).Value.HasValue)
                                    {
                                        lastPoint = points[i];
                                        break;
                                    }

                                    var cubicInfo = CalculateCubicInfo(points, i, next, itemSize);
                                    path.CubicTo(cubicInfo.control, cubicInfo.nextControl, cubicInfo.nextPoint);
                                    lastPoint = cubicInfo.nextPoint;
                                }
                                else if (lineMode == LineMode.Straight)
                                {
                                    path.LineTo(points[i]);
                                    lastPoint = points[i];
                                }
                            }

                            path.LineTo(lastPoint.X, origin);
                            path.Close();
                            canvas.DrawPath(path, paint);
                        }
                }
            }
        }
示例#31
0
 public override void Render(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint)
 {
 }
        private void OnTouch(object sender, SKTouchEventArgs e)
        {
            var mouse = new MouseEventArgs()
            {
                X      = (int)e.Location.X,
                Y      = (int)e.Location.Y,
                Button = e.MouseButton == SKMouseButton.Left ? MouseButtons.Left :
                         e.MouseButton == SKMouseButton.Unknown ? MouseButtons.None :
                         e.MouseButton == SKMouseButton.Right ? MouseButtons.Right : MouseButtons.Middle,
                Delta = 0 // mouse wheel
            };

            Form.MousePosition = new Point((int)e.Location.X, (int)e.Location.Y);

            // pinching - multiple paths at once
            if (temporaryPaths.Count > 1)
            {
                //System.Diagnostics.Debug.WriteLine(temporaryPaths.ToJSON());

                var key1 = temporaryPaths.Keys.ElementAt(0);
                var key2 = temporaryPaths.Keys.ElementAt(1);

                var startdist = temporaryPaths[key1].Points.First() - temporaryPaths[key2].Points.First();
                var enddist   = temporaryPaths[key1].Points.Last() - temporaryPaths[key2].Points.Last();

                var delta = enddist - startdist;



                //tru is smaller
                //System.Diagnostics.Debug.WriteLine(delta + " " + delta.Length + " " + (startdist.Length > enddist.Length));

                var m1 = new SKPoint(temporaryPaths[key1].Bounds.MidX, temporaryPaths[key1].Bounds.MidY);
                var m2 = new SKPoint(temporaryPaths[key2].Bounds.MidX, temporaryPaths[key2].Bounds.MidY);

                var mid = m1 - m2;

                mouse.X = (int)(m2.X + mid.X / 2.0);
                mouse.Y = (int)(m2.Y + mid.Y / 2.0);

                // set it only after length movement
                if (delta.Length > mousewheeldelta + 10 || delta.Length < mousewheeldelta - 10)
                {
                    mouse.Delta = (startdist.Length > enddist.Length) ? -1 : 1;

                    System.Diagnostics.Debug.WriteLine(delta + " " + delta.Length + " " +
                                                       (startdist.Length > enddist.Length) + " " +
                                                       ((startdist.Length > enddist.Length) ? -1 : 1));


                    mousewheeldelta = delta.Length;
                }
                OnMouseEnter(null);
                // set mouse centre on pinch
                OnMouseMove(mouse);
                // do the scroll
                OnMouseWheel(mouse);
                OnMouseLeave(null);
            }
            else
            {
                if (e.ActionType == SKTouchAction.Moved)
                {
                    OnMouseMove(mouse);
                }

                if (e.ActionType == SKTouchAction.Pressed)
                {
                    OnMouseDown(mouse);
                }

                if (e.ActionType == SKTouchAction.Released)
                {
                    OnMouseUp(mouse);
                    OnMouseClick(mouse);
                }

                if (e.ActionType == SKTouchAction.Entered)
                {
                    OnMouseEnter(null);
                }

                if (e.ActionType == SKTouchAction.Exited)
                {
                    OnMouseLeave(null);
                }
            }

            switch (e.ActionType)
            {
            case SKTouchAction.Pressed:
                // start of a stroke
                var p = new SKPath();
                p.MoveTo(e.Location);
                temporaryPaths[e.Id] = p;
                Invalidate();
                break;

            case SKTouchAction.Moved:
                // the stroke, while pressed
                if (e.InContact && temporaryPaths.ContainsKey(e.Id))
                {
                    temporaryPaths[e.Id].LineTo(e.Location);
                }
                break;

            case SKTouchAction.Released:
                // end of a stroke
                //paths.Add(temporaryPaths[e.Id]);
                temporaryPaths.Remove(e.Id);
                Invalidate();
                break;

            case SKTouchAction.Cancelled:
                // we don't want that stroke
                temporaryPaths.Remove(e.Id);
                break;
            }

            //System.Diagnostics.Debug.WriteLine(e.ToJSON());

            // we have handled these events
            e.Handled = true;
        }
示例#33
0
 public static SKPath Clone(this SKPath src)
 {
     return(src != null ? new SKPath(src) : null);
 }