diff --git a/internal/input/input_js.go b/internal/input/input_js.go index 378af8e9e..4d6ee9431 100644 --- a/internal/input/input_js.go +++ b/internal/input/input_js.go @@ -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 diff --git a/internal/ui/ui_js.go b/internal/ui/ui_js.go index 0bd8ced8f..2dfc5a142 100644 --- a/internal/ui/ui_js.go +++ b/internal/ui/ui_js.go @@ -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 {