Debian Codegraph @

scene/gui/slider.h

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