1 | /**************************************************************************/ |
2 | /* 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 SLIDER_H |
32 | #define SLIDER_H |
33 | |
34 | #include "scene/gui/range.h" |
35 | |
36 | class Slider : public Range { |
37 | GDCLASS(Slider, Range); |
38 | |
39 | struct Grab { |
40 | int pos = 0; |
41 | double uvalue = 0.0; |
42 | bool active = false; |
43 | } grab; |
44 | |
45 | int ticks = 0; |
46 | bool mouse_inside = false; |
47 | Orientation orientation; |
48 | double custom_step = -1.0; |
49 | bool editable = true; |
50 | bool scrollable = true; |
51 | |
52 | const float DEFAULT_GAMEPAD_EVENT_DELAY_MS = 0.5; |
53 | const float GAMEPAD_EVENT_REPEAT_RATE_MS = 1.0 / 20; |
54 | float gamepad_event_delay_ms = DEFAULT_GAMEPAD_EVENT_DELAY_MS; |
55 | |
56 | struct ThemeCache { |
57 | Ref<StyleBox> slider_style; |
58 | Ref<StyleBox> grabber_area_style; |
59 | Ref<StyleBox> grabber_area_hl_style; |
60 | |
61 | Ref<Texture2D> grabber_icon; |
62 | Ref<Texture2D> grabber_hl_icon; |
63 | Ref<Texture2D> grabber_disabled_icon; |
64 | Ref<Texture2D> tick_icon; |
65 | |
66 | bool center_grabber = false; |
67 | int grabber_offset = 0; |
68 | } theme_cache; |
69 | |
70 | protected: |
71 | bool ticks_on_borders = false; |
72 | |
73 | virtual void gui_input(const Ref<InputEvent> &p_event) override; |
74 | void _notification(int p_what); |
75 | static void _bind_methods(); |
76 | |
77 | public: |
78 | virtual Size2 get_minimum_size() const override; |
79 | |
80 | void set_custom_step(double p_custom_step); |
81 | double get_custom_step() const; |
82 | |
83 | void set_ticks(int p_count); |
84 | int get_ticks() const; |
85 | |
86 | void set_ticks_on_borders(bool); |
87 | bool get_ticks_on_borders() const; |
88 | |
89 | void set_editable(bool p_editable); |
90 | bool is_editable() const; |
91 | |
92 | void set_scrollable(bool p_scrollable); |
93 | bool is_scrollable() const; |
94 | |
95 | Slider(Orientation p_orientation = VERTICAL); |
96 | }; |
97 | |
98 | class HSlider : public Slider { |
99 | GDCLASS(HSlider, Slider); |
100 | |
101 | public: |
102 | HSlider() : |
103 | Slider(HORIZONTAL) { set_v_size_flags(0); } |
104 | }; |
105 | |
106 | class VSlider : public Slider { |
107 | GDCLASS(VSlider, Slider); |
108 | |
109 | public: |
110 | VSlider() : |
111 | Slider(VERTICAL) { set_h_size_flags(0); } |
112 | }; |
113 | |
114 | #endif // SLIDER_H |
115 | |