FillRoundedRectangle() public méthode

Paints the interior of the specified rounded rectangle.
This method doesn't return an error code if it fails. To determine whether a drawing operation (such as {{FillRoundedRectangle}}) 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 FillRoundedRectangle ( RoundedRectangle roundedRect, Brush brush ) : void
roundedRect RoundedRectangle The dimensions of the rounded rectangle to paint, in device-independent pixels.
brush Brush The brush used to paint the interior of the rounded rectangle.
Résultat void
Exemple #1
0
 /// <summary>
 /// Draws a filled rectangle.
 /// </summary>
 /// <param name="brush">The brush.</param>
 /// <param name="rect">The rectangle bounds.</param>
 /// <param name="cornerRadius">The corner radius.</param>
 public void FillRectangle(IBrush brush, Rect rect, float cornerRadius)
 {
     using (var b = CreateBrush(brush, rect.Size))
     {
         if (b.PlatformBrush != null)
         {
             if (cornerRadius == 0)
             {
                 _renderTarget.FillRectangle(rect.ToDirect2D(), b.PlatformBrush);
             }
             else
             {
                 _renderTarget.FillRoundedRectangle(
                     new RoundedRectangle
                 {
                     Rect = new RawRectangleF(
                         (float)rect.X,
                         (float)rect.Y,
                         (float)rect.Right,
                         (float)rect.Bottom),
                     RadiusX = cornerRadius,
                     RadiusY = cornerRadius
                 },
                     b.PlatformBrush);
             }
         }
     }
 }
        /// <summary>
        /// Fills the given rectangle with the given brush object.
        /// </summary>
        /// <param name="radiusX">The x radius of the rectangle's corners.</param>
        /// <param name="radiusY">The y radius of the rectangle's corners.</param>
        /// <param name="rectangle">The rectangle to be filled.</param>
        /// <param name="brush">The brush to be used.</param>
        public void FillRoundedRectangle(RectangleF rectangle, float radiusX, float radiusY, BrushResource brush)
        {
            if (m_renderTarget == null)
            {
                return;
            }

            rectangle.EnsureNotEmpty(nameof(rectangle));
            brush.EnsureNotNull(nameof(brush));
            radiusX.EnsurePositive(nameof(radiusX));
            radiusY.EnsurePositive(nameof(radiusY));

            D2D.RoundedRectangle roundedRect = new D2D.RoundedRectangle();
            roundedRect.Rect    = rectangle.ToDXRectangle();
            roundedRect.RadiusX = radiusX;
            roundedRect.RadiusY = radiusY;

            m_renderTarget.FillRoundedRectangle(
                roundedRect,
                brush.GetBrush(m_device));
        }
        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));
                }
            }
        }
Exemple #4
0
        public void OnRender(RenderTarget target)
        {
            if (mImage == null)
                return;

            target.DrawBitmap(mImage, mTargetRectangle, 1.0f, BitmapInterpolationMode.Linear, mSourceRectangle);
            if (mIndexLocation == 0)
            {
                target.FillRoundedRectangle(new RoundedRectangle
                {
                    RadiusX = 5,
                    RadiusY = 5,
                    Rect = new RectangleF(Position.X + 5, Position.Y + 2, mIndexDraw.GetLayout().Metrics.Width + 10, mIndexDraw.GetLayout().Metrics.Height + 4)
                }, Brushes.Solid[0xDD555555]);
            }
            else
            {
                target.FillRoundedRectangle(new RoundedRectangle
                {
                    RadiusX = 5,
                    RadiusY = 5,
                    Rect = new RectangleF(Position.X + mTargetRectangle.Width - mIndexDraw.GetLayout().Metrics.Width - 15, Position.Y + 2, mIndexDraw.GetLayout().Metrics.Width + 10, mIndexDraw.GetLayout().Metrics.Height + 4)
                }, Brushes.Solid[0xDD555555]);
            }

            target.DrawTextLayout(new Vector2(mPosition.X + 10, mPosition.Y + 5), mIndexDraw, Brushes.White);
        }