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.go58
1 files changed, 30 insertions, 28 deletions
diff --git a/go/ui/touchManager.go b/go/ui/touchManager.go
index ef4448d5..462b9934 100644
--- a/go/ui/touchManager.go
+++ b/go/ui/touchManager.go
@@ -30,13 +30,15 @@ const (
_pinch
)
-var TouchTypes = struct {
- Tap TouchType
- Pan TouchType
- Pinch TouchType
-}{Tap: _tap,
- Pan: _pan,
- Pinch: _pinch}
+var touchTypes = struct {
+ tap TouchType
+ pan TouchType
+ pinch TouchType
+}{
+ tap: _tap,
+ pan: _pan,
+ pinch: _pinch,
+}
// TouchInput is a "manager" for touch input and provides logical encapsulations of
// touch interactions like panning, pinching, and tapping.
@@ -44,16 +46,16 @@ type TouchInput struct {
touchIDs []ebiten.TouchID
touches map[ebiten.TouchID]*touch
- Pinch *pinch
- Pan *pan
- Taps []Tap
+ pinch *pinch
+ pan *pan
+ taps []tap
}
-func (t *TouchInput) consumeTap(i int) {
- if len(t.Taps) == 1 {
- t.Taps = []Tap{}
+func (t *TouchInput) consumetap(i int) {
+ if len(t.taps) == 1 {
+ t.taps = []tap{}
} else {
- t.Taps[i] = t.Taps[len(t.Taps)-1]
+ t.taps[i] = t.taps[len(t.taps)-1]
}
}
@@ -83,26 +85,26 @@ func hypotenuse(xa, ya, xb, yb int) float64 {
// have one touch, held longer than (N)ms, then we have a pan.
// If we have quickly released presses, then they are represented in taps.
func (in *TouchInput) Update() error {
- in.Taps = []Tap{}
+ in.taps = []tap{}
// What's gone?
for id, t := range in.touches {
if inpututil.IsTouchJustReleased(id) {
- if in.Pinch != nil && (id == in.Pinch.id1 || id == in.Pinch.id2) {
+ if in.pinch != nil && (id == in.pinch.id1 || id == in.pinch.id2) {
// FIXME: what about this frame's movement?
- in.Pinch = nil
+ in.pinch = nil
}
- if in.Pan != nil && id == in.Pan.id {
+ if in.pan != nil && id == in.pan.id {
// FIXME: what about this frame's movement?
- in.Pan = nil
+ in.pan = 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) {
- in.Taps = append(in.Taps, Tap{
- X: t.currX,
- Y: t.currY,
+ in.taps = append(in.taps, tap{
+ x: t.currX,
+ y: t.currY,
})
}
@@ -137,10 +139,10 @@ func (in *TouchInput) Update() error {
t1, t2 := in.touches[id1], in.touches[id2]
originDiff := hypotenuse(t1.originX, t1.originY, t2.originX, t2.originY)
currDiff := hypotenuse(t1.currX, t1.currY, t2.currX, t2.currY)
- if in.Pinch == nil && in.Pan == nil && math.Abs(originDiff-currDiff) > 3 {
+ if in.pinch == nil && in.pan == nil && math.Abs(originDiff-currDiff) > 3 {
t1.wasPinch = true
t2.wasPinch = true
- in.Pinch = &pinch{
+ in.pinch = &pinch{
id1: id1,
id2: id2,
originH: originDiff,
@@ -151,11 +153,11 @@ func (in *TouchInput) Update() error {
// Potential pan.
id := in.touchIDs[0]
t := in.touches[id]
- if !t.wasPinch && in.Pan == nil && in.Pinch == nil {
+ if !t.wasPinch && in.pan == nil && in.pinch == nil {
diff := math.Abs(hypotenuse(t.originX, t.originY, t.currX, t.currY))
if diff > 0.25 {
t.isPan = true
- in.Pan = &pan{
+ in.pan = &pan{
id: id,
originX: t.originX,
originY: t.originY,
@@ -223,6 +225,6 @@ func (p *pan) Incremental() (float64, float64) {
return float64(deltaX), float64(deltaY)
}
-type Tap struct {
- X, Y int
+type tap struct {
+ x, y int
}