Table of Contents

Class CanvasItem

Namespace
Godot
Assembly
GodotSharp.dll

Abstract base class for everything in 2D space. Canvas items are laid out in a tree; children inherit and extend their parent's transform. CanvasItem is extended by Control for GUI-related nodes, and by Node2D for 2D game objects.

Any CanvasItem can draw. For this, QueueRedraw() is called by the engine, then NotificationDraw will be received on idle time to request a redraw. Because of this, canvas items don't need to be redrawn on every frame, improving the performance significantly. Several functions for drawing on the CanvasItem are provided (see draw_* functions). However, they can only be used inside _Draw(), its corresponding _Notification(int) or methods connected to the Draw signal.

Canvas items are drawn in tree order on their canvas layer. By default, children are on top of their parents, so a root CanvasItem will be drawn behind everything. This behavior can be changed on a per-item basis.

A CanvasItem can be hidden, which will also hide its children. By adjusting various other properties of a CanvasItem, you can also modulate its color (via Modulate or SelfModulate), change its Z-index, blend mode, and more.

public class CanvasItem : Node, IDisposable
Inheritance
CanvasItem
Implements
Derived
Inherited Members

Fields

NotificationDraw

The CanvasItem is requested to draw (see _Draw()).

public const long NotificationDraw = 30

Field Value

long

NotificationEnterCanvas

The CanvasItem has entered the canvas.

public const long NotificationEnterCanvas = 32

Field Value

long

NotificationExitCanvas

The CanvasItem has exited the canvas.

public const long NotificationExitCanvas = 33

Field Value

long

NotificationLocalTransformChanged

The CanvasItem's local transform has changed. This notification is only received if enabled by SetNotifyLocalTransform(bool).

public const long NotificationLocalTransformChanged = 35

Field Value

long

NotificationTransformChanged

The CanvasItem's global transform has changed. This notification is only received if enabled by SetNotifyTransform(bool).

public const long NotificationTransformChanged = 2000

Field Value

long

NotificationVisibilityChanged

The CanvasItem's visibility has changed.

public const long NotificationVisibilityChanged = 31

Field Value

long

NotificationWorld2DChanged

The CanvasItem's active World2D changed.

public const long NotificationWorld2DChanged = 36

Field Value

long

Properties

ClipChildren

Allows the current node to clip child nodes, essentially acting as a mask.

public CanvasItem.ClipChildrenMode ClipChildren { get; set; }

Property Value

CanvasItem.ClipChildrenMode

LightMask

The rendering layers in which this CanvasItem responds to Light2D nodes.

public int LightMask { get; set; }

Property Value

int

Material

The material applied to this CanvasItem.

public Material Material { get; set; }

Property Value

Material

Modulate

The color applied to this CanvasItem. This property does affect child CanvasItems, unlike SelfModulate which only affects the node itself.

public Color Modulate { get; set; }

Property Value

Color

SelfModulate

The color applied to this CanvasItem. This property does not affect child CanvasItems, unlike Modulate which affects both the node itself and its children.

Note: Internal children (e.g. sliders in ColorPicker or tab bar in TabContainer) are also not affected by this property (see include_internal parameter of GetChild(int, bool) and other similar methods).

public Color SelfModulate { get; set; }

Property Value

Color

ShowBehindParent

If true, the object draws behind its parent.

public bool ShowBehindParent { get; set; }

Property Value

bool

TextureFilter

The texture filtering mode to use on this CanvasItem.

public CanvasItem.TextureFilterEnum TextureFilter { get; set; }

Property Value

CanvasItem.TextureFilterEnum

TextureRepeat

The texture repeating mode to use on this CanvasItem.

public CanvasItem.TextureRepeatEnum TextureRepeat { get; set; }

Property Value

CanvasItem.TextureRepeatEnum

TopLevel

If true, this CanvasItem will not inherit its transform from parent CanvasItems. Its draw order will also be changed to make it draw on top of other CanvasItems that do not have TopLevel set to true. The CanvasItem will effectively act as if it was placed as a child of a bare Node.

public bool TopLevel { get; set; }

Property Value

bool

UseParentMaterial

If true, the parent CanvasItem's Material property is used as this one's material.

