Skip to content

Commit 25f367a

Browse files
Improve Virtual Controllers Handling (Helps #9)
1 parent e5b3098 commit 25f367a

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

app/src/main/java/com/micewine/emu/views/OverlayView.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class OverlayView @JvmOverloads constructor(
132132
if (detectClick(event, event.actionIndex, it.x, it.y, it.radius)) {
133133
it.isPressed = true
134134
it.fingerId = event.actionIndex
135+
135136
handleButton(it, true)
136137

137138
return@forEach
@@ -146,7 +147,7 @@ class OverlayView @JvmOverloads constructor(
146147
it.fingerX = posX
147148
it.fingerY = posY
148149
it.isPressed = true
149-
it.fingerId = event.getPointerId(event.actionIndex)
150+
it.fingerId = event.actionIndex
150151

151152
val axisX = posX / (it.radius / 4)
152153
val axisY = posY / (it.radius / 4)
@@ -174,13 +175,10 @@ class OverlayView @JvmOverloads constructor(
174175

175176
buttonList.forEach {
176177
if (it.fingerId == i) {
177-
val clicked = detectClick(event, i, it.x, it.y, it.radius)
178-
it.isPressed = clicked
179-
handleButton(it, clicked)
178+
it.isPressed = true
179+
handleButton(it, true)
180180

181-
if (clicked) {
182-
isFingerPressingButton = true
183-
}
181+
isFingerPressingButton = true
184182
}
185183
}
186184

@@ -230,20 +228,21 @@ class OverlayView @JvmOverloads constructor(
230228

231229
MotionEvent.ACTION_POINTER_UP -> {
232230
buttonList.forEach {
231+
if (it.fingerId == event.actionIndex) {
232+
it.fingerId = -1
233+
}
233234
if (detectClick(event, event.actionIndex, it.x, it.y, it.radius)) {
234235
handleButton(it, false)
235236
}
236237
}
237238

238239
analogList.forEach {
239-
if ((event.getX(event.actionIndex) >= it.x - it.radius / 2 && event.getX(event.actionIndex) <= (it.x + (it.radius / 2))) &&
240-
(event.getY(event.actionIndex) >= it.y - it.radius / 2 && event.getY(event.actionIndex) <= (it.y + (it.radius / 2)))
241-
) {
240+
if (it.fingerId == event.actionIndex) {
241+
it.fingerId = -1
242242
it.fingerX = 0F
243243
it.fingerY = 0F
244244

245245
it.isPressed = false
246-
it.fingerId = -1
247246

248247
virtualAxis(
249248
0F,
@@ -262,6 +261,7 @@ class OverlayView @JvmOverloads constructor(
262261

263262
MotionEvent.ACTION_UP -> {
264263
buttonList.forEach {
264+
it.fingerId = -1
265265
handleButton(it, false)
266266
}
267267

0 commit comments

Comments
 (0)