diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-09-03 13:07:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-03 13:07:44 +0200 |
commit | af5bfd138a7f79aa5698a4046214c7af3f70f39d (patch) | |
tree | b3e0dc761b9e526d85918d51cf2110d4558faa7b | |
parent | 4dfea5fc9c39d78d8aa4643f4d56bb33dd3916b1 (diff) | |
parent | e89c4c22dee54533450feb4032bc5d608dbb2ddc (diff) |
Merge pull request #31346 from sparkart/Add_scrollwheel_input_to_spinslider
Add scrollwheel input to spin slider
-rw-r--r-- | editor/editor_spin_slider.cpp | 29 | ||||
-rw-r--r-- | editor/editor_spin_slider.h | 1 |
2 files changed, 28 insertions, 2 deletions
diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp index 46a30b7554..35fe366526 100644 --- a/editor/editor_spin_slider.cpp +++ b/editor/editor_spin_slider.cpp @@ -138,20 +138,39 @@ void EditorSpinSlider::_gui_input(const Ref<InputEvent> &p_event) { void EditorSpinSlider::_grabber_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> mb = p_event; + + if (grabbing_grabber) { + if (mb.is_valid()) { + + if (mb->get_button_index() == BUTTON_WHEEL_UP) { + set_value(get_value() + get_step()); + mousewheel_over_grabber = true; + } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN) { + set_value(get_value() - get_step()); + mousewheel_over_grabber = true; + } + } + } + if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT) { if (mb->is_pressed()) { grabbing_grabber = true; - grabbing_ratio = get_as_ratio(); - grabbing_from = grabber->get_transform().xform(mb->get_position()).x; + if (!mousewheel_over_grabber) { + grabbing_ratio = get_as_ratio(); + grabbing_from = grabber->get_transform().xform(mb->get_position()).x; + } } else { grabbing_grabber = false; + mousewheel_over_grabber = false; } } Ref<InputEventMouseMotion> mm = p_event; if (mm.is_valid() && grabbing_grabber) { + if (mousewheel_over_grabber) + return; float grabbing_ofs = (grabber->get_transform().xform(mm->get_position()).x - grabbing_from) / float(grabber_range); set_as_ratio(grabbing_ratio + grabbing_ofs); @@ -267,6 +286,11 @@ void EditorSpinSlider::_notification(int p_what) { grabber->set_size(Size2(0, 0)); grabber->set_position(get_global_position() + grabber_rect.position + grabber_rect.size * 0.5 - grabber->get_size() * 0.5); + + if (mousewheel_over_grabber) { + Input::get_singleton()->warp_mouse_position(grabber->get_position() + grabber_rect.size); + } + grabber_range = width; } } @@ -462,6 +486,7 @@ EditorSpinSlider::EditorSpinSlider() { grabber->connect("gui_input", this, "_grabber_gui_input"); mouse_over_spin = false; mouse_over_grabber = false; + mousewheel_over_grabber = false; grabbing_grabber = false; grabber_range = 1; value_input = memnew(LineEdit); diff --git a/editor/editor_spin_slider.h b/editor/editor_spin_slider.h index d91380e175..2dc6e2c2f2 100644 --- a/editor/editor_spin_slider.h +++ b/editor/editor_spin_slider.h @@ -48,6 +48,7 @@ class EditorSpinSlider : public Range { bool mouse_over_spin; bool mouse_over_grabber; + bool mousewheel_over_grabber; bool grabbing_grabber; int grabbing_from; |