Skip to content

Commit

Permalink
Working multi-touch
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerboa-app committed Aug 5, 2024
1 parent c8b3769 commit 89fdf70
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/app/jerboa/spp/ui/view/SPPRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 14 additions & 8 deletions app/src/main/java/app/jerboa/spp/ui/view/SPPView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand All @@ -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())
}
}
}
}
Expand Down

0 comments on commit 89fdf70

Please sign in to comment.