summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2022-12-23 17:37:45 +0200
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2022-12-23 23:44:10 +0200
commit223a612c0c79563047eee80edf3552bcb5e112e1 (patch)
tree16b7074b2691584f1ea907d1e0688018f160914b /core
parent5784bf1be0cdf409a115556bf6c54f78f3d454ef (diff)
[iOS] Add Apple Pencil pressure and tilt support.
Diffstat (limited to 'core')
-rw-r--r--core/input/input.cpp6
-rw-r--r--core/input/input_event.cpp41
-rw-r--r--core/input/input_event.h12
3 files changed, 58 insertions, 1 deletions
diff --git a/core/input/input.cpp b/core/input/input.cpp
index cb65d2569c..554f8fad00 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -540,6 +540,9 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
drag_event->set_position(position);
drag_event->set_relative(relative);
+ drag_event->set_tilt(mm->get_tilt());
+ drag_event->set_pen_inverted(mm->get_pen_inverted());
+ drag_event->set_pressure(mm->get_pressure());
drag_event->set_velocity(get_last_mouse_velocity());
event_dispatch_function(drag_event);
@@ -605,6 +608,9 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
motion_event.instantiate();
motion_event->set_device(InputEvent::DEVICE_ID_TOUCH_MOUSE);
+ motion_event->set_tilt(sd->get_tilt());
+ motion_event->set_pen_inverted(sd->get_pen_inverted());
+ motion_event->set_pressure(sd->get_pressure());
motion_event->set_position(sd->get_position());
motion_event->set_global_position(sd->get_position());
motion_event->set_relative(sd->get_relative());
diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp
index 0a32b4bf68..4859490230 100644
--- a/core/input/input_event.cpp
+++ b/core/input/input_event.cpp
@@ -1223,6 +1223,30 @@ int InputEventScreenDrag::get_index() const {
return index;
}
+void InputEventScreenDrag::set_tilt(const Vector2 &p_tilt) {
+ tilt = p_tilt;
+}
+
+Vector2 InputEventScreenDrag::get_tilt() const {
+ return tilt;
+}
+
+void InputEventScreenDrag::set_pressure(float p_pressure) {
+ pressure = p_pressure;
+}
+
+float InputEventScreenDrag::get_pressure() const {
+ return pressure;
+}
+
+void InputEventScreenDrag::set_pen_inverted(bool p_inverted) {
+ pen_inverted = p_inverted;
+}
+
+bool InputEventScreenDrag::get_pen_inverted() const {
+ return pen_inverted;
+}
+
void InputEventScreenDrag::set_position(const Vector2 &p_pos) {
pos = p_pos;
}
@@ -1256,6 +1280,9 @@ Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, con
sd->set_window_id(get_window_id());
sd->set_index(index);
+ sd->set_pressure(get_pressure());
+ sd->set_pen_inverted(get_pen_inverted());
+ sd->set_tilt(get_tilt());
sd->set_position(p_xform.xform(pos + p_local_ofs));
sd->set_relative(p_xform.basis_xform(relative));
sd->set_velocity(p_xform.basis_xform(velocity));
@@ -1268,7 +1295,7 @@ String InputEventScreenDrag::as_text() const {
}
String InputEventScreenDrag::to_string() {
- return vformat("InputEventScreenDrag: index=%d, position=(%s), relative=(%s), velocity=(%s)", index, String(get_position()), String(get_relative()), String(get_velocity()));
+ return vformat("InputEventScreenDrag: index=%d, position=(%s), relative=(%s), velocity=(%s), pressure=%.2f, tilt=(%s), pen_inverted=(%s)", index, String(get_position()), String(get_relative()), String(get_velocity()), get_pressure(), String(get_tilt()), get_pen_inverted());
}
bool InputEventScreenDrag::accumulate(const Ref<InputEvent> &p_event) {
@@ -1292,6 +1319,15 @@ void InputEventScreenDrag::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenDrag::set_index);
ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenDrag::get_index);
+ ClassDB::bind_method(D_METHOD("set_tilt", "tilt"), &InputEventScreenDrag::set_tilt);
+ ClassDB::bind_method(D_METHOD("get_tilt"), &InputEventScreenDrag::get_tilt);
+
+ ClassDB::bind_method(D_METHOD("set_pressure", "pressure"), &InputEventScreenDrag::set_pressure);
+ ClassDB::bind_method(D_METHOD("get_pressure"), &InputEventScreenDrag::get_pressure);
+
+ ClassDB::bind_method(D_METHOD("set_pen_inverted", "pen_inverted"), &InputEventScreenDrag::set_pen_inverted);
+ ClassDB::bind_method(D_METHOD("get_pen_inverted"), &InputEventScreenDrag::get_pen_inverted);
+
ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventScreenDrag::set_position);
ClassDB::bind_method(D_METHOD("get_position"), &InputEventScreenDrag::get_position);
@@ -1302,6 +1338,9 @@ void InputEventScreenDrag::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_velocity"), &InputEventScreenDrag::get_velocity);
ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "tilt"), "set_tilt", "get_tilt");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "pressure"), "set_pressure", "get_pressure");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pen_inverted"), "set_pen_inverted", "get_pen_inverted");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position", PROPERTY_HINT_NONE, "suffix:px"), "set_position", "get_position");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative", PROPERTY_HINT_NONE, "suffix:px"), "set_relative", "get_relative");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "velocity", PROPERTY_HINT_NONE, "suffix:px/s"), "set_velocity", "get_velocity");
diff --git a/core/input/input_event.h b/core/input/input_event.h
index adbcb7cf68..06c3118abc 100644
--- a/core/input/input_event.h
+++ b/core/input/input_event.h
@@ -384,6 +384,9 @@ class InputEventScreenDrag : public InputEventFromWindow {
Vector2 pos;
Vector2 relative;
Vector2 velocity;
+ Vector2 tilt;
+ float pressure = 0;
+ bool pen_inverted = false;
protected:
static void _bind_methods();
@@ -392,6 +395,15 @@ public:
void set_index(int p_index);
int get_index() const;
+ void set_tilt(const Vector2 &p_tilt);
+ Vector2 get_tilt() const;
+
+ void set_pressure(float p_pressure);
+ float get_pressure() const;
+
+ void set_pen_inverted(bool p_inverted);
+ bool get_pen_inverted() const;
+
void set_position(const Vector2 &p_pos);
Vector2 get_position() const;