Description
The DrawText
method in the Sandbox.Graphics
class is used to render text onto the screen. This method allows you to specify various parameters such as the position, text content, color, font family, font size, font weight, and text flags to customize the appearance and behavior of the text being drawn.
Usage
To use the DrawText
method, you need to provide the following parameters:
position
: A reference to a Sandbox.Rect
that defines the position and size of the text area.
text
: A string
representing the text content to be drawn.
color
: A Color
object specifying the color of the text.
fontFamily
: A string
indicating the font family to be used for the text.
fontSize
: A float
value that sets the size of the font.
fontWeight
: A float
value that determines the weight (thickness) of the font.
flags
: A Sandbox.TextFlag
enumeration value that specifies additional text rendering options, such as alignment and wrapping.
The method returns a Sandbox.Rect
that represents the area occupied by the drawn text.
Example
// Example of using DrawText to render text on the screen
Sandbox.Rect textPosition = new Sandbox.Rect(10, 10, 200, 50);
string textContent = "Hello, Sandbox!";
Color textColor = Color.White;
string fontFamily = "Arial";
float fontSize = 16.0f;
float fontWeight = 400.0f; // Normal weight
Sandbox.TextFlag textFlags = Sandbox.TextFlag.Left | Sandbox.TextFlag.Top;
Sandbox.Rect resultRect = Sandbox.Graphics.DrawText(
ref textPosition,
textContent,
textColor,
fontFamily,
fontSize,
fontWeight,
textFlags
);
// The resultRect contains the area occupied by the text.