aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Verschelde2017-02-12 23:12:14 +0100
committerGitHub2017-02-12 23:12:14 +0100
commit3b09d7720838142bb76c6ff8fa7b0dbded5ee813 (patch)
treeeabf5ab49bc34911c6219fc7d826a028e23b18f4
parent4e9f88b6493a3bcfe19d53137c5d3d8c061ab6cd (diff)
parentc0f7b80b89680b0a53dfe5e2306b751116ac9350 (diff)
downloadgodot-3b09d7720838142bb76c6ff8fa7b0dbded5ee813.tar.gz
godot-3b09d7720838142bb76c6ff8fa7b0dbded5ee813.tar.zst
godot-3b09d7720838142bb76c6ff8fa7b0dbded5ee813.zip
Merge pull request #7721 from RandomShaper/improve-touch-button-2.1
Fix touch button issues (2.1)
-rw-r--r--scene/2d/screen_button.cpp137
-rw-r--r--scene/2d/screen_button.h4
2 files changed, 56 insertions, 85 deletions
diff --git a/scene/2d/screen_button.cpp b/scene/2d/screen_button.cpp
index 68c98907f..697c387c1 100644
--- a/scene/2d/screen_button.cpp
+++ b/scene/2d/screen_button.cpp
@@ -145,8 +145,12 @@ void TouchScreenButton::_notification(int p_what) {
} break;
case NOTIFICATION_EXIT_TREE: {
if (is_pressed())
- Input::get_singleton()->action_release(action);
+ _release(true);
} break;
+ case NOTIFICATION_PAUSED: {
+ // So the button can be pressed again even though the release gets unhandled because of coming during pause
+ allow_repress=true;
+ }
}
}
@@ -184,22 +188,7 @@ void TouchScreenButton::_input(const InputEvent& p_event) {
if (p_event.type==InputEvent::SCREEN_TOUCH && !p_event.screen_touch.pressed && finger_pressed==p_event.screen_touch.index) {
- emit_signal("released");
-
- if (action_id!=-1) {
-
- Input::get_singleton()->action_release(action);
- InputEvent ie;
- ie.type=InputEvent::ACTION;
- ie.ID=0;
- ie.action.action=action_id;
- ie.action.pressed=false;
- get_tree()->input_event(ie);
- }
- finger_pressed=-1;
-
- update();
-
+ _release();
}
if ((p_event.type==InputEvent::SCREEN_TOUCH && p_event.screen_touch.pressed)|| p_event.type==InputEvent::SCREEN_DRAG) {
@@ -225,44 +214,12 @@ void TouchScreenButton::_input(const InputEvent& p_event) {
if (touched) {
-
if (finger_pressed==-1) {
- finger_pressed=p_event.screen_touch.index;
- //emit change stuff
- emit_signal("pressed");
- if (action_id!=-1) {
-
- Input::get_singleton()->action_press(action);
- InputEvent ie;
- ie.type=InputEvent::ACTION;
- ie.ID=0;
- ie.action.action=action_id;
- ie.action.pressed=true;
- get_tree()->input_event(ie);
- }
-
- update();
+ _press(p_event.screen_touch.index);
}
-
} else {
-
if (finger_pressed!=-1) {
-
- emit_signal("released");
-
- if (action_id!=-1) {
-
- Input::get_singleton()->action_release(action);
- InputEvent ie;
- ie.type=InputEvent::ACTION;
- ie.ID=0;
- ie.action.action=action_id;
- ie.action.pressed=false;
- get_tree()->input_event(ie);
- }
- finger_pressed=-1;
-
- update();
+ _release();
}
}
@@ -280,7 +237,8 @@ void TouchScreenButton::_input(const InputEvent& p_event) {
if (!is_visible())
return;
- if (finger_pressed!=-1)
+ const bool can_press=finger_pressed==-1 || allow_repress;
+ if (!can_press)
return; //already fingering
Point2 coord = (get_global_transform_with_canvas()).affine_inverse().xform(Point2(p_event.screen_touch.x,p_event.screen_touch.y));
@@ -311,48 +269,56 @@ void TouchScreenButton::_input(const InputEvent& p_event) {
}
-
if (touched) {
+ _press(p_event.screen_touch.index);
+ }
+ } else {
+ if (p_event.screen_touch.index==finger_pressed) {
+ _release();
+ }
+ }
+ }
+ }
+}
- finger_pressed=p_event.screen_touch.index;
- //emit change stuff
- emit_signal("pressed");
- if (action_id!=-1) {
+void TouchScreenButton::_press(int p_finger_pressed) {
- Input::get_singleton()->action_press(action);
- InputEvent ie;
- ie.type=InputEvent::ACTION;
- ie.ID=0;
- ie.action.action=action_id;
- ie.action.pressed=true;
- get_tree()->input_event(ie);
- }
- update();
+ finger_pressed=p_finger_pressed;
+ allow_repress=false;
- }
- } else {
+ if (action_id!=-1) {
+ Input::get_singleton()->action_press(action);
+ InputEvent ie;
+ ie.type=InputEvent::ACTION;
+ ie.ID=0;
+ ie.action.action=action_id;
+ ie.action.pressed=true;
+ get_tree()->input_event(ie);
+ }
- if (p_event.screen_touch.index==finger_pressed) {
- //untouch
+ emit_signal("pressed");
+ update();
+}
- emit_signal("released");
+void TouchScreenButton::_release(bool p_exiting_tree) {
- if (action_id!=-1) {
+ finger_pressed=-1;
- Input::get_singleton()->action_release(action);
- InputEvent ie;
- ie.type=InputEvent::ACTION;
- ie.ID=0;
- ie.action.action=action_id;
- ie.action.pressed=false;
- get_tree()->input_event(ie);
- }
- finger_pressed=-1;
- update();
- }
- }
- }
+ if (action_id!=-1) {
+
+ Input::get_singleton()->action_release(action);
+ InputEvent ie;
+ ie.type=InputEvent::ACTION;
+ ie.ID=0;
+ ie.action.action=action_id;
+ ie.action.pressed=false;
+ get_tree()->input_event(ie);
+ }
+
+ if (!p_exiting_tree) {
+ emit_signal("released");
+ update();
}
}
@@ -438,6 +404,7 @@ void TouchScreenButton::_bind_methods() {
TouchScreenButton::TouchScreenButton() {
finger_pressed=-1;
+ allow_repress=false;
action_id=-1;
passby_press=false;
visibility=VISIBILITY_ALWAYS;
diff --git a/scene/2d/screen_button.h b/scene/2d/screen_button.h
index bf9ae54a3..46090e036 100644
--- a/scene/2d/screen_button.h
+++ b/scene/2d/screen_button.h
@@ -56,12 +56,16 @@ private:
StringName action;
bool passby_press;
int finger_pressed;
+ bool allow_repress;
int action_id;
VisibilityMode visibility;
void _input(const InputEvent& p_Event);
+ void _press(int p_finger_pressed);
+ void _release(bool p_exiting_tree=false);
+
protected:
void _notification(int p_what);