public bool UseParentMaterial { get; set; }

Property Value

bool

VisibilityLayer

The rendering layer in which this CanvasItem is rendered by Viewport nodes. A Viewport will render a CanvasItem if it and all its parents share a layer with the Viewport's canvas cull mask.

public uint VisibilityLayer { get; set; }

Property Value

uint

Visible

If true, this CanvasItem is drawn. The node is only visible if all of its ancestors are visible as well (in other words, IsVisibleInTree() must return true).

Note: For controls that inherit Popup, the correct way to make them visible is to call one of the multiple popup*() functions instead.

public bool Visible { get; set; }

Property Value

bool

YSortEnabled

If true, child nodes with the lowest Y position are drawn before those with a higher Y position. If false, Y-sorting is disabled. Y-sorting only affects children that inherit from CanvasItem.

You can nest nodes with Y-sorting. Child Y-sorted nodes are sorted in the same space as the parent Y-sort. This feature allows you to organize a scene better or divide it into multiple ones without changing your scene tree.

public bool YSortEnabled { get; set; }

Property Value

bool

ZAsRelative

If true, the node's Z index is relative to its parent's Z index. If this node's Z index is 2 and its parent's effective Z index is 3, then this node's effective Z index will be 2 + 3 = 5.

public bool ZAsRelative { get; set; }

Property Value

bool

ZIndex

Z index. Controls the order in which the nodes render. A node with a higher Z index will display in front of others. Must be between CanvasItemZMin and CanvasItemZMax (inclusive).

Note: Changing the Z index of a Control only affects the drawing order, not the order in which input events are handled. This can be useful to implement certain UI animations, e.g. a menu where hovered items are scaled and should overlap others.

public int ZIndex { get; set; }

Property Value

int

Methods

DrawAnimationSlice(double, double, double, double)

Subsequent drawing commands will be ignored unless they fall within the specified animation slice. This is a faster way to implement animations that loop on background rather than redrawing constantly.

public void DrawAnimationSlice(double animationLength, double sliceBegin, double sliceEnd, double offset = 0)

Parameters

animationLength double
sliceBegin double
sliceEnd double
offset double

DrawArc(Vector2, float, float, float, int, Color, float, bool)

Draws an unfilled arc between the given angles with a uniform color and width and optional antialiasing (supported only for positive width). The larger the value of pointCount, the smoother the curve. See also DrawCircle(Vector2, float, Color).

If width is negative, it will be ignored and the arc will be drawn using LineStrip. This means that when the CanvasItem is scaled, the arc will remain thin. If this behavior is not desired, then pass a positive width like 1.0.

The arc is drawn from startAngle towards the value of endAngle so in clockwise direction if start_angle < end_angle and counter-clockwise otherwise. Passing the same angles but in reversed order will produce the same arc. If absolute difference of startAngle and endAngle is greater than @GDScript.TAU radians, then a full circle arc is drawn (i.e. arc will not overlap itself).

public void DrawArc(Vector2 center, float radius, float startAngle, float endAngle, int pointCount, Color color, float width = -1, bool antialiased = false)

Parameters

center Vector2
radius float
startAngle float
endAngle float
pointCount int
color Color
width float
antialiased bool

DrawChar(Font, Vector2, string, int, Color?)

Draws a string first character using a custom font.

public void DrawChar(Font font, Vector2 pos, string @char, int fontSize = 16, Color? modulate = null)

Parameters

font Font
pos Vector2
char string
fontSize int
modulate Color?

If the parameter is null, then the default value is new Color(1, 1, 1, 1).

DrawCharOutline(Font, Vector2, string, int, int, Color?)

Draws a string first character outline using a custom font.

public void DrawCharOutline(Font font, Vector2 pos, string @char, int fontSize = 16, int size = -1, Color? modulate = null)

Parameters

font Font
pos Vector2
char string
fontSize int
size int
modulate Color?

If the parameter is null, then the default value is new Color(1, 1, 1, 1).

DrawCircle(Vector2, float, Color)

public void DrawCircle(Vector2 position, float radius, Color color)

Parameters

position Vector2
radius float
color Color

