Exemplo n.º 1
0
        protected void RenderFps(IDrawingContextImpl context, Rect clientRect, int?layerCount)
        {
            var now     = _stopwatch.Elapsed;
            var elapsed = now - _lastFpsUpdate;

            ++_framesThisSecond;

            if (elapsed.TotalSeconds > 1)
            {
                _fps = (int)(_framesThisSecond / elapsed.TotalSeconds);
                _framesThisSecond = 0;
                _lastFpsUpdate    = now;
            }

            if (layerCount.HasValue)
            {
                _fpsText.Text = string.Format("Layers: {0} FPS: {1:000}", layerCount, _fps);
            }
            else
            {
                _fpsText.Text = string.Format("FPS: {0:000}", _fps);
            }

            var size = _fpsText.Bounds.Size;
            var rect = new Rect(clientRect.Right - size.Width, 0, size.Width, size.Height);

            context.Transform = Matrix.Identity;
            context.DrawRectangle(Brushes.Black, null, rect);
            context.DrawText(Brushes.White, rect.TopLeft, _fpsText.PlatformImpl);
        }
Exemplo n.º 2
0
        protected void RenderFps(IDrawingContextImpl context, Rect clientRect, bool incrementFrameCount)
        {
            var now     = _stopwatch.Elapsed;
            var elapsed = now - _lastFpsUpdate;

            if (incrementFrameCount)
            {
                ++_framesThisSecond;
            }

            if (elapsed.TotalSeconds > 1)
            {
                _fps = (int)(_framesThisSecond / elapsed.TotalSeconds);
                _framesThisSecond = 0;
                _lastFpsUpdate    = now;
            }

            _fpsText.Text = string.Format("FPS: {0:000}", _fps);
            var size = _fpsText.Measure();
            var rect = new Rect(clientRect.Right - size.Width, 0, size.Width, size.Height);

            context.Transform = Matrix.Identity;
            context.FillRectangle(Brushes.Black, rect);
            context.DrawText(Brushes.White, rect.TopLeft, _fpsText.PlatformImpl);
        }
Exemplo n.º 3
0
            public void Render(IDrawingContextImpl context)
            {
                var canvas = (context as ISkiaDrawingContextImpl)?.SkCanvas;

                if (canvas == null)
                {
                    context.DrawText(Brushes.Black, new Point(), _noSkia.PlatformImpl);
                }
                else
                {
                    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();
                }
            }
Exemplo n.º 4
0
        public override void Render(IDrawingContextImpl context)
        {
            var canvas  = (context as ISkiaDrawingContextImpl)?.SkCanvas;
            var surface = (context as ISkiaDrawingContextImpl)?.SkSurface;

            if (canvas == null | surface == null)
            {
                context.Clear(Colors.White);
                context.DrawText(new SolidColorBrush(Colors.Black), new Point(), NoSkia);
            }
            else
            {
                Surface = surface;
                var width  = (int)Bounds.Width;
                var height = (int)Bounds.Height;

                var info = new SKImageInfo(width, height);

                using (SKPaint paint = new SKPaint())
                {
                    SKColor[] colors = { SKColors.White, HueColor.ToSKColor() };

                    SKPoint center = new SKPoint(info.Rect.MidX, info.Rect.MidY);

                    paint.Shader = SKShader.CreateLinearGradient(new SKPoint(0, 0), new SKPoint(width, 0), colors, SKShaderTileMode.Repeat);

                    var rect = SKRect.Create(width, height);
                    canvas.DrawRect(rect, paint);
                }

                // Creates the black gradient effect (transparent to black)
                using (SKPaint paint = new SKPaint())
                {
                    SKColor[] colors = { SKColors.Transparent, SKColors.Black };

                    paint.Shader = SKShader.CreateLinearGradient(new SKPoint(0, 0), new SKPoint(0, height), colors, SKShaderTileMode.Repeat);

                    var rect = SKRect.Create(width, height);

                    canvas.DrawRect(rect, paint);
                }

                using (SKPaint paint = new SKPaint())
                {
                    paint.Shader = SKShader.CreateColor(StrokeColor.ToSKColor());
                    var rect = SKRect.Create(width, height);
                    paint.Style       = SKPaintStyle.Stroke;
                    paint.StrokeWidth = StrokeWidth;
                    canvas.DrawRect(rect, paint);
                }
            }
        }
        public void Render(IDrawingContextImpl context)
        {
            var canvas = (context as ISkiaDrawingContextImpl)?.SkCanvas;

            if (canvas == null)
            {
                context.DrawText(Brushes.Black, new Point(), NoEngine.PlatformImpl);
            }
            else
            {
                canvas.Save();
                canvas.DrawOval(500, 500, 100, 200, _debugPaint);
                canvas.Restore();
            }
        }
