ui: Adjust touch positions in ui package (js)

This commit is contained in:
Hajime Hoshi 2018-04-03 00:53:06 +09:00
parent c540d0fc0d
commit 0f2beab260
2 changed files with 14 additions and 8 deletions

View File

@ -267,12 +267,10 @@ func (i *Input) updateTouches(e *js.Object, scale float64, left, top int) {
for i := 0; i < len(ts); i++ {
jj := j.Call("item", i)
id := jj.Get("identifier").Int()
x := int(float64(jj.Get("clientX").Int()-left) / scale)
y := int(float64(jj.Get("clientY").Int()-top) / scale)
ts[i] = &Touch{
id: id,
x: x,
y: y,
x: jj.Get("clientX").Int(),
y: jj.Get("clientY").Int(),
}
}
i.touches = ts

View File

@ -77,8 +77,7 @@ func ScreenPadding() (x0, y0, x1, y1 float64) {
return 0, 0, 0, 0
}
func AdjustedCursorPosition() (x, y int) {
x, y = input.Get().CursorPosition()
func adjustPosition(x, y int) (int, int) {
rect := canvas.Call("getBoundingClientRect")
x -= rect.Get("left").Int()
y -= rect.Get("top").Int()
@ -86,9 +85,18 @@ func AdjustedCursorPosition() (x, y int) {
return int(float64(x) / scale), int(float64(y) / scale)
}
func AdjustedCursorPosition() (x, y int) {
return adjustPosition(input.Get().CursorPosition())
}
func AdjustedTouches() []*input.Touch {
// TODO: Apply adjustment here
return input.Get().Touches()
ts := input.Get().Touches()
adjusted := make([]*input.Touch, len(ts))
for i, t := range ts {
x, y := adjustPosition(t.Position())
adjusted[i] = input.NewTouch(t.ID(), x, y)
}
return adjusted
}
func IsCursorVisible() bool {