DrawColoredPolygon(Vector2[], Color, Vector2[], Texture2D)

Draws a colored polygon of any number of points, convex or concave. Unlike DrawPolygon(Vector2[], Color[], Vector2[], Texture2D), a single color must be specified for the whole polygon.

public void DrawColoredPolygon(Vector2[] points, Color color, Vector2[] uvs = null, Texture2D texture = null)

Parameters

points Vector2[]
color Color
uvs Vector2[]

If the parameter is null, then the default value is Array.Empty<Vector2>().

texture Texture2D

DrawDashedLine(Vector2, Vector2, Color, float, float, bool)

Draws a dashed line from a 2D point to another, with a given color and width. See also DrawMultiline(Vector2[], Color, float) and DrawPolyline(Vector2[], Color, float, bool).

If width is negative, then a two-point primitives will be drawn instead of a four-point ones. This means that when the CanvasItem is scaled, the line parts will remain thin. If this behavior is not desired, then pass a positive width like 1.0.

public void DrawDashedLine(Vector2 from, Vector2 to, Color color, float width = -1, float dash = 2, bool aligned = true)

Parameters

from Vector2
to Vector2
color Color
width float
dash float
aligned bool

DrawEndAnimation()

After submitting all animations slices via DrawAnimationSlice(double, double, double, double), this function can be used to revert drawing to its default state (all subsequent drawing commands will be visible). If you don't care about this particular use case, usage of this function after submitting the slices is not required.

public void DrawEndAnimation()

DrawLcdTextureRectRegion(Texture2D, Rect2, Rect2, Color?)

Draws a textured rectangle region of the font texture with LCD subpixel anti-aliasing at a given position, optionally modulated by a color.

Texture is drawn using the following blend operation, blend mode of the CanvasItemMaterial is ignored:

dst.r = texture.r * modulate.r * modulate.a + dst.r * (1.0 - texture.r * modulate.a);
  dst.g = texture.g * modulate.g * modulate.a + dst.g * (1.0 - texture.g * modulate.a);
  dst.b = texture.b * modulate.b * modulate.a + dst.b * (1.0 - texture.b * modulate.a);
  dst.a = modulate.a + dst.a * (1.0 - modulate.a);
public void DrawLcdTextureRectRegion(Texture2D texture, Rect2 rect, Rect2 srcRect, Color? modulate = null)

Parameters

texture Texture2D
rect Rect2
srcRect Rect2
modulate Color?

If the parameter is null, then the default value is new Color(1, 1, 1, 1).

DrawLine(Vector2, Vector2, Color, float, bool)

Draws a line from a 2D point to another, with a given color and width. It can be optionally antialiased. See also DrawMultiline(Vector2[], Color, float) and DrawPolyline(Vector2[], Color, float, bool).

If width is negative, then a two-point primitive will be drawn instead of a four-point one. This means that when the CanvasItem is scaled, the line will remain thin. If this behavior is not desired, then pass a positive width like 1.0.

public void DrawLine(Vector2 from, Vector2 to, Color color, float width = -1, bool antialiased = false)

Parameters

from Vector2
to Vector2
color Color
width float
antialiased bool

DrawMesh(Mesh, Texture2D, Transform2D?, Color?)

Draws a Mesh in 2D, using the provided texture. See MeshInstance2D for related documentation.

public void DrawMesh(Mesh mesh, Texture2D texture, Transform2D? transform = null, Color? modulate = null)

Parameters

mesh Mesh
texture Texture2D
transform Transform2D?

If the parameter is null, then the default value is Transform2D.Identity.

modulate Color?

If the parameter is null, then the default value is new Color(1, 1, 1, 1).

DrawMsdfTextureRectRegion(Texture2D, Rect2, Rect2, Color?, double, double, double)

Draws a textured rectangle region of the multi-channel signed distance field texture at a given position, optionally modulated by a color. See MultichannelSignedDistanceField for more information and caveats about MSDF font rendering.

If outline is positive, each alpha channel value of pixel in region is set to maximum value of true distance in the outline radius.

Value of the pixelRange should the same that was used during distance field texture generation.

