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