mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 02:42:02 +01:00
input: Refactoring
This commit is contained in:
parent
7d2fd9654a
commit
e44a930bbb
@ -176,11 +176,6 @@ func (i *Input) UpdateGamepads() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Input) updateTouches(t []*Touch) {
|
|
||||||
i.touches = make([]*Touch, len(t))
|
|
||||||
copy(i.touches, t)
|
|
||||||
}
|
|
||||||
|
|
||||||
func OnKeyDown(e *js.Object) {
|
func OnKeyDown(e *js.Object) {
|
||||||
c := e.Get("code")
|
c := e.Get("code")
|
||||||
if c == js.Undefined {
|
if c == js.Undefined {
|
||||||
@ -248,17 +243,17 @@ func OnMouseMove(e *js.Object) {
|
|||||||
|
|
||||||
func OnTouchStart(e *js.Object, scale float64, left, top int) {
|
func OnTouchStart(e *js.Object, scale float64, left, top int) {
|
||||||
e.Call("preventDefault")
|
e.Call("preventDefault")
|
||||||
theInput.updateTouches(touchEventToTouches(e, scale, left, top))
|
theInput.updateTouches(e, scale, left, top)
|
||||||
}
|
}
|
||||||
|
|
||||||
func OnTouchEnd(e *js.Object, scale float64, left, top int) {
|
func OnTouchEnd(e *js.Object, scale float64, left, top int) {
|
||||||
e.Call("preventDefault")
|
e.Call("preventDefault")
|
||||||
theInput.updateTouches(touchEventToTouches(e, scale, left, top))
|
theInput.updateTouches(e, scale, left, top)
|
||||||
}
|
}
|
||||||
|
|
||||||
func OnTouchMove(e *js.Object, scale float64, left, top int) {
|
func OnTouchMove(e *js.Object, scale float64, left, top int) {
|
||||||
e.Call("preventDefault")
|
e.Call("preventDefault")
|
||||||
theInput.updateTouches(touchEventToTouches(e, scale, left, top))
|
theInput.updateTouches(e, scale, left, top)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setMouseCursorFromEvent(e *js.Object) {
|
func setMouseCursorFromEvent(e *js.Object) {
|
||||||
@ -266,19 +261,19 @@ func setMouseCursorFromEvent(e *js.Object) {
|
|||||||
theInput.setMouseCursor(x, y)
|
theInput.setMouseCursor(x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
func touchEventToTouches(e *js.Object, scale float64, left, top int) []*Touch {
|
func (i *Input) updateTouches(e *js.Object, scale float64, left, top int) {
|
||||||
j := e.Get("targetTouches")
|
j := e.Get("targetTouches")
|
||||||
t := make([]*Touch, j.Get("length").Int())
|
ts := make([]*Touch, j.Get("length").Int())
|
||||||
for i := 0; i < len(t); 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)
|
x := int(float64(jj.Get("clientX").Int()-left) / scale)
|
||||||
y := int(float64(jj.Get("clientY").Int()-top) / scale)
|
y := int(float64(jj.Get("clientY").Int()-top) / scale)
|
||||||
t[i] = &Touch{
|
ts[i] = &Touch{
|
||||||
id: id,
|
id: id,
|
||||||
x: x,
|
x: x,
|
||||||
y: y,
|
y: y,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return t
|
i.touches = ts
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user