github.com/as/shiny@v0.8.2/event/touch/touch.go (about) 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 package touch 7 8 // The best source on android input events is the NDK: include/android/input.h 9 // 10 // iOS event handling guide: 11 // https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS 12 13 import ( 14 "fmt" 15 ) 16 17 // Event is a touch event. 18 type Event struct { 19 // X and Y are the touch location, in pixels. 20 X, Y float32 21 22 // Sequence is the sequence number. The same number is shared by all events 23 // in a sequence. A sequence begins with a single TypeBegin, is followed by 24 // zero or more TypeMoves, and ends with a single TypeEnd. A Sequence 25 // distinguishes concurrent sequences but its value is subsequently reused. 26 Sequence Sequence 27 28 // Type is the touch type. 29 Type Type 30 } 31 32 // Sequence identifies a sequence of touch events. 33 type Sequence int64 34 35 // Type describes the type of a touch event. 36 type Type byte 37 38 const ( 39 // TypeBegin is a user first touching the device. 40 // 41 // On Android, this is a AMOTION_EVENT_ACTION_DOWN. 42 // On iOS, this is a call to touchesBegan. 43 TypeBegin Type = iota 44 45 // TypeMove is a user dragging across the device. 46 // 47 // A TypeMove is delivered between a TypeBegin and TypeEnd. 48 // 49 // On Android, this is a AMOTION_EVENT_ACTION_MOVE. 50 // On iOS, this is a call to touchesMoved. 51 TypeMove 52 53 // TypeEnd is a user no longer touching the device. 54 // 55 // On Android, this is a AMOTION_EVENT_ACTION_UP. 56 // On iOS, this is a call to touchesEnded. 57 TypeEnd 58 ) 59 60 func (t Type) String() string { 61 switch t { 62 case TypeBegin: 63 return "begin" 64 case TypeMove: 65 return "move" 66 case TypeEnd: 67 return "end" 68 } 69 return fmt.Sprintf("touch.Type(%d)", t) 70 }