Exemplo n.º 1
0
 /// <summary>
 /// Attempts to get an optional feature from the drawing context implementation
 /// </summary>
 public static T?GetFeature <T>(this IDrawingContextImpl context) where T : class =>
 (T?)context.GetFeature(typeof(T));
Exemplo n.º 2
0
            public void Render(IDrawingContextImpl context)
            {
                var leaseFeature = context.GetFeature <ISkiaSharpApiLeaseFeature>();

                if (leaseFeature == null)
                {
                    using (var c = new DrawingContext(context, false))
                    {
                        c.DrawText(_noSkia, new Point());
                    }
                }
                else
                {
                    using var lease = leaseFeature.Lease();
                    var canvas = lease.SkCanvas;
                    canvas.Save();
                    // create the first shader
                    var colors = new SKColor[] {
                        new SKColor(0, 255, 255),
                        new SKColor(255, 0, 255),
                        new SKColor(255, 255, 0),
                        new SKColor(0, 255, 255)
                    };

                    var sx            = Animate(100, 2, 10);
                    var sy            = Animate(1000, 5, 15);
                    var lightPosition = new SKPoint(
                        (float)(Bounds.Width / 2 + Math.Cos(St.Elapsed.TotalSeconds) * Bounds.Width / 4),
                        (float)(Bounds.Height / 2 + Math.Sin(St.Elapsed.TotalSeconds) * Bounds.Height / 4));
                    using (var sweep =
                               SKShader.CreateSweepGradient(new SKPoint((int)Bounds.Width / 2, (int)Bounds.Height / 2), colors,
                                                            null))
                        using (var turbulence = SKShader.CreatePerlinNoiseFractalNoise(0.05f, 0.05f, 4, 0))
                            using (var shader = SKShader.CreateCompose(sweep, turbulence, SKBlendMode.SrcATop))
                                using (var blur = SKImageFilter.CreateBlur(Animate(100, 2, 10), Animate(100, 5, 15)))
                                    using (var paint = new SKPaint
                                    {
                                        Shader = shader,
                                        ImageFilter = blur
                                    })
                                        canvas.DrawPaint(paint);

                    using (var pseudoLight = SKShader.CreateRadialGradient(
                               lightPosition,
                               (float)(Bounds.Width / 3),
                               new [] {
                        new SKColor(255, 200, 200, 100),
                        SKColors.Transparent,
                        new SKColor(40, 40, 40, 220),
                        new SKColor(20, 20, 20, (byte)Animate(100, 200, 220))
                    },
                               new float[] { 0.3f, 0.3f, 0.8f, 1 },
                               SKShaderTileMode.Clamp))
                        using (var paint = new SKPaint
                        {
                            Shader = pseudoLight
                        })
                            canvas.DrawPaint(paint);
                    canvas.Restore();
                }
            }