Ejemplo n.º 1
0
        void OnCanvasViewPaintSurface(object sender, SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs args)
        {
            SkiaSharp.SKImageInfo info    = args.Info;
            SkiaSharp.SKSurface   surface = args.Surface;
            SkiaSharp.SKCanvas    canvas  = surface.Canvas;
            canvas.Clear();
            SkiaSharp.SKRect bounds;
            SkiaSharp.SKPath path = SkiaSharp.SKPath.ParseSvgPathData((string)this.Resources["PathString"]);
            path.GetTightBounds(out bounds);
            SkiaSharp.SKPaint paint = new SkiaSharp.SKPaint
            {
                Style       = SkiaSharp.SKPaintStyle.Stroke,
                Color       = SkiaSharp.SKColors.Black,
                StrokeWidth = 10,
                StrokeCap   = SkiaSharp.SKStrokeCap.Round,
                StrokeJoin  = SkiaSharp.SKStrokeJoin.Round
            };
            canvas.Translate(info.Width / 2, info.Height / 2);

            canvas.Scale(info.Width / (bounds.Width + paint.StrokeWidth),
                         info.Height / (bounds.Height + paint.StrokeWidth));

            canvas.Translate(-bounds.MidX, -bounds.MidY);

            canvas.DrawPath(path, paint);
        }
Ejemplo n.º 2
0
        private void DrawPasteOverlay(Avalonia.Point dominoPoint, PointerEventArgs e)
        {
            // display the dominoes to paste as a half-transparent overlay.
            // reference point:
            var reference_point = Dominoes[toCopy.Min()].CenterPoint - dominoPoint;

            if (PasteOverlays.Count == 0)
            {
                // create the overlays
                foreach (int i in toCopy)
                {
                    var p      = new SkiaSharp.SKPath();
                    var points = Dominoes[i].CanvasPoints;
                    if (points.Length > 1)
                    {
                        p.MoveTo(new SkiaSharp.SKPoint((float)points[0].X - (float)reference_point.X, (float)points[0].Y - (float)reference_point.Y));
                        foreach (var point in points.Skip(1))
                        {
                            p.LineTo(new SkiaSharp.SKPoint((float)point.X - (float)reference_point.X, (float)point.Y - (float)reference_point.Y));
                        }
                    }
                    var color = Dominoes[i].StoneColor.ToSKColor().WithAlpha(128);
                    PasteOverlays.Add(new CanvasDrawable()
                    {
                        BeforeBorders = false, Paint = new SkiaSharp.SKPaint()
                        {
                            Color = color
                        }, Path = p
                    });
                }
                AdditionalDrawables.AddRange(PasteOverlays);
            }
            else
            {
                // find out difference between current and last reference point
                var shift     = lastreference - reference_point;
                var transform = SkiaSharp.SKMatrix.CreateTranslation((float)shift.X, (float)shift.Y);
                System.Diagnostics.Debug.WriteLine(shift);
                foreach (var stone in PasteOverlays)
                {
                    stone.Path.Transform(transform);
                }
            }
            lastreference = reference_point;
            Redraw();
        }
Ejemplo n.º 3
0
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
        {
            try
            {
                var   w  = e.Info.Width;
                var   h  = e.Info.Height;
                float cx = w / 2.0f;
                float cy = h / 2.0f;

                float Radius = Math.Min(cx, cy);

                Paint.Typeface = Font;

                float currentRate = 0;
                foreach (var item in Members)
                {
                    paint.IsAntialias = true;
                    {
                        var path = new SkiaSharp.SKPath();
                        if (item.Rate % 1 == 0f && item.Rate > 0.5f)
                        {
                            path.AddCircle(cx, cy, Radius * OuterRate);
                        }
                        else
                        {
                            path.ArcTo(new SkiaSharp.SKRect(cx - Radius * OuterRate, cy - Radius * OuterRate, cx + Radius * OuterRate, cy + Radius * OuterRate), 360 * (currentRate - 0.25f), 360 * item.Rate, false);
                            path.LineTo(cx, cy);
                            //path.LineTo(cx + Radius * (float)Math.Sin(Math.PI * 2 * currentRate) * OuterRate, cy - Radius * (float)Math.Cos(Math.PI * 2 * currentRate) * OuterRate);
                            path.Close();
                        }
                        Paint.Color    = item.Color;
                        Paint.IsStroke = false;
                        e.Surface.Canvas.DrawPath(path, Paint);
                    }
                    {
                        var path = new SkiaSharp.SKPath();
                        path.MoveTo(cx + Radius * (float)Math.Sin(Math.PI * 2 * currentRate) * OuterRate, cy - Radius * (float)Math.Cos(Math.PI * 2 * currentRate) * OuterRate);
                        path.LineTo(cx, cy);
                        Paint.Color       = new SkiaSharp.SKColor(255, 255, 255, 0);
                        Paint.StrokeWidth = Radius * 0.02f;
                        Paint.IsStroke    = true;
                        Paint.BlendMode   = SkiaSharp.SKBlendMode.Clear;
                        e.Surface.Canvas.DrawPath(path, Paint);
                        Paint.BlendMode = SkiaSharp.SKBlendMode.SrcOver;
                    }

                    currentRate += item.Rate;
                }
                {
                    Paint.Color     = new SkiaSharp.SKColor(255, 255, 255);
                    Paint.IsStroke  = false;
                    Paint.BlendMode = SkiaSharp.SKBlendMode.Clear;
                    e.Surface.Canvas.DrawCircle(cx, cy, Radius * InnerRate, Paint);
                    Paint.BlendMode = SkiaSharp.SKBlendMode.SrcOver;
                }
                {
                    var path = new SkiaSharp.SKPath();
                    path.MoveTo(cx + Radius * (float)Math.Sin(Math.PI * 2 * currentRate) * OuterRate, cy - Radius * (float)Math.Cos(Math.PI * 2 * currentRate) * OuterRate);
                    path.LineTo(cx, cy);
                    Paint.Color       = new SkiaSharp.SKColor(255, 255, 255, 0);
                    Paint.StrokeWidth = Radius * 0.02f;
                    Paint.IsStroke    = true;
                    Paint.BlendMode   = SkiaSharp.SKBlendMode.Clear;
                    e.Surface.Canvas.DrawPath(path, Paint);
                    Paint.BlendMode = SkiaSharp.SKBlendMode.SrcOver;
                }
                {
                    Paint.TextSize  = TitleFontSize * Radius;
                    Paint.Color     = new SkiaSharp.SKColor(0, 0, 0);
                    Paint.IsStroke  = false;
                    Paint.TextAlign = SkiaSharp.SKTextAlign.Center;
                    e.Surface.Canvas.DrawText(Title, cx, cy + Paint.FontMetrics.AverageCharacterWidth / 2.0f, Paint);
                }
            }
            catch { }
            base.OnPaintSurface(e);
        }