CanvasItem

Base class of anything 2D.

Canvas items are laid out in a tree and children inherit and extend the transform of their parent. CanvasItem is extended by Control, for anything GUI related, and by Node2D for anything 2D engine related. Any CanvasItem can draw. For this, the "update" function must be called, then NOTIFICATION_DRAW will be received on idle time to request redraw. Because of this, canvas items don't need to be redraw on every frame, improving the performance significantly. Several functions for drawing on the CanvasItem are provided (see draw_* functions). They can only be used inside the notification, signal or _draw() overrides function, though. Canvas items are draw in tree order. By default, children are on top of their parents so a root CanvasItem will be drawn behind everything (this can be changed per item though). Canvas items can also be hidden (hiding also their subtree). They provide many means for changing standard parameters such as opacity (for it and the subtree) and self opacity, 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.

@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()

Called (if exists) to draw the canvas item.

_editGetPivot
Vector2 _editGetPivot()
_editGetPosition
Vector2 _editGetPosition()
_editGetRect
Rect2 _editGetRect()
_editGetRotation
double _editGetRotation()
_editGetScale
Vector2 _editGetScale()
_editGetState
Dictionary _editGetState()
_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()
drawChar
double drawChar(Font font, Vector2 position, StringArg2 _char, StringArg3 next, Color modulate)

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

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)
drawMultiline
void drawMultiline(PoolVector2Array points, Color color, double width, bool antialiased)

Draws multiple, parallel lines with a uniform color and width and optional antialiasing.

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

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

drawMultimesh
void drawMultimesh(Mesh mesh, Texture texture, Texture normal_map)
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)

Draws a colored rectangle.

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, StringArg2 text, Color modulate, long clip_w)

Draws a string using a custom 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. Transpose swaps the x and y coordinates when reading the texture.

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. Transpose swaps the x and y coordinates when reading the texture.

forceUpdateTransform
void forceUpdateTransform()
getCanvas
RID getCanvas()

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

getCanvasItem
RID getCanvasItem()

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

getCanvasTransform
Transform2D getCanvasTransform()

Get the transform matrix of this item's canvas.

getGlobalMousePosition
Vector2 getGlobalMousePosition()

Get the global position of the mouse.

getGlobalTransform
Transform2D getGlobalTransform()

Get the global transform matrix of this item.

getGlobalTransformWithCanvas
Transform2D getGlobalTransformWithCanvas()

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

getLightMask
long getLightMask()
getLocalMousePosition
Vector2 getLocalMousePosition()

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

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

Get the transform matrix of this item.

getUseParentMaterial
bool getUseParentMaterial()
getViewportRect
Rect2 getViewportRect()

Get the viewport's boundaries as a Rect2.

getViewportTransform
Transform2D getViewportTransform()

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

getWorld2d
Ref!World2D getWorld2d()

Get the World2D where this item is in.

hide
void hide()

Hide the CanvasItem currently visible.

isDrawBehindParentEnabled
bool isDrawBehindParentEnabled()
isLocalTransformNotificationEnabled
bool isLocalTransformNotificationEnabled()

Returns true if local transform notifications are communicated to children.

isSetAsToplevel
bool isSetAsToplevel()

Return if set as toplevel. 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 its inherited visibility is also true.

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
CanvasItem opAssign(T n)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(CanvasItem other)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(typeof(null) n)
Undocumented in source. Be warned that the author may not have intended to support it.
setAsToplevel
void setAsToplevel(bool enable)

Sets as top level. This means that it will not inherit 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 currently hidden.

update
void update()

Queue the CanvasItem for update. 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. Default value: 1.

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

The color applied to textures on this CanvasItem. Default value: Color(1, 1, 1, 1) (opaque "white").

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

The color applied to textures on this CanvasItem. This is not inherited by children CanvasItems. Default value: Color(1, 1, 1, 1) (opaque "white")..

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

If true the object draws behind its parent. Default value: false.

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

If true the object draws on top of its parent. Default value: true.

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

If true the parent CanvasItem's material property is used as this one's material. Default value: false.

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

If true this CanvasItem is drawn. Default value: true.

Static functions

_new
CanvasItem _new()
Undocumented in source. Be warned that the author may not have intended to support it.

Static variables

_classBindingInitialized
bool _classBindingInitialized;
Undocumented in source.

Structs

_classBinding
struct _classBinding
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
To as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
To as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
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