Description
The DrawRoundedRectangle
method is a static function within the Sandbox.Graphics
class. It is used to render a rectangle with rounded corners on the screen. This method allows you to specify the rectangle's dimensions, color, corner radius, border width, and border color, providing a flexible way to draw UI elements or other graphical components with rounded edges.
Usage
To use the DrawRoundedRectangle
method, you need to provide the following parameters:
rect
: A reference to a Sandbox.Rect
structure that defines the position and size of the rectangle.
color
: A reference to a Color
structure that specifies the fill color of the rectangle.
cornerRadius
: A reference to a Vector4
structure that defines the radius of each corner of the rectangle. Each component of the vector corresponds to a corner, allowing for different radii for each corner.
borderWidth
: A reference to a Vector4
structure that specifies the width of the border for each side of the rectangle.
borderColor
: A reference to a Color
structure that defines the color of the rectangle's border.
Ensure that the Sandbox.Graphics
class is active and the rendering context is properly set up before calling this method.
Example
// Example of using DrawRoundedRectangle
// Define the rectangle's position and size
Rect rect = new Rect(10, 10, 200, 100);
// Define the fill color
Color fillColor = new Color(0.5f, 0.5f, 0.5f, 1.0f); // Gray color
// Define the corner radius for each corner
Vector4 cornerRadius = new Vector4(10, 10, 10, 10); // 10 units radius for all corners
// Define the border width for each side
Vector4 borderWidth = new Vector4(2, 2, 2, 2); // 2 units width for all sides
// Define the border color
Color borderColor = new Color(0, 0, 0, 1.0f); // Black color
// Draw the rounded rectangle
Graphics.DrawRoundedRectangle(ref rect, ref fillColor, ref cornerRadius, ref borderWidth, ref borderColor);