示例#1
0
        public static SKPathEffect ToSkia(this PenStyle penStyle, float width, float[] dashArray = null, float dashOffset = 0)
        {
            switch (penStyle)
            {
            case PenStyle.UserDefined:
                // If dashArray is empty or not even, create sold dash
                if (dashArray == null || dashArray.Length == 0 || dashArray.Length % 2 != 0)
                {
                    return(SKPathEffect.CreateDash(new float[0], 0));
                }
                // Multiply each dash entry with line width
                float[] dash = new float[dashArray.Length];
                for (var i = 0; i < dashArray.Length; i++)
                {
                    dash[i] = dashArray[i] * width;
                }
                return(SKPathEffect.CreateDash(dash, dashOffset));

            case PenStyle.Dash:
                return(SKPathEffect.CreateDash(new [] { width * 4f, width * 3f }, dashOffset));

            case PenStyle.Dot:
                return(SKPathEffect.CreateDash(new [] { width * 1f, width * 3f }, dashOffset));

            case PenStyle.DashDot:
                return(SKPathEffect.CreateDash(new [] { width * 4f, width * 3f, width * 1f, width * 3f }, dashOffset));

            case PenStyle.DashDotDot:
                return(SKPathEffect.CreateDash(new [] { width * 4f, width * 3f, width * 1f, width * 3f, width * 1f, width * 3f }, dashOffset));

            case PenStyle.LongDash:
                return(SKPathEffect.CreateDash(new [] { width * 8f, width * 3f }, dashOffset));

            case PenStyle.LongDashDot:
                return(SKPathEffect.CreateDash(new [] { width * 8f, width * 3f, width * 1f, width * 3f }, dashOffset));

            case PenStyle.ShortDash:
                return(SKPathEffect.CreateDash(new [] { width * 2f, width * 3f }, dashOffset));

            case PenStyle.ShortDashDot:
                return(SKPathEffect.CreateDash(new [] { width * 2f, width * 3f, width * 1f, width * 3f }, dashOffset));

            case PenStyle.ShortDashDotDot:
                return(SKPathEffect.CreateDash(new [] { width * 2f, width * 3f, width * 1f, width * 3f, width * 1f, width * 3f }, dashOffset));

            case PenStyle.ShortDot:
                return(SKPathEffect.CreateDash(new [] { width * 1f, width * 3f }, dashOffset));

            default:
                return(SKPathEffect.CreateDash(new float[0], dashOffset));
            }
        }
示例#2
0
        private void PaintChessPattern(SKCanvas canvas, SliderLocation slider, SKSize canvasSize)
        {
            var    pickerRadiusPixels = GetPickerRadiusPixels();
            var    sliderTop          = slider.GetSliderOffset(pickerRadiusPixels);
            var    scale = pickerRadiusPixels / 3;
            SKPath path  = new SKPath();

            path.MoveTo(-1 * scale, -1 * scale);
            path.LineTo(0 * scale, -1 * scale);
            path.LineTo(0 * scale, 0 * scale);
            path.LineTo(1 * scale, 0 * scale);
            path.LineTo(1 * scale, 1 * scale);
            path.LineTo(0 * scale, 1 * scale);
            path.LineTo(0 * scale, 0 * scale);
            path.LineTo(-1 * scale, 0 * scale);
            path.LineTo(-1 * scale, -1 * scale);

            SKMatrix matrix = SKMatrix.MakeScale(2 * scale, 2 * scale);
            SKPaint  paint  = new SKPaint
            {
                PathEffect  = SKPathEffect.Create2DPath(matrix, path),
                Color       = Color.LightGray.ToSKColor(),
                IsAntialias = true
            };

            SKRect      patternRect;
            SKRect      clipRect;
            SKRoundRect clipRoundRect;

            if (Vertical)
            {
                patternRect = new SKRect(sliderTop - pickerRadiusPixels, pickerRadiusPixels
                                         , sliderTop + pickerRadiusPixels, canvasSize.Height - pickerRadiusPixels);
                clipRect = new SKRect(sliderTop - (pickerRadiusPixels * 0.65f), pickerRadiusPixels * 1.35f
                                      , sliderTop + (pickerRadiusPixels * 0.65f), canvasSize.Height - (pickerRadiusPixels * 1.35f));
                clipRoundRect = new SKRoundRect(clipRect, pickerRadiusPixels * 0.65f, pickerRadiusPixels * 0.65f);
            }
            else
            {
                patternRect = new SKRect(pickerRadiusPixels, sliderTop - pickerRadiusPixels
                                         , canvasSize.Width - pickerRadiusPixels, sliderTop + pickerRadiusPixels);
                clipRect = new SKRect(pickerRadiusPixels * 1.35f, sliderTop - (pickerRadiusPixels * 0.65f)
                                      , canvasSize.Width - (pickerRadiusPixels * 1.35f), sliderTop + (pickerRadiusPixels * 0.65f));
                clipRoundRect = new SKRoundRect(clipRect, pickerRadiusPixels * 0.65f, pickerRadiusPixels * 0.65f);
            }

            canvas.Save();
            canvas.ClipRoundRect(clipRoundRect);
            canvas.DrawRect(patternRect, paint);
            canvas.Restore();
        }
