texture_button.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*************************************************************************/
  2. /* texture_button.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef TEXTURE_BUTTON_H
  31. #define TEXTURE_BUTTON_H
  32. #include "scene/gui/base_button.h"
  33. #include "scene/resources/bit_map.h"
  34. class TextureButton : public BaseButton {
  35. GDCLASS(TextureButton, BaseButton);
  36. public:
  37. enum StretchMode {
  38. STRETCH_SCALE,
  39. STRETCH_TILE,
  40. STRETCH_KEEP,
  41. STRETCH_KEEP_CENTERED,
  42. STRETCH_KEEP_ASPECT,
  43. STRETCH_KEEP_ASPECT_CENTERED,
  44. STRETCH_KEEP_ASPECT_COVERED,
  45. };
  46. private:
  47. Ref<Texture> normal;
  48. Ref<Texture> pressed;
  49. Ref<Texture> hover;
  50. Ref<Texture> disabled;
  51. Ref<Texture> focused;
  52. Ref<BitMap> click_mask;
  53. bool expand;
  54. StretchMode stretch_mode;
  55. Rect2 _texture_region;
  56. Rect2 _position_rect;
  57. bool _tile;
  58. protected:
  59. virtual Size2 get_minimum_size() const;
  60. virtual bool has_point(const Point2 &p_point) const;
  61. void _notification(int p_what);
  62. static void _bind_methods();
  63. public:
  64. void set_normal_texture(const Ref<Texture> &p_normal);
  65. void set_pressed_texture(const Ref<Texture> &p_pressed);
  66. void set_hover_texture(const Ref<Texture> &p_hover);
  67. void set_disabled_texture(const Ref<Texture> &p_disabled);
  68. void set_focused_texture(const Ref<Texture> &p_focused);
  69. void set_click_mask(const Ref<BitMap> &p_click_mask);
  70. Ref<Texture> get_normal_texture() const;
  71. Ref<Texture> get_pressed_texture() const;
  72. Ref<Texture> get_hover_texture() const;
  73. Ref<Texture> get_disabled_texture() const;
  74. Ref<Texture> get_focused_texture() const;
  75. Ref<BitMap> get_click_mask() const;
  76. bool get_expand() const;
  77. void set_expand(bool p_expand);
  78. void set_stretch_mode(StretchMode p_stretch_mode);
  79. StretchMode get_stretch_mode() const;
  80. TextureButton();
  81. };
  82. VARIANT_ENUM_CAST(TextureButton::StretchMode);
  83. #endif // TEXTURE_BUTTON_H