CanvasItem

Base class of anything 2D.

Canvas items are laid out in a tree; children inherit and extend their parent's transform. CanvasItem is extended by Control for anything GUI-related, and by Node2D for anything related to the 2D engine. Any CanvasItem can draw. For this, update must be called, then constant NOTIFICATION_DRAW will be received on idle time to request 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 the GodotObject._notification, signal or _draw virtual functions. Canvas items are drawn in tree order. 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 also be hidden, which will also hide its children. It provides many ways to change parameters such as modulation (for itself and its children) and self modulation (only for itself), as well as its blend mode. Ultimately, a transform notification can be requested, which will notify the node that its global position changed in case the parent tree changed. Note: Unless otherwise specified, all methods that have angle parameters must have angles specified as radians. To convert degrees to radians, use @GDScript.deg2rad.

@GodotBaseClass
struct CanvasItem {}

Members

Aliases

BaseClasses
alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses)
Undocumented in source.

Enums

BlendMode
enum BlendMode
Constants
enum Constants

Functions

_draw
void _draw()

Overridable function called by the engine (if defined) to draw the canvas item.

_editGetPivot
Vector2 _editGetPivot()
_editGetPosition
Vector2 _editGetPosition()
_editGetRect
Rect2 _editGetRect()
_editGetRotation
double _editGetRotation()
_editGetScale
Vector2 _editGetScale()
_editGetState
Dictionary _editGetState()
_editGetTransform
Transform2D _editGetTransform()
_editSetPivot
void _editSetPivot(Vector2 pivot)
_editSetPosition
void _editSetPosition(Vector2 position)
_editSetRect
void _editSetRect(Rect2 rect)
_editSetRotation
void _editSetRotation(double degrees)
_editSetScale
void _editSetScale(Vector2 scale)
_editSetState
void _editSetState(Dictionary state)
_editUsePivot
bool _editUsePivot()
_editUseRect
bool _editUseRect()
_editUseRotation
bool _editUseRotation()
_isOnTop
bool _isOnTop()
_setOnTop
void _setOnTop(bool on_top)
_toplevelRaiseSelf
void _toplevelRaiseSelf()
_updateCallback
void _updateCallback()
drawArc
void drawArc(Vector2 center, double radius, double start_angle, double end_angle, long point_count, Color color, double width, bool antialiased)

Draws an arc between the given angles. The larger the value of point_count, the smoother the curve.

drawChar
double drawChar(Font font, Vector2 position, String _char, String next, Color modulate)

Draws a string character using a custom font. Returns the advance, depending on the character width and kerning with an optional next character.

drawCircle
void drawCircle(Vector2 position, double radius, Color color)

Draws a colored circle.

drawColoredPolygon
void drawColoredPolygon(PoolVector2Array points, Color color, PoolVector2Array uvs, Texture texture, Texture normal_map, bool antialiased)

Draws a colored polygon of any amount of points, convex or concave.

drawLine
void drawLine(Vector2 from, Vector2 to, Color color, double width, bool antialiased)

Draws a line from a 2D point to another, with a given color and width. It can be optionally antialiased.

drawMesh
void drawMesh(Mesh mesh, Texture texture, Texture normal_map, Transform2D transform, Color modulate)

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

drawMultiline
void drawMultiline(PoolVector2Array points, Color color, double width, bool antialiased)

Draws multiple, parallel lines with a uniform color. Note: width and antialiased are currently not implemented and have no effect.

drawMultilineColors
void drawMultilineColors(PoolVector2Array points, PoolColorArray colors, double width, bool antialiased)

Draws multiple, parallel lines with a uniform width and segment-by-segment coloring. Colors assigned to line segments match by index between points and colors. Note: width and antialiased are currently not implemented and have no effect.

drawMultimesh
void drawMultimesh(MultiMesh multimesh, Texture texture, Texture normal_map)

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

drawPolygon
void drawPolygon(PoolVector2Array points, PoolColorArray colors, PoolVector2Array uvs, Texture texture, Texture normal_map, bool antialiased)

Draws a polygon of any amount of points, convex or concave.

drawPolyline
void drawPolyline(PoolVector2Array points, Color color, double width, bool antialiased)

Draws interconnected line segments with a uniform color and width and optional antialiasing.

drawPolylineColors
void drawPolylineColors(PoolVector2Array points, PoolColorArray colors, double width, bool antialiased)

Draws interconnected line segments with a uniform width, segment-by-segment coloring, and optional antialiasing. Colors assigned to line segments match by index between points and colors.

drawPrimitive
void drawPrimitive(PoolVector2Array points, PoolColorArray colors, PoolVector2Array uvs, Texture texture, double width, Texture normal_map)

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.

drawRect
void drawRect(Rect2 rect, Color color, bool filled, double width, bool antialiased)

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. If antialiased is true, the lines will be antialiased. Note: width and antialiased are only effective if filled is false.

drawSetTransform
void drawSetTransform(Vector2 position, double rotation, Vector2 scale)

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

drawSetTransformMatrix
void drawSetTransformMatrix(Transform2D xform)

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

drawString
void drawString(Font font, Vector2 position, String text, Color modulate, long clip_w)

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

drawStyleBox
void drawStyleBox(StyleBox style_box, Rect2 rect)

Draws a styled rectangle.

drawTexture
void drawTexture(Texture texture, Vector2 position, Color modulate, Texture normal_map)

Draws a texture at a given position.