示例#3
0
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            GridPos tempStart = new GridPos(11, 35);


            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;

            surfaceCanvas = surface.Canvas;

            System.Diagnostics.Debug.WriteLine(info.Width + "Width");
            System.Diagnostics.Debug.WriteLine(info.Height + "Height");
            App.ScreenHeight = info.Height;
            App.ScreenWidth  = info.Width;

            route = new Routing(tempStart, myDestination, myGrid);
            List <GridPos> pathList = route.GetNodes();

            pathList.Reverse();

            surfaceCanvas.Clear();

            using (SKPath path = new SKPath())
            {
                for (int p = 0; p < pathList.Count; p++)
                {
                    System.Diagnostics.Debug.WriteLine("....");
                    System.Diagnostics.Debug.WriteLine("path.LineTo(" + pathList[p].x + ", " + pathList[p].y + ");");
                    if (p == 0)
                    {
                        path.MoveTo(pathList[0].x, pathList[0].y);
                    }
                    else
                    {
                        path.LineTo(pathList[p].x, pathList[p].y);
                    }
                }


                using (SKPaint paint = new SKPaint())
                {
                    paint.Style       = SKPaintStyle.Stroke;
                    paint.Color       = SKColors.Blue;
                    paint.StrokeWidth = 6;
                    paint.PathEffect  = SKPathEffect.CreateDash(new float[] { 5, 5 }, dashPhase);

                    surfaceCanvas.DrawPath(path, paint);
                }
            }
        }
示例#4
0
        private void DrawLines(ChartItem chartItem, SKCanvas canvas, SKPoint[] points)
        {
            if (points?.Any() != true)
            {
                return;
            }

            using (var paint = new SKPaint
            {
                Style = SKPaintStyle.Stroke,
                StrokeCap = SKStrokeCap.Round,
                IsStroke = true,
                Color = chartItem.Color.ToSKColor(),
                StrokeWidth = chartItem.LineWidth,
                IsAntialias = true
            })
            {
                if (chartItem.UseDashedEffect)
                {
                    paint.PathEffect = SKPathEffect.CreateDash(new float[] { 12, 12 }, 0);
                }

                var path = new SKPath();

                path.MoveTo(points.First());

                var last = LineMode == LineMode.Straight ? points.Length : points.Length - 1;

                for (int i = 0; i < last; i++)
                {
                    if (LineMode == LineMode.Spline)
                    {
                        var point = points[i];
                        var nextPoint = points[i + 1];
                        var offsetPoint = new SKPoint((nextPoint.X - point.X) * 0.8f, 0);

                        var currentPoint = point + offsetPoint;
                        var next = nextPoint - offsetPoint;

                        path.CubicTo(currentPoint, next, nextPoint);
                    }
                    else
                    {
                        path.LineTo(points[i]);
                    }
                }

                canvas.DrawPath(path, paint);
            }
        }
        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);
        }
示例#6
0
        /// <summary>
        /// Get called when drawing is required
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SkCanvasViewRequiredPainting(object sender, SKPaintSurfaceEventArgs e)
        {
            // get and clear the canvas
            SKCanvas canvas = e.Surface.Canvas;

            canvas.Clear();

            // if the border path is null generate the path
            _borderPath = _borderPath ?? GeneratePath(_paint);

            // set the dash effect to the generated border path and draw it on the canvas
            _paint.PathEffect = SKPathEffect.CreateDash(_strokeDashStart.Intervals, _strokeDashStart.Phase);
            canvas.DrawPath(_borderPath, _paint);
        }
示例#7
0
 public SkiaSharpRenderer(IViewControl viewControl, IWorkspace workspace)
 {
     ViewControl = viewControl;
     Workspace   = workspace;
     InitializeComponent();
     DashedLines = SKPathEffect.CreateDash(new[] { 4.0f, 4.0f }, 0.0f);
     // TODO: tune these
     Workspace.CommandExecuted                    += (o, args) => Invalidate();
     Workspace.CommandExecuting                   += (o, args) => Invalidate();
     Workspace.RubberBandGeneratorChanged         += (o, args) => Invalidate();
     Workspace.SelectedEntities.CollectionChanged += (o, args) => Invalidate();
     Workspace.SettingsService.SettingChanged     += (o, args) => Invalidate();
     Workspace.WorkspaceChanged                   += (o, args) => Invalidate();
 }
