From 44bc834623e9119169fc57af4c56027e3786b235 Mon Sep 17 00:00:00 2001 From: Janek Szynal Date: Wed, 5 Sep 2018 15:09:18 +0200 Subject: [PATCH 01/18] initial setup --- Sources/GLRenderer.swift | 10 +- Sources/UIApplication+handleSDLEvents.swift | 140 ++++++++++++++++++ Sources/UIWindow+TouchHandling.swift | 5 + Sources/UIWindow.swift | 3 +- samples/getting-started/android/build.gradle | 2 +- src/main/java/org/libsdl/app/SDLActivity.kt | 4 +- .../java/org/libsdl/app/SDLOnTouchListener.kt | 17 ++- 7 files changed, 165 insertions(+), 16 deletions(-) diff --git a/Sources/GLRenderer.swift b/Sources/GLRenderer.swift index 5ef4f0a2..2217ee3f 100644 --- a/Sources/GLRenderer.swift +++ b/Sources/GLRenderer.swift @@ -77,13 +77,13 @@ internal final class GLRenderer { } func absolutePointInOwnCoordinates(x inputX: CGFloat, y inputY: CGFloat) -> CGPoint { - #if os(macOS) +// #if os(macOS) // Here SDL scales our touch events for us, which means we need a special case for it: return CGPoint(x: inputX, y: inputY) - #else - // On all other platforms, we scale the touch events to the screen size manually: - return CGPoint(x: inputX / scale, y: inputY / scale) - #endif +// #else +// // On all other platforms, we scale the touch events to the screen size manually: +// return CGPoint(x: inputX / scale, y: inputY / scale) +// #endif } func blit( diff --git a/Sources/UIApplication+handleSDLEvents.swift b/Sources/UIApplication+handleSDLEvents.swift index 8a1d7d3e..ae318b72 100644 --- a/Sources/UIApplication+handleSDLEvents.swift +++ b/Sources/UIApplication+handleSDLEvents.swift @@ -14,6 +14,15 @@ extension UIApplication { var e = SDL_Event() while SDL_PollEvent(&e) == 1 { + + #if !os(macOS) + if let uievent = UIEvent.from(e) { + sendEvent(uievent) + break + } + #endif + + switch SDL_EventType(rawValue: e.type) { case SDL_QUIT: handleSDLQuit() @@ -45,6 +54,7 @@ extension UIApplication { let event = UIEvent.activeEvents.first, let touch = event.allTouches?.first(where: { $0.touchId == Int(0) } ) { + print("Mouseup with active events \(UIEvent.activeEvents.count)") touch.timestamp = e.timestampInSeconds touch.phase = .ended sendEvent(event) @@ -96,3 +106,133 @@ extension SDL_Event { return TimeInterval(self.common.timestamp) / 1000 } } + + +extension UIEvent { + + + static func from(_ event: SDL_Event) -> UIEvent? { + switch SDL_EventType(event.type) { + case SDL_FINGERDOWN: + let newTouch = UITouch( + touchId: Int(event.tfinger.fingerId), + at: CGPoint( + x: CGFloat(event.tfinger.x), + y: CGFloat(event.tfinger.y) + ), + timestamp: event.timestampInSeconds + ) + + if + let firstExistingEvent = UIEvent.activeEvents.first, + let _ = firstExistingEvent.allTouches?.first(where: {$0.touchId == event.tfinger.fingerId} ) + { + //found a matching event, adding current touch to it and returning + firstExistingEvent.allTouches?.insert(newTouch) + return firstExistingEvent + } else { + //no matching event found, creating a new one + return UIEvent(touch: newTouch) + } + + case SDL_FINGERMOTION: + if + let firstExistingEvent = UIEvent.activeEvents.first, + let matchingTouch = firstExistingEvent.allTouches?.first(where: { $0.touchId == event.tfinger.fingerId} ) + { + + matchingTouch.updateAbsoluteLocation(.from(event.tfinger)) + matchingTouch.timestamp = event.timestampInSeconds + matchingTouch.phase = .moved + + return firstExistingEvent + } + else { + return nil + } + + case SDL_FINGERUP: + if + let firstExistingEvent = UIEvent.activeEvents.first, + let matchingTouch = firstExistingEvent.allTouches?.first(where: {$0.touchId == event.tfinger.fingerId} ) + { + matchingTouch.phase = .ended + matchingTouch.timestamp = event.timestampInSeconds + return firstExistingEvent + } else { + return nil + } + + default: + return nil + } + } +} + +extension UIEvent: CustomStringConvertible { + public var description: String { + var listOfTouches = "" + if let touches = allTouches { + for touch in touches { + listOfTouches += "\(touch.description),\n" + } + } + return "Event with touches: \(listOfTouches)" + } +} + +extension UITouch: CustomStringConvertible { + public var description: String { + return "TouchID: \(self.touchId), timestamp: \(self.timestamp)" + } +} + +#if os(Android) +import JNI + + +@_silgen_name("Java_org_libsdl_app_SDLActivity_onNativeTouch") +public func Java_org_libsdl_app_SDLActivity_onNativeTouch(env: UnsafeMutablePointer, view: JavaObject, + touchDeviceID: JavaInt, pointerFingerID: JavaInt, action: JavaInt, + x: JavaFloat, y: JavaFloat, pressure: JavaFloat, timestamp: JavaLong) { + + guard let eventType = SDL_EventType.eventFrom(androidAction: action) else {return} + + let timestamp = JavaLong(littleEndian: timestamp) + let timestamp32B = UInt32(timestamp & Int64(UInt32.max)) + + var event = SDL_Event(tfinger: + SDL_TouchFingerEvent( + type: eventType.rawValue, + timestamp: timestamp32B, // ensure this is in ms + touchId: Int64(touchDeviceID), // I think this is the "Touch Device ID" which should always be 0, but check this + fingerId: Int64(pointerFingerID), + x: x / Float(UIScreen.main.scale), + y: y / Float(UIScreen.main.scale), + dx: 0, + dy: 0, + pressure: pressure + ) + ) + + // add the event to SDL's event stack + // don't use SDL_PushEvent because it overrides `event.timestamp` with its own: + SDL_PeepEvents(&event, 1, SDL_ADDEVENT, 0, 0) +} + + +extension SDL_EventType { + public static func eventFrom(androidAction: JavaInt) -> SDL_EventType? { + switch androidAction { + case 0, 5: return SDL_FINGERDOWN + case 1, 6: return SDL_FINGERUP + case 2: return SDL_FINGERMOTION + default: return nil + } + } +} + +#endif + + + diff --git a/Sources/UIWindow+TouchHandling.swift b/Sources/UIWindow+TouchHandling.swift index d07f5722..5f5d06a4 100644 --- a/Sources/UIWindow+TouchHandling.swift +++ b/Sources/UIWindow+TouchHandling.swift @@ -14,8 +14,13 @@ protocol SDLEventWithCoordinates { extension SDL_MouseButtonEvent: SDLEventWithCoordinates {} extension SDL_MouseMotionEvent: SDLEventWithCoordinates {} + extension CGPoint { static func from(_ event: SDLEventWithCoordinates) -> CGPoint { return UIApplication.shared.glRenderer.absolutePointInOwnCoordinates(x: CGFloat(event.x), y: CGFloat(event.y)) } + + static func from(_ event: SDL_TouchFingerEvent) -> CGPoint { + return UIApplication.shared.glRenderer.absolutePointInOwnCoordinates(x: CGFloat(event.x), y: CGFloat(event.y)) + } } diff --git a/Sources/UIWindow.swift b/Sources/UIWindow.swift index 0a8183d6..ceffd2b4 100644 --- a/Sources/UIWindow.swift +++ b/Sources/UIWindow.swift @@ -36,7 +36,7 @@ public class UIWindow: UIView { UIEvent.activeEvents.insert(event) currentTouch.view = hitView currentTouch.gestureRecognizers = hitView.getRecognizerHierachy() - + print("recognizers: \(currentTouch.gestureRecognizers)" ) currentTouch.runTouchActionOnRecognizerHierachy { $0.touchesBegan(allTouches, with: event) } hitView.touchesBegan(allTouches, with: event) @@ -53,6 +53,7 @@ public class UIWindow: UIView { } UIEvent.activeEvents.remove(event) + print("After removing, left with \(UIEvent.activeEvents.count) active events") } } } diff --git a/samples/getting-started/android/build.gradle b/samples/getting-started/android/build.gradle index c75cf5f0..d2e510b9 100644 --- a/samples/getting-started/android/build.gradle +++ b/samples/getting-started/android/build.gradle @@ -7,7 +7,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.3' + classpath 'com.android.tools.build:gradle:3.1.4' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong diff --git a/src/main/java/org/libsdl/app/SDLActivity.kt b/src/main/java/org/libsdl/app/SDLActivity.kt index 40d84654..46f3a77a 100644 --- a/src/main/java/org/libsdl/app/SDLActivity.kt +++ b/src/main/java/org/libsdl/app/SDLActivity.kt @@ -40,7 +40,7 @@ open class SDLActivity internal constructor (context: Context?) : RelativeLayout } private var mSurface: SurfaceView - private var mIsSurfaceReady = false + private var mIsSurfaceReady = false/**/ private var mHasFocus = false private external fun nativeRender() @@ -58,7 +58,7 @@ open class SDLActivity internal constructor (context: Context?) : RelativeLayout // SDLOnTouchListener conformance external override fun onNativeMouse(button: Int, action: Int, x: Float, y: Float) - external override fun onNativeTouch(touchDevId: Int, pointerFingerId: Int, action: Int, x: Float, y: Float, p: Float) + external override fun onNativeTouch(touchDevId: Int, pointerFingerId: Int, action: Int, x: Float, y: Float, p: Float, t: Long) override var mWidth: Float = 1.0f // Keep track of the surface size to normalize touch events override var mHeight: Float = 1.0f // Start with non-zero values to avoid potential division by zero diff --git a/src/main/java/org/libsdl/app/SDLOnTouchListener.kt b/src/main/java/org/libsdl/app/SDLOnTouchListener.kt index e225abc0..2c3bcae2 100644 --- a/src/main/java/org/libsdl/app/SDLOnTouchListener.kt +++ b/src/main/java/org/libsdl/app/SDLOnTouchListener.kt @@ -1,5 +1,6 @@ package main.java.org.libsdl.app +import android.util.Log import android.view.InputDevice import android.view.MotionEvent import android.view.View @@ -13,21 +14,23 @@ interface SDLOnTouchListener: View.OnTouchListener { var mHeight: Float fun onNativeMouse(button: Int, action: Int, x: Float, y: Float) - fun onNativeTouch(touchDevId: Int, pointerFingerId: Int, action: Int, x: Float, y: Float, p: Float) + fun onNativeTouch(touchDevId: Int, pointerFingerId: Int, action: Int, x: Float, y: Float, p: Float, t: Long) // Touch events override fun onTouch(v: View, event: MotionEvent): Boolean { /* Ref: http://developer.android.com/training/gestures/multi.html */ val touchDevId = event.deviceId val action = event.actionMasked + val time = event.eventTime + data class TouchValues(val fingerId: Int, val x: Float, val y: Float, val p: Float) fun MotionEvent.touchValues(i: Int): TouchValues { return TouchValues( getPointerId(i), - getX(i) / mWidth, - getY(i) / mHeight, + getX(i), + getY(i), // Pressure can be > 1.0 on some devices. See getPressure(i) docs. min(this.getPressure(i), 1.0f) ) @@ -43,25 +46,25 @@ interface SDLOnTouchListener: View.OnTouchListener { MotionEvent.ACTION_MOVE -> { for (i in 0 until event.pointerCount) { val (fingerId, x, y, p) = event.touchValues(i) - this.onNativeTouch(touchDevId, fingerId, action, x, y, p) + this.onNativeTouch(touchDevId, fingerId, action, x, y, p, time) } } MotionEvent.ACTION_UP, MotionEvent.ACTION_DOWN -> { // Primary pointer up/down, the index is always zero val (fingerId, x, y, p) = event.touchValues(event.actionIndex) - this.onNativeTouch(touchDevId, fingerId, action, x, y, p) + this.onNativeTouch(touchDevId, fingerId, action, x, y, p, time) } MotionEvent.ACTION_POINTER_UP, MotionEvent.ACTION_POINTER_DOWN -> { val (fingerId, x, y, p) = event.touchValues(event.actionIndex) - this.onNativeTouch(touchDevId, fingerId, action, x, y, p) + this.onNativeTouch(touchDevId, fingerId, action, x, y, p, time) } MotionEvent.ACTION_CANCEL -> { for (i in 0 until event.pointerCount) { val (fingerId, x, y, p) = event.touchValues(i) - this.onNativeTouch(touchDevId, fingerId, MotionEvent.ACTION_UP, x, y, p) + this.onNativeTouch(touchDevId, fingerId, MotionEvent.ACTION_UP, x, y, p, time) } } } From a8d0a352da955f9d0a0358c98dcb265f26316f85 Mon Sep 17 00:00:00 2001 From: Janek Szynal Date: Wed, 5 Sep 2018 18:35:29 +0200 Subject: [PATCH 02/18] changed timestamp to Double in Kotlin, removed unused func in GLRenderer --- Sources/GLRenderer.swift | 10 ---------- Sources/UIApplication+handleSDLEvents.swift | 11 ++++------- Sources/UIWindow+TouchHandling.swift | 4 ++-- src/main/java/org/libsdl/app/SDLActivity.kt | 2 +- src/main/java/org/libsdl/app/SDLOnTouchListener.kt | 4 ++-- 5 files changed, 9 insertions(+), 22 deletions(-) diff --git a/Sources/GLRenderer.swift b/Sources/GLRenderer.swift index 2217ee3f..5d5cada0 100644 --- a/Sources/GLRenderer.swift +++ b/Sources/GLRenderer.swift @@ -76,16 +76,6 @@ internal final class GLRenderer { clearErrors() // by now we have handled any errors we might have wanted to } - func absolutePointInOwnCoordinates(x inputX: CGFloat, y inputY: CGFloat) -> CGPoint { -// #if os(macOS) - // Here SDL scales our touch events for us, which means we need a special case for it: - return CGPoint(x: inputX, y: inputY) -// #else -// // On all other platforms, we scale the touch events to the screen size manually: -// return CGPoint(x: inputX / scale, y: inputY / scale) -// #endif - } - func blit( _ image: CGImage, anchorPoint: CGPoint, diff --git a/Sources/UIApplication+handleSDLEvents.swift b/Sources/UIApplication+handleSDLEvents.swift index ae318b72..96b524e0 100644 --- a/Sources/UIApplication+handleSDLEvents.swift +++ b/Sources/UIApplication+handleSDLEvents.swift @@ -141,10 +141,9 @@ extension UIEvent { let matchingTouch = firstExistingEvent.allTouches?.first(where: { $0.touchId == event.tfinger.fingerId} ) { - matchingTouch.updateAbsoluteLocation(.from(event.tfinger)) matchingTouch.timestamp = event.timestampInSeconds matchingTouch.phase = .moved - + matchingTouch.updateAbsoluteLocation(.from(event.tfinger)) return firstExistingEvent } else { @@ -156,8 +155,8 @@ extension UIEvent { let firstExistingEvent = UIEvent.activeEvents.first, let matchingTouch = firstExistingEvent.allTouches?.first(where: {$0.touchId == event.tfinger.fingerId} ) { - matchingTouch.phase = .ended matchingTouch.timestamp = event.timestampInSeconds + matchingTouch.phase = .ended return firstExistingEvent } else { return nil @@ -194,17 +193,15 @@ import JNI @_silgen_name("Java_org_libsdl_app_SDLActivity_onNativeTouch") public func Java_org_libsdl_app_SDLActivity_onNativeTouch(env: UnsafeMutablePointer, view: JavaObject, touchDeviceID: JavaInt, pointerFingerID: JavaInt, action: JavaInt, - x: JavaFloat, y: JavaFloat, pressure: JavaFloat, timestamp: JavaLong) { + x: JavaFloat, y: JavaFloat, pressure: JavaFloat, timestamp: JavaDouble) { guard let eventType = SDL_EventType.eventFrom(androidAction: action) else {return} - let timestamp = JavaLong(littleEndian: timestamp) - let timestamp32B = UInt32(timestamp & Int64(UInt32.max)) var event = SDL_Event(tfinger: SDL_TouchFingerEvent( type: eventType.rawValue, - timestamp: timestamp32B, // ensure this is in ms + timestamp: UInt32(timestamp), //TODO: change to timestamp // (ensure this is in ms?) touchId: Int64(touchDeviceID), // I think this is the "Touch Device ID" which should always be 0, but check this fingerId: Int64(pointerFingerID), x: x / Float(UIScreen.main.scale), diff --git a/Sources/UIWindow+TouchHandling.swift b/Sources/UIWindow+TouchHandling.swift index 5f5d06a4..33b19012 100644 --- a/Sources/UIWindow+TouchHandling.swift +++ b/Sources/UIWindow+TouchHandling.swift @@ -17,10 +17,10 @@ extension SDL_MouseMotionEvent: SDLEventWithCoordinates {} extension CGPoint { static func from(_ event: SDLEventWithCoordinates) -> CGPoint { - return UIApplication.shared.glRenderer.absolutePointInOwnCoordinates(x: CGFloat(event.x), y: CGFloat(event.y)) + return CGPoint(x: CGFloat(event.x), y: CGFloat(event.y)) } static func from(_ event: SDL_TouchFingerEvent) -> CGPoint { - return UIApplication.shared.glRenderer.absolutePointInOwnCoordinates(x: CGFloat(event.x), y: CGFloat(event.y)) + return CGPoint(x: CGFloat(event.x), y: CGFloat(event.y)) } } diff --git a/src/main/java/org/libsdl/app/SDLActivity.kt b/src/main/java/org/libsdl/app/SDLActivity.kt index 46f3a77a..09c4fb05 100644 --- a/src/main/java/org/libsdl/app/SDLActivity.kt +++ b/src/main/java/org/libsdl/app/SDLActivity.kt @@ -58,7 +58,7 @@ open class SDLActivity internal constructor (context: Context?) : RelativeLayout // SDLOnTouchListener conformance external override fun onNativeMouse(button: Int, action: Int, x: Float, y: Float) - external override fun onNativeTouch(touchDevId: Int, pointerFingerId: Int, action: Int, x: Float, y: Float, p: Float, t: Long) + external override fun onNativeTouch(touchDevId: Int, pointerFingerId: Int, action: Int, x: Float, y: Float, p: Float, t: Double) override var mWidth: Float = 1.0f // Keep track of the surface size to normalize touch events override var mHeight: Float = 1.0f // Start with non-zero values to avoid potential division by zero diff --git a/src/main/java/org/libsdl/app/SDLOnTouchListener.kt b/src/main/java/org/libsdl/app/SDLOnTouchListener.kt index 2c3bcae2..3a85a0a1 100644 --- a/src/main/java/org/libsdl/app/SDLOnTouchListener.kt +++ b/src/main/java/org/libsdl/app/SDLOnTouchListener.kt @@ -14,14 +14,14 @@ interface SDLOnTouchListener: View.OnTouchListener { var mHeight: Float fun onNativeMouse(button: Int, action: Int, x: Float, y: Float) - fun onNativeTouch(touchDevId: Int, pointerFingerId: Int, action: Int, x: Float, y: Float, p: Float, t: Long) + fun onNativeTouch(touchDevId: Int, pointerFingerId: Int, action: Int, x: Float, y: Float, p: Float, t: Double) // Touch events override fun onTouch(v: View, event: MotionEvent): Boolean { /* Ref: http://developer.android.com/training/gestures/multi.html */ val touchDevId = event.deviceId val action = event.actionMasked - val time = event.eventTime + val time = event.eventTime.toDouble() data class TouchValues(val fingerId: Int, val x: Float, val y: Float, val p: Float) From 96ca5e5d09cf1ff5d91329827faf308cba5f8e5c Mon Sep 17 00:00:00 2001 From: Janek Szynal Date: Wed, 5 Sep 2018 18:47:28 +0200 Subject: [PATCH 03/18] cosmetics - removed some comments, removed a typo --- Sources/UIApplication+handleSDLEvents.swift | 3 +-- Sources/UIWindow.swift | 3 +-- src/main/java/org/libsdl/app/SDLActivity.kt | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Sources/UIApplication+handleSDLEvents.swift b/Sources/UIApplication+handleSDLEvents.swift index 96b524e0..52c601c2 100644 --- a/Sources/UIApplication+handleSDLEvents.swift +++ b/Sources/UIApplication+handleSDLEvents.swift @@ -54,7 +54,6 @@ extension UIApplication { let event = UIEvent.activeEvents.first, let touch = event.allTouches?.first(where: { $0.touchId == Int(0) } ) { - print("Mouseup with active events \(UIEvent.activeEvents.count)") touch.timestamp = e.timestampInSeconds touch.phase = .ended sendEvent(event) @@ -201,7 +200,7 @@ public func Java_org_libsdl_app_SDLActivity_onNativeTouch(env: UnsafeMutablePoin var event = SDL_Event(tfinger: SDL_TouchFingerEvent( type: eventType.rawValue, - timestamp: UInt32(timestamp), //TODO: change to timestamp // (ensure this is in ms?) + timestamp: UInt32(timestamp), // ensure this is in ms touchId: Int64(touchDeviceID), // I think this is the "Touch Device ID" which should always be 0, but check this fingerId: Int64(pointerFingerID), x: x / Float(UIScreen.main.scale), diff --git a/Sources/UIWindow.swift b/Sources/UIWindow.swift index ceffd2b4..0a8183d6 100644 --- a/Sources/UIWindow.swift +++ b/Sources/UIWindow.swift @@ -36,7 +36,7 @@ public class UIWindow: UIView { UIEvent.activeEvents.insert(event) currentTouch.view = hitView currentTouch.gestureRecognizers = hitView.getRecognizerHierachy() - print("recognizers: \(currentTouch.gestureRecognizers)" ) + currentTouch.runTouchActionOnRecognizerHierachy { $0.touchesBegan(allTouches, with: event) } hitView.touchesBegan(allTouches, with: event) @@ -53,7 +53,6 @@ public class UIWindow: UIView { } UIEvent.activeEvents.remove(event) - print("After removing, left with \(UIEvent.activeEvents.count) active events") } } } diff --git a/src/main/java/org/libsdl/app/SDLActivity.kt b/src/main/java/org/libsdl/app/SDLActivity.kt index 09c4fb05..07c728ed 100644 --- a/src/main/java/org/libsdl/app/SDLActivity.kt +++ b/src/main/java/org/libsdl/app/SDLActivity.kt @@ -40,7 +40,7 @@ open class SDLActivity internal constructor (context: Context?) : RelativeLayout } private var mSurface: SurfaceView - private var mIsSurfaceReady = false/**/ + private var mIsSurfaceReady = false private var mHasFocus = false private external fun nativeRender() From 3c026ecaf53ee9568934f04360de9d666edb5440 Mon Sep 17 00:00:00 2001 From: Janek Szynal Date: Wed, 5 Sep 2018 19:28:42 +0200 Subject: [PATCH 04/18] removed some whitespaces --- Sources/UIApplication+handleSDLEvents.swift | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Sources/UIApplication+handleSDLEvents.swift b/Sources/UIApplication+handleSDLEvents.swift index 52c601c2..ad83951c 100644 --- a/Sources/UIApplication+handleSDLEvents.swift +++ b/Sources/UIApplication+handleSDLEvents.swift @@ -22,7 +22,6 @@ extension UIApplication { } #endif - switch SDL_EventType(rawValue: e.type) { case SDL_QUIT: handleSDLQuit() @@ -108,8 +107,6 @@ extension SDL_Event { extension UIEvent { - - static func from(_ event: SDL_Event) -> UIEvent? { switch SDL_EventType(event.type) { case SDL_FINGERDOWN: @@ -188,7 +185,6 @@ extension UITouch: CustomStringConvertible { #if os(Android) import JNI - @_silgen_name("Java_org_libsdl_app_SDLActivity_onNativeTouch") public func Java_org_libsdl_app_SDLActivity_onNativeTouch(env: UnsafeMutablePointer, view: JavaObject, touchDeviceID: JavaInt, pointerFingerID: JavaInt, action: JavaInt, @@ -216,7 +212,6 @@ public func Java_org_libsdl_app_SDLActivity_onNativeTouch(env: UnsafeMutablePoin SDL_PeepEvents(&event, 1, SDL_ADDEVENT, 0, 0) } - extension SDL_EventType { public static func eventFrom(androidAction: JavaInt) -> SDL_EventType? { switch androidAction { @@ -229,6 +224,3 @@ extension SDL_EventType { } #endif - - - From d6b8453c324797436ad4a7c9f22a2fff0034d247 Mon Sep 17 00:00:00 2001 From: Janek Szynal Date: Fri, 7 Sep 2018 16:59:17 +0200 Subject: [PATCH 05/18] retuned hand-made velocity factor from 0.75 to 0.4 --- Sources/UIScrollView+velocity.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/UIScrollView+velocity.swift b/Sources/UIScrollView+velocity.swift index 2f2d346c..4999484b 100644 --- a/Sources/UIScrollView+velocity.swift +++ b/Sources/UIScrollView+velocity.swift @@ -20,7 +20,7 @@ extension UIScrollView { // Otherwise we could animate after scrolling quickly, pausing for a few seconds, then letting go let velocityIsLargeEnoughToDecelerate = (self.panGestureRecognizer.velocity(in: self).magnitude > 10) - let nonBoundsCheckedScrollAnimationDistance = self.weightedAverageVelocity * 0.74 // hand-tuned + let nonBoundsCheckedScrollAnimationDistance = self.weightedAverageVelocity * 0.4 // hand-tuned let targetOffset = getBoundsCheckedContentOffset(contentOffset - nonBoundsCheckedScrollAnimationDistance) let distanceToBoundsCheckedTarget = contentOffset - targetOffset From 962bcca5ef8a4261559d529f39970ad8ec883912 Mon Sep 17 00:00:00 2001 From: rikner Date: Tue, 16 Oct 2018 14:10:10 +0200 Subject: [PATCH 06/18] pass timestamp as Long instead of Double, use @_cdecl for onNativeTouch --- Sources/UIApplication+handleSDLEvents.swift | 21 ++++++++++++------- src/main/java/org/libsdl/app/SDLActivity.kt | 2 +- .../java/org/libsdl/app/SDLOnTouchListener.kt | 4 ++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Sources/UIApplication+handleSDLEvents.swift b/Sources/UIApplication+handleSDLEvents.swift index ad83951c..af2f0eff 100644 --- a/Sources/UIApplication+handleSDLEvents.swift +++ b/Sources/UIApplication+handleSDLEvents.swift @@ -185,13 +185,20 @@ extension UITouch: CustomStringConvertible { #if os(Android) import JNI -@_silgen_name("Java_org_libsdl_app_SDLActivity_onNativeTouch") -public func Java_org_libsdl_app_SDLActivity_onNativeTouch(env: UnsafeMutablePointer, view: JavaObject, - touchDeviceID: JavaInt, pointerFingerID: JavaInt, action: JavaInt, - x: JavaFloat, y: JavaFloat, pressure: JavaFloat, timestamp: JavaDouble) { - - guard let eventType = SDL_EventType.eventFrom(androidAction: action) else {return} - +@_cdecl("Java_org_libsdl_app_SDLActivity_onNativeTouch") +public func Java_org_libsdl_app_SDLActivity_onNativeTouch( + env: UnsafeMutablePointer, + view: JavaObject, + touchDeviceID: JavaInt, + pointerFingerID: JavaInt, + action: JavaInt, + x: JavaFloat, + y: JavaFloat, + pressure: JavaFloat, + timestamp: JavaLong +) { + guard let eventType = SDL_EventType.eventFrom(androidAction: action) + else { return } var event = SDL_Event(tfinger: SDL_TouchFingerEvent( diff --git a/src/main/java/org/libsdl/app/SDLActivity.kt b/src/main/java/org/libsdl/app/SDLActivity.kt index 07c728ed..491291a1 100644 --- a/src/main/java/org/libsdl/app/SDLActivity.kt +++ b/src/main/java/org/libsdl/app/SDLActivity.kt @@ -58,7 +58,7 @@ open class SDLActivity internal constructor (context: Context?) : RelativeLayout // SDLOnTouchListener conformance external override fun onNativeMouse(button: Int, action: Int, x: Float, y: Float) - external override fun onNativeTouch(touchDevId: Int, pointerFingerId: Int, action: Int, x: Float, y: Float, p: Float, t: Double) + external override fun onNativeTouch(touchDevId: Int, pointerFingerId: Int, action: Int, x: Float, y: Float, p: Float, t: Long) override var mWidth: Float = 1.0f // Keep track of the surface size to normalize touch events override var mHeight: Float = 1.0f // Start with non-zero values to avoid potential division by zero diff --git a/src/main/java/org/libsdl/app/SDLOnTouchListener.kt b/src/main/java/org/libsdl/app/SDLOnTouchListener.kt index 3a85a0a1..03b10bf2 100644 --- a/src/main/java/org/libsdl/app/SDLOnTouchListener.kt +++ b/src/main/java/org/libsdl/app/SDLOnTouchListener.kt @@ -14,15 +14,15 @@ interface SDLOnTouchListener: View.OnTouchListener { var mHeight: Float fun onNativeMouse(button: Int, action: Int, x: Float, y: Float) - fun onNativeTouch(touchDevId: Int, pointerFingerId: Int, action: Int, x: Float, y: Float, p: Float, t: Double) + fun onNativeTouch(touchDevId: Int, pointerFingerId: Int, action: Int, x: Float, y: Float, p: Float, t: Long) // Touch events override fun onTouch(v: View, event: MotionEvent): Boolean { /* Ref: http://developer.android.com/training/gestures/multi.html */ val touchDevId = event.deviceId val action = event.actionMasked - val time = event.eventTime.toDouble() + val time = event.eventTime data class TouchValues(val fingerId: Int, val x: Float, val y: Float, val p: Float) From 47e5c5811d397be9337f0ec523fa3a96afc1a254 Mon Sep 17 00:00:00 2001 From: rikner Date: Thu, 18 Oct 2018 16:20:30 +0200 Subject: [PATCH 07/18] move TouchValues data class and MotionEvent extension declaration to top-level --- .../java/org/libsdl/app/SDLOnTouchListener.kt | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/libsdl/app/SDLOnTouchListener.kt b/src/main/java/org/libsdl/app/SDLOnTouchListener.kt index 03b10bf2..a7df0dc1 100644 --- a/src/main/java/org/libsdl/app/SDLOnTouchListener.kt +++ b/src/main/java/org/libsdl/app/SDLOnTouchListener.kt @@ -8,6 +8,18 @@ import org.libsdl.app.SDLActivity import kotlin.math.min +private data class TouchValues(val fingerId: Int, val x: Float, val y: Float, val p: Float) + +private fun MotionEvent.touchValues(i: Int): TouchValues { + return TouchValues( + getPointerId(i), + getX(i), + getY(i), + // Pressure can be > 1.0 on some devices. See getPressure(i) docs. + min(this.getPressure(i), 1.0f) + ) +} + interface SDLOnTouchListener: View.OnTouchListener { var mWidth: Float @@ -24,18 +36,6 @@ interface SDLOnTouchListener: View.OnTouchListener { val time = event.eventTime - data class TouchValues(val fingerId: Int, val x: Float, val y: Float, val p: Float) - - fun MotionEvent.touchValues(i: Int): TouchValues { - return TouchValues( - getPointerId(i), - getX(i), - getY(i), - // Pressure can be > 1.0 on some devices. See getPressure(i) docs. - min(this.getPressure(i), 1.0f) - ) - } - if (event.source == InputDevice.SOURCE_MOUSE && SDLActivity.mSeparateMouseAndTouch) { val mouseButton = try { event.buttonState } catch (e: Exception) { 1 } // 1 is left button this.onNativeMouse(mouseButton, action, event.getX(0), event.getY(0)) From 24c4364ba7c845877cf08393393bac4219d14d00 Mon Sep 17 00:00:00 2001 From: rikner Date: Thu, 18 Oct 2018 16:33:50 +0200 Subject: [PATCH 08/18] update SDL (onNativeTouch removed) --- SDL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDL b/SDL index cde44443..1626a23c 160000 --- a/SDL +++ b/SDL @@ -1 +1 @@ -Subproject commit cde44443ff9c09cd9c4538751f1f8bf96c0e3936 +Subproject commit 1626a23c18955780549cd202d2ea7e7d66a0e5b6 From 95633dcfb04c8212badfab9b95a015ddfd1e3e04 Mon Sep 17 00:00:00 2001 From: rikner Date: Thu, 18 Oct 2018 17:49:33 +0200 Subject: [PATCH 09/18] cleanup SDLOnTouchListener: rename p to pressure, rename time to timestamp, move MotionEvent to bottom, merge switch cases, --- .../java/org/libsdl/app/SDLOnTouchListener.kt | 54 +++++++++---------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/libsdl/app/SDLOnTouchListener.kt b/src/main/java/org/libsdl/app/SDLOnTouchListener.kt index a7df0dc1..aa7208b3 100644 --- a/src/main/java/org/libsdl/app/SDLOnTouchListener.kt +++ b/src/main/java/org/libsdl/app/SDLOnTouchListener.kt @@ -1,6 +1,5 @@ package main.java.org.libsdl.app -import android.util.Log import android.view.InputDevice import android.view.MotionEvent import android.view.View @@ -8,18 +7,6 @@ import org.libsdl.app.SDLActivity import kotlin.math.min -private data class TouchValues(val fingerId: Int, val x: Float, val y: Float, val p: Float) - -private fun MotionEvent.touchValues(i: Int): TouchValues { - return TouchValues( - getPointerId(i), - getX(i), - getY(i), - // Pressure can be > 1.0 on some devices. See getPressure(i) docs. - min(this.getPressure(i), 1.0f) - ) -} - interface SDLOnTouchListener: View.OnTouchListener { var mWidth: Float @@ -33,8 +20,7 @@ interface SDLOnTouchListener: View.OnTouchListener { /* Ref: http://developer.android.com/training/gestures/multi.html */ val touchDevId = event.deviceId val action = event.actionMasked - - val time = event.eventTime + val timestamp = event.eventTime if (event.source == InputDevice.SOURCE_MOUSE && SDLActivity.mSeparateMouseAndTouch) { val mouseButton = try { event.buttonState } catch (e: Exception) { 1 } // 1 is left button @@ -45,30 +31,40 @@ interface SDLOnTouchListener: View.OnTouchListener { when (action) { MotionEvent.ACTION_MOVE -> { for (i in 0 until event.pointerCount) { - val (fingerId, x, y, p) = event.touchValues(i) - this.onNativeTouch(touchDevId, fingerId, action, x, y, p, time) + val (fingerId, x, y, pressure) = event.touchValues(i) + this.onNativeTouch(touchDevId, fingerId, action, x, y, pressure, timestamp) } } - MotionEvent.ACTION_UP, MotionEvent.ACTION_DOWN -> { - // Primary pointer up/down, the index is always zero - val (fingerId, x, y, p) = event.touchValues(event.actionIndex) - this.onNativeTouch(touchDevId, fingerId, action, x, y, p, time) - } - - MotionEvent.ACTION_POINTER_UP, MotionEvent.ACTION_POINTER_DOWN -> { - val (fingerId, x, y, p) = event.touchValues(event.actionIndex) - this.onNativeTouch(touchDevId, fingerId, action, x, y, p, time) + MotionEvent.ACTION_UP, + MotionEvent.ACTION_DOWN, + MotionEvent.ACTION_POINTER_UP, + MotionEvent.ACTION_POINTER_DOWN -> { + val (fingerId, x, y, pressure) = event.touchValues(event.actionIndex) + this.onNativeTouch(touchDevId, fingerId, action, x, y, pressure, timestamp) } MotionEvent.ACTION_CANCEL -> { for (i in 0 until event.pointerCount) { - val (fingerId, x, y, p) = event.touchValues(i) - this.onNativeTouch(touchDevId, fingerId, MotionEvent.ACTION_UP, x, y, p, time) + val (fingerId, x, y, pressure) = event.touchValues(i) + this.onNativeTouch(touchDevId, fingerId, MotionEvent.ACTION_UP, x, y, pressure, timestamp) } } } return true } -} \ No newline at end of file +} + + +private data class TouchValues(val fingerId: Int, val x: Float, val y: Float, val pressure: Float) + +private fun MotionEvent.touchValues(i: Int): TouchValues { + return TouchValues( + getPointerId(i), + getX(i), + getY(i), + // Pressure can be > 1.0 on some devices. See getPressure(i) docs. + min(this.getPressure(i), 1.0f) + ) +} From 23b73b313e36cd4cf5c53da877c30b86e545685b Mon Sep 17 00:00:00 2001 From: rikner Date: Fri, 26 Oct 2018 11:04:44 +0200 Subject: [PATCH 10/18] return to SDL master (not removing onNativeTouch) --- SDL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDL b/SDL index 1626a23c..cde44443 160000 --- a/SDL +++ b/SDL @@ -1 +1 @@ -Subproject commit 1626a23c18955780549cd202d2ea7e7d66a0e5b6 +Subproject commit cde44443ff9c09cd9c4538751f1f8bf96c0e3936 From 3a84c6bb45882f6954fb89fe015fd45989600fc0 Mon Sep 17 00:00:00 2001 From: rikner Date: Fri, 26 Oct 2018 12:13:20 +0200 Subject: [PATCH 11/18] rename onNativeTouch to onNativeTouchUIKit to prevent conflict with SDL implementation --- Sources/UIApplication+handleSDLEvents.swift | 4 ++-- src/main/java/org/libsdl/app/SDLActivity.kt | 2 +- src/main/java/org/libsdl/app/SDLOnTouchListener.kt | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/UIApplication+handleSDLEvents.swift b/Sources/UIApplication+handleSDLEvents.swift index af2f0eff..023ff9e6 100644 --- a/Sources/UIApplication+handleSDLEvents.swift +++ b/Sources/UIApplication+handleSDLEvents.swift @@ -185,8 +185,8 @@ extension UITouch: CustomStringConvertible { #if os(Android) import JNI -@_cdecl("Java_org_libsdl_app_SDLActivity_onNativeTouch") -public func Java_org_libsdl_app_SDLActivity_onNativeTouch( +@_cdecl("Java_org_libsdl_app_SDLActivity_onNativeTouchUIKit") +public func onNativeTouch( env: UnsafeMutablePointer, view: JavaObject, touchDeviceID: JavaInt, diff --git a/src/main/java/org/libsdl/app/SDLActivity.kt b/src/main/java/org/libsdl/app/SDLActivity.kt index 491291a1..524a354d 100644 --- a/src/main/java/org/libsdl/app/SDLActivity.kt +++ b/src/main/java/org/libsdl/app/SDLActivity.kt @@ -58,7 +58,7 @@ open class SDLActivity internal constructor (context: Context?) : RelativeLayout // SDLOnTouchListener conformance external override fun onNativeMouse(button: Int, action: Int, x: Float, y: Float) - external override fun onNativeTouch(touchDevId: Int, pointerFingerId: Int, action: Int, x: Float, y: Float, p: Float, t: Long) + external override fun onNativeTouchUIKit(touchDevId: Int, pointerFingerId: Int, action: Int, x: Float, y: Float, p: Float, t: Long) override var mWidth: Float = 1.0f // Keep track of the surface size to normalize touch events override var mHeight: Float = 1.0f // Start with non-zero values to avoid potential division by zero diff --git a/src/main/java/org/libsdl/app/SDLOnTouchListener.kt b/src/main/java/org/libsdl/app/SDLOnTouchListener.kt index aa7208b3..61650c83 100644 --- a/src/main/java/org/libsdl/app/SDLOnTouchListener.kt +++ b/src/main/java/org/libsdl/app/SDLOnTouchListener.kt @@ -13,7 +13,7 @@ interface SDLOnTouchListener: View.OnTouchListener { var mHeight: Float fun onNativeMouse(button: Int, action: Int, x: Float, y: Float) - fun onNativeTouch(touchDevId: Int, pointerFingerId: Int, action: Int, x: Float, y: Float, p: Float, t: Long) + fun onNativeTouchUIKit(touchDevId: Int, pointerFingerId: Int, action: Int, x: Float, y: Float, p: Float, t: Long) // Touch events override fun onTouch(v: View, event: MotionEvent): Boolean { @@ -32,7 +32,7 @@ interface SDLOnTouchListener: View.OnTouchListener { MotionEvent.ACTION_MOVE -> { for (i in 0 until event.pointerCount) { val (fingerId, x, y, pressure) = event.touchValues(i) - this.onNativeTouch(touchDevId, fingerId, action, x, y, pressure, timestamp) + this.onNativeTouchUIKit(touchDevId, fingerId, action, x, y, pressure, timestamp) } } @@ -41,13 +41,13 @@ interface SDLOnTouchListener: View.OnTouchListener { MotionEvent.ACTION_POINTER_UP, MotionEvent.ACTION_POINTER_DOWN -> { val (fingerId, x, y, pressure) = event.touchValues(event.actionIndex) - this.onNativeTouch(touchDevId, fingerId, action, x, y, pressure, timestamp) + this.onNativeTouchUIKit(touchDevId, fingerId, action, x, y, pressure, timestamp) } MotionEvent.ACTION_CANCEL -> { for (i in 0 until event.pointerCount) { val (fingerId, x, y, pressure) = event.touchValues(i) - this.onNativeTouch(touchDevId, fingerId, MotionEvent.ACTION_UP, x, y, pressure, timestamp) + this.onNativeTouchUIKit(touchDevId, fingerId, MotionEvent.ACTION_UP, x, y, pressure, timestamp) } } } From bb665c5389a667a14c7be8abfe7b0398cb757224 Mon Sep 17 00:00:00 2001 From: Michael Knoch Date: Wed, 31 Oct 2018 14:28:04 +0100 Subject: [PATCH 12/18] check for os(Android) instead of !os(macOS) Co-Authored-By: rikner --- Sources/UIApplication+handleSDLEvents.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/UIApplication+handleSDLEvents.swift b/Sources/UIApplication+handleSDLEvents.swift index 023ff9e6..9250796e 100644 --- a/Sources/UIApplication+handleSDLEvents.swift +++ b/Sources/UIApplication+handleSDLEvents.swift @@ -15,7 +15,7 @@ extension UIApplication { while SDL_PollEvent(&e) == 1 { - #if !os(macOS) + #if os(Android) if let uievent = UIEvent.from(e) { sendEvent(uievent) break From 03734543a52089906cbab33c948a3535b153fbe4 Mon Sep 17 00:00:00 2001 From: rikner Date: Wed, 31 Oct 2018 14:36:26 +0100 Subject: [PATCH 13/18] lint swift files --- Sources/UIApplication+handleSDLEvents.swift | 23 +++++++++------------ Sources/UIScrollView+velocity.swift | 17 +++++++++------ Sources/UIWindow+TouchHandling.swift | 1 - 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Sources/UIApplication+handleSDLEvents.swift b/Sources/UIApplication+handleSDLEvents.swift index cb7f9bb8..0b329eab 100644 --- a/Sources/UIApplication+handleSDLEvents.swift +++ b/Sources/UIApplication+handleSDLEvents.swift @@ -33,7 +33,7 @@ extension UIApplication { case SDL_MOUSEMOTION: if let event = UIEvent.activeEvents.first, - let touch = event.allTouches?.first(where: { $0.touchId == Int(0) } ) + let touch = event.allTouches?.first(where: { $0.touchId == Int(0) }) { let previousTimestamp = touch.timestamp let newTimestamp = e.timestampInSeconds @@ -51,7 +51,7 @@ extension UIApplication { case SDL_MOUSEBUTTONUP: if let event = UIEvent.activeEvents.first, - let touch = event.allTouches?.first(where: { $0.touchId == Int(0) } ) + let touch = event.allTouches?.first(where: { $0.touchId == Int(0) }) { touch.timestamp = e.timestampInSeconds touch.phase = .ended @@ -69,7 +69,6 @@ extension UIApplication { keyWindow?.printViewHierarchy() default: print(e.key.keysym.sym) - break } } @@ -141,7 +140,6 @@ extension SDL_Event { } } - extension UIEvent { static func from(_ event: SDL_Event) -> UIEvent? { switch SDL_EventType(event.type) { @@ -157,35 +155,34 @@ extension UIEvent { if let firstExistingEvent = UIEvent.activeEvents.first, - let _ = firstExistingEvent.allTouches?.first(where: {$0.touchId == event.tfinger.fingerId} ) + let _ = firstExistingEvent.allTouches?.first(where: {$0.touchId == event.tfinger.fingerId}) { - //found a matching event, adding current touch to it and returning + // Found a matching event, adding current touch to it and returning firstExistingEvent.allTouches?.insert(newTouch) return firstExistingEvent } else { - //no matching event found, creating a new one + // No matching event found, creating a new one return UIEvent(touch: newTouch) } case SDL_FINGERMOTION: if let firstExistingEvent = UIEvent.activeEvents.first, - let matchingTouch = firstExistingEvent.allTouches?.first(where: { $0.touchId == event.tfinger.fingerId} ) + let matchingTouch = firstExistingEvent.allTouches?.first(where: { $0.touchId == event.tfinger.fingerId}) { matchingTouch.timestamp = event.timestampInSeconds matchingTouch.phase = .moved matchingTouch.updateAbsoluteLocation(.from(event.tfinger)) return firstExistingEvent - } - else { + } else { return nil } case SDL_FINGERUP: if let firstExistingEvent = UIEvent.activeEvents.first, - let matchingTouch = firstExistingEvent.allTouches?.first(where: {$0.touchId == event.tfinger.fingerId} ) + let matchingTouch = firstExistingEvent.allTouches?.first(where: {$0.touchId == event.tfinger.fingerId}) { matchingTouch.timestamp = event.timestampInSeconds matchingTouch.phase = .ended @@ -229,11 +226,11 @@ public func onNativeTouch( pointerFingerID: JavaInt, action: JavaInt, x: JavaFloat, - y: JavaFloat, + y: JavaFloat, pressure: JavaFloat, timestamp: JavaLong ) { - guard let eventType = SDL_EventType.eventFrom(androidAction: action) + guard let eventType = SDL_EventType.eventFrom(androidAction: action) else { return } var event = SDL_Event(tfinger: diff --git a/Sources/UIScrollView+velocity.swift b/Sources/UIScrollView+velocity.swift index 4999484b..7719ca9c 100644 --- a/Sources/UIScrollView+velocity.swift +++ b/Sources/UIScrollView+velocity.swift @@ -37,12 +37,17 @@ extension UIScrollView { // This calculation is a weird approximation but it's close enough for now... let animationTime = log(Double(distanceToBoundsCheckedTarget.magnitude)) * animationTimeConstant - UIView.animate(withDuration: animationTime, options: [.beginFromCurrentState, .customEaseOut, .allowUserInteraction], animations: { - self.isDecelerating = true - self.contentOffset = targetOffset - }, completion: { _ in - self.isDecelerating = false - }) + UIView.animate( + withDuration: animationTime, + options: [.beginFromCurrentState, .customEaseOut, .allowUserInteraction], + animations: { + self.isDecelerating = true + self.contentOffset = targetOffset + }, + completion: { _ in + self.isDecelerating = false + } + ) } func cancelDeceleratingIfNeccessary() { diff --git a/Sources/UIWindow+TouchHandling.swift b/Sources/UIWindow+TouchHandling.swift index ad0892b6..d236b99a 100644 --- a/Sources/UIWindow+TouchHandling.swift +++ b/Sources/UIWindow+TouchHandling.swift @@ -14,7 +14,6 @@ protocol SDLEventWithCoordinates { extension SDL_MouseButtonEvent: SDLEventWithCoordinates {} extension SDL_MouseMotionEvent: SDLEventWithCoordinates {} - extension CGPoint { static func from(_ event: SDLEventWithCoordinates) -> CGPoint { return UIScreen.main.absolutePointInOwnCoordinates(x: CGFloat(event.x), y: CGFloat(event.y)) From 13ef5590462945b107056b2d390a09d2d76301b3 Mon Sep 17 00:00:00 2001 From: rikner Date: Wed, 31 Oct 2018 15:15:51 +0100 Subject: [PATCH 14/18] refactor UIEvent.description using map() --- Sources/UIApplication+handleSDLEvents.swift | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Sources/UIApplication+handleSDLEvents.swift b/Sources/UIApplication+handleSDLEvents.swift index cf7a51dd..470920b8 100644 --- a/Sources/UIApplication+handleSDLEvents.swift +++ b/Sources/UIApplication+handleSDLEvents.swift @@ -168,7 +168,7 @@ extension UIEvent { case SDL_FINGERMOTION: if let firstExistingEvent = UIEvent.activeEvents.first, - let matchingTouch = firstExistingEvent.allTouches?.first(where: { $0.touchId == event.tfinger.fingerId}) + let matchingTouch = firstExistingEvent.allTouches?.first(where: {$0.touchId == event.tfinger.fingerId}) { matchingTouch.timestamp = event.timestampInSeconds @@ -199,13 +199,12 @@ extension UIEvent { extension UIEvent: CustomStringConvertible { public var description: String { - var listOfTouches = "" - if let touches = allTouches { - for touch in touches { - listOfTouches += "\(touch.description),\n" - } + let text = "Event with touches: " + guard let allTouches = self.allTouches else { + return text + "none" } - return "Event with touches: \(listOfTouches)" + let descriptions = allTouches.map { $0.description } + return text + descriptions.joined(separator: ",\n") } } From 9a847e9c7bb2da146f72b69a87bc8e4175ee6a24 Mon Sep 17 00:00:00 2001 From: rikner Date: Wed, 7 Nov 2018 13:38:30 +0100 Subject: [PATCH 15/18] update to SDL version ignoring .DS_Store --- SDL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDL b/SDL index cde44443..9cdeedb7 160000 --- a/SDL +++ b/SDL @@ -1 +1 @@ -Subproject commit cde44443ff9c09cd9c4538751f1f8bf96c0e3936 +Subproject commit 9cdeedb713f959ed6192cf5209b609d5cfa88be1 From c2bd7422cfc2fa1db04833690705da8c09e8ae06 Mon Sep 17 00:00:00 2001 From: rikner Date: Mon, 4 Mar 2019 15:29:44 +0100 Subject: [PATCH 16/18] tune UIScrollView deceleration timing (as seen in b6c6d5a) --- Sources/UIScrollView+velocity.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Sources/UIScrollView+velocity.swift b/Sources/UIScrollView+velocity.swift index 7719ca9c..418b3c87 100644 --- a/Sources/UIScrollView+velocity.swift +++ b/Sources/UIScrollView+velocity.swift @@ -7,6 +7,7 @@ // import func Foundation.sqrt +import func Foundation.log private extension CGPoint { var magnitude: CGFloat { @@ -20,7 +21,8 @@ extension UIScrollView { // Otherwise we could animate after scrolling quickly, pausing for a few seconds, then letting go let velocityIsLargeEnoughToDecelerate = (self.panGestureRecognizer.velocity(in: self).magnitude > 10) - let nonBoundsCheckedScrollAnimationDistance = self.weightedAverageVelocity * 0.4 // hand-tuned + let dampingFactor: CGFloat = 0.55 // hand-tuned + let nonBoundsCheckedScrollAnimationDistance = self.weightedAverageVelocity * dampingFactor // hand-tuned let targetOffset = getBoundsCheckedContentOffset(contentOffset - nonBoundsCheckedScrollAnimationDistance) let distanceToBoundsCheckedTarget = contentOffset - targetOffset @@ -32,13 +34,13 @@ extension UIScrollView { // TODO: This value should be calculated from `self.decelerationRate` instead // But actually we want to redo this function to avoid `UIView.animate` entirely, // in which case we wouldn't need an animationTime at all. - let animationTimeConstant = 0.325 / 2 + let animationTimeConstant = 0.325 * dampingFactor // This calculation is a weird approximation but it's close enough for now... - let animationTime = log(Double(distanceToBoundsCheckedTarget.magnitude)) * animationTimeConstant + let animationTime = log(distanceToBoundsCheckedTarget.magnitude) * animationTimeConstant UIView.animate( - withDuration: animationTime, + withDuration: Double(animationTime), options: [.beginFromCurrentState, .customEaseOut, .allowUserInteraction], animations: { self.isDecelerating = true From 28b4b71340a388d137e29b86860cf3b181154200 Mon Sep 17 00:00:00 2001 From: Geordie J Date: Mon, 5 Nov 2018 19:28:22 +0100 Subject: [PATCH 17/18] Fix multitouch --- Sources/UIApplication+handleSDLEvents.swift | 128 +------------------ Sources/UIEvent+fromSDL_Event.swift | 129 ++++++++++++++++++++ Sources/UIScrollView+velocity.swift | 2 +- Sources/UIWindow.swift | 49 ++++---- UIKit.xcodeproj/project.pbxproj | 14 +-- 5 files changed, 161 insertions(+), 161 deletions(-) create mode 100644 Sources/UIEvent+fromSDL_Event.swift diff --git a/Sources/UIApplication+handleSDLEvents.swift b/Sources/UIApplication+handleSDLEvents.swift index f9840451..d897754e 100644 --- a/Sources/UIApplication+handleSDLEvents.swift +++ b/Sources/UIApplication+handleSDLEvents.swift @@ -16,8 +16,8 @@ extension UIApplication { while SDL_PollEvent(&e) == 1 { #if os(Android) - if let uievent = UIEvent.from(e) { - sendEvent(uievent) + if let uiEvent = UIEvent.from(e) { + sendEvent(uiEvent) break } #endif @@ -150,127 +150,3 @@ extension SDL_Event { return TimeInterval(self.common.timestamp) / 1000 } } - -extension UIEvent { - static func from(_ event: SDL_Event) -> UIEvent? { - switch SDL_EventType(event.type) { - case SDL_FINGERDOWN: - let newTouch = UITouch( - touchId: Int(event.tfinger.fingerId), - at: CGPoint( - x: CGFloat(event.tfinger.x), - y: CGFloat(event.tfinger.y) - ), - timestamp: event.timestampInSeconds - ) - - if - let firstExistingEvent = UIEvent.activeEvents.first, - let _ = firstExistingEvent.allTouches?.first(where: {$0.touchId == event.tfinger.fingerId}) - { - // Found a matching event, adding current touch to it and returning - firstExistingEvent.allTouches?.insert(newTouch) - return firstExistingEvent - } else { - // No matching event found, creating a new one - return UIEvent(touch: newTouch) - } - - case SDL_FINGERMOTION: - if - let firstExistingEvent = UIEvent.activeEvents.first, - let matchingTouch = firstExistingEvent.allTouches?.first(where: {$0.touchId == event.tfinger.fingerId}) - { - - matchingTouch.timestamp = event.timestampInSeconds - matchingTouch.phase = .moved - matchingTouch.updateAbsoluteLocation(.from(event.tfinger)) - return firstExistingEvent - } else { - return nil - } - - case SDL_FINGERUP: - if - let firstExistingEvent = UIEvent.activeEvents.first, - let matchingTouch = firstExistingEvent.allTouches?.first(where: {$0.touchId == event.tfinger.fingerId}) - { - matchingTouch.timestamp = event.timestampInSeconds - matchingTouch.phase = .ended - return firstExistingEvent - } else { - return nil - } - - default: - return nil - } - } -} - -extension UIEvent: CustomStringConvertible { - public var description: String { - let text = "Event with touches: " - guard let allTouches = self.allTouches else { - return text + "none" - } - let descriptions = allTouches.map { $0.description } - return text + descriptions.joined(separator: ",\n") - } -} - -extension UITouch: CustomStringConvertible { - public var description: String { - return "TouchID: \(self.touchId), timestamp: \(self.timestamp)" - } -} - -#if os(Android) -import JNI - -@_cdecl("Java_org_libsdl_app_SDLActivity_onNativeTouchUIKit") -public func onNativeTouch( - env: UnsafeMutablePointer, - view: JavaObject, - touchDeviceID: JavaInt, - pointerFingerID: JavaInt, - action: JavaInt, - x: JavaFloat, - y: JavaFloat, - pressure: JavaFloat, - timestamp: JavaLong -) { - guard let eventType = SDL_EventType.eventFrom(androidAction: action) - else { return } - - var event = SDL_Event(tfinger: - SDL_TouchFingerEvent( - type: eventType.rawValue, - timestamp: UInt32(timestamp), // ensure this is in ms - touchId: Int64(touchDeviceID), // I think this is the "Touch Device ID" which should always be 0, but check this - fingerId: Int64(pointerFingerID), - x: x / Float(UIScreen.main.scale), - y: y / Float(UIScreen.main.scale), - dx: 0, - dy: 0, - pressure: pressure - ) - ) - - // add the event to SDL's event stack - // don't use SDL_PushEvent because it overrides `event.timestamp` with its own: - SDL_PeepEvents(&event, 1, SDL_ADDEVENT, 0, 0) -} - -extension SDL_EventType { - public static func eventFrom(androidAction: JavaInt) -> SDL_EventType? { - switch androidAction { - case 0, 5: return SDL_FINGERDOWN - case 1, 6: return SDL_FINGERUP - case 2: return SDL_FINGERMOTION - default: return nil - } - } -} - -#endif diff --git a/Sources/UIEvent+fromSDL_Event.swift b/Sources/UIEvent+fromSDL_Event.swift new file mode 100644 index 00000000..172b11d3 --- /dev/null +++ b/Sources/UIEvent+fromSDL_Event.swift @@ -0,0 +1,129 @@ +// +// UIEvent+fromSDL_Event.swift +// UIKit +// +// Created by Geordie Jay on 05.11.18. +// Copyright © 2018 flowkey. All rights reserved. +// + +#if os(Android) +import JNI +import SDL + +extension UIEvent { + static func from(_ event: SDL_Event) -> UIEvent? { + switch SDL_EventType(event.type) { + case SDL_FINGERDOWN: + let newTouch = UITouch( + touchId: Int(event.tfinger.fingerId), + at: CGPoint( + x: CGFloat(event.tfinger.x), + y: CGFloat(event.tfinger.y) + ), + timestamp: event.timestampInSeconds + ) + + guard let existingTouchEvent = UIEvent.activeEvents.first(where: { $0.allTouches != nil }) else { + return UIEvent(touch: newTouch) + } + + assert(!existingTouchEvent.allTouches!.contains(where: { $0.touchId == event.tfinger.fingerId }), + "The active event already has a touch with this fingerId, this should be impossible") + + existingTouchEvent.allTouches!.insert(newTouch) + return existingTouchEvent + + case SDL_FINGERMOTION: + if + let existingTouchEvent = UIEvent.activeEvents.first(where: { $0.allTouches != nil }), + let matchingTouch = existingTouchEvent.allTouches?.first(where: { $0.touchId == event.tfinger.fingerId }) + { + matchingTouch.timestamp = event.timestampInSeconds + matchingTouch.phase = .moved + matchingTouch.updateAbsoluteLocation(.from(event.tfinger)) + return existingTouchEvent + } else { + assertionFailure("Got a motion event for a touch we know nothing about") + return nil + } + + case SDL_FINGERUP: + if + let firstExistingEvent = UIEvent.activeEvents.first(where: { $0.allTouches != nil }), + let matchingTouch = firstExistingEvent.allTouches?.first(where: { $0.touchId == event.tfinger.fingerId }) + { + matchingTouch.timestamp = event.timestampInSeconds + matchingTouch.phase = .ended + return firstExistingEvent + } else { + assertionFailure("Got a finger up event for a touch we know nothing about") + return nil + } + + default: + return nil + } + } +} + +extension UIEvent: CustomStringConvertible { + public var description: String { + let baseText = "UIEvent:" + guard let allTouches = self.allTouches else { + return baseText + " no touches" + } + + return baseText + "\n" + allTouches.map { $0.description }.joined(separator: ",\n") + } +} + +extension UITouch: CustomStringConvertible { + public var description: String { + return "TouchID: \(self.touchId), timestamp: \(self.timestamp)" + } +} + +@_cdecl("Java_org_libsdl_app_SDLActivity_onNativeTouchUIKit") +public func onNativeTouch( + env: UnsafeMutablePointer, + view: JavaObject, + touchDeviceID: JavaInt, + pointerFingerID: JavaInt, + action: JavaInt, + x: JavaFloat, + y: JavaFloat, + pressure: JavaFloat, + timestamp: JavaLong + ) { + guard let eventType = SDL_EventType.from(androidAction: action) else { return } + + var event = SDL_Event(tfinger: + SDL_TouchFingerEvent( + type: eventType.rawValue, + timestamp: UInt32(timestamp), // the Android system provides timestamps in ms + touchId: Int64(touchDeviceID), // seems to remain constant but actual value depends on phone/tablet + fingerId: Int64(pointerFingerID), + x: x / Float(UIScreen.main.scale), + y: y / Float(UIScreen.main.scale), + dx: 0, // Not used in UIKit cross platform: + dy: 0, // Instead, we do these calculations in our UIGestureRecognizers etc. + pressure: pressure + ) + ) + + // Add the event to SDL's event stack + // Don't use SDL_PushEvent because that overrides `event.timestamp` with its own: + SDL_PeepEvents(&event, 1, SDL_ADDEVENT, 0, 0) +} + +extension SDL_EventType { + public static func from(androidAction: JavaInt) -> SDL_EventType? { + switch androidAction { + case 0, 5: return SDL_FINGERDOWN + case 1, 6: return SDL_FINGERUP + case 2: return SDL_FINGERMOTION + default: return nil + } + } +} +#endif diff --git a/Sources/UIScrollView+velocity.swift b/Sources/UIScrollView+velocity.swift index 418b3c87..cb21243b 100644 --- a/Sources/UIScrollView+velocity.swift +++ b/Sources/UIScrollView+velocity.swift @@ -22,7 +22,7 @@ extension UIScrollView { let velocityIsLargeEnoughToDecelerate = (self.panGestureRecognizer.velocity(in: self).magnitude > 10) let dampingFactor: CGFloat = 0.55 // hand-tuned - let nonBoundsCheckedScrollAnimationDistance = self.weightedAverageVelocity * dampingFactor // hand-tuned + let nonBoundsCheckedScrollAnimationDistance = self.weightedAverageVelocity * dampingFactor let targetOffset = getBoundsCheckedContentOffset(contentOffset - nonBoundsCheckedScrollAnimationDistance) let distanceToBoundsCheckedTarget = contentOffset - targetOffset diff --git a/Sources/UIWindow.swift b/Sources/UIWindow.swift index 0a8183d6..efda5828 100644 --- a/Sources/UIWindow.swift +++ b/Sources/UIWindow.swift @@ -25,34 +25,37 @@ public class UIWindow: UIView { } public func sendEvent(_ event: UIEvent) { - guard - let allTouches = event.allTouches, - let currentTouch = allTouches.first, - let hitView = currentTouch.view ?? hitTest(currentTouch.location(in: nil), with: nil) - else { return } + guard let allTouches = event.allTouches else { return } + UIEvent.activeEvents.insert(event) - switch currentTouch.phase { - case .began: - UIEvent.activeEvents.insert(event) - currentTouch.view = hitView - currentTouch.gestureRecognizers = hitView.getRecognizerHierachy() + for touch in allTouches { + guard let hitView = touch.view ?? hitTest(touch.location(in: nil), with: nil) else { return } - currentTouch.runTouchActionOnRecognizerHierachy { $0.touchesBegan(allTouches, with: event) } - hitView.touchesBegan(allTouches, with: event) + switch touch.phase { + case .began: + touch.view = hitView + touch.gestureRecognizers = hitView.getRecognizerHierachy() - case .moved: - currentTouch.runTouchActionOnRecognizerHierachy { $0.touchesMoved(allTouches, with: event) } - if !currentTouch.hasBeenCancelledByAGestureRecognizer { - hitView.touchesMoved(allTouches, with: event) - } + touch.runTouchActionOnRecognizerHierachy { $0.touchesBegan([touch], with: event) } + hitView.touchesBegan([touch], with: event) - case .ended: - currentTouch.runTouchActionOnRecognizerHierachy { $0.touchesEnded(allTouches, with: event) } - if !currentTouch.hasBeenCancelledByAGestureRecognizer { - hitView.touchesEnded(allTouches, with: event) - } + case .moved: + touch.runTouchActionOnRecognizerHierachy { $0.touchesMoved([touch], with: event) } + if !touch.hasBeenCancelledByAGestureRecognizer { + hitView.touchesMoved([touch], with: event) + } - UIEvent.activeEvents.remove(event) + case .ended: + touch.runTouchActionOnRecognizerHierachy { $0.touchesEnded([touch], with: event) } + if !touch.hasBeenCancelledByAGestureRecognizer { + hitView.touchesEnded([touch], with: event) + } + + event.allTouches?.remove(touch) + if event.allTouches?.isEmpty == true { + UIEvent.activeEvents.remove(event) + } + } } } } diff --git a/UIKit.xcodeproj/project.pbxproj b/UIKit.xcodeproj/project.pbxproj index 34622ed0..ea6e3884 100644 --- a/UIKit.xcodeproj/project.pbxproj +++ b/UIKit.xcodeproj/project.pbxproj @@ -53,6 +53,7 @@ 5C418DBA20F505FF005D0E92 /* UIApplicationDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C418DB920F505FF005D0E92 /* UIApplicationDelegate.swift */; }; 5C418DC020F507DA005D0E92 /* UIApplication.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C418DBF20F507DA005D0E92 /* UIApplication.swift */; }; 5C418DC220F5149E005D0E92 /* UIApplicationMain+Mac.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C418DC120F5149E005D0E92 /* UIApplicationMain+Mac.swift */; }; + 5C43B2DE2190C49000CA5C07 /* UIEvent+fromSDL_Event.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C43B2DD2190C48F00CA5C07 /* UIEvent+fromSDL_Event.swift */; }; 5C4AD7E3204EE2B70021DD4A /* AVPlayerItem+Mac.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C4AD7E1204EE2B60021DD4A /* AVPlayerItem+Mac.swift */; }; 5C4CD51120615FCF00217B4C /* UIApplication+handleSDLEvents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C4CD51020615FCF00217B4C /* UIApplication+handleSDLEvents.swift */; }; 5C4CD51A206160EC00217B4C /* UIView+printViewHierarchy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C4CD519206160EC00217B4C /* UIView+printViewHierarchy.swift */; }; @@ -324,7 +325,6 @@ 5C1F06AE1F3210F200EFF087 /* UIViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = UIViewController.swift; path = Sources/UIViewController.swift; sourceTree = SOURCE_ROOT; }; 5C2714A11F2A3FC50026BBA9 /* SDL+JNIExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SDL+JNIExtensions.swift"; sourceTree = ""; }; 5C27E7AE1ECB2F6500F5020D /* UIKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = UIKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 5C27E7B21ECB2F6500F5020D /* Mac-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "Mac-Info.plist"; path = "../Sources/Mac-Info.plist"; sourceTree = ""; }; 5C27E7B71ECB2F6500F5020D /* UIKitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UIKitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 5C27E7BE1ECB2F6500F5020D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 5C27E7D21ECB2F9100F5020D /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; @@ -346,6 +346,7 @@ 5C418DB920F505FF005D0E92 /* UIApplicationDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIApplicationDelegate.swift; sourceTree = ""; }; 5C418DBF20F507DA005D0E92 /* UIApplication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIApplication.swift; sourceTree = ""; }; 5C418DC120F5149E005D0E92 /* UIApplicationMain+Mac.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIApplicationMain+Mac.swift"; sourceTree = ""; }; + 5C43B2DD2190C48F00CA5C07 /* UIEvent+fromSDL_Event.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIEvent+fromSDL_Event.swift"; sourceTree = ""; }; 5C4AD7E1204EE2B60021DD4A /* AVPlayerItem+Mac.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AVPlayerItem+Mac.swift"; sourceTree = ""; }; 5C4AD7E2204EE2B60021DD4A /* AVPlayerItem+Android.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AVPlayerItem+Android.swift"; sourceTree = ""; }; 5C4AD7E6204EE45F0021DD4A /* AVPlayerLayer+Android.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AVPlayerLayer+Android.swift"; sourceTree = ""; }; @@ -570,7 +571,6 @@ 5C27E7B01ECB2F6500F5020D /* UIKit */, 5C27E7BB1ECB2F6500F5020D /* UIKitTests */, 83C18F391F0FB486008FEA07 /* Resources */, - 5C27E7E61ECB2FE000F5020D /* zSupporting Files */, ); sourceTree = ""; }; @@ -697,15 +697,6 @@ name = Frameworks; sourceTree = ""; }; - 5C27E7E61ECB2FE000F5020D /* zSupporting Files */ = { - isa = PBXGroup; - children = ( - 5C27E7B21ECB2F6500F5020D /* Mac-Info.plist */, - ); - name = "zSupporting Files"; - path = UIKit; - sourceTree = ""; - }; 5C27E7F51ECB301900F5020D /* SDL */ = { isa = PBXGroup; children = ( @@ -1171,6 +1162,7 @@ 5B4F43CF1F39C45900FB4AB9 /* CASpringAnimation.swift in Sources */, 5BA87A9C2018FC990080C876 /* CATransform3D+animations.swift in Sources */, 5C6AB71F1ED3BECD006F90AC /* UIWindow.swift in Sources */, + 5C43B2DE2190C49000CA5C07 /* UIEvent+fromSDL_Event.swift in Sources */, 5CB6E1C32033460C001FEAC9 /* CATransform3D+SDL_gpu.swift in Sources */, 5C8E6A21203A089A00D1DBE0 /* CALayer+ContentsGravity.swift in Sources */, 5BF666A01F4AEC6800BF698C /* CASpringAnimationPrototype.swift in Sources */, From 5bb40a3cb17f2bcfa60cae2c11cd8f12cecfb7ba Mon Sep 17 00:00:00 2001 From: rikner Date: Mon, 4 Mar 2019 15:59:41 +0100 Subject: [PATCH 18/18] remove UIEvent+fromSDL_Event.swift from xcode project (Android only), lint onNativeTouch --- Sources/UIEvent+fromSDL_Event.swift | 4 +--- UIKit.xcodeproj/project.pbxproj | 3 --- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/Sources/UIEvent+fromSDL_Event.swift b/Sources/UIEvent+fromSDL_Event.swift index 172b11d3..c12cf1cd 100644 --- a/Sources/UIEvent+fromSDL_Event.swift +++ b/Sources/UIEvent+fromSDL_Event.swift @@ -6,7 +6,6 @@ // Copyright © 2018 flowkey. All rights reserved. // -#if os(Android) import JNI import SDL @@ -94,7 +93,7 @@ public func onNativeTouch( y: JavaFloat, pressure: JavaFloat, timestamp: JavaLong - ) { +) { guard let eventType = SDL_EventType.from(androidAction: action) else { return } var event = SDL_Event(tfinger: @@ -126,4 +125,3 @@ extension SDL_EventType { } } } -#endif diff --git a/UIKit.xcodeproj/project.pbxproj b/UIKit.xcodeproj/project.pbxproj index ea6e3884..9af43f46 100644 --- a/UIKit.xcodeproj/project.pbxproj +++ b/UIKit.xcodeproj/project.pbxproj @@ -53,7 +53,6 @@ 5C418DBA20F505FF005D0E92 /* UIApplicationDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C418DB920F505FF005D0E92 /* UIApplicationDelegate.swift */; }; 5C418DC020F507DA005D0E92 /* UIApplication.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C418DBF20F507DA005D0E92 /* UIApplication.swift */; }; 5C418DC220F5149E005D0E92 /* UIApplicationMain+Mac.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C418DC120F5149E005D0E92 /* UIApplicationMain+Mac.swift */; }; - 5C43B2DE2190C49000CA5C07 /* UIEvent+fromSDL_Event.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C43B2DD2190C48F00CA5C07 /* UIEvent+fromSDL_Event.swift */; }; 5C4AD7E3204EE2B70021DD4A /* AVPlayerItem+Mac.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C4AD7E1204EE2B60021DD4A /* AVPlayerItem+Mac.swift */; }; 5C4CD51120615FCF00217B4C /* UIApplication+handleSDLEvents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C4CD51020615FCF00217B4C /* UIApplication+handleSDLEvents.swift */; }; 5C4CD51A206160EC00217B4C /* UIView+printViewHierarchy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C4CD519206160EC00217B4C /* UIView+printViewHierarchy.swift */; }; @@ -346,7 +345,6 @@ 5C418DB920F505FF005D0E92 /* UIApplicationDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIApplicationDelegate.swift; sourceTree = ""; }; 5C418DBF20F507DA005D0E92 /* UIApplication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIApplication.swift; sourceTree = ""; }; 5C418DC120F5149E005D0E92 /* UIApplicationMain+Mac.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIApplicationMain+Mac.swift"; sourceTree = ""; }; - 5C43B2DD2190C48F00CA5C07 /* UIEvent+fromSDL_Event.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIEvent+fromSDL_Event.swift"; sourceTree = ""; }; 5C4AD7E1204EE2B60021DD4A /* AVPlayerItem+Mac.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AVPlayerItem+Mac.swift"; sourceTree = ""; }; 5C4AD7E2204EE2B60021DD4A /* AVPlayerItem+Android.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AVPlayerItem+Android.swift"; sourceTree = ""; }; 5C4AD7E6204EE45F0021DD4A /* AVPlayerLayer+Android.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AVPlayerLayer+Android.swift"; sourceTree = ""; }; @@ -1162,7 +1160,6 @@ 5B4F43CF1F39C45900FB4AB9 /* CASpringAnimation.swift in Sources */, 5BA87A9C2018FC990080C876 /* CATransform3D+animations.swift in Sources */, 5C6AB71F1ED3BECD006F90AC /* UIWindow.swift in Sources */, - 5C43B2DE2190C49000CA5C07 /* UIEvent+fromSDL_Event.swift in Sources */, 5CB6E1C32033460C001FEAC9 /* CATransform3D+SDL_gpu.swift in Sources */, 5C8E6A21203A089A00D1DBE0 /* CALayer+ContentsGravity.swift in Sources */, 5BF666A01F4AEC6800BF698C /* CASpringAnimationPrototype.swift in Sources */,