aboutsummaryrefslogtreecommitdiff
path: root/go/ui/touchManager.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/ui/touchManager.go')
-rw-r--r--go/ui/touchManager.go30
1 files changed, 28 insertions, 2 deletions
diff --git a/go/ui/touchManager.go b/go/ui/touchManager.go
index 462b9934..b675ff0e 100644
--- a/go/ui/touchManager.go
+++ b/go/ui/touchManager.go
@@ -22,20 +22,25 @@ import (
"github.com/hajimehoshi/ebiten/v2/inpututil"
)
+const LONGTAP_THRESHOLD = 75
+
type TouchType int
const (
_tap TouchType = iota + 1
+ _longtap
_pan
_pinch
)
var touchTypes = struct {
tap TouchType
+ longtap TouchType
pan TouchType
pinch TouchType
}{
tap: _tap,
+ longtap: _longtap,
pan: _pan,
pinch: _pinch,
}
@@ -48,6 +53,7 @@ type TouchInput struct {
pinch *pinch
pan *pan
+ longtap *longtap
taps []tap
}
@@ -99,9 +105,14 @@ func (in *TouchInput) Update() error {
in.pan = nil
}
+ if in.longtap != nil && id == in.longtap.id {
+ // FIXME: what about this frame's movement?
+ in.longtap = nil
+ }
+
// If this one has not been touched long, or moved far, then it's a tap.
diff := hypotenuse(t.originX, t.originY, t.currX, t.currY)
- if !t.wasPinch && !t.isPan && (t.duration <= 75 || diff < 5) {
+ if !t.wasPinch && !t.isPan && (t.duration <= LONGTAP_THRESHOLD || diff < 5) {
in.taps = append(in.taps, tap{
x: t.currX,
y: t.currY,
@@ -165,6 +176,15 @@ func (in *TouchInput) Update() error {
prevY: t.originY,
}
}
+ } else if t.duration > LONGTAP_THRESHOLD {
+ id := in.touchIDs[0]
+ t := in.touches[id]
+ t.isLongtap = true
+ in.longtap = &longtap{
+ id: id,
+ tap: tap{t.originX, t.originY},
+ duration: t.duration,
+ }
}
}
@@ -175,7 +195,7 @@ type touch struct {
originX, originY int
currX, currY int
duration int
- wasPinch, isPan bool
+ wasPinch, isPan, isLongtap bool
}
type pinch struct {
@@ -228,3 +248,9 @@ func (p *pan) Incremental() (float64, float64) {
type tap struct {
x, y int
}
+
+type longtap struct {
+ tap
+ id ebiten.TouchID
+ duration int
+}