示例#8
0
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
        {
            var     canvas  = e.Surface.Canvas;
            var     min     = (float)Math.Min(CanvasSize.Width, CanvasSize.Height);
            float   radius  = min * 0.4f;
            float   scaling = (float)(CanvasSize.Width / Width);
            var     center  = new SKPoint(CanvasSize.Width / 2, min * 0.1f + radius);
            SKPaint paint   = new SKPaint
            {
                Color       = Color.LightGray.ToSKColor(),
                StrokeWidth = 5 * scaling,
                Style       = SKPaintStyle.StrokeAndFill,
                TextSize    = 12 * scaling,
                IsAntialias = true
            };

            canvas.Clear();
            canvas.DrawCircle(center, radius, paint);

            // draw lines
            paint.Style       = SKPaintStyle.Stroke;
            paint.StrokeWidth = 1 * scaling;
            paint.Color       = Color.Gray.ToSKColor();
            canvas.DrawLine(center.X - radius, center.Y, center.X + radius, center.Y, paint);
            canvas.DrawLine(center.X, center.Y - radius, center.X, center.Y + radius, paint);

            // degree markers
            paint.Color = Color.Black.ToSKColor();
            DrawText(canvas, paint, "0", center.X + radius, center.Y, TextPosition.Left);
            DrawText(canvas, paint, "90", center.X, center.Y - radius, TextPosition.Bottom);
            DrawText(canvas, paint, "180", center.X - radius, center.Y, TextPosition.Right);
            DrawText(canvas, paint, "270", center.X, center.Y + radius, TextPosition.Top);

            paint.PathEffect = SKPathEffect.CreateDash(new float[] { 10, 10 }, 0);
            canvas.DrawCircle(center, radius / 3, paint);
            canvas.DrawCircle(center, radius * 2 / 3, paint);

            paint.PathEffect  = null;
            paint.Color       = Color.Orange.ToSKColor();
            paint.StrokeCap   = SKStrokeCap.Round;
            paint.StrokeWidth = 5 * scaling;
            var p1 = new SKPoint((float)(center.X + radius * 0.9f * Math.Cos(FAngle)),
                                 (float)(center.Y - radius * 0.9f * Math.Sin(FAngle)));

            canvas.DrawLine(center, p1, paint);

            paint.Color = Color.Gray.ToSKColor();
            paint.Style = SKPaintStyle.StrokeAndFill;
            canvas.DrawCircle(center, 5 * scaling, paint);
        }
示例#9
0
文件: OxyPlot.cs 项目: w8w8w8/dwsim5
        /// <summary>
        /// Sets the stroke style.
        /// </summary>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="lineJoin">The line join.</param>
        /// <param name="aliased">Use aliased strokes if set to <c>true</c>.</param>
        private void SetStroke(OxyColor stroke, double thickness, double[] dashArray = null, LineJoin lineJoin = LineJoin.Miter, bool aliased = false)
        {
            this.paint.Style       = SKPaintStyle.Stroke;
            this.paint.Color       = stroke.ToSKColor();
            this.paint.StrokeWidth = this.Convert(thickness);
            this.paint.StrokeJoin  = lineJoin.Convert();
            if (dashArray != null)
            {
                var dashArrayF = dashArray.Select(this.Convert).ToArray();
                this.paint.PathEffect = SKPathEffect.CreateDash(dashArrayF, 0f);
            }

            this.paint.IsAntialias = !aliased;
        }
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            int   numVertices = 7;
            float radius      = 0.45f * Math.Min(info.Width, info.Height);

            SKPoint[] vertices    = new SKPoint[numVertices];
            double    vertexAngle = -0.5f * Math.PI;    // straight up

            // Coordinates of the vertices of the polygon
            for (int vertex = 0; vertex < numVertices; vertex++)
            {
                vertices[vertex] = new SKPoint(radius * (float)Math.Cos(vertexAngle),
                                               radius * (float)Math.Sin(vertexAngle));
                vertexAngle += 2 * Math.PI / numVertices;
            }

            float cornerRadius = 100;

            // Create the path
            using (SKPath path = new SKPath())
            {
                path.AddPoly(vertices, true);

                // Render the path in the center of the screen
                using (SKPaint paint = new SKPaint())
                {
                    paint.Style       = SKPaintStyle.Stroke;
                    paint.Color       = SKColors.Blue;
                    paint.StrokeWidth = 10;

                    // Set argument to half the desired corner radius!
                    paint.PathEffect = SKPathEffect.CreateCorner(cornerRadius / 2);

                    canvas.Translate(info.Width / 2, info.Height / 2);
                    canvas.DrawPath(path, paint);

                    // Uncomment DrawCircle call to verify corner radius
                    float offset = cornerRadius / (float)Math.Sin(Math.PI * (numVertices - 2) / numVertices / 2);
                    paint.Color = SKColors.Green;
                    // canvas.DrawCircle(vertices[0].X, vertices[0].Y + offset, cornerRadius, paint);
                }
            }
        }
