public DrawRoundedRectangle ( RoundedRectangle roundedRect, Brush brush ) : void | ||
roundedRect | RoundedRectangle | The dimensions of the rounded rectangle to draw, in device-independent pixels. |
brush | Brush | The brush used to paint the rounded rectangle's outline. |
Résultat | void |
/// <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(Pen pen, Rect rect, float cornerRadius) { using (var brush = CreateBrush(pen.Brush, rect.Size)) using (var d2dStroke = pen.ToDirect2DStrokeStyle(_renderTarget)) { if (brush.PlatformBrush != null) { if (cornerRadius == 0) { _renderTarget.DrawRectangle( rect.ToDirect2D(), brush.PlatformBrush, (float)pen.Thickness, d2dStroke); } else { _renderTarget.DrawRoundedRectangle( new RoundedRectangle { Rect = rect.ToDirect2D(), RadiusX = cornerRadius, RadiusY = cornerRadius }, brush.PlatformBrush, (float)pen.Thickness, d2dStroke); } } } }
/// <summary> /// Draws the given rounded rectangle with the given brush. /// </summary> public void DrawRoundedRectangle(RectangleF rectangle, float radiusX, float radiusY, BrushResource brush, float strokeWidth = 1f) { if (m_renderTarget == null) { return; } rectangle.EnsureNotEmpty(nameof(rectangle)); brush.EnsureNotNull(nameof(brush)); radiusX.EnsurePositive(nameof(radiusX)); radiusY.EnsurePositive(nameof(radiusY)); strokeWidth.EnsurePositive(nameof(strokeWidth)); D2D.RoundedRectangle roundedRect = new D2D.RoundedRectangle(); roundedRect.Rect = rectangle.ToDXRectangle(); roundedRect.RadiusX = radiusX; roundedRect.RadiusY = radiusY; m_renderTarget.DrawRoundedRectangle( roundedRect, brush.GetBrush(m_device), strokeWidth); }
public void DrawRectangle(Rect frame, Size corner, Pen pen = null, Brush brush = null) { var p = GetBrush(pen); var b = GetBrush(frame, brush); if (b != null) { if (corner.Width > 0 || corner.Height > 0) { var rr = new D2D1.RoundedRectangle(); rr.Rect = frame.ToRectangleF(); rr.RadiusX = (float)corner.Width; rr.RadiusY = (float)corner.Height; renderTarget.FillRoundedRectangle(ref rr, b); } else { renderTarget.FillRectangle(frame.ToRectangleF(), b); } } if (p != null) { if (corner.Width > 0 || corner.Height > 0) { var rr = new D2D1.RoundedRectangle(); rr.Rect = frame.ToRectangleF(); rr.RadiusX = (float)corner.Width; rr.RadiusY = (float)corner.Height; renderTarget.DrawRoundedRectangle(ref rr, p, (float)pen.Width, GetStrokeStyle(pen)); } else { renderTarget.DrawRectangle(frame.ToRectangleF(), p, (float)pen.Width, GetStrokeStyle(pen)); } } }