mouse.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 mouse defines an event for mouse input.
  5. //
  6. // See the golang.org/x/mobile/app package for details on the event model.
  7. package mouse // import "golang.org/x/mobile/event/mouse"
  8. import (
  9. "fmt"
  10. "golang.org/x/mobile/event/key"
  11. )
  12. // Event is a mouse event.
  13. type Event struct {
  14. // X and Y are the mouse location, in pixels.
  15. X, Y float32
  16. // Button is the mouse button being pressed or released. Its value may be
  17. // zero, for a mouse move or drag without any button change.
  18. Button Button
  19. // TODO: have a field to hold what other buttons are down, for detecting
  20. // drags or button-chords.
  21. // Modifiers is a bitmask representing a set of modifier keys:
  22. // key.ModShift, key.ModAlt, etc.
  23. Modifiers key.Modifiers
  24. // Direction is the direction of the mouse event: DirPress, DirRelease,
  25. // or DirNone (for mouse moves or drags).
  26. Direction Direction
  27. // TODO: add a Device ID, for multiple input devices?
  28. // TODO: add a time.Time?
  29. }
  30. // Button is a mouse button.
  31. type Button int32
  32. // IsWheel reports whether the button is for a scroll wheel.
  33. func (b Button) IsWheel() bool {
  34. return b < 0
  35. }
  36. // TODO: have a separate axis concept for wheel up/down? How does that relate
  37. // to joystick events?
  38. const (
  39. ButtonNone Button = +0
  40. ButtonLeft Button = +1
  41. ButtonMiddle Button = +2
  42. ButtonRight Button = +3
  43. ButtonWheelUp Button = -1
  44. ButtonWheelDown Button = -2
  45. ButtonWheelLeft Button = -3
  46. ButtonWheelRight Button = -4
  47. )
  48. // Direction is the direction of the mouse event.
  49. type Direction uint8
  50. const (
  51. DirNone Direction = 0
  52. DirPress Direction = 1
  53. DirRelease Direction = 2
  54. // DirStep is a simultaneous press and release, such as a single step of a
  55. // mouse wheel.
  56. //
  57. // Its value equals DirPress | DirRelease.
  58. DirStep Direction = 3
  59. )
  60. func (d Direction) String() string {
  61. switch d {
  62. case DirNone:
  63. return "None"
  64. case DirPress:
  65. return "Press"
  66. case DirRelease:
  67. return "Release"
  68. case DirStep:
  69. return "Step"
  70. default:
  71. return fmt.Sprintf("mouse.Direction(%d)", d)
  72. }
  73. }