Description
The DrawRect
method in the HudPainter
struct is used to draw a rectangle on the HUD (Heads-Up Display) with specified properties such as color, corner radius, border width, and border color. This method is part of the Sandbox.Rendering
namespace and is designed to provide a flexible way to render rectangles with customizable appearance.
Usage
To use the DrawRect
method, you need to provide the following parameters:
rect
: A reference to a 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 the corners of the rectangle. Each component of the vector corresponds to a corner of the rectangle.
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 border.
Ensure that the HudPainter
instance is properly initialized before calling this method.
Example
// Example usage of HudPainter.DrawRect
// Create a HudPainter instance
HudPainter hudPainter = new HudPainter();
// Define the rectangle properties
Rect rect = new Rect(10, 10, 100, 50);
Color fillColor = new Color(1.0f, 0.0f, 0.0f, 1.0f); // Red color
Vector4 cornerRadius = new Vector4(5, 5, 5, 5); // Rounded corners
Vector4 borderWidth = new Vector4(2, 2, 2, 2); // Border width
Color borderColor = new Color(0.0f, 0.0f, 0.0f, 1.0f); // Black border
// Draw the rectangle
hudPainter.DrawRect(ref rect, ref fillColor, ref cornerRadius, ref borderWidth, ref borderColor);