style_box_texture.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**************************************************************************/
  2. /* style_box_texture.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 STYLE_BOX_TEXTURE_H
  31. #define STYLE_BOX_TEXTURE_H
  32. #include "scene/resources/style_box.h"
  33. #include "scene/resources/texture.h"
  34. class StyleBoxTexture : public StyleBox {
  35. GDCLASS(StyleBoxTexture, StyleBox);
  36. public:
  37. enum AxisStretchMode {
  38. AXIS_STRETCH_MODE_STRETCH,
  39. AXIS_STRETCH_MODE_TILE,
  40. AXIS_STRETCH_MODE_TILE_FIT,
  41. };
  42. private:
  43. float expand_margin[4] = {};
  44. float texture_margin[4] = {};
  45. Rect2 region_rect;
  46. Ref<Texture2D> texture;
  47. bool draw_center = true;
  48. Color modulate = Color(1, 1, 1, 1);
  49. AxisStretchMode axis_h = AXIS_STRETCH_MODE_STRETCH;
  50. AxisStretchMode axis_v = AXIS_STRETCH_MODE_STRETCH;
  51. protected:
  52. virtual float get_style_margin(Side p_side) const override;
  53. static void _bind_methods();
  54. public:
  55. void set_texture(Ref<Texture2D> p_texture);
  56. Ref<Texture2D> get_texture() const;
  57. void set_texture_margin(Side p_side, float p_size);
  58. void set_texture_margin_all(float p_size);
  59. void set_texture_margin_individual(float p_left, float p_top, float p_right, float p_bottom);
  60. float get_texture_margin(Side p_side) const;
  61. void set_expand_margin(Side p_expand_side, float p_size);
  62. void set_expand_margin_all(float p_expand_margin_size);
  63. void set_expand_margin_individual(float p_left, float p_top, float p_right, float p_bottom);
  64. float get_expand_margin(Side p_expand_side) const;
  65. void set_region_rect(const Rect2 &p_region_rect);
  66. Rect2 get_region_rect() const;
  67. void set_draw_center(bool p_enabled);
  68. bool is_draw_center_enabled() const;
  69. void set_h_axis_stretch_mode(AxisStretchMode p_mode);
  70. AxisStretchMode get_h_axis_stretch_mode() const;
  71. void set_v_axis_stretch_mode(AxisStretchMode p_mode);
  72. AxisStretchMode get_v_axis_stretch_mode() const;
  73. void set_modulate(const Color &p_modulate);
  74. Color get_modulate() const;
  75. virtual Rect2 get_draw_rect(const Rect2 &p_rect) const override;
  76. virtual void draw(RID p_canvas_item, const Rect2 &p_rect) const override;
  77. StyleBoxTexture();
  78. ~StyleBoxTexture();
  79. };
  80. VARIANT_ENUM_CAST(StyleBoxTexture::AxisStretchMode)
  81. #endif // STYLE_BOX_TEXTURE_H