protected override void OnDraw(global::Android.Graphics.Canvas canvas)
        {
            var rect = new Rect();

            GetDrawingRect(rect);

            var halfThickness = Element.StrokeThickness / 2f;

            var RectangleRect = new RectF(
                rect.Left + halfThickness,
                rect.Top + halfThickness,
                rect.Right - halfThickness,
                rect.Bottom - halfThickness);

            var paint = new Paint(PaintFlags.AntiAlias);

            if (Element.Fill.A != 0)
            {
                var circleDotFillPath = new Path();
                circleDotFillPath.AddRect(RectangleRect, Path.Direction.Cw);

                paint.SetStyle(Paint.Style.Fill);
                paint.Color = Element.Fill.ToAndroid();
                canvas.DrawRect(RectangleRect, paint);
            }

            paint.StrokeWidth = Element.StrokeThickness;
            paint.StrokeMiter = 10f;
            canvas.Save();
            paint.SetStyle(Paint.Style.Stroke);
            paint.Color = Element.Stroke.ToAndroid();
            canvas.DrawRect(RectangleRect, paint);
            canvas.Restore();
        }
Beispiel #2
0
        protected override void OnDraw(global::Android.Graphics.Canvas canvas)
        {
            var rect = new Rect();

            GetDrawingRect(rect);
            Paint paint;

            var halfThickness = Context.DpToPixels(Element.StrokeThickness / 2f);

            var ellipseRect = new RectF(
                rect.Left + halfThickness,
                rect.Top + halfThickness,
                rect.Right - halfThickness,
                rect.Bottom - halfThickness);

            canvas.Save();

            try
            {
                var scale = Context.DpToPixels(1);
                // circleDotFill
                if (Element.Fill.A != 0)
                {
                    var circleDotFillPath = new Path();
                    circleDotFillPath.AddOval(ellipseRect, Path.Direction.Cw);

                    paint = new Paint(PaintFlags.AntiAlias);
                    paint.SetStyle(Paint.Style.Fill);
                    paint.Color = Element.Fill.ToAndroid();
                    canvas.DrawPath(circleDotFillPath, paint);
                }

                // circleDotStroke
                Path circleDotStrokePath = new Path();
                circleDotStrokePath.AddOval(ellipseRect, Path.Direction.Cw);

                paint             = new Paint(PaintFlags.AntiAlias);
                paint.StrokeWidth = Element.StrokeThickness;
                paint.StrokeMiter = 10f;
                paint.SetStyle(Paint.Style.Stroke);
                paint.Color = Element.Stroke.ToAndroid();
                canvas.DrawPath(circleDotStrokePath, paint);
            }
            finally
            {
                canvas.Restore();
            }
        }