示例#11
0
 public void Apply(SKPaint stroke)
 {
     double[] dashArray = DashArray;
     if (dashArray.Length > 0)
     {
         if (dashArray.Length % 2 != 0)
         {
             var list = new double[dashArray.Length + 1];
             System.Array.Copy(dashArray, 0, list, 0, dashArray.Length);
             list[dashArray.Length] = dashArray[dashArray.Length - 1];
             dashArray = list;
         }
         stroke.PathEffect = SKPathEffect.CreateDash(ConvertUtils.ToFloatArray(dashArray), (float)DashPhase);
     }
 }
示例#12
0
        internal void ApplyToSKPaint(SKPaint skPaint)
        {
            skPaint.Color       = new SKColor((uint)Color.Value);
            skPaint.Style       = SKPaintStyle.Stroke;
            skPaint.StrokeWidth = Width;

            if (dashStyle != DashStyle.Solid)
            {
                if (skPathEffect == null)
                {
                    skPathEffect = SKPathEffect.CreateDash(DashPattern, 0);
                }
                skPaint.PathEffect = skPathEffect;
            }
        }
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            float width          = info.Width / 3;
            float verticalMargin = width / 2 + 150;

            using (SKPath conveyerPath = new SKPath())
            {
                // Straight verticals capped by semicircles on top and bottom
                conveyerPath.MoveTo(width, verticalMargin);
                conveyerPath.ArcTo(width / 2, width / 2, 0, SKPathArcSize.Large,
                                   SKPathDirection.Clockwise, 2 * width, verticalMargin);
                conveyerPath.LineTo(2 * width, info.Height - verticalMargin);
                conveyerPath.ArcTo(width / 2, width / 2, 0, SKPathArcSize.Large,
                                   SKPathDirection.Clockwise, width, info.Height - verticalMargin);
                conveyerPath.Close();

                // Draw the conveyor belt itself
                canvas.DrawPath(conveyerPath, conveyerPaint);

                // Calculate spacing based on length of conveyer path
                float length = 2 * (info.Height - 2 * verticalMargin) +
                               2 * ((float)Math.PI * width / 2);

                // Value will be somewhere around 200
                float spacing = length / (float)Math.Round(length / 200);

                // Now animate the phase; t is 0 to 1 every 2 seconds
                TimeSpan timeSpan = new TimeSpan(DateTime.Now.Ticks);
                float    t        = (float)(timeSpan.TotalSeconds % 2 / 2);
                float    phase    = -t * spacing;

                // Create the buckets PathEffect
                using (SKPathEffect bucketsPathEffect =
                           SKPathEffect.Create1DPath(bucketPath, spacing, phase,
                                                     SKPath1DPathEffectStyle.Rotate))
                {
                    // Set it to the Paint object and draw the path again
                    bucketsPaint.PathEffect = bucketsPathEffect;
                    canvas.DrawPath(conveyerPath, bucketsPaint);
                }
            }
        }
示例#14
0
        void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    if (skPathEffect != null)
                    {
                        skPathEffect.Dispose();
                        skPathEffect = null;
                    }
                }

                disposedValue = true;
            }
        }
示例#15
0
 public RoomData(string id)
 {
     RoomId    = id;
     ImageInfo = new SKImageInfo(800, 600);
     Image     = SKImage.Create(new SKImageInfo(800, 600));
     Surface   = SKSurface.Create(ImageInfo);
     Paint     = new SKPaint
     {
         IsAntialias = true,
         Color       = new SKColor(0, 0, 0, 255),
         StrokeWidth = 4,
         PathEffect  = SKPathEffect.CreateCorner(50),
         Style       = SKPaintStyle.Stroke
     };
     Path = new SKPath();
 }
示例#16
0
        public void Apply(SKPaint stroke)
        {
            var dashArray = DashArray;

            if (dashArray.Length > 0)
            {
                if (dashArray.Length % 2 != 0)
                {
                    var list = new float[dashArray.Length + 1];
                    System.Array.Copy(dashArray, 0, list, 0, dashArray.Length);
                    list[dashArray.Length] = dashArray[dashArray.Length - 1];
                    dashArray = list;
                }
                stroke.PathEffect = SKPathEffect.CreateDash(dashArray, DashPhase);
            }
        }
