| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 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; |
| 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 |
}; |