summaryrefslogtreecommitdiff
path: root/platform/ios
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 /platform/ios
parent5784bf1be0cdf409a115556bf6c54f78f3d454ef (diff)
[iOS] Add Apple Pencil pressure and tilt support.
Diffstat (limited to 'platform/ios')
-rw-r--r--platform/ios/display_server_ios.h4
-rw-r--r--platform/ios/display_server_ios.mm4
-rw-r--r--platform/ios/godot_view.mm4
3 files changed, 8 insertions, 4 deletions
diff --git a/platform/ios/display_server_ios.h b/platform/ios/display_server_ios.h
index 0ca0d3d1fe..82351a536b 100644
--- a/platform/ios/display_server_ios.h
+++ b/platform/ios/display_server_ios.h
@@ -105,10 +105,10 @@ public:
// MARK: - Input
- // MARK: Touches
+ // MARK: Touches and Apple Pencil
void touch_press(int p_idx, int p_x, int p_y, bool p_pressed, bool p_double_click);
- void touch_drag(int p_idx, int p_prev_x, int p_prev_y, int p_x, int p_y);
+ void touch_drag(int p_idx, int p_prev_x, int p_prev_y, int p_x, int p_y, float p_pressure, Vector2 p_tilt);
void touches_cancelled(int p_idx);
// MARK: Keyboard
diff --git a/platform/ios/display_server_ios.mm b/platform/ios/display_server_ios.mm
index 3f4a406116..ad1a1ae673 100644
--- a/platform/ios/display_server_ios.mm
+++ b/platform/ios/display_server_ios.mm
@@ -237,10 +237,12 @@ void DisplayServerIOS::touch_press(int p_idx, int p_x, int p_y, bool p_pressed,
perform_event(ev);
}
-void DisplayServerIOS::touch_drag(int p_idx, int p_prev_x, int p_prev_y, int p_x, int p_y) {
+void DisplayServerIOS::touch_drag(int p_idx, int p_prev_x, int p_prev_y, int p_x, int p_y, float p_pressure, Vector2 p_tilt) {
Ref<InputEventScreenDrag> ev;
ev.instantiate();
ev->set_index(p_idx);
+ ev->set_pressure(p_pressure);
+ ev->set_tilt(p_tilt);
ev->set_position(Vector2(p_x, p_y));
ev->set_relative(Vector2(p_x - p_prev_x, p_y - p_prev_y));
perform_event(ev);
diff --git a/platform/ios/godot_view.mm b/platform/ios/godot_view.mm
index 4537dc2985..02b8e748ef 100644
--- a/platform/ios/godot_view.mm
+++ b/platform/ios/godot_view.mm
@@ -363,7 +363,9 @@ static const float earth_gravity = 9.80665;
ERR_FAIL_COND(tid == -1);
CGPoint touchPoint = [touch locationInView:self];
CGPoint prev_point = [touch previousLocationInView:self];
- DisplayServerIOS::get_singleton()->touch_drag(tid, prev_point.x * self.contentScaleFactor, prev_point.y * self.contentScaleFactor, touchPoint.x * self.contentScaleFactor, touchPoint.y * self.contentScaleFactor);
+ CGFloat alt = [touch altitudeAngle];
+ CGVector azim = [touch azimuthUnitVectorInView:self];
+ DisplayServerIOS::get_singleton()->touch_drag(tid, prev_point.x * self.contentScaleFactor, prev_point.y * self.contentScaleFactor, touchPoint.x * self.contentScaleFactor, touchPoint.y * self.contentScaleFactor, [touch force] / [touch maximumPossibleForce], Vector2(azim.dx, azim.dy) * Math::cos(alt));
}
}
}