class_canvasitem.rst 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/3.5/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.5/doc/classes/CanvasItem.xml.
  6. .. _class_CanvasItem:
  7. CanvasItem
  8. ==========
  9. **Inherits:** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`Control<class_Control>`, :ref:`Node2D<class_Node2D>`
  11. Base class of anything 2D.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. 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 :ref:`Control<class_Control>` for anything GUI-related, and by :ref:`Node2D<class_Node2D>` for anything related to the 2D engine.
  16. Any **CanvasItem** can draw. For this, :ref:`update<class_CanvasItem_method_update>` is called by the engine, then :ref:`NOTIFICATION_DRAW<class_CanvasItem_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 :ref:`_draw<class_CanvasItem_method__draw>`, its corresponding :ref:`Object._notification<class_Object_method__notification>` or methods connected to the :ref:`draw<class_CanvasItem_signal_draw>` signal.
  17. 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.
  18. 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.
  19. Ultimately, a transform notification can be requested, which will notify the node that its global position changed in case the parent tree changed.
  20. \ **Note:** Unless otherwise specified, all methods that have angle parameters must have angles specified as *radians*. To convert degrees to radians, use :ref:`@GDScript.deg2rad<class_@GDScript_method_deg2rad>`.
  21. .. rst-class:: classref-introduction-group
  22. Tutorials
  23. ---------
  24. - :doc:`Viewport and canvas transforms <../tutorials/2d/2d_transforms>`
  25. - :doc:`Custom drawing in 2D <../tutorials/2d/custom_drawing_in_2d>`
  26. - `Audio Spectrum Demo <https://godotengine.org/asset-library/asset/528>`__
  27. .. rst-class:: classref-reftable-group
  28. Properties
  29. ----------
  30. .. table::
  31. :widths: auto
  32. +---------------------------------+---------------------------------------------------------------------------+-------------------------+
  33. | :ref:`int<class_int>` | :ref:`light_mask<class_CanvasItem_property_light_mask>` | ``1`` |
  34. +---------------------------------+---------------------------------------------------------------------------+-------------------------+
  35. | :ref:`Material<class_Material>` | :ref:`material<class_CanvasItem_property_material>` | |
  36. +---------------------------------+---------------------------------------------------------------------------+-------------------------+
  37. | :ref:`Color<class_Color>` | :ref:`modulate<class_CanvasItem_property_modulate>` | ``Color( 1, 1, 1, 1 )`` |
  38. +---------------------------------+---------------------------------------------------------------------------+-------------------------+
  39. | :ref:`Color<class_Color>` | :ref:`self_modulate<class_CanvasItem_property_self_modulate>` | ``Color( 1, 1, 1, 1 )`` |
  40. +---------------------------------+---------------------------------------------------------------------------+-------------------------+
  41. | :ref:`bool<class_bool>` | :ref:`show_behind_parent<class_CanvasItem_property_show_behind_parent>` | ``false`` |
  42. +---------------------------------+---------------------------------------------------------------------------+-------------------------+
  43. | :ref:`bool<class_bool>` | :ref:`show_on_top<class_CanvasItem_property_show_on_top>` | |
  44. +---------------------------------+---------------------------------------------------------------------------+-------------------------+
  45. | :ref:`bool<class_bool>` | :ref:`use_parent_material<class_CanvasItem_property_use_parent_material>` | ``false`` |
  46. +---------------------------------+---------------------------------------------------------------------------+-------------------------+
  47. | :ref:`bool<class_bool>` | :ref:`visible<class_CanvasItem_property_visible>` | ``true`` |
  48. +---------------------------------+---------------------------------------------------------------------------+-------------------------+
  49. .. rst-class:: classref-reftable-group
  50. Methods
  51. -------
  52. .. table::
  53. :widths: auto
  54. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`_draw<class_CanvasItem_method__draw>` **(** **)** |virtual| |
  56. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`draw_arc<class_CanvasItem_method_draw_arc>` **(** :ref:`Vector2<class_Vector2>` center, :ref:`float<class_float>` radius, :ref:`float<class_float>` start_angle, :ref:`float<class_float>` end_angle, :ref:`int<class_int>` point_count, :ref:`Color<class_Color>` color, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)** |
  58. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`float<class_float>` | :ref:`draw_char<class_CanvasItem_method_draw_char>` **(** :ref:`Font<class_Font>` font, :ref:`Vector2<class_Vector2>` position, :ref:`String<class_String>` char, :ref:`String<class_String>` next, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ) **)** |
  60. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | void | :ref:`draw_circle<class_CanvasItem_method_draw_circle>` **(** :ref:`Vector2<class_Vector2>` position, :ref:`float<class_float>` radius, :ref:`Color<class_Color>` color **)** |
  62. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | void | :ref:`draw_colored_polygon<class_CanvasItem_method_draw_colored_polygon>` **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`Color<class_Color>` color, :ref:`PoolVector2Array<class_PoolVector2Array>` uvs=PoolVector2Array( ), :ref:`Texture<class_Texture>` texture=null, :ref:`Texture<class_Texture>` normal_map=null, :ref:`bool<class_bool>` antialiased=false **)** |
  64. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | void | :ref:`draw_line<class_CanvasItem_method_draw_line>` **(** :ref:`Vector2<class_Vector2>` from, :ref:`Vector2<class_Vector2>` to, :ref:`Color<class_Color>` color, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)** |
  66. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | void | :ref:`draw_mesh<class_CanvasItem_method_draw_mesh>` **(** :ref:`Mesh<class_Mesh>` mesh, :ref:`Texture<class_Texture>` texture, :ref:`Texture<class_Texture>` normal_map=null, :ref:`Transform2D<class_Transform2D>` transform=Transform2D( 1, 0, 0, 1, 0, 0 ), :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ) **)** |
  68. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | void | :ref:`draw_multiline<class_CanvasItem_method_draw_multiline>` **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`Color<class_Color>` color, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)** |
  70. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | void | :ref:`draw_multiline_colors<class_CanvasItem_method_draw_multiline_colors>` **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`PoolColorArray<class_PoolColorArray>` colors, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)** |
  72. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | void | :ref:`draw_multimesh<class_CanvasItem_method_draw_multimesh>` **(** :ref:`MultiMesh<class_MultiMesh>` multimesh, :ref:`Texture<class_Texture>` texture, :ref:`Texture<class_Texture>` normal_map=null **)** |
  74. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | void | :ref:`draw_polygon<class_CanvasItem_method_draw_polygon>` **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`PoolColorArray<class_PoolColorArray>` colors, :ref:`PoolVector2Array<class_PoolVector2Array>` uvs=PoolVector2Array( ), :ref:`Texture<class_Texture>` texture=null, :ref:`Texture<class_Texture>` normal_map=null, :ref:`bool<class_bool>` antialiased=false **)** |
  76. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | void | :ref:`draw_polyline<class_CanvasItem_method_draw_polyline>` **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`Color<class_Color>` color, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)** |
  78. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | void | :ref:`draw_polyline_colors<class_CanvasItem_method_draw_polyline_colors>` **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`PoolColorArray<class_PoolColorArray>` colors, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)** |
  80. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. | void | :ref:`draw_primitive<class_CanvasItem_method_draw_primitive>` **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`PoolColorArray<class_PoolColorArray>` colors, :ref:`PoolVector2Array<class_PoolVector2Array>` uvs, :ref:`Texture<class_Texture>` texture=null, :ref:`float<class_float>` width=1.0, :ref:`Texture<class_Texture>` normal_map=null **)** |
  82. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. | void | :ref:`draw_rect<class_CanvasItem_method_draw_rect>` **(** :ref:`Rect2<class_Rect2>` rect, :ref:`Color<class_Color>` color, :ref:`bool<class_bool>` filled=true, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)** |
  84. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  85. | void | :ref:`draw_set_transform<class_CanvasItem_method_draw_set_transform>` **(** :ref:`Vector2<class_Vector2>` position, :ref:`float<class_float>` rotation, :ref:`Vector2<class_Vector2>` scale **)** |
  86. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  87. | void | :ref:`draw_set_transform_matrix<class_CanvasItem_method_draw_set_transform_matrix>` **(** :ref:`Transform2D<class_Transform2D>` xform **)** |
  88. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  89. | void | :ref:`draw_string<class_CanvasItem_method_draw_string>` **(** :ref:`Font<class_Font>` font, :ref:`Vector2<class_Vector2>` position, :ref:`String<class_String>` text, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`int<class_int>` clip_w=-1 **)** |
  90. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  91. | void | :ref:`draw_style_box<class_CanvasItem_method_draw_style_box>` **(** :ref:`StyleBox<class_StyleBox>` style_box, :ref:`Rect2<class_Rect2>` rect **)** |
  92. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  93. | void | :ref:`draw_texture<class_CanvasItem_method_draw_texture>` **(** :ref:`Texture<class_Texture>` texture, :ref:`Vector2<class_Vector2>` position, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`Texture<class_Texture>` normal_map=null **)** |
  94. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  95. | void | :ref:`draw_texture_rect<class_CanvasItem_method_draw_texture_rect>` **(** :ref:`Texture<class_Texture>` texture, :ref:`Rect2<class_Rect2>` rect, :ref:`bool<class_bool>` tile, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`bool<class_bool>` transpose=false, :ref:`Texture<class_Texture>` normal_map=null **)** |
  96. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  97. | void | :ref:`draw_texture_rect_region<class_CanvasItem_method_draw_texture_rect_region>` **(** :ref:`Texture<class_Texture>` texture, :ref:`Rect2<class_Rect2>` rect, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`bool<class_bool>` transpose=false, :ref:`Texture<class_Texture>` normal_map=null, :ref:`bool<class_bool>` clip_uv=true **)** |
  98. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  99. | void | :ref:`force_update_transform<class_CanvasItem_method_force_update_transform>` **(** **)** |
  100. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  101. | :ref:`RID<class_RID>` | :ref:`get_canvas<class_CanvasItem_method_get_canvas>` **(** **)** |const| |
  102. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  103. | :ref:`RID<class_RID>` | :ref:`get_canvas_item<class_CanvasItem_method_get_canvas_item>` **(** **)** |const| |
  104. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  105. | :ref:`Transform2D<class_Transform2D>` | :ref:`get_canvas_transform<class_CanvasItem_method_get_canvas_transform>` **(** **)** |const| |
  106. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  107. | :ref:`Vector2<class_Vector2>` | :ref:`get_global_mouse_position<class_CanvasItem_method_get_global_mouse_position>` **(** **)** |const| |
  108. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  109. | :ref:`Transform2D<class_Transform2D>` | :ref:`get_global_transform<class_CanvasItem_method_get_global_transform>` **(** **)** |const| |
  110. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  111. | :ref:`Transform2D<class_Transform2D>` | :ref:`get_global_transform_with_canvas<class_CanvasItem_method_get_global_transform_with_canvas>` **(** **)** |const| |
  112. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  113. | :ref:`Vector2<class_Vector2>` | :ref:`get_local_mouse_position<class_CanvasItem_method_get_local_mouse_position>` **(** **)** |const| |
  114. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  115. | :ref:`Transform2D<class_Transform2D>` | :ref:`get_transform<class_CanvasItem_method_get_transform>` **(** **)** |const| |
  116. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  117. | :ref:`Rect2<class_Rect2>` | :ref:`get_viewport_rect<class_CanvasItem_method_get_viewport_rect>` **(** **)** |const| |
  118. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  119. | :ref:`Transform2D<class_Transform2D>` | :ref:`get_viewport_transform<class_CanvasItem_method_get_viewport_transform>` **(** **)** |const| |
  120. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  121. | :ref:`World2D<class_World2D>` | :ref:`get_world_2d<class_CanvasItem_method_get_world_2d>` **(** **)** |const| |
  122. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  123. | void | :ref:`hide<class_CanvasItem_method_hide>` **(** **)** |
  124. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  125. | :ref:`bool<class_bool>` | :ref:`is_local_transform_notification_enabled<class_CanvasItem_method_is_local_transform_notification_enabled>` **(** **)** |const| |
  126. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  127. | :ref:`bool<class_bool>` | :ref:`is_set_as_toplevel<class_CanvasItem_method_is_set_as_toplevel>` **(** **)** |const| |
  128. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  129. | :ref:`bool<class_bool>` | :ref:`is_transform_notification_enabled<class_CanvasItem_method_is_transform_notification_enabled>` **(** **)** |const| |
  130. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  131. | :ref:`bool<class_bool>` | :ref:`is_visible_in_tree<class_CanvasItem_method_is_visible_in_tree>` **(** **)** |const| |
  132. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  133. | :ref:`Vector2<class_Vector2>` | :ref:`make_canvas_position_local<class_CanvasItem_method_make_canvas_position_local>` **(** :ref:`Vector2<class_Vector2>` screen_point **)** |const| |
  134. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  135. | :ref:`InputEvent<class_InputEvent>` | :ref:`make_input_local<class_CanvasItem_method_make_input_local>` **(** :ref:`InputEvent<class_InputEvent>` event **)** |const| |
  136. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  137. | void | :ref:`set_as_toplevel<class_CanvasItem_method_set_as_toplevel>` **(** :ref:`bool<class_bool>` enable **)** |
  138. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  139. | void | :ref:`set_notify_local_transform<class_CanvasItem_method_set_notify_local_transform>` **(** :ref:`bool<class_bool>` enable **)** |
  140. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  141. | void | :ref:`set_notify_transform<class_CanvasItem_method_set_notify_transform>` **(** :ref:`bool<class_bool>` enable **)** |
  142. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  143. | void | :ref:`show<class_CanvasItem_method_show>` **(** **)** |
  144. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  145. | void | :ref:`update<class_CanvasItem_method_update>` **(** **)** |
  146. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  147. .. rst-class:: classref-section-separator
  148. ----
  149. .. rst-class:: classref-descriptions-group
  150. Signals
  151. -------
  152. .. _class_CanvasItem_signal_draw:
  153. .. rst-class:: classref-signal
  154. **draw** **(** **)**
  155. Emitted when the **CanvasItem** must redraw, *after* the related :ref:`NOTIFICATION_DRAW<class_CanvasItem_constant_NOTIFICATION_DRAW>` notification, and *before* :ref:`_draw<class_CanvasItem_method__draw>` is called.
  156. \ **Note:** Deferred connections do not allow drawing through the ``draw_*`` methods.
  157. .. rst-class:: classref-item-separator
  158. ----
  159. .. _class_CanvasItem_signal_hide:
  160. .. rst-class:: classref-signal
  161. **hide** **(** **)**
  162. Emitted when becoming hidden.
  163. .. rst-class:: classref-item-separator
  164. ----
  165. .. _class_CanvasItem_signal_item_rect_changed:
  166. .. rst-class:: classref-signal
  167. **item_rect_changed** **(** **)**
  168. Emitted when the item's :ref:`Rect2<class_Rect2>` boundaries (position or size) have changed, or when an action is taking place that may have impacted these boundaries (e.g. changing :ref:`Sprite.texture<class_Sprite_property_texture>`).
  169. .. rst-class:: classref-item-separator
  170. ----
  171. .. _class_CanvasItem_signal_visibility_changed:
  172. .. rst-class:: classref-signal
  173. **visibility_changed** **(** **)**
  174. Emitted when the visibility (hidden/visible) changes.
  175. .. rst-class:: classref-section-separator
  176. ----
  177. .. rst-class:: classref-descriptions-group
  178. Enumerations
  179. ------------
  180. .. _enum_CanvasItem_BlendMode:
  181. .. rst-class:: classref-enumeration
  182. enum **BlendMode**:
  183. .. _class_CanvasItem_constant_BLEND_MODE_MIX:
  184. .. rst-class:: classref-enumeration-constant
  185. :ref:`BlendMode<enum_CanvasItem_BlendMode>` **BLEND_MODE_MIX** = ``0``
  186. Mix blending mode. Colors are assumed to be independent of the alpha (opacity) value.
  187. .. _class_CanvasItem_constant_BLEND_MODE_ADD:
  188. .. rst-class:: classref-enumeration-constant
  189. :ref:`BlendMode<enum_CanvasItem_BlendMode>` **BLEND_MODE_ADD** = ``1``
  190. Additive blending mode.
  191. .. _class_CanvasItem_constant_BLEND_MODE_SUB:
  192. .. rst-class:: classref-enumeration-constant
  193. :ref:`BlendMode<enum_CanvasItem_BlendMode>` **BLEND_MODE_SUB** = ``2``
  194. Subtractive blending mode.
  195. .. _class_CanvasItem_constant_BLEND_MODE_MUL:
  196. .. rst-class:: classref-enumeration-constant
  197. :ref:`BlendMode<enum_CanvasItem_BlendMode>` **BLEND_MODE_MUL** = ``3``
  198. Multiplicative blending mode.
  199. .. _class_CanvasItem_constant_BLEND_MODE_PREMULT_ALPHA:
  200. .. rst-class:: classref-enumeration-constant
  201. :ref:`BlendMode<enum_CanvasItem_BlendMode>` **BLEND_MODE_PREMULT_ALPHA** = ``4``
  202. Mix blending mode. Colors are assumed to be premultiplied by the alpha (opacity) value.
  203. .. _class_CanvasItem_constant_BLEND_MODE_DISABLED:
  204. .. rst-class:: classref-enumeration-constant
  205. :ref:`BlendMode<enum_CanvasItem_BlendMode>` **BLEND_MODE_DISABLED** = ``5``
  206. Disables blending mode. Colors including alpha are written as-is. Only applicable for render targets with a transparent background. No lighting will be applied.
  207. .. rst-class:: classref-section-separator
  208. ----
  209. .. rst-class:: classref-descriptions-group
  210. Constants
  211. ---------
  212. .. _class_CanvasItem_constant_NOTIFICATION_TRANSFORM_CHANGED:
  213. .. rst-class:: classref-constant
  214. **NOTIFICATION_TRANSFORM_CHANGED** = ``2000``
  215. The **CanvasItem**'s global transform has changed. This notification is only received if enabled by :ref:`set_notify_transform<class_CanvasItem_method_set_notify_transform>`.
  216. .. _class_CanvasItem_constant_NOTIFICATION_LOCAL_TRANSFORM_CHANGED:
  217. .. rst-class:: classref-constant
  218. **NOTIFICATION_LOCAL_TRANSFORM_CHANGED** = ``35``
  219. The **CanvasItem**'s local transform has changed. This notification is only received if enabled by :ref:`set_notify_local_transform<class_CanvasItem_method_set_notify_local_transform>`.
  220. .. _class_CanvasItem_constant_NOTIFICATION_DRAW:
  221. .. rst-class:: classref-constant
  222. **NOTIFICATION_DRAW** = ``30``
  223. The **CanvasItem** is requested to draw (see :ref:`_draw<class_CanvasItem_method__draw>`).
  224. .. _class_CanvasItem_constant_NOTIFICATION_VISIBILITY_CHANGED:
  225. .. rst-class:: classref-constant
  226. **NOTIFICATION_VISIBILITY_CHANGED** = ``31``
  227. The **CanvasItem**'s visibility has changed.
  228. .. _class_CanvasItem_constant_NOTIFICATION_ENTER_CANVAS:
  229. .. rst-class:: classref-constant
  230. **NOTIFICATION_ENTER_CANVAS** = ``32``
  231. The **CanvasItem** has entered the canvas.
  232. .. _class_CanvasItem_constant_NOTIFICATION_EXIT_CANVAS:
  233. .. rst-class:: classref-constant
  234. **NOTIFICATION_EXIT_CANVAS** = ``33``
  235. The **CanvasItem** has exited the canvas.
  236. .. rst-class:: classref-section-separator
  237. ----
  238. .. rst-class:: classref-descriptions-group
  239. Property Descriptions
  240. ---------------------
  241. .. _class_CanvasItem_property_light_mask:
  242. .. rst-class:: classref-property
  243. :ref:`int<class_int>` **light_mask** = ``1``
  244. .. rst-class:: classref-property-setget
  245. - void **set_light_mask** **(** :ref:`int<class_int>` value **)**
  246. - :ref:`int<class_int>` **get_light_mask** **(** **)**
  247. The rendering layers in which this **CanvasItem** responds to :ref:`Light2D<class_Light2D>` nodes.
  248. .. rst-class:: classref-item-separator
  249. ----
  250. .. _class_CanvasItem_property_material:
  251. .. rst-class:: classref-property
  252. :ref:`Material<class_Material>` **material**
  253. .. rst-class:: classref-property-setget
  254. - void **set_material** **(** :ref:`Material<class_Material>` value **)**
  255. - :ref:`Material<class_Material>` **get_material** **(** **)**
  256. The material applied to textures on this **CanvasItem**.
  257. .. rst-class:: classref-item-separator
  258. ----
  259. .. _class_CanvasItem_property_modulate:
  260. .. rst-class:: classref-property
  261. :ref:`Color<class_Color>` **modulate** = ``Color( 1, 1, 1, 1 )``
  262. .. rst-class:: classref-property-setget
  263. - void **set_modulate** **(** :ref:`Color<class_Color>` value **)**
  264. - :ref:`Color<class_Color>` **get_modulate** **(** **)**
  265. The color applied to textures on this **CanvasItem**.
  266. .. rst-class:: classref-item-separator
  267. ----
  268. .. _class_CanvasItem_property_self_modulate:
  269. .. rst-class:: classref-property
  270. :ref:`Color<class_Color>` **self_modulate** = ``Color( 1, 1, 1, 1 )``
  271. .. rst-class:: classref-property-setget
  272. - void **set_self_modulate** **(** :ref:`Color<class_Color>` value **)**
  273. - :ref:`Color<class_Color>` **get_self_modulate** **(** **)**
  274. The color applied to textures on this **CanvasItem**. This is not inherited by children **CanvasItem**\ s.
  275. .. rst-class:: classref-item-separator
  276. ----
  277. .. _class_CanvasItem_property_show_behind_parent:
  278. .. rst-class:: classref-property
  279. :ref:`bool<class_bool>` **show_behind_parent** = ``false``
  280. .. rst-class:: classref-property-setget
  281. - void **set_draw_behind_parent** **(** :ref:`bool<class_bool>` value **)**
  282. - :ref:`bool<class_bool>` **is_draw_behind_parent_enabled** **(** **)**
  283. If ``true``, the object draws behind its parent.
  284. .. rst-class:: classref-item-separator
  285. ----
  286. .. _class_CanvasItem_property_show_on_top:
  287. .. rst-class:: classref-property
  288. :ref:`bool<class_bool>` **show_on_top**
  289. If ``true``, the object draws on top of its parent.
  290. .. rst-class:: classref-item-separator
  291. ----
  292. .. _class_CanvasItem_property_use_parent_material:
  293. .. rst-class:: classref-property
  294. :ref:`bool<class_bool>` **use_parent_material** = ``false``
  295. .. rst-class:: classref-property-setget
  296. - void **set_use_parent_material** **(** :ref:`bool<class_bool>` value **)**
  297. - :ref:`bool<class_bool>` **get_use_parent_material** **(** **)**
  298. If ``true``, the parent **CanvasItem**'s :ref:`material<class_CanvasItem_property_material>` property is used as this one's material.
  299. .. rst-class:: classref-item-separator
  300. ----
  301. .. _class_CanvasItem_property_visible:
  302. .. rst-class:: classref-property
  303. :ref:`bool<class_bool>` **visible** = ``true``
  304. .. rst-class:: classref-property-setget
  305. - void **set_visible** **(** :ref:`bool<class_bool>` value **)**
  306. - :ref:`bool<class_bool>` **is_visible** **(** **)**
  307. If ``true``, this **CanvasItem** is drawn. The node is only visible if all of its ancestors are visible as well (in other words, :ref:`is_visible_in_tree<class_CanvasItem_method_is_visible_in_tree>` must return ``true``).
  308. \ **Note:** For controls that inherit :ref:`Popup<class_Popup>`, the correct way to make them visible is to call one of the multiple ``popup*()`` functions instead.
  309. .. rst-class:: classref-section-separator
  310. ----
  311. .. rst-class:: classref-descriptions-group
  312. Method Descriptions
  313. -------------------
  314. .. _class_CanvasItem_method__draw:
  315. .. rst-class:: classref-method
  316. void **_draw** **(** **)** |virtual|
  317. Called when **CanvasItem** has been requested to redraw (when :ref:`update<class_CanvasItem_method_update>` is called, either manually or by the engine).
  318. Corresponds to the :ref:`NOTIFICATION_DRAW<class_CanvasItem_constant_NOTIFICATION_DRAW>` notification in :ref:`Object._notification<class_Object_method__notification>`.
  319. .. rst-class:: classref-item-separator
  320. ----
  321. .. _class_CanvasItem_method_draw_arc:
  322. .. rst-class:: classref-method
  323. void **draw_arc** **(** :ref:`Vector2<class_Vector2>` center, :ref:`float<class_float>` radius, :ref:`float<class_float>` start_angle, :ref:`float<class_float>` end_angle, :ref:`int<class_int>` point_count, :ref:`Color<class_Color>` color, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)**
  324. Draws a unfilled arc between the given angles. The larger the value of ``point_count``, the smoother the curve. See also :ref:`draw_circle<class_CanvasItem_method_draw_circle>`.
  325. \ **Note:** Line drawing is not accelerated by batching if ``antialiased`` is ``true``.
  326. \ **Note:** Due to how it works, built-in antialiasing will not look correct for translucent lines and may not work on certain platforms. As a workaround, install the `Antialiased Line2D <https://github.com/godot-extended-libraries/godot-antialiased-line2d>`__ add-on then create an AntialiasedRegularPolygon2D node. That node relies on a texture with custom mipmaps to perform antialiasing. 2D batching is also still supported with those antialiased lines.
  327. .. rst-class:: classref-item-separator
  328. ----
  329. .. _class_CanvasItem_method_draw_char:
  330. .. rst-class:: classref-method
  331. :ref:`float<class_float>` **draw_char** **(** :ref:`Font<class_Font>` font, :ref:`Vector2<class_Vector2>` position, :ref:`String<class_String>` char, :ref:`String<class_String>` next, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ) **)**
  332. Draws a string character using a custom font. Returns the advance, depending on the character width and kerning with an optional next character.
  333. .. rst-class:: classref-item-separator
  334. ----
  335. .. _class_CanvasItem_method_draw_circle:
  336. .. rst-class:: classref-method
  337. void **draw_circle** **(** :ref:`Vector2<class_Vector2>` position, :ref:`float<class_float>` radius, :ref:`Color<class_Color>` color **)**
  338. Draws a colored, filled circle. See also :ref:`draw_arc<class_CanvasItem_method_draw_arc>`, :ref:`draw_polyline<class_CanvasItem_method_draw_polyline>` and :ref:`draw_polygon<class_CanvasItem_method_draw_polygon>`.
  339. \ **Note:** Built-in antialiasing is not provided for :ref:`draw_circle<class_CanvasItem_method_draw_circle>`. As a workaround, install the `Antialiased Line2D <https://github.com/godot-extended-libraries/godot-antialiased-line2d>`__ add-on then create an AntialiasedRegularPolygon2D node. That node relies on a texture with custom mipmaps to perform antialiasing.
  340. .. rst-class:: classref-item-separator
  341. ----
  342. .. _class_CanvasItem_method_draw_colored_polygon:
  343. .. rst-class:: classref-method
  344. void **draw_colored_polygon** **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`Color<class_Color>` color, :ref:`PoolVector2Array<class_PoolVector2Array>` uvs=PoolVector2Array( ), :ref:`Texture<class_Texture>` texture=null, :ref:`Texture<class_Texture>` normal_map=null, :ref:`bool<class_bool>` antialiased=false **)**
  345. Draws a colored polygon of any amount of points, convex or concave. Unlike :ref:`draw_polygon<class_CanvasItem_method_draw_polygon>`, a single color must be specified for the whole polygon.
  346. \ **Note:** Due to how it works, built-in antialiasing will not look correct for translucent polygons and may not work on certain platforms. As a workaround, install the `Antialiased Line2D <https://github.com/godot-extended-libraries/godot-antialiased-line2d>`__ add-on then create an AntialiasedPolygon2D node. That node relies on a texture with custom mipmaps to perform antialiasing.
  347. .. rst-class:: classref-item-separator
  348. ----
  349. .. _class_CanvasItem_method_draw_line:
  350. .. rst-class:: classref-method
  351. void **draw_line** **(** :ref:`Vector2<class_Vector2>` from, :ref:`Vector2<class_Vector2>` to, :ref:`Color<class_Color>` color, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)**
  352. Draws a line from a 2D point to another, with a given color and width. It can be optionally antialiased. See also :ref:`draw_multiline<class_CanvasItem_method_draw_multiline>` and :ref:`draw_polyline<class_CanvasItem_method_draw_polyline>`.
  353. \ **Note:** Line drawing is not accelerated by batching if ``antialiased`` is ``true``.
  354. \ **Note:** Due to how it works, built-in antialiasing will not look correct for translucent lines and may not work on certain platforms. As a workaround, install the `Antialiased Line2D <https://github.com/godot-extended-libraries/godot-antialiased-line2d>`__ add-on then create an AntialiasedLine2D node. That node relies on a texture with custom mipmaps to perform antialiasing. 2D batching is also still supported with those antialiased lines.
  355. .. rst-class:: classref-item-separator
  356. ----
  357. .. _class_CanvasItem_method_draw_mesh:
  358. .. rst-class:: classref-method
  359. void **draw_mesh** **(** :ref:`Mesh<class_Mesh>` mesh, :ref:`Texture<class_Texture>` texture, :ref:`Texture<class_Texture>` normal_map=null, :ref:`Transform2D<class_Transform2D>` transform=Transform2D( 1, 0, 0, 1, 0, 0 ), :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ) **)**
  360. Draws a :ref:`Mesh<class_Mesh>` in 2D, using the provided texture. See :ref:`MeshInstance2D<class_MeshInstance2D>` for related documentation.
  361. .. rst-class:: classref-item-separator
  362. ----
  363. .. _class_CanvasItem_method_draw_multiline:
  364. .. rst-class:: classref-method
  365. void **draw_multiline** **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`Color<class_Color>` color, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)**
  366. Draws multiple disconnected lines with a uniform ``color``. When drawing large amounts of lines, this is faster than using individual :ref:`draw_line<class_CanvasItem_method_draw_line>` calls. To draw interconnected lines, use :ref:`draw_polyline<class_CanvasItem_method_draw_polyline>` instead.
  367. \ **Note:** ``width`` and ``antialiased`` are currently not implemented and have no effect. As a workaround, install the `Antialiased Line2D <https://github.com/godot-extended-libraries/godot-antialiased-line2d>`__ add-on then create an AntialiasedLine2D node. That node relies on a texture with custom mipmaps to perform antialiasing. 2D batching is also still supported with those antialiased lines.
  368. .. rst-class:: classref-item-separator
  369. ----
  370. .. _class_CanvasItem_method_draw_multiline_colors:
  371. .. rst-class:: classref-method
  372. void **draw_multiline_colors** **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`PoolColorArray<class_PoolColorArray>` colors, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)**
  373. Draws multiple disconnected lines with a uniform ``width`` and segment-by-segment coloring. Colors assigned to line segments match by index between ``points`` and ``colors``. When drawing large amounts of lines, this is faster than using individual :ref:`draw_line<class_CanvasItem_method_draw_line>` calls. To draw interconnected lines, use :ref:`draw_polyline_colors<class_CanvasItem_method_draw_polyline_colors>` instead.
  374. \ **Note:** ``width`` and ``antialiased`` are currently not implemented and have no effect. As a workaround, install the `Antialiased Line2D <https://github.com/godot-extended-libraries/godot-antialiased-line2d>`__ add-on then create an AntialiasedLine2D node. That node relies on a texture with custom mipmaps to perform antialiasing. 2D batching is also still supported with those antialiased lines.
  375. .. rst-class:: classref-item-separator
  376. ----
  377. .. _class_CanvasItem_method_draw_multimesh:
  378. .. rst-class:: classref-method
  379. void **draw_multimesh** **(** :ref:`MultiMesh<class_MultiMesh>` multimesh, :ref:`Texture<class_Texture>` texture, :ref:`Texture<class_Texture>` normal_map=null **)**
  380. Draws a :ref:`MultiMesh<class_MultiMesh>` in 2D with the provided texture. See :ref:`MultiMeshInstance2D<class_MultiMeshInstance2D>` for related documentation.
  381. .. rst-class:: classref-item-separator
  382. ----
  383. .. _class_CanvasItem_method_draw_polygon:
  384. .. rst-class:: classref-method
  385. void **draw_polygon** **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`PoolColorArray<class_PoolColorArray>` colors, :ref:`PoolVector2Array<class_PoolVector2Array>` uvs=PoolVector2Array( ), :ref:`Texture<class_Texture>` texture=null, :ref:`Texture<class_Texture>` normal_map=null, :ref:`bool<class_bool>` antialiased=false **)**
  386. Draws a solid polygon of any amount of points, convex or concave. Unlike :ref:`draw_colored_polygon<class_CanvasItem_method_draw_colored_polygon>`, each point's color can be changed individually. See also :ref:`draw_polyline<class_CanvasItem_method_draw_polyline>` and :ref:`draw_polyline_colors<class_CanvasItem_method_draw_polyline_colors>`.
  387. \ **Note:** Due to how it works, built-in antialiasing will not look correct for translucent polygons and may not work on certain platforms. As a workaround, install the `Antialiased Line2D <https://github.com/godot-extended-libraries/godot-antialiased-line2d>`__ add-on then create an AntialiasedPolygon2D node. That node relies on a texture with custom mipmaps to perform antialiasing.
  388. .. rst-class:: classref-item-separator
  389. ----
  390. .. _class_CanvasItem_method_draw_polyline:
  391. .. rst-class:: classref-method
  392. void **draw_polyline** **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`Color<class_Color>` color, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)**
  393. Draws interconnected line segments with a uniform ``color`` and ``width`` and optional antialiasing. When drawing large amounts of lines, this is faster than using individual :ref:`draw_line<class_CanvasItem_method_draw_line>` calls. To draw disconnected lines, use :ref:`draw_multiline<class_CanvasItem_method_draw_multiline>` instead. See also :ref:`draw_polygon<class_CanvasItem_method_draw_polygon>`.
  394. \ **Note:** Due to how it works, built-in antialiasing will not look correct for translucent polygons and may not work on certain platforms. As a workaround, install the `Antialiased Line2D <https://github.com/godot-extended-libraries/godot-antialiased-line2d>`__ add-on then create an AntialiasedPolygon2D node. That node relies on a texture with custom mipmaps to perform antialiasing.
  395. .. rst-class:: classref-item-separator
  396. ----
  397. .. _class_CanvasItem_method_draw_polyline_colors:
  398. .. rst-class:: classref-method
  399. void **draw_polyline_colors** **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`PoolColorArray<class_PoolColorArray>` colors, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)**
  400. Draws interconnected line segments with a uniform ``width`` and segment-by-segment coloring, and optional antialiasing. Colors assigned to line segments match by index between ``points`` and ``colors``. When drawing large amounts of lines, this is faster than using individual :ref:`draw_line<class_CanvasItem_method_draw_line>` calls. To draw disconnected lines, use :ref:`draw_multiline_colors<class_CanvasItem_method_draw_multiline_colors>` instead. See also :ref:`draw_polygon<class_CanvasItem_method_draw_polygon>`.
  401. \ **Note:** Due to how it works, built-in antialiasing will not look correct for translucent polygons and may not work on certain platforms. As a workaround, install the `Antialiased Line2D <https://github.com/godot-extended-libraries/godot-antialiased-line2d>`__ add-on then create an AntialiasedPolygon2D node. That node relies on a texture with custom mipmaps to perform antialiasing.
  402. .. rst-class:: classref-item-separator
  403. ----
  404. .. _class_CanvasItem_method_draw_primitive:
  405. .. rst-class:: classref-method
  406. void **draw_primitive** **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`PoolColorArray<class_PoolColorArray>` colors, :ref:`PoolVector2Array<class_PoolVector2Array>` uvs, :ref:`Texture<class_Texture>` texture=null, :ref:`float<class_float>` width=1.0, :ref:`Texture<class_Texture>` normal_map=null **)**
  407. 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. See also :ref:`draw_line<class_CanvasItem_method_draw_line>`, :ref:`draw_polyline<class_CanvasItem_method_draw_polyline>`, :ref:`draw_polygon<class_CanvasItem_method_draw_polygon>`, and :ref:`draw_rect<class_CanvasItem_method_draw_rect>`.
  408. .. rst-class:: classref-item-separator
  409. ----
  410. .. _class_CanvasItem_method_draw_rect:
  411. .. rst-class:: classref-method
  412. void **draw_rect** **(** :ref:`Rect2<class_Rect2>` rect, :ref:`Color<class_Color>` color, :ref:`bool<class_bool>` filled=true, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)**
  413. 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 attempt to perform antialiasing using OpenGL line smoothing.
  414. \ **Note:** ``width`` and ``antialiased`` are only effective if ``filled`` is ``false``.
  415. \ **Note:** Due to how it works, built-in antialiasing will not look correct for translucent polygons and may not work on certain platforms. As a workaround, install the `Antialiased Line2D <https://github.com/godot-extended-libraries/godot-antialiased-line2d>`__ add-on then create an AntialiasedPolygon2D node. That node relies on a texture with custom mipmaps to perform antialiasing.
  416. .. rst-class:: classref-item-separator
  417. ----
  418. .. _class_CanvasItem_method_draw_set_transform:
  419. .. rst-class:: classref-method
  420. void **draw_set_transform** **(** :ref:`Vector2<class_Vector2>` position, :ref:`float<class_float>` rotation, :ref:`Vector2<class_Vector2>` scale **)**
  421. Sets a custom transform for drawing via components. Anything drawn afterwards will be transformed by this.
  422. .. rst-class:: classref-item-separator
  423. ----
  424. .. _class_CanvasItem_method_draw_set_transform_matrix:
  425. .. rst-class:: classref-method
  426. void **draw_set_transform_matrix** **(** :ref:`Transform2D<class_Transform2D>` xform **)**
  427. Sets a custom transform for drawing via matrix. Anything drawn afterwards will be transformed by this.
  428. .. rst-class:: classref-item-separator
  429. ----
  430. .. _class_CanvasItem_method_draw_string:
  431. .. rst-class:: classref-method
  432. void **draw_string** **(** :ref:`Font<class_Font>` font, :ref:`Vector2<class_Vector2>` position, :ref:`String<class_String>` text, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`int<class_int>` clip_w=-1 **)**
  433. Draws ``text`` using the specified ``font`` at the ``position`` (bottom-left corner using the baseline of the font). The text will have its color multiplied by ``modulate``. If ``clip_w`` is greater than or equal to 0, the text will be clipped if it exceeds the specified width.
  434. \ **Example using the default project font:**\
  435. ::
  436. # If using this method in a script that redraws constantly, move the
  437. # `default_font` declaration to a member variable assigned in `_ready()`
  438. # so the Control is only created once.
  439. var default_font = Control.new().get_font("font")
  440. draw_string(default_font, Vector2(64, 64), "Hello world")
  441. See also :ref:`Font.draw<class_Font_method_draw>`.
  442. .. rst-class:: classref-item-separator
  443. ----
  444. .. _class_CanvasItem_method_draw_style_box:
  445. .. rst-class:: classref-method
  446. void **draw_style_box** **(** :ref:`StyleBox<class_StyleBox>` style_box, :ref:`Rect2<class_Rect2>` rect **)**
  447. Draws a styled rectangle.
  448. .. rst-class:: classref-item-separator
  449. ----
  450. .. _class_CanvasItem_method_draw_texture:
  451. .. rst-class:: classref-method
  452. void **draw_texture** **(** :ref:`Texture<class_Texture>` texture, :ref:`Vector2<class_Vector2>` position, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`Texture<class_Texture>` normal_map=null **)**
  453. Draws a texture at a given position.
  454. .. rst-class:: classref-item-separator
  455. ----
  456. .. _class_CanvasItem_method_draw_texture_rect:
  457. .. rst-class:: classref-method
  458. void **draw_texture_rect** **(** :ref:`Texture<class_Texture>` texture, :ref:`Rect2<class_Rect2>` rect, :ref:`bool<class_bool>` tile, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`bool<class_bool>` transpose=false, :ref:`Texture<class_Texture>` normal_map=null **)**
  459. 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.
  460. .. rst-class:: classref-item-separator
  461. ----
  462. .. _class_CanvasItem_method_draw_texture_rect_region:
  463. .. rst-class:: classref-method
  464. void **draw_texture_rect_region** **(** :ref:`Texture<class_Texture>` texture, :ref:`Rect2<class_Rect2>` rect, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`bool<class_bool>` transpose=false, :ref:`Texture<class_Texture>` normal_map=null, :ref:`bool<class_bool>` clip_uv=true **)**
  465. 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.
  466. .. rst-class:: classref-item-separator
  467. ----
  468. .. _class_CanvasItem_method_force_update_transform:
  469. .. rst-class:: classref-method
  470. void **force_update_transform** **(** **)**
  471. Forces the transform to update. Transform changes in physics are not instant for performance reasons. Transforms are accumulated and then set. Use this if you need an up-to-date transform when doing physics operations.
  472. .. rst-class:: classref-item-separator
  473. ----
  474. .. _class_CanvasItem_method_get_canvas:
  475. .. rst-class:: classref-method
  476. :ref:`RID<class_RID>` **get_canvas** **(** **)** |const|
  477. Returns the :ref:`RID<class_RID>` of the :ref:`World2D<class_World2D>` canvas where this item is in.
  478. .. rst-class:: classref-item-separator
  479. ----
  480. .. _class_CanvasItem_method_get_canvas_item:
  481. .. rst-class:: classref-method
  482. :ref:`RID<class_RID>` **get_canvas_item** **(** **)** |const|
  483. Returns the canvas item RID used by :ref:`VisualServer<class_VisualServer>` for this item.
  484. .. rst-class:: classref-item-separator
  485. ----
  486. .. _class_CanvasItem_method_get_canvas_transform:
  487. .. rst-class:: classref-method
  488. :ref:`Transform2D<class_Transform2D>` **get_canvas_transform** **(** **)** |const|
  489. Returns the transform from the coordinate system of the canvas, this item is in, to the :ref:`Viewport<class_Viewport>`\ s coordinate system.
  490. .. rst-class:: classref-item-separator
  491. ----
  492. .. _class_CanvasItem_method_get_global_mouse_position:
  493. .. rst-class:: classref-method
  494. :ref:`Vector2<class_Vector2>` **get_global_mouse_position** **(** **)** |const|
  495. Returns the mouse's position in the :ref:`CanvasLayer<class_CanvasLayer>` that this **CanvasItem** is in using the coordinate system of the :ref:`CanvasLayer<class_CanvasLayer>`.
  496. .. rst-class:: classref-item-separator
  497. ----
  498. .. _class_CanvasItem_method_get_global_transform:
  499. .. rst-class:: classref-method
  500. :ref:`Transform2D<class_Transform2D>` **get_global_transform** **(** **)** |const|
  501. Returns the global transform matrix of this item.
  502. .. rst-class:: classref-item-separator
  503. ----
  504. .. _class_CanvasItem_method_get_global_transform_with_canvas:
  505. .. rst-class:: classref-method
  506. :ref:`Transform2D<class_Transform2D>` **get_global_transform_with_canvas** **(** **)** |const|
  507. Returns the transform from the local coordinate system of this **CanvasItem** to the :ref:`Viewport<class_Viewport>`\ s coordinate system.
  508. .. rst-class:: classref-item-separator
  509. ----
  510. .. _class_CanvasItem_method_get_local_mouse_position:
  511. .. rst-class:: classref-method
  512. :ref:`Vector2<class_Vector2>` **get_local_mouse_position** **(** **)** |const|
  513. Returns the mouse's position in this **CanvasItem** using the local coordinate system of this **CanvasItem**.
  514. .. rst-class:: classref-item-separator
  515. ----
  516. .. _class_CanvasItem_method_get_transform:
  517. .. rst-class:: classref-method
  518. :ref:`Transform2D<class_Transform2D>` **get_transform** **(** **)** |const|
  519. Returns the transform matrix of this item.
  520. .. rst-class:: classref-item-separator
  521. ----
  522. .. _class_CanvasItem_method_get_viewport_rect:
  523. .. rst-class:: classref-method
  524. :ref:`Rect2<class_Rect2>` **get_viewport_rect** **(** **)** |const|
  525. Returns the viewport's boundaries as a :ref:`Rect2<class_Rect2>`.
  526. .. rst-class:: classref-item-separator
  527. ----
  528. .. _class_CanvasItem_method_get_viewport_transform:
  529. .. rst-class:: classref-method
  530. :ref:`Transform2D<class_Transform2D>` **get_viewport_transform** **(** **)** |const|
  531. Returns the transform from the coordinate system of the canvas, this item is in, to the :ref:`Viewport<class_Viewport>`\ s embedders coordinate system.
  532. .. rst-class:: classref-item-separator
  533. ----
  534. .. _class_CanvasItem_method_get_world_2d:
  535. .. rst-class:: classref-method
  536. :ref:`World2D<class_World2D>` **get_world_2d** **(** **)** |const|
  537. Returns the :ref:`World2D<class_World2D>` where this item is in.
  538. .. rst-class:: classref-item-separator
  539. ----
  540. .. _class_CanvasItem_method_hide:
  541. .. rst-class:: classref-method
  542. void **hide** **(** **)**
  543. Hide the **CanvasItem** if it's currently visible. This is equivalent to setting :ref:`visible<class_CanvasItem_property_visible>` to ``false``.
  544. .. rst-class:: classref-item-separator
  545. ----
  546. .. _class_CanvasItem_method_is_local_transform_notification_enabled:
  547. .. rst-class:: classref-method
  548. :ref:`bool<class_bool>` **is_local_transform_notification_enabled** **(** **)** |const|
  549. Returns ``true`` if local transform notifications are communicated to children.
  550. .. rst-class:: classref-item-separator
  551. ----
  552. .. _class_CanvasItem_method_is_set_as_toplevel:
  553. .. rst-class:: classref-method
  554. :ref:`bool<class_bool>` **is_set_as_toplevel** **(** **)** |const|
  555. Returns ``true`` if the node is set as top-level. See :ref:`set_as_toplevel<class_CanvasItem_method_set_as_toplevel>`.
  556. .. rst-class:: classref-item-separator
  557. ----
  558. .. _class_CanvasItem_method_is_transform_notification_enabled:
  559. .. rst-class:: classref-method
  560. :ref:`bool<class_bool>` **is_transform_notification_enabled** **(** **)** |const|
  561. Returns ``true`` if global transform notifications are communicated to children.
  562. .. rst-class:: classref-item-separator
  563. ----
  564. .. _class_CanvasItem_method_is_visible_in_tree:
  565. .. rst-class:: classref-method
  566. :ref:`bool<class_bool>` **is_visible_in_tree** **(** **)** |const|
  567. Returns ``true`` if the node is present in the :ref:`SceneTree<class_SceneTree>`, its :ref:`visible<class_CanvasItem_property_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 consequently not drawn (see :ref:`_draw<class_CanvasItem_method__draw>`).
  568. .. rst-class:: classref-item-separator
  569. ----
  570. .. _class_CanvasItem_method_make_canvas_position_local:
  571. .. rst-class:: classref-method
  572. :ref:`Vector2<class_Vector2>` **make_canvas_position_local** **(** :ref:`Vector2<class_Vector2>` screen_point **)** |const|
  573. Assigns ``screen_point`` as this node's new local transform.
  574. .. rst-class:: classref-item-separator
  575. ----
  576. .. _class_CanvasItem_method_make_input_local:
  577. .. rst-class:: classref-method
  578. :ref:`InputEvent<class_InputEvent>` **make_input_local** **(** :ref:`InputEvent<class_InputEvent>` event **)** |const|
  579. Transformations issued by ``event``'s inputs are applied in local space instead of global space.
  580. .. rst-class:: classref-item-separator
  581. ----
  582. .. _class_CanvasItem_method_set_as_toplevel:
  583. .. rst-class:: classref-method
  584. void **set_as_toplevel** **(** :ref:`bool<class_bool>` enable **)**
  585. If ``enable`` is ``true``, this **CanvasItem** will *not* inherit its transform from parent **CanvasItem**\ s. Its draw order will also be changed to make it draw on top of other **CanvasItem**\ s that are not set as top-level. The **CanvasItem** will effectively act as if it was placed as a child of a bare :ref:`Node<class_Node>`. See also :ref:`is_set_as_toplevel<class_CanvasItem_method_is_set_as_toplevel>`.
  586. .. rst-class:: classref-item-separator
  587. ----
  588. .. _class_CanvasItem_method_set_notify_local_transform:
  589. .. rst-class:: classref-method
  590. void **set_notify_local_transform** **(** :ref:`bool<class_bool>` enable **)**
  591. If ``enable`` is ``true``, this node will receive :ref:`NOTIFICATION_LOCAL_TRANSFORM_CHANGED<class_CanvasItem_constant_NOTIFICATION_LOCAL_TRANSFORM_CHANGED>` when its local transform changes.
  592. .. rst-class:: classref-item-separator
  593. ----
  594. .. _class_CanvasItem_method_set_notify_transform:
  595. .. rst-class:: classref-method
  596. void **set_notify_transform** **(** :ref:`bool<class_bool>` enable **)**
  597. If ``enable`` is ``true``, this node will receive :ref:`NOTIFICATION_TRANSFORM_CHANGED<class_CanvasItem_constant_NOTIFICATION_TRANSFORM_CHANGED>` when its global transform changes.
  598. .. rst-class:: classref-item-separator
  599. ----
  600. .. _class_CanvasItem_method_show:
  601. .. rst-class:: classref-method
  602. void **show** **(** **)**
  603. Show the **CanvasItem** if it's currently hidden. This is equivalent to setting :ref:`visible<class_CanvasItem_property_visible>` to ``true``. For controls that inherit :ref:`Popup<class_Popup>`, the correct way to make them visible is to call one of the multiple ``popup*()`` functions instead.
  604. .. rst-class:: classref-item-separator
  605. ----
  606. .. _class_CanvasItem_method_update:
  607. .. rst-class:: classref-method
  608. void **update** **(** **)**
  609. Queues the **CanvasItem** to redraw. During idle time, if **CanvasItem** is visible, :ref:`NOTIFICATION_DRAW<class_CanvasItem_constant_NOTIFICATION_DRAW>` is sent and :ref:`_draw<class_CanvasItem_method__draw>` is called. This only occurs **once** per frame, even if this method has been called multiple times.
  610. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  611. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  612. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  613. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`