| 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/line_edit.h" |
| 34 |
#include "scene/gui/range.h" |
| 35 |
#include "scene/gui/texture_rect.h" |
| 36 |
|
| 37 |
class EditorSpinSlider : public Range { |
| 38 |
GDCLASS(EditorSpinSlider, Range); |
| 39 |
|
| 40 |
String label; |
| 41 |
String suffix; |
| 42 |
int updown_offset = -1; |
| 43 |
bool hover_updown = false; |
| 44 |
|
| 45 |
TextureRect *grabber = nullptr; |
| 46 |
int grabber_range = 1; |
| 47 |
|
| 48 |
bool mouse_over_spin = false; |
| 49 |
bool mouse_over_grabber = false; |
| 50 |
bool mousewheel_over_grabber = false; |
| 51 |
|
| 52 |
bool grabbing_grabber = false; |
| 53 |
int grabbing_from = 0; |
| 54 |
float grabbing_ratio = 0.0f; |
| 55 |
|
| 56 |
bool grabbing_spinner_attempt = false; |
| 57 |
bool grabbing_spinner = false; |
| 58 |
|
| 59 |
bool read_only = false; |
| 60 |
float grabbing_spinner_dist_cache = 0.0f; |
| 61 |
float grabbing_spinner_speed = 0.0f; |
| 62 |
Vector2 grabbing_spinner_mouse_pos; |
| 63 |
double pre_grab_value = 0.0; |
| 64 |
|
| 65 |
LineEdit *value_input = nullptr; |
| 66 |
uint64_t value_input_closed_frame = 0; |
| 67 |
bool value_input_dirty = false; |
| 68 |
bool value_input_focus_visible = false; |
| 69 |
|
| 70 |
public: |
| 71 |
enum ControlState { |
| 72 |
CONTROL_STATE_DEFAULT, |
| 73 |
CONTROL_STATE_PREFER_SLIDER, |
| 74 |
CONTROL_STATE_HIDE, |
| 75 |
}; |
| 76 |
|
| 77 |
private: |
| 78 |
ControlState control_state = CONTROL_STATE_DEFAULT; |
| 79 |
bool flat = false; |
| 80 |
bool editing_integer = false; |
| 81 |
|
| 82 |
void _grab_start(); |
| 83 |
void _grab_end(); |
| 84 |
|
| 85 |
void _grabber_gui_input(const Ref<InputEvent> &p_event); |
| 86 |
void _value_input_hidden(); |
| 87 |
void _value_input_submitted(const String &); |
| 88 |
void _value_focus_exited(); |
| 89 |
void _value_input_gui_input(const Ref<InputEvent> &p_event); |
| 90 |
|
| 91 |
void _evaluate_input_text(); |
| 92 |
|
| 93 |
void _update_value_input_stylebox(); |
| 94 |
void _ensure_value_input(); |
| 95 |
void _draw_spin_slider(); |
| 96 |
|
| 97 |
struct ThemeCache { |
| 98 |
Ref<Texture2D> updown_icon; |
| 99 |
Ref<Texture2D> updown_disabled_icon; |
| 100 |
} theme_cache; |
| 101 |
|
| 102 |
protected: |
| 103 |
void _notification(int p_what); |
| 104 |
virtual void gui_input(const Ref<InputEvent> &p_event) override; |
| 105 |
static void _bind_methods(); |
| 106 |
void _grabber_mouse_entered(); |
| 107 |
void _grabber_mouse_exited(); |
| 108 |
void _focus_entered(bool p_hide_focus = false); |
| 109 |
|
| 110 |
public: |
| 111 |
String get_tooltip(const Point2 &p_pos) const override; |
| 112 |
|
| 113 |
virtual Size2 get_minimum_size() const override; |
| 114 |
|
| 115 |
String get_text_value() const; |
| 116 |
void set_label(const String &p_label); |
| 117 |
String get_label() const; |
| 118 |
|
| 119 |
void set_suffix(const String &p_suffix); |
| 120 |
String get_suffix() const; |
| 121 |
|
| 122 |
void set_control_state(ControlState p_type); |
| 123 |
ControlState get_control_state() const; |
| 124 |
|
| 125 |
#ifndef DISABLE_DEPRECATED |
| 126 |
void set_hide_slider(bool p_hide); |
| 127 |
bool is_hiding_slider() const; |
| 128 |
#endif |
| 129 |
|
| 130 |
void set_editing_integer(bool p_editing_integer); |
| 131 |
bool is_editing_integer() const; |
| 132 |
|
| 133 |
void set_read_only(bool p_enable); |
| 134 |
bool is_read_only() const; |
| 135 |
|
| 136 |
void set_flat(bool p_enable); |
| 137 |
bool is_flat() const; |
| 138 |
|
| 139 |
bool is_grabbing() const; |
| 140 |
|
| 141 |
void setup_and_show() { _focus_entered(); } |
| 142 |
LineEdit *get_line_edit(); |
| 143 |
|
| 144 |
EditorSpinSlider(); |
| 145 |
}; |
| 146 |
|
| 147 |
VARIANT_ENUM_CAST(EditorSpinSlider::ControlState) |