void PaintContents(object sender, SKPaintSurfaceEventArgs e) { var canvas = e.Surface.Canvas; canvas.Clear(SKColors.Transparent); var b = canvas.ClipBounds; using (var paint = new SKPaint { IsAntialias = true, IsStroke = false, Color = FillColor.ToSKColor(), }) { canvas.DrawCircle(b.MidX, b.MidX, b.MidX - 2, paint); } if (!string.IsNullOrWhiteSpace(Text)) { if (_textLabel == null) { //Using a label here instead of drawing text because Skia text size is non-DPI pixels _textLabel = new Label { FontSize = TextSize, TextColor = TextColor, Margin = new Thickness(4), VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, }; _root.Children.Add(_textLabel); } _textLabel.Text = Text; //using(var paint = new SKPaint //{ // IsAntialias = true, // Color = TextColor.ToSKColor(), // TextSize = (float)TextSize, //}) //{ // var tw = paint.MeasureText(Text); // var w = b.MidX - (tw / 2); // var h = b.MidY + (paint.TextSize / 2) - 6; // canvas.DrawText(Text, w, h, paint); //} } }
void PaintContents(object sender, SKPaintSurfaceEventArgs e) { var canvas = e.Surface.Canvas; canvas.Clear(SKColors.Transparent); var b = canvas.ClipBounds; using (var paint = new SKPaint { IsAntialias = true, IsStroke = false, Color = FillColor.ToSKColor(), }) { canvas.DrawRoundRect(b, (float)CornerRadius, (float)CornerRadius, paint); } }
void DrawCheckFilled(SKPaintSurfaceEventArgs e) { var imageInfo = e.Info; var canvas = e?.Surface?.Canvas; using (var checkfill = new SKPaint { Style = SKPaintStyle.Fill, Color = FillColor.ToSKColor(), StrokeJoin = SKStrokeJoin.Round, IsAntialias = true }) { if (Shape == Shape.Circle) { canvas.DrawCircle(imageInfo.Width / 2, imageInfo.Height / 2, (imageInfo.Width / 2) - (OutlineWidth / 2), checkfill); } else { canvas.DrawRoundRect(OutlineWidth, OutlineWidth, imageInfo.Width - (OutlineWidth * 2), imageInfo.Height - (OutlineWidth * 2), OutlineWidth, OutlineWidth, checkfill); } } using (var checkPath = new SKPath()) { checkPath.MoveTo(.275f * imageInfo.Width, .5f * imageInfo.Height); checkPath.LineTo(.425f * imageInfo.Width, .65f * imageInfo.Height); checkPath.LineTo(.725f * imageInfo.Width, .375f * imageInfo.Height); using (var checkStroke = new SKPaint { Style = SKPaintStyle.Stroke, Color = CheckColor.ToSKColor(), StrokeWidth = (float)OutlineWidth, StrokeCap = SKStrokeCap.Round, IsAntialias = true }) { canvas.DrawPath(checkPath, checkStroke); } } }
void PaintContents(object sender, SKPaintSurfaceEventArgs e) { var canvas = e.Surface.Canvas; canvas.Clear(SKColors.Transparent); var b = canvas.LocalClipBounds; if (FillColor != Color.Transparent) { using (var paint = new SKPaint { IsAntialias = true, IsStroke = false, Color = FillColor.ToSKColor(), }) { canvas.DrawRoundRect(b, (float)CornerRadius, (float)CornerRadius, paint); } } if (BorderColor != Color.Transparent) { using (var paint = new SKPaint { IsAntialias = true, IsStroke = true, StrokeWidth = 1.5f, Color = BorderColor.ToSKColor(), }) { var rect = new SKRect(b.Left + paint.StrokeWidth, b.Top + paint.StrokeWidth, b.Right - paint.StrokeWidth, b.Bottom - paint.StrokeWidth); canvas.DrawRoundRect(rect, (float)CornerRadius, (float)CornerRadius, paint); } } }
void DrawCheckFilled(SKPaintSurfaceEventArgs e) { var imageInfo = e.Info; var canvas = e?.Surface?.Canvas; using (var checkfill = new SKPaint { Style = SKPaintStyle.Fill, Color = FillColor.ToSKColor(), StrokeJoin = SKStrokeJoin.Round, IsAntialias = true }) { var shape = Design == Design.Unified ? Shape : DEFAULT_SHAPE; if (shape == Shape.Circle) { canvas.DrawCircle(imageInfo.Width / 2, imageInfo.Height / 2, (imageInfo.Width / 2) - (OutlineWidth / 2), checkfill); } else { var cornerRadius = Design == Design.Native && Device.RuntimePlatform == Device.UWP ? 0 : OutlineWidth; canvas.DrawRoundRect(OutlineWidth, OutlineWidth, imageInfo.Width - (OutlineWidth * 2), imageInfo.Height - (OutlineWidth * 2), cornerRadius, cornerRadius, checkfill); } } using (var checkPath = new SKPath()) { if (Design == Design.Unified) { checkPath.MoveTo(.275f * imageInfo.Width, .5f * imageInfo.Height); checkPath.LineTo(.425f * imageInfo.Width, .65f * imageInfo.Height); checkPath.LineTo(.725f * imageInfo.Width, .375f * imageInfo.Height); } else { switch (Device.RuntimePlatform) { case Device.iOS: checkPath.MoveTo(.2f * imageInfo.Width, .5f * imageInfo.Height); checkPath.LineTo(.375f * imageInfo.Width, .675f * imageInfo.Height); checkPath.LineTo(.75f * imageInfo.Width, .3f * imageInfo.Height); break; case Device.Android: checkPath.MoveTo(.2f * imageInfo.Width, .5f * imageInfo.Height); checkPath.LineTo(.425f * imageInfo.Width, .7f * imageInfo.Height); checkPath.LineTo(.8f * imageInfo.Width, .275f * imageInfo.Height); break; case Device.UWP: checkPath.MoveTo(.15f * imageInfo.Width, .5f * imageInfo.Height); checkPath.LineTo(.375f * imageInfo.Width, .75f * imageInfo.Height); checkPath.LineTo(.85f * imageInfo.Width, .25f * imageInfo.Height); break; default: break; } } using (var checkStroke = new SKPaint { Style = SKPaintStyle.Stroke, Color = CheckColor.ToSKColor(), StrokeWidth = OutlineWidth, IsAntialias = true }) { checkStroke.StrokeCap = Design == Design.Unified ? SKStrokeCap.Round : SKStrokeCap.Butt; canvas.DrawPath(checkPath, checkStroke); } } }