texture_button.h 4.1 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) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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_mask.h"
  34. class TextureButton : public BaseButton {
  35. OBJ_TYPE(TextureButton, BaseButton);
  36. public:
  37. enum ResizeMode {
  38. RESIZE_SCALE, // for backwards compatibility
  39. RESIZE_STRETCH,
  40. };
  41. enum StretchMode {
  42. STRETCH_SCALE_ON_EXPAND, //default, for backwards compatibility
  43. STRETCH_SCALE,
  44. STRETCH_TILE,
  45. STRETCH_KEEP,
  46. STRETCH_KEEP_CENTERED,
  47. STRETCH_KEEP_ASPECT,
  48. STRETCH_KEEP_ASPECT_CENTERED,
  49. STRETCH_KEEP_ASPECT_COVERED,
  50. };
  51. private:
  52. Ref<Texture> normal;
  53. Ref<Texture> pressed;
  54. Ref<Texture> hover;
  55. Ref<Texture> disabled;
  56. Ref<Texture> focused;
  57. Ref<BitMap> click_mask;
  58. Color modulate;
  59. ResizeMode resize_mode;
  60. Size2 scale;
  61. StretchMode stretch_mode;
  62. protected:
  63. virtual bool has_point(const Point2 &p_point) const;
  64. virtual Size2 get_minimum_size() const;
  65. void _notification(int p_what);
  66. static void _bind_methods();
  67. public:
  68. void set_normal_texture(const Ref<Texture> &p_normal);
  69. void set_pressed_texture(const Ref<Texture> &p_pressed);
  70. void set_hover_texture(const Ref<Texture> &p_hover);
  71. void set_disabled_texture(const Ref<Texture> &p_disabled);
  72. void set_focused_texture(const Ref<Texture> &p_focused);
  73. void set_click_mask(const Ref<BitMap> &p_image);
  74. Ref<Texture> get_normal_texture() const;
  75. Ref<Texture> get_pressed_texture() const;
  76. Ref<Texture> get_hover_texture() const;
  77. Ref<Texture> get_disabled_texture() const;
  78. Ref<Texture> get_focused_texture() const;
  79. Ref<BitMap> get_click_mask() const;
  80. void set_modulate(const Color &p_modulate);
  81. Color get_modulate() const;
  82. ResizeMode get_resize_mode() const;
  83. void set_resize_mode(ResizeMode p_mode);
  84. void set_texture_scale(Size2 p_scale);
  85. Size2 get_texture_scale() const;
  86. void set_stretch_mode(StretchMode stretch_mode);
  87. StretchMode get_stretch_mode() const;
  88. TextureButton();
  89. };
  90. VARIANT_ENUM_CAST(TextureButton::ResizeMode);
  91. VARIANT_ENUM_CAST(TextureButton::StretchMode);
  92. #endif // TEXTURE_BUTTON_H