Skip to content

Latest commit

 

History

History
465 lines (282 loc) · 50.7 KB

class_canvasitem.rst

File metadata and controls

465 lines (282 loc) · 50.7 KB

CanvasItem

Inherits: Node<class_node> < Object<class_object>

Inherited By: Node2D<class_node2d>, Control<class_control>

Category: Core

Brief Description

Base class of anything 2D.

Member Functions

void _draw<class_CanvasItem__draw> ( ) virtual
float<class_float> draw_char<class_CanvasItem_draw_char> ( :ref:Font<class_font> font, Vector2<class_vector2> position, String<class_string> char, String<class_string> next, Color<class_color> modulate=Color( 1, 1, 1, 1 ) )
void draw_circle<class_CanvasItem_draw_circle> ( Vector2<class_vector2> position, float<class_float> radius, Color<class_color> color )
void draw_colored_polygon<class_CanvasItem_draw_colored_polygon> ( PoolVector2Array<class_poolvector2array> points, Color<class_color> color, PoolVector2Array<class_poolvector2array> uvs=PoolVector2Array( ), Texture<class_texture> texture=null, Texture<class_texture> normal_map=null, bool<class_bool> antialiased=false )
void draw_line<class_CanvasItem_draw_line> ( Vector2<class_vector2> from, Vector2<class_vector2> to, Color<class_color> color, float<class_float> width=1.0, bool<class_bool> antialiased=false )
void draw_multiline<class_CanvasItem_draw_multiline> ( PoolVector2Array<class_poolvector2array> points, Color<class_color> color, float<class_float> width=1.0, bool<class_bool> antialiased=false )
void draw_multiline_colors<class_CanvasItem_draw_multiline_colors> ( PoolVector2Array<class_poolvector2array> points, PoolColorArray<class_poolcolorarray> colors, float<class_float> width=1.0, bool<class_bool> antialiased=false )
void draw_polygon<class_CanvasItem_draw_polygon> ( PoolVector2Array<class_poolvector2array> points, PoolColorArray<class_poolcolorarray> colors, PoolVector2Array<class_poolvector2array> uvs=PoolVector2Array( ), Texture<class_texture> texture=null, Texture<class_texture> normal_map=null, bool<class_bool> antialiased=false )
void draw_polyline<class_CanvasItem_draw_polyline> ( PoolVector2Array<class_poolvector2array> points, Color<class_color> color, float<class_float> width=1.0, bool<class_bool> antialiased=false )
void draw_polyline_colors<class_CanvasItem_draw_polyline_colors> ( PoolVector2Array<class_poolvector2array> points, PoolColorArray<class_poolcolorarray> colors, float<class_float> width=1.0, bool<class_bool> antialiased=false )
void draw_primitive<class_CanvasItem_draw_primitive> ( PoolVector2Array<class_poolvector2array> points, PoolColorArray<class_poolcolorarray> colors, PoolVector2Array<class_poolvector2array> uvs, Texture<class_texture> texture=null, float<class_float> width=1.0, Texture<class_texture> normal_map=null )
void draw_rect<class_CanvasItem_draw_rect> ( Rect2<class_rect2> rect, Color<class_color> color, bool<class_bool> filled=true )
void draw_set_transform<class_CanvasItem_draw_set_transform> ( Vector2<class_vector2> position, float<class_float> rotation, Vector2<class_vector2> scale )
void draw_set_transform_matrix<class_CanvasItem_draw_set_transform_matrix> ( Transform2D<class_transform2d> xform )
void draw_string<class_CanvasItem_draw_string> ( Font<class_font> font, Vector2<class_vector2> position, String<class_string> text, Color<class_color> modulate=Color( 1, 1, 1, 1 ), int<class_int> clip_w=-1 )
void draw_style_box<class_CanvasItem_draw_style_box> ( StyleBox<class_stylebox> style_box, Rect2<class_rect2> rect )
void draw_texture<class_CanvasItem_draw_texture> ( Texture<class_texture> texture, Vector2<class_vector2> position, Color<class_color> modulate=Color( 1, 1, 1, 1 ), Texture<class_texture> normal_map=null )
void draw_texture_rect<class_CanvasItem_draw_texture_rect> ( Texture<class_texture> texture, Rect2<class_rect2> rect, bool<class_bool> tile, Color<class_color> modulate=Color( 1, 1, 1, 1 ), bool<class_bool> transpose=false, Texture<class_texture> normal_map=null )
void draw_texture_rect_region<class_CanvasItem_draw_texture_rect_region> ( Texture<class_texture> texture, Rect2<class_rect2> rect, Rect2<class_rect2> src_rect, Color<class_color> modulate=Color( 1, 1, 1, 1 ), bool<class_bool> transpose=false, Texture<class_texture> normal_map=null, bool<class_bool> clip_uv=true )
RID<class_rid> get_canvas<class_CanvasItem_get_canvas> ( ) const
RID<class_rid> get_canvas_item<class_CanvasItem_get_canvas_item> ( ) const
Transform2D<class_transform2d> get_canvas_transform<class_CanvasItem_get_canvas_transform> ( ) const
Vector2<class_vector2> get_global_mouse_position<class_CanvasItem_get_global_mouse_position> ( ) const
Transform2D<class_transform2d> get_global_transform<class_CanvasItem_get_global_transform> ( ) const
Transform2D<class_transform2d> get_global_transform_with_canvas<class_CanvasItem_get_global_transform_with_canvas> ( ) const
Vector2<class_vector2> get_local_mouse_position<class_CanvasItem_get_local_mouse_position> ( ) const
Transform2D<class_transform2d> get_transform<class_CanvasItem_get_transform> ( ) const
Rect2<class_rect2> get_viewport_rect<class_CanvasItem_get_viewport_rect> ( ) const
Transform2D<class_transform2d> get_viewport_transform<class_CanvasItem_get_viewport_transform> ( ) const
World2D<class_world2d> get_world_2d<class_CanvasItem_get_world_2d> ( ) const
void hide<class_CanvasItem_hide> ( )
bool<class_bool> is_local_transform_notification_enabled<class_CanvasItem_is_local_transform_notification_enabled> ( ) const
bool<class_bool> is_set_as_toplevel<class_CanvasItem_is_set_as_toplevel> ( ) const
bool<class_bool> is_transform_notification_enabled<class_CanvasItem_is_transform_notification_enabled> ( ) const
bool<class_bool> is_visible_in_tree<class_CanvasItem_is_visible_in_tree> ( ) const
Vector2<class_vector2> make_canvas_position_local<class_CanvasItem_make_canvas_position_local> ( Vector2<class_vector2> screen_point ) const
InputEvent<class_inputevent> make_input_local<class_CanvasItem_make_input_local> ( InputEvent<class_inputevent> event ) const
void set_as_toplevel<class_CanvasItem_set_as_toplevel> ( bool<class_bool> enable )
void set_notify_local_transform<class_CanvasItem_set_notify_local_transform> ( bool<class_bool> enable )
void set_notify_transform<class_CanvasItem_set_notify_transform> ( bool<class_bool> enable )
void show<class_CanvasItem_show> ( )
void update<class_CanvasItem_update> ( )

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.

