Painterclass

Records 2D drawing commands. Obtained from Painter.Begin() or a panel's OnDraw callback. Copies share drawing state. Dispose a destination-owned painter to submit; panel-supplied painters remain owned by the panel.

objectPainter
Namespace
Sandbox
Assembly
Sandbox.Engine
Declaration
public sealed struct Sandbox.Painter

Methods48

Showing 48 methods

public void Arc(Vector2 center, float radius, float startAngle, float sweepAngle)PUBLIC

Draws an arc using the current `Sandbox.Painter.Stroke` with angles in clockwise degrees from right. Negative sweeps run counterclockwise. Radius measures to the centerline in drawing pixels. Sweeps of at least 360 degrees form a closed ring.

ParameterTypeDescription
centerVector2
radiusfloat
startAnglefloat
sweepAnglefloat
Returns:void

public void Arrow(Vector2 from, Vector2 to, float width = 4, float headSize = 16)PUBLIC

Draws a shafted arrow as one polygon using `Sandbox.Painter.Fill` and `Sandbox.Painter.Stroke`. All dimensions are in drawing pixels. Zero-length arrows or nonpositive shaft/head sizes draw nothing.

ParameterTypeDescription
fromVector2Center of the shaft's starting edge.
toVector2Arrow tip.
width = 4floatShaft width.
headSize = 16floatHead length and width. Length is limited to the arrow's length; width is at least the shaft width.
Returns:void

public Sandbox.Painter.LayerScope BeginLayer(Sandbox.Rect bounds, float opacity = 1, System.Nullable`1<Sandbox.Painter.Filter> filter = null, System.Nullable`1<Sandbox.Painter.Mask> mask = null)PUBLIC

ParameterTypeDescription
boundsRect
opacity = 1float
filter = nullNullable<Filter>
mask = nullNullable<Mask>
Returns:LayerScope

public void Capsule(Vector2 from, Vector2 to, float fromRadius, float toRadius)PUBLIC

Draws the convex hull of two discs using Fill and Stroke. Endpoint radii are in drawing pixels. Equal radii form a capsule; unequal radii taper along common tangents. A contained disc reduces to the larger circle.

ParameterTypeDescription
fromVector2
toVector2
fromRadiusfloat
toRadiusfloat
Returns:void

public void Clear(Color color)PUBLIC

Clears the destination, ignoring drawing state. Supported by texture and command-list painters, outside layers.

ParameterTypeDescription
colorColor
Returns:void

public void Clip(Sandbox.Rect rect, Sandbox.Painter.CornerRadii corners = null)PUBLIC

Intersects subsequent drawing with a rectangle, optionally rounded like Painter.Rect. Captures the current Transform; later transform changes do not move this clip. Nested clips intersect with each other and the panel's CSS clip. Scope() restores the previous clip. Empty rectangles or a collapsed transform clip all drawing.

ParameterTypeDescription
rectRect
corners = nullCornerRadii
Returns:void

public void Crescent(Vector2 center, float radius, float cutoutRadius, Vector2 cutoutOffset)PUBLIC

Draws a circle minus an offset circular cutout using Fill and Stroke. Dimensions and offset are in drawing pixels. Moving the cutout changes the moon's phase and direction. Disjoint circles leave a disc; a covering cutout draws nothing.

ParameterTypeDescription
centerVector2
radiusfloat
cutoutRadiusfloat
cutoutOffsetVector2
Returns:void

public void Cross(Vector2 center, float width, float length)PUBLIC

Draws a plus-shaped cross as one contour using Fill and Stroke, without overlapping bars. Width is the thickness of each bar; length is the full tip-to-tip span on both axes, in drawing pixels. Nonpositive, non-finite dimensions or a width greater than length draw nothing.

ParameterTypeDescription
centerVector2
widthfloat
lengthfloat
Returns:void

public void Dispose()PUBLIC

Submits a destination-owned recording. Copies may be disposed more than once. Panel-supplied painters do not own their recording.

Returns:void

public void FilterBackdrop(Sandbox.Rect rect, Sandbox.Painter.Filter filter, Sandbox.Painter.CornerRadii corners = null)PUBLIC

Filter pixels already drawn behind a rectangle. Captures the current transform, clip, opacity and blend mode.

ParameterTypeDescription
rectRect
filterFilter
corners = nullCornerRadii
Returns:void

public void Heart(Vector2 center, float size)PUBLIC

Draws a heart with two round lobes and a pointed base, using Fill and Stroke. Size is the full width in drawing pixels; its proportions are fixed and its bounds are centered at center.

ParameterTypeDescription
centerVector2
sizefloat
Returns:void

