1 | /**************************************************************************/ |
2 | /* editor_spin_slider.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 EDITOR_SPIN_SLIDER_H |
32 | #define EDITOR_SPIN_SLIDER_H |
33 | |
34 | #include "scene/gui/line_edit.h" |
35 | #include "scene/gui/range.h" |
36 | #include "scene/gui/texture_rect.h" |
37 | |
38 | class EditorSpinSlider : public Range { |
39 | GDCLASS(EditorSpinSlider, Range); |
40 | |
41 | String label; |
42 | String suffix; |
43 | int updown_offset = -1; |
44 | bool hover_updown = false; |
45 | bool mouse_hover = false; |
46 | |
47 | TextureRect *grabber = nullptr; |
48 | int grabber_range = 1; |
49 | |
50 | bool mouse_over_spin = false; |
51 | bool mouse_over_grabber = false; |
52 | bool mousewheel_over_grabber = false; |
53 | |
54 | bool grabbing_grabber = false; |
55 | int grabbing_from = 0; |
56 | float grabbing_ratio = 0.0f; |
57 | |
58 | bool grabbing_spinner_attempt = false; |
59 | bool grabbing_spinner = false; |
60 | |
61 | bool read_only = false; |
62 | float grabbing_spinner_dist_cache = 0.0f; |
63 | float grabbing_spinner_speed = 0.0f; |
64 | Vector2 grabbing_spinner_mouse_pos; |
65 | double pre_grab_value = 0.0; |
66 | |
67 | Control * = nullptr; |
68 | LineEdit *value_input = nullptr; |
69 | uint64_t value_input_closed_frame = 0; |
70 | bool value_input_dirty = false; |
71 | |
72 | bool hide_slider = false; |
73 | bool flat = false; |
74 | |
75 | void _grabber_gui_input(const Ref<InputEvent> &p_event); |
76 | void _value_input_closed(); |
77 | void _value_input_submitted(const String &); |
78 | void _value_focus_exited(); |
79 | void _value_input_gui_input(const Ref<InputEvent> &p_event); |
80 | |
81 | void _evaluate_input_text(); |
82 | |
83 | void _update_value_input_stylebox(); |
84 | void (); |
85 | void _draw_spin_slider(); |
86 | |
87 | protected: |
88 | void _notification(int p_what); |
89 | virtual void gui_input(const Ref<InputEvent> &p_event) override; |
90 | static void _bind_methods(); |
91 | void _grabber_mouse_entered(); |
92 | void _grabber_mouse_exited(); |
93 | void _focus_entered(); |
94 | |
95 | public: |
96 | String get_tooltip(const Point2 &p_pos) const override; |
97 | |
98 | String get_text_value() const; |
99 | void set_label(const String &p_label); |
100 | String get_label() const; |
101 | |
102 | void set_suffix(const String &p_suffix); |
103 | String get_suffix() const; |
104 | |
105 | void set_hide_slider(bool p_hide); |
106 | bool is_hiding_slider() const; |
107 | |
108 | void set_read_only(bool p_enable); |
109 | bool is_read_only() const; |
110 | |
111 | void set_flat(bool p_enable); |
112 | bool is_flat() const; |
113 | |
114 | bool is_grabbing() const; |
115 | |
116 | void setup_and_show() { _focus_entered(); } |
117 | LineEdit *get_line_edit(); |
118 | |
119 | virtual Size2 get_minimum_size() const override; |
120 | EditorSpinSlider(); |
121 | }; |
122 | |
123 | #endif // EDITOR_SPIN_SLIDER_H |
124 | |