mirror of
https://github.com/geode-sdk/android-launcher.git
synced 2026-10-21 16:32:39 +00:00
add timestamp for fallback inputs
This commit is contained in:
2 files changed
+24
-18
No files matched your search
@@ -23,6 +23,7 @@ import kotlin.math.abs
|
||||
private const val HANDLER_OPEN_IME_KEYBOARD = 2
|
||||
private const val HANDLER_CLOSE_IME_KEYBOARD = 3
|
||||
private const val MS_TO_NS = 1_000_000
|
||||
private const val SEC_TO_NS = 1_000_000_000.0
|
||||
|
||||
class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
||||
companion object {
|
||||
@@ -167,6 +168,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
||||
val ys = FloatArray(pointerNumber)
|
||||
val timestamp = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
|
||||
motionEvent.eventTimeNanos else motionEvent.eventTime * MS_TO_NS
|
||||
val timestampSec = timestamp / SEC_TO_NS
|
||||
|
||||
for (i in 0 until pointerNumber) {
|
||||
ids[i] = motionEvent.getPointerId(i)
|
||||
@@ -188,7 +190,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
||||
GeodeUtils.TOUCH_TYPE_BEGIN, ids.sliceArray(0..0), xs.sliceArray(0..0), ys.sliceArray(0..0)
|
||||
)
|
||||
else
|
||||
cocos2dxRenderer.handleActionDown(idDown, xDown, f)
|
||||
cocos2dxRenderer.handleActionDown(idDown, xDown, f, timestampSec)
|
||||
}
|
||||
true
|
||||
}
|
||||
@@ -205,7 +207,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
||||
GeodeUtils.TOUCH_TYPE_END, ids.sliceArray(0..0), xs.sliceArray(0..0), ys.sliceArray(0..0)
|
||||
)
|
||||
else
|
||||
cocos2dxRenderer.handleActionUp(idUp, f2, f3)
|
||||
cocos2dxRenderer.handleActionUp(idUp, f2, f3, timestampSec)
|
||||
}
|
||||
true
|
||||
}
|
||||
@@ -219,7 +221,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
||||
GeodeUtils.TOUCH_TYPE_MOVE, ids, xs, ys
|
||||
)
|
||||
else
|
||||
cocos2dxRenderer.handleActionMove(ids, xs, ys)
|
||||
cocos2dxRenderer.handleActionMove(ids, xs, ys, timestampSec)
|
||||
}
|
||||
true
|
||||
}
|
||||
@@ -233,7 +235,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
||||
GeodeUtils.TOUCH_TYPE_CANCEL, ids, xs, ys
|
||||
)
|
||||
else
|
||||
cocos2dxRenderer.handleActionCancel(ids, xs, ys)
|
||||
cocos2dxRenderer.handleActionCancel(ids, xs, ys, timestampSec)
|
||||
}
|
||||
true
|
||||
}
|
||||
@@ -251,7 +253,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
||||
GeodeUtils.TOUCH_TYPE_BEGIN, intArrayOf(idPointerDown), floatArrayOf(xPointerDown), floatArrayOf(y)
|
||||
)
|
||||
else
|
||||
cocos2dxRenderer.handleActionDown(idPointerDown, xPointerDown, y)
|
||||
cocos2dxRenderer.handleActionDown(idPointerDown, xPointerDown, y, timestampSec)
|
||||
}
|
||||
true
|
||||
}
|
||||
@@ -269,7 +271,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
||||
GeodeUtils.TOUCH_TYPE_END, intArrayOf(idPointerUp), floatArrayOf(xPointerUp), floatArrayOf(y2)
|
||||
)
|
||||
else
|
||||
cocos2dxRenderer.handleActionUp(idPointerUp, xPointerUp, y2)
|
||||
cocos2dxRenderer.handleActionUp(idPointerUp, xPointerUp, y2, timestampSec)
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
@@ -40,21 +40,25 @@ class Cocos2dxRenderer(private var handler: Cocos2dxGLSurfaceView) : GLSurfaceVi
|
||||
@JvmStatic
|
||||
private external fun nativeTextClosed()
|
||||
|
||||
// timestamp was added in 2.208, but the jni method has no required type signature.
|
||||
// it doesn't hurt to unconditionally send one
|
||||
|
||||
@JvmStatic
|
||||
private external fun nativeTouchesBegin(id: Int, x: Float, y: Float)
|
||||
private external fun nativeTouchesBegin(id: Int, x: Float, y: Float, timestamp: Double)
|
||||
|
||||
@JvmStatic
|
||||
private external fun nativeTouchesCancel(
|
||||
ids: IntArray,
|
||||
xs: FloatArray,
|
||||
ys: FloatArray
|
||||
ys: FloatArray,
|
||||
timestamp: Double,
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
private external fun nativeTouchesEnd(id: Int, x: Float, y: Float)
|
||||
private external fun nativeTouchesEnd(id: Int, x: Float, y: Float, timestamp: Double)
|
||||
|
||||
@JvmStatic
|
||||
private external fun nativeTouchesMove(ids: IntArray, xs: FloatArray, ys: FloatArray)
|
||||
private external fun nativeTouchesMove(ids: IntArray, xs: FloatArray, ys: FloatArray, timestamp: Double)
|
||||
|
||||
@JvmStatic
|
||||
private external fun nativeInit(width: Int, height: Int)
|
||||
@@ -109,20 +113,20 @@ class Cocos2dxRenderer(private var handler: Cocos2dxGLSurfaceView) : GLSurfaceVi
|
||||
}
|
||||
}
|
||||
|
||||
fun handleActionDown(id: Int, x: Float, y: Float) {
|
||||
nativeTouchesBegin(id, x, y)
|
||||
fun handleActionDown(id: Int, x: Float, y: Float, timestamp: Double) {
|
||||
nativeTouchesBegin(id, x, y, timestamp)
|
||||
}
|
||||
|
||||
fun handleActionUp(id: Int, x: Float, y: Float) {
|
||||
nativeTouchesEnd(id, x, y)
|
||||
fun handleActionUp(id: Int, x: Float, y: Float, timestamp: Double) {
|
||||
nativeTouchesEnd(id, x, y, timestamp)
|
||||
}
|
||||
|
||||
fun handleActionCancel(ids: IntArray, xs: FloatArray, ys: FloatArray) {
|
||||
nativeTouchesCancel(ids, xs, ys)
|
||||
fun handleActionCancel(ids: IntArray, xs: FloatArray, ys: FloatArray, timestamp: Double) {
|
||||
nativeTouchesCancel(ids, xs, ys, timestamp)
|
||||
}
|
||||
|
||||
fun handleActionMove(ids: IntArray, xs: FloatArray, ys: FloatArray) {
|
||||
nativeTouchesMove(ids, xs, ys)
|
||||
fun handleActionMove(ids: IntArray, xs: FloatArray, ys: FloatArray, timestamp: Double) {
|
||||
nativeTouchesMove(ids, xs, ys, timestamp)
|
||||
}
|
||||
|
||||
fun handleKeyDown(keyCode: Int) {
|
||||
|
||||
Reference in new issue
Block a user