public void LineSmooth(System.ReadOnlySpan`1<Vector2> points)PUBLIC

ParameterTypeDescription
pointsReadOnlySpan<Vector2>
Returns:void

public void Pie(Vector2 center, float radius, float startAngle, float sweepAngle)PUBLIC

Draws a pie sector using `Sandbox.Painter.Fill` and the current `Sandbox.Painter.Stroke`. Angles are clockwise degrees from right; negative sweeps are supported. A full sweep draws a circle without radial seams.

ParameterTypeDescription
centerVector2
radiusfloat
startAnglefloat
sweepAnglefloat
Returns:void

public void Polygon(System.ReadOnlySpan`1<Vector2> points)PUBLIC

ParameterTypeDescription
pointsReadOnlySpan<Vector2>
Returns:void

public void Quad(Vector2 a, Vector2 b, Vector2 c, Vector2 d)PUBLIC

Draws a quad using `Sandbox.Painter.Fill` and the current `Sandbox.Painter.Stroke`. Vertices follow the perimeter in drawing pixels.

ParameterTypeDescription
aVector2
bVector2
cVector2
dVector2
Returns:void

public void RectShadow(Sandbox.Rect rect, Sandbox.Painter.CornerRadii corners = null, System.Nullable`1<Color> color = null, float blur = 0, float spread = 0, Vector2 offset = null, bool inset = False)PUBLIC

ParameterTypeDescription
rectRect
corners = nullCornerRadii
color = nullNullable<Color>
blur = 0float
spread = 0float
offset = nullVector2
inset = Falsebool
Returns:void

public void Rotate(float degrees)PUBLIC

Rotates the drawing axes clockwise in degrees around their current origin.

ParameterTypeDescription
degreesfloat
Returns:void

public void Star(Vector2 center, float bodyRadius, float spikeLength, int points = 5, float rotation = -90)PUBLIC

Draws a star using Fill and Stroke. Body radius measures to the valleys; spike length extends beyond it to the tips, in drawing pixels. Rotation is clockwise degrees from right. At least three points and a positive body radius are required. Zero spike length draws a regular polygon.

ParameterTypeDescription
centerVector2
bodyRadiusfloat
spikeLengthfloat
points = 5int
rotation = -90float
Returns:void

public void Text(string text, Sandbox.Rect rect)PUBLIC

Draws text with the current TextStyle, opacity, transform and clip.

ParameterTypeDescription
textstring
rectRect
Returns:void

public void Texture(Sandbox.Texture texture, Sandbox.Rect rect, System.Nullable`1<Color> tint = null)PUBLIC

ParameterTypeDescription
textureTexture
rectRect
tint = nullNullable<Color>
Returns:void

public void Tick(Vector2 center, float width, float length)PUBLIC

Draws a check mark as one filled contour using Fill and Stroke. Width is the arm thickness; length is the horizontal span of its centerline in drawing pixels. The long arm rises to the right. Nonpositive, non-finite dimensions or a width greater than half the length draw nothing.

ParameterTypeDescription
centerVector2
widthfloat
lengthfloat
Returns:void

Properties7

Showing 7 properties

public Sandbox.BlendMode Sandbox.Painter.BlendMode { get; set; }PUBLICGETSET

Blend mode for subsequent draws. Defaults to BlendMode.Normal.

Returns:BlendMode

public Sandbox.Rect Sandbox.Painter.Bounds { get; set; }PUBLICGETSET

The destination bounds in drawing coordinates. Panel painters start at (0, 0).

Returns:Rect

public Sandbox.Fill Sandbox.Painter.Fill { get; set; }PUBLICGETSET

Fill for closed shapes. Defaults to Fill.None.

Returns:Fill

public float Sandbox.Painter.Opacity { get; set; }PUBLICGETSET

Alpha multiplier for each draw, clamped to [0, 1]. Defaults to 1.

Returns:float

public Sandbox.Stroke Sandbox.Painter.Stroke { get; set; }PUBLICGETSET

Stroke for shapes and lines. Defaults to Stroke.None. Open paths always use centered alignment.

Returns:Stroke

public Matrix Sandbox.Painter.Transform { get; set; }PUBLICGETSET

2D affine transform applied before the destination transform. Defaults to identity.

Returns:Matrix

On this page