示例#17
0
        private PaintWrapper CreatePaint(Pen pen, Size targetSize)
        {
            var rv    = CreatePaint(pen.Brush, targetSize);
            var paint = rv.Paint;

            paint.IsStroke    = true;
            paint.StrokeWidth = (float)pen.Thickness;

            if (pen.StartLineCap == PenLineCap.Round)
            {
                paint.StrokeCap = SKStrokeCap.Round;
            }
            else if (pen.StartLineCap == PenLineCap.Square)
            {
                paint.StrokeCap = SKStrokeCap.Square;
            }
            else
            {
                paint.StrokeCap = SKStrokeCap.Butt;
            }

            if (pen.LineJoin == PenLineJoin.Miter)
            {
                paint.StrokeJoin = SKStrokeJoin.Miter;
            }
            else if (pen.LineJoin == PenLineJoin.Round)
            {
                paint.StrokeJoin = SKStrokeJoin.Round;
            }
            else
            {
                paint.StrokeJoin = SKStrokeJoin.Bevel;
            }

            paint.StrokeMiter = (float)pen.MiterLimit;

            if (pen.DashStyle?.Dashes != null && pen.DashStyle.Dashes.Count > 0)
            {
                var pe = SKPathEffect.CreateDash(
                    pen.DashStyle?.Dashes.Select(x => (float)x).ToArray(),
                    (float)pen.DashStyle.Offset);
                paint.PathEffect = pe;
                rv.AddDisposable(pe);
            }

            return(rv);
        }
示例#18
0
        private void OnPaint(UIElement element, SKCanvas canvas)
        {
            var p = new SKPaint
            {
                Style       = SKPaintStyle.Stroke,
                IsAntialias = true,
                PathEffect  = SKPathEffect.CreateDash(new[] { 10.0f, 10.0f }, 10),
                Color       = new SKColor(210, 170, 0, 100)
            };
            var pp = new SKPaint
            {
                Style       = SKPaintStyle.Fill,
                IsAntialias = true,
                Color       = new SKColor(50, 50, 50)
            };

            canvas.DrawRect(40, 40, Width - 80, Height - 80, p);
            canvas.DrawCircle(Width - 120, Y + 40, 36, p);
            canvas.DrawCircle(Width - 120, Y + 40, 36, pp);

            canvas.DrawText($"120", Width - 121, Y + 48,
                            new SKPaint
            {
                TextSize    = 25,
                IsAntialias = true,
                TextAlign   = SKTextAlign.Center,
                Color       = new SKColor(100, 100, 100)
            });

            //    canvas.DrawText($"Current screen: {GetType().Name} [FPS: {HipsterEngine.DeltaTime.GetFPS()}]", 20, 65,
            //        new SKPaint
            //         {
            //             TextSize = 20,
            //             IsAntialias = true,
            //            Color = new SKColor(100, 100, 100)
            //        });

            //    canvas.DrawText($"Life: {Enabled}", 20, 40, new SKPaint
            //    {
            //        TextSize = 20,
            //            IsAntialias = true,
            //        Color = new SKColor(100, 100, 100)
            //    });

            ButtonPlay.Draw(canvas);
        }
示例#19
0
        private void DrawHorizontalDashes()
        {
            SKCanvas      graphCavnas = this.graphSurface.Canvas;
            ArpansaUVData arpansaData = this.arpansaModel.ArpansaUVData;

            if (arpansaData?.ReferenceUVs == null)
            {
                //need reference UV levels
                return;
            }

            //for each refernce UV level
            for (int i = 0; i < arpansaData.ReferenceUVs.Count; i++)
            {
                float uvValue     = arpansaData.ReferenceUVs[i].LowerValue;
                float unitsHigh   = uvValue * this.unitsPerUVLevel;
                float RefLineYPos = unitsHigh;

                SKPaint refLinePaint = new SKPaint
                {
                    Color       = arpansaData.ReferenceUVs[i].Colour.WithAlpha(0.5f),
                    Style       = SKPaintStyle.Stroke,
                    StrokeWidth = 1f,
                    PathEffect  = SKPathEffect.CreateDash(new float[] { 6f, 3f }, 0),
                    IsAntialias = true
                };

                // draw line
                graphCavnas.DrawLine(0, RefLineYPos, this.gridWidth, RefLineYPos, refLinePaint);

                // write text above each reference point
                SKPaint refTextPaint = new SKPaint
                {
                    Color       = arpansaData.ReferenceUVs[i].Colour,
                    TextAlign   = SKTextAlign.Right,
                    IsAntialias = true,
                    TextSize    = 15f
                };

                float padding  = 10f;
                float textPosX = this.gridWidth - padding;
                float textPosY = RefLineYPos + padding;

                DrawTextOnGraph(arpansaData.ReferenceUVs[i].DetailText, textPosX, textPosY, refTextPaint);
            }
        }
