Beispiel #1
0
        /// <summary>
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="i"></param>
        /// <param name="p0"></param>
        /// <param name="p1"></param>
        private void DrawLine(SKCanvas canvas, int width, int height, int i, GraphIndex p0, GraphIndex p1)
        {
            using (var paint = new SKPaint())
            {
                paint.Color       = SKColors.DarkBlue;
                paint.Style       = SKPaintStyle.Stroke;
                paint.StrokeWidth = 4 * _scale;
                paint.IsAntialias = true;
                paint.StrokeCap   = SKStrokeCap.Round;

                var x0 = _paddingW + _availableW * (i - 1) / (_sizeX - 1);
                var y0 = height - (_paddingH * 2f + 0.8f * _availableH * (p0.Y - _minY) / _sizeY);
                var x1 = _paddingW + _availableW * i / (_sizeX - 1);
                var y1 = height - (_paddingH * 2f + 0.8f * _availableH * (p1.Y - _minY) / _sizeY);

                var colors = new[]
                {
                    CalcColor(p0.Y),
                    CalcColor(p1.Y)
                };

                var shader = SKShader.CreateLinearGradient(new SKPoint(x0, y0), new SKPoint(x1, y1), colors, null, SKShaderTileMode.Clamp);

                paint.Shader = shader;
                canvas.DrawLine(x0, y0, x1, y1, paint);
            }
        }
Beispiel #2
0
        /// <summary>
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="p"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="scale"></param>
        private static void DrawYVal(SKCanvas canvas, GraphIndex p, float x, float y, float scale)
        {
            using (var paint = new SKPaint())
            {
                if (p.Hide)
                {
                    return;
                }

                paint.Color       = SKColors.White;
                paint.TextSize    = 18 * scale;
                paint.Style       = SKPaintStyle.Stroke;
                paint.StrokeWidth = 5 * scale;
                paint.IsAntialias = true;

                using (var paint2 = new SKPaint())
                {
                    paint2.Style        = SKPaintStyle.Fill;
                    paint2.Color        = CalcColor(p.Y);
                    paint2.TextSize     = 18 * scale;
                    paint2.FakeBoldText = true;
                    paint2.IsAntialias  = true;

                    SKRect textBounds;

                    var yLabel = XameteoApp.Instance.Temperature.Convert(p.Y);

                    paint.MeasureText(yLabel, ref textBounds);
                    canvas.DrawText(yLabel, x - textBounds.MidX, y + 2 * textBounds.Top, paint);
                    canvas.DrawText(yLabel, x - textBounds.MidX, y + 2 * textBounds.Top, paint2);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="p"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="scale"></param>
        private void DrawLabel(SKCanvas canvas, GraphIndex p, float x, float y, float scale)
        {
            using (var paint = new SKPaint())
            {
                if (p.Hide)
                {
                    return;
                }

                SKRect textBounds;

                paint.Color       = new SKColor(27, 30, 35);
                paint.StrokeWidth = 1 * scale;
                paint.IsAntialias = true;
                paint.TextSize    = 15 * scale;
                paint.Style       = SKPaintStyle.StrokeAndFill;
                paint.MeasureText(p.Label, ref textBounds);
                canvas.DrawText(p.Label, x - textBounds.MidX, _availableH - textBounds.Top + _paddingH, paint);
            }
        }
Beispiel #4
0
        /// <summary>
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="p"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="scale"></param>
        private void DrawWeatherImag(SKCanvas canvas, GraphIndex p, float x, float y, float scale)
        {
            using (var paint = new SKPaint())
            {
                if (p.Hide || p.ImageId == null)
                {
                    return;
                }

                var assembly = GetType().GetTypeInfo().Assembly;

                using (var stream = assembly.GetManifestResourceStream(p.ImageId))
                    using (var skStream = new SKManagedStream(stream))
                    {
                        var bitmap = SKBitmap.Decode(skStream);
                        var left   = x - scale * bitmap.Width / 2;
                        var top    = y - scale * bitmap.Height / 2;
                        var right  = left + scale * bitmap.Width * 1.2f;
                        var bottom = top + scale * bitmap.Height * 1.2f;

                        canvas.DrawBitmap(bitmap, new SKRect(left, top, right, bottom));
                    }
            }
        }