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

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 Object._Notification(int), 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.

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 = 2000

    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.

    public Material Material { get; set; }

The material applied to textures on this CanvasItem.

    public Color Modulate { get; set; }

The color applied to textures on this CanvasItem.

    public Color SelfModulate { get; set; }

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

    public bool ShowBehindParent { get; set; }

If true, the object draws behind its parent.

    public bool ShowOnTop { get; set; }

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

    public bool UseParentMaterial { get; set; }

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

    public bool Visible { get; set; }

If true, this CanvasItem is drawn. 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 character width and kerning with an optional next character.

    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, Transform2D? transform = default(Transform2D?), Color? modulate = default(Color?))

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

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

    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, float width = 1f, bool antialiased = false)

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.

    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. If transpose is true, the texture will have its X and Y coordinates swapped.

    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. If transpose is true, the texture will have its X and Y coordinates swapped.

    public void ForceUpdateTransform()

    public RID GetCanvas()

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

    public RID GetCanvasItem()

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

    public Transform2D GetCanvasTransform()

Gets the transform matrix of this item’s canvas.

    public Vector2 GetGlobalMousePosition()

Gets the global position of the mouse.

    public Transform2D GetGlobalTransform()

Gets the global transform matrix of this item.

    public Transform2D GetGlobalTransformWithCanvas()

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

    [Obsolete("GetLightMask is deprecated. Use the LightMask property instead.")]
    public int GetLightMask()

Getter for LightMask

    public Vector2 GetLocalMousePosition()

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

    [Obsolete("GetMaterial is deprecated. Use the Material property instead.")]
    public Material GetMaterial()

Getter for Material

    [Obsolete("GetModulate is deprecated. Use the Modulate property instead.")]
    public Color GetModulate()

Getter for Modulate

    [Obsolete("GetSelfModulate is deprecated. Use the SelfModulate property instead.")]
    public Color GetSelfModulate()

Getter for SelfModulate

    public Transform2D GetTransform()

Gets the transform matrix of this item.

    [Obsolete("GetUseParentMaterial is deprecated. Use the UseParentMaterial property instead.")]
    public bool GetUseParentMaterial()

Getter for UseParentMaterial

    public Rect2 GetViewportRect()

Gets the viewport’s boundaries as a Rect2.

    public Transform2D GetViewportTransform()

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

    public World2D GetWorld2d()

Gets the World2D where this item is in.

    public void Hide()

Hide the CanvasItem if it’s currently visible.

    [Obsolete("IsDrawBehindParentEnabled is deprecated. Use the ShowBehindParent property instead.")]
    public bool IsDrawBehindParentEnabled()

Getter for ShowBehindParent

    public bool IsLocalTransformNotificationEnabled()

Returns true if local transform notifications are communicated to children.

    public bool IsSetAsToplevel()

Returns true if the node is set as top-level. See SetAsToplevel(bool).

    public bool IsTransformNotificationEnabled()

Returns true if global transform notifications are communicated to children.

    [Obsolete("IsVisible is deprecated. Use the Visible property instead.")]
    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)

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

    [Obsolete("SetDrawBehindParent is deprecated. Use the ShowBehindParent property instead.")]
    public void SetDrawBehindParent(bool enable)

Setter for ShowBehindParent

    [Obsolete("SetLightMask is deprecated. Use the LightMask property instead.")]
    public void SetLightMask(int lightMask)

Setter for LightMask

    [Obsolete("SetMaterial is deprecated. Use the Material property instead.")]
    public void SetMaterial(Material material)

Setter for Material

    [Obsolete("SetModulate is deprecated. Use the Modulate property instead.")]
    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.

    [Obsolete("SetSelfModulate is deprecated. Use the SelfModulate property instead.")]
    public void SetSelfModulate(Color selfModulate)

Setter for SelfModulate

    [Obsolete("SetUseParentMaterial is deprecated. Use the UseParentMaterial property instead.")]
    public void SetUseParentMaterial(bool enable)

Setter for UseParentMaterial

    [Obsolete("SetVisible is deprecated. Use the Visible property instead.")]
    public void SetVisible(bool visible)

Setter for Visible

    public 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.

    public void Update()

Queue the CanvasItem for update. [constant 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 Disables blending mode. Colors including alpha are written as-is. Only applicable for render targets with a transparent background. No lighting will be applied.
Tags: