/
touch.go
99 lines (79 loc) · 2.61 KB
/
touch.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (c) 2018, Cogent Core. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package events
import (
"fmt"
"image"
)
// The best source on android input events is the NDK: include/android/input.h
//
// iOS event handling guide:
// https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS
// Touch is a touch event.
type Touch struct {
Base
// Sequence is the sequence number. The same number is shared by all events
// in a sequence. A sequence begins with a single Begin, is followed by
// zero or more Moves, and ends with a single End. A Sequence
// distinguishes concurrent sequences but its value is subsequently reused.
Sequence Sequence
}
// Sequence identifies a sequence of touch events.
type Sequence int64
// NewTouch creates a new touch event from the given values.
func NewTouch(typ Types, seq Sequence, where image.Point) *Touch {
ev := &Touch{}
ev.Typ = typ
ev.SetUnique()
ev.Sequence = seq
ev.Where = where
return ev
}
func (ev *Touch) HasPos() bool {
return true
}
func (ev *Touch) String() string {
return fmt.Sprintf("%v{Pos: %v, Sequence: %v, Time: %v}", ev.Type(), ev.Where, ev.Sequence, ev.Time().Format("04:05"))
}
// todo: what about these higher-level abstractions of touch-like events?
// TouchMagnify is a touch magnification (scaling) gesture event.
// It is the event struct corresponding to events of type [Magnify].
type TouchMagnify struct {
Touch
// the multiplicative scale factor relative to the previous
// zoom of the screen
ScaleFactor float32
}
// NewMagnify creates a new [TouchMagnify] event based on
// the given multiplicative scale factor.
func NewMagnify(scaleFactor float32, where image.Point) *TouchMagnify {
ev := &TouchMagnify{}
ev.Typ = Magnify
ev.ScaleFactor = scaleFactor
ev.Where = where
return ev
}
// // check for interface implementation
// var _ Event = &MagnifyEvent{}
// ////////////////////////////////////////////
// // RotateEvent is used to represent a rotation gesture.
// type RotateEvent struct {
// GestureEvent
// Rotation float64 // measured in degrees; positive == clockwise
// }
// func (ev *RotateEvent) EventTypes() EventTypes {
// return RotateEventTypes
// }
// // check for interface implementation
// var _ Event = &RotateEvent{}
// // Scroll Event is used to represent a scrolling gesture.
// type ScrollEvent struct {
// GestureEvent
// Delta image.Point
// }
// func (ev *ScrollEvent) EventTypes() EventTypes {
// return ScrollEventTypes
// }
// // check for interface implementation
// var _ Event = &ScrollEvent{}