public void DrawMsdfTextureRectRegion(Texture2D texture, Rect2 rect, Rect2 srcRect, Color? modulate = null, double outline = 0, double pixelRange = 4, double scale = 1)

Parameters

texture Texture2D
rect Rect2
srcRect Rect2
modulate Color?

If the parameter is null, then the default value is new Color(1, 1, 1, 1).

outline double
pixelRange double
scale double

DrawMultiline(Vector2[], Color, float)

Draws multiple disconnected lines with a uniform width and color. Each line is defined by two consecutive points from points array, i.e. i-th segment consists of points[2 * i], points[2 * i + 1] endpoints. When drawing large amounts of lines, this is faster than using individual DrawLine(Vector2, Vector2, Color, float, bool) calls. To draw interconnected lines, use DrawPolyline(Vector2[], Color, float, bool) instead.

If width is negative, then two-point primitives will be drawn instead of a four-point ones. This means that when the CanvasItem is scaled, the lines will remain thin. If this behavior is not desired, then pass a positive width like 1.0.

public void DrawMultiline(Vector2[] points, Color color, float width = -1)

Parameters

points Vector2[]
color Color
width float

DrawMultilineColors(Vector2[], Color[], float)

Draws multiple disconnected lines with a uniform width and segment-by-segment coloring. Each segment is defined by two consecutive points from points array and a corresponding color from colors array, i.e. i-th segment consists of points[2 * i], points[2 * i + 1] endpoints and has colors[i] color. When drawing large amounts of lines, this is faster than using individual DrawLine(Vector2, Vector2, Color, float, bool) calls. To draw interconnected lines, use DrawPolylineColors(Vector2[], Color[], float, bool) instead.

If width is negative, then two-point primitives will be drawn instead of a four-point ones. This means that when the CanvasItem is scaled, the lines will remain thin. If this behavior is not desired, then pass a positive width like 1.0.

public void DrawMultilineColors(Vector2[] points, Color[] colors, float width = -1)

Parameters

points Vector2[]
colors Color[]
width float

DrawMultilineString(Font, Vector2, string, HorizontalAlignment, float, int, int, Color?, LineBreakFlag, JustificationFlag, Direction, Orientation)

Breaks text into lines and draws it using the specified font at the pos (top-left corner). The text will have its color multiplied by modulate. If width is greater than or equal to 0, the text will be clipped if it exceeds the specified width.

public void DrawMultilineString(Font font, Vector2 pos, string text, HorizontalAlignment alignment = HorizontalAlignment.Left, float width = -1, int fontSize = 16, int maxLines = -1, Color? modulate = null, TextServer.LineBreakFlag brkFlags = LineBreakFlag.Mandatory | LineBreakFlag.WordBound, TextServer.JustificationFlag justificationFlags = JustificationFlag.Kashida | JustificationFlag.WordBound, TextServer.Direction direction = Direction.Auto, TextServer.Orientation orientation = Orientation.Horizontal)

Parameters

font Font
pos Vector2
text string
alignment HorizontalAlignment
width float
fontSize int
maxLines int
modulate Color?

If the parameter is null, then the default value is new Color(1, 1, 1, 1).

brkFlags TextServer.LineBreakFlag
justificationFlags TextServer.JustificationFlag
direction TextServer.Direction
orientation TextServer.Orientation

DrawMultilineStringOutline(Font, Vector2, string, HorizontalAlignment, float, int, int, int, Color?, LineBreakFlag, JustificationFlag, Direction, Orientation)

Breaks text to the lines and draws text outline using the specified font at the pos (top-left corner). The text will have its color multiplied by modulate. If width is greater than or equal to 0, the text will be clipped if it exceeds the specified width.

public void DrawMultilineStringOutline(Font font, Vector2 pos, string text, HorizontalAlignment alignment = HorizontalAlignment.Left, float width = -1, int fontSize = 16, int maxLines = -1, int size = 1, Color? modulate = null, TextServer.LineBreakFlag brkFlags = LineBreakFlag.Mandatory | LineBreakFlag.WordBound, TextServer.JustificationFlag justificationFlags = JustificationFlag.Kashida | JustificationFlag.WordBound, TextServer.Direction direction = Direction.Auto, TextServer.Orientation orientation = Orientation.Horizontal)