示例#20
0
        private void CanvasView_OnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            var canvas = e.Surface.Canvas;

            canvas.Clear(BackgroundColor.ToSKColor());
            var w             = canvas.LocalClipBounds.Width;
            var h             = canvas.LocalClipBounds.Height;
            var joystickSize  = 60;
            var joystickColor = SKColors.DarkSlateBlue;

            if ((int)_canvasHeight == 0)
            {
                _canvasHeight = h;
                _canvasWidth  = w;
            }

            var strokeLineStyle = new SKPaint
            {
                Style       = SKPaintStyle.Stroke,
                Color       = SKColors.Purple,
                StrokeWidth = 1,
                PathEffect  = SKPathEffect.CreateDash(new float[] { 7, 7 }, 0)
            };

            canvas.DrawLine(w / 2, 0, w / 2, h, strokeLineStyle);
            canvas.DrawLine(0, h / 2, w, h / 2, strokeLineStyle);


            if (_idDictionary.Count == 0)
            {
                canvas.DrawCircle(w / 2, h / 2, joystickSize, new SKPaint {
                    Color = joystickColor, Style = SKPaintStyle.Fill
                });
            }

            foreach (var key in _idDictionary.Keys)
            {
                var info = _idDictionary[key];

                canvas.DrawCircle(w / 2, info.Location.Y, joystickSize, new SKPaint
                {
                    Color = joystickColor,
                    Style = SKPaintStyle.Fill,
                });
            }
        }
示例#21
0
        private void DrawGrid(SKCanvas canvas, double dx, double dy, double zx, double zy)
        {
            float gw = (float)_view.Width;
            float gh = (float)_view.Height;
            float cw = 15.0f;
            float ch = 15.0f;

            canvas.Save();
            canvas.Translate((float)dx, (float)dy);
            canvas.Scale((float)zx, (float)zy);

            var hlattice = SKMatrix.CreateScale(cw, ch);

            hlattice = hlattice.PreConcat(SKMatrix.CreateRotation((float)(Math.PI * 0.0 / 180.0)));

            var vlattice = SKMatrix.CreateScale(cw, ch);

            vlattice = vlattice.PreConcat(SKMatrix.CreateRotation((float)(Math.PI * 90.0 / 180.0)));

            using (var heffect = SKPathEffect.Create2DLine((float)(1.0 / zx), hlattice))
                using (var veffect = SKPathEffect.Create2DLine((float)(1.0 / zx), vlattice))
                    using (var hpaint = new SKPaint())
                        using (var vpaint = new SKPaint())
                        {
                            hpaint.IsAntialias = false;
                            hpaint.Color       = SKColors.LightGray;
                            hpaint.PathEffect  = heffect;
                            canvas.DrawRect(SKRect.Create(0.0f, ch, gw, gh - ch), hpaint);
                            vpaint.IsAntialias = false;
                            vpaint.Color       = SKColors.LightGray;
                            vpaint.PathEffect  = veffect;
                            canvas.DrawRect(SKRect.Create(cw, 0.0f, gw - cw, gh), vpaint);
                        }

            using (SKPaint strokePaint = new SKPaint())
            {
                strokePaint.IsAntialias = false;
                strokePaint.StrokeWidth = (float)(1.0 / zx);
                strokePaint.Color       = SKColors.Red;
                strokePaint.Style       = SKPaintStyle.Stroke;
                canvas.DrawRect(SKRect.Create(0.0f, 0.0f, gw, gh), strokePaint);
            }

            canvas.Restore();
        }
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            // Create an SKPaint object to display the text
            using (SKPaint textPaint = new SKPaint
            {
                Style = SKPaintStyle.Stroke,
                StrokeWidth = strokeWidth,
                StrokeCap = SKStrokeCap.Round,
                Color = SKColors.Blue,
            })
            {
                // Adjust TextSize property so text is 95% of screen width
                float textWidth = textPaint.MeasureText(text);
                textPaint.TextSize *= 0.95f * info.Width / textWidth;

                // Find the text bounds
                SKRect textBounds;
                textPaint.MeasureText(text, ref textBounds);

                // Calculate offsets to center the text on the screen
                float xText = info.Width / 2 - textBounds.MidX;
                float yText = info.Height / 2 - textBounds.MidY;

                // Animate the phase; t is 0 to 1 every second
                TimeSpan timeSpan = new TimeSpan(DateTime.Now.Ticks);
                float    t        = (float)(timeSpan.TotalSeconds % 1 / 1);
                float    phase    = -t * 2 * strokeWidth;

                // Create dotted line effect based on dash array and phase
                using (SKPathEffect dashEffect = SKPathEffect.CreateDash(dashArray, phase))
                {
                    // Set it to the paint object
                    textPaint.PathEffect = dashEffect;

                    // And draw the text
                    canvas.DrawText(text, xText, yText, textPaint);
                }
            }
        }
