multixy: methodize handle hit test

This commit is contained in:
jean-emmanuel 2025-03-17 18:27:24 +01:00
parent 911c318cc1
commit d4297dd4ab

View file

@ -119,26 +119,10 @@ class MultiXy extends Pad {
if (!this.touchMap[e.pointerId]) {
var ndiff, diff = -1
for (var i in this.pads) {
if (Object.values(this.touchMap).indexOf(i) != -1) continue
if (!this.pads[i].getProp('visible')) continue
ndiff = Math.abs(e.offsetX - this.padsCoords[i][0]) + Math.abs(e.offsetY - (this.padsCoords[i][1] + this.height))
if (diff == -1 || ndiff < diff) {
id = i
diff = ndiff
}
}
id = this.getPadIdFromCoords(e.offsetX, e.offsetY)
this.touchMap[e.pointerId] = id
}
if (!id) return
@ -235,6 +219,29 @@ class MultiXy extends Pad {
}
getPadIdFromCoords(x, y) {
var ndiff, diff = -1,
id
for (var i in this.pads) {
if (Object.values(this.touchMap).indexOf(i) != -1) continue
if (!this.pads[i].getProp('visible')) continue
ndiff = Math.abs(x - this.padsCoords[i][0]) + Math.abs(y - (this.padsCoords[i][1] + this.height))
if (diff == -1 || ndiff < diff) {
id = i
diff = ndiff
}
}
return id
}
extraResizeHandle(event){
super.extraResizeHandle(event)