Parameters

font Font
pos Vector2
text string
alignment HorizontalAlignment
width float
fontSize int
maxLines int
size int
modulate Color?

If the parameter is null, then the default value is new Color(1, 1, 1, 1).

brkFlags TextServer.LineBreakFlag
justificationFlags TextServer.JustificationFlag
direction TextServer.Direction
orientation TextServer.Orientation

DrawMultimesh(MultiMesh, Texture2D)

Draws a MultiMesh in 2D with the provided texture. See MultiMeshInstance2D for related documentation.

public void DrawMultimesh(MultiMesh multimesh, Texture2D texture)

Parameters

multimesh MultiMesh
texture Texture2D

DrawPolygon(Vector2[], Color[], Vector2[], Texture2D)

Draws a solid polygon of any number of points, convex or concave. Unlike DrawColoredPolygon(Vector2[], Color, Vector2[], Texture2D), each point's color can be changed individually. See also DrawPolyline(Vector2[], Color, float, bool) and DrawPolylineColors(Vector2[], Color[], float, bool). If you need more flexibility (such as being able to use bones), use CanvasItemAddTriangleArray(Rid, int[], Vector2[], Color[], Vector2[], int[], float[], Rid, int) instead.

public void DrawPolygon(Vector2[] points, Color[] colors, Vector2[] uvs = null, Texture2D texture = null)

Parameters

points Vector2[]
colors Color[]
uvs Vector2[]

If the parameter is null, then the default value is Array.Empty<Vector2>().

texture Texture2D

DrawPolyline(Vector2[], Color, float, bool)

Draws interconnected line segments with a uniform color and width and optional antialiasing (supported only for positive width). When drawing large amounts of lines, this is faster than using individual DrawLine(Vector2, Vector2, Color, float, bool) calls. To draw disconnected lines, use DrawMultiline(Vector2[], Color, float) instead. See also DrawPolygon(Vector2[], Color[], Vector2[], Texture2D).

If width is negative, it will be ignored and the polyline will be drawn using LineStrip. This means that when the CanvasItem is scaled, the polyline will remain thin. If this behavior is not desired, then pass a positive width like 1.0.

public void DrawPolyline(Vector2[] points, Color color, float width = -1, bool antialiased = false)

Parameters

points Vector2[]
color Color
width float
antialiased bool

DrawPolylineColors(Vector2[], Color[], float, bool)

Draws interconnected line segments with a uniform width, point-by-point coloring, and optional antialiasing (supported only for positive width). Colors assigned to line points match by index between points and colors, i.e. each line segment is filled with a gradient between the colors of the endpoints. When drawing large amounts of lines, this is faster than using individual DrawLine(Vector2, Vector2, Color, float, bool) calls. To draw disconnected lines, use DrawMultilineColors(Vector2[], Color[], float) instead. See also DrawPolygon(Vector2[], Color[], Vector2[], Texture2D).

If width is negative, it will be ignored and the polyline will be drawn using LineStrip. This means that when the CanvasItem is scaled, the polyline will remain thin. If this behavior is not desired, then pass a positive width like 1.0.

public void DrawPolylineColors(Vector2[] points, Color[] colors, float width = -1, bool antialiased = false)

Parameters

points Vector2[]
colors Color[]
width float
antialiased bool

DrawPrimitive(Vector2[], Color[], Vector2[], Texture2D)

Draws a custom primitive. 1 point for a point, 2 points for a line, 3 points for a triangle, and 4 points for a quad. If 0 points or more than 4 points are specified, nothing will be drawn and an error message will be printed. See also DrawLine(Vector2, Vector2, Color, float, bool), DrawPolyline(Vector2[], Color, float, bool), DrawPolygon(Vector2[], Color[], Vector2[], Texture2D), and DrawRect(Rect2, Color, bool, float).

public void DrawPrimitive(Vector2[] points, Color[] colors, Vector2[] uvs, Texture2D texture = null)

Parameters

points Vector2[]
colors Color[]
uvs Vector2[]
texture Texture2D

DrawRect(Rect2, Color, bool, float)