示例#23
0
    internal static SKPaint SKPaint(this Pen pen)
    {
        var paint = new SKPaint
        {
            Color         = pen.Color.SKColor(),
            StrokeWidth   = pen.Width,
            IsAntialias   = true,
            Style         = SKPaintStyle.Stroke,
            BlendMode     = SKBlendMode.SrcOver,
            FilterQuality = SKFilterQuality.High
        };

        if (pen.DashStyle != DashStyle.Solid)
        {
            paint.PathEffect = SKPathEffect.CreateDash(pen.DashPattern, 0);
        }
        return(paint);
    }
示例#24
0
        public void Draw(SKCanvasView skCanvasView, SKCanvas skCanvas)
        {
            skCanvas.Clear();

            if (_highlightState == null)
            {
                return;
            }
            if (_skPaint == null)
            {
                _skPaint = CreateHighlightSkPaint(skCanvasView, _highlightSettings, _highlightState.HighlightPath);
            }
            var strokeDash = _highlightState.StrokeDash;

            // Comment the next line to see whole path without dash effect
            _skPaint.PathEffect = SKPathEffect.CreateDash(strokeDash.Intervals, strokeDash.Phase);
            skCanvas.DrawPath(_highlightState.HighlightPath.Path, _skPaint);
        }
        private void SKCanvasView_PaintSurface(object sender, SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs e)
        {
            SKImageInfo info    = e.Info;
            SKSurface   surface = e.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            canvas.DrawRoundRect(0, 0, info.Width, info.Height - 5, 15, 15, new SKPaint()
            {
                Style       = SKPaintStyle.Stroke,
                StrokeWidth = 3,
                StrokeCap   = SKStrokeCap.Round,
                StrokeJoin  = SKStrokeJoin.Round,
                Color       = AppThemeConstants.LightPurpleColor.ToSKColor(),
                PathEffect  = SKPathEffect.CreateDash(new float[] { 4, 4 }, 3f),
            });
        }
        private void DueByThisWeekCanvasView_PaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            SKImageInfo info    = e.Info;
            SKSurface   surface = e.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            canvas.DrawRoundRect(0, 0, info.Width, info.Height, 20, 20, new SKPaint()
            {
                Style       = SKPaintStyle.Stroke,
                StrokeWidth = 4,
                StrokeCap   = SKStrokeCap.Round,
                StrokeJoin  = SKStrokeJoin.Round,
                Color       = AppThemeConstants.LightPurpleColor.ToSKColor(),
                PathEffect  = SKPathEffect.CreateDash(new float[] { 8, 8 }, 5f),
            });
        }
示例#27
0
        public void UpdateStrokeDash()
        {
            if (_strokeDash != null && _strokeDash.Length > 1)
            {
                float[] strokeDash = new float[_strokeDash.Length];

                for (int i = 0; i < _strokeDash.Length; i++)
                {
                    strokeDash[i] = _strokeDash[i] * _strokeWidth;
                }
                _skPaint.PathEffect = SKPathEffect.CreateDash(strokeDash, _strokeDashOffset * _strokeWidth);
            }
            else
            {
                _skPaint.PathEffect = null;
            }
            UpdatePathStrokeBounds();
        }
        public bool ChartAxisEvent(Object o)
        {
            var     args = o as ChartAxisEventArgs;
            var     canvas = args.Canvas;
            SKPoint p1, p2;

            if (args.Orientation == ChartAxis.AxisOrientation.Horizontal)
            {
                (p1, p2) = ParentPadding.GetVerticalLine((float)args.Position);
            }
            else
            {
                (p1, p2) = ParentPadding.GetHorozontalLine((float)args.Position);
            }

            switch (args.EventType)
            {
            case ChartAxisEventArgs.ChartAxisEventType.DrawMajorTick:
                if (EnableMajorLines)
                {
                    MajorPaint.ColorFilter = SKColorFilter.CreateBlendMode(args.Color, SKBlendMode.Dst);
                    MajorPaint.Color       = args.Color;
                    MajorPaint.PathEffect  = SKPathEffect.CreateDash(new[] { 1f, 1f }, 0);
                    DrawGridLine(canvas, new Gridline(p1, p2, MajorPaint));
                }
                break;

            case ChartAxisEventArgs.ChartAxisEventType.DrawMinorTick:
                if (EnableMinorLines)
                {
                    MinorPaint.ColorFilter = SKColorFilter.CreateBlendMode(args.Color, SKBlendMode.DstOver);
                    MinorPaint.Color       = args.Color;
                    MinorPaint.PathEffect  = SKPathEffect.CreateDash(new[] { 1f, 1f }, 0);
                    DrawGridLine(canvas, new Gridline(p1, p2, MinorPaint));
                }
                break;

            default:
                break;
            }

            //There may be multiple grids?
            return(false);
        }
