Base class of anything 2D.
    public abstract class CanvasItem : Node

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.

Inheritance Chain

Derived Classes

Static Fields

    public const Int32 NotificationDraw = 30

    public const Int32 NotificationEnterCanvas = 32

    public const Int32 NotificationExitCanvas = 33

    public const Int32 NotificationTransformChanged = 29

    public const Int32 NotificationVisibilityChanged = 31

Signals

    "draw" ()

Emitted when the CanvasItem must redraw. This can only be connected realtime, as deferred will not allow drawing.

    "hide" ()

Emitted when becoming hidden.

    "item_rect_changed" ()

Emitted when the item rect has changed.

    "visibility_changed" ()

Emitted when the visibility (hidden/visible) changes.

Properties

    public int LightMask { get; set; }

The rendering layers in which this CanvasItem responds to Light2D nodes. Default value: 1.

    public Material Material { get; set; }

The material applied to textures on this CanvasItem. Default value: null.

    public Color Modulate { get; set; }

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

    public Color SelfModulate { get; set; }

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

    public bool ShowBehindParent { get; set; }

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

    public bool ShowOnTop { get; set; }

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

    public bool UseParentMaterial { get; set; }

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

    public bool Visible { get; set; }

If true, this CanvasItem is drawn. Default value: true. For controls that inherit Popup, the correct way to make them visible is to call one of the multiple popup*() functions instead.

Methods

    public virtual void _Draw()

Called (if exists) to draw the canvas item.

    public float DrawChar(Font font, Vector2 position, string @char, string next, Color? modulate = default(Color?))

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

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

Draws a colored circle.

    public void DrawColoredPolygon(Vector2[] points, Color color, Vector2[] uvs = null, Texture texture = null, Texture normalMap = null, bool antialiased = false)

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

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

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

    public void DrawMesh(Mesh mesh, Texture texture, Texture normalMap = null)

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

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

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

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.

    public void DrawMultimesh(MultiMesh multimesh, Texture texture, Texture normalMap = null)

    public void DrawPolygon(Vector2[] points, Color[] colors, Vector2[] uvs = null, Texture texture = null, Texture normalMap = null, bool antialiased = false)

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

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

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

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

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.

    public void DrawPrimitive(Vector2[] points, Color[] colors, Vector2[] uvs, Texture texture = null, float width = 1f, Texture normalMap = null)

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.

    public void DrawRect(Rect2 rect, Color color, bool filled = true)

Draws a colored rectangle.

    public void DrawSetTransform(Vector2 position, float rotation, Vector2 scale)

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

    public void DrawSetTransformMatrix(Transform2D xform)

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

    public void DrawString(Font font, Vector2 position, string text, Color? modulate = default(Color?), int clipW = -1)

Draws a string using a custom font.

    public void DrawStyleBox(StyleBox styleBox, Rect2 rect)

Draws a styled rectangle.

    public void DrawTexture(Texture texture, Vector2 position, Color? modulate = default(Color?), Texture normalMap = null)

Draws a texture at a given position.

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

Draws a textured rectangle at a given position, optionally modulated by a color. Transpose swaps the x and y coordinates when reading the texture.

    public void DrawTextureRectRegion(Texture texture, Rect2 rect, Rect2 srcRect, Color? modulate = default(Color?), bool transpose = false, Texture normalMap = null, bool clipUv = true)

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.

    public void ForceUpdateTransform()

    public RID GetCanvas()

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

    public RID GetCanvasItem()

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

    public Transform2D GetCanvasTransform()

Get the transform matrix of this item’s canvas.

    public Vector2 GetGlobalMousePosition()

Get the global position of the mouse.

    public Transform2D GetGlobalTransform()

Get the global transform matrix of this item.

    public Transform2D GetGlobalTransformWithCanvas()

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

    public int GetLightMask()

Getter for LightMask

    public Vector2 GetLocalMousePosition()

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

    public Material GetMaterial()

Getter for Material

    public Color GetModulate()

Getter for Modulate

    public Color GetSelfModulate()

Getter for SelfModulate

    public Transform2D GetTransform()

Get the transform matrix of this item.

    public bool GetUseParentMaterial()

Getter for UseParentMaterial

    public Rect2 GetViewportRect()

Get the viewport’s boundaries as a Rect2.

    public Transform2D GetViewportTransform()

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

    public World2D GetWorld2d()

Get the World2D where this item is in.

    public void Hide()

Hide the CanvasItem currently visible.

    public bool IsDrawBehindParentEnabled()

Getter for ShowBehindParent

    public bool IsLocalTransformNotificationEnabled()

Returns true if local transform notifications are communicated to children.

    public bool IsSetAsToplevel()

Return if set as toplevel. See SetAsToplevel(bool).

    public bool IsTransformNotificationEnabled()

Returns true if global transform notifications are communicated to children.

    public bool IsVisible()

Getter for Visible

    public bool IsVisibleInTree()

Returns true if the node is present in the SceneTree, its Visible property is true and its inherited visibility is also true.

    public Vector2 MakeCanvasPositionLocal(Vector2 screenPoint)

Assigns screenPoint as this node’s new local transform.

    public InputEvent MakeInputLocal(InputEvent @event)

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

    public void SetAsToplevel(bool enable)

Sets as top level. This means that it will not inherit transform from parent canvas items.

    public void SetDrawBehindParent(bool enable)

Setter for ShowBehindParent

    public void SetLightMask(int lightMask)

Setter for LightMask

    public void SetMaterial(Material material)

Setter for Material

    public void SetModulate(Color modulate)

Setter for Modulate

    public void SetNotifyLocalTransform(bool enable)

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

    public void SetNotifyTransform(bool enable)

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

    public void SetSelfModulate(Color selfModulate)

Setter for SelfModulate

    public void SetUseParentMaterial(bool enable)

Setter for UseParentMaterial

    public void SetVisible(bool visible)

Setter for Visible

    public void Show()

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

    public void Update()

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

Inner Types

BlendMode

Name Value Description
Mix 0 Mix blending mode. Colors are assumed to be independent of the alpha (opacity) value.
Add 1 Additive blending mode.
Sub 2 Subtractive blending mode.
Mul 3 Multiplicative blending mode.
PremultAlpha 4 Mix blending mode. Colors are assumed to be premultiplied by the alpha (opacity) value.
Disabled 5 Disable blending mode. Colors including alpha are written as is. Only applicable for render targets with a transparent background. No lighting will be applied.
Tags: