texture_rect.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**************************************************************************/
  2. /* texture_rect.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_RECT_H
  31. #define TEXTURE_RECT_H
  32. #include "scene/gui/control.h"
  33. class TextureRect : public Control {
  34. GDCLASS(TextureRect, Control);
  35. public:
  36. enum ExpandMode {
  37. EXPAND_KEEP_SIZE,
  38. EXPAND_IGNORE_SIZE,
  39. EXPAND_FIT_WIDTH,
  40. EXPAND_FIT_WIDTH_PROPORTIONAL,
  41. EXPAND_FIT_HEIGHT,
  42. EXPAND_FIT_HEIGHT_PROPORTIONAL,
  43. };
  44. enum StretchMode {
  45. STRETCH_SCALE,
  46. STRETCH_TILE,
  47. STRETCH_KEEP,
  48. STRETCH_KEEP_CENTERED,
  49. STRETCH_KEEP_ASPECT,
  50. STRETCH_KEEP_ASPECT_CENTERED,
  51. STRETCH_KEEP_ASPECT_COVERED,
  52. };
  53. private:
  54. bool hflip = false;
  55. bool vflip = false;
  56. Ref<Texture2D> texture;
  57. ExpandMode expand_mode = EXPAND_KEEP_SIZE;
  58. StretchMode stretch_mode = STRETCH_SCALE;
  59. void _texture_changed();
  60. protected:
  61. void _notification(int p_what);
  62. virtual Size2 get_minimum_size() const override;
  63. static void _bind_methods();
  64. #ifndef DISABLE_DEPRECATED
  65. bool _set(const StringName &p_name, const Variant &p_value);
  66. #endif
  67. public:
  68. void set_texture(const Ref<Texture2D> &p_tex);
  69. Ref<Texture2D> get_texture() const;
  70. void set_expand_mode(ExpandMode p_mode);
  71. ExpandMode get_expand_mode() const;
  72. void set_stretch_mode(StretchMode p_mode);
  73. StretchMode get_stretch_mode() const;
  74. void set_flip_h(bool p_flip);
  75. bool is_flipped_h() const;
  76. void set_flip_v(bool p_flip);
  77. bool is_flipped_v() const;
  78. TextureRect();
  79. ~TextureRect();
  80. };
  81. VARIANT_ENUM_CAST(TextureRect::ExpandMode);
  82. VARIANT_ENUM_CAST(TextureRect::StretchMode);
  83. #endif // TEXTURE_RECT_H