示例#29
0
        public Benchmarks()
        {
            skSurface = SKSurface.Create(width: 1024, height: 1024, colorType: SKImageInfo.PlatformColorType, alphaType: SKAlphaType.Premul);
            skCanvas  = skSurface.Canvas;
            skCanvas.ClipRect(new SKRect(0, 0, 1024, 1024));

            skPaintSolidThick             = new SKPaint();
            skPaintSolidThick.StrokeWidth = STROKE_WIDTH;
            skPaintSolidThick.IsAntialias = AntiAlias;
            skPaintSolidThick.Style       = SKPaintStyle.Fill;

            skPaintSolidThin             = new SKPaint();
            skPaintSolidThin.StrokeWidth = 1;
            skPaintSolidThin.IsAntialias = AntiAlias;

            SKPathEffect dashEffect = SKPathEffect.CreateDash(new float[] { 2F, 6F }, 1F);

            skPaintDashedThick             = new SKPaint();
            skPaintDashedThick.StrokeWidth = STROKE_WIDTH;
            skPaintDashedThick.IsAntialias = AntiAlias;
            skPaintDashedThick.PathEffect  = dashEffect;

            skPaintDashedThin             = new SKPaint();
            skPaintDashedThin.StrokeWidth = 1;
            skPaintDashedThin.IsAntialias = AntiAlias;
            skPaintDashedThin.PathEffect  = dashEffect;


            Bitmap bmp = new Bitmap(1024, 1024);

            gdiGraphics                  = Graphics.FromImage(bmp);
            gdiPenThick                  = new Pen(Color.Red, STROKE_WIDTH);
            gdiPenThin                   = new Pen(Color.Red, 1F);
            gdiPenDashedThin             = new Pen(Color.Red, 1F);
            gdiPenDashedThin.DashPattern = new float[] { 2F, 6F };
            gdiPenDashedThin.DashStyle   = System.Drawing.Drawing2D.DashStyle.Custom;

            gdiPenDashedThick             = new Pen(Color.Red, STROKE_WIDTH);
            gdiPenDashedThick.DashPattern = new float[] { 2F, 6F };
            gdiPenDashedThick.DashStyle   = System.Drawing.Drawing2D.DashStyle.Custom;

            lineSegments    = new LineSegment[1];
            lineSegments[0] = new LineSegment(-10F, -10F, 1200F, 1200F);
        }
示例#30
0
        public void TrimPathEffectWorks()
        {
            using (var bitmap = new SKBitmap(new SKImageInfo(100, 100)))
                using (var canvas = new SKCanvas(bitmap))
                    using (var path = new SKPath())
                    {
                        path.MoveTo(0, 50);
                        path.LineTo(new SKPoint(100, 50));
                        canvas.Clear(SKColors.White);

                        // draw the base path
                        using (var paint = new SKPaint())
                        {
                            paint.Style       = SKPaintStyle.Stroke;
                            paint.StrokeWidth = 20;
                            paint.Color       = SKColors.Black;

                            canvas.DrawPath(path, paint);
                        }

                        // should be black
                        Assert.Equal(SKColors.Black, bitmap.GetPixel(10, 50));
                        Assert.Equal(SKColors.Black, bitmap.GetPixel(50, 50));
                        Assert.Equal(SKColors.Black, bitmap.GetPixel(90, 50));

                        // draw the path with an effect
                        using (var paint = new SKPaint())
                        {
                            paint.Style       = SKPaintStyle.Stroke;
                            paint.StrokeWidth = 20;
                            paint.Color       = SKColors.Red;

                            // attach the effect
                            paint.PathEffect = SKPathEffect.CreateTrim(0.3f, 0.7f);

                            canvas.DrawPath(path, paint);
                        }

                        // should be red
                        Assert.Equal(SKColors.Black, bitmap.GetPixel(10, 50));
                        Assert.Equal(SKColors.Red, bitmap.GetPixel(50, 50));
                        Assert.Equal(SKColors.Black, bitmap.GetPixel(90, 50));
                    }
        }