touch.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. // Package touch defines an event for touch input.
  5. //
  6. // See the golang.org/x/mobile/app package for details on the event model.
  7. package touch // import "golang.org/x/mobile/event/touch"
  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. import (
  13. "fmt"
  14. )
  15. // Event is a touch event.
  16. type Event struct {
  17. // X and Y are the touch location, in pixels.
  18. X, Y float32
  19. // Sequence is the sequence number. The same number is shared by all events
  20. // in a sequence. A sequence begins with a single TypeBegin, is followed by
  21. // zero or more TypeMoves, and ends with a single TypeEnd. A Sequence
  22. // distinguishes concurrent sequences but its value is subsequently reused.
  23. Sequence Sequence
  24. // Type is the touch type.
  25. Type Type
  26. }
  27. // Sequence identifies a sequence of touch events.
  28. type Sequence int64
  29. // Type describes the type of a touch event.
  30. type Type byte
  31. const (
  32. // TypeBegin is a user first touching the device.
  33. //
  34. // On Android, this is a AMOTION_EVENT_ACTION_DOWN.
  35. // On iOS, this is a call to touchesBegan.
  36. TypeBegin Type = iota
  37. // TypeMove is a user dragging across the device.
  38. //
  39. // A TypeMove is delivered between a TypeBegin and TypeEnd.
  40. //
  41. // On Android, this is a AMOTION_EVENT_ACTION_MOVE.
  42. // On iOS, this is a call to touchesMoved.
  43. TypeMove
  44. // TypeEnd is a user no longer touching the device.
  45. //
  46. // On Android, this is a AMOTION_EVENT_ACTION_UP.
  47. // On iOS, this is a call to touchesEnded.
  48. TypeEnd
  49. )
  50. func (t Type) String() string {
  51. switch t {
  52. case TypeBegin:
  53. return "begin"
  54. case TypeMove:
  55. return "move"
  56. case TypeEnd:
  57. return "end"
  58. }
  59. return fmt.Sprintf("touch.Type(%d)", t)
  60. }