| 1 | /**************************************************************************/ |
| 2 | /* range.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 RANGE_H |
| 32 | #define RANGE_H |
| 33 | |
| 34 | #include "scene/gui/control.h" |
| 35 | |
| 36 | class Range : public Control { |
| 37 | GDCLASS(Range, Control); |
| 38 | |
| 39 | struct Shared { |
| 40 | double val = 0.0; |
| 41 | double min = 0.0; |
| 42 | double max = 100.0; |
| 43 | double step = 1.0; |
| 44 | double page = 0.0; |
| 45 | bool exp_ratio = false; |
| 46 | bool allow_greater = false; |
| 47 | bool allow_lesser = false; |
| 48 | HashSet<Range *> owners; |
| 49 | void emit_value_changed(); |
| 50 | void emit_changed(const char *p_what = "" ); |
| 51 | void redraw_owners(); |
| 52 | }; |
| 53 | |
| 54 | Shared *shared = nullptr; |
| 55 | |
| 56 | void _ref_shared(Shared *p_shared); |
| 57 | void _unref_shared(); |
| 58 | |
| 59 | void _share(Node *p_range); |
| 60 | |
| 61 | void _value_changed_notify(); |
| 62 | void _changed_notify(const char *p_what = "" ); |
| 63 | void _set_value_no_signal(double p_val); |
| 64 | |
| 65 | protected: |
| 66 | virtual void _value_changed(double p_value); |
| 67 | |
| 68 | static void _bind_methods(); |
| 69 | |
| 70 | bool _rounded_values = false; |
| 71 | |
| 72 | GDVIRTUAL1(_value_changed, double) |
| 73 | |
| 74 | public: |
| 75 | void set_value(double p_val); |
| 76 | void set_value_no_signal(double p_val); |
| 77 | void set_min(double p_min); |
| 78 | void set_max(double p_max); |
| 79 | void set_step(double p_step); |
| 80 | void set_page(double p_page); |
| 81 | void set_as_ratio(double p_value); |
| 82 | |
| 83 | double get_value() const; |
| 84 | double get_min() const; |
| 85 | double get_max() const; |
| 86 | double get_step() const; |
| 87 | double get_page() const; |
| 88 | double get_as_ratio() const; |
| 89 | |
| 90 | void set_use_rounded_values(bool p_enable); |
| 91 | bool is_using_rounded_values() const; |
| 92 | |
| 93 | void set_exp_ratio(bool p_enable); |
| 94 | bool is_ratio_exp() const; |
| 95 | |
| 96 | void set_allow_greater(bool p_allow); |
| 97 | bool is_greater_allowed() const; |
| 98 | |
| 99 | void set_allow_lesser(bool p_allow); |
| 100 | bool is_lesser_allowed() const; |
| 101 | |
| 102 | void share(Range *p_range); |
| 103 | void unshare(); |
| 104 | |
| 105 | PackedStringArray get_configuration_warnings() const override; |
| 106 | |
| 107 | Range(); |
| 108 | ~Range(); |
| 109 | }; |
| 110 | |
| 111 | #endif // RANGE_H |
| 112 | |