-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtouchevent_js.go
58 lines (51 loc) · 1.2 KB
/
touchevent_js.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package webgl
import (
"syscall/js"
)
type TouchEvent struct {
UIEvent
ChangedTouches []Touch
TargetTouches []Touch
Touches []Touch
AltKey bool
CtrlKey bool
ShiftKey bool
}
func parseTouchEvent(event js.Value) TouchEvent {
return TouchEvent{
UIEvent: UIEvent{
Event: Event{
event: event,
},
},
ChangedTouches: parseTouches(event.Get("changedTouches")),
TargetTouches: parseTouches(event.Get("targetTouches")),
Touches: parseTouches(event.Get("touches")),
AltKey: event.Get("altKey").Bool(),
CtrlKey: event.Get("ctrlKey").Bool(),
ShiftKey: event.Get("shiftKey").Bool(),
}
}
type Touch struct {
Identifier int
ScreenX, ScreenY int
ClientX, ClientY int
PageX, PageY int
}
func parseTouches(touches js.Value) []Touch {
n := touches.Length()
ts := make([]Touch, 0, n)
for i := 0; i < n; i++ {
t := touches.Index(i)
ts = append(ts, Touch{
Identifier: t.Get("identifier").Int(),
ScreenX: t.Get("screenX").Int(),
ScreenY: t.Get("screenY").Int(),
ClientX: t.Get("clientX").Int(),
ClientY: t.Get("clientY").Int(),
PageX: t.Get("pageX").Int(),
PageY: t.Get("pageY").Int(),
})
}
return ts
}