texture_button.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**************************************************************************/
  2. /* texture_button.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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<Texture2D> normal;
  48. Ref<Texture2D> pressed;
  49. Ref<Texture2D> hover;
  50. Ref<Texture2D> disabled;
  51. Ref<Texture2D> focused;
  52. Ref<BitMap> click_mask;
  53. bool ignore_texture_size = false;
  54. StretchMode stretch_mode = STRETCH_KEEP;
  55. Rect2 _texture_region;
  56. Rect2 _position_rect;
  57. bool _tile = false;
  58. bool hflip = false;
  59. bool vflip = false;
  60. void _set_texture(Ref<Texture2D> *p_destination, const Ref<Texture2D> &p_texture);
  61. void _texture_changed();
  62. protected:
  63. virtual Size2 get_minimum_size() const override;
  64. virtual bool has_point(const Point2 &p_point) const override;
  65. void _notification(int p_what);
  66. static void _bind_methods();
  67. public:
  68. void set_texture_normal(const Ref<Texture2D> &p_normal);
  69. void set_texture_pressed(const Ref<Texture2D> &p_pressed);
  70. void set_texture_hover(const Ref<Texture2D> &p_hover);
  71. void set_texture_disabled(const Ref<Texture2D> &p_disabled);
  72. void set_texture_focused(const Ref<Texture2D> &p_focused);
  73. void set_click_mask(const Ref<BitMap> &p_click_mask);
  74. Ref<Texture2D> get_texture_normal() const;
  75. Ref<Texture2D> get_texture_pressed() const;
  76. Ref<Texture2D> get_texture_hover() const;
  77. Ref<Texture2D> get_texture_disabled() const;
  78. Ref<Texture2D> get_texture_focused() const;
  79. Ref<BitMap> get_click_mask() const;
  80. bool get_ignore_texture_size() const;
  81. void set_ignore_texture_size(bool p_ignore);
  82. void set_stretch_mode(StretchMode p_stretch_mode);
  83. StretchMode get_stretch_mode() const;
  84. void set_flip_h(bool p_flip);
  85. bool is_flipped_h() const;
  86. void set_flip_v(bool p_flip);
  87. bool is_flipped_v() const;
  88. TextureButton();
  89. };
  90. VARIANT_ENUM_CAST(TextureButton::StretchMode);
  91. #endif // TEXTURE_BUTTON_H