Exemplo n.º 1
0
        protected virtual void InternalDraw(SKCanvas canvas)
        {
            using (var paint = new SKPaint())
            {
                if (BackgroundColor.A > 0)
                {
                    paint.Color = BackgroundColor.ToSKColor();
                    canvas.DrawRect(RenderBounds.ToSKRect(), paint);
                }

                if (FrameColor.A > 0)
                {
                    paint.Color       = FrameColor.ToSKColor();
                    paint.IsStroke    = true;
                    paint.StrokeWidth = (float)FrameThickness;
                    canvas.DrawRect(RenderBounds.ToSKRect(), paint);
                }
            }

            if (Drawing != null)
            {
                Drawing(canvas);
            }
        }
Exemplo n.º 2
0
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
        {
            base.OnPaintSurface(e);
            var canvas = e.Surface.Canvas;

            canvas.Clear();

            int width  = e.Info.Width;
            int height = e.Info.Height;

            SKPaint backPaint = new SKPaint
            {
                Style = SKPaintStyle.Fill,
                Color = SKColors.WhiteSmoke,
            };

            canvas.DrawRect(new SKRect(0, 0, width, height), backPaint);

            canvas.Save();

            canvas.Translate(width / 2, height / 2);
            canvas.Scale(Math.Min(width / 210f, height / 520f));

            var rect = new SKRect(-100, -100, 100, 100);

            // Add a buffer for the rectangle
            rect.Inflate(-10, -10);

            var bgColorPaint = new SKPaint
            {
                Color       = BGColor.ToSKColor(),
                IsAntialias = true,
                Style       = SKPaintStyle.Fill,
                StrokeWidth = 0
            };


            var barColorPaint = new SKPaint
            {
                Color       = BarColor.ToSKColor(),
                IsAntialias = true,
                Style       = SKPaintStyle.Fill,
                StrokeWidth = 0
            };

            var frameColorPaint = new SKPaint
            {
                Color       = FrameColor.ToSKColor(),
                IsAntialias = true,
                Style       = SKPaintStyle.Stroke,
                StrokeWidth = 2
            };

            var skrect      = new SKRect(0, 0, PGWidth, PGHeight);
            var skRoundRect = new SKRoundRect(skrect, PGHeight / 2, PGHeight / 2);

            canvas.DrawRoundRect(0, 0, PGWidth, PGHeight, PGHeight / 2, PGHeight / 2, bgColorPaint);
            canvas.DrawRoundRect(skRoundRect, frameColorPaint);
            canvas.ClipRoundRect(skRoundRect, SKClipOperation.Intersect);

            if (StartColor != Color.Default && EndColor != Color.Default)
            {
                barColorPaint.Shader = SKShader.CreateLinearGradient(
                    new SKPoint(skrect.Left, skrect.Bottom),
                    new SKPoint(skrect.Right, skrect.Top),
                    new SKColor[] { StartColor.ToSKColor(), EndColor.ToSKColor() },
                    new float[] { 0, 1 },
                    SKShaderTileMode.Repeat);
            }
            canvas.DrawRoundRect(0, 0, PGWidth * Progress / 100, PGHeight, PGWidth / 2, 0, barColorPaint);

            canvas.Restore();
        }
Exemplo n.º 3
0
        protected void DrawVerticalLabels(SKCanvas canvas, SKRect frame, SKRect chart)
        {
            using (var paint = new SKPaint
            {
                TextSize = VerticalLabelTextSize,
                Color = this.VerticalLabelColor.ToSKColor(),
                IsAntialias = true
            })
            {
                // Calculates maximum value depending on chart height
                var maximumValue = chart.Height * (MaxValue / chart.Height);

                if (VerticalLabelMode != LabelMode.None)
                {
                    // Draw vertical unit
                    if (!string.IsNullOrEmpty(VerticalUnit))
                    {
                        // Draws maximum value
                        canvas.DrawText(this.VerticalUnit, ChartRectMargin.Left, frame.Top + VerticalLabelTextSize, paint);
                        canvas.DrawText(maximumValue.ToString(), ChartRectMargin.Left, frame.Top + (VerticalLabelTextSize * 2), paint);
                    }
                    else
                    {
                        // Draws maximum value
                        canvas.DrawText(maximumValue.ToString(), ChartRectMargin.Left, frame.Top + VerticalLabelTextSize, paint);
                    }

                    canvas.DrawText("0", ChartRectMargin.Left, frame.Bottom, paint);
                }

                if (VerticalLabelMode == LabelMode.StartCenterEnd || VerticalLabelMode == LabelMode.All)
                {
                    using (var framePaint = new SKPaint
                    {
                        Style = SKPaintStyle.Stroke,
                        Color = FrameColor.ToSKColor(),
                        StrokeWidth = FrameWidth / 2,
                    })
                    {
                        if (DashedFrame)
                        {
                            framePaint.PathEffect = SKPathEffect.CreateDash(new float[] { 12, 12 }, 0);
                        }

                        if (HideFrame)
                        {
                            canvas.DrawLine(frame.Left, string.IsNullOrEmpty(VerticalUnit) ? frame.Top + (VerticalLabelTextSize / 2) : frame.Top + VerticalLabelTextSize, frame.Right, string.IsNullOrEmpty(VerticalUnit) ? frame.Top + (VerticalLabelTextSize / 2) : frame.Top + VerticalLabelTextSize, framePaint);
                            canvas.DrawLine(frame.Left, frame.Bottom - (VerticalLabelTextSize / 4), frame.Right, frame.Bottom - (VerticalLabelTextSize / 4), framePaint);
                        }

                        canvas.DrawText((maximumValue / 2).ToString(), ChartRectMargin.Left, frame.MidY + (VerticalLabelTextSize / 4), paint);

                        canvas.DrawLine(frame.Left, frame.MidY, frame.Right, frame.MidY, framePaint);

                        if (VerticalLabelMode == LabelMode.All)
                        {
                            canvas.DrawText((maximumValue * .25).ToString(), ChartRectMargin.Left, (frame.Height * .75f) + (VerticalLabelTextSize / 4), paint);
                            canvas.DrawText((maximumValue * .75).ToString(), ChartRectMargin.Left, (frame.Height * .25f) + (VerticalLabelTextSize / 4), paint);

                            canvas.DrawLine(frame.Left, frame.Height * .75f, frame.Right, frame.Height * .75f, framePaint);
                            canvas.DrawLine(frame.Left, frame.Height * .25f, frame.Right, frame.Height * .25f, framePaint);
                        }
                    }
                }
            }
        }