Methodspublic System.Void Arc(Vector2 center, System.Single radius, System.Single startAngle, System.Single sweepAngle)public System.Void Arrow(Vector2 from, Vector2 to, System.Single width = 4, System.Single headSize = 16)public static Sandbox.Painter Begin(Sandbox.Rendering.CommandList commandList, Sandbox.Rect bounds)public static Sandbox.Painter Begin(Sandbox.Rendering.CommandList commandList)public static Sandbox.Painter Begin(Sandbox.Texture texture)public Sandbox.Painter.LayerScope BeginLayer(Sandbox.Rect bounds, System.Single opacity = 1, System.Nullable`1<Sandbox.Painter.Filter> filter = null, System.Nullable`1<Sandbox.Painter.Mask> mask = null)public System.Void Bezier(Vector2 from, Vector2 control1, Vector2 control2, Vector2 to)public System.Void Bezier(Vector2 from, Vector2 control, Vector2 to)public System.Void Capsule(Vector2 from, Vector2 to, System.Single fromRadius, System.Single toRadius)public System.Void Circle(Sandbox.Rect rect)public System.Void Circle(Vector2 center, System.Single radius)public System.Void Circle(Vector2 center, Vector2 size)public System.Void Clear(Color color)public System.Void Clip(Sandbox.Rect rect, Sandbox.Painter.CornerRadii corners = null)public System.Void Crescent(Vector2 center, System.Single radius, System.Single cutoutRadius, Vector2 cutoutOffset)public System.Void Cross(Vector2 center, System.Single width, System.Single length)public System.Void Dispose()public System.Void FilterBackdrop(Sandbox.Rect rect, Sandbox.Painter.Filter filter, Sandbox.Painter.CornerRadii corners = null)public System.Void Heart(Vector2 center, System.Single size)public System.Void Line(Line line)public System.Void Line(System.ReadOnlySpan`1<Vector2> points)public System.Void Line(Vector2 from, Vector2 to)public System.Void LineSmooth(System.ReadOnlySpan`1<Vector2> points)public Sandbox.Rect MeasureText(System.String text, Sandbox.Rect rect)public Vector2 MeasureText(System.String text, Vector2 maxSize = null)public System.Void Outline(Sandbox.Rect rect, Sandbox.Painter.CornerRadii corners, System.Single offset = 0)public System.Void Outline(Sandbox.Rect rect, System.Single cornerRadius = 0, System.Single offset = 0)public System.Void Pie(Vector2 center, System.Single radius, System.Single startAngle, System.Single sweepAngle)public System.Void Polygon(System.ReadOnlySpan`1<Vector2> points)public System.Void Quad(Vector2 a, Vector2 b, Vector2 c, Vector2 d)public System.Void Rect(Sandbox.Rect rect, Sandbox.Painter.CornerRadii corners = null)public System.Void Rect(Sandbox.Rect rect, Vector4 borderWidths, Color colorLeft, Color colorTop, Color colorRight, Color colorBottom, Sandbox.Painter.CornerRadii corners = null)public System.Void RectShadow(Sandbox.Rect rect, Sandbox.Painter.CornerRadii corners = null, System.Nullable`1<Color> color = null, System.Single blur = 0, System.Single spread = 0, Vector2 offset = null, System.Boolean inset = False)public System.Void Ring(Vector2 center, System.Single innerRadius, System.Single outerRadius, System.Single startAngle, System.Single sweepAngle)public System.Void Ring(Vector2 center, System.Single innerRadius, System.Single outerRadius)public System.Void Rotate(System.Single degrees)public System.Void Scale(System.Single x, System.Single y)public System.Void Scale(System.Single scale)public System.Void Scale(Vector2 scale)public Sandbox.Painter.StateScope Scope()public System.Void Star(Vector2 center, System.Single bodyRadius, System.Single spikeLength, System.Int32 points = 5, System.Single rotation = -90)public System.Void Text(System.String text, Sandbox.Rect rect)public System.Void Texture(Sandbox.Texture texture, Sandbox.Rect rect, System.Nullable`1<Color> tint = null)public System.Void Tick(Vector2 center, System.Single width, System.Single length)public System.Void Translate(System.Single x, System.Single y)public System.Void Translate(Vector2 offset)public System.Void Triangle(Sandbox.Triangle triangle)public System.Void Triangle(Vector2 a, Vector2 b, Vector2 c)Propertiespublic Sandbox.BlendMode Sandbox.Painter.BlendMode { get; set; }public Sandbox.Rect Sandbox.Painter.Bounds { get; set; }public Sandbox.Fill Sandbox.Painter.Fill { get; set; }public System.Single Sandbox.Painter.Opacity { get; set; }public Sandbox.Stroke Sandbox.Painter.Stroke { get; set; }public Sandbox.TextStyle Sandbox.Painter.TextStyle { get; set; }public Matrix Sandbox.Painter.Transform { get; set; }Metadata