diff options
author | Fredia Huya-Kouadio <fhuya@meta.com> | 2022-10-22 07:30:46 -0700 |
---|---|---|
committer | Fredia Huya-Kouadio <fhuya@meta.com> | 2022-10-22 07:30:46 -0700 |
commit | 13e4770b97d0e6343556676dddb1b97d09d8bbdf (patch) | |
tree | fdc45faed424d118c3655e88726fa7c4f4f83505 /core | |
parent | 276ab5be07752582b4341c33fb8f53a7887af87a (diff) |
Add double_tap attribute to InputEventScreenTouch
This provides parity with the `InputEventMouseButton` allowing for proper conversion between the two events.
Diffstat (limited to 'core')
-rw-r--r-- | core/input/input.cpp | 2 | ||||
-rw-r--r-- | core/input/input_event.cpp | 15 | ||||
-rw-r--r-- | core/input/input_event.h | 4 |
3 files changed, 20 insertions, 1 deletions
diff --git a/core/input/input.cpp b/core/input/input.cpp index 889c2a92fa..1321e40795 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -519,6 +519,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em touch_event.instantiate(); touch_event->set_pressed(mb->is_pressed()); touch_event->set_position(mb->get_position()); + touch_event->set_double_tap(mb->is_double_click()); event_dispatch_function(touch_event); } } @@ -580,6 +581,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em button_event->set_global_position(st->get_position()); button_event->set_pressed(st->is_pressed()); button_event->set_button_index(MouseButton::LEFT); + button_event->set_double_click(st->is_double_tap()); if (st->is_pressed()) { button_event->set_button_mask(MouseButton(mouse_button_mask | MouseButton::MASK_LEFT)); } else { diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index 38037eaf72..9dc071de9c 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -1162,6 +1162,13 @@ bool InputEventScreenTouch::is_pressed() const { return pressed; } +void InputEventScreenTouch::set_double_tap(bool p_double_tap) { + double_tap = p_double_tap; +} +bool InputEventScreenTouch::is_double_tap() const { + return double_tap; +} + Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { Ref<InputEventScreenTouch> st; st.instantiate(); @@ -1170,6 +1177,7 @@ Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, co st->set_index(index); st->set_position(p_xform.xform(pos + p_local_ofs)); st->set_pressed(pressed); + st->set_double_tap(double_tap); return st; } @@ -1182,7 +1190,8 @@ String InputEventScreenTouch::as_text() const { String InputEventScreenTouch::to_string() { String p = pressed ? "true" : "false"; - return vformat("InputEventScreenTouch: index=%d, pressed=%s, position=(%s)", index, p, String(get_position())); + String double_tap_string = double_tap ? "true" : "false"; + return vformat("InputEventScreenTouch: index=%d, pressed=%s, position=(%s), double_tap=%s", index, p, String(get_position()), double_tap_string); } void InputEventScreenTouch::_bind_methods() { @@ -1195,9 +1204,13 @@ void InputEventScreenTouch::_bind_methods() { ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventScreenTouch::set_pressed); //ClassDB::bind_method(D_METHOD("is_pressed"),&InputEventScreenTouch::is_pressed); + ClassDB::bind_method(D_METHOD("set_double_tap", "double_tap"), &InputEventScreenTouch::set_double_tap); + ClassDB::bind_method(D_METHOD("is_double_tap"), &InputEventScreenTouch::is_double_tap); + ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position", PROPERTY_HINT_NONE, "suffix:px"), "set_position", "get_position"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "double_tap"), "set_double_tap", "is_double_tap"); } /////////////////////////////////// diff --git a/core/input/input_event.h b/core/input/input_event.h index bc3ec3e7ac..adbcb7cf68 100644 --- a/core/input/input_event.h +++ b/core/input/input_event.h @@ -353,6 +353,7 @@ class InputEventScreenTouch : public InputEventFromWindow { int index = 0; Vector2 pos; bool pressed = false; + bool double_tap = false; protected: static void _bind_methods(); @@ -367,6 +368,9 @@ public: void set_pressed(bool p_pressed); virtual bool is_pressed() const override; + void set_double_tap(bool p_double_tap); + bool is_double_tap() const; + virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override; virtual String as_text() const override; virtual String to_string() override; |