Draws a rectangle. If filled is true, the rectangle will be filled with the color specified. If filled is false, the rectangle will be drawn as a stroke with the color and width specified. See also DrawTextureRect(Texture2D, Rect2, bool, Color?, bool).

If width is negative, then two-point primitives will be drawn instead of a four-point ones. This means that when the CanvasItem is scaled, the lines will remain thin. If this behavior is not desired, then pass a positive width like 1.0.

Note: width is only effective if filled is false.

Note: Unfilled rectangles drawn with a negative width may not display perfectly. For example, corners may be missing or brighter due to overlapping lines (for a translucent color).

public void DrawRect(Rect2 rect, Color color, bool filled = true, float width = -1)

Parameters

rect Rect2
color Color
filled bool
width float

DrawSetTransform(Vector2, float, Vector2?)

Sets a custom transform for drawing via components. Anything drawn afterwards will be transformed by this.

Note: Oversampling does not take scale into account. This means that scaling up/down will cause bitmap fonts and rasterized (non-MSDF) dynamic fonts to appear blurry or pixelated. To ensure text remains crisp regardless of scale, you can enable MSDF font rendering by enabling ProjectSettings.gui/theme/default_font_multichannel_signed_distance_field (applies to the default project font only), or enabling Multichannel Signed Distance Field in the import options of a DynamicFont for custom fonts. On system fonts, MultichannelSignedDistanceField can be enabled in the inspector.

public void DrawSetTransform(Vector2 position, float rotation = 0, Vector2? scale = null)

Parameters

position Vector2
rotation float
scale Vector2?

If the parameter is null, then the default value is new Vector2(1, 1).

DrawSetTransformMatrix(Transform2D)

Sets a custom transform for drawing via matrix. Anything drawn afterwards will be transformed by this.

public void DrawSetTransformMatrix(Transform2D xform)

Parameters

xform Transform2D

DrawString(Font, Vector2, string, HorizontalAlignment, float, int, Color?, JustificationFlag, Direction, Orientation)

Draws text using the specified font at the pos (bottom-left corner using the baseline of the font). The text will have its color multiplied by modulate. If width is greater than or equal to 0, the text will be clipped if it exceeds the specified width.

Example using the default project font:

// If using this method in a script that redraws constantly, move the
  // `default_font` declaration to a member variable assigned in `_Ready()`
  // so the Control is only created once.
  Font defaultFont = ThemeDB.FallbackFont;
  int defaultFontSize = ThemeDB.FallbackFontSize;
  DrawString(defaultFont, new Vector2(64, 64), "Hello world", HORIZONTAL_ALIGNMENT_LEFT, -1, defaultFontSize);

See also DrawString(Rid, Vector2, string, HorizontalAlignment, float, int, Color?, JustificationFlag, Direction, Orientation).

public void DrawString(Font font, Vector2 pos, string text, HorizontalAlignment alignment = HorizontalAlignment.Left, float width = -1, int fontSize = 16, Color? modulate = null, TextServer.JustificationFlag justificationFlags = JustificationFlag.Kashida | JustificationFlag.WordBound, TextServer.Direction direction = Direction.Auto, TextServer.Orientation orientation = Orientation.Horizontal)

Parameters

font Font
pos Vector2
text string
alignment HorizontalAlignment
width float
fontSize int
modulate Color?

If the parameter is null, then the default value is new Color(1, 1, 1, 1).

justificationFlags TextServer.JustificationFlag
direction TextServer.Direction
orientation TextServer.Orientation

DrawStringOutline(Font, Vector2, string, HorizontalAlignment, float, int, int, Color?, JustificationFlag, Direction, Orientation)

Draws text outline using the specified font at the pos (bottom-left corner using the baseline of the font). The text will have its color multiplied by modulate. If width is greater than or equal to 0, the text will be clipped if it exceeds the specified width.

public void DrawStringOutline(Font font, Vector2 pos, string text, HorizontalAlignment alignment = HorizontalAlignment.Left, float width = -1, int fontSize = 16, int size = 1, Color? modulate = null, TextServer.JustificationFlag justificationFlags = JustificationFlag.Kashida | JustificationFlag.WordBound, TextServer.Direction direction = Direction.Auto, TextServer.Orientation orientation = Orientation.Horizontal)

