summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2018-12-11 18:16:29 +0100
committerGitHub <noreply@github.com>2018-12-11 18:16:29 +0100
commit13d037b2006ed097569814f694e4ad0ccd3b7bfa (patch)
tree2b1e7bf0164ba99e5de6cf90968defbb88c03b7a /scene/gui
parent3f9c0541630a168efc4acad541b95c4565580f46 (diff)
parent0838eca06322e5789450e03bf9be4c82b1d7a5e5 (diff)
Merge pull request #21471 from RodZill4/issue_11893
Fixed issue #11893 (SpinBox capturing mouse)
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/spin_box.cpp34
-rw-r--r--scene/gui/spin_box.h4
2 files changed, 13 insertions, 25 deletions
diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp
index ace22dddff..4f43bb0581 100644
--- a/scene/gui/spin_box.cpp
+++ b/scene/gui/spin_box.cpp
@@ -110,6 +110,9 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
range_click_timer->start();
line_edit->grab_focus();
+
+ drag.allowed = true;
+ drag.capture_pos = mb->get_position();
} break;
case BUTTON_RIGHT: {
@@ -133,14 +136,7 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
}
}
- if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == 1) {
-
- //set_default_cursor_shape(CURSOR_VSIZE);
- Vector2 cpos = Vector2(mb->get_position().x, mb->get_position().y);
- drag.mouse_pos = cpos;
- }
-
- if (mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == 1) {
+ if (mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
//set_default_cursor_shape(CURSOR_ARROW);
range_click_timer->stop();
@@ -150,32 +146,24 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
warp_mouse(drag.capture_pos);
}
+ drag.allowed = false;
}
Ref<InputEventMouseMotion> mm = p_event;
- if (mm.is_valid() && mm->get_button_mask() & 1) {
-
- Vector2 cpos = mm->get_position();
+ if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_LEFT) {
if (drag.enabled) {
- float diff_y = drag.mouse_pos.y - cpos.y;
- diff_y = Math::pow(ABS(diff_y), 1.8f) * SGN(diff_y);
- diff_y *= 0.1;
-
- drag.mouse_pos = cpos;
- drag.base_val = CLAMP(drag.base_val + get_step() * diff_y, get_min(), get_max());
-
- set_value(drag.base_val);
-
- } else if (drag.mouse_pos.distance_to(cpos) > 2) {
+ drag.diff_y += mm->get_relative().y;
+ float diff_y = -0.01 * Math::pow(ABS(drag.diff_y), 1.8f) * SGN(drag.diff_y);
+ set_value(CLAMP(drag.base_val + get_step() * diff_y, get_min(), get_max()));
+ } else if (drag.allowed && drag.capture_pos.distance_to(mm->get_position()) > 2) {
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
drag.enabled = true;
drag.base_val = get_value();
- drag.mouse_pos = cpos;
- drag.capture_pos = cpos;
+ drag.diff_y = 0;
}
}
}
diff --git a/scene/gui/spin_box.h b/scene/gui/spin_box.h
index f1ee26d9f3..6425af7158 100644
--- a/scene/gui/spin_box.h
+++ b/scene/gui/spin_box.h
@@ -54,10 +54,10 @@ class SpinBox : public Range {
struct Drag {
float base_val;
+ bool allowed;
bool enabled;
- Vector2 from;
- Vector2 mouse_pos;
Vector2 capture_pos;
+ float diff_y;
} drag;
void _line_edit_focus_exit();