mirror of
https://github.com/godotengine/godot.git
synced 2026-01-06 10:11:57 +03:00
Add double_tap attribute to InputEventScreenTouch
This provides parity with the `InputEventMouseButton` allowing for proper conversion between the two events.
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
///////////////////////////////////
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user