Exemplo n.º 6
0
        public override void Render(IDrawingContextImpl context)
        {
            // converts the impl to SKCanvas
            var canvas = (context as ISkiaDrawingContextImpl)?.SkCanvas;

            //Checks if that is valid
            if (canvas == null)
            {
                context.Clear(Colors.White);
                context.DrawText(new SolidColorBrush(Colors.Black), new Point(), NoSkia);
            }
            else // when it's valid to this
            {
                var info = new SKImageInfo((int)Bounds.Width, (int)Bounds.Height); // creates the image info

                using (SKPaint paint = new SKPaint()) // creates the paint
                {
                    // Define an array of rainbow colors
                    SKColor[] colors = new SKColor[8];

                    for (int i = 0; i < colors.Length; i++)
                    {
                        colors[i] = SKColor.FromHsl(i * 360f / 7, 100, 50); //sets the colors
                    }

                    SKPoint center = new SKPoint(info.Rect.MidX, info.Rect.MidY); // creates the center

                    // Create sweep gradient based on center of canvas
                    paint.Shader = SKShader.CreateSweepGradient(center, colors, null);

                    // Draw a circle with a wide line
                    paint.Style       = SKPaintStyle.Stroke;
                    paint.StrokeWidth = StrokeWidth;

                    float radius = (Math.Min(info.Width, info.Height) - StrokeWidth) / 2; //computes the radius
                    canvas.DrawCircle(center, radius, paint);                             // draw a circle with its respects parameters
                }
            }
        }
Exemplo n.º 7
0
 /// <inheritdoc/>
 public override void Render(IDrawingContextImpl context)
 {
     context.Transform = Transform;
     context.DrawText(Foreground, Origin, Text);
 }
Exemplo n.º 8
0
        public void Render(IDrawingContextImpl context)
        {
            if (rendered > 20)
            {
                return;
            }

            var canvas = (context as ISkiaDrawingContextImpl)?.SkCanvas;

            if (canvas == null)
            {
                context.DrawText(Brushes.Black, new Avalonia.Point(), _noSkia.PlatformImpl);
                return;
            }

            if (project == null)
            {
                return;
            }

            canvas.Save();

            if (background.Alpha != 0)
            {
                canvas.DrawRect(new SKRect(0, 0, (float)Bounds.Width, (float)Bounds.Height), new SKPaint()
                {
                    Color = background
                });
            }

            if (!above)
            {
                DrawImage(canvas);
            }
            for (int i = 0; i < project.Count; i++)
            {
                DrawDomino(canvas, project[i]);
            }
            DrawAdditionals(canvas, true);
            for (int i = 0; i < project.Count; i++)
            {
                DrawDominoBorder(canvas, project[i]);
            }
            if (above)
            {
                DrawImage(canvas);
            }

            if (selectionVisible && selectionPath != null)
            {
                canvas.DrawPath(selectionPath, new SKPaint()
                {
                    Color = new SKColor(0, 0, 0, 255), IsStroke = true, StrokeWidth = 4, IsAntialias = true
                });
                canvas.DrawPath(selectionPath, new SKPaint()
                {
                    Color = selectionColor, IsStroke = true, StrokeWidth = 2, IsAntialias = true
                });
            }
            DrawAdditionals(canvas, false);



            canvas.Restore();
            rendered += 1;
        }
Exemplo n.º 9
0
 /// <summary>
 /// Draws text.
 /// </summary>
 /// <param name="foreground">The foreground brush.</param>
 /// <param name="origin">The upper-left corner of the text.</param>
 /// <param name="text">The text.</param>
 public void DrawText(Brush foreground, Point origin, FormattedText text)
 => _impl.DrawText(foreground, origin, text);
