class_texturebutton.rst 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.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:`StretchMode<enum_TextureButton_StretchMode>` | :ref:`stretch_mode<class_TextureButton_property_stretch_mode>` | ``0`` |
  24. +----------------------------------------------------+----------------------------------------------------------------------------+-----------+
  25. | :ref:`BitMap<class_BitMap>` | :ref:`texture_click_mask<class_TextureButton_property_texture_click_mask>` | |
  26. +----------------------------------------------------+----------------------------------------------------------------------------+-----------+
  27. | :ref:`Texture<class_Texture>` | :ref:`texture_disabled<class_TextureButton_property_texture_disabled>` | |
  28. +----------------------------------------------------+----------------------------------------------------------------------------+-----------+
  29. | :ref:`Texture<class_Texture>` | :ref:`texture_focused<class_TextureButton_property_texture_focused>` | |
  30. +----------------------------------------------------+----------------------------------------------------------------------------+-----------+
  31. | :ref:`Texture<class_Texture>` | :ref:`texture_hover<class_TextureButton_property_texture_hover>` | |
  32. +----------------------------------------------------+----------------------------------------------------------------------------+-----------+
  33. | :ref:`Texture<class_Texture>` | :ref:`texture_normal<class_TextureButton_property_texture_normal>` | |
  34. +----------------------------------------------------+----------------------------------------------------------------------------+-----------+
  35. | :ref:`Texture<class_Texture>` | :ref:`texture_pressed<class_TextureButton_property_texture_pressed>` | |
  36. +----------------------------------------------------+----------------------------------------------------------------------------+-----------+
  37. Enumerations
  38. ------------
  39. .. _enum_TextureButton_StretchMode:
  40. .. _class_TextureButton_constant_STRETCH_SCALE:
  41. .. _class_TextureButton_constant_STRETCH_TILE:
  42. .. _class_TextureButton_constant_STRETCH_KEEP:
  43. .. _class_TextureButton_constant_STRETCH_KEEP_CENTERED:
  44. .. _class_TextureButton_constant_STRETCH_KEEP_ASPECT:
  45. .. _class_TextureButton_constant_STRETCH_KEEP_ASPECT_CENTERED:
  46. .. _class_TextureButton_constant_STRETCH_KEEP_ASPECT_COVERED:
  47. enum **StretchMode**:
  48. - **STRETCH_SCALE** = **0** --- Scale to fit the node's bounding rectangle.
  49. - **STRETCH_TILE** = **1** --- Tile inside the node's bounding rectangle.
  50. - **STRETCH_KEEP** = **2** --- The texture keeps its original size and stays in the bounding rectangle's top-left corner.
  51. - **STRETCH_KEEP_CENTERED** = **3** --- The texture keeps its original size and stays centered in the node's bounding rectangle.
  52. - **STRETCH_KEEP_ASPECT** = **4** --- Scale the texture to fit the node's bounding rectangle, but maintain the texture's aspect ratio.
  53. - **STRETCH_KEEP_ASPECT_CENTERED** = **5** --- Scale the texture to fit the node's bounding rectangle, center it, and maintain its aspect ratio.
  54. - **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.
  55. Property Descriptions
  56. ---------------------
  57. .. _class_TextureButton_property_expand:
  58. - :ref:`bool<class_bool>` **expand**
  59. +-----------+-------------------+
  60. | *Default* | ``false`` |
  61. +-----------+-------------------+
  62. | *Setter* | set_expand(value) |
  63. +-----------+-------------------+
  64. | *Getter* | get_expand() |
  65. +-----------+-------------------+
  66. 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.
  67. ----
  68. .. _class_TextureButton_property_stretch_mode:
  69. - :ref:`StretchMode<enum_TextureButton_StretchMode>` **stretch_mode**
  70. +-----------+-------------------------+
  71. | *Default* | ``0`` |
  72. +-----------+-------------------------+
  73. | *Setter* | set_stretch_mode(value) |
  74. +-----------+-------------------------+
  75. | *Getter* | get_stretch_mode() |
  76. +-----------+-------------------------+
  77. 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.
  78. ----
  79. .. _class_TextureButton_property_texture_click_mask:
  80. - :ref:`BitMap<class_BitMap>` **texture_click_mask**
  81. +----------+-----------------------+
  82. | *Setter* | set_click_mask(value) |
  83. +----------+-----------------------+
  84. | *Getter* | get_click_mask() |
  85. +----------+-----------------------+
  86. 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.
  87. ----
  88. .. _class_TextureButton_property_texture_disabled:
  89. - :ref:`Texture<class_Texture>` **texture_disabled**
  90. +----------+-----------------------------+
  91. | *Setter* | set_disabled_texture(value) |
  92. +----------+-----------------------------+
  93. | *Getter* | get_disabled_texture() |
  94. +----------+-----------------------------+
  95. Texture to display when the node is disabled. See :ref:`BaseButton.disabled<class_BaseButton_property_disabled>`.
  96. ----
  97. .. _class_TextureButton_property_texture_focused:
  98. - :ref:`Texture<class_Texture>` **texture_focused**
  99. +----------+----------------------------+
  100. | *Setter* | set_focused_texture(value) |
  101. +----------+----------------------------+
  102. | *Getter* | get_focused_texture() |
  103. +----------+----------------------------+
  104. Texture to display when the node has mouse or keyboard focus.
  105. ----
  106. .. _class_TextureButton_property_texture_hover:
  107. - :ref:`Texture<class_Texture>` **texture_hover**
  108. +----------+--------------------------+
  109. | *Setter* | set_hover_texture(value) |
  110. +----------+--------------------------+
  111. | *Getter* | get_hover_texture() |
  112. +----------+--------------------------+
  113. Texture to display when the mouse hovers the node.
  114. ----
  115. .. _class_TextureButton_property_texture_normal:
  116. - :ref:`Texture<class_Texture>` **texture_normal**
  117. +----------+---------------------------+
  118. | *Setter* | set_normal_texture(value) |
  119. +----------+---------------------------+
  120. | *Getter* | get_normal_texture() |
  121. +----------+---------------------------+
  122. Texture to display by default, when the node is **not** in the disabled, focused, hover or pressed state.
  123. ----
  124. .. _class_TextureButton_property_texture_pressed:
  125. - :ref:`Texture<class_Texture>` **texture_pressed**
  126. +----------+----------------------------+
  127. | *Setter* | set_pressed_texture(value) |
  128. +----------+----------------------------+
  129. | *Getter* | get_pressed_texture() |
  130. +----------+----------------------------+
  131. 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.
  132. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  133. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  134. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`