From 89fdf707b1f5a4cff34135438bcb890e1b0641e1 Mon Sep 17 00:00:00 2001 From: Jerboa-app Date: Mon, 5 Aug 2024 07:41:12 +0100 Subject: [PATCH] Working multi-touch --- .../app/jerboa/spp/ui/view/SPPRenderer.kt | 2 +- .../java/app/jerboa/spp/ui/view/SPPView.kt | 22 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/app/jerboa/spp/ui/view/SPPRenderer.kt b/app/src/main/java/app/jerboa/spp/ui/view/SPPRenderer.kt index 791da3b..9c34d66 100644 --- a/app/src/main/java/app/jerboa/spp/ui/view/SPPRenderer.kt +++ b/app/src/main/java/app/jerboa/spp/ui/view/SPPRenderer.kt @@ -535,7 +535,7 @@ class SPPRenderer( } // propagate a tap event - fun tap(x: Float,y: Float, type: TOY = TOY.ATTRACTOR){ + private fun tap(x: Float,y: Float, type: TOY = TOY.ATTRACTOR){ if (DEMO_REAL){return} runBlocking { withContext(Dispatchers.Default) { diff --git a/app/src/main/java/app/jerboa/spp/ui/view/SPPView.kt b/app/src/main/java/app/jerboa/spp/ui/view/SPPView.kt index 7b3b9b0..483dd3e 100644 --- a/app/src/main/java/app/jerboa/spp/ui/view/SPPView.kt +++ b/app/src/main/java/app/jerboa/spp/ui/view/SPPView.kt @@ -85,7 +85,6 @@ class SPPView ( } override fun onTouchEvent(event: MotionEvent): Boolean { - Log.d("event", "${event.action}") when (event.actionMasked) { MotionEvent.ACTION_DOWN -> { event.actionIndex.also { pointer -> @@ -106,23 +105,30 @@ class SPPView ( event.getY(pointer), DRAG.START, placingToy, - event.actionIndex.toUInt() + event.getPointerId(event.actionIndex).toUInt() ) } } MotionEvent.ACTION_MOVE -> { - val pointer = event.findPointerIndex(event.actionIndex) - renderer.handleTouchEvent(event.getX(pointer), event.getY(pointer), DRAG.CONTINUE, placingToy, event.actionIndex.toUInt()) + for (i in 0 until event.pointerCount) { + renderer.handleTouchEvent( + event.getX(i), + event.getY(i), + DRAG.CONTINUE, + placingToy, + event.getPointerId(i).toUInt() + ) + } } MotionEvent.ACTION_UP -> { - renderer.handleTouchEvent(event.getX(0),event.getY(0),DRAG.STOP, placingToy, event.actionIndex.toUInt()) + renderer.handleTouchEvent(event.getX(0),event.getY(0),DRAG.STOP, placingToy, event.getPointerId(event.actionIndex).toUInt()) } MotionEvent.ACTION_POINTER_UP -> { event.actionIndex.also { pointer -> event.getPointerId(pointer) - .run { - renderer.handleTouchEvent(event.getX(pointer),event.getY(pointer),DRAG.STOP, placingToy, event.actionIndex.toUInt()) - } + .run { + renderer.handleTouchEvent(event.getX(pointer),event.getY(pointer),DRAG.STOP, placingToy, event.getPointerId(event.actionIndex).toUInt()) + } } } }