mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
ui: Adjust touch positions in ui package (js)
This commit is contained in:
parent
c540d0fc0d
commit
0f2beab260
@ -267,12 +267,10 @@ func (i *Input) updateTouches(e *js.Object, scale float64, left, top int) {
|
|||||||
for i := 0; i < len(ts); i++ {
|
for i := 0; i < len(ts); i++ {
|
||||||
jj := j.Call("item", i)
|
jj := j.Call("item", i)
|
||||||
id := jj.Get("identifier").Int()
|
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{
|
ts[i] = &Touch{
|
||||||
id: id,
|
id: id,
|
||||||
x: x,
|
x: jj.Get("clientX").Int(),
|
||||||
y: y,
|
y: jj.Get("clientY").Int(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i.touches = ts
|
i.touches = ts
|
||||||
|
@ -77,8 +77,7 @@ func ScreenPadding() (x0, y0, x1, y1 float64) {
|
|||||||
return 0, 0, 0, 0
|
return 0, 0, 0, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func AdjustedCursorPosition() (x, y int) {
|
func adjustPosition(x, y int) (int, int) {
|
||||||
x, y = input.Get().CursorPosition()
|
|
||||||
rect := canvas.Call("getBoundingClientRect")
|
rect := canvas.Call("getBoundingClientRect")
|
||||||
x -= rect.Get("left").Int()
|
x -= rect.Get("left").Int()
|
||||||
y -= rect.Get("top").Int()
|
y -= rect.Get("top").Int()
|
||||||
@ -86,9 +85,18 @@ func AdjustedCursorPosition() (x, y int) {
|
|||||||
return int(float64(x) / scale), int(float64(y) / scale)
|
return int(float64(x) / scale), int(float64(y) / scale)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AdjustedCursorPosition() (x, y int) {
|
||||||
|
return adjustPosition(input.Get().CursorPosition())
|
||||||
|
}
|
||||||
|
|
||||||
func AdjustedTouches() []*input.Touch {
|
func AdjustedTouches() []*input.Touch {
|
||||||
// TODO: Apply adjustment here
|
ts := input.Get().Touches()
|
||||||
return 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 {
|
func IsCursorVisible() bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user