texture_progress_bar.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**************************************************************************/
  2. /* texture_progress_bar.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_PROGRESS_BAR_H
  31. #define TEXTURE_PROGRESS_BAR_H
  32. #include "scene/gui/range.h"
  33. class TextureProgressBar : public Range {
  34. GDCLASS(TextureProgressBar, Range);
  35. Ref<Texture2D> under;
  36. Ref<Texture2D> progress;
  37. Ref<Texture2D> over;
  38. protected:
  39. static void _bind_methods();
  40. void _notification(int p_what);
  41. public:
  42. enum FillMode {
  43. FILL_LEFT_TO_RIGHT = 0,
  44. FILL_RIGHT_TO_LEFT,
  45. FILL_TOP_TO_BOTTOM,
  46. FILL_BOTTOM_TO_TOP,
  47. FILL_CLOCKWISE,
  48. FILL_COUNTER_CLOCKWISE,
  49. FILL_BILINEAR_LEFT_AND_RIGHT,
  50. FILL_BILINEAR_TOP_AND_BOTTOM,
  51. FILL_CLOCKWISE_AND_COUNTER_CLOCKWISE,
  52. FILL_MODE_MAX,
  53. };
  54. void set_fill_mode(int p_fill);
  55. int get_fill_mode();
  56. void set_progress_offset(Point2 p_offset);
  57. Point2 get_progress_offset() const;
  58. void set_radial_initial_angle(float p_angle);
  59. float get_radial_initial_angle();
  60. void set_fill_degrees(float p_angle);
  61. float get_fill_degrees();
  62. void set_radial_center_offset(const Point2 &p_off);
  63. Point2 get_radial_center_offset();
  64. void set_under_texture(const Ref<Texture2D> &p_texture);
  65. Ref<Texture2D> get_under_texture() const;
  66. void set_progress_texture(const Ref<Texture2D> &p_texture);
  67. Ref<Texture2D> get_progress_texture() const;
  68. void set_over_texture(const Ref<Texture2D> &p_texture);
  69. Ref<Texture2D> get_over_texture() const;
  70. void set_stretch_margin(Side p_side, int p_size);
  71. int get_stretch_margin(Side p_side) const;
  72. void set_nine_patch_stretch(bool p_stretch);
  73. bool get_nine_patch_stretch() const;
  74. void set_tint_under(const Color &p_tint);
  75. Color get_tint_under() const;
  76. void set_tint_progress(const Color &p_tint);
  77. Color get_tint_progress() const;
  78. void set_tint_over(const Color &p_tint);
  79. Color get_tint_over() const;
  80. Size2 get_minimum_size() const override;
  81. TextureProgressBar();
  82. private:
  83. FillMode mode = FILL_LEFT_TO_RIGHT;
  84. Point2 progress_offset;
  85. float rad_init_angle = 0.0;
  86. float rad_max_degrees = 360.0;
  87. Point2 rad_center_off;
  88. bool nine_patch_stretch = false;
  89. int stretch_margin[4] = {};
  90. Color tint_under = Color(1, 1, 1);
  91. Color tint_progress = Color(1, 1, 1);
  92. Color tint_over = Color(1, 1, 1);
  93. void _set_texture(Ref<Texture2D> *p_destination, const Ref<Texture2D> &p_texture);
  94. void _texture_changed();
  95. Point2 unit_val_to_uv(float val);
  96. Point2 get_relative_center();
  97. void draw_nine_patch_stretched(const Ref<Texture2D> &p_texture, FillMode p_mode, double p_ratio, const Color &p_modulate);
  98. };
  99. VARIANT_ENUM_CAST(TextureProgressBar::FillMode);
  100. #endif // TEXTURE_PROGRESS_BAR_H