mobile: UpdateTouchesOnIOS should take int64 ptrs

This commit is contained in:
Hajime Hoshi 2016-06-26 15:33:14 +09:00
parent 475d659459
commit 891ad34d88
4 changed files with 26 additions and 6 deletions

View File

@ -54,6 +54,6 @@ func UpdateTouchesOnAndroid(action int, id int, x, y int) {
updateTouchesOnAndroid(action, id, x, y) updateTouchesOnAndroid(action, id, x, y)
} }
func UpdateTouchesOnIOS(phase int, ptr int, x, y int) { func UpdateTouchesOnIOS(phase int, ptr int64, x, y int) {
updateTouchesOnIOSImpl(phase, ptr, x, y) updateTouchesOnIOSImpl(phase, ptr, x, y)
} }

View File

@ -25,6 +25,6 @@ func updateTouchesOnAndroid(action int, id int, x, y int) {
} }
} }
func updateTouchesOnIOSImpl(phase int, ptr int, x, y int) { func updateTouchesOnIOSImpl(phase int, ptr int64, x, y int) {
panic("not reach") panic("not reach")
} }

View File

@ -21,5 +21,5 @@ package mobile
func updateTouchesOnAndroid(action int, id int, x, y int) { func updateTouchesOnAndroid(action int, id int, x, y int) {
} }
func updateTouchesOnIOSImpl(phase int, ptr int, x, y int) { func updateTouchesOnIOSImpl(phase int, ptr int64, x, y int) {
} }

View File

@ -22,17 +22,37 @@ package mobile
// #import <UIKit/UIKit.h> // #import <UIKit/UIKit.h>
import "C" import "C"
var ptrToID = map[int64]int{}
func getIDFromPtr(ptr int64) int {
if id, ok := ptrToID[ptr]; ok {
return id
}
maxID := 0
for _, id := range ptrToID {
if maxID > id {
maxID = id
}
}
id := maxID + 1
ptrToID[ptr] = id
return id
}
func updateTouchesOnAndroid(action int, id int, x, y int) { func updateTouchesOnAndroid(action int, id int, x, y int) {
panic("not reach") panic("not reach")
} }
func updateTouchesOnIOSImpl(phase int, ptr int, x, y int) { func updateTouchesOnIOSImpl(phase int, ptr int64, x, y int) {
switch phase { switch phase {
case C.UITouchPhaseBegan, C.UITouchPhaseMoved, C.UITouchPhaseStationary: case C.UITouchPhaseBegan, C.UITouchPhaseMoved, C.UITouchPhaseStationary:
touches[ptr] = position{x, y} id := getIDFromPtr(ptr)
touches[id] = position{x, y}
updateTouches() updateTouches()
case C.UITouchPhaseEnded, C.UITouchPhaseCancelled: case C.UITouchPhaseEnded, C.UITouchPhaseCancelled:
delete(touches, ptr) id := getIDFromPtr(ptr)
delete(ptrToID, ptr)
delete(touches, id)
updateTouches() updateTouches()
default: default:
panic("not reach") panic("not reach")