class_canvasitem.rst 149 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529
  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/4.0/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.0/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. Abstract base class for everything in 2D space.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. Abstract base class for everything in 2D space. 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 GUI-related nodes, and by :ref:`Node2D<class_Node2D>` for 2D game objects.
  16. Any **CanvasItem** can draw. For this, :ref:`queue_redraw<class_CanvasItem_method_queue_redraw>` is called by the engine, then :ref:`NOTIFICATION_DRAW<class_CanvasItem_constant_NOTIFICATION_DRAW>` will be received on idle time to request a redraw. Because of this, canvas items don't need to be redrawn on every frame, improving the performance significantly. Several functions for drawing on the **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 be hidden, which will also hide its children. By adjusting various other properties of a **CanvasItem**, you can also modulate its color (via :ref:`modulate<class_CanvasItem_property_modulate>` or :ref:`self_modulate<class_CanvasItem_property_self_modulate>`), change its Z-index, blend mode, and more.
  19. .. rst-class:: classref-introduction-group
  20. Tutorials
  21. ---------
  22. - :doc:`Viewport and canvas transforms <../tutorials/2d/2d_transforms>`
  23. - :doc:`Custom drawing in 2D <../tutorials/2d/custom_drawing_in_2d>`
  24. - `Audio Spectrum Demo <https://godotengine.org/asset-library/asset/528>`__
  25. .. rst-class:: classref-reftable-group
  26. Properties
  27. ----------
  28. .. table::
  29. :widths: auto
  30. +-----------------------------------------------------------+---------------------------------------------------------------------------+-----------------------+
  31. | :ref:`ClipChildrenMode<enum_CanvasItem_ClipChildrenMode>` | :ref:`clip_children<class_CanvasItem_property_clip_children>` | ``0`` |
  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:`TextureFilter<enum_CanvasItem_TextureFilter>` | :ref:`texture_filter<class_CanvasItem_property_texture_filter>` | ``0`` |
  44. +-----------------------------------------------------------+---------------------------------------------------------------------------+-----------------------+
  45. | :ref:`TextureRepeat<enum_CanvasItem_TextureRepeat>` | :ref:`texture_repeat<class_CanvasItem_property_texture_repeat>` | ``0`` |
  46. +-----------------------------------------------------------+---------------------------------------------------------------------------+-----------------------+
  47. | :ref:`bool<class_bool>` | :ref:`top_level<class_CanvasItem_property_top_level>` | ``false`` |
  48. +-----------------------------------------------------------+---------------------------------------------------------------------------+-----------------------+
  49. | :ref:`bool<class_bool>` | :ref:`use_parent_material<class_CanvasItem_property_use_parent_material>` | ``false`` |
  50. +-----------------------------------------------------------+---------------------------------------------------------------------------+-----------------------+
  51. | :ref:`int<class_int>` | :ref:`visibility_layer<class_CanvasItem_property_visibility_layer>` | ``1`` |
  52. +-----------------------------------------------------------+---------------------------------------------------------------------------+-----------------------+
  53. | :ref:`bool<class_bool>` | :ref:`visible<class_CanvasItem_property_visible>` | ``true`` |
  54. +-----------------------------------------------------------+---------------------------------------------------------------------------+-----------------------+
  55. | :ref:`bool<class_bool>` | :ref:`y_sort_enabled<class_CanvasItem_property_y_sort_enabled>` | ``false`` |
  56. +-----------------------------------------------------------+---------------------------------------------------------------------------+-----------------------+
  57. | :ref:`bool<class_bool>` | :ref:`z_as_relative<class_CanvasItem_property_z_as_relative>` | ``true`` |
  58. +-----------------------------------------------------------+---------------------------------------------------------------------------+-----------------------+
  59. | :ref:`int<class_int>` | :ref:`z_index<class_CanvasItem_property_z_index>` | ``0`` |
  60. +-----------------------------------------------------------+---------------------------------------------------------------------------+-----------------------+
  61. .. rst-class:: classref-reftable-group
  62. Methods
  63. -------
  64. .. table::
  65. :widths: auto
  66. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | void | :ref:`_draw<class_CanvasItem_method__draw>` **(** **)** |virtual| |
  68. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | void | :ref:`draw_animation_slice<class_CanvasItem_method_draw_animation_slice>` **(** :ref:`float<class_float>` animation_length, :ref:`float<class_float>` slice_begin, :ref:`float<class_float>` slice_end, :ref:`float<class_float>` offset=0.0 **)** |
  70. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | 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 **)** |
  72. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | void | :ref:`draw_char<class_CanvasItem_method_draw_char>` **(** :ref:`Font<class_Font>` font, :ref:`Vector2<class_Vector2>` pos, :ref:`String<class_String>` char, :ref:`int<class_int>` font_size=16, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1) **)** |const| |
  74. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | void | :ref:`draw_char_outline<class_CanvasItem_method_draw_char_outline>` **(** :ref:`Font<class_Font>` font, :ref:`Vector2<class_Vector2>` pos, :ref:`String<class_String>` char, :ref:`int<class_int>` font_size=16, :ref:`int<class_int>` size=-1, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1) **)** |const| |
  76. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | void | :ref:`draw_circle<class_CanvasItem_method_draw_circle>` **(** :ref:`Vector2<class_Vector2>` position, :ref:`float<class_float>` radius, :ref:`Color<class_Color>` color **)** |
  78. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | void | :ref:`draw_colored_polygon<class_CanvasItem_method_draw_colored_polygon>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` points, :ref:`Color<class_Color>` color, :ref:`PackedVector2Array<class_PackedVector2Array>` uvs=PackedVector2Array(), :ref:`Texture2D<class_Texture2D>` texture=null **)** |
  80. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. | void | :ref:`draw_dashed_line<class_CanvasItem_method_draw_dashed_line>` **(** :ref:`Vector2<class_Vector2>` from, :ref:`Vector2<class_Vector2>` to, :ref:`Color<class_Color>` color, :ref:`float<class_float>` width=-1.0, :ref:`float<class_float>` dash=2.0, :ref:`bool<class_bool>` aligned=true **)** |
  82. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. | void | :ref:`draw_end_animation<class_CanvasItem_method_draw_end_animation>` **(** **)** |
  84. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  85. | void | :ref:`draw_lcd_texture_rect_region<class_CanvasItem_method_draw_lcd_texture_rect_region>` **(** :ref:`Texture2D<class_Texture2D>` texture, :ref:`Rect2<class_Rect2>` rect, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1) **)** |
  86. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  87. | 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 **)** |
  88. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  89. | void | :ref:`draw_mesh<class_CanvasItem_method_draw_mesh>` **(** :ref:`Mesh<class_Mesh>` mesh, :ref:`Texture2D<class_Texture2D>` texture, :ref:`Transform2D<class_Transform2D>` transform=Transform2D(1, 0, 0, 1, 0, 0), :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1) **)** |
  90. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  91. | void | :ref:`draw_msdf_texture_rect_region<class_CanvasItem_method_draw_msdf_texture_rect_region>` **(** :ref:`Texture2D<class_Texture2D>` texture, :ref:`Rect2<class_Rect2>` rect, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1), :ref:`float<class_float>` outline=0.0, :ref:`float<class_float>` pixel_range=4.0, :ref:`float<class_float>` scale=1.0 **)** |
  92. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  93. | void | :ref:`draw_multiline<class_CanvasItem_method_draw_multiline>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` points, :ref:`Color<class_Color>` color, :ref:`float<class_float>` width=-1.0 **)** |
  94. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  95. | void | :ref:`draw_multiline_colors<class_CanvasItem_method_draw_multiline_colors>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` points, :ref:`PackedColorArray<class_PackedColorArray>` colors, :ref:`float<class_float>` width=-1.0 **)** |
  96. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  97. | void | :ref:`draw_multiline_string<class_CanvasItem_method_draw_multiline_string>` **(** :ref:`Font<class_Font>` font, :ref:`Vector2<class_Vector2>` pos, :ref:`String<class_String>` text, :ref:`HorizontalAlignment<enum_@GlobalScope_HorizontalAlignment>` alignment=0, :ref:`float<class_float>` width=-1, :ref:`int<class_int>` font_size=16, :ref:`int<class_int>` max_lines=-1, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1), :ref:`LineBreakFlag<enum_TextServer_LineBreakFlag>` brk_flags=3, :ref:`JustificationFlag<enum_TextServer_JustificationFlag>` jst_flags=3, :ref:`Direction<enum_TextServer_Direction>` direction=0, :ref:`Orientation<enum_TextServer_Orientation>` orientation=0 **)** |const| |
  98. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  99. | void | :ref:`draw_multiline_string_outline<class_CanvasItem_method_draw_multiline_string_outline>` **(** :ref:`Font<class_Font>` font, :ref:`Vector2<class_Vector2>` pos, :ref:`String<class_String>` text, :ref:`HorizontalAlignment<enum_@GlobalScope_HorizontalAlignment>` alignment=0, :ref:`float<class_float>` width=-1, :ref:`int<class_int>` font_size=16, :ref:`int<class_int>` max_lines=-1, :ref:`int<class_int>` size=1, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1), :ref:`LineBreakFlag<enum_TextServer_LineBreakFlag>` brk_flags=3, :ref:`JustificationFlag<enum_TextServer_JustificationFlag>` jst_flags=3, :ref:`Direction<enum_TextServer_Direction>` direction=0, :ref:`Orientation<enum_TextServer_Orientation>` orientation=0 **)** |const| |
  100. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  101. | void | :ref:`draw_multimesh<class_CanvasItem_method_draw_multimesh>` **(** :ref:`MultiMesh<class_MultiMesh>` multimesh, :ref:`Texture2D<class_Texture2D>` texture **)** |
  102. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  103. | void | :ref:`draw_polygon<class_CanvasItem_method_draw_polygon>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` points, :ref:`PackedColorArray<class_PackedColorArray>` colors, :ref:`PackedVector2Array<class_PackedVector2Array>` uvs=PackedVector2Array(), :ref:`Texture2D<class_Texture2D>` texture=null **)** |
  104. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  105. | void | :ref:`draw_polyline<class_CanvasItem_method_draw_polyline>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` points, :ref:`Color<class_Color>` color, :ref:`float<class_float>` width=-1.0, :ref:`bool<class_bool>` antialiased=false **)** |
  106. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  107. | void | :ref:`draw_polyline_colors<class_CanvasItem_method_draw_polyline_colors>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` points, :ref:`PackedColorArray<class_PackedColorArray>` colors, :ref:`float<class_float>` width=-1.0, :ref:`bool<class_bool>` antialiased=false **)** |
  108. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  109. | void | :ref:`draw_primitive<class_CanvasItem_method_draw_primitive>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` points, :ref:`PackedColorArray<class_PackedColorArray>` colors, :ref:`PackedVector2Array<class_PackedVector2Array>` uvs, :ref:`Texture2D<class_Texture2D>` texture=null **)** |
  110. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  111. | 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 **)** |
  112. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  113. | void | :ref:`draw_set_transform<class_CanvasItem_method_draw_set_transform>` **(** :ref:`Vector2<class_Vector2>` position, :ref:`float<class_float>` rotation=0.0, :ref:`Vector2<class_Vector2>` scale=Vector2(1, 1) **)** |
  114. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  115. | void | :ref:`draw_set_transform_matrix<class_CanvasItem_method_draw_set_transform_matrix>` **(** :ref:`Transform2D<class_Transform2D>` xform **)** |
  116. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  117. | void | :ref:`draw_string<class_CanvasItem_method_draw_string>` **(** :ref:`Font<class_Font>` font, :ref:`Vector2<class_Vector2>` pos, :ref:`String<class_String>` text, :ref:`HorizontalAlignment<enum_@GlobalScope_HorizontalAlignment>` alignment=0, :ref:`float<class_float>` width=-1, :ref:`int<class_int>` font_size=16, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1), :ref:`JustificationFlag<enum_TextServer_JustificationFlag>` jst_flags=3, :ref:`Direction<enum_TextServer_Direction>` direction=0, :ref:`Orientation<enum_TextServer_Orientation>` orientation=0 **)** |const| |
  118. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  119. | void | :ref:`draw_string_outline<class_CanvasItem_method_draw_string_outline>` **(** :ref:`Font<class_Font>` font, :ref:`Vector2<class_Vector2>` pos, :ref:`String<class_String>` text, :ref:`HorizontalAlignment<enum_@GlobalScope_HorizontalAlignment>` alignment=0, :ref:`float<class_float>` width=-1, :ref:`int<class_int>` font_size=16, :ref:`int<class_int>` size=1, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1), :ref:`JustificationFlag<enum_TextServer_JustificationFlag>` jst_flags=3, :ref:`Direction<enum_TextServer_Direction>` direction=0, :ref:`Orientation<enum_TextServer_Orientation>` orientation=0 **)** |const| |
  120. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  121. | void | :ref:`draw_style_box<class_CanvasItem_method_draw_style_box>` **(** :ref:`StyleBox<class_StyleBox>` style_box, :ref:`Rect2<class_Rect2>` rect **)** |
  122. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  123. | void | :ref:`draw_texture<class_CanvasItem_method_draw_texture>` **(** :ref:`Texture2D<class_Texture2D>` texture, :ref:`Vector2<class_Vector2>` position, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1) **)** |
  124. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  125. | void | :ref:`draw_texture_rect<class_CanvasItem_method_draw_texture_rect>` **(** :ref:`Texture2D<class_Texture2D>` 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 **)** |
  126. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  127. | void | :ref:`draw_texture_rect_region<class_CanvasItem_method_draw_texture_rect_region>` **(** :ref:`Texture2D<class_Texture2D>` 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:`bool<class_bool>` clip_uv=true **)** |
  128. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  129. | void | :ref:`force_update_transform<class_CanvasItem_method_force_update_transform>` **(** **)** |
  130. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  131. | :ref:`RID<class_RID>` | :ref:`get_canvas<class_CanvasItem_method_get_canvas>` **(** **)** |const| |
  132. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  133. | :ref:`RID<class_RID>` | :ref:`get_canvas_item<class_CanvasItem_method_get_canvas_item>` **(** **)** |const| |
  134. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  135. | :ref:`Transform2D<class_Transform2D>` | :ref:`get_canvas_transform<class_CanvasItem_method_get_canvas_transform>` **(** **)** |const| |
  136. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  137. | :ref:`Vector2<class_Vector2>` | :ref:`get_global_mouse_position<class_CanvasItem_method_get_global_mouse_position>` **(** **)** |const| |
  138. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  139. | :ref:`Transform2D<class_Transform2D>` | :ref:`get_global_transform<class_CanvasItem_method_get_global_transform>` **(** **)** |const| |
  140. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  141. | :ref:`Transform2D<class_Transform2D>` | :ref:`get_global_transform_with_canvas<class_CanvasItem_method_get_global_transform_with_canvas>` **(** **)** |const| |
  142. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  143. | :ref:`Vector2<class_Vector2>` | :ref:`get_local_mouse_position<class_CanvasItem_method_get_local_mouse_position>` **(** **)** |const| |
  144. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  145. | :ref:`Transform2D<class_Transform2D>` | :ref:`get_screen_transform<class_CanvasItem_method_get_screen_transform>` **(** **)** |const| |
  146. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  147. | :ref:`Transform2D<class_Transform2D>` | :ref:`get_transform<class_CanvasItem_method_get_transform>` **(** **)** |const| |
  148. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  149. | :ref:`Rect2<class_Rect2>` | :ref:`get_viewport_rect<class_CanvasItem_method_get_viewport_rect>` **(** **)** |const| |
  150. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  151. | :ref:`Transform2D<class_Transform2D>` | :ref:`get_viewport_transform<class_CanvasItem_method_get_viewport_transform>` **(** **)** |const| |
  152. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  153. | :ref:`bool<class_bool>` | :ref:`get_visibility_layer_bit<class_CanvasItem_method_get_visibility_layer_bit>` **(** :ref:`int<class_int>` layer **)** |const| |
  154. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  155. | :ref:`World2D<class_World2D>` | :ref:`get_world_2d<class_CanvasItem_method_get_world_2d>` **(** **)** |const| |
  156. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  157. | void | :ref:`hide<class_CanvasItem_method_hide>` **(** **)** |
  158. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  159. | :ref:`bool<class_bool>` | :ref:`is_local_transform_notification_enabled<class_CanvasItem_method_is_local_transform_notification_enabled>` **(** **)** |const| |
  160. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  161. | :ref:`bool<class_bool>` | :ref:`is_transform_notification_enabled<class_CanvasItem_method_is_transform_notification_enabled>` **(** **)** |const| |
  162. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  163. | :ref:`bool<class_bool>` | :ref:`is_visible_in_tree<class_CanvasItem_method_is_visible_in_tree>` **(** **)** |const| |
  164. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  165. | :ref:`Vector2<class_Vector2>` | :ref:`make_canvas_position_local<class_CanvasItem_method_make_canvas_position_local>` **(** :ref:`Vector2<class_Vector2>` screen_point **)** |const| |
  166. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  167. | :ref:`InputEvent<class_InputEvent>` | :ref:`make_input_local<class_CanvasItem_method_make_input_local>` **(** :ref:`InputEvent<class_InputEvent>` event **)** |const| |
  168. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  169. | void | :ref:`move_to_front<class_CanvasItem_method_move_to_front>` **(** **)** |
  170. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  171. | void | :ref:`queue_redraw<class_CanvasItem_method_queue_redraw>` **(** **)** |
  172. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  173. | void | :ref:`set_notify_local_transform<class_CanvasItem_method_set_notify_local_transform>` **(** :ref:`bool<class_bool>` enable **)** |
  174. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  175. | void | :ref:`set_notify_transform<class_CanvasItem_method_set_notify_transform>` **(** :ref:`bool<class_bool>` enable **)** |
  176. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  177. | void | :ref:`set_visibility_layer_bit<class_CanvasItem_method_set_visibility_layer_bit>` **(** :ref:`int<class_int>` layer, :ref:`bool<class_bool>` enabled **)** |
  178. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  179. | void | :ref:`show<class_CanvasItem_method_show>` **(** **)** |
  180. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  181. .. rst-class:: classref-section-separator
  182. ----
  183. .. rst-class:: classref-descriptions-group
  184. Signals
  185. -------
  186. .. _class_CanvasItem_signal_draw:
  187. .. rst-class:: classref-signal
  188. **draw** **(** **)**
  189. 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.
  190. \ **Note:** Deferred connections do not allow drawing through the ``draw_*`` methods.
  191. .. rst-class:: classref-item-separator
  192. ----
  193. .. _class_CanvasItem_signal_hidden:
  194. .. rst-class:: classref-signal
  195. **hidden** **(** **)**
  196. Emitted when becoming hidden.
  197. .. rst-class:: classref-item-separator
  198. ----
  199. .. _class_CanvasItem_signal_item_rect_changed:
  200. .. rst-class:: classref-signal
  201. **item_rect_changed** **(** **)**
  202. 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:`Sprite2D.texture<class_Sprite2D_property_texture>`).
  203. .. rst-class:: classref-item-separator
  204. ----
  205. .. _class_CanvasItem_signal_visibility_changed:
  206. .. rst-class:: classref-signal
  207. **visibility_changed** **(** **)**
  208. Emitted when the visibility (hidden/visible) changes.
  209. .. rst-class:: classref-section-separator
  210. ----
  211. .. rst-class:: classref-descriptions-group
  212. Enumerations
  213. ------------
  214. .. _enum_CanvasItem_TextureFilter:
  215. .. rst-class:: classref-enumeration
  216. enum **TextureFilter**:
  217. .. _class_CanvasItem_constant_TEXTURE_FILTER_PARENT_NODE:
  218. .. rst-class:: classref-enumeration-constant
  219. :ref:`TextureFilter<enum_CanvasItem_TextureFilter>` **TEXTURE_FILTER_PARENT_NODE** = ``0``
  220. The **CanvasItem** will inherit the filter from its parent.
  221. .. _class_CanvasItem_constant_TEXTURE_FILTER_NEAREST:
  222. .. rst-class:: classref-enumeration-constant
  223. :ref:`TextureFilter<enum_CanvasItem_TextureFilter>` **TEXTURE_FILTER_NEAREST** = ``1``
  224. The texture filter reads from the nearest pixel only. The simplest and fastest method of filtering. Useful for pixel art.
  225. .. _class_CanvasItem_constant_TEXTURE_FILTER_LINEAR:
  226. .. rst-class:: classref-enumeration-constant
  227. :ref:`TextureFilter<enum_CanvasItem_TextureFilter>` **TEXTURE_FILTER_LINEAR** = ``2``
  228. The texture filter blends between the nearest four pixels. Use this for most cases where you want to avoid a pixelated style.
  229. .. _class_CanvasItem_constant_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS:
  230. .. rst-class:: classref-enumeration-constant
  231. :ref:`TextureFilter<enum_CanvasItem_TextureFilter>` **TEXTURE_FILTER_NEAREST_WITH_MIPMAPS** = ``3``
  232. The texture filter reads from the nearest pixel in the nearest mipmap. This is the fastest way to read from textures with mipmaps.
  233. .. _class_CanvasItem_constant_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS:
  234. .. rst-class:: classref-enumeration-constant
  235. :ref:`TextureFilter<enum_CanvasItem_TextureFilter>` **TEXTURE_FILTER_LINEAR_WITH_MIPMAPS** = ``4``
  236. The texture filter blends between the nearest 4 pixels and between the nearest 2 mipmaps. Use this for non-pixel art textures that may be viewed at a low scale (e.g. due to :ref:`Camera2D<class_Camera2D>` zoom), as mipmaps are important to smooth out pixels that are smaller than on-screen pixels.
  237. .. _class_CanvasItem_constant_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC:
  238. .. rst-class:: classref-enumeration-constant
  239. :ref:`TextureFilter<enum_CanvasItem_TextureFilter>` **TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC** = ``5``
  240. The texture filter reads from the nearest pixel, but selects a mipmap based on the angle between the surface and the camera view. This reduces artifacts on surfaces that are almost in line with the camera. The anisotropic filtering level can be changed by adjusting :ref:`ProjectSettings.rendering/textures/default_filters/anisotropic_filtering_level<class_ProjectSettings_property_rendering/textures/default_filters/anisotropic_filtering_level>`.
  241. \ **Note:** This texture filter is rarely useful in 2D projects. :ref:`TEXTURE_FILTER_NEAREST_WITH_MIPMAPS<class_CanvasItem_constant_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS>` is usually more appropriate.
  242. .. _class_CanvasItem_constant_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC:
  243. .. rst-class:: classref-enumeration-constant
  244. :ref:`TextureFilter<enum_CanvasItem_TextureFilter>` **TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC** = ``6``
  245. The texture filter blends between the nearest 4 pixels and selects a mipmap based on the angle between the surface and the camera view. This reduces artifacts on surfaces that are almost in line with the camera. This is the slowest of the filtering options, but results in the highest quality texturing. The anisotropic filtering level can be changed by adjusting :ref:`ProjectSettings.rendering/textures/default_filters/anisotropic_filtering_level<class_ProjectSettings_property_rendering/textures/default_filters/anisotropic_filtering_level>`.
  246. \ **Note:** This texture filter is rarely useful in 2D projects. :ref:`TEXTURE_FILTER_LINEAR_WITH_MIPMAPS<class_CanvasItem_constant_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS>` is usually more appropriate.
  247. .. _class_CanvasItem_constant_TEXTURE_FILTER_MAX:
  248. .. rst-class:: classref-enumeration-constant
  249. :ref:`TextureFilter<enum_CanvasItem_TextureFilter>` **TEXTURE_FILTER_MAX** = ``7``
  250. Represents the size of the :ref:`TextureFilter<enum_CanvasItem_TextureFilter>` enum.
  251. .. rst-class:: classref-item-separator
  252. ----
  253. .. _enum_CanvasItem_TextureRepeat:
  254. .. rst-class:: classref-enumeration
  255. enum **TextureRepeat**:
  256. .. _class_CanvasItem_constant_TEXTURE_REPEAT_PARENT_NODE:
  257. .. rst-class:: classref-enumeration-constant
  258. :ref:`TextureRepeat<enum_CanvasItem_TextureRepeat>` **TEXTURE_REPEAT_PARENT_NODE** = ``0``
  259. The **CanvasItem** will inherit the filter from its parent.
  260. .. _class_CanvasItem_constant_TEXTURE_REPEAT_DISABLED:
  261. .. rst-class:: classref-enumeration-constant
  262. :ref:`TextureRepeat<enum_CanvasItem_TextureRepeat>` **TEXTURE_REPEAT_DISABLED** = ``1``
  263. Texture will not repeat.
  264. .. _class_CanvasItem_constant_TEXTURE_REPEAT_ENABLED:
  265. .. rst-class:: classref-enumeration-constant
  266. :ref:`TextureRepeat<enum_CanvasItem_TextureRepeat>` **TEXTURE_REPEAT_ENABLED** = ``2``
  267. Texture will repeat normally.
  268. .. _class_CanvasItem_constant_TEXTURE_REPEAT_MIRROR:
  269. .. rst-class:: classref-enumeration-constant
  270. :ref:`TextureRepeat<enum_CanvasItem_TextureRepeat>` **TEXTURE_REPEAT_MIRROR** = ``3``
  271. Texture will repeat in a 2x2 tiled mode, where elements at even positions are mirrored.
  272. .. _class_CanvasItem_constant_TEXTURE_REPEAT_MAX:
  273. .. rst-class:: classref-enumeration-constant
  274. :ref:`TextureRepeat<enum_CanvasItem_TextureRepeat>` **TEXTURE_REPEAT_MAX** = ``4``
  275. Represents the size of the :ref:`TextureRepeat<enum_CanvasItem_TextureRepeat>` enum.
  276. .. rst-class:: classref-item-separator
  277. ----
  278. .. _enum_CanvasItem_ClipChildrenMode:
  279. .. rst-class:: classref-enumeration
  280. enum **ClipChildrenMode**:
  281. .. _class_CanvasItem_constant_CLIP_CHILDREN_DISABLED:
  282. .. rst-class:: classref-enumeration-constant
  283. :ref:`ClipChildrenMode<enum_CanvasItem_ClipChildrenMode>` **CLIP_CHILDREN_DISABLED** = ``0``
  284. Child draws over parent and is not clipped.
  285. .. _class_CanvasItem_constant_CLIP_CHILDREN_ONLY:
  286. .. rst-class:: classref-enumeration-constant
  287. :ref:`ClipChildrenMode<enum_CanvasItem_ClipChildrenMode>` **CLIP_CHILDREN_ONLY** = ``1``
  288. Parent is used for the purposes of clipping only. Child is clipped to the parent's visible area, parent is not drawn.
  289. .. _class_CanvasItem_constant_CLIP_CHILDREN_AND_DRAW:
  290. .. rst-class:: classref-enumeration-constant
  291. :ref:`ClipChildrenMode<enum_CanvasItem_ClipChildrenMode>` **CLIP_CHILDREN_AND_DRAW** = ``2``
  292. Parent is used for clipping child, but parent is also drawn underneath child as normal before clipping child to its visible area.
  293. .. _class_CanvasItem_constant_CLIP_CHILDREN_MAX:
  294. .. rst-class:: classref-enumeration-constant
  295. :ref:`ClipChildrenMode<enum_CanvasItem_ClipChildrenMode>` **CLIP_CHILDREN_MAX** = ``3``
  296. Represents the size of the :ref:`ClipChildrenMode<enum_CanvasItem_ClipChildrenMode>` enum.
  297. .. rst-class:: classref-section-separator
  298. ----
  299. .. rst-class:: classref-descriptions-group
  300. Constants
  301. ---------
  302. .. _class_CanvasItem_constant_NOTIFICATION_TRANSFORM_CHANGED:
  303. .. rst-class:: classref-constant
  304. **NOTIFICATION_TRANSFORM_CHANGED** = ``2000``
  305. 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>`.
  306. .. _class_CanvasItem_constant_NOTIFICATION_LOCAL_TRANSFORM_CHANGED:
  307. .. rst-class:: classref-constant
  308. **NOTIFICATION_LOCAL_TRANSFORM_CHANGED** = ``35``
  309. 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>`.
  310. .. _class_CanvasItem_constant_NOTIFICATION_DRAW:
  311. .. rst-class:: classref-constant
  312. **NOTIFICATION_DRAW** = ``30``
  313. The **CanvasItem** is requested to draw (see :ref:`_draw<class_CanvasItem_method__draw>`).
  314. .. _class_CanvasItem_constant_NOTIFICATION_VISIBILITY_CHANGED:
  315. .. rst-class:: classref-constant
  316. **NOTIFICATION_VISIBILITY_CHANGED** = ``31``
  317. The **CanvasItem**'s visibility has changed.
  318. .. _class_CanvasItem_constant_NOTIFICATION_ENTER_CANVAS:
  319. .. rst-class:: classref-constant
  320. **NOTIFICATION_ENTER_CANVAS** = ``32``
  321. The **CanvasItem** has entered the canvas.
  322. .. _class_CanvasItem_constant_NOTIFICATION_EXIT_CANVAS:
  323. .. rst-class:: classref-constant
  324. **NOTIFICATION_EXIT_CANVAS** = ``33``
  325. The **CanvasItem** has exited the canvas.
  326. .. rst-class:: classref-section-separator
  327. ----
  328. .. rst-class:: classref-descriptions-group
  329. Property Descriptions
  330. ---------------------
  331. .. _class_CanvasItem_property_clip_children:
  332. .. rst-class:: classref-property
  333. :ref:`ClipChildrenMode<enum_CanvasItem_ClipChildrenMode>` **clip_children** = ``0``
  334. .. rst-class:: classref-property-setget
  335. - void **set_clip_children_mode** **(** :ref:`ClipChildrenMode<enum_CanvasItem_ClipChildrenMode>` value **)**
  336. - :ref:`ClipChildrenMode<enum_CanvasItem_ClipChildrenMode>` **get_clip_children_mode** **(** **)**
  337. Allows the current node to clip children nodes, essentially acting as a mask.
  338. .. rst-class:: classref-item-separator
  339. ----
  340. .. _class_CanvasItem_property_light_mask:
  341. .. rst-class:: classref-property
  342. :ref:`int<class_int>` **light_mask** = ``1``
  343. .. rst-class:: classref-property-setget
  344. - void **set_light_mask** **(** :ref:`int<class_int>` value **)**
  345. - :ref:`int<class_int>` **get_light_mask** **(** **)**
  346. The rendering layers in which this **CanvasItem** responds to :ref:`Light2D<class_Light2D>` nodes.
  347. .. rst-class:: classref-item-separator
  348. ----
  349. .. _class_CanvasItem_property_material:
  350. .. rst-class:: classref-property
  351. :ref:`Material<class_Material>` **material**
  352. .. rst-class:: classref-property-setget
  353. - void **set_material** **(** :ref:`Material<class_Material>` value **)**
  354. - :ref:`Material<class_Material>` **get_material** **(** **)**
  355. The material applied to this **CanvasItem**.
  356. .. rst-class:: classref-item-separator
  357. ----
  358. .. _class_CanvasItem_property_modulate:
  359. .. rst-class:: classref-property
  360. :ref:`Color<class_Color>` **modulate** = ``Color(1, 1, 1, 1)``
  361. .. rst-class:: classref-property-setget
  362. - void **set_modulate** **(** :ref:`Color<class_Color>` value **)**
  363. - :ref:`Color<class_Color>` **get_modulate** **(** **)**
  364. The color applied to this **CanvasItem**. This property does affect child **CanvasItem**\ s, unlike :ref:`self_modulate<class_CanvasItem_property_self_modulate>` which only affects the node itself.
  365. .. rst-class:: classref-item-separator
  366. ----
  367. .. _class_CanvasItem_property_self_modulate:
  368. .. rst-class:: classref-property
  369. :ref:`Color<class_Color>` **self_modulate** = ``Color(1, 1, 1, 1)``
  370. .. rst-class:: classref-property-setget
  371. - void **set_self_modulate** **(** :ref:`Color<class_Color>` value **)**
  372. - :ref:`Color<class_Color>` **get_self_modulate** **(** **)**
  373. The color applied to this **CanvasItem**. This property does **not** affect child **CanvasItem**\ s, unlike :ref:`modulate<class_CanvasItem_property_modulate>` which affects both the node itself and its children.
  374. \ **Note:** Internal children (e.g. sliders in :ref:`ColorPicker<class_ColorPicker>` or tab bar in :ref:`TabContainer<class_TabContainer>`) are also not affected by this property (see ``include_internal`` parameter of :ref:`Node.get_child<class_Node_method_get_child>` and other similar methods).
  375. .. rst-class:: classref-item-separator
  376. ----
  377. .. _class_CanvasItem_property_show_behind_parent:
  378. .. rst-class:: classref-property
  379. :ref:`bool<class_bool>` **show_behind_parent** = ``false``
  380. .. rst-class:: classref-property-setget
  381. - void **set_draw_behind_parent** **(** :ref:`bool<class_bool>` value **)**
  382. - :ref:`bool<class_bool>` **is_draw_behind_parent_enabled** **(** **)**
  383. If ``true``, the object draws behind its parent.
  384. .. rst-class:: classref-item-separator
  385. ----
  386. .. _class_CanvasItem_property_texture_filter:
  387. .. rst-class:: classref-property
  388. :ref:`TextureFilter<enum_CanvasItem_TextureFilter>` **texture_filter** = ``0``
  389. .. rst-class:: classref-property-setget
  390. - void **set_texture_filter** **(** :ref:`TextureFilter<enum_CanvasItem_TextureFilter>` value **)**
  391. - :ref:`TextureFilter<enum_CanvasItem_TextureFilter>` **get_texture_filter** **(** **)**
  392. The texture filtering mode to use on this **CanvasItem**.
  393. .. rst-class:: classref-item-separator
  394. ----
  395. .. _class_CanvasItem_property_texture_repeat:
  396. .. rst-class:: classref-property
  397. :ref:`TextureRepeat<enum_CanvasItem_TextureRepeat>` **texture_repeat** = ``0``
  398. .. rst-class:: classref-property-setget
  399. - void **set_texture_repeat** **(** :ref:`TextureRepeat<enum_CanvasItem_TextureRepeat>` value **)**
  400. - :ref:`TextureRepeat<enum_CanvasItem_TextureRepeat>` **get_texture_repeat** **(** **)**
  401. The texture repeating mode to use on this **CanvasItem**.
  402. .. rst-class:: classref-item-separator
  403. ----
  404. .. _class_CanvasItem_property_top_level:
  405. .. rst-class:: classref-property
  406. :ref:`bool<class_bool>` **top_level** = ``false``
  407. .. rst-class:: classref-property-setget
  408. - void **set_as_top_level** **(** :ref:`bool<class_bool>` value **)**
  409. - :ref:`bool<class_bool>` **is_set_as_top_level** **(** **)**
  410. If ``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 do not have :ref:`top_level<class_CanvasItem_property_top_level>` set to ``true``. The **CanvasItem** will effectively act as if it was placed as a child of a bare :ref:`Node<class_Node>`.
  411. .. rst-class:: classref-item-separator
  412. ----
  413. .. _class_CanvasItem_property_use_parent_material:
  414. .. rst-class:: classref-property
  415. :ref:`bool<class_bool>` **use_parent_material** = ``false``
  416. .. rst-class:: classref-property-setget
  417. - void **set_use_parent_material** **(** :ref:`bool<class_bool>` value **)**
  418. - :ref:`bool<class_bool>` **get_use_parent_material** **(** **)**
  419. If ``true``, the parent **CanvasItem**'s :ref:`material<class_CanvasItem_property_material>` property is used as this one's material.
  420. .. rst-class:: classref-item-separator
  421. ----
  422. .. _class_CanvasItem_property_visibility_layer:
  423. .. rst-class:: classref-property
  424. :ref:`int<class_int>` **visibility_layer** = ``1``
  425. .. rst-class:: classref-property-setget
  426. - void **set_visibility_layer** **(** :ref:`int<class_int>` value **)**
  427. - :ref:`int<class_int>` **get_visibility_layer** **(** **)**
  428. The rendering layer in which this **CanvasItem** is rendered by :ref:`Viewport<class_Viewport>` nodes. A :ref:`Viewport<class_Viewport>` will render a **CanvasItem** if it and all its parents share a layer with the :ref:`Viewport<class_Viewport>`'s canvas cull mask.
  429. .. rst-class:: classref-item-separator
  430. ----
  431. .. _class_CanvasItem_property_visible:
  432. .. rst-class:: classref-property
  433. :ref:`bool<class_bool>` **visible** = ``true``
  434. .. rst-class:: classref-property-setget
  435. - void **set_visible** **(** :ref:`bool<class_bool>` value **)**
  436. - :ref:`bool<class_bool>` **is_visible** **(** **)**
  437. 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``).
  438. \ **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.
  439. .. rst-class:: classref-item-separator
  440. ----
  441. .. _class_CanvasItem_property_y_sort_enabled:
  442. .. rst-class:: classref-property
  443. :ref:`bool<class_bool>` **y_sort_enabled** = ``false``
  444. .. rst-class:: classref-property-setget
  445. - void **set_y_sort_enabled** **(** :ref:`bool<class_bool>` value **)**
  446. - :ref:`bool<class_bool>` **is_y_sort_enabled** **(** **)**
  447. If ``true``, child nodes with the lowest Y position are drawn before those with a higher Y position. If ``false``, Y-sorting is disabled. Y-sorting only affects children that inherit from **CanvasItem**.
  448. You can nest nodes with Y-sorting. Child Y-sorted nodes are sorted in the same space as the parent Y-sort. This feature allows you to organize a scene better or divide it into multiple ones without changing your scene tree.
  449. .. rst-class:: classref-item-separator
  450. ----
  451. .. _class_CanvasItem_property_z_as_relative:
  452. .. rst-class:: classref-property
  453. :ref:`bool<class_bool>` **z_as_relative** = ``true``
  454. .. rst-class:: classref-property-setget
  455. - void **set_z_as_relative** **(** :ref:`bool<class_bool>` value **)**
  456. - :ref:`bool<class_bool>` **is_z_relative** **(** **)**
  457. If ``true``, the node's Z index is relative to its parent's Z index. If this node's Z index is 2 and its parent's effective Z index is 3, then this node's effective Z index will be 2 + 3 = 5.
  458. .. rst-class:: classref-item-separator
  459. ----
  460. .. _class_CanvasItem_property_z_index:
  461. .. rst-class:: classref-property
  462. :ref:`int<class_int>` **z_index** = ``0``
  463. .. rst-class:: classref-property-setget
  464. - void **set_z_index** **(** :ref:`int<class_int>` value **)**
  465. - :ref:`int<class_int>` **get_z_index** **(** **)**
  466. Z index. Controls the order in which the nodes render. A node with a higher Z index will display in front of others. Must be between :ref:`RenderingServer.CANVAS_ITEM_Z_MIN<class_RenderingServer_constant_CANVAS_ITEM_Z_MIN>` and :ref:`RenderingServer.CANVAS_ITEM_Z_MAX<class_RenderingServer_constant_CANVAS_ITEM_Z_MAX>` (inclusive).
  467. \ **Note:** Changing the Z index of a :ref:`Control<class_Control>` only affects the drawing order, not the order in which input events are handled. This can be useful to implement certain UI animations, e.g. a menu where hovered items are scaled and should overlap others.
  468. .. rst-class:: classref-section-separator
  469. ----
  470. .. rst-class:: classref-descriptions-group
  471. Method Descriptions
  472. -------------------
  473. .. _class_CanvasItem_method__draw:
  474. .. rst-class:: classref-method
  475. void **_draw** **(** **)** |virtual|
  476. Called when **CanvasItem** has been requested to redraw (after :ref:`queue_redraw<class_CanvasItem_method_queue_redraw>` is called, either manually or by the engine).
  477. Corresponds to the :ref:`NOTIFICATION_DRAW<class_CanvasItem_constant_NOTIFICATION_DRAW>` notification in :ref:`Object._notification<class_Object_method__notification>`.
  478. .. rst-class:: classref-item-separator
  479. ----
  480. .. _class_CanvasItem_method_draw_animation_slice:
  481. .. rst-class:: classref-method
  482. void **draw_animation_slice** **(** :ref:`float<class_float>` animation_length, :ref:`float<class_float>` slice_begin, :ref:`float<class_float>` slice_end, :ref:`float<class_float>` offset=0.0 **)**
  483. Subsequent drawing commands will be ignored unless they fall within the specified animation slice. This is a faster way to implement animations that loop on background rather than redrawing constantly.
  484. .. rst-class:: classref-item-separator
  485. ----
  486. .. _class_CanvasItem_method_draw_arc:
  487. .. rst-class:: classref-method
  488. 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 **)**
  489. Draws an unfilled arc between the given angles with a uniform ``color`` and ``width`` and optional antialiasing (supported only for positive ``width``). The larger the value of ``point_count``, the smoother the curve. See also :ref:`draw_circle<class_CanvasItem_method_draw_circle>`.
  490. If ``width`` is negative, then the arc is drawn using :ref:`RenderingServer.PRIMITIVE_LINE_STRIP<class_RenderingServer_constant_PRIMITIVE_LINE_STRIP>`. This means that when the CanvasItem is scaled, the arc will remain thin. If this behavior is not desired, then pass a positive ``width`` like ``1.0``.
  491. The arc is drawn from ``start_angle`` towards the value of ``end_angle`` so in clockwise direction if ``start_angle < end_angle`` and counter-clockwise otherwise. Passing the same angles but in reversed order will produce the same arc. If absolute difference of ``start_angle`` and ``end_angle`` is greater than :ref:`@GDScript.TAU<class_@GDScript_constant_TAU>` radians, then a full circle arc is drawn (i.e. arc will not overlap itself).
  492. .. rst-class:: classref-item-separator
  493. ----
  494. .. _class_CanvasItem_method_draw_char:
  495. .. rst-class:: classref-method
  496. void **draw_char** **(** :ref:`Font<class_Font>` font, :ref:`Vector2<class_Vector2>` pos, :ref:`String<class_String>` char, :ref:`int<class_int>` font_size=16, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1) **)** |const|
  497. Draws a string first character using a custom font.
  498. .. rst-class:: classref-item-separator
  499. ----
  500. .. _class_CanvasItem_method_draw_char_outline:
  501. .. rst-class:: classref-method
  502. void **draw_char_outline** **(** :ref:`Font<class_Font>` font, :ref:`Vector2<class_Vector2>` pos, :ref:`String<class_String>` char, :ref:`int<class_int>` font_size=16, :ref:`int<class_int>` size=-1, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1) **)** |const|
  503. Draws a string first character outline using a custom font.
  504. .. rst-class:: classref-item-separator
  505. ----
  506. .. _class_CanvasItem_method_draw_circle:
  507. .. rst-class:: classref-method
  508. void **draw_circle** **(** :ref:`Vector2<class_Vector2>` position, :ref:`float<class_float>` radius, :ref:`Color<class_Color>` color **)**
  509. 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>`.
  510. .. rst-class:: classref-item-separator
  511. ----
  512. .. _class_CanvasItem_method_draw_colored_polygon:
  513. .. rst-class:: classref-method
  514. void **draw_colored_polygon** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` points, :ref:`Color<class_Color>` color, :ref:`PackedVector2Array<class_PackedVector2Array>` uvs=PackedVector2Array(), :ref:`Texture2D<class_Texture2D>` texture=null **)**
  515. Draws a colored polygon of any number of points, convex or concave. Unlike :ref:`draw_polygon<class_CanvasItem_method_draw_polygon>`, a single color must be specified for the whole polygon.
  516. .. rst-class:: classref-item-separator
  517. ----
  518. .. _class_CanvasItem_method_draw_dashed_line:
  519. .. rst-class:: classref-method
  520. void **draw_dashed_line** **(** :ref:`Vector2<class_Vector2>` from, :ref:`Vector2<class_Vector2>` to, :ref:`Color<class_Color>` color, :ref:`float<class_float>` width=-1.0, :ref:`float<class_float>` dash=2.0, :ref:`bool<class_bool>` aligned=true **)**
  521. Draws a dashed line from a 2D point to another, with a given color and width. See also :ref:`draw_multiline<class_CanvasItem_method_draw_multiline>` and :ref:`draw_polyline<class_CanvasItem_method_draw_polyline>`.
  522. If ``width`` is negative, then a two-point primitives will be drawn instead of a four-point ones. This means that when the CanvasItem is scaled, the line parts will remain thin. If this behavior is not desired, then pass a positive ``width`` like ``1.0``.
  523. .. rst-class:: classref-item-separator
  524. ----
  525. .. _class_CanvasItem_method_draw_end_animation:
  526. .. rst-class:: classref-method
  527. void **draw_end_animation** **(** **)**
  528. After submitting all animations slices via :ref:`draw_animation_slice<class_CanvasItem_method_draw_animation_slice>`, this function can be used to revert drawing to its default state (all subsequent drawing commands will be visible). If you don't care about this particular use case, usage of this function after submitting the slices is not required.
  529. .. rst-class:: classref-item-separator
  530. ----
  531. .. _class_CanvasItem_method_draw_lcd_texture_rect_region:
  532. .. rst-class:: classref-method
  533. void **draw_lcd_texture_rect_region** **(** :ref:`Texture2D<class_Texture2D>` texture, :ref:`Rect2<class_Rect2>` rect, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1) **)**
  534. Draws a textured rectangle region of the font texture with LCD subpixel anti-aliasing at a given position, optionally modulated by a color.
  535. Texture is drawn using the following blend operation, blend mode of the :ref:`CanvasItemMaterial<class_CanvasItemMaterial>` is ignored:
  536. ::
  537. dst.r = texture.r * modulate.r * modulate.a + dst.r * (1.0 - texture.r * modulate.a);
  538. dst.g = texture.g * modulate.g * modulate.a + dst.g * (1.0 - texture.g * modulate.a);
  539. dst.b = texture.b * modulate.b * modulate.a + dst.b * (1.0 - texture.b * modulate.a);
  540. dst.a = modulate.a + dst.a * (1.0 - modulate.a);
  541. .. rst-class:: classref-item-separator
  542. ----
  543. .. _class_CanvasItem_method_draw_line:
  544. .. rst-class:: classref-method
  545. 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 **)**
  546. 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>`.
  547. If ``width`` is negative, then a two-point primitive will be drawn instead of a four-point one. This means that when the CanvasItem is scaled, the line will remain thin. If this behavior is not desired, then pass a positive ``width`` like ``1.0``.
  548. .. rst-class:: classref-item-separator
  549. ----
  550. .. _class_CanvasItem_method_draw_mesh:
  551. .. rst-class:: classref-method
  552. void **draw_mesh** **(** :ref:`Mesh<class_Mesh>` mesh, :ref:`Texture2D<class_Texture2D>` texture, :ref:`Transform2D<class_Transform2D>` transform=Transform2D(1, 0, 0, 1, 0, 0), :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1) **)**
  553. Draws a :ref:`Mesh<class_Mesh>` in 2D, using the provided texture. See :ref:`MeshInstance2D<class_MeshInstance2D>` for related documentation.
  554. .. rst-class:: classref-item-separator
  555. ----
  556. .. _class_CanvasItem_method_draw_msdf_texture_rect_region:
  557. .. rst-class:: classref-method
  558. void **draw_msdf_texture_rect_region** **(** :ref:`Texture2D<class_Texture2D>` texture, :ref:`Rect2<class_Rect2>` rect, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1), :ref:`float<class_float>` outline=0.0, :ref:`float<class_float>` pixel_range=4.0, :ref:`float<class_float>` scale=1.0 **)**
  559. Draws a textured rectangle region of the multi-channel signed distance field texture at a given position, optionally modulated by a color. See :ref:`FontFile.multichannel_signed_distance_field<class_FontFile_property_multichannel_signed_distance_field>` for more information and caveats about MSDF font rendering.
  560. If ``outline`` is positive, each alpha channel value of pixel in region is set to maximum value of true distance in the ``outline`` radius.
  561. Value of the ``pixel_range`` should the same that was used during distance field texture generation.
  562. .. rst-class:: classref-item-separator
  563. ----
  564. .. _class_CanvasItem_method_draw_multiline:
  565. .. rst-class:: classref-method
  566. void **draw_multiline** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` points, :ref:`Color<class_Color>` color, :ref:`float<class_float>` width=-1.0 **)**
  567. 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.
  568. If ``width`` is negative, then two-point primitives will be drawn instead of a four-point ones. This means that when the CanvasItem is scaled, the lines will remain thin. If this behavior is not desired, then pass a positive ``width`` like ``1.0``.
  569. .. rst-class:: classref-item-separator
  570. ----
  571. .. _class_CanvasItem_method_draw_multiline_colors:
  572. .. rst-class:: classref-method
  573. void **draw_multiline_colors** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` points, :ref:`PackedColorArray<class_PackedColorArray>` colors, :ref:`float<class_float>` width=-1.0 **)**
  574. 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.
  575. If ``width`` is negative, then two-point primitives will be drawn instead of a four-point ones. This means that when the CanvasItem is scaled, the lines will remain thin. If this behavior is not desired, then pass a positive ``width`` like ``1.0``.
  576. .. rst-class:: classref-item-separator
  577. ----
  578. .. _class_CanvasItem_method_draw_multiline_string:
  579. .. rst-class:: classref-method
  580. void **draw_multiline_string** **(** :ref:`Font<class_Font>` font, :ref:`Vector2<class_Vector2>` pos, :ref:`String<class_String>` text, :ref:`HorizontalAlignment<enum_@GlobalScope_HorizontalAlignment>` alignment=0, :ref:`float<class_float>` width=-1, :ref:`int<class_int>` font_size=16, :ref:`int<class_int>` max_lines=-1, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1), :ref:`LineBreakFlag<enum_TextServer_LineBreakFlag>` brk_flags=3, :ref:`JustificationFlag<enum_TextServer_JustificationFlag>` jst_flags=3, :ref:`Direction<enum_TextServer_Direction>` direction=0, :ref:`Orientation<enum_TextServer_Orientation>` orientation=0 **)** |const|
  581. Breaks ``text`` into lines and draws it using the specified ``font`` at the ``pos`` (top-left corner). The text will have its color multiplied by ``modulate``. If ``width`` is greater than or equal to 0, the text will be clipped if it exceeds the specified width.
  582. .. rst-class:: classref-item-separator
  583. ----
  584. .. _class_CanvasItem_method_draw_multiline_string_outline:
  585. .. rst-class:: classref-method
  586. void **draw_multiline_string_outline** **(** :ref:`Font<class_Font>` font, :ref:`Vector2<class_Vector2>` pos, :ref:`String<class_String>` text, :ref:`HorizontalAlignment<enum_@GlobalScope_HorizontalAlignment>` alignment=0, :ref:`float<class_float>` width=-1, :ref:`int<class_int>` font_size=16, :ref:`int<class_int>` max_lines=-1, :ref:`int<class_int>` size=1, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1), :ref:`LineBreakFlag<enum_TextServer_LineBreakFlag>` brk_flags=3, :ref:`JustificationFlag<enum_TextServer_JustificationFlag>` jst_flags=3, :ref:`Direction<enum_TextServer_Direction>` direction=0, :ref:`Orientation<enum_TextServer_Orientation>` orientation=0 **)** |const|
  587. Breaks ``text`` to the lines and draws text outline using the specified ``font`` at the ``pos`` (top-left corner). The text will have its color multiplied by ``modulate``. If ``width`` is greater than or equal to 0, the text will be clipped if it exceeds the specified width.
  588. .. rst-class:: classref-item-separator
  589. ----
  590. .. _class_CanvasItem_method_draw_multimesh:
  591. .. rst-class:: classref-method
  592. void **draw_multimesh** **(** :ref:`MultiMesh<class_MultiMesh>` multimesh, :ref:`Texture2D<class_Texture2D>` texture **)**
  593. Draws a :ref:`MultiMesh<class_MultiMesh>` in 2D with the provided texture. See :ref:`MultiMeshInstance2D<class_MultiMeshInstance2D>` for related documentation.
  594. .. rst-class:: classref-item-separator
  595. ----
  596. .. _class_CanvasItem_method_draw_polygon:
  597. .. rst-class:: classref-method
  598. void **draw_polygon** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` points, :ref:`PackedColorArray<class_PackedColorArray>` colors, :ref:`PackedVector2Array<class_PackedVector2Array>` uvs=PackedVector2Array(), :ref:`Texture2D<class_Texture2D>` texture=null **)**
  599. Draws a solid polygon of any number 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>`. If you need more flexibility (such as being able to use bones), use :ref:`RenderingServer.canvas_item_add_triangle_array<class_RenderingServer_method_canvas_item_add_triangle_array>` instead.
  600. .. rst-class:: classref-item-separator
  601. ----
  602. .. _class_CanvasItem_method_draw_polyline:
  603. .. rst-class:: classref-method
  604. void **draw_polyline** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` points, :ref:`Color<class_Color>` color, :ref:`float<class_float>` width=-1.0, :ref:`bool<class_bool>` antialiased=false **)**
  605. Draws interconnected line segments with a uniform ``color`` and ``width`` and optional antialiasing (supported only for positive ``width``). 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>`.
  606. If ``width`` is negative, the polyline is drawn using :ref:`RenderingServer.PRIMITIVE_LINE_STRIP<class_RenderingServer_constant_PRIMITIVE_LINE_STRIP>`. This means that when the CanvasItem is scaled, the polyline will remain thin. If this behavior is not desired, then pass a positive ``width`` like ``1.0``.
  607. .. rst-class:: classref-item-separator
  608. ----
  609. .. _class_CanvasItem_method_draw_polyline_colors:
  610. .. rst-class:: classref-method
  611. void **draw_polyline_colors** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` points, :ref:`PackedColorArray<class_PackedColorArray>` colors, :ref:`float<class_float>` width=-1.0, :ref:`bool<class_bool>` antialiased=false **)**
  612. Draws interconnected line segments with a uniform ``width`` and segment-by-segment coloring, and optional antialiasing (supported only for positive ``width``). 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>`.
  613. If ``width`` is negative, then the polyline is drawn using :ref:`RenderingServer.PRIMITIVE_LINE_STRIP<class_RenderingServer_constant_PRIMITIVE_LINE_STRIP>`. This means that when the CanvasItem is scaled, the polyline will remain thin. If this behavior is not desired, then pass a positive ``width`` like ``1.0``.
  614. .. rst-class:: classref-item-separator
  615. ----
  616. .. _class_CanvasItem_method_draw_primitive:
  617. .. rst-class:: classref-method
  618. void **draw_primitive** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` points, :ref:`PackedColorArray<class_PackedColorArray>` colors, :ref:`PackedVector2Array<class_PackedVector2Array>` uvs, :ref:`Texture2D<class_Texture2D>` texture=null **)**
  619. 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>`.
  620. .. rst-class:: classref-item-separator
  621. ----
  622. .. _class_CanvasItem_method_draw_rect:
  623. .. rst-class:: classref-method
  624. 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 **)**
  625. 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. See also :ref:`draw_texture_rect<class_CanvasItem_method_draw_texture_rect>`.
  626. If ``width`` is negative, then two-point primitives will be drawn instead of a four-point ones. This means that when the CanvasItem is scaled, the lines will remain thin. If this behavior is not desired, then pass a positive ``width`` like ``1.0``.
  627. \ **Note:** ``width`` is only effective if ``filled`` is ``false``.
  628. \ **Note:** Unfilled rectangles drawn with a negative ``width`` may not display perfectly. For example, corners may be missing or brighter due to overlapping lines (for a translucent ``color``).
  629. .. rst-class:: classref-item-separator
  630. ----
  631. .. _class_CanvasItem_method_draw_set_transform:
  632. .. rst-class:: classref-method
  633. void **draw_set_transform** **(** :ref:`Vector2<class_Vector2>` position, :ref:`float<class_float>` rotation=0.0, :ref:`Vector2<class_Vector2>` scale=Vector2(1, 1) **)**
  634. Sets a custom transform for drawing via components. Anything drawn afterwards will be transformed by this.
  635. \ **Note:** :ref:`FontFile.oversampling<class_FontFile_property_oversampling>` does *not* take ``scale`` into account. This means that scaling up/down will cause bitmap fonts and rasterized (non-MSDF) dynamic fonts to appear blurry or pixelated. To ensure text remains crisp regardless of scale, you can enable MSDF font rendering by enabling :ref:`ProjectSettings.gui/theme/default_font_multichannel_signed_distance_field<class_ProjectSettings_property_gui/theme/default_font_multichannel_signed_distance_field>` (applies to the default project font only), or enabling **Multichannel Signed Distance Field** in the import options of a DynamicFont for custom fonts. On system fonts, :ref:`SystemFont.multichannel_signed_distance_field<class_SystemFont_property_multichannel_signed_distance_field>` can be enabled in the inspector.
  636. .. rst-class:: classref-item-separator
  637. ----
  638. .. _class_CanvasItem_method_draw_set_transform_matrix:
  639. .. rst-class:: classref-method
  640. void **draw_set_transform_matrix** **(** :ref:`Transform2D<class_Transform2D>` xform **)**
  641. Sets a custom transform for drawing via matrix. Anything drawn afterwards will be transformed by this.
  642. .. rst-class:: classref-item-separator
  643. ----
  644. .. _class_CanvasItem_method_draw_string:
  645. .. rst-class:: classref-method
  646. void **draw_string** **(** :ref:`Font<class_Font>` font, :ref:`Vector2<class_Vector2>` pos, :ref:`String<class_String>` text, :ref:`HorizontalAlignment<enum_@GlobalScope_HorizontalAlignment>` alignment=0, :ref:`float<class_float>` width=-1, :ref:`int<class_int>` font_size=16, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1), :ref:`JustificationFlag<enum_TextServer_JustificationFlag>` jst_flags=3, :ref:`Direction<enum_TextServer_Direction>` direction=0, :ref:`Orientation<enum_TextServer_Orientation>` orientation=0 **)** |const|
  647. Draws ``text`` using the specified ``font`` at the ``pos`` (bottom-left corner using the baseline of the font). The text will have its color multiplied by ``modulate``. If ``width`` is greater than or equal to 0, the text will be clipped if it exceeds the specified width.
  648. \ **Example using the default project font:**\
  649. .. tabs::
  650. .. code-tab:: gdscript
  651. # If using this method in a script that redraws constantly, move the
  652. # `default_font` declaration to a member variable assigned in `_ready()`
  653. # so the Control is only created once.
  654. var default_font = ThemeDB.fallback_font
  655. var default_font_size = ThemeDB.fallback_font_size
  656. draw_string(default_font, Vector2(64, 64), "Hello world", HORIZONTAL_ALIGNMENT_LEFT, -1, default_font_size)
  657. .. code-tab:: csharp
  658. // If using this method in a script that redraws constantly, move the
  659. // `default_font` declaration to a member variable assigned in `_Ready()`
  660. // so the Control is only created once.
  661. Font defaultFont = ThemeDB.FallbackFont;
  662. int defaultFontSize = ThemeDB.FallbackFontSize;
  663. DrawString(defaultFont, new Vector2(64, 64), "Hello world", HORIZONTAL_ALIGNMENT_LEFT, -1, defaultFontSize);
  664. See also :ref:`Font.draw_string<class_Font_method_draw_string>`.
  665. .. rst-class:: classref-item-separator
  666. ----
  667. .. _class_CanvasItem_method_draw_string_outline:
  668. .. rst-class:: classref-method
  669. void **draw_string_outline** **(** :ref:`Font<class_Font>` font, :ref:`Vector2<class_Vector2>` pos, :ref:`String<class_String>` text, :ref:`HorizontalAlignment<enum_@GlobalScope_HorizontalAlignment>` alignment=0, :ref:`float<class_float>` width=-1, :ref:`int<class_int>` font_size=16, :ref:`int<class_int>` size=1, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1), :ref:`JustificationFlag<enum_TextServer_JustificationFlag>` jst_flags=3, :ref:`Direction<enum_TextServer_Direction>` direction=0, :ref:`Orientation<enum_TextServer_Orientation>` orientation=0 **)** |const|
  670. Draws ``text`` outline using the specified ``font`` at the ``pos`` (bottom-left corner using the baseline of the font). The text will have its color multiplied by ``modulate``. If ``width`` is greater than or equal to 0, the text will be clipped if it exceeds the specified width.
  671. .. rst-class:: classref-item-separator
  672. ----
  673. .. _class_CanvasItem_method_draw_style_box:
  674. .. rst-class:: classref-method
  675. void **draw_style_box** **(** :ref:`StyleBox<class_StyleBox>` style_box, :ref:`Rect2<class_Rect2>` rect **)**
  676. Draws a styled rectangle.
  677. .. rst-class:: classref-item-separator
  678. ----
  679. .. _class_CanvasItem_method_draw_texture:
  680. .. rst-class:: classref-method
  681. void **draw_texture** **(** :ref:`Texture2D<class_Texture2D>` texture, :ref:`Vector2<class_Vector2>` position, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1) **)**
  682. Draws a texture at a given position.
  683. .. rst-class:: classref-item-separator
  684. ----
  685. .. _class_CanvasItem_method_draw_texture_rect:
  686. .. rst-class:: classref-method
  687. void **draw_texture_rect** **(** :ref:`Texture2D<class_Texture2D>` 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 **)**
  688. 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. See also :ref:`draw_rect<class_CanvasItem_method_draw_rect>` and :ref:`draw_texture_rect_region<class_CanvasItem_method_draw_texture_rect_region>`.
  689. .. rst-class:: classref-item-separator
  690. ----
  691. .. _class_CanvasItem_method_draw_texture_rect_region:
  692. .. rst-class:: classref-method
  693. void **draw_texture_rect_region** **(** :ref:`Texture2D<class_Texture2D>` 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:`bool<class_bool>` clip_uv=true **)**
  694. Draws a textured rectangle from a texture's region (specified by ``src_rect``) at a given position, optionally modulated by a color. If ``transpose`` is ``true``, the texture will have its X and Y coordinates swapped. See also :ref:`draw_texture_rect<class_CanvasItem_method_draw_texture_rect>`.
  695. .. rst-class:: classref-item-separator
  696. ----
  697. .. _class_CanvasItem_method_force_update_transform:
  698. .. rst-class:: classref-method
  699. void **force_update_transform** **(** **)**
  700. 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.
  701. .. rst-class:: classref-item-separator
  702. ----
  703. .. _class_CanvasItem_method_get_canvas:
  704. .. rst-class:: classref-method
  705. :ref:`RID<class_RID>` **get_canvas** **(** **)** |const|
  706. Returns the :ref:`RID<class_RID>` of the :ref:`World2D<class_World2D>` canvas where this item is in.
  707. .. rst-class:: classref-item-separator
  708. ----
  709. .. _class_CanvasItem_method_get_canvas_item:
  710. .. rst-class:: classref-method
  711. :ref:`RID<class_RID>` **get_canvas_item** **(** **)** |const|
  712. Returns the canvas item RID used by :ref:`RenderingServer<class_RenderingServer>` for this item.
  713. .. rst-class:: classref-item-separator
  714. ----
  715. .. _class_CanvasItem_method_get_canvas_transform:
  716. .. rst-class:: classref-method
  717. :ref:`Transform2D<class_Transform2D>` **get_canvas_transform** **(** **)** |const|
  718. Returns the transform from the coordinate system of the canvas, this item is in, to the :ref:`Viewport<class_Viewport>`\ s coordinate system.
  719. .. rst-class:: classref-item-separator
  720. ----
  721. .. _class_CanvasItem_method_get_global_mouse_position:
  722. .. rst-class:: classref-method
  723. :ref:`Vector2<class_Vector2>` **get_global_mouse_position** **(** **)** |const|
  724. 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>`.
  725. \ **Note:** For screen-space coordinates (e.g. when using a non-embedded :ref:`Popup<class_Popup>`), you can use :ref:`DisplayServer.mouse_get_position<class_DisplayServer_method_mouse_get_position>`.
  726. .. rst-class:: classref-item-separator
  727. ----
  728. .. _class_CanvasItem_method_get_global_transform:
  729. .. rst-class:: classref-method
  730. :ref:`Transform2D<class_Transform2D>` **get_global_transform** **(** **)** |const|
  731. Returns the global transform matrix of this item, i.e. the combined transform up to the topmost **CanvasItem** node. The topmost item is a **CanvasItem** that either has no parent, has non-**CanvasItem** parent or it has :ref:`top_level<class_CanvasItem_property_top_level>` enabled.
  732. .. rst-class:: classref-item-separator
  733. ----
  734. .. _class_CanvasItem_method_get_global_transform_with_canvas:
  735. .. rst-class:: classref-method
  736. :ref:`Transform2D<class_Transform2D>` **get_global_transform_with_canvas** **(** **)** |const|
  737. Returns the transform from the local coordinate system of this **CanvasItem** to the :ref:`Viewport<class_Viewport>`\ s coordinate system.
  738. .. rst-class:: classref-item-separator
  739. ----
  740. .. _class_CanvasItem_method_get_local_mouse_position:
  741. .. rst-class:: classref-method
  742. :ref:`Vector2<class_Vector2>` **get_local_mouse_position** **(** **)** |const|
  743. Returns the mouse's position in this **CanvasItem** using the local coordinate system of this **CanvasItem**.
  744. .. rst-class:: classref-item-separator
  745. ----
  746. .. _class_CanvasItem_method_get_screen_transform:
  747. .. rst-class:: classref-method
  748. :ref:`Transform2D<class_Transform2D>` **get_screen_transform** **(** **)** |const|
  749. Returns the transform of this **CanvasItem** in global screen coordinates (i.e. taking window position into account). Mostly useful for editor plugins.
  750. Equals to :ref:`get_global_transform<class_CanvasItem_method_get_global_transform>` if the window is embedded (see :ref:`Viewport.gui_embed_subwindows<class_Viewport_property_gui_embed_subwindows>`).
  751. .. rst-class:: classref-item-separator
  752. ----
  753. .. _class_CanvasItem_method_get_transform:
  754. .. rst-class:: classref-method
  755. :ref:`Transform2D<class_Transform2D>` **get_transform** **(** **)** |const|
  756. Returns the transform matrix of this item.
  757. .. rst-class:: classref-item-separator
  758. ----
  759. .. _class_CanvasItem_method_get_viewport_rect:
  760. .. rst-class:: classref-method
  761. :ref:`Rect2<class_Rect2>` **get_viewport_rect** **(** **)** |const|
  762. Returns the viewport's boundaries as a :ref:`Rect2<class_Rect2>`.
  763. .. rst-class:: classref-item-separator
  764. ----
  765. .. _class_CanvasItem_method_get_viewport_transform:
  766. .. rst-class:: classref-method
  767. :ref:`Transform2D<class_Transform2D>` **get_viewport_transform** **(** **)** |const|
  768. Returns the transform from the coordinate system of the canvas, this item is in, to the :ref:`Viewport<class_Viewport>`\ s embedders coordinate system.
  769. .. rst-class:: classref-item-separator
  770. ----
  771. .. _class_CanvasItem_method_get_visibility_layer_bit:
  772. .. rst-class:: classref-method
  773. :ref:`bool<class_bool>` **get_visibility_layer_bit** **(** :ref:`int<class_int>` layer **)** |const|
  774. Returns an individual bit on the rendering visibility layer.
  775. .. rst-class:: classref-item-separator
  776. ----
  777. .. _class_CanvasItem_method_get_world_2d:
  778. .. rst-class:: classref-method
  779. :ref:`World2D<class_World2D>` **get_world_2d** **(** **)** |const|
  780. Returns the :ref:`World2D<class_World2D>` where this item is in.
  781. .. rst-class:: classref-item-separator
  782. ----
  783. .. _class_CanvasItem_method_hide:
  784. .. rst-class:: classref-method
  785. void **hide** **(** **)**
  786. Hide the **CanvasItem** if it's currently visible. This is equivalent to setting :ref:`visible<class_CanvasItem_property_visible>` to ``false``.
  787. .. rst-class:: classref-item-separator
  788. ----
  789. .. _class_CanvasItem_method_is_local_transform_notification_enabled:
  790. .. rst-class:: classref-method
  791. :ref:`bool<class_bool>` **is_local_transform_notification_enabled** **(** **)** |const|
  792. Returns ``true`` if local transform notifications are communicated to children.
  793. .. rst-class:: classref-item-separator
  794. ----
  795. .. _class_CanvasItem_method_is_transform_notification_enabled:
  796. .. rst-class:: classref-method
  797. :ref:`bool<class_bool>` **is_transform_notification_enabled** **(** **)** |const|
  798. Returns ``true`` if global transform notifications are communicated to children.
  799. .. rst-class:: classref-item-separator
  800. ----
  801. .. _class_CanvasItem_method_is_visible_in_tree:
  802. .. rst-class:: classref-method
  803. :ref:`bool<class_bool>` **is_visible_in_tree** **(** **)** |const|
  804. 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>`).
  805. .. rst-class:: classref-item-separator
  806. ----
  807. .. _class_CanvasItem_method_make_canvas_position_local:
  808. .. rst-class:: classref-method
  809. :ref:`Vector2<class_Vector2>` **make_canvas_position_local** **(** :ref:`Vector2<class_Vector2>` screen_point **)** |const|
  810. Assigns ``screen_point`` as this node's new local transform.
  811. .. rst-class:: classref-item-separator
  812. ----
  813. .. _class_CanvasItem_method_make_input_local:
  814. .. rst-class:: classref-method
  815. :ref:`InputEvent<class_InputEvent>` **make_input_local** **(** :ref:`InputEvent<class_InputEvent>` event **)** |const|
  816. Transformations issued by ``event``'s inputs are applied in local space instead of global space.
  817. .. rst-class:: classref-item-separator
  818. ----
  819. .. _class_CanvasItem_method_move_to_front:
  820. .. rst-class:: classref-method
  821. void **move_to_front** **(** **)**
  822. Moves this node to display on top of its siblings.
  823. Internally, the node is moved to the bottom of parent's children list. The method has no effect on nodes without a parent.
  824. .. rst-class:: classref-item-separator
  825. ----
  826. .. _class_CanvasItem_method_queue_redraw:
  827. .. rst-class:: classref-method
  828. void **queue_redraw** **(** **)**
  829. 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.
  830. .. rst-class:: classref-item-separator
  831. ----
  832. .. _class_CanvasItem_method_set_notify_local_transform:
  833. .. rst-class:: classref-method
  834. void **set_notify_local_transform** **(** :ref:`bool<class_bool>` enable **)**
  835. 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.
  836. .. rst-class:: classref-item-separator
  837. ----
  838. .. _class_CanvasItem_method_set_notify_transform:
  839. .. rst-class:: classref-method
  840. void **set_notify_transform** **(** :ref:`bool<class_bool>` enable **)**
  841. If ``enable`` is ``true``, this node will receive :ref:`NOTIFICATION_TRANSFORM_CHANGED<class_CanvasItem_constant_NOTIFICATION_TRANSFORM_CHANGED>` when its global transform changes.
  842. .. rst-class:: classref-item-separator
  843. ----
  844. .. _class_CanvasItem_method_set_visibility_layer_bit:
  845. .. rst-class:: classref-method
  846. void **set_visibility_layer_bit** **(** :ref:`int<class_int>` layer, :ref:`bool<class_bool>` enabled **)**
  847. Set/clear individual bits on the rendering visibility layer. This simplifies editing this **CanvasItem**'s visibility layer.
  848. .. rst-class:: classref-item-separator
  849. ----
  850. .. _class_CanvasItem_method_show:
  851. .. rst-class:: classref-method
  852. void **show** **(** **)**
  853. 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.
  854. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  855. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  856. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  857. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  858. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  859. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`