Exemplo n.º 10
0
        public override void Render(IDrawingContextImpl context)
        {
            var canvas = ((ISkiaDrawingContextImpl)context)?.SkCanvas;

            if (canvas == null)
            {
                context.Clear(Colors.White);
                context.DrawText(new SolidColorBrush(Colors.Black), new Point(), NoSkia);
            }
            else
            {
                int width  = (int)Bounds.Width;
                int height = (int)Bounds.Height;

                var info = new SKImageInfo(width, height);

                //canvas.Scale((float)Bounds.Width, (float)Bounds.Height, -(float)Bounds.Width, -(float)Bounds.Height);
                canvas.RotateDegrees(-90f, (float)Bounds.Center.X, (float)Bounds.Center.Y);

                using (SKPaint paint = new SKPaint())
                {
                    SKColor[] colors = new SKColor[8];

                    for (int i = 0; i < colors.Length; i++)
                    {
                        colors[i] = SKColor.FromHsl(i * 360f / 7, 100, 50); //sets the colors
                    }

                    SKPoint center = new SKPoint(info.Rect.MidX, info.Rect.MidY); // creates the center

                    // Create sweep gradient based on center of canvas
                    paint.Shader = SKShader.CreateSweepGradient(center, colors, null);


                    float radius = (Math.Min(info.Width, info.Height) - StrokeWidth) / 2; //computes the radius
                    canvas.DrawCircle(center, radius, paint);                             // draw a circle with its respects parameters
                }

                // Creates the black gradient effect (transparent to black)
                using (SKPaint paint = new SKPaint())
                {
                    SKColor[] colors = { SKColors.White, SKColors.Transparent };

                    SKPoint center = new SKPoint(info.Rect.MidX, info.Rect.MidY); // creates the center

                    int   strokeWidth = 20;
                    float radius      = (Math.Min(info.Width, info.Height) - strokeWidth) / 2; //computes the radius

                    paint.Shader = SKShader.CreateRadialGradient(center, radius, colors, null, SKShaderTileMode.Repeat);

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

                using (SKPaint paint = new SKPaint())
                {
                    var colorStroke = Stroke.ToSKColor();

                    SKPoint center = new SKPoint(info.Rect.MidX, info.Rect.MidY);           // creates the center
                    float   radius = (Math.Min(info.Width, info.Height) - StrokeWidth) / 2; //computes the radius

                    paint.Shader = SKShader.CreateColor(colorStroke);

                    paint.Style       = SKPaintStyle.Stroke;
                    paint.StrokeWidth = StrokeWidth;

                    canvas.DrawCircle(center, radius, paint);
                }
            }
        }
Exemplo n.º 11
0
            public void Render(IDrawingContextImpl context)
            {
                bool isLightTheme = Application.Current.Styles[1] == App.FluentLight;

                var canvas = (context as ISkiaDrawingContextImpl)?.SkCanvas;

                if (canvas == null)
                {
                    context.DrawText(Brushes.Black, new Point(), _noSkia.PlatformImpl);
                }
                else
                {
                    canvas.Save();

                    SKPaint solidForeground = new SKPaint
                    {
                        Color    = isLightTheme ? new SKColor(0, 0, 0) : new SKColor(255, 255, 255),
                        TextSize = 12.0f
                    };

                    SKPaint strokeBlue = new SKPaint
                    {
                        Color       = new SKColor(0, 0, 255),
                        Style       = SKPaintStyle.Stroke,
                        StrokeWidth = 2.0f
                    };

                    SKPaint solidBlue = new SKPaint
                    {
                        Color = new SKColor(0, 0, 255)
                    };

                    float canvasWidth  = canvas.LocalClipBounds.Width;
                    float canvasHeight = canvas.LocalClipBounds.Height;

                    /*canvas.DrawLine(0,
                     *              canvasHeight / 2.0f,
                     *              canvasWidth,
                     *              canvasHeight / 2.0f,
                     *              solidBlack);*/

                    canvas.DrawLine(5,
                                    0,
                                    5,
                                    canvasHeight,
                                    solidForeground);

                    var          stringData    = _viewModel.ReceivedMessages.Split('\n');
                    List <float> numericalData = new List <float>();

                    foreach (string item in stringData)
                    {
                        float numericData;
                        if (float.TryParse(item, out numericData))
                        {
                            numericalData.Add(numericData);
                        }
                    }

                    float maxValue, minValue;
                    try
                    {
                        maxValue = numericalData.Max();
                        minValue = numericalData.Min();
                    }
                    catch (InvalidOperationException e)
                    {
                        Debug.WriteLine(e.Message);
                        return;
                    }


                    float range  = Math.Abs(maxValue - minValue);
                    float offset = range * 0.05f;
                    //float upperBound = maxValue + offset;
                    float lowerBound = minValue - offset;
                    float plotRange  = range + offset * 2;

                    //Prevent errors by zero division.
                    if (plotRange == 0)
                    {
                        plotRange = 0.1f;
                    }

                    canvas.DrawLine(2.5f, canvasHeight - (maxValue - lowerBound) / plotRange * canvasHeight, 7.5f, canvasHeight - (maxValue - lowerBound) / plotRange * canvasHeight, solidForeground);
                    canvas.DrawLine(2.5f, canvasHeight - (minValue - lowerBound) / plotRange * canvasHeight, 7.5f, canvasHeight - (minValue - lowerBound) / plotRange * canvasHeight, solidForeground);

                    canvas.DrawText(maxValue.ToString(), 7.5f, canvasHeight - (maxValue - lowerBound) / plotRange * canvasHeight + 6.0f, solidForeground);
                    canvas.DrawText(minValue.ToString(), 7.5f, canvasHeight - (minValue - lowerBound) / plotRange * canvasHeight + 6.0f, solidForeground);

                    int   dataPoints    = numericalData.Count;
                    float pointDistance = (canvasWidth - 5.0f) / (dataPoints - 1);

                    if (dataPoints > 1)
                    {
                        SKPath plotLine = new SKPath();
                        plotLine.MoveTo(5.0f, canvasHeight - (numericalData[0] - lowerBound) / plotRange * canvasHeight);
                        for (int i = 1; i < dataPoints; i++)
                        {
                            plotLine.LineTo(i * pointDistance + 5.0f, canvasHeight - (numericalData[i] - lowerBound) / plotRange * canvasHeight);
                        }
                        canvas.DrawPath(plotLine, strokeBlue);
                    }
                    else if (dataPoints == 1)
                    {
                        canvas.DrawCircle(5.0f, canvasHeight - (numericalData[0] - lowerBound) / plotRange * canvasHeight, 5.0f, solidBlue);
                    }

                    canvas.Restore();
                }
            }