diff --git a/Perspex.Controls/Border.cs b/Perspex.Controls/Border.cs index 98919a4e8b..7a8836c6c4 100644 --- a/Perspex.Controls/Border.cs +++ b/Perspex.Controls/Border.cs @@ -22,6 +22,9 @@ namespace Perspex.Controls public static readonly PerspexProperty BorderThicknessProperty = PerspexProperty.Register("BorderThickness"); + public static readonly PerspexProperty CornerRadiusProperty = + PerspexProperty.Register("CornerRadius"); + static Border() { Control.AffectsRender(Border.BackgroundProperty); @@ -46,21 +49,28 @@ namespace Perspex.Controls set { this.SetValue(BorderThicknessProperty, value); } } + public float CornerRadius + { + get { return this.GetValue(CornerRadiusProperty); } + set { this.SetValue(CornerRadiusProperty, value); } + } + public override void Render(IDrawingContext context) { Brush background = this.Background; Brush borderBrush = this.BorderBrush; double borderThickness = this.BorderThickness; + float cornerRadius = this.CornerRadius; Rect rect = new Rect(this.Bounds.Size).Deflate(this.BorderThickness); if (background != null) { - context.FillRectange(background, rect); + context.FillRectange(background, rect, cornerRadius); } if (borderBrush != null && borderThickness > 0) { - context.DrawRectange(new Pen(borderBrush, borderThickness), rect); + context.DrawRectange(new Pen(borderBrush, borderThickness), rect, cornerRadius); } } diff --git a/Perspex.SceneGraph/Media/IDrawingContext.cs b/Perspex.SceneGraph/Media/IDrawingContext.cs index 03be931167..106b6ab3e5 100644 --- a/Perspex.SceneGraph/Media/IDrawingContext.cs +++ b/Perspex.SceneGraph/Media/IDrawingContext.cs @@ -39,7 +39,7 @@ namespace Perspex.Media /// /// The pen. /// The rectangle bounds. - void DrawRectange(Pen pen, Rect rect); + void DrawRectange(Pen pen, Rect rect, float cornerRadius = 0.0f); /// /// Draws text. @@ -54,7 +54,7 @@ namespace Perspex.Media /// /// The brush. /// The rectangle bounds. - void FillRectange(Brush brush, Rect rect); + void FillRectange(Brush brush, Rect rect, float cornerRadius = 0.0f); /// /// Pushes a clip rectange. diff --git a/Windows/Perspex.Direct2D1/Media/DrawingContext.cs b/Windows/Perspex.Direct2D1/Media/DrawingContext.cs index 98fc237d1f..b5d922cc5e 100644 --- a/Windows/Perspex.Direct2D1/Media/DrawingContext.cs +++ b/Windows/Perspex.Direct2D1/Media/DrawingContext.cs @@ -125,13 +125,13 @@ namespace Perspex.Direct2D1.Media /// /// The pen. /// The rectangle bounds. - public void DrawRectange(Pen pen, Rect rect) + public void DrawRectange(Pen pen, Rect rect, float cornerRadius) { using (var brush = pen.Brush.ToDirect2D(this.renderTarget)) using (var d2dStroke = pen.ToDirect2DStrokeStyle(this.renderTarget)) { - this.renderTarget.DrawRectangle( - rect.ToDirect2D(), + this.renderTarget.DrawRoundedRectangle( + new RoundedRectangle { Rect = rect.ToDirect2D(), RadiusX = cornerRadius, RadiusY = cornerRadius }, brush, (float)pen.Thickness, d2dStroke); @@ -162,16 +162,21 @@ namespace Perspex.Direct2D1.Media /// /// The brush. /// The rectangle bounds. - public void FillRectange(Perspex.Media.Brush brush, Rect rect) + public void FillRectange(Perspex.Media.Brush brush, Rect rect, float cornerRadius) { using (var b = brush.ToDirect2D(this.renderTarget)) { - this.renderTarget.FillRectangle( - new RectangleF( - (float)rect.X, - (float)rect.Y, - (float)rect.Width, - (float)rect.Height), + this.renderTarget.FillRoundedRectangle( + new RoundedRectangle + { + Rect = new RectangleF( + (float)rect.X, + (float)rect.Y, + (float)rect.Width, + (float)rect.Height), + RadiusX = cornerRadius, + RadiusY = cornerRadius + }, b); } }