class_canvasitem.rst 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the CanvasItem.xml source instead.
  3. .. The source is found in doc/classes or modules/<name>/doc_classes.
  4. .. _class_CanvasItem:
  5. CanvasItem
  6. ==========
  7. **Inherits:** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  8. **Inherited By:** :ref:`Control<class_Control>`, :ref:`Node2D<class_Node2D>`
  9. **Category:** Core
  10. Brief Description
  11. -----------------
  12. Base class of anything 2D.
  13. Properties
  14. ----------
  15. +---------------------------------+---------------------------------------------------------------------------+---------------------+
  16. | :ref:`int<class_int>` | :ref:`light_mask<class_CanvasItem_property_light_mask>` | 1 |
  17. +---------------------------------+---------------------------------------------------------------------------+---------------------+
  18. | :ref:`Material<class_Material>` | :ref:`material<class_CanvasItem_property_material>` | |
  19. +---------------------------------+---------------------------------------------------------------------------+---------------------+
  20. | :ref:`Color<class_Color>` | :ref:`modulate<class_CanvasItem_property_modulate>` | Color( 1, 1, 1, 1 ) |
  21. +---------------------------------+---------------------------------------------------------------------------+---------------------+
  22. | :ref:`Color<class_Color>` | :ref:`self_modulate<class_CanvasItem_property_self_modulate>` | Color( 1, 1, 1, 1 ) |
  23. +---------------------------------+---------------------------------------------------------------------------+---------------------+
  24. | :ref:`bool<class_bool>` | :ref:`show_behind_parent<class_CanvasItem_property_show_behind_parent>` | false |
  25. +---------------------------------+---------------------------------------------------------------------------+---------------------+
  26. | :ref:`bool<class_bool>` | :ref:`show_on_top<class_CanvasItem_property_show_on_top>` | |
  27. +---------------------------------+---------------------------------------------------------------------------+---------------------+
  28. | :ref:`bool<class_bool>` | :ref:`use_parent_material<class_CanvasItem_property_use_parent_material>` | false |
  29. +---------------------------------+---------------------------------------------------------------------------+---------------------+
  30. | :ref:`bool<class_bool>` | :ref:`visible<class_CanvasItem_property_visible>` | true |
  31. +---------------------------------+---------------------------------------------------------------------------+---------------------+
  32. Methods
  33. -------
  34. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | void | :ref:`_draw<class_CanvasItem_method__draw>` **(** **)** virtual |
  36. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`float<class_float>` | :ref:`draw_char<class_CanvasItem_method_draw_char>` **(** :ref:`Font<class_Font>` font, :ref:`Vector2<class_Vector2>` position, :ref:`String<class_String>` char, :ref:`String<class_String>` next, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ) **)** |
  38. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | void | :ref:`draw_circle<class_CanvasItem_method_draw_circle>` **(** :ref:`Vector2<class_Vector2>` position, :ref:`float<class_float>` radius, :ref:`Color<class_Color>` color **)** |
  40. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | void | :ref:`draw_colored_polygon<class_CanvasItem_method_draw_colored_polygon>` **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`Color<class_Color>` color, :ref:`PoolVector2Array<class_PoolVector2Array>` uvs=PoolVector2Array( ), :ref:`Texture<class_Texture>` texture=null, :ref:`Texture<class_Texture>` normal_map=null, :ref:`bool<class_bool>` antialiased=false **)** |
  42. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | 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 **)** |
  44. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | void | :ref:`draw_mesh<class_CanvasItem_method_draw_mesh>` **(** :ref:`Mesh<class_Mesh>` mesh, :ref:`Texture<class_Texture>` texture, :ref:`Texture<class_Texture>` normal_map=null, :ref:`Transform2D<class_Transform2D>` transform=Transform2D( 1, 0, 0, 1, 0, 0 ), :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ) **)** |
  46. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | void | :ref:`draw_multiline<class_CanvasItem_method_draw_multiline>` **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`Color<class_Color>` color, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)** |
  48. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`draw_multiline_colors<class_CanvasItem_method_draw_multiline_colors>` **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`PoolColorArray<class_PoolColorArray>` colors, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)** |
  50. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`draw_multimesh<class_CanvasItem_method_draw_multimesh>` **(** :ref:`MultiMesh<class_MultiMesh>` multimesh, :ref:`Texture<class_Texture>` texture, :ref:`Texture<class_Texture>` normal_map=null **)** |
  52. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`draw_polygon<class_CanvasItem_method_draw_polygon>` **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`PoolColorArray<class_PoolColorArray>` colors, :ref:`PoolVector2Array<class_PoolVector2Array>` uvs=PoolVector2Array( ), :ref:`Texture<class_Texture>` texture=null, :ref:`Texture<class_Texture>` normal_map=null, :ref:`bool<class_bool>` antialiased=false **)** |
  54. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`draw_polyline<class_CanvasItem_method_draw_polyline>` **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`Color<class_Color>` color, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)** |
  56. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`draw_polyline_colors<class_CanvasItem_method_draw_polyline_colors>` **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`PoolColorArray<class_PoolColorArray>` colors, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)** |
  58. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`draw_primitive<class_CanvasItem_method_draw_primitive>` **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`PoolColorArray<class_PoolColorArray>` colors, :ref:`PoolVector2Array<class_PoolVector2Array>` uvs, :ref:`Texture<class_Texture>` texture=null, :ref:`float<class_float>` width=1.0, :ref:`Texture<class_Texture>` normal_map=null **)** |
  60. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | void | :ref:`draw_rect<class_CanvasItem_method_draw_rect>` **(** :ref:`Rect2<class_Rect2>` rect, :ref:`Color<class_Color>` color, :ref:`bool<class_bool>` filled=true, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)** |
  62. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | void | :ref:`draw_set_transform<class_CanvasItem_method_draw_set_transform>` **(** :ref:`Vector2<class_Vector2>` position, :ref:`float<class_float>` rotation, :ref:`Vector2<class_Vector2>` scale **)** |
  64. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | void | :ref:`draw_set_transform_matrix<class_CanvasItem_method_draw_set_transform_matrix>` **(** :ref:`Transform2D<class_Transform2D>` xform **)** |
  66. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | void | :ref:`draw_string<class_CanvasItem_method_draw_string>` **(** :ref:`Font<class_Font>` font, :ref:`Vector2<class_Vector2>` position, :ref:`String<class_String>` text, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`int<class_int>` clip_w=-1 **)** |
  68. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | void | :ref:`draw_style_box<class_CanvasItem_method_draw_style_box>` **(** :ref:`StyleBox<class_StyleBox>` style_box, :ref:`Rect2<class_Rect2>` rect **)** |
  70. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | void | :ref:`draw_texture<class_CanvasItem_method_draw_texture>` **(** :ref:`Texture<class_Texture>` texture, :ref:`Vector2<class_Vector2>` position, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`Texture<class_Texture>` normal_map=null **)** |
  72. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | void | :ref:`draw_texture_rect<class_CanvasItem_method_draw_texture_rect>` **(** :ref:`Texture<class_Texture>` texture, :ref:`Rect2<class_Rect2>` rect, :ref:`bool<class_bool>` tile, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`bool<class_bool>` transpose=false, :ref:`Texture<class_Texture>` normal_map=null **)** |
  74. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | void | :ref:`draw_texture_rect_region<class_CanvasItem_method_draw_texture_rect_region>` **(** :ref:`Texture<class_Texture>` texture, :ref:`Rect2<class_Rect2>` rect, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`bool<class_bool>` transpose=false, :ref:`Texture<class_Texture>` normal_map=null, :ref:`bool<class_bool>` clip_uv=true **)** |
  76. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | void | :ref:`force_update_transform<class_CanvasItem_method_force_update_transform>` **(** **)** |
  78. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | :ref:`RID<class_RID>` | :ref:`get_canvas<class_CanvasItem_method_get_canvas>` **(** **)** const |
  80. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. | :ref:`RID<class_RID>` | :ref:`get_canvas_item<class_CanvasItem_method_get_canvas_item>` **(** **)** const |
  82. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. | :ref:`Transform2D<class_Transform2D>` | :ref:`get_canvas_transform<class_CanvasItem_method_get_canvas_transform>` **(** **)** const |
  84. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  85. | :ref:`Vector2<class_Vector2>` | :ref:`get_global_mouse_position<class_CanvasItem_method_get_global_mouse_position>` **(** **)** const |
  86. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  87. | :ref:`Transform2D<class_Transform2D>` | :ref:`get_global_transform<class_CanvasItem_method_get_global_transform>` **(** **)** const |
  88. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  89. | :ref:`Transform2D<class_Transform2D>` | :ref:`get_global_transform_with_canvas<class_CanvasItem_method_get_global_transform_with_canvas>` **(** **)** const |
  90. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  91. | :ref:`Vector2<class_Vector2>` | :ref:`get_local_mouse_position<class_CanvasItem_method_get_local_mouse_position>` **(** **)** const |
  92. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  93. | :ref:`Transform2D<class_Transform2D>` | :ref:`get_transform<class_CanvasItem_method_get_transform>` **(** **)** const |
  94. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  95. | :ref:`Rect2<class_Rect2>` | :ref:`get_viewport_rect<class_CanvasItem_method_get_viewport_rect>` **(** **)** const |
  96. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  97. | :ref:`Transform2D<class_Transform2D>` | :ref:`get_viewport_transform<class_CanvasItem_method_get_viewport_transform>` **(** **)** const |
  98. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  99. | :ref:`World2D<class_World2D>` | :ref:`get_world_2d<class_CanvasItem_method_get_world_2d>` **(** **)** const |
  100. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  101. | void | :ref:`hide<class_CanvasItem_method_hide>` **(** **)** |
  102. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  103. | :ref:`bool<class_bool>` | :ref:`is_local_transform_notification_enabled<class_CanvasItem_method_is_local_transform_notification_enabled>` **(** **)** const |
  104. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  105. | :ref:`bool<class_bool>` | :ref:`is_set_as_toplevel<class_CanvasItem_method_is_set_as_toplevel>` **(** **)** const |
  106. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  107. | :ref:`bool<class_bool>` | :ref:`is_transform_notification_enabled<class_CanvasItem_method_is_transform_notification_enabled>` **(** **)** const |
  108. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  109. | :ref:`bool<class_bool>` | :ref:`is_visible_in_tree<class_CanvasItem_method_is_visible_in_tree>` **(** **)** const |
  110. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  111. | :ref:`Vector2<class_Vector2>` | :ref:`make_canvas_position_local<class_CanvasItem_method_make_canvas_position_local>` **(** :ref:`Vector2<class_Vector2>` screen_point **)** const |
  112. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  113. | :ref:`InputEvent<class_InputEvent>` | :ref:`make_input_local<class_CanvasItem_method_make_input_local>` **(** :ref:`InputEvent<class_InputEvent>` event **)** const |
  114. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  115. | void | :ref:`set_as_toplevel<class_CanvasItem_method_set_as_toplevel>` **(** :ref:`bool<class_bool>` enable **)** |
  116. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  117. | void | :ref:`set_notify_local_transform<class_CanvasItem_method_set_notify_local_transform>` **(** :ref:`bool<class_bool>` enable **)** |
  118. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  119. | void | :ref:`set_notify_transform<class_CanvasItem_method_set_notify_transform>` **(** :ref:`bool<class_bool>` enable **)** |
  120. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  121. | void | :ref:`show<class_CanvasItem_method_show>` **(** **)** |
  122. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  123. | void | :ref:`update<class_CanvasItem_method_update>` **(** **)** |
  124. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  125. Signals
  126. -------
  127. .. _class_CanvasItem_signal_draw:
  128. - **draw** **(** **)**
  129. Emitted when the CanvasItem must redraw. This can only be connected realtime, as deferred will not allow drawing.
  130. .. _class_CanvasItem_signal_hide:
  131. - **hide** **(** **)**
  132. Emitted when becoming hidden.
  133. .. _class_CanvasItem_signal_item_rect_changed:
  134. - **item_rect_changed** **(** **)**
  135. Emitted when the item rect has changed.
  136. .. _class_CanvasItem_signal_visibility_changed:
  137. - **visibility_changed** **(** **)**
  138. Emitted when the visibility (hidden/visible) changes.
  139. Enumerations
  140. ------------
  141. .. _enum_CanvasItem_BlendMode:
  142. .. _class_CanvasItem_constant_BLEND_MODE_MIX:
  143. .. _class_CanvasItem_constant_BLEND_MODE_ADD:
  144. .. _class_CanvasItem_constant_BLEND_MODE_SUB:
  145. .. _class_CanvasItem_constant_BLEND_MODE_MUL:
  146. .. _class_CanvasItem_constant_BLEND_MODE_PREMULT_ALPHA:
  147. .. _class_CanvasItem_constant_BLEND_MODE_DISABLED:
  148. enum **BlendMode**:
  149. - **BLEND_MODE_MIX** = **0** --- Mix blending mode. Colors are assumed to be independent of the alpha (opacity) value.
  150. - **BLEND_MODE_ADD** = **1** --- Additive blending mode.
  151. - **BLEND_MODE_SUB** = **2** --- Subtractive blending mode.
  152. - **BLEND_MODE_MUL** = **3** --- Multiplicative blending mode.
  153. - **BLEND_MODE_PREMULT_ALPHA** = **4** --- Mix blending mode. Colors are assumed to be premultiplied by the alpha (opacity) value.
  154. - **BLEND_MODE_DISABLED** = **5** --- Disables blending mode. Colors including alpha are written as-is. Only applicable for render targets with a transparent background. No lighting will be applied.
  155. Constants
  156. ---------
  157. .. _class_CanvasItem_constant_NOTIFICATION_TRANSFORM_CHANGED:
  158. .. _class_CanvasItem_constant_NOTIFICATION_DRAW:
  159. .. _class_CanvasItem_constant_NOTIFICATION_VISIBILITY_CHANGED:
  160. .. _class_CanvasItem_constant_NOTIFICATION_ENTER_CANVAS:
  161. .. _class_CanvasItem_constant_NOTIFICATION_EXIT_CANVAS:
  162. - **NOTIFICATION_TRANSFORM_CHANGED** = **2000** --- The CanvasItem's transform has changed. This notification is only received if enabled by :ref:`set_notify_transform<class_CanvasItem_method_set_notify_transform>` or :ref:`set_notify_local_transform<class_CanvasItem_method_set_notify_local_transform>`.
  163. - **NOTIFICATION_DRAW** = **30** --- The CanvasItem is requested to draw.
  164. - **NOTIFICATION_VISIBILITY_CHANGED** = **31** --- The CanvasItem's visibility has changed.
  165. - **NOTIFICATION_ENTER_CANVAS** = **32** --- The CanvasItem has entered the canvas.
  166. - **NOTIFICATION_EXIT_CANVAS** = **33** --- The CanvasItem has exited the canvas.
  167. Description
  168. -----------
  169. Base class of anything 2D. Canvas items are laid out in a tree; children inherit and extend their parent's transform. CanvasItem is extended by :ref:`Control<class_Control>` for anything GUI-related, and by :ref:`Node2D<class_Node2D>` for anything related to the 2D engine.
  170. Any CanvasItem can draw. For this, :ref:`update<class_CanvasItem_method_update>` must be called, then :ref:`NOTIFICATION_DRAW<class_CanvasItem_constant_NOTIFICATION_DRAW>` will be received on idle time to request redraw. Because of this, canvas items don't need to be redrawn on every frame, improving the performance significantly. Several functions for drawing on the CanvasItem are provided (see ``draw_*`` functions). However, they can only be used inside the :ref:`Object._notification<class_Object_method__notification>`, signal or :ref:`_draw<class_CanvasItem_method__draw>` virtual functions.
  171. 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.
  172. A CanvasItem can also be hidden, which will also hide its children. It provides many ways to change parameters such as modulation (for itself and its children) and self modulation (only for itself), as well as its blend mode.
  173. Ultimately, a transform notification can be requested, which will notify the node that its global position changed in case the parent tree changed.
  174. Tutorials
  175. ---------
  176. - :doc:`../tutorials/2d/2d_transforms`
  177. - :doc:`../tutorials/2d/custom_drawing_in_2d`
  178. Property Descriptions
  179. ---------------------
  180. .. _class_CanvasItem_property_light_mask:
  181. - :ref:`int<class_int>` **light_mask**
  182. +-----------+-----------------------+
  183. | *Default* | 1 |
  184. +-----------+-----------------------+
  185. | *Setter* | set_light_mask(value) |
  186. +-----------+-----------------------+
  187. | *Getter* | get_light_mask() |
  188. +-----------+-----------------------+
  189. The rendering layers in which this ``CanvasItem`` responds to :ref:`Light2D<class_Light2D>` nodes.
  190. .. _class_CanvasItem_property_material:
  191. - :ref:`Material<class_Material>` **material**
  192. +----------+---------------------+
  193. | *Setter* | set_material(value) |
  194. +----------+---------------------+
  195. | *Getter* | get_material() |
  196. +----------+---------------------+
  197. The material applied to textures on this ``CanvasItem``.
  198. .. _class_CanvasItem_property_modulate:
  199. - :ref:`Color<class_Color>` **modulate**
  200. +-----------+---------------------+
  201. | *Default* | Color( 1, 1, 1, 1 ) |
  202. +-----------+---------------------+
  203. | *Setter* | set_modulate(value) |
  204. +-----------+---------------------+
  205. | *Getter* | get_modulate() |
  206. +-----------+---------------------+
  207. The color applied to textures on this ``CanvasItem``.
  208. .. _class_CanvasItem_property_self_modulate:
  209. - :ref:`Color<class_Color>` **self_modulate**
  210. +-----------+--------------------------+
  211. | *Default* | Color( 1, 1, 1, 1 ) |
  212. +-----------+--------------------------+
  213. | *Setter* | set_self_modulate(value) |
  214. +-----------+--------------------------+
  215. | *Getter* | get_self_modulate() |
  216. +-----------+--------------------------+
  217. The color applied to textures on this ``CanvasItem``. This is not inherited by children ``CanvasItem``\ s.
  218. .. _class_CanvasItem_property_show_behind_parent:
  219. - :ref:`bool<class_bool>` **show_behind_parent**
  220. +-----------+---------------------------------+
  221. | *Default* | false |
  222. +-----------+---------------------------------+
  223. | *Setter* | set_draw_behind_parent(value) |
  224. +-----------+---------------------------------+
  225. | *Getter* | is_draw_behind_parent_enabled() |
  226. +-----------+---------------------------------+
  227. If ``true``, the object draws behind its parent.
  228. .. _class_CanvasItem_property_show_on_top:
  229. - :ref:`bool<class_bool>` **show_on_top**
  230. If ``true``, the object draws on top of its parent.
  231. .. _class_CanvasItem_property_use_parent_material:
  232. - :ref:`bool<class_bool>` **use_parent_material**
  233. +-----------+--------------------------------+
  234. | *Default* | false |
  235. +-----------+--------------------------------+
  236. | *Setter* | set_use_parent_material(value) |
  237. +-----------+--------------------------------+
  238. | *Getter* | get_use_parent_material() |
  239. +-----------+--------------------------------+
  240. If ``true``, the parent ``CanvasItem``'s :ref:`material<class_CanvasItem_property_material>` property is used as this one's material.
  241. .. _class_CanvasItem_property_visible:
  242. - :ref:`bool<class_bool>` **visible**
  243. +-----------+--------------------+
  244. | *Default* | true |
  245. +-----------+--------------------+
  246. | *Setter* | set_visible(value) |
  247. +-----------+--------------------+
  248. | *Getter* | is_visible() |
  249. +-----------+--------------------+
  250. If ``true``, this ``CanvasItem`` is drawn. 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.
  251. Method Descriptions
  252. -------------------
  253. .. _class_CanvasItem_method__draw:
  254. - void **_draw** **(** **)** virtual
  255. Called (if exists) to draw the canvas item.
  256. .. _class_CanvasItem_method_draw_char:
  257. - :ref:`float<class_float>` **draw_char** **(** :ref:`Font<class_Font>` font, :ref:`Vector2<class_Vector2>` position, :ref:`String<class_String>` char, :ref:`String<class_String>` next, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ) **)**
  258. Draws a string character using a custom font. Returns the advance, depending on the character width and kerning with an optional next character.
  259. .. _class_CanvasItem_method_draw_circle:
  260. - void **draw_circle** **(** :ref:`Vector2<class_Vector2>` position, :ref:`float<class_float>` radius, :ref:`Color<class_Color>` color **)**
  261. Draws a colored circle.
  262. .. _class_CanvasItem_method_draw_colored_polygon:
  263. - void **draw_colored_polygon** **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`Color<class_Color>` color, :ref:`PoolVector2Array<class_PoolVector2Array>` uvs=PoolVector2Array( ), :ref:`Texture<class_Texture>` texture=null, :ref:`Texture<class_Texture>` normal_map=null, :ref:`bool<class_bool>` antialiased=false **)**
  264. Draws a colored polygon of any amount of points, convex or concave.
  265. .. _class_CanvasItem_method_draw_line:
  266. - 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 **)**
  267. Draws a line from a 2D point to another, with a given color and width. It can be optionally antialiased.
  268. .. _class_CanvasItem_method_draw_mesh:
  269. - void **draw_mesh** **(** :ref:`Mesh<class_Mesh>` mesh, :ref:`Texture<class_Texture>` texture, :ref:`Texture<class_Texture>` normal_map=null, :ref:`Transform2D<class_Transform2D>` transform=Transform2D( 1, 0, 0, 1, 0, 0 ), :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ) **)**
  270. .. _class_CanvasItem_method_draw_multiline:
  271. - void **draw_multiline** **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`Color<class_Color>` color, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)**
  272. Draws multiple, parallel lines with a uniform ``color``. ``width`` and ``antialiased`` are currently not implemented and have no effect.
  273. .. _class_CanvasItem_method_draw_multiline_colors:
  274. - void **draw_multiline_colors** **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`PoolColorArray<class_PoolColorArray>` colors, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)**
  275. Draws multiple, parallel lines with a uniform ``width``, segment-by-segment coloring, and optional antialiasing. Colors assigned to line segments match by index between ``points`` and ``colors``.
  276. .. _class_CanvasItem_method_draw_multimesh:
  277. - void **draw_multimesh** **(** :ref:`MultiMesh<class_MultiMesh>` multimesh, :ref:`Texture<class_Texture>` texture, :ref:`Texture<class_Texture>` normal_map=null **)**
  278. .. _class_CanvasItem_method_draw_polygon:
  279. - void **draw_polygon** **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`PoolColorArray<class_PoolColorArray>` colors, :ref:`PoolVector2Array<class_PoolVector2Array>` uvs=PoolVector2Array( ), :ref:`Texture<class_Texture>` texture=null, :ref:`Texture<class_Texture>` normal_map=null, :ref:`bool<class_bool>` antialiased=false **)**
  280. Draws a polygon of any amount of points, convex or concave.
  281. .. _class_CanvasItem_method_draw_polyline:
  282. - void **draw_polyline** **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`Color<class_Color>` color, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)**
  283. Draws interconnected line segments with a uniform ``color`` and ``width`` and optional antialiasing.
  284. .. _class_CanvasItem_method_draw_polyline_colors:
  285. - void **draw_polyline_colors** **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`PoolColorArray<class_PoolColorArray>` colors, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)**
  286. Draws interconnected line segments with a uniform ``width``, segment-by-segment coloring, and optional antialiasing. Colors assigned to line segments match by index between ``points`` and ``colors``.
  287. .. _class_CanvasItem_method_draw_primitive:
  288. - void **draw_primitive** **(** :ref:`PoolVector2Array<class_PoolVector2Array>` points, :ref:`PoolColorArray<class_PoolColorArray>` colors, :ref:`PoolVector2Array<class_PoolVector2Array>` uvs, :ref:`Texture<class_Texture>` texture=null, :ref:`float<class_float>` width=1.0, :ref:`Texture<class_Texture>` normal_map=null **)**
  289. 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.
  290. .. _class_CanvasItem_method_draw_rect:
  291. - void **draw_rect** **(** :ref:`Rect2<class_Rect2>` rect, :ref:`Color<class_Color>` color, :ref:`bool<class_bool>` filled=true, :ref:`float<class_float>` width=1.0, :ref:`bool<class_bool>` antialiased=false **)**
  292. Draws a rectangle. If ``filled`` is ``true``, the rectangle will be filled with the ``color`` specified. If ``filled`` is ``false``, the rectangle will be drawn as a stroke with the ``color`` and ``width`` specified. If ``antialiased`` is ``true``, the lines will be antialiased.
  293. **Note:** ``width`` and ``antialiased`` are only effective if ``filled`` is ``false``.
  294. .. _class_CanvasItem_method_draw_set_transform:
  295. - void **draw_set_transform** **(** :ref:`Vector2<class_Vector2>` position, :ref:`float<class_float>` rotation, :ref:`Vector2<class_Vector2>` scale **)**
  296. Sets a custom transform for drawing via components. Anything drawn afterwards will be transformed by this.
  297. .. _class_CanvasItem_method_draw_set_transform_matrix:
  298. - void **draw_set_transform_matrix** **(** :ref:`Transform2D<class_Transform2D>` xform **)**
  299. Sets a custom transform for drawing via matrix. Anything drawn afterwards will be transformed by this.
  300. .. _class_CanvasItem_method_draw_string:
  301. - void **draw_string** **(** :ref:`Font<class_Font>` font, :ref:`Vector2<class_Vector2>` position, :ref:`String<class_String>` text, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`int<class_int>` clip_w=-1 **)**
  302. Draws a string using a custom font.
  303. .. _class_CanvasItem_method_draw_style_box:
  304. - void **draw_style_box** **(** :ref:`StyleBox<class_StyleBox>` style_box, :ref:`Rect2<class_Rect2>` rect **)**
  305. Draws a styled rectangle.
  306. .. _class_CanvasItem_method_draw_texture:
  307. - void **draw_texture** **(** :ref:`Texture<class_Texture>` texture, :ref:`Vector2<class_Vector2>` position, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`Texture<class_Texture>` normal_map=null **)**
  308. Draws a texture at a given position.
  309. .. _class_CanvasItem_method_draw_texture_rect:
  310. - void **draw_texture_rect** **(** :ref:`Texture<class_Texture>` texture, :ref:`Rect2<class_Rect2>` rect, :ref:`bool<class_bool>` tile, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`bool<class_bool>` transpose=false, :ref:`Texture<class_Texture>` normal_map=null **)**
  311. 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.
  312. .. _class_CanvasItem_method_draw_texture_rect_region:
  313. - void **draw_texture_rect_region** **(** :ref:`Texture<class_Texture>` texture, :ref:`Rect2<class_Rect2>` rect, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`bool<class_bool>` transpose=false, :ref:`Texture<class_Texture>` normal_map=null, :ref:`bool<class_bool>` clip_uv=true **)**
  314. Draws a textured rectangle region at a given position, optionally modulated by a color. If ``transpose`` is ``true``, the texture will have its X and Y coordinates swapped.
  315. .. _class_CanvasItem_method_force_update_transform:
  316. - void **force_update_transform** **(** **)**
  317. .. _class_CanvasItem_method_get_canvas:
  318. - :ref:`RID<class_RID>` **get_canvas** **(** **)** const
  319. Returns the :ref:`RID<class_RID>` of the :ref:`World2D<class_World2D>` canvas where this item is in.
  320. .. _class_CanvasItem_method_get_canvas_item:
  321. - :ref:`RID<class_RID>` **get_canvas_item** **(** **)** const
  322. Returns the canvas item RID used by :ref:`VisualServer<class_VisualServer>` for this item.
  323. .. _class_CanvasItem_method_get_canvas_transform:
  324. - :ref:`Transform2D<class_Transform2D>` **get_canvas_transform** **(** **)** const
  325. Gets the transform matrix of this item's canvas.
  326. .. _class_CanvasItem_method_get_global_mouse_position:
  327. - :ref:`Vector2<class_Vector2>` **get_global_mouse_position** **(** **)** const
  328. Gets the global position of the mouse.
  329. .. _class_CanvasItem_method_get_global_transform:
  330. - :ref:`Transform2D<class_Transform2D>` **get_global_transform** **(** **)** const
  331. Gets the global transform matrix of this item.
  332. .. _class_CanvasItem_method_get_global_transform_with_canvas:
  333. - :ref:`Transform2D<class_Transform2D>` **get_global_transform_with_canvas** **(** **)** const
  334. Gets the global transform matrix of this item in relation to the canvas.
  335. .. _class_CanvasItem_method_get_local_mouse_position:
  336. - :ref:`Vector2<class_Vector2>` **get_local_mouse_position** **(** **)** const
  337. Gets the mouse position relative to this item's position.
  338. .. _class_CanvasItem_method_get_transform:
  339. - :ref:`Transform2D<class_Transform2D>` **get_transform** **(** **)** const
  340. Gets the transform matrix of this item.
  341. .. _class_CanvasItem_method_get_viewport_rect:
  342. - :ref:`Rect2<class_Rect2>` **get_viewport_rect** **(** **)** const
  343. Gets the viewport's boundaries as a :ref:`Rect2<class_Rect2>`.
  344. .. _class_CanvasItem_method_get_viewport_transform:
  345. - :ref:`Transform2D<class_Transform2D>` **get_viewport_transform** **(** **)** const
  346. Gets this item's transform in relation to the viewport.
  347. .. _class_CanvasItem_method_get_world_2d:
  348. - :ref:`World2D<class_World2D>` **get_world_2d** **(** **)** const
  349. Gets the :ref:`World2D<class_World2D>` where this item is in.
  350. .. _class_CanvasItem_method_hide:
  351. - void **hide** **(** **)**
  352. Hide the CanvasItem if it's currently visible.
  353. .. _class_CanvasItem_method_is_local_transform_notification_enabled:
  354. - :ref:`bool<class_bool>` **is_local_transform_notification_enabled** **(** **)** const
  355. Returns ``true`` if local transform notifications are communicated to children.
  356. .. _class_CanvasItem_method_is_set_as_toplevel:
  357. - :ref:`bool<class_bool>` **is_set_as_toplevel** **(** **)** const
  358. Returns ``true`` if the node is set as top-level. See :ref:`set_as_toplevel<class_CanvasItem_method_set_as_toplevel>`.
  359. .. _class_CanvasItem_method_is_transform_notification_enabled:
  360. - :ref:`bool<class_bool>` **is_transform_notification_enabled** **(** **)** const
  361. Returns ``true`` if global transform notifications are communicated to children.
  362. .. _class_CanvasItem_method_is_visible_in_tree:
  363. - :ref:`bool<class_bool>` **is_visible_in_tree** **(** **)** const
  364. Returns ``true`` if the node is present in the :ref:`SceneTree<class_SceneTree>`, its :ref:`visible<class_CanvasItem_property_visible>` property is ``true`` and its inherited visibility is also ``true``.
  365. .. _class_CanvasItem_method_make_canvas_position_local:
  366. - :ref:`Vector2<class_Vector2>` **make_canvas_position_local** **(** :ref:`Vector2<class_Vector2>` screen_point **)** const
  367. Assigns ``screen_point`` as this node's new local transform.
  368. .. _class_CanvasItem_method_make_input_local:
  369. - :ref:`InputEvent<class_InputEvent>` **make_input_local** **(** :ref:`InputEvent<class_InputEvent>` event **)** const
  370. Transformations issued by ``event``'s inputs are applied in local space instead of global space.
  371. .. _class_CanvasItem_method_set_as_toplevel:
  372. - void **set_as_toplevel** **(** :ref:`bool<class_bool>` enable **)**
  373. If ``enable`` is ``true``, the node won't inherit its transform from parent canvas items.
  374. .. _class_CanvasItem_method_set_notify_local_transform:
  375. - void **set_notify_local_transform** **(** :ref:`bool<class_bool>` enable **)**
  376. If ``enable`` is ``true``, children will be updated with local transform data.
  377. .. _class_CanvasItem_method_set_notify_transform:
  378. - void **set_notify_transform** **(** :ref:`bool<class_bool>` enable **)**
  379. If ``enable`` is ``true``, children will be updated with global transform data.
  380. .. _class_CanvasItem_method_show:
  381. - void **show** **(** **)**
  382. Show the CanvasItem if it's currently hidden. 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.
  383. .. _class_CanvasItem_method_update:
  384. - void **update** **(** **)**
  385. Queue the CanvasItem for update. :ref:`NOTIFICATION_DRAW<class_CanvasItem_constant_NOTIFICATION_DRAW>` will be called on idle time to request redraw.