Parameters

font Font
pos Vector2
text string
alignment HorizontalAlignment
width float
fontSize int
size int
modulate Color?

If the parameter is null, then the default value is new Color(1, 1, 1, 1).

justificationFlags TextServer.JustificationFlag
direction TextServer.Direction
orientation TextServer.Orientation

DrawStyleBox(StyleBox, Rect2)

Draws a styled rectangle.

public void DrawStyleBox(StyleBox styleBox, Rect2 rect)

Parameters

styleBox StyleBox
rect Rect2

DrawTexture(Texture2D, Vector2, Color?)

Draws a texture at a given position.

public void DrawTexture(Texture2D texture, Vector2 position, Color? modulate = null)

Parameters

texture Texture2D
position Vector2
modulate Color?

If the parameter is null, then the default value is new Color(1, 1, 1, 1).

DrawTextureRect(Texture2D, Rect2, bool, Color?, bool)

Draws a textured rectangle at a given position, optionally modulated by a color. If transpose is true, the texture will have its X and Y coordinates swapped. See also DrawRect(Rect2, Color, bool, float) and DrawTextureRectRegion(Texture2D, Rect2, Rect2, Color?, bool, bool).

public void DrawTextureRect(Texture2D texture, Rect2 rect, bool tile, Color? modulate = null, bool transpose = false)

Parameters

texture Texture2D
rect Rect2
tile bool
modulate Color?

If the parameter is null, then the default value is new Color(1, 1, 1, 1).

transpose bool

DrawTextureRectRegion(Texture2D, Rect2, Rect2, Color?, bool, bool)

Draws a textured rectangle from a texture's region (specified by srcRect) at a given position, optionally modulated by a color. If transpose is true, the texture will have its X and Y coordinates swapped. See also DrawTextureRect(Texture2D, Rect2, bool, Color?, bool).

public void DrawTextureRectRegion(Texture2D texture, Rect2 rect, Rect2 srcRect, Color? modulate = null, bool transpose = false, bool clipUV = true)

Parameters

texture Texture2D
rect Rect2
srcRect Rect2
modulate Color?

If the parameter is null, then the default value is new Color(1, 1, 1, 1).

transpose bool
clipUV bool

ForceUpdateTransform()

Forces the transform to update. Transform changes in physics are not instant for performance reasons. Transforms are accumulated and then set. Use this if you need an up-to-date transform when doing physics operations.

public void ForceUpdateTransform()

GetCanvas()

Returns the Rid of the World2D canvas where this item is in.

public Rid GetCanvas()

Returns

Rid

GetCanvasItem()

Returns the canvas item RID used by RenderingServer for this item.

public Rid GetCanvasItem()

Returns

Rid

GetCanvasTransform()

Returns the transform from the coordinate system of the canvas, this item is in, to the Viewports coordinate system.

public Transform2D GetCanvasTransform()

Returns

Transform2D

GetGlobalMousePosition()

Returns the mouse's position in the CanvasLayer that this CanvasItem is in using the coordinate system of the CanvasLayer.

Note: For screen-space coordinates (e.g. when using a non-embedded Popup), you can use MouseGetPosition().

public Vector2 GetGlobalMousePosition()

Returns

Vector2

GetGlobalTransform()

Returns the global transform matrix of this item, i.e. the combined transform up to the topmost CanvasItem node. The topmost item is a CanvasItem that either has no parent, has non-CanvasItem parent or it has TopLevel enabled.

public Transform2D GetGlobalTransform()

Returns

Transform2D

GetGlobalTransformWithCanvas()

Returns the transform from the local coordinate system of this CanvasItem to the Viewports coordinate system.

public Transform2D GetGlobalTransformWithCanvas()

Returns

Transform2D

GetLocalMousePosition()

Returns the mouse's position in this CanvasItem using the local coordinate system of this CanvasItem.

public Vector2 GetLocalMousePosition()

Returns

Vector2

GetScreenTransform()

Returns the transform of this CanvasItem in global screen coordinates (i.e. taking window position into account). Mostly useful for editor plugins.

Equals to GetGlobalTransform() if the window is embedded (see GuiEmbedSubwindows).

