touch.go (1951B)
1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package touch defines an event for touch input. 6 // 7 // See the golang.org/x/mobile/app package for details on the event model. 8 package touch // import "golang.org/x/mobile/event/touch" 9 10 // The best source on android input events is the NDK: include/android/input.h 11 // 12 // iOS event handling guide: 13 // https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS 14 15 import ( 16 "fmt" 17 ) 18 19 // Event is a touch event. 20 type Event struct { 21 // X and Y are the touch location, in pixels. 22 X, Y float32 23 24 // Sequence is the sequence number. The same number is shared by all events 25 // in a sequence. A sequence begins with a single TypeBegin, is followed by 26 // zero or more TypeMoves, and ends with a single TypeEnd. A Sequence 27 // distinguishes concurrent sequences but its value is subsequently reused. 28 Sequence Sequence 29 30 // Type is the touch type. 31 Type Type 32 } 33 34 // Sequence identifies a sequence of touch events. 35 type Sequence int64 36 37 // Type describes the type of a touch event. 38 type Type byte 39 40 const ( 41 // TypeBegin is a user first touching the device. 42 // 43 // On Android, this is a AMOTION_EVENT_ACTION_DOWN. 44 // On iOS, this is a call to touchesBegan. 45 TypeBegin Type = iota 46 47 // TypeMove is a user dragging across the device. 48 // 49 // A TypeMove is delivered between a TypeBegin and TypeEnd. 50 // 51 // On Android, this is a AMOTION_EVENT_ACTION_MOVE. 52 // On iOS, this is a call to touchesMoved. 53 TypeMove 54 55 // TypeEnd is a user no longer touching the device. 56 // 57 // On Android, this is a AMOTION_EVENT_ACTION_UP. 58 // On iOS, this is a call to touchesEnded. 59 TypeEnd 60 ) 61 62 func (t Type) String() string { 63 switch t { 64 case TypeBegin: 65 return "begin" 66 case TypeMove: 67 return "move" 68 case TypeEnd: 69 return "end" 70 } 71 return fmt.Sprintf("touch.Type(%d)", t) 72 }