Member Variables

  • int<class_int> light_mask - The rendering layers in which this CanvasItem responds to Light2D<class_light2d> nodes. Default value: 1.
  • Material<class_material> material - The material applied to textures on this CanvasItem. Default value: null.
  • Color<class_color> modulate - The color applied to textures on this CanvasItem. Default value: Color(1, 1, 1, 1) (opaque "white").
  • Color<class_color> self_modulate - The color applied to textures on this CanvasItem. This is not inherited by children CanvasItems. Default value: Color(1, 1, 1, 1) (opaque "white")..
  • bool<class_bool> show_behind_parent - If true the object draws behind its parent. Default value: false.
  • bool<class_bool> show_on_top - If true the object draws on top of its parent. Default value: true.
  • bool<class_bool> use_parent_material - If true the parent CanvasItem's material<class_CanvasItem_material> property is used as this one's material. Default value: false.
  • bool<class_bool> visible - If true this CanvasItem is drawn. Default value: true.

Numeric Constants

  • NOTIFICATION_TRANSFORM_CHANGED = 29 --- Canvas item transform has changed. Only received if requested.
  • NOTIFICATION_DRAW = 30 --- CanvasItem is requested to draw.
  • NOTIFICATION_VISIBILITY_CHANGED = 31 --- Canvas item visibility has changed.
  • NOTIFICATION_ENTER_CANVAS = 32 --- Canvas item has entered the canvas.
  • NOTIFICATION_EXIT_CANVAS = 33 --- Canvas item has exited the canvas.