public Transform2D GetScreenTransform()

Returns

Transform2D

GetTransform()

Returns the transform matrix of this item.

public Transform2D GetTransform()

Returns

Transform2D

GetViewportRect()

Returns the viewport's boundaries as a Rect2.

public Rect2 GetViewportRect()

Returns

Rect2

GetViewportTransform()

Returns the transform from the coordinate system of the canvas, this item is in, to the Viewports embedders coordinate system.

public Transform2D GetViewportTransform()

Returns

Transform2D

GetVisibilityLayerBit(uint)

Returns an individual bit on the rendering visibility layer.

public bool GetVisibilityLayerBit(uint layer)

Parameters

layer uint

Returns

bool

GetWorld2D()

Returns the World2D where this item is in.

public World2D GetWorld2D()

Returns

World2D

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

Hide()

Hide the CanvasItem if it's currently visible. This is equivalent to setting Visible to false.

public void Hide()

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

IsLocalTransformNotificationEnabled()

Returns true if local transform notifications are communicated to children.

public bool IsLocalTransformNotificationEnabled()

Returns

bool

IsTransformNotificationEnabled()

Returns true if global transform notifications are communicated to children.

public bool IsTransformNotificationEnabled()

Returns

bool

IsVisibleInTree()

Returns true if the node is present in the SceneTree, its Visible property is true and all its ancestors are also visible. If any ancestor is hidden, this node will not be visible in the scene tree, and is therefore not drawn (see _Draw()).

public bool IsVisibleInTree()

Returns

bool

MakeCanvasPositionLocal(Vector2)

Assigns screenPoint as this node's new local transform.

public Vector2 MakeCanvasPositionLocal(Vector2 screenPoint)

Parameters

screenPoint Vector2

Returns

Vector2

MakeInputLocal(InputEvent)

Transformations issued by event's inputs are applied in local space instead of global space.

public InputEvent MakeInputLocal(InputEvent @event)

Parameters

event InputEvent

Returns

InputEvent

MoveToFront()

Moves this node to display on top of its siblings.

Internally, the node is moved to the bottom of parent's child list. The method has no effect on nodes without a parent.

public void MoveToFront()

QueueRedraw()

Queues the CanvasItem to redraw. During idle time, if CanvasItem is visible, NotificationDraw is sent and _Draw() is called. This only occurs once per frame, even if this method has been called multiple times.

public void QueueRedraw()

SetNotifyLocalTransform(bool)

If enable is true, this node will receive NotificationLocalTransformChanged when its local transform changes.

public void SetNotifyLocalTransform(bool enable)

Parameters

enable bool

SetNotifyTransform(bool)

If enable is true, this node will receive NotificationTransformChanged when its global transform changes.

public void SetNotifyTransform(bool enable)

Parameters

enable bool

SetVisibilityLayerBit(uint, bool)

Set/clear individual bits on the rendering visibility layer. This simplifies editing this CanvasItem's visibility layer.

public void SetVisibilityLayerBit(uint layer, bool enabled)

Parameters

layer uint
enabled bool

Show()

Show the CanvasItem if it's currently hidden. This is equivalent to setting Visible to true. For controls that inherit Popup, the correct way to make them visible is to call one of the multiple popup*() functions instead.

public void Show()

_Draw()

Called when CanvasItem has been requested to redraw (after QueueRedraw() is called, either manually or by the engine).

Corresponds to the NotificationDraw notification in _Notification(int).

public virtual void _Draw()

Events

Draw

Emitted when the CanvasItem must redraw, after the related NotificationDraw notification, and before_Draw() is called.

Note: Deferred connections do not allow drawing through the draw_* methods.

public event Action Draw

Event Type

Action

Hidden

Emitted when becoming hidden.

public event Action Hidden

Event Type

Action

ItemRectChanged

Emitted when the item's Rect2 boundaries (position or size) have changed, or when an action is taking place that may have impacted these boundaries (e.g. changing Texture).

public event Action ItemRectChanged

Event Type

Action

VisibilityChanged

Emitted when the visibility (hidden/visible) changes.

public event Action VisibilityChanged

Event Type

Action