Documentation
¶
Overview ¶
Abstract base class for everything in 2D space. Canvas items are laid out in a tree; children inherit and extend their parent's transform. graphics.gd/classdb/CanvasItem is extended by graphics.gd/classdb/Control for GUI-related nodes, and by graphics.gd/classdb/Node2D for 2D game objects.
Any graphics.gd/classdb/CanvasItem can draw. For this, Instance.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 graphics.gd/classdb/CanvasItem are provided (see draw_* functions). However, they can only be used inside [Interface.Draw], its corresponding graphics.gd/classdb/Object.Instance.Notification or methods connected to the Instance.OnDraw signal.
Canvas items are drawn in tree order on their canvas layer. By default, children are on top of their parents, so a root graphics.gd/classdb/CanvasItem will be drawn behind everything. This behavior can be changed on a per-item basis.
A graphics.gd/classdb/CanvasItem can be hidden, which will also hide its children. By adjusting various other properties of a graphics.gd/classdb/CanvasItem, you can also modulate its color (via Instance.Modulate or Instance.SelfModulate), change its Z-index, blend mode, and more.
Note that properties like transform, modulation, and visibility are only propagated to direct graphics.gd/classdb/CanvasItem child nodes. If there is a non-graphics.gd/classdb/CanvasItem node in between, like graphics.gd/classdb/Node or graphics.gd/classdb/AnimationPlayer, the graphics.gd/classdb/CanvasItem nodes below will have an independent position and Instance.Modulate chain. See also Instance.TopLevel.
Index ¶
- Constants
- type Advanced
- type Any
- type ClipChildrenMode
- type Expanded
- func (self Expanded) DrawAnimationSlice(animation_length Float.X, slice_begin Float.X, slice_end Float.X, ...)
- func (self Expanded) DrawArc(center Vector2.XY, radius Float.X, start_angle Angle.Radians, ...)
- func (self Expanded) DrawChar(font Font.Instance, pos Vector2.XY, char string, font_size int, ...)
- func (self Expanded) DrawCharOutline(font Font.Instance, pos Vector2.XY, char string, font_size int, size int, ...)
- func (self Expanded) DrawCircle(position Vector2.XY, radius Float.X, color Color.RGBA, filled bool, ...)
- func (self Expanded) DrawColoredPolygon(points []Vector2.XY, color Color.RGBA, uvs []Vector2.XY, ...)
- func (self Expanded) DrawDashedLine(from Vector2.XY, to Vector2.XY, color Color.RGBA, width Float.X, dash Float.X, ...)
- func (self Expanded) DrawLcdTextureRectRegion(texture Texture2D.Instance, rect Rect2.PositionSize, ...)
- func (self Expanded) DrawLine(from Vector2.XY, to Vector2.XY, color Color.RGBA, width Float.X, ...)
- func (self Expanded) DrawMesh(mesh Mesh.Instance, texture Texture2D.Instance, transform Transform2D.OriginXY, ...)
- func (self Expanded) DrawMsdfTextureRectRegion(texture Texture2D.Instance, rect Rect2.PositionSize, ...)
- func (self Expanded) DrawMultiline(points []Vector2.XY, color Color.RGBA, width Float.X, antialiased bool)
- func (self Expanded) DrawMultilineColors(points []Vector2.XY, colors []Color.RGBA, width Float.X, antialiased bool)
- func (self Expanded) DrawMultilineString(font Font.Instance, pos Vector2.XY, text string, ...)
- func (self Expanded) DrawMultilineStringOutline(font Font.Instance, pos Vector2.XY, text string, ...)
- func (self Expanded) DrawPolygon(points []Vector2.XY, colors []Color.RGBA, uvs []Vector2.XY, ...)
- func (self Expanded) DrawPolyline(points []Vector2.XY, color Color.RGBA, width Float.X, antialiased bool)
- func (self Expanded) DrawPolylineColors(points []Vector2.XY, colors []Color.RGBA, width Float.X, antialiased bool)
- func (self Expanded) DrawPrimitive(points []Vector2.XY, colors []Color.RGBA, uvs []Vector2.XY, ...)
- func (self Expanded) DrawRect(rect Rect2.PositionSize, color Color.RGBA, filled bool, width Float.X, ...)
- func (self Expanded) DrawSetTransform(position Vector2.XY, rotation Angle.Radians, scale Vector2.XY)
- func (self Expanded) DrawString(font Font.Instance, pos Vector2.XY, text string, ...)
- func (self Expanded) DrawStringOutline(font Font.Instance, pos Vector2.XY, text string, ...)
- func (self Expanded) DrawTexture(texture Texture2D.Instance, position Vector2.XY, modulate Color.RGBA)
- func (self Expanded) DrawTextureRect(texture Texture2D.Instance, rect Rect2.PositionSize, tile bool, ...)
- func (self Expanded) DrawTextureRectRegion(texture Texture2D.Instance, rect Rect2.PositionSize, ...)
- type Extension
- type ID
- type Implementation
- type Instance
- func (self Instance) AsCanvasItem() Instance
- func (self Instance) AsNode() Node.Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) ClipChildren() ClipChildrenMode
- func (self Instance) DrawAnimationSlice(animation_length Float.X, slice_begin Float.X, slice_end Float.X)
- func (self Instance) DrawArc(center Vector2.XY, radius Float.X, start_angle Angle.Radians, ...)
- func (self Instance) DrawChar(font Font.Instance, pos Vector2.XY, char string)
- func (self Instance) DrawCharOutline(font Font.Instance, pos Vector2.XY, char string)
- func (self Instance) DrawCircle(position Vector2.XY, radius Float.X, color Color.RGBA)
- func (self Instance) DrawColoredPolygon(points []Vector2.XY, color Color.RGBA)
- func (self Instance) DrawDashedLine(from Vector2.XY, to Vector2.XY, color Color.RGBA)
- func (self Instance) DrawEndAnimation()
- func (self Instance) DrawLcdTextureRectRegion(texture Texture2D.Instance, rect Rect2.PositionSize, ...)
- func (self Instance) DrawLine(from Vector2.XY, to Vector2.XY, color Color.RGBA)
- func (self Instance) DrawMesh(mesh Mesh.Instance, texture Texture2D.Instance)
- func (self Instance) DrawMsdfTextureRectRegion(texture Texture2D.Instance, rect Rect2.PositionSize, ...)
- func (self Instance) DrawMultiline(points []Vector2.XY, color Color.RGBA)
- func (self Instance) DrawMultilineColors(points []Vector2.XY, colors []Color.RGBA)
- func (self Instance) DrawMultilineString(font Font.Instance, pos Vector2.XY, text string)
- func (self Instance) DrawMultilineStringOutline(font Font.Instance, pos Vector2.XY, text string)
- func (self Instance) DrawMultimesh(multimesh MultiMesh.Instance, texture Texture2D.Instance)
- func (self Instance) DrawPolygon(points []Vector2.XY, colors []Color.RGBA)
- func (self Instance) DrawPolyline(points []Vector2.XY, color Color.RGBA)
- func (self Instance) DrawPolylineColors(points []Vector2.XY, colors []Color.RGBA)
- func (self Instance) DrawPrimitive(points []Vector2.XY, colors []Color.RGBA, uvs []Vector2.XY)
- func (self Instance) DrawRect(rect Rect2.PositionSize, color Color.RGBA)
- func (self Instance) DrawSetTransform(position Vector2.XY)
- func (self Instance) DrawSetTransformMatrix(xform Transform2D.OriginXY)
- func (self Instance) DrawString(font Font.Instance, pos Vector2.XY, text string)
- func (self Instance) DrawStringOutline(font Font.Instance, pos Vector2.XY, text string)
- func (self Instance) DrawTexture(texture Texture2D.Instance, position Vector2.XY)
- func (self Instance) DrawTextureRect(texture Texture2D.Instance, rect Rect2.PositionSize, tile bool)
- func (self Instance) DrawTextureRectRegion(texture Texture2D.Instance, rect Rect2.PositionSize, ...)
- func (self Instance) ForceUpdateTransform()
- func (self Instance) GetCanvas() RID.Canvas
- func (self Instance) GetCanvasItem() RID.CanvasItem
- func (self Instance) GetCanvasLayerNode() CanvasLayer.Instance
- func (self Instance) GetCanvasTransform() Transform2D.OriginXY
- func (self Instance) GetGlobalMousePosition() Vector2.XY
- func (self Instance) GetGlobalTransform() Transform2D.OriginXY
- func (self Instance) GetGlobalTransformWithCanvas() Transform2D.OriginXY
- func (self Instance) GetInstanceShaderParameter(name string) any
- func (self Instance) GetLocalMousePosition() Vector2.XY
- func (self Instance) GetScreenTransform() Transform2D.OriginXY
- func (self Instance) GetTransform() Transform2D.OriginXY
- func (self Instance) GetViewportRect() Rect2.PositionSize
- func (self Instance) GetViewportTransform() Transform2D.OriginXY
- func (self Instance) GetVisibilityLayerBit(layer int) bool
- func (self Instance) GetWorld2d() World2D.Instance
- func (self Instance) Hide()
- func (self Instance) ID() ID
- func (self Instance) IsLocalTransformNotificationEnabled() bool
- func (self Instance) IsTransformNotificationEnabled() bool
- func (self Instance) IsVisibleInTree() bool
- func (self Instance) LightMask() int
- func (self Instance) MakeCanvasPositionLocal(viewport_point Vector2.XY) Vector2.XY
- func (self Instance) MakeInputLocal(event InputEvent.Instance) InputEvent.Instance
- func (self Instance) Material() Material.Instance
- func (self Instance) Modulate() Color.RGBA
- func (self Instance) MoveToFront()
- func (self Instance) OnDraw(cb func(), flags ...Signal.Flags)
- func (self Instance) OnHidden(cb func(), flags ...Signal.Flags)
- func (self Instance) OnItemRectChanged(cb func(), flags ...Signal.Flags)
- func (self Instance) OnVisibilityChanged(cb func(), flags ...Signal.Flags)
- func (self Instance) QueueRedraw()
- func (self Instance) SelfModulate() Color.RGBA
- func (self Instance) SetClipChildren(value ClipChildrenMode)
- func (self Instance) SetInstanceShaderParameter(name string, value any)
- func (self Instance) SetLightMask(value int)
- func (self Instance) SetMaterial(value Material.Instance)
- func (self Instance) SetModulate(value Color.RGBA)
- func (self Instance) SetNotifyLocalTransform(enable bool)
- func (self Instance) SetNotifyTransform(enable bool)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) SetSelfModulate(value Color.RGBA)
- func (self Instance) SetShowBehindParent(value bool)
- func (self Instance) SetTextureFilter(value TextureFilter)
- func (self Instance) SetTextureRepeat(value TextureRepeat)
- func (self Instance) SetTopLevel(value bool)
- func (self Instance) SetUseParentMaterial(value bool)
- func (self Instance) SetVisibilityLayer(value int)
- func (self Instance) SetVisibilityLayerBit(layer int, enabled bool)
- func (self Instance) SetVisible(value bool)
- func (self Instance) SetYSortEnabled(value bool)
- func (self Instance) SetZAsRelative(value bool)
- func (self Instance) SetZIndex(value int)
- func (self Instance) Show()
- func (self Instance) ShowBehindParent() bool
- func (self Instance) TextureFilter() TextureFilter
- func (self Instance) TextureRepeat() TextureRepeat
- func (self Instance) TopLevel() bool
- func (self Instance) UseParentMaterial() bool
- func (self Instance) Virtual(name string) reflect.Value
- func (self Instance) VisibilityLayer() int
- func (self Instance) Visible() bool
- func (self Instance) YSortEnabled() bool
- func (self Instance) ZAsRelative() bool
- func (self Instance) ZIndex() int
- type Interface
- type TextureFilter
- type TextureRepeat
Constants ¶
const NotificationDraw Object.Notification = 30 //gd:CanvasItem.NOTIFICATION_DRAW
const NotificationEnterCanvas Object.Notification = 32 //gd:CanvasItem.NOTIFICATION_ENTER_CANVAS
const NotificationExitCanvas Object.Notification = 33 //gd:CanvasItem.NOTIFICATION_EXIT_CANVAS
const NotificationLocalTransformChanged Object.Notification = 35 //gd:CanvasItem.NOTIFICATION_LOCAL_TRANSFORM_CHANGED
const NotificationTransformChanged Object.Notification = 2000 //gd:CanvasItem.NOTIFICATION_TRANSFORM_CHANGED
const NotificationVisibilityChanged Object.Notification = 31 //gd:CanvasItem.NOTIFICATION_VISIBILITY_CHANGED
const NotificationWorld2dChanged Object.Notification = 36 //gd:CanvasItem.NOTIFICATION_WORLD_2D_CHANGED
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type ClipChildrenMode ¶
type ClipChildrenMode int //gd:CanvasItem.ClipChildrenMode
const ( // Children are drawn over this node and are not clipped. ClipChildrenDisabled ClipChildrenMode = 0 // This node is used as a mask and is not drawn. The mask is based on this node's alpha channel: Opaque pixels are kept, transparent pixels are discarded, and semi-transparent pixels are blended in according to their opacity. Children are clipped to this node's drawn area. ClipChildrenOnly ClipChildrenMode = 1 // This node is used as a mask and is also drawn. The mask is based on this node's alpha channel: Opaque pixels are kept, transparent pixels are discarded, and semi-transparent pixels are blended in according to their opacity. Children are clipped to the parent's drawn area. ClipChildrenAndDraw ClipChildrenMode = 2 // Represents the size of the [ClipChildrenMode] enum. ClipChildrenMax ClipChildrenMode = 3 )
type Expanded ¶
type Expanded [1]gdclass.CanvasItem
func (Expanded) DrawAnimationSlice ¶
func (self Expanded) DrawAnimationSlice(animation_length Float.X, slice_begin Float.X, slice_end Float.X, offset Float.X)
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.
func (Expanded) DrawArc ¶
func (self Expanded) DrawArc(center Vector2.XY, radius Float.X, start_angle Angle.Radians, end_angle Angle.Radians, point_count int, color Color.RGBA, width Float.X, antialiased 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 'point_count', the smoother the curve. 'center' is defined in local space. See also Instance.DrawCircle.
If 'width' is negative, it will be ignored and the arc will be drawn using [Renderingserver.PrimitiveLineStrip]. 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 'start_angle' towards the value of 'end_angle' 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 'start_angle' and 'end_angle' is greater than [@Gdscript.Tau] radians, then a full circle arc is drawn (i.e. arc will not overlap itself).
func (Expanded) DrawChar ¶
func (self Expanded) DrawChar(font Font.Instance, pos Vector2.XY, char string, font_size int, modulate Color.RGBA, oversampling Float.X)
Draws a string first character using a custom font. If 'oversampling' is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used. 'pos' is defined in local space.
func (Expanded) DrawCharOutline ¶
func (self Expanded) DrawCharOutline(font Font.Instance, pos Vector2.XY, char string, font_size int, size int, modulate Color.RGBA, oversampling Float.X)
Draws a string first character outline using a custom font. If 'oversampling' is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used. 'pos' is defined in local space.
func (Expanded) DrawCircle ¶
func (self Expanded) DrawCircle(position Vector2.XY, radius Float.X, color Color.RGBA, filled bool, width Float.X, antialiased bool)
Draws a circle, with 'position' defined in local space. See also Instance.DrawArc, Instance.DrawPolyline, and Instance.DrawPolygon.
If 'filled' is true, the circle will be filled with the 'color' specified. If 'filled' is false, the circle will be drawn as a stroke with the 'color' and 'width' specified.
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.
If 'antialiased' is true, half transparent "feathers" will be attached to the boundary, making outlines smooth.
Note: 'width' is only effective if 'filled' is false.
func (Expanded) DrawColoredPolygon ¶
func (self Expanded) DrawColoredPolygon(points []Vector2.XY, color Color.RGBA, uvs []Vector2.XY, texture Texture2D.Instance)
Draws a colored polygon of any number of points, convex or concave. The points in the 'points' array are defined in local space. Unlike Instance.DrawPolygon, a single color must be specified for the whole polygon.
Note: If you frequently redraw the same polygon with a large number of vertices, consider pre-calculating the triangulation with graphics.gd/classdb/Geometry2D.TriangulatePolygon and using Instance.DrawMesh, Instance.DrawMultimesh, or graphics.gd/classdb/RenderingServer.CanvasItemAddTriangleArray.
func (Expanded) DrawDashedLine ¶
func (self Expanded) DrawDashedLine(from Vector2.XY, to Vector2.XY, color Color.RGBA, width Float.X, dash Float.X, aligned bool, antialiased bool)
Draws a dashed line from a 2D point to another, with a given color and width. The 'from' and 'to' positions are defined in local space. See also Instance.DrawLine, Instance.DrawMultiline, and Instance.DrawPolyline.
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.
'dash' is the length of each dash in pixels, with the gap between each dash being the same length. If 'aligned' is true, the length of the first and last dashes may be shortened or lengthened to allow the line to begin and end at the precise points defined by 'from' and 'to'. Both ends are always symmetrical when 'aligned' is true. If 'aligned' is false, all dashes will have the same length, but the line may appear incomplete at the end due to the dash length not dividing evenly into the line length. Only full dashes are drawn when 'aligned' is false.
If 'antialiased' is true, half transparent "feathers" will be attached to the boundary, making outlines smooth.
Note: 'antialiased' is only effective if 'width' is greater than 0.0.
func (Expanded) DrawLcdTextureRectRegion ¶
func (self Expanded) DrawLcdTextureRectRegion(texture Texture2D.Instance, rect Rect2.PositionSize, src_rect Rect2.PositionSize, modulate Color.RGBA)
Draws a textured rectangle region of the font texture with LCD subpixel anti-aliasing at a given position, optionally modulated by a color. The 'rect' is defined in local space.
Texture is drawn using the following blend operation, blend mode of the graphics.gd/classdb/CanvasItemMaterial is ignored:
var dst, texture, modulate Color.RGBA 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)
func (Expanded) DrawLine ¶
func (self Expanded) DrawLine(from Vector2.XY, to Vector2.XY, color Color.RGBA, width Float.X, antialiased bool)
Draws a line from a 2D point to another, with a given color and width. It can be optionally antialiased. The 'from' and 'to' positions are defined in local space. See also Instance.DrawDashedLine, Instance.DrawMultiline, and Instance.DrawPolyline.
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.
func (Expanded) DrawMesh ¶
func (self Expanded) DrawMesh(mesh Mesh.Instance, texture Texture2D.Instance, transform Transform2D.OriginXY, modulate Color.RGBA)
Draws a graphics.gd/classdb/Mesh in 2D, using the provided texture. See graphics.gd/classdb/MeshInstance2D for related documentation. The 'transform' is defined in local space.
func (Expanded) DrawMsdfTextureRectRegion ¶
func (self Expanded) DrawMsdfTextureRectRegion(texture Texture2D.Instance, rect Rect2.PositionSize, src_rect Rect2.PositionSize, modulate Color.RGBA, outline Float.X, pixel_range Float.X, scale Float.X)
Draws a textured rectangle region of the multichannel signed distance field texture at a given position, optionally modulated by a color. The 'rect' is defined in local space. See graphics.gd/classdb/FontFile.Instance.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 'pixel_range' should the same that was used during distance field texture generation.
func (Expanded) DrawMultiline ¶
func (self Expanded) DrawMultiline(points []Vector2.XY, color Color.RGBA, width Float.X, antialiased bool)
Draws multiple disconnected lines with a uniform 'width' and 'color'. Each line is defined by two consecutive points from 'points' array in local space, 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 Instance.DrawLine calls. To draw interconnected lines, use Instance.DrawPolyline 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.
Note: 'antialiased' is only effective if 'width' is greater than 0.0.
func (Expanded) DrawMultilineColors ¶
func (self Expanded) DrawMultilineColors(points []Vector2.XY, colors []Color.RGBA, width Float.X, antialiased bool)
Draws multiple disconnected lines with a uniform 'width' and segment-by-segment coloring. Each segment is defined by two consecutive points from 'points' array in local space 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 Instance.DrawLine calls. To draw interconnected lines, use Instance.DrawPolylineColors 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.
Note: 'antialiased' is only effective if 'width' is greater than 0.0.
func (Expanded) DrawMultilineString ¶
func (self Expanded) DrawMultilineString(font Font.Instance, pos Vector2.XY, text string, alignment GUI.HorizontalAlignment, width Float.X, font_size int, max_lines int, modulate Color.RGBA, brk_flags TextServer.LineBreakFlag, justification_flags TextServer.JustificationFlag, direction TextServer.Direction, orientation TextServer.Orientation, oversampling Float.X)
Breaks 'text' into lines and draws it using the specified 'font' at the 'pos' in local space (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. If 'oversampling' is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used.
func (Expanded) DrawMultilineStringOutline ¶
func (self Expanded) DrawMultilineStringOutline(font Font.Instance, pos Vector2.XY, text string, alignment GUI.HorizontalAlignment, width Float.X, font_size int, max_lines int, size int, modulate Color.RGBA, brk_flags TextServer.LineBreakFlag, justification_flags TextServer.JustificationFlag, direction TextServer.Direction, orientation TextServer.Orientation, oversampling Float.X)
Breaks 'text' to the lines and draws text outline using the specified 'font' at the 'pos' in local space (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. If 'oversampling' is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used.
func (Expanded) DrawPolygon ¶
func (self Expanded) DrawPolygon(points []Vector2.XY, colors []Color.RGBA, uvs []Vector2.XY, texture Texture2D.Instance)
Draws a solid polygon of any number of points, convex or concave. Unlike Instance.DrawColoredPolygon, each point's color can be changed individually. The 'points' array is defined in local space. See also Instance.DrawPolyline and Instance.DrawPolylineColors. If you need more flexibility (such as being able to use bones), use graphics.gd/classdb/RenderingServer.CanvasItemAddTriangleArray instead.
Note: If you frequently redraw the same polygon with a large number of vertices, consider pre-calculating the triangulation with graphics.gd/classdb/Geometry2D.TriangulatePolygon and using Instance.DrawMesh, Instance.DrawMultimesh, or graphics.gd/classdb/RenderingServer.CanvasItemAddTriangleArray.
func (Expanded) DrawPolyline ¶
func (self Expanded) DrawPolyline(points []Vector2.XY, color Color.RGBA, width Float.X, antialiased bool)
Draws interconnected line segments with a uniform 'color' and 'width' and optional antialiasing (supported only for positive 'width'). The 'points' array is defined in local space. When drawing large amounts of lines, this is faster than using individual Instance.DrawLine calls. To draw disconnected lines, use Instance.DrawMultiline instead. See also Instance.DrawPolygon.
If 'width' is negative, it will be ignored and the polyline will be drawn using [Renderingserver.PrimitiveLineStrip]. 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.
func (Expanded) DrawPolylineColors ¶
func (self Expanded) DrawPolylineColors(points []Vector2.XY, colors []Color.RGBA, width Float.X, antialiased 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. The 'points' array is defined in local space. When drawing large amounts of lines, this is faster than using individual Instance.DrawLine calls. To draw disconnected lines, use Instance.DrawMultilineColors instead. See also Instance.DrawPolygon.
If 'width' is negative, it will be ignored and the polyline will be drawn using [Renderingserver.PrimitiveLineStrip]. 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.
func (Expanded) DrawPrimitive ¶
func (self Expanded) DrawPrimitive(points []Vector2.XY, colors []Color.RGBA, uvs []Vector2.XY, texture Texture2D.Instance)
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. The 'points' array is defined in local space. See also Instance.DrawLine, Instance.DrawPolyline, Instance.DrawPolygon, and Instance.DrawRect.
func (Expanded) DrawRect ¶
func (self Expanded) DrawRect(rect Rect2.PositionSize, color Color.RGBA, filled bool, width Float.X, antialiased bool)
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. The 'rect' is specified in local space. See also Instance.DrawTextureRect.
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.
If 'antialiased' is true, half transparent "feathers" will be attached to the boundary, making outlines smooth.
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').
func (Expanded) DrawSetTransform ¶
func (self Expanded) DrawSetTransform(position Vector2.XY, rotation Angle.Radians, scale Vector2.XY)
Sets a custom local transform for drawing via components. Anything drawn afterwards will be transformed by this.
Note: graphics.gd/classdb/FontFile.Instance.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 graphics.gd/classdb/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, graphics.gd/classdb/SystemFont.Instance.MultichannelSignedDistanceField can be enabled in the inspector.
func (Expanded) DrawString ¶
func (self Expanded) DrawString(font Font.Instance, pos Vector2.XY, text string, alignment GUI.HorizontalAlignment, width Float.X, font_size int, modulate Color.RGBA, justification_flags TextServer.JustificationFlag, direction TextServer.Direction, orientation TextServer.Orientation, oversampling Float.X)
Draws 'text' using the specified 'font' at the 'pos' in local space (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. If 'oversampling' is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used.
Example: Draw "Hello world", using the project's default 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. var defaultFont = ThemeDB.FallbackFont() var defaultFontSize = ThemeDB.FallbackFontSize() CanvasItem.Expanded(canvas_item).DrawString(defaultFont, Vector2.New(64, 64), "Hello world", GUI.HorizontalAlignmentLeft, -1, defaultFontSize, Color.W3C.White, TextServer.JustificationKashida|TextServer.JustificationWordBound, 0, 0, 0)
func (Expanded) DrawStringOutline ¶
func (self Expanded) DrawStringOutline(font Font.Instance, pos Vector2.XY, text string, alignment GUI.HorizontalAlignment, width Float.X, font_size int, size int, modulate Color.RGBA, justification_flags TextServer.JustificationFlag, direction TextServer.Direction, orientation TextServer.Orientation, oversampling Float.X)
Draws 'text' outline using the specified 'font' at the 'pos' in local space (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. If 'oversampling' is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used.
func (Expanded) DrawTexture ¶
func (self Expanded) DrawTexture(texture Texture2D.Instance, position Vector2.XY, modulate Color.RGBA)
Draws a texture at a given position. The 'position' is defined in local space.
func (Expanded) DrawTextureRect ¶
func (self Expanded) DrawTextureRect(texture Texture2D.Instance, rect Rect2.PositionSize, tile bool, modulate Color.RGBA, transpose bool)
Draws a textured rectangle at a given position, optionally modulated by a color. The 'rect' is defined in local space. If 'transpose' is true, the texture will have its X and Y coordinates swapped. See also Instance.DrawRect and Instance.DrawTextureRectRegion.
func (Expanded) DrawTextureRectRegion ¶
func (self Expanded) DrawTextureRectRegion(texture Texture2D.Instance, rect Rect2.PositionSize, src_rect Rect2.PositionSize, modulate Color.RGBA, transpose bool, clip_uv bool)
Draws a textured rectangle from a texture's region (specified by 'src_rect') at a given position in local space, optionally modulated by a color. If 'transpose' is true, the texture will have its X and Y coordinates swapped. See also Instance.DrawTextureRect.
type Extension ¶
Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this [Extension]See Interface for methods that can be overridden by T.
func (*Extension[T]) AsCanvasItem ¶
type ID ¶
ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.
type Implementation ¶
type Implementation = implementation
Implementation implements Interface with empty methods.
type Instance ¶
type Instance [1]gdclass.CanvasItem
Instance of the class with convieniently typed arguments and results.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func (Instance) AsCanvasItem ¶
func (Instance) ClipChildren ¶
func (self Instance) ClipChildren() ClipChildrenMode
func (Instance) DrawAnimationSlice ¶
func (self Instance) DrawAnimationSlice(animation_length Float.X, slice_begin Float.X, slice_end Float.X)
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.
func (Instance) DrawArc ¶
func (self Instance) DrawArc(center Vector2.XY, radius Float.X, start_angle Angle.Radians, end_angle Angle.Radians, point_count int, color Color.RGBA)
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 'point_count', the smoother the curve. 'center' is defined in local space. See also Instance.DrawCircle.
If 'width' is negative, it will be ignored and the arc will be drawn using [Renderingserver.PrimitiveLineStrip]. 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 'start_angle' towards the value of 'end_angle' 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 'start_angle' and 'end_angle' is greater than [@Gdscript.Tau] radians, then a full circle arc is drawn (i.e. arc will not overlap itself).
func (Instance) DrawChar ¶
Draws a string first character using a custom font. If 'oversampling' is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used. 'pos' is defined in local space.
func (Instance) DrawCharOutline ¶
Draws a string first character outline using a custom font. If 'oversampling' is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used. 'pos' is defined in local space.
func (Instance) DrawCircle ¶
Draws a circle, with 'position' defined in local space. See also Instance.DrawArc, Instance.DrawPolyline, and Instance.DrawPolygon.
If 'filled' is true, the circle will be filled with the 'color' specified. If 'filled' is false, the circle will be drawn as a stroke with the 'color' and 'width' specified.
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.
If 'antialiased' is true, half transparent "feathers" will be attached to the boundary, making outlines smooth.
Note: 'width' is only effective if 'filled' is false.
func (Instance) DrawColoredPolygon ¶
Draws a colored polygon of any number of points, convex or concave. The points in the 'points' array are defined in local space. Unlike Instance.DrawPolygon, a single color must be specified for the whole polygon.
Note: If you frequently redraw the same polygon with a large number of vertices, consider pre-calculating the triangulation with graphics.gd/classdb/Geometry2D.TriangulatePolygon and using Instance.DrawMesh, Instance.DrawMultimesh, or graphics.gd/classdb/RenderingServer.CanvasItemAddTriangleArray.
func (Instance) DrawDashedLine ¶
Draws a dashed line from a 2D point to another, with a given color and width. The 'from' and 'to' positions are defined in local space. See also Instance.DrawLine, Instance.DrawMultiline, and Instance.DrawPolyline.
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.
'dash' is the length of each dash in pixels, with the gap between each dash being the same length. If 'aligned' is true, the length of the first and last dashes may be shortened or lengthened to allow the line to begin and end at the precise points defined by 'from' and 'to'. Both ends are always symmetrical when 'aligned' is true. If 'aligned' is false, all dashes will have the same length, but the line may appear incomplete at the end due to the dash length not dividing evenly into the line length. Only full dashes are drawn when 'aligned' is false.
If 'antialiased' is true, half transparent "feathers" will be attached to the boundary, making outlines smooth.
Note: 'antialiased' is only effective if 'width' is greater than 0.0.
func (Instance) DrawEndAnimation ¶
func (self Instance) DrawEndAnimation()
After submitting all animations slices via Instance.DrawAnimationSlice, 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.
func (Instance) DrawLcdTextureRectRegion ¶
func (self Instance) DrawLcdTextureRectRegion(texture Texture2D.Instance, rect Rect2.PositionSize, src_rect Rect2.PositionSize)
Draws a textured rectangle region of the font texture with LCD subpixel anti-aliasing at a given position, optionally modulated by a color. The 'rect' is defined in local space.
Texture is drawn using the following blend operation, blend mode of the graphics.gd/classdb/CanvasItemMaterial is ignored:
var dst, texture, modulate Color.RGBA 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)
func (Instance) DrawLine ¶
Draws a line from a 2D point to another, with a given color and width. It can be optionally antialiased. The 'from' and 'to' positions are defined in local space. See also Instance.DrawDashedLine, Instance.DrawMultiline, and Instance.DrawPolyline.
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.
func (Instance) DrawMesh ¶
Draws a graphics.gd/classdb/Mesh in 2D, using the provided texture. See graphics.gd/classdb/MeshInstance2D for related documentation. The 'transform' is defined in local space.
func (Instance) DrawMsdfTextureRectRegion ¶
func (self Instance) DrawMsdfTextureRectRegion(texture Texture2D.Instance, rect Rect2.PositionSize, src_rect Rect2.PositionSize)
Draws a textured rectangle region of the multichannel signed distance field texture at a given position, optionally modulated by a color. The 'rect' is defined in local space. See graphics.gd/classdb/FontFile.Instance.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 'pixel_range' should the same that was used during distance field texture generation.
func (Instance) DrawMultiline ¶
Draws multiple disconnected lines with a uniform 'width' and 'color'. Each line is defined by two consecutive points from 'points' array in local space, 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 Instance.DrawLine calls. To draw interconnected lines, use Instance.DrawPolyline 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.
Note: 'antialiased' is only effective if 'width' is greater than 0.0.
func (Instance) DrawMultilineColors ¶
Draws multiple disconnected lines with a uniform 'width' and segment-by-segment coloring. Each segment is defined by two consecutive points from 'points' array in local space 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 Instance.DrawLine calls. To draw interconnected lines, use Instance.DrawPolylineColors 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.
Note: 'antialiased' is only effective if 'width' is greater than 0.0.
func (Instance) DrawMultilineString ¶
Breaks 'text' into lines and draws it using the specified 'font' at the 'pos' in local space (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. If 'oversampling' is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used.
func (Instance) DrawMultilineStringOutline ¶
Breaks 'text' to the lines and draws text outline using the specified 'font' at the 'pos' in local space (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. If 'oversampling' is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used.
func (Instance) DrawMultimesh ¶
Draws a graphics.gd/classdb/MultiMesh in 2D with the provided texture. See graphics.gd/classdb/MultiMeshInstance2D for related documentation.
func (Instance) DrawPolygon ¶
Draws a solid polygon of any number of points, convex or concave. Unlike Instance.DrawColoredPolygon, each point's color can be changed individually. The 'points' array is defined in local space. See also Instance.DrawPolyline and Instance.DrawPolylineColors. If you need more flexibility (such as being able to use bones), use graphics.gd/classdb/RenderingServer.CanvasItemAddTriangleArray instead.
Note: If you frequently redraw the same polygon with a large number of vertices, consider pre-calculating the triangulation with graphics.gd/classdb/Geometry2D.TriangulatePolygon and using Instance.DrawMesh, Instance.DrawMultimesh, or graphics.gd/classdb/RenderingServer.CanvasItemAddTriangleArray.
func (Instance) DrawPolyline ¶
Draws interconnected line segments with a uniform 'color' and 'width' and optional antialiasing (supported only for positive 'width'). The 'points' array is defined in local space. When drawing large amounts of lines, this is faster than using individual Instance.DrawLine calls. To draw disconnected lines, use Instance.DrawMultiline instead. See also Instance.DrawPolygon.
If 'width' is negative, it will be ignored and the polyline will be drawn using [Renderingserver.PrimitiveLineStrip]. 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.
func (Instance) DrawPolylineColors ¶
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. The 'points' array is defined in local space. When drawing large amounts of lines, this is faster than using individual Instance.DrawLine calls. To draw disconnected lines, use Instance.DrawMultilineColors instead. See also Instance.DrawPolygon.
If 'width' is negative, it will be ignored and the polyline will be drawn using [Renderingserver.PrimitiveLineStrip]. 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.
func (Instance) DrawPrimitive ¶
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. The 'points' array is defined in local space. See also Instance.DrawLine, Instance.DrawPolyline, Instance.DrawPolygon, and Instance.DrawRect.
func (Instance) DrawRect ¶
func (self Instance) DrawRect(rect Rect2.PositionSize, color Color.RGBA)
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. The 'rect' is specified in local space. See also Instance.DrawTextureRect.
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.
If 'antialiased' is true, half transparent "feathers" will be attached to the boundary, making outlines smooth.
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').
func (Instance) DrawSetTransform ¶
Sets a custom local transform for drawing via components. Anything drawn afterwards will be transformed by this.
Note: graphics.gd/classdb/FontFile.Instance.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 graphics.gd/classdb/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, graphics.gd/classdb/SystemFont.Instance.MultichannelSignedDistanceField can be enabled in the inspector.
func (Instance) DrawSetTransformMatrix ¶
func (self Instance) DrawSetTransformMatrix(xform Transform2D.OriginXY)
Sets a custom local transform for drawing via matrix. Anything drawn afterwards will be transformed by this.
func (Instance) DrawString ¶
Draws 'text' using the specified 'font' at the 'pos' in local space (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. If 'oversampling' is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used.
Example: Draw "Hello world", using the project's default 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. var defaultFont = ThemeDB.FallbackFont() var defaultFontSize = ThemeDB.FallbackFontSize() CanvasItem.Expanded(canvas_item).DrawString(defaultFont, Vector2.New(64, 64), "Hello world", GUI.HorizontalAlignmentLeft, -1, defaultFontSize, Color.W3C.White, TextServer.JustificationKashida|TextServer.JustificationWordBound, 0, 0, 0)
func (Instance) DrawStringOutline ¶
Draws 'text' outline using the specified 'font' at the 'pos' in local space (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. If 'oversampling' is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used.
func (Instance) DrawTexture ¶
Draws a texture at a given position. The 'position' is defined in local space.
func (Instance) DrawTextureRect ¶
func (self Instance) DrawTextureRect(texture Texture2D.Instance, rect Rect2.PositionSize, tile bool)
Draws a textured rectangle at a given position, optionally modulated by a color. The 'rect' is defined in local space. If 'transpose' is true, the texture will have its X and Y coordinates swapped. See also Instance.DrawRect and Instance.DrawTextureRectRegion.
func (Instance) DrawTextureRectRegion ¶
func (self Instance) DrawTextureRectRegion(texture Texture2D.Instance, rect Rect2.PositionSize, src_rect Rect2.PositionSize)
Draws a textured rectangle from a texture's region (specified by 'src_rect') at a given position in local space, optionally modulated by a color. If 'transpose' is true, the texture will have its X and Y coordinates swapped. See also Instance.DrawTextureRect.
func (Instance) ForceUpdateTransform ¶
func (self Instance) ForceUpdateTransform()
Forces the node's transform to update. Fails if the node is not inside the tree. See also Instance.GetTransform.
Note: For performance reasons, transform changes are usually accumulated and applied once at the end of the frame. The update propagates through graphics.gd/classdb/CanvasItem children, as well. Therefore, use this method only when you need an up-to-date transform (such as during physics operations).
func (Instance) GetCanvas ¶
Returns the [Resource.ID] of the graphics.gd/classdb/World2D canvas where this node is registered to, used by the graphics.gd/classdb/RenderingServer.
func (Instance) GetCanvasItem ¶
func (self Instance) GetCanvasItem() RID.CanvasItem
Returns the internal canvas item [Resource.ID] used by the graphics.gd/classdb/RenderingServer for this node.
func (Instance) GetCanvasLayerNode ¶
func (self Instance) GetCanvasLayerNode() CanvasLayer.Instance
Returns the graphics.gd/classdb/CanvasLayer that contains this node, or null if the node is not in any graphics.gd/classdb/CanvasLayer.
func (Instance) GetCanvasTransform ¶
func (self Instance) GetCanvasTransform() Transform2D.OriginXY
Returns the transform of this node, converted from its registered canvas's coordinate system to its viewport's coordinate system. See also graphics.gd/classdb/Node.Instance.GetViewport.
func (Instance) GetGlobalMousePosition ¶
Returns mouse cursor's global position relative to the graphics.gd/classdb/CanvasLayer that contains this node.
Note: For screen-space coordinates (e.g. when using a non-embedded graphics.gd/classdb/Popup), you can use graphics.gd/classdb/DisplayServer.MouseGetPosition.
func (Instance) GetGlobalTransform ¶
func (self Instance) GetGlobalTransform() Transform2D.OriginXY
Returns the global transform matrix of this item, i.e. the combined transform up to the topmost graphics.gd/classdb/CanvasItem node. The topmost item is a graphics.gd/classdb/CanvasItem that either has no parent, has non-graphics.gd/classdb/CanvasItem parent or it has Instance.TopLevel enabled.
func (Instance) GetGlobalTransformWithCanvas ¶
func (self Instance) GetGlobalTransformWithCanvas() Transform2D.OriginXY
Returns the transform from the local coordinate system of this graphics.gd/classdb/CanvasItem to the [graphics.gd/classdb/Viewport]s coordinate system.
func (Instance) GetInstanceShaderParameter ¶
Get the value of a shader parameter as set on this instance.
func (Instance) GetLocalMousePosition ¶
Returns the mouse's position in this graphics.gd/classdb/CanvasItem using the local coordinate system of this graphics.gd/classdb/CanvasItem.
func (Instance) GetScreenTransform ¶
func (self Instance) GetScreenTransform() Transform2D.OriginXY
Returns the transform of this graphics.gd/classdb/CanvasItem in global screen coordinates (i.e. taking window position into account). Mostly useful for editor plugins.
Equals to Instance.GetGlobalTransform if the window is embedded (see graphics.gd/classdb/Viewport.Instance.GuiEmbedSubwindows).
func (Instance) GetTransform ¶
func (self Instance) GetTransform() Transform2D.OriginXY
Returns the transform matrix of this graphics.gd/classdb/CanvasItem.
func (Instance) GetViewportRect ¶
func (self Instance) GetViewportRect() Rect2.PositionSize
Returns this node's viewport boundaries as a [Rect2.PositionSize]. See also graphics.gd/classdb/Node.Instance.GetViewport.
func (Instance) GetViewportTransform ¶
func (self Instance) GetViewportTransform() Transform2D.OriginXY
Returns the transform of this node, converted from its registered canvas's coordinate system to its viewport embedder's coordinate system. See also graphics.gd/classdb/Viewport.Instance.GetFinalTransform and graphics.gd/classdb/Node.Instance.GetViewport.
func (Instance) GetVisibilityLayerBit ¶
Returns true if the layer at the given index is set in Instance.VisibilityLayer.
func (Instance) GetWorld2d ¶
Returns the graphics.gd/classdb/World2D this node is registered to.
Usually, this is the same as this node's viewport (see graphics.gd/classdb/Node.Instance.GetViewport and graphics.gd/classdb/Viewport.Instance.FindWorld2d).
func (Instance) Hide ¶
func (self Instance) Hide()
Hide the graphics.gd/classdb/CanvasItem if it's currently visible. This is equivalent to setting Instance.Visible to false.
func (Instance) IsLocalTransformNotificationEnabled ¶
Returns true if the node receives NotificationLocalTransformChanged whenever its local transform changes. This is enabled with Instance.SetNotifyLocalTransform.
func (Instance) IsTransformNotificationEnabled ¶
Returns true if the node receives NotificationTransformChanged whenever its global transform changes. This is enabled with Instance.SetNotifyTransform.
func (Instance) IsVisibleInTree ¶
Returns true if the node is present in the graphics.gd/classdb/SceneTree, its Instance.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 [Interface.Draw]).
Visibility is checked only in parent nodes that inherit from graphics.gd/classdb/CanvasItem, graphics.gd/classdb/CanvasLayer, and graphics.gd/classdb/Window. If the parent is of any other type (such as graphics.gd/classdb/Node, graphics.gd/classdb/AnimationPlayer, or graphics.gd/classdb/Node3D), it is assumed to be visible.
Note: This method does not take Instance.VisibilityLayer into account, so even if this method returns true, the node might end up not being rendered.
func (Instance) MakeCanvasPositionLocal ¶
Transforms 'viewport_point' from the viewport's coordinates to this node's local coordinates.
For the opposite operation, use Instance.GetGlobalTransformWithCanvas.
var viewport_point = Transform2D.Vector(local_point, canvas_item.GetGlobalTransformWithCanvas())
func (Instance) MakeInputLocal ¶
func (self Instance) MakeInputLocal(event InputEvent.Instance) InputEvent.Instance
Returns a copy of the given 'event' with its coordinates converted from global space to this graphics.gd/classdb/CanvasItem's local space. If not possible, returns the same graphics.gd/classdb/InputEvent unchanged.
func (Instance) MoveToFront ¶
func (self Instance) MoveToFront()
Moves this node below its siblings, usually causing the node to draw on top of its siblings. Does nothing if this node does not have a parent. See also graphics.gd/classdb/Node.Instance.MoveChild.
func (Instance) OnItemRectChanged ¶
func (Instance) OnVisibilityChanged ¶
func (Instance) QueueRedraw ¶
func (self Instance) QueueRedraw()
Queues the graphics.gd/classdb/CanvasItem to redraw. During idle time, if graphics.gd/classdb/CanvasItem is visible, NotificationDraw is sent and [Interface.Draw] is called. This only occurs once per frame, even if this method has been called multiple times.
func (Instance) SelfModulate ¶
func (Instance) SetClipChildren ¶
func (self Instance) SetClipChildren(value ClipChildrenMode)
func (Instance) SetInstanceShaderParameter ¶
Set the value of a shader uniform for this instance only (per-instance uniform). See also graphics.gd/classdb/ShaderMaterial.Instance.SetShaderParameter to assign a uniform on all instances using the same graphics.gd/classdb/ShaderMaterial.
Note: For a shader uniform to be assignable on a per-instance basis, it must be defined with instance uniform ... rather than uniform ... in the shader code.
Note: 'name' is case-sensitive and must match the name of the uniform in the code exactly (not the capitalized name in the inspector).
func (Instance) SetLightMask ¶
func (Instance) SetMaterial ¶
func (Instance) SetModulate ¶
func (Instance) SetNotifyLocalTransform ¶
If true, the node will receive NotificationLocalTransformChanged whenever its local transform changes.
Note: Many canvas items such as graphics.gd/classdb/Bone2D or graphics.gd/classdb/CollisionShape2D automatically enable this in order to function correctly.
func (Instance) SetNotifyTransform ¶
If true, the node will receive NotificationTransformChanged whenever global transform changes.
Note: Many canvas items such as graphics.gd/classdb/Camera2D or graphics.gd/classdb/Light2D automatically enable this in order to function correctly.
func (Instance) SetSelfModulate ¶
func (Instance) SetShowBehindParent ¶
func (Instance) SetTextureFilter ¶
func (self Instance) SetTextureFilter(value TextureFilter)
func (Instance) SetTextureRepeat ¶
func (self Instance) SetTextureRepeat(value TextureRepeat)
func (Instance) SetTopLevel ¶
func (Instance) SetUseParentMaterial ¶
func (Instance) SetVisibilityLayer ¶
func (Instance) SetVisibilityLayerBit ¶
Set/clear individual bits on the rendering visibility layer. This simplifies editing this graphics.gd/classdb/CanvasItem's visibility layer.
func (Instance) SetVisible ¶
func (Instance) SetYSortEnabled ¶
func (Instance) SetZAsRelative ¶
func (Instance) Show ¶
func (self Instance) Show()
Show the graphics.gd/classdb/CanvasItem if it's currently hidden. This is equivalent to setting Instance.Visible to true.
Note: For controls that inherit graphics.gd/classdb/Popup, the correct way to make them visible is to call one of the multiple popup*() functions instead.
func (Instance) ShowBehindParent ¶
func (Instance) TextureFilter ¶
func (self Instance) TextureFilter() TextureFilter
func (Instance) TextureRepeat ¶
func (self Instance) TextureRepeat() TextureRepeat
func (Instance) UseParentMaterial ¶
func (Instance) VisibilityLayer ¶
func (Instance) YSortEnabled ¶
func (Instance) ZAsRelative ¶
type Interface ¶
type Interface interface { // Called when [graphics.gd/classdb/CanvasItem] has been requested to redraw (after [Instance.QueueRedraw] is called, either manually or by the engine). // // Corresponds to the [NotificationDraw] notification in [graphics.gd/classdb/Object.Instance.Notification]. Draw() }
type TextureFilter ¶
type TextureFilter int //gd:CanvasItem.TextureFilter
const ( // The [graphics.gd/classdb/CanvasItem] will inherit the filter from its parent. TextureFilterParentNode TextureFilter = 0 // The texture filter reads from the nearest pixel only. This makes the texture look pixelated from up close, and grainy from a distance (due to mipmaps not being sampled). TextureFilterNearest TextureFilter = 1 // The texture filter blends between the nearest 4 pixels. This makes the texture look smooth from up close, and grainy from a distance (due to mipmaps not being sampled). TextureFilterLinear TextureFilter = 2 // The texture filter reads from the nearest pixel and blends between the nearest 2 mipmaps (or uses the nearest mipmap if [graphics.gd/classdb/ProjectSettings] "rendering/textures/default_filters/use_nearest_mipmap_filter" is true). This makes the texture look pixelated from up close, and smooth from a distance. // // Use this for non-pixel art textures that may be viewed at a low scale (e.g. due to [graphics.gd/classdb/Camera2D] zoom or sprite scaling), as mipmaps are important to smooth out pixels that are smaller than on-screen pixels. TextureFilterNearestWithMipmaps TextureFilter = 3 // The texture filter blends between the nearest 4 pixels and between the nearest 2 mipmaps (or uses the nearest mipmap if [graphics.gd/classdb/ProjectSettings] "rendering/textures/default_filters/use_nearest_mipmap_filter" is true). This makes the texture look smooth from up close, and smooth from a distance. // // Use this for non-pixel art textures that may be viewed at a low scale (e.g. due to [graphics.gd/classdb/Camera2D] zoom or sprite scaling), as mipmaps are important to smooth out pixels that are smaller than on-screen pixels. TextureFilterLinearWithMipmaps TextureFilter = 4 // The texture filter reads from the nearest pixel and blends between 2 mipmaps (or uses the nearest mipmap if [graphics.gd/classdb/ProjectSettings] "rendering/textures/default_filters/use_nearest_mipmap_filter" is true) based on the angle between the surface and the camera view. This makes the texture look pixelated from up close, and smooth from a distance. Anisotropic filtering improves texture quality on surfaces that are almost in line with the camera, but is slightly slower. The anisotropic filtering level can be changed by adjusting [graphics.gd/classdb/ProjectSettings] "rendering/textures/default_filters/anisotropic_filtering_level". // // Note: This texture filter is rarely useful in 2D projects. [TextureFilterNearestWithMipmaps] is usually more appropriate in this case. TextureFilterNearestWithMipmapsAnisotropic TextureFilter = 5 // The texture filter blends between the nearest 4 pixels and blends between 2 mipmaps (or uses the nearest mipmap if [graphics.gd/classdb/ProjectSettings] "rendering/textures/default_filters/use_nearest_mipmap_filter" is true) based on the angle between the surface and the camera view. This makes the texture look smooth from up close, and smooth from a distance. Anisotropic filtering improves texture quality on surfaces that are almost in line with the camera, but is slightly slower. The anisotropic filtering level can be changed by adjusting [graphics.gd/classdb/ProjectSettings] "rendering/textures/default_filters/anisotropic_filtering_level". // // Note: This texture filter is rarely useful in 2D projects. [TextureFilterLinearWithMipmaps] is usually more appropriate in this case. TextureFilterLinearWithMipmapsAnisotropic TextureFilter = 6 // Represents the size of the [TextureFilter] enum. TextureFilterMax TextureFilter = 7 )
type TextureRepeat ¶
type TextureRepeat int //gd:CanvasItem.TextureRepeat
const ( // The [graphics.gd/classdb/CanvasItem] will inherit the filter from its parent. TextureRepeatParentNode TextureRepeat = 0 // The texture does not repeat. Sampling the texture outside its extents will result in "stretching" of the edge pixels. You can avoid this by ensuring a 1-pixel fully transparent border on each side of the texture. TextureRepeatDisabled TextureRepeat = 1 // The texture repeats when exceeding the texture's size. TextureRepeatEnabled TextureRepeat = 2 // The texture repeats when the exceeding the texture's size in a "2×2 tiled mode". Repeated textures at even positions are mirrored. TextureRepeatMirror TextureRepeat = 3 // Represents the size of the [TextureRepeat] enum. TextureRepeatMax TextureRepeat = 4 )