DrawRoundedRectangle() public method

Draws the outline of the specified rounded rectangle.
This method doesn't return an error code if it fails. To determine whether a drawing operation (such as {{DrawRoundedRectangle}}) failed, check the result returned by the M:SharpDX.Direct2D1.RenderTarget.EndDraw(System.Int64@,System.Int64@) or M:SharpDX.Direct2D1.RenderTarget.Flush(System.Int64@,System.Int64@) methods.
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.
return void
Beispiel #1
0
 /// <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);
                 }
             }
         }
 }
Beispiel #2
0
        /// <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));
                }
            }
        }