SKRoundRect makeBox(SKImageInfo info, SKCanvas canvas, TypeShadow typeShadow, float x, float y, Color color, Color backgroundColor) { SKPaint skPaint = new SKPaint() { Style = SKPaintStyle.Fill, Color = backgroundColor.ToSKColor(), //StrokeWidth = 20, IsAntialias = true, }; SKRect skRectangle = new SKRect(); if (!ShowOut) { skRectangle.Size = new SKSize(info.Width, info.Height); skRectangle.Location = new SKPoint(0, 0); } else { skRectangle.Size = new SKSize(info.Width - (SizeShadow * 2), info.Height - (SizeShadow * 2)); skRectangle.Location = new SKPoint(SizeShadow, SizeShadow); } var mask = new SKRoundRect(skRectangle, BorderRadius, BorderRadius); canvas.DrawRoundRect(skRectangle, BorderRadius, BorderRadius, skPaint); //canvas.ClipRoundRect(mask, SKClipOperation.Difference); return(mask); }
protected internal void ClipRoundRect(SKRoundRect roundRect, IGradientMask mask, DrawContext context) { using var canvasLock = new CanvasLock(context.Canvas); LayoutBounds(mask, roundRect.Rect, context, false); context.Canvas.ClipRoundRect(roundRect, mask.ClipMode.ToSkOperation(), true); }
protected override void OnPaintSurface(SKPaintSurfaceEventArgs eventArgs) { var givenCanvas = eventArgs.Surface.Canvas; givenCanvas.Clear(); this.canvasWidth = eventArgs.Info.Width; this.canvasHeight = eventArgs.Info.Height; SKPaint paintBadge = new SKPaint() { IsAntialias = true, Color = this.colorBadge.ToSKColor() }; SKRect rectBadge = new SKRect(0, 0, this.canvasWidth, this.canvasHeight); SKRoundRect roundRectBadge = new SKRoundRect(rectBadge, 15, 15); givenCanvas.DrawRoundRect(roundRectBadge, paintBadge); SKPaint paintBadgeText = new SKPaint() { TextSize = FontSize, IsAntialias = true, Color = SKColors.White, TextAlign = SKTextAlign.Center }; SKRect rectBadgeText = new SKRect(); paintBadgeText.MeasureText(this.contentBadge, ref rectBadgeText); givenCanvas.DrawText(this.contentBadge, this.canvasWidth / 2, this.canvasHeight / 2 - rectBadgeText.MidY, paintBadgeText); }
private void CornersCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs e) { var canvas = e.Surface.Canvas; var info = e.Info; canvas.Clear(); SKRoundRect roundRect = new SKRoundRect(new SKRect(0, 0, info.Width, info.Height), cornerRadius, cornerRadius); using (SKPaint cornerPaint = new SKPaint()) { cornerPaint.Color = App.Current.Resources.GetValue <Color>("DarkDetailColour").ToSKColor(); cornerPaint.Style = SKPaintStyle.Stroke; cornerPaint.StrokeWidth = 20; cornerPaint.IsAntialias = true; cornerPaint.StrokeCap = SKStrokeCap.Butt; cornerPaint.StrokeJoin = SKStrokeJoin.Round; canvas.ClipRoundRect(roundRect, antialias: true); canvas.ClipRect(new SKRect(0, cornerRadius * 1.5f, info.Width, info.Height - (cornerRadius * 1.5f)), SKClipOperation.Difference); canvas.ClipRect(new SKRect(cornerRadius * 1.5f, 0, info.Width - (cornerRadius * 1.5f), info.Height), SKClipOperation.Difference); canvas.DrawRoundRect(roundRect, cornerPaint); } }
public void CanConstructRectWithRadii() { var rect = SKRect.Create(10, 10, 100, 100); var radii = new[] { new SKPoint(1, 2), new SKPoint(3, 4), new SKPoint(5, 6), new SKPoint(7, 8) }; var rrect = new SKRoundRect(); rrect.SetRectRadii(rect, radii); Assert.NotNull(rrect); Assert.True(rrect.IsValid); Assert.Equal(SKRoundRectType.Complex, rrect.Type); Assert.Equal(100f, rrect.Width); Assert.Equal(100f, rrect.Height); Assert.Equal(rect, rrect.Rect); Assert.Equal(radii[0], rrect.GetRadii(SKRoundRectCorner.UpperLeft)); Assert.Equal(radii[1], rrect.GetRadii(SKRoundRectCorner.UpperRight)); Assert.Equal(radii[2], rrect.GetRadii(SKRoundRectCorner.LowerRight)); Assert.Equal(radii[3], rrect.GetRadii(SKRoundRectCorner.LowerLeft)); }
public RenderDimensions(int width, int height, Board board) { _width = width; _height = height; _board = board; // Calculated values CellHeight = (height / (board.Height + 3)); TextSize = CellHeight * 0.8f; StatusHeight = CellHeight * 1.5f; BoardHeight = height - StatusHeight; PlayerWidth = (width / (board.Players.Count)); PlayerStatusPadding = CellHeight * 0.1f; PlayerBoxPadding = CellHeight * 0.2f; PlayerBoxBottom = CellHeight - PlayerBoxPadding; CellWidth = width / board.Width; // End turn rounded rectangle var r = new SKRect(0 + PlayerStatusPadding, height - (CellHeight * 1.5f) + PlayerStatusPadding, width - PlayerStatusPadding, height - PlayerStatusPadding); EndTurnRect = new SKRoundRect(r, PlayerStatusPadding, PlayerStatusPadding); // Precompute all zone rectangles ZoneToRect = new Dictionary <Zone, SKRect>(); foreach (var z in board.Zones) { r = new SKRect(); r.Left = CellWidth * z.X; r.Top = StatusHeight + CellHeight * z.Y; r.Right = r.Left + CellWidth; r.Bottom = r.Top + CellHeight; ZoneToRect[z] = r; } }
private void ScanCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs e) { var canvas = e.Surface.Canvas; var info = e.Info; canvas.Clear(); SKRoundRect roundRect = new SKRoundRect(new SKRect(4, 4, info.Width - 4, info.Height - 4), cornerRadius - 4, cornerRadius - 4); if (overlayPaint == null) { overlayPaint = new SKPaint(); } bool down = transparentPosition - whitePosition < 0; overlayPaint.Shader = SKShader.CreateLinearGradient( new SKPoint(info.Rect.Left, info.Rect.Top), new SKPoint(info.Rect.Left, info.Height), new SKColor[] { down?transparentColour: whiteColour, down ? whiteColour : transparentColour }, new float[] { down?transparentPosition: whitePosition, down ? whitePosition : transparentPosition }, SKShaderTileMode.Clamp); canvas.ClipRoundRect(roundRect, antialias: true); canvas.DrawRoundRect(0, down ? info.Height * transparentPosition : info.Height * whitePosition, info.Width, down ? info.Height * whitePosition : info.Height * transparentPosition, cornerRadius, cornerRadius, overlayPaint); }
public void CanDrawRoundRectDifference() { using var outer = new SKRoundRect(SKRect.Create(50, 50, 200, 200), 20); using var inner = new SKRoundRect(SKRect.Create(100, 100, 100, 100), 20); using var paint = new SKPaint(); SKColor[] diff; using (var bmp = new SKBitmap(new SKImageInfo(300, 300))) using (var canvas = new SKCanvas(bmp)) { canvas.Clear(SKColors.Transparent); canvas.DrawRoundRectDifference(outer, inner, paint); diff = bmp.Pixels; } SKColor[] paths; using (var bmp = new SKBitmap(new SKImageInfo(300, 300))) using (var canvas = new SKCanvas(bmp)) using (var path = new SKPath()) { canvas.Clear(SKColors.Transparent); path.AddRoundRect(outer); path.AddRoundRect(inner); path.FillType = SKPathFillType.EvenOdd; canvas.DrawPath(path, paint); paths = bmp.Pixels; } Assert.Equal(paths, diff); }
public void set_path(SKPath path) { path_ = path; isRect_ = false; SKRect rect = new SKRect(); // Awaiting API implementation in SkiaSharp //if (path.isRect(rect)) //{ // isRect_ = true; // frameRRect_ = new SKRoundRect(rect); //} //else if (SKPath.path.isRRect(frameRRect_)) //{ // isRect_ = frameRRect_.isRect(); //} //else if (path.isOval(rect)) //{ // // isRRect returns false for ovals, so we need to explicitly check isOval // // as well. // frameRRect_ = new SKRoundRect(rect); //} //else //{ // Scenic currently doesn't provide an easy way to create shapes from // arbitrary paths. // For shapes that cannot be represented as a rounded rectangle we // default to use the bounding rectangle. // TODO(amirh): fix this once we have a way to create a Scenic shape from // an SKPath. frameRRect_ = new SKRoundRect(path.Bounds); //} }
public void CheckAllCornersCircular() { var rect = SKRect.Create(10, 10, 100, 100); var rrect = new SKRoundRect(rect, 5, 5); Assert.True(rrect.AllCornersCircular); }
private void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args) { SKImageInfo info = args.Info; SKSurface surface = args.Surface; SKCanvas canvas = surface.Canvas; canvas.Clear(); float size = 600; float posX = (info.Width - size) / 2; float posY = (info.Height - size) / 2; using (SKPath path = new SKPath()) { var fillRect = SKRect.Create(info.Width, info.Height); var codeRect = SKRect.Create(posX, posY, size, size); var roundRect = new SKRoundRect(codeRect, 20); canvas.ClipRoundRect(roundRect, SKClipOperation.Difference, true); SKColor maskColor; SKColor.TryParse("003AB6", out maskColor); using (SKPaint paint = new SKPaint()) { paint.Style = SKPaintStyle.Fill; paint.Color = maskColor; canvas.DrawRect(fillRect, paint); } } }
protected override void OnPaintSurface(SKPaintSurfaceEventArgs e) { base.OnPaintSurface(e); SKRoundRect skRoundRect = new SKRoundRect(e.Info.Rect, myRoundRadius); SKSurface surface = e.Surface; SKCanvas canvas = surface.Canvas; canvas.Clear(myBackgroundColor); SKPaint paint = new SKPaint { Style = SKPaintStyle.Fill, TextSize = 48, StrokeWidth = myCircleStrokeWidth, IsAntialias = true }; paint.Style = SKPaintStyle.Fill; paint.Color = myColor1; paint.Shader = SKShader.CreateLinearGradient( new SKPoint(skRoundRect.Rect.Left, skRoundRect.Rect.Top), new SKPoint(skRoundRect.Rect.Right, skRoundRect.Rect.Bottom), new SKColor[] { myColor1, myColor2 }, new float[] { 0, 1f }, SKShaderTileMode.Repeat); canvas.DrawRoundRect(skRoundRect, paint); }
protected internal void ClipRoundRect(SKRoundRect roundRect, IRectangleMask mask, DrawContext context) { var canvas = context.GetNativeCanvas <SkiaCanvasEx>(); using var layout = ShapeMaskLayout.Create(mask, roundRect.Rect.AsRectangleF(), context, false); canvas.ClipRoundRect(roundRect, mask.ClipMode.ToSkOperation()); }
public static SKPath ToPath(this SKRoundRect bounds) { var path = new SKPath(); path.AddRoundRect(bounds); path.Close(); return(path); }
public void CheckAllCornersCircularWithTolerance() { var rect = SKRect.Create(10, 10, 100, 100); var rrect = new SKRoundRect(rect, 5, 7); Assert.False(rrect.AllCornersCircular); Assert.True(rrect.CheckAllCornersCircular(2f)); }
protected override void OnPaintSurface(SKPaintSurfaceEventArgs eventArgs) { var givenCanvas = eventArgs.Surface.Canvas; givenCanvas.Clear(); int canvasWidth = eventArgs.Info.Width; int canvasHeight = eventArgs.Info.Height; this.roundRectButton = new SKRoundRect(new SKRect(0, 0, canvasWidth, canvasHeight - 20), ButtonRadius, ButtonRadius); this.paintButton = new SKPaint() { Color = this.ColorPrimary.ToSKColor(), IsAntialias = true }; if (HasShadow) { paintButton.ImageFilter = SKImageFilter.CreateDropShadow( 0, 8, 0, 5, Color.FromRgba(0, 0, 0, 0.4).ToSKColor(), SKDropShadowImageFilterShadowMode.DrawShadowAndForeground ); } if (this.IsGradient) { paintButton.Shader = SKShader.CreateLinearGradient( new SKPoint(this.roundRectButton.Rect.Left, this.roundRectButton.Rect.Top), new SKPoint(this.roundRectButton.Rect.Right, this.roundRectButton.Rect.Bottom), new SKColor[] { this.ColorPrimary.ToSKColor(), this.ColorSecondary.ToSKColor() }, new float[] { this.buttonGradientOffset, 1 }, SKShaderTileMode.Repeat ); } givenCanvas.DrawRoundRect(this.roundRectButton, this.paintButton); SKPaint paintButtonTitle = new SKPaint() { TextSize = FontSize * coreSettings.ScalingFactor, IsAntialias = true, Color = this.ColorText.ToSKColor(), TextAlign = TextAlign, Typeface = TextFont }; givenCanvas.DrawText(this.ButtonTitle, canvasWidth / 2, ((canvasHeight - 30) / 2 + 25), paintButtonTitle); }
public void DrawRoundRect(SKRoundRect rect, SKPaint paint) { canvas.DrawRoundRect(rect, paint); if (calculateBounds) { displayObject.addBoundingRect(rect.Rect); } }
SKRoundRect CreateRoundRect(SKRect bounds) { var border = Forms.ConvertToScaledPixel(s_borderWidth) * (Element.HasShadow ? 4 : 2); var radius = Forms.ConvertToScaledPixel(Element.CornerRadius); var roundRect = new SKRoundRect(bounds, radius); roundRect.Deflate(border, border); return(roundRect); }
/* Method to create the underlying empty bar for nutritional visualizations * Called for each base cell of each nutrient */ private void DrawBaseVisual(SKPaintSurfaceEventArgs e) { SKCanvas canvas = e.Surface.Canvas; using (SKPaint paint = new SKPaint()) { canvas.Clear(BASEBACKGROUND); var HORIZONTALPADDING = 30f; var VERTICALPADDING = 15f; var width = e.Info.Width - 2 * HORIZONTALPADDING; var height = e.Info.Height - 2 * VERTICALPADDING; // The black outline to the visualize bar paint.Color = Color.Black.ToSKColor(); canvas.DrawRoundRect(new SKRoundRect(new SKRect(HORIZONTALPADDING - 19, VERTICALPADDING - 4, width + HORIZONTALPADDING + 19, height + VERTICALPADDING + 4), 15f, 15f), paint); // The left rounded edge of the nutrition visual // Starts Red to indicate that it could fill up SKRoundRect firstRound = new SKRoundRect(new SKRect(HORIZONTALPADDING - 15f, VERTICALPADDING, HORIZONTALPADDING + 15f, height + VERTICALPADDING), 15f, 15f); paint.Color = Color.Red.ToSKColor(); canvas.DrawRoundRect(firstRound, paint); // The right rounded edge SKRoundRect secondRound = new SKRoundRect(new SKRect(width + 15f, VERTICALPADDING, width + 45f, height + VERTICALPADDING), 15f, 15f); paint.Color = LIGHTRED; canvas.DrawRoundRect(secondRound, paint); // Rectangle for consumed DRI 0 tp Min Threshold SKRect firstRect = new SKRect(HORIZONTALPADDING, VERTICALPADDING, (width / 10) + HORIZONTALPADDING, height + VERTICALPADDING); paint.Color = LIGHTRED; canvas.DrawRect(firstRect, paint); // Rectangle for consumed DRI from Min Threshold to half way between Min and DRI SKRect secRect = new SKRect((width / 10) + HORIZONTALPADDING, VERTICALPADDING, (width / 10) * 3 + HORIZONTALPADDING, height + VERTICALPADDING); paint.Color = LIGHTYELLOW; canvas.DrawRect(secRect, paint); // Rectangle for consumed DRI from // half way between low thresh and DRI to half way from DRI to max threshhold SKRect thirdRect = new SKRect((width / 10) * 3 + HORIZONTALPADDING, VERTICALPADDING, (width / 10) * 7 + HORIZONTALPADDING, height + VERTICALPADDING); paint.Color = LIGHTGREEN; canvas.DrawRect(thirdRect, paint); // Rectangle for consumed DRI from // halfway between DRI and max threshhold to max threshold SKRect fourRect = new SKRect((width / 10) * 7 + HORIZONTALPADDING, VERTICALPADDING, (width / 10) * 9 + HORIZONTALPADDING, height + VERTICALPADDING); paint.Color = LIGHTYELLOW; canvas.DrawRect(fourRect, paint); // Rectangle for consumed DRI from max threshold to twice the regular DRI SKRect fiveRect = new SKRect(((width / 10) * 9) + HORIZONTALPADDING, VERTICALPADDING, width + HORIZONTALPADDING, height + VERTICALPADDING); paint.Color = LIGHTRED; canvas.DrawRect(fiveRect, paint); } }
public void ContainsRect() { var rect = SKRect.Create(10, 10, 100, 100); var rrect = new SKRoundRect(rect, 5, 5); var contains = rrect.Contains(SKRect.Create(20, 20, 20, 20)); Assert.True(contains); }
public static SKPath CreateRoundedRectPath(SKRoundRect skroundRect) { var skPath = new SKPath(); skPath.AddRoundRect(skroundRect, SKPathDirection.Clockwise); skPath.Close(); return(skPath); }
public static SKBitmap ClipRoundRect(this SKBitmap bitmap, int cornerRadius) { var rect = new SKRoundRect(new SKRect(0, 0, bitmap.Width, bitmap.Height), cornerRadius); var skCanvas = new SKCanvas(bitmap); skCanvas.ClipRoundRect(rect); skCanvas.Flush(); skCanvas.Save(); return(bitmap); }
public void CanGetRadii() { var rect = SKRect.Create(10, 10, 100, 100); var rrect = new SKRoundRect(rect, 5, 7); Assert.Equal(new SKPoint(5, 7), rrect.GetRadii(SKRoundRectCorner.UpperLeft)); Assert.Equal(new SKPoint(5, 7), rrect.GetRadii(SKRoundRectCorner.UpperRight)); Assert.Equal(new SKPoint(5, 7), rrect.GetRadii(SKRoundRectCorner.LowerRight)); Assert.Equal(new SKPoint(5, 7), rrect.GetRadii(SKRoundRectCorner.LowerLeft)); }
public Frame(SceneUpdateContext context, SKRoundRect rrect, uint color, float elevation) : base(context) { this.rrect_ = new SKRoundRect(rrect); this.color_ = color; this.paint_bounds_ = SKRect.Empty; if (elevation != 0.0F) { //entity_node().SetTranslation(0.0f, 0.0f, elevation); } }
public void PathContainsPointInRoundRect() { using (var path = new SKPath()) { var rrect = new SKRoundRect(SKRect.Create(10, 10, 100, 100), 5, 5); path.AddRoundRect(rrect); Assert.True(path.Contains(30, 30)); Assert.False(path.Contains(5, 30)); } }
public void CanInflate() { var rect = SKRect.Create(10, 10, 100, 100); var inflated = SKRect.Inflate(rect, 2, 2); var rrect = new SKRoundRect(rect, 5, 5); rrect.Inflate(2, 2); Assert.Equal(inflated, rrect.Rect); }
private SKRoundRect WalkingDataRect(WalkingDataPointModel value, float totalWidth, float totalHeight) { var d = totalWidth / (HOUR - 1); // divide into minutes var xStart = d * value.Start.Minute + (float)minMargin.Left; var xEnd = d * value.Stop.Minute - (float)minMargin.Right; var rect = new SKRect(xStart, 0, xEnd, totalHeight); var roundedRect = new SKRoundRect(rect, CornerRadius, CornerRadius); return(roundedRect); }
public void WillFailToTransformWithInvalidTransformation() { var rect = SKRect.Create(10, 10, 100, 100); var offset = rect; offset.Offset(2, 2); var rrect = new SKRoundRect(rect, 5, 5); var transformed = rrect.Transform(SKMatrix.CreateRotationDegrees(30)); Assert.Null(transformed); }
/// <summary> /// Draws a filled rectangle with rounded corners. /// </summary> public static void FillRoundedRectangle(this SKCanvas canvas, int x, int y, int width, int height, SKColor color, int rx = 3, int ry = 3, float strokeWidth = 1) { using var paint = new SKPaint { Color = color, IsStroke = false, IsAntialias = true, StrokeWidth = strokeWidth }; var r = new SKRoundRect(); canvas.DrawRoundRect(x + .5f, y + .5f, width, height, rx, ry, paint); }
protected override void OnPaintSurface(SKPaintSurfaceEventArgs eventArgs) { var givenCanvas = eventArgs.Surface.Canvas; givenCanvas.Clear(); this.canvasWidth = eventArgs.Info.Width; this.canvasHeight = eventArgs.Info.Height; if (!this.HasShadow) { this.shadowPadding = 0; } // Draw the Checkbox container SKRoundRect roundRectCheckbox = new SKRoundRect(new SKRect(this.shadowPadding, 0, this.canvasWidth - this.shadowPadding, this.canvasHeight - (this.shadowPadding * 2)), ((this.canvasHeight - (this.shadowPadding * 2)) / 6), ((this.canvasHeight - (this.shadowPadding * 2)) / 6)); SKPaint paintCheckbox = new SKPaint() { Color = this.colorCurrent.ToSKColor(), Style = SKPaintStyle.Fill, IsAntialias = true }; if (this.HasShadow) { paintCheckbox.ImageFilter = SKImageFilter.CreateDropShadow( 0, 8, 0, 5, Color.FromRgba(0, 0, 0, 0.4).ToSKColor(), SKDropShadowImageFilterShadowMode.DrawShadowAndForeground ); } givenCanvas.DrawRoundRect(roundRectCheckbox, paintCheckbox); if (this.IsChecked) { SKPaint paintIcon = new SKPaint() { TextSize = 48f, IsAntialias = true, Color = this.ColorIcon.ToSKColor(), TextAlign = SKTextAlign.Center, Typeface = this.GetTypeface("fa-solid-900.ttf") }; SKRect rectIcon = new SKRect(); paintIcon.MeasureText("\uf00d", ref rectIcon); givenCanvas.DrawText("\uf00d", this.canvasWidth / 2, this.canvasHeight / 2 - rectIcon.MidY - this.shadowPadding, paintIcon); } }