Enums

enum BlendMode

  • BLEND_MODE_MIX = 0 --- Mix blending mode. Colors are assumed to be independent of the alpha (opacity) value.
  • BLEND_MODE_ADD = 1 --- Additive blending mode.
  • BLEND_MODE_SUB = 2 --- Subtractive blending mode.
  • BLEND_MODE_MUL = 3 --- Multiplicative blending mode.
  • BLEND_MODE_PREMULT_ALPHA = 4 --- Mix blending mode. Colors are assumed to be premultiplied by the alpha (opacity) value.

Description

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<class_control>, for anything GUI related, and by Node2D<class_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.

Member Function Description

  • void _draw ( ) virtual

Called (if exists) to draw the canvas item.

  • float<class_float> draw_char ( Font<class_font> font, Vector2<class_vector2> position, String<class_string> char, String<class_string> next, Color<class_color> modulate=Color( 1, 1, 1, 1 ) )

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

  • void draw_circle ( Vector2<class_vector2> position, float<class_float> radius, Color<class_color> color )

Draws a colored circle.

  • void draw_colored_polygon ( PoolVector2Array<class_poolvector2array> points, Color<class_color> color, PoolVector2Array<class_poolvector2array> uvs=PoolVector2Array( ), Texture<class_texture> texture=null, Texture<class_texture> normal_map=null, bool<class_bool> antialiased=false )

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

  • void draw_line ( Vector2<class_vector2> from, Vector2<class_vector2> to, Color<class_color> color, float<class_float> width=1.0, bool<class_bool> antialiased=false )

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

  • void draw_multiline ( PoolVector2Array<class_poolvector2array> points, Color<class_color> color, float<class_float> width=1.0, bool<class_bool> antialiased=false )

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

  • void draw_multiline_colors ( PoolVector2Array<class_poolvector2array> points, PoolColorArray<class_poolcolorarray> colors, float<class_float> width=1.0, bool<class_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.

  • void draw_polygon ( PoolVector2Array<class_poolvector2array> points, PoolColorArray<class_poolcolorarray> colors, PoolVector2Array<class_poolvector2array> uvs=PoolVector2Array( ), Texture<class_texture> texture=null, Texture<class_texture> normal_map=null, bool<class_bool> antialiased=false )

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

  • void draw_polyline ( PoolVector2Array<class_poolvector2array> points, Color<class_color> color, float<class_float> width=1.0, bool<class_bool> antialiased=false )

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

  • void draw_polyline_colors ( PoolVector2Array<class_poolvector2array> points, PoolColorArray<class_poolcolorarray> colors, float<class_float> width=1.0, bool<class_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.

  • void draw_primitive ( PoolVector2Array<class_poolvector2array> points, PoolColorArray<class_poolcolorarray> colors, PoolVector2Array<class_poolvector2array> uvs, Texture<class_texture> texture=null, float<class_float> width=1.0, Texture<class_texture> normal_map=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.

  • void draw_rect ( Rect2<class_rect2> rect, Color<class_color> color, bool<class_bool> filled=true )

Draws a colored rectangle.

  • void draw_set_transform ( Vector2<class_vector2> position, float<class_float> rotation, Vector2<class_vector2> scale )

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

  • void draw_set_transform_matrix ( Transform2D<class_transform2d> xform )

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

  • void draw_string ( Font<class_font> font, Vector2<class_vector2> position, String<class_string> text, Color<class_color> modulate=Color( 1, 1, 1, 1 ), int<class_int> clip_w=-1 )

Draws a string using a custom font.

  • void draw_style_box ( StyleBox<class_stylebox> style_box, Rect2<class_rect2> rect )

Draws a styled rectangle.

  • void draw_texture ( Texture<class_texture> texture, Vector2<class_vector2> position, Color<class_color> modulate=Color( 1, 1, 1, 1 ), Texture<class_texture> normal_map=null )

Draws a texture at a given position.

  • void draw_texture_rect ( Texture<class_texture> texture, Rect2<class_rect2> rect, bool<class_bool> tile, Color<class_color> modulate=Color( 1, 1, 1, 1 ), bool<class_bool> transpose=false, Texture<class_texture> normal_map=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.

  • void draw_texture_rect_region ( Texture<class_texture> texture, Rect2<class_rect2> rect, Rect2<class_rect2> src_rect, Color<class_color> modulate=Color( 1, 1, 1, 1 ), bool<class_bool> transpose=false, Texture<class_texture> normal_map=null, bool<class_bool> clip_uv=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.

  • RID<class_rid> get_canvas ( ) const

Return the RID<class_rid> of the World2D<class_world2d> canvas where this item is in.

  • RID<class_rid> get_canvas_item ( ) const

Return the canvas item RID used by VisualServer<class_visualserver> for this item.

  • Transform2D<class_transform2d> get_canvas_transform ( ) const

Get the transform matrix of this item's canvas.

  • Vector2<class_vector2> get_global_mouse_position ( ) const

Get the global position of the mouse.

  • Transform2D<class_transform2d> get_global_transform ( ) const

Get the global transform matrix of this item.

  • Transform2D<class_transform2d> get_global_transform_with_canvas ( ) const

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

  • Vector2<class_vector2> get_local_mouse_position ( ) const

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

  • Transform2D<class_transform2d> get_transform ( ) const

Get the transform matrix of this item.

  • Rect2<class_rect2> get_viewport_rect ( ) const

Get the viewport's boundaries as a Rect2<class_rect2>.

  • Transform2D<class_transform2d> get_viewport_transform ( ) const

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

  • World2D<class_world2d> get_world_2d ( ) const

Get the World2D<class_world2d> where this item is in.

  • void hide ( )

Hide the CanvasItem currently visible.

  • bool<class_bool> is_local_transform_notification_enabled ( ) const

Returns true if local transform notifications are communicated to children.

  • bool<class_bool> is_set_as_toplevel ( ) const

Return if set as toplevel. See set_as_toplevel<class_CanvasItem_set_as_toplevel>.

  • bool<class_bool> is_transform_notification_enabled ( ) const

Returns true if global transform notifications are communicated to children.

  • bool<class_bool> is_visible_in_tree ( ) const

Returns true if the node is present in the SceneTree<class_scenetree>, its visible<class_CanvasItem_visible> property is true and its inherited visibility is also true.

  • Vector2<class_vector2> make_canvas_position_local ( Vector2<class_vector2> screen_point ) const

Assigns screen_point as this node's new local transform.

  • InputEvent<class_inputevent> make_input_local ( InputEvent<class_inputevent> event ) const

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

  • void set_as_toplevel ( bool<class_bool> enable )

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

  • void set_notify_local_transform ( bool<class_bool> enable )

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

  • void set_notify_transform ( bool<class_bool> enable )

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

  • void show ( )

Show the CanvasItem currently hidden.

  • void update ( )

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