drawTextureRect
void drawTextureRect(Texture texture, Rect2 rect, bool tile, Color modulate, bool transpose, Texture normal_map)

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.

drawTextureRectRegion
void drawTextureRectRegion(Texture texture, Rect2 rect, Rect2 src_rect, Color modulate, bool transpose, Texture normal_map, bool clip_uv)

Draws a textured rectangle region at a given position, optionally modulated by a color. If transpose is true, the texture will have its X and Y coordinates swapped.

forceUpdateTransform
void 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.

getCanvas
RID getCanvas()

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

getCanvasItem
RID getCanvasItem()

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

getCanvasTransform
Transform2D getCanvasTransform()

Returns the transform matrix of this item's canvas.

getGlobalMousePosition
Vector2 getGlobalMousePosition()

Returns the global position of the mouse.

getGlobalTransform
Transform2D getGlobalTransform()

Returns the global transform matrix of this item.

getGlobalTransformWithCanvas
Transform2D getGlobalTransformWithCanvas()

Returns the global transform matrix of this item in relation to the canvas.

getLightMask
long getLightMask()
getLocalMousePosition
Vector2 getLocalMousePosition()

Returns the mouse position relative to this item's position.

getMaterial
Ref!Material getMaterial()
getModulate
Color getModulate()
getSelfModulate
Color getSelfModulate()
getTransform
Transform2D getTransform()

Returns the transform matrix of this item.

getUseParentMaterial
bool getUseParentMaterial()
getViewportRect
Rect2 getViewportRect()

Returns the viewport's boundaries as a Rect2.

getViewportTransform
Transform2D getViewportTransform()

Returns this item's transform in relation to the viewport.

getWorld2d
Ref!World2D getWorld2d()

Returns the World2D where this item is in.

hide
void hide()

Hide the CanvasItem if it's currently visible.

isDrawBehindParentEnabled
bool isDrawBehindParentEnabled()
isLocalTransformNotificationEnabled
bool isLocalTransformNotificationEnabled()

Returns true if local transform notifications are communicated to children.

isSetAsToplevel
bool isSetAsToplevel()

Returns true if the node is set as top-level. See setAsToplevel.

isTransformNotificationEnabled
bool isTransformNotificationEnabled()

Returns true if global transform notifications are communicated to children.

isVisible
bool isVisible()
isVisibleInTree
bool isVisibleInTree()

Returns true if the node is present in the SceneTree, its visible property is true and all its antecedents are also visible. If any antecedent is hidden, this node will not be visible in the scene tree.

makeCanvasPositionLocal
Vector2 makeCanvasPositionLocal(Vector2 screen_point)

Assigns screen_point as this node's new local transform.

makeInputLocal
Ref!InputEvent makeInputLocal(InputEvent event)

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

opAssign
typeof(null) opAssign(typeof(null) n)
opEquals
bool opEquals(CanvasItem other)
opEquals
bool opEquals(typeof(null) n)
setAsToplevel
void setAsToplevel(bool enable)

If enable is true, the node won't inherit its transform from parent canvas items.

setDrawBehindParent
void setDrawBehindParent(bool enable)
setLightMask
void setLightMask(long light_mask)
setMaterial
void setMaterial(Material material)
setModulate
void setModulate(Color modulate)
setNotifyLocalTransform
void setNotifyLocalTransform(bool enable)

If enable is true, children will be updated with local transform data.

setNotifyTransform
void setNotifyTransform(bool enable)

If enable is true, children will be updated with global transform data.

setSelfModulate
void setSelfModulate(Color self_modulate)
setUseParentMaterial
void setUseParentMaterial(bool enable)
setVisible
void setVisible(bool visible)
show
void show()

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

toHash
size_t toHash()
update
void update()

Queue the CanvasItem for update. constant NOTIFICATION_DRAW will be called on idle time to request redraw.

Mixins

__anonymous
mixin baseCasts
Undocumented in source.

Properties

lightMask
long lightMask [@property getter]
long lightMask [@property setter]

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

modulate
Color modulate [@property getter]
Color modulate [@property setter]

The color applied to textures on this CanvasItem.

selfModulate
Color selfModulate [@property getter]
Color selfModulate [@property setter]

The color applied to textures on this CanvasItem. This is not inherited by children CanvasItems.

showBehindParent
bool showBehindParent [@property getter]
bool showBehindParent [@property setter]

If true, the object draws behind its parent.

showOnTop
bool showOnTop [@property getter]
bool showOnTop [@property setter]

If true, the object draws on top of its parent.

useParentMaterial
bool useParentMaterial [@property getter]
bool useParentMaterial [@property setter]

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

visible
bool visible [@property getter]
bool visible [@property setter]

If true, this CanvasItem is drawn. The node is only visible if all of its antecedents 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.

Static functions

_new
CanvasItem _new()

Construct a new instance of CanvasItem. Note: use memnew!CanvasItem instead.

Static variables

_classBindingInitialized
bool _classBindingInitialized;
Undocumented in source.

Structs

GDNativeClassBinding
struct GDNativeClassBinding
Undocumented in source.

Unions

__anonymous
union __anonymous
Undocumented in source.

Variables

_GODOT_internal_name
enum string _GODOT_internal_name;
Undocumented in source.

Mixed In Members

From mixin baseCasts

as
inout(To) as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
inout(To) as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
inout(ToRef) as()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(ToRef)
Undocumented in source.
opCast
void* opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
godot_object opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
bool opCast()
Undocumented in source. Be warned that the author may not have intended to support it.

Meta