Add the option to check if input was handled

When working with a viewport you should call Viewport.input() to pass
the input, but if the input was unhandled you might also want to call
Viewport.unhandled_input() so that objects in the sub-scene can handle
the event. This adds a way to check if the input was handled so that you
know whether you should call Viewport.unhandled_input() or not.

Signed-off-by: Saggi Mizrahi <saggi@mizrahi.cc>
(cherry picked from commit 245ace6e2e)
This commit is contained in:
Saggi Mizrahi 2017-03-16 18:52:50 +02:00 committed by Rémi Verschelde
parent e5d63aaece
commit 89b201b466
2 changed files with 6 additions and 0 deletions

View file

@ -327,6 +327,10 @@ void SceneTree::input_text(const String &p_text) {
root_lock--;
}
bool SceneTree::is_input_handled() {
return input_handled;
}
void SceneTree::input_event(const InputEvent &p_event) {
if (is_editor_hint() && (p_event.type == InputEvent::JOYSTICK_MOTION || p_event.type == InputEvent::JOYSTICK_BUTTON))
@ -1556,6 +1560,7 @@ void SceneTree::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_pause", "enable"), &SceneTree::set_pause);
ObjectTypeDB::bind_method(_MD("is_paused"), &SceneTree::is_paused);
ObjectTypeDB::bind_method(_MD("set_input_as_handled"), &SceneTree::set_input_as_handled);
ObjectTypeDB::bind_method(_MD("is_input_handled"), &SceneTree::is_input_handled);
ObjectTypeDB::bind_method(_MD("get_node_count"), &SceneTree::get_node_count);
ObjectTypeDB::bind_method(_MD("get_frame"), &SceneTree::get_frame);

View file

@ -262,6 +262,7 @@ public:
void quit();
void set_input_as_handled();
bool is_input_handled();
_FORCE_INLINE_ float get_fixed_process_time() const { return fixed_process_time; }
_FORCE_INLINE_ float get_idle_process_time() const { return idle_process_time; }