/// <summary> /// Draws the outline of a rectangle. /// </summary> /// <param name="pen">The pen.</param> /// <param name="rect">The rectangle bounds.</param> /// <param name="cornerRadius">The corner radius.</param> public void DrawRectangle(IPen pen, Rect rect, float cornerRadius) { using (var brush = CreateBrush(pen.Brush, rect.Size)) using (var d2dStroke = pen.ToDirect2DStrokeStyle(_deviceContext)) { if (brush.PlatformBrush != null) { if (cornerRadius == 0) { _deviceContext.DrawRectangle( rect.ToDirect2D(), brush.PlatformBrush, (float)pen.Thickness, d2dStroke); } else { _deviceContext.DrawRoundedRectangle( new RoundedRectangle { Rect = rect.ToDirect2D(), RadiusX = cornerRadius, RadiusY = cornerRadius }, brush.PlatformBrush, (float)pen.Thickness, d2dStroke); } } } }
/// <summary> /// Draws a geometry. /// </summary> /// <param name="brush">The fill brush.</param> /// <param name="pen">The stroke pen.</param> /// <param name="geometry">The geometry.</param> public void DrawGeometry(IBrush brush, IPen pen, IGeometryImpl geometry) { if (brush != null) { using (var d2dBrush = CreateBrush(brush, geometry.Bounds.Size)) { if (d2dBrush.PlatformBrush != null) { var impl = (GeometryImpl)geometry; _deviceContext.FillGeometry(impl.Geometry, d2dBrush.PlatformBrush); } } } if (pen != null) { using (var d2dBrush = CreateBrush(pen.Brush, geometry.GetRenderBounds(pen).Size)) using (var d2dStroke = pen.ToDirect2DStrokeStyle(_deviceContext)) { if (d2dBrush.PlatformBrush != null) { var impl = (GeometryImpl)geometry; _deviceContext.DrawGeometry(impl.Geometry, d2dBrush.PlatformBrush, (float)pen.Thickness, d2dStroke); } } } }
/// <summary> /// Draws a line. /// </summary> /// <param name="pen">The stroke pen.</param> /// <param name="p1">The first point of the line.</param> /// <param name="p2">The second point of the line.</param> public void DrawLine(IPen pen, Point p1, Point p2) { if (pen != null) { using (var d2dBrush = CreateBrush(pen.Brush, new Rect(p1, p2).Normalize())) using (var d2dStroke = pen.ToDirect2DStrokeStyle(_deviceContext)) { if (d2dBrush.PlatformBrush != null) { _deviceContext.DrawLine( p1.ToSharpDX(), p2.ToSharpDX(), d2dBrush.PlatformBrush, (float)pen.Thickness, d2dStroke); } } } }
/// <inheritdoc /> public void DrawEllipse(IBrush brush, IPen pen, Rect rect) { var rc = rect.ToDirect2D(); if (brush != null) { using (var b = CreateBrush(brush, rect.Size)) { if (b.PlatformBrush != null) { _deviceContext.FillEllipse(new Ellipse { Point = rect.Center.ToSharpDX(), RadiusX = (float)(rect.Width / 2), RadiusY = (float)(rect.Height / 2) }, b.PlatformBrush); } } } if (pen?.Brush != null) { using (var wrapper = CreateBrush(pen.Brush, rect.Size)) using (var d2dStroke = pen.ToDirect2DStrokeStyle(_deviceContext)) { if (wrapper.PlatformBrush != null) { _deviceContext.DrawEllipse(new Ellipse { Point = rect.Center.ToSharpDX(), RadiusX = (float)(rect.Width / 2), RadiusY = (float)(rect.Height / 2) }, wrapper.PlatformBrush, (float)pen.Thickness, d2dStroke); } } } }
/// <inheritdoc /> public void DrawRectangle(IBrush brush, IPen pen, RoundedRect rrect, BoxShadows boxShadow = default) { var rc = rrect.Rect.ToDirect2D(); var rect = rrect.Rect; var radiusX = Math.Max(rrect.RadiiTopLeft.X, Math.Max(rrect.RadiiTopRight.X, Math.Max(rrect.RadiiBottomRight.X, rrect.RadiiBottomLeft.X))); var radiusY = Math.Max(rrect.RadiiTopLeft.Y, Math.Max(rrect.RadiiTopRight.Y, Math.Max(rrect.RadiiBottomRight.Y, rrect.RadiiBottomLeft.Y))); var isRounded = !MathUtilities.IsZero(radiusX) || !MathUtilities.IsZero(radiusY); if (brush != null) { using (var b = CreateBrush(brush, rect.Size)) { if (b.PlatformBrush != null) { if (isRounded) { _deviceContext.FillRoundedRectangle( new RoundedRectangle { Rect = new RawRectangleF( (float)rect.X, (float)rect.Y, (float)rect.Right, (float)rect.Bottom), RadiusX = (float)radiusX, RadiusY = (float)radiusY }, b.PlatformBrush); } else { _deviceContext.FillRectangle(rc, b.PlatformBrush); } } } } if (pen?.Brush != null) { using (var wrapper = CreateBrush(pen.Brush, rect.Size)) using (var d2dStroke = pen.ToDirect2DStrokeStyle(_deviceContext)) { if (wrapper.PlatformBrush != null) { if (isRounded) { _deviceContext.DrawRoundedRectangle( new RoundedRectangle { Rect = rc, RadiusX = (float)radiusX, RadiusY = (float)radiusY }, wrapper.PlatformBrush, (float)pen.Thickness, d2dStroke); } else { _deviceContext.DrawRectangle( rc, wrapper.PlatformBrush, (float)pen.Thickness, d2dStroke); } } } } }
/// <inheritdoc /> public void DrawRectangle(IBrush brush, IPen pen, Rect rect, double radiusX, double radiusY) { var rc = rect.ToDirect2D(); var isRounded = Math.Abs(radiusX) > double.Epsilon || Math.Abs(radiusY) > double.Epsilon; if (brush != null) { using (var b = CreateBrush(brush, rect.Size)) { if (b.PlatformBrush != null) { if (isRounded) { _deviceContext.FillRoundedRectangle( new RoundedRectangle { Rect = new RawRectangleF( (float)rect.X, (float)rect.Y, (float)rect.Right, (float)rect.Bottom), RadiusX = (float)radiusX, RadiusY = (float)radiusY }, b.PlatformBrush); } else { _deviceContext.FillRectangle(rc, b.PlatformBrush); } } } } if (pen?.Brush != null) { using (var wrapper = CreateBrush(pen.Brush, rect.Size)) using (var d2dStroke = pen.ToDirect2DStrokeStyle(_deviceContext)) { if (wrapper.PlatformBrush != null) { if (isRounded) { _deviceContext.DrawRoundedRectangle( new RoundedRectangle { Rect = rc, RadiusX = (float)radiusX, RadiusY = (float)radiusY }, wrapper.PlatformBrush, (float)pen.Thickness, d2dStroke); } else { _deviceContext.DrawRectangle( rc, wrapper.PlatformBrush, (float)pen.Thickness, d2dStroke); } } } } }