diff options
author | AnaDenisa <anasecuiu@yahoo.com> | 2018-12-04 12:30:00 +0000 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2019-06-28 12:25:19 +0200 |
commit | 13279a7da7bf26a64efe91a3ea29139b0c73cd6d (patch) | |
tree | c518bff1a17e244cf2964e73a428c6b0d41fcaa6 /editor | |
parent | 7b10bae916dabcf1639fa1ee99c5fefd2790a1ca (diff) |
Add option to input value manually in EditorPropertyEasing
Double-clicking on the EditorPropertyEasing widget (e.g. for the Light
Attenuation parameter) shows an EditorSpinSlider to set the value manually.
Fixes #8449.
Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor_properties.cpp | 49 | ||||
-rw-r--r-- | editor/editor_properties.h | 15 | ||||
-rw-r--r-- | editor/editor_spin_slider.h | 3 |
3 files changed, 59 insertions, 8 deletions
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 8e4ec47435..1ede0bd8dc 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "editor_properties.h" + #include "editor/editor_resource_preview.h" #include "editor_node.h" #include "editor_properties_array_dict.h" @@ -925,6 +926,9 @@ void EditorPropertyEasing::_drag_easing(const Ref<InputEvent> &p_ev) { preset->set_global_position(easing_draw->get_global_transform().xform(mb->get_position())); preset->popup(); } + if (mb.is_valid() && mb->is_doubleclick() && mb->get_button_index() == BUTTON_LEFT) { + _setup_spin(); + } Ref<InputEventMouseMotion> mm = p_ev; @@ -963,7 +967,6 @@ void EditorPropertyEasing::_draw_easing() { Size2 s = easing_draw->get_size(); Rect2 r(Point2(), s); r = r.grow(3); - //get_stylebox("normal", "LineEdit")->draw(ci, r); int points = 48; @@ -1006,6 +1009,31 @@ void EditorPropertyEasing::_set_preset(int p_preset) { easing_draw->update(); } +void EditorPropertyEasing::_setup_spin() { + setting = true; + spin->setup_and_show(); + spin->get_line_edit()->set_text(rtos(get_edited_object()->get(get_edited_property()))); + setting = false; + spin->show(); +} + +void EditorPropertyEasing::_spin_value_changed(double p_value) { + if (setting) + return; + + // 0 is a singularity, but both positive and negative values + // are otherwise allowed. Enforce 0+ as workaround. + if (Math::is_zero_approx(p_value)) { + p_value = 0.00001; + } + emit_changed(get_edited_property(), p_value); + _spin_focus_exited(); +} + +void EditorPropertyEasing::_spin_focus_exited() { + spin->hide(); +} + void EditorPropertyEasing::setup(bool p_full, bool p_flip) { flip = p_flip; @@ -1028,9 +1056,6 @@ void EditorPropertyEasing::_notification(int p_what) { } easing_draw->set_custom_minimum_size(Size2(0, get_font("font", "Label")->get_height() * 2)); } break; - case NOTIFICATION_RESIZED: { - - } break; } } @@ -1039,6 +1064,9 @@ void EditorPropertyEasing::_bind_methods() { ClassDB::bind_method("_draw_easing", &EditorPropertyEasing::_draw_easing); ClassDB::bind_method("_drag_easing", &EditorPropertyEasing::_drag_easing); ClassDB::bind_method("_set_preset", &EditorPropertyEasing::_set_preset); + + ClassDB::bind_method("_spin_value_changed", &EditorPropertyEasing::_spin_value_changed); + ClassDB::bind_method("_spin_focus_exited", &EditorPropertyEasing::_spin_focus_exited); } EditorPropertyEasing::EditorPropertyEasing() { @@ -1053,6 +1081,19 @@ EditorPropertyEasing::EditorPropertyEasing() { add_child(preset); preset->connect("id_pressed", this, "_set_preset"); + spin = memnew(EditorSpinSlider); + spin->set_flat(true); + spin->set_min(-100); + spin->set_max(100); + spin->set_step(0); + spin->set_hide_slider(true); + spin->set_allow_lesser(true); + spin->set_allow_greater(true); + spin->connect("value_changed", this, "_spin_value_changed"); + spin->get_line_edit()->connect("focus_exited", this, "_spin_focus_exited"); + spin->hide(); + add_child(spin); + flip = false; full = false; } diff --git a/editor/editor_properties.h b/editor/editor_properties.h index 02d9349f2d..0a4a07cdc0 100644 --- a/editor/editor_properties.h +++ b/editor/editor_properties.h @@ -32,12 +32,12 @@ #define EDITOR_PROPERTIES_H #include "editor/create_dialog.h" -#include "editor/editor_file_system.h" #include "editor/editor_inspector.h" #include "editor/editor_spin_slider.h" #include "editor/property_selector.h" #include "editor/scene_tree_editor.h" #include "scene/gui/color_picker.h" +#include "scene/gui/line_edit.h" class EditorPropertyNil : public EditorProperty { GDCLASS(EditorPropertyNil, EditorProperty); @@ -308,7 +308,11 @@ class EditorPropertyEasing : public EditorProperty { GDCLASS(EditorPropertyEasing, EditorProperty); Control *easing_draw; PopupMenu *preset; + EditorSpinSlider *spin; + bool setting; + bool full; + bool flip; enum { EASING_ZERO, @@ -321,13 +325,16 @@ class EditorPropertyEasing : public EditorProperty { }; - bool flip; - void _drag_easing(const Ref<InputEvent> &p_ev); void _draw_easing(); - void _notification(int p_what); void _set_preset(int); + void _setup_spin(); + void _spin_value_changed(double p_value); + void _spin_focus_exited(); + + void _notification(int p_what); + protected: static void _bind_methods(); diff --git a/editor/editor_spin_slider.h b/editor/editor_spin_slider.h index 1523c20f48..d91380e175 100644 --- a/editor/editor_spin_slider.h +++ b/editor/editor_spin_slider.h @@ -102,6 +102,9 @@ public: void set_custom_label_color(bool p_use_custom_label_color, Color p_custom_label_color); + void setup_and_show() { _focus_entered(); } + LineEdit *get_line_edit() { return value_input; } + virtual Size2 get_minimum_size() const; EditorSpinSlider(); }; |