| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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 event defines user input events. | |
| 6 package event // import "golang.org/x/mobile/event" | |
| 7 | |
| 8 /* | |
| 9 The best source on android input events is the NDK: include/android/input.h | |
| 10 | |
| 11 iOS event handling guide: | |
| 12 https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/E
ventHandlingiPhoneOS | |
| 13 */ | |
| 14 | |
| 15 import ( | |
| 16 "fmt" | |
| 17 | |
| 18 "golang.org/x/mobile/geom" | |
| 19 ) | |
| 20 | |
| 21 // Touch is a user touch event. | |
| 22 // | |
| 23 // On Android, this is an AInputEvent with AINPUT_EVENT_TYPE_MOTION. | |
| 24 // On iOS, it is the UIEvent delivered to a UIView. | |
| 25 type Touch struct { | |
| 26 Type TouchType | |
| 27 Loc geom.Point | |
| 28 } | |
| 29 | |
| 30 func (t Touch) String() string { | |
| 31 var ty string | |
| 32 switch t.Type { | |
| 33 case TouchStart: | |
| 34 ty = "start" | |
| 35 case TouchMove: | |
| 36 ty = "move " | |
| 37 case TouchEnd: | |
| 38 ty = "end " | |
| 39 } | |
| 40 return fmt.Sprintf("Touch{ %s, %s }", ty, t.Loc) | |
| 41 } | |
| 42 | |
| 43 // TouchType describes the type of a touch event. | |
| 44 type TouchType byte | |
| 45 | |
| 46 const ( | |
| 47 // TouchStart is a user first touching the device. | |
| 48 // | |
| 49 // On Android, this is a AMOTION_EVENT_ACTION_DOWN. | |
| 50 // On iOS, this is a call to touchesBegan. | |
| 51 TouchStart TouchType = iota | |
| 52 | |
| 53 // TouchMove is a user dragging across the device. | |
| 54 // | |
| 55 // A TouchMove is delivered between a TouchStart and TouchEnd. | |
| 56 // | |
| 57 // On Android, this is a AMOTION_EVENT_ACTION_MOVE. | |
| 58 // On iOS, this is a call to touchesMoved. | |
| 59 TouchMove | |
| 60 | |
| 61 // TouchEnd is a user no longer touching the device. | |
| 62 // | |
| 63 // On Android, this is a AMOTION_EVENT_ACTION_UP. | |
| 64 // On iOS, this is a call to touchesEnded. | |
| 65 TouchEnd | |
| 66 ) | |
| OLD | NEW |