summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorEvgeny Zuev <evgeny.zuev@xored.com>2017-08-07 11:44:46 +0700
committerEvgeny Zuev <evgeny.zuev@xored.com>2017-08-07 15:14:50 +0700
commit60230675d9f84ea9e3e1e7409d9cb3f280c63389 (patch)
treed6a692fc8ac93fab2fc423e0bf71bfdc3b4b774b /scene
parentd9a97aae04b947517c286f019ce7cd8abd3745fe (diff)
Add handling of touch events in _gui_input_event
Fixes #10039
Diffstat (limited to 'scene')
-rw-r--r--scene/main/viewport.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 76b281ebac..91cff72338 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -2028,6 +2028,89 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
}
}
+ Ref<InputEventScreenTouch> touch_event = p_event;
+ if (touch_event.is_valid()) {
+
+ Size2 pos = touch_event->get_position();
+ if (touch_event->is_pressed()) {
+
+ Control *over = _gui_find_control(pos);
+ if (over) {
+
+ if (!gui.modal_stack.empty()) {
+
+ Control *top = gui.modal_stack.back()->get();
+ if (over != top && !top->is_a_parent_of(over)) {
+
+ return;
+ }
+ }
+ if (over->can_process()) {
+
+ touch_event = touch_event->xformed_by(Transform2D()); //make a copy
+ if (over == gui.mouse_focus) {
+ pos = gui.focus_inv_xform.xform(pos);
+ } else {
+ pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos);
+ }
+ touch_event->set_position(pos);
+ _gui_call_input(over, touch_event);
+ }
+ get_tree()->set_input_as_handled();
+ return;
+ }
+ } else if (gui.mouse_focus) {
+
+ if (gui.mouse_focus->can_process()) {
+
+ touch_event = touch_event->xformed_by(Transform2D()); //make a copy
+ touch_event->set_position(gui.focus_inv_xform.xform(pos));
+
+ _gui_call_input(gui.mouse_focus, touch_event);
+ }
+ get_tree()->set_input_as_handled();
+ return;
+ }
+ }
+
+ Ref<InputEventScreenDrag> drag_event = p_event;
+ if (drag_event.is_valid()) {
+
+ Control *over = gui.mouse_focus;
+ if (!over) {
+ over = _gui_find_control(drag_event->get_position());
+ }
+ if (over) {
+
+ if (!gui.modal_stack.empty()) {
+
+ Control *top = gui.modal_stack.back()->get();
+ if (over != top && !top->is_a_parent_of(over)) {
+
+ return;
+ }
+ }
+ if (over->can_process()) {
+
+ Transform2D localizer = over->get_global_transform_with_canvas().affine_inverse();
+ Size2 pos = localizer.xform(drag_event->get_position());
+ Vector2 speed = localizer.basis_xform(drag_event->get_speed());
+ Vector2 rel = localizer.basis_xform(drag_event->get_relative());
+
+ drag_event = drag_event->xformed_by(Transform2D()); //make a copy
+
+ drag_event->set_speed(speed);
+ drag_event->set_relative(rel);
+ drag_event->set_position(pos);
+
+ _gui_call_input(over, drag_event);
+ }
+
+ get_tree()->set_input_as_handled();
+ return;
+ }
+ }
+
if (mm.is_null() && mb.is_null() && p_event->is_action_type()) {
if (gui.key_focus && !gui.key_focus->is_visible_in_tree()) {