class_texturebutton.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the TextureButton.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_TextureButton:
  6. TextureButton
  7. =============
  8. **Inherits:** :ref:`BaseButton<class_BaseButton>` **<** :ref:`Control<class_Control>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  9. Texture-based button. Supports Pressed, Hover, Disabled and Focused states.
  10. Description
  11. -----------
  12. ``TextureButton`` has the same functionality as :ref:`Button<class_Button>`, except it uses sprites instead of Godot's :ref:`Theme<class_Theme>` resource. It is faster to create, but it doesn't support localization like more complex :ref:`Control<class_Control>`\ s.
  13. The "normal" state must contain a texture (:ref:`texture_normal<class_TextureButton_property_texture_normal>`); other textures are optional.
  14. See also :ref:`BaseButton<class_BaseButton>` which contains common properties and methods associated with this node.
  15. Tutorials
  16. ---------
  17. - `3D Voxel Demo <https://godotengine.org/asset-library/asset/676>`__
  18. Properties
  19. ----------
  20. +----------------------------------------------------+----------------------------------------------------------------------------+-----------+
  21. | :ref:`bool<class_bool>` | :ref:`expand<class_TextureButton_property_expand>` | ``false`` |
  22. +----------------------------------------------------+----------------------------------------------------------------------------+-----------+
  23. | :ref:`bool<class_bool>` | :ref:`flip_h<class_TextureButton_property_flip_h>` | ``false`` |
  24. +----------------------------------------------------+----------------------------------------------------------------------------+-----------+
  25. | :ref:`bool<class_bool>` | :ref:`flip_v<class_TextureButton_property_flip_v>` | ``false`` |
  26. +----------------------------------------------------+----------------------------------------------------------------------------+-----------+
  27. | :ref:`StretchMode<enum_TextureButton_StretchMode>` | :ref:`stretch_mode<class_TextureButton_property_stretch_mode>` | ``0`` |
  28. +----------------------------------------------------+----------------------------------------------------------------------------+-----------+
  29. | :ref:`BitMap<class_BitMap>` | :ref:`texture_click_mask<class_TextureButton_property_texture_click_mask>` | |
  30. +----------------------------------------------------+----------------------------------------------------------------------------+-----------+
  31. | :ref:`Texture<class_Texture>` | :ref:`texture_disabled<class_TextureButton_property_texture_disabled>` | |
  32. +----------------------------------------------------+----------------------------------------------------------------------------+-----------+
  33. | :ref:`Texture<class_Texture>` | :ref:`texture_focused<class_TextureButton_property_texture_focused>` | |
  34. +----------------------------------------------------+----------------------------------------------------------------------------+-----------+
  35. | :ref:`Texture<class_Texture>` | :ref:`texture_hover<class_TextureButton_property_texture_hover>` | |
  36. +----------------------------------------------------+----------------------------------------------------------------------------+-----------+
  37. | :ref:`Texture<class_Texture>` | :ref:`texture_normal<class_TextureButton_property_texture_normal>` | |
  38. +----------------------------------------------------+----------------------------------------------------------------------------+-----------+
  39. | :ref:`Texture<class_Texture>` | :ref:`texture_pressed<class_TextureButton_property_texture_pressed>` | |
  40. +----------------------------------------------------+----------------------------------------------------------------------------+-----------+
  41. Enumerations
  42. ------------
  43. .. _enum_TextureButton_StretchMode:
  44. .. _class_TextureButton_constant_STRETCH_SCALE:
  45. .. _class_TextureButton_constant_STRETCH_TILE:
  46. .. _class_TextureButton_constant_STRETCH_KEEP:
  47. .. _class_TextureButton_constant_STRETCH_KEEP_CENTERED:
  48. .. _class_TextureButton_constant_STRETCH_KEEP_ASPECT:
  49. .. _class_TextureButton_constant_STRETCH_KEEP_ASPECT_CENTERED:
  50. .. _class_TextureButton_constant_STRETCH_KEEP_ASPECT_COVERED:
  51. enum **StretchMode**:
  52. - **STRETCH_SCALE** = **0** --- Scale to fit the node's bounding rectangle.
  53. - **STRETCH_TILE** = **1** --- Tile inside the node's bounding rectangle.
  54. - **STRETCH_KEEP** = **2** --- The texture keeps its original size and stays in the bounding rectangle's top-left corner.
  55. - **STRETCH_KEEP_CENTERED** = **3** --- The texture keeps its original size and stays centered in the node's bounding rectangle.
  56. - **STRETCH_KEEP_ASPECT** = **4** --- Scale the texture to fit the node's bounding rectangle, but maintain the texture's aspect ratio.
  57. - **STRETCH_KEEP_ASPECT_CENTERED** = **5** --- Scale the texture to fit the node's bounding rectangle, center it, and maintain its aspect ratio.
  58. - **STRETCH_KEEP_ASPECT_COVERED** = **6** --- Scale the texture so that the shorter side fits the bounding rectangle. The other side clips to the node's limits.
  59. Property Descriptions
  60. ---------------------
  61. .. _class_TextureButton_property_expand:
  62. - :ref:`bool<class_bool>` **expand**
  63. +-----------+-------------------+
  64. | *Default* | ``false`` |
  65. +-----------+-------------------+
  66. | *Setter* | set_expand(value) |
  67. +-----------+-------------------+
  68. | *Getter* | get_expand() |
  69. +-----------+-------------------+
  70. If ``true``, the texture stretches to the edges of the node's bounding rectangle using the :ref:`stretch_mode<class_TextureButton_property_stretch_mode>`. If ``false``, the texture will not scale with the node.
  71. ----
  72. .. _class_TextureButton_property_flip_h:
  73. - :ref:`bool<class_bool>` **flip_h**
  74. +-----------+-------------------+
  75. | *Default* | ``false`` |
  76. +-----------+-------------------+
  77. | *Setter* | set_flip_h(value) |
  78. +-----------+-------------------+
  79. | *Getter* | is_flipped_h() |
  80. +-----------+-------------------+
  81. If ``true``, texture is flipped horizontally.
  82. ----
  83. .. _class_TextureButton_property_flip_v:
  84. - :ref:`bool<class_bool>` **flip_v**
  85. +-----------+-------------------+
  86. | *Default* | ``false`` |
  87. +-----------+-------------------+
  88. | *Setter* | set_flip_v(value) |
  89. +-----------+-------------------+
  90. | *Getter* | is_flipped_v() |
  91. +-----------+-------------------+
  92. If ``true``, texture is flipped vertically.
  93. ----
  94. .. _class_TextureButton_property_stretch_mode:
  95. - :ref:`StretchMode<enum_TextureButton_StretchMode>` **stretch_mode**
  96. +-----------+-------------------------+
  97. | *Default* | ``0`` |
  98. +-----------+-------------------------+
  99. | *Setter* | set_stretch_mode(value) |
  100. +-----------+-------------------------+
  101. | *Getter* | get_stretch_mode() |
  102. +-----------+-------------------------+
  103. Controls the texture's behavior when you resize the node's bounding rectangle, **only if** :ref:`expand<class_TextureButton_property_expand>` is ``true``. Set it to one of the :ref:`StretchMode<enum_TextureButton_StretchMode>` constants. See the constants to learn more.
  104. ----
  105. .. _class_TextureButton_property_texture_click_mask:
  106. - :ref:`BitMap<class_BitMap>` **texture_click_mask**
  107. +----------+-----------------------+
  108. | *Setter* | set_click_mask(value) |
  109. +----------+-----------------------+
  110. | *Getter* | get_click_mask() |
  111. +----------+-----------------------+
  112. Pure black and white :ref:`BitMap<class_BitMap>` image to use for click detection. On the mask, white pixels represent the button's clickable area. Use it to create buttons with curved shapes.
  113. ----
  114. .. _class_TextureButton_property_texture_disabled:
  115. - :ref:`Texture<class_Texture>` **texture_disabled**
  116. +----------+-----------------------------+
  117. | *Setter* | set_disabled_texture(value) |
  118. +----------+-----------------------------+
  119. | *Getter* | get_disabled_texture() |
  120. +----------+-----------------------------+
  121. Texture to display when the node is disabled. See :ref:`BaseButton.disabled<class_BaseButton_property_disabled>`.
  122. ----
  123. .. _class_TextureButton_property_texture_focused:
  124. - :ref:`Texture<class_Texture>` **texture_focused**
  125. +----------+----------------------------+
  126. | *Setter* | set_focused_texture(value) |
  127. +----------+----------------------------+
  128. | *Getter* | get_focused_texture() |
  129. +----------+----------------------------+
  130. Texture to display when the node has mouse or keyboard focus.
  131. ----
  132. .. _class_TextureButton_property_texture_hover:
  133. - :ref:`Texture<class_Texture>` **texture_hover**
  134. +----------+--------------------------+
  135. | *Setter* | set_hover_texture(value) |
  136. +----------+--------------------------+
  137. | *Getter* | get_hover_texture() |
  138. +----------+--------------------------+
  139. Texture to display when the mouse hovers the node.
  140. ----
  141. .. _class_TextureButton_property_texture_normal:
  142. - :ref:`Texture<class_Texture>` **texture_normal**
  143. +----------+---------------------------+
  144. | *Setter* | set_normal_texture(value) |
  145. +----------+---------------------------+
  146. | *Getter* | get_normal_texture() |
  147. +----------+---------------------------+
  148. Texture to display by default, when the node is **not** in the disabled, focused, hover or pressed state.
  149. ----
  150. .. _class_TextureButton_property_texture_pressed:
  151. - :ref:`Texture<class_Texture>` **texture_pressed**
  152. +----------+----------------------------+
  153. | *Setter* | set_pressed_texture(value) |
  154. +----------+----------------------------+
  155. | *Getter* | get_pressed_texture() |
  156. +----------+----------------------------+
  157. Texture to display on mouse down over the node, if the node has keyboard focus and the player presses the Enter key or if the player presses the :ref:`BaseButton.shortcut<class_BaseButton_property_shortcut>` key.
  158. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  159. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  160. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`