event.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. // Copyright 2019 Beoran
  2. //
  3. // Licensed under the MIT LICENSE.
  4. // Package event is a package that models events that occur during
  5. // the execution of a program.
  6. package event
  7. // Event is an interface that custom events should implement.
  8. // It is empty for now because there are no general methods
  9. // required of events yet.
  10. type Event interface {
  11. }
  12. // KeyCharacter is an event that occurs when a character is actually typed on
  13. // the keyboard. This may be provided by an input method.
  14. type KeyCharacter struct {
  15. // Code is the key code of the key typed.
  16. // TODO: this should change later from an int to an enumeration type.
  17. Code int
  18. // Modifiers are the modifiers pressed together with the key.
  19. // TODO: this should change later from an int to an enumeration type.
  20. Modifiers int
  21. // Character is the character that was typed.
  22. Character rune
  23. }
  24. // KeyDown is an event that occurs when a key is pressed on the keyboard.
  25. type KeyDown struct {
  26. // Code is the key code of the key pressed or released.
  27. // TODO: this should change later from an int to an enumeration type.
  28. Code int
  29. // Modifiers are the modifiers pressed together with the key.
  30. // TODO: this should change later from an int to an enumeration type.
  31. Modifiers int
  32. }
  33. // KeyUp is an event that occurs when a key is released on the keyboard.
  34. // The data is the same as for a KeyDown event.
  35. type KeyUp KeyDown
  36. // GamepadAxis is for event where an axis on a gamepad changes.
  37. type GamepadAxis struct {
  38. // ID represents which gamepad caused the event.
  39. ID int
  40. // Axis is the axis of the game pad that changed position.
  41. Axis int
  42. // Position is the psoition of the axis after the change.
  43. // It varies between -1.0 and 1.0.
  44. Position float32
  45. }
  46. // GamepadButtonDown is a gamepad button press event.
  47. type GamepadButtonDown struct {
  48. // ID represents which gamepad caused the event.
  49. ID int
  50. // Button is the button that was pressed on the game pad.
  51. Button int
  52. // Pressure is the pressure that is applied to the gamepad button.
  53. // It varies between 0.0 for not pressed, and 1.0 for completely pressed.
  54. Pressure float32
  55. }
  56. // GamepadButtonDown is a gamepad button release event.
  57. // The data is identical to a GamePadButtonDown event.
  58. type GamepadButtonUp GamepadButtonDown
  59. // GamepadAttach happens when a new gamepad is attached.
  60. type GamepadAttach struct {
  61. // ID represents which gamepad caused the event.
  62. ID int
  63. // Axes represents the amount of axes the gamepad has.
  64. Axes int
  65. // Buttons represents the amount of buttons the gamepad has.
  66. Buttons int
  67. }
  68. // GamepadDetach happens when a gamepad is detached.
  69. type GamepadDetach struct {
  70. // ID represents which gamepad caused the event.
  71. ID int
  72. }
  73. // MouseMove is a mouse movement event.
  74. type MouseMove struct {
  75. // X is the X position of the mouse pointer.
  76. // This value is expressed in device independent pixels.
  77. X float32
  78. // Y is the Y position of the mouse pointer.
  79. // This value is expressed in device independent pixels.
  80. Y float32
  81. // DeltaX is the change in X since the last MouseMove event.
  82. // This value is expressed in device independent pixels.
  83. DeltaX float32
  84. // DeltaY is the change in Y since the last MouseMove event.
  85. // This value is expressed in device independent pixels.
  86. DeltaY float32
  87. }
  88. // MouseWheel is a mouse wheel event.
  89. type MouseWheel struct {
  90. // X is the X position of the mouse wheel.
  91. // This value is expressed in arbitrary units.
  92. // It increases when the mouse wheel is scrolled downwards,
  93. // and decreases when the mouse is scrolled upwards.
  94. X float32
  95. // Y is the Y position of the mouse wheel.
  96. // This value is expressed in arbitrary units.
  97. // It increases when the mouse wheel is scrolled to the right,
  98. // and decreases when the mouse is scrolled to the left.
  99. Y float32
  100. // DeltaX is the change in X since the last MouseWheel event.
  101. // This value is expressed in arbitrary units.
  102. // It is positive when the mouse wheel is scrolled downwards,
  103. // and negative when the mouse is scrolled upwards.
  104. DeltaX float32
  105. // DeltaY is the change in Y since the last MouseWheel event.
  106. // This value is expressed in arbitrary units.
  107. // It is positive when the mouse wheel is scrolled to the right,
  108. // and negative when the mouse is scrolled to the left.
  109. DeltaY float32
  110. }
  111. // MouseButtonDown is a mouse button press event.
  112. type MouseButtonDown struct {
  113. // X is the X position of the mouse pointer.
  114. // This value is expressed in device independent pixels.
  115. X float32
  116. // Y is the Y position of the mouse pointer.
  117. // This value is expressed in device independent pixels.
  118. Y float32
  119. // Button is the button on the mouse that was pressed.
  120. // TODO: this should change later from an int to an enumeration type.
  121. Button int
  122. // Pressure is the pressure applied on the mouse button.
  123. // It varies between 0.0 for not pressed, and 1.0 for completely pressed.
  124. Pressure float32
  125. }
  126. // MouseButtonDown is a mouse button Release event.
  127. // The data is identical to a MouseButtonDown event.
  128. type MouseButtonUp MouseButtonDown
  129. // MouseEnter occurs when the mouse enters the view window.
  130. type MouseEnter struct {
  131. // X is the X position of the mouse pointer.
  132. // This value is expressed in device independent pixels.
  133. X float32
  134. // Y is the Y position of the mouse pointer.
  135. // This value is expressed in device independent pixels.
  136. Y float32
  137. }
  138. // MouseLeave occurs when the mouse leaves the view window.
  139. // The data is identical to MouseEnter.
  140. type MouseLeave MouseEnter
  141. // ViewUpdate occurs when the application is ready to update
  142. // the next frame on the view port.
  143. type ViewUpdate struct {
  144. // No data neccesary, for now.
  145. }
  146. // ViewSize occurs when the size of the application's view port changes.
  147. type ViewSize struct {
  148. // Width is the width of the view.
  149. // This value is expressed in device independent pixels.
  150. Width int
  151. // Height is the height of the view.
  152. // This value is expressed in device independent pixels.
  153. Height int
  154. }
  155. // TouchBegin occurs when a touch begins.
  156. type TouchBegin struct {
  157. // ID identifies the touch that caused the touch event.
  158. ID int
  159. // X is the X position of the touch.
  160. // This value is expressed in device independent pixels.
  161. X float32
  162. // Y is the Y position of the touch.
  163. // This value is expressed in device independent pixels.
  164. Y float32
  165. // Pressure is the pressure applied to the touch.
  166. // It varies between 0.0 for not pressed, and 1.0 for completely pressed.
  167. Pressure float32
  168. // Primary represents whether the touch event is the primary touch or not.
  169. // If it is true, then it is a primary touch.
  170. // Otherwise it is false.
  171. Primary bool
  172. }
  173. // TouchMove occurs when a touch moved, or in other words, is dragged.
  174. type TouchMove struct {
  175. // ID identifies the touch that caused the touch event.
  176. ID int
  177. // X is the X position of the touch.
  178. // This value is expressed in device independent pixels.
  179. X float32
  180. // Y is the Y position of the touch.
  181. // This value is expressed in device independent pixels.
  182. Y float32
  183. // DeltaX is the change in X since last touch event.
  184. // This value is expressed in device independent pixels.
  185. DeltaX float32
  186. // Deltay is the change in Y since last touch event.
  187. // This value is expressed in device independent pixels.
  188. DeltaY float32
  189. // Pressure of applied touch.
  190. // It varies between 0.0 for not pressed, and 1.0 for completely pressed.
  191. Pressure float32
  192. // Primary represents whether the touch event is the primary touch or not.
  193. // If it is true, then it is a primary touch.
  194. // If it is false then it is not.
  195. Primary bool
  196. }
  197. // TouchEnd occurs when a touch ends.
  198. // The data is the same as for a TouchMove event.
  199. type TouchEnd TouchMove
  200. // TouchCancel occurs when a touch is canceled.
  201. // This can happen in various situations, depending on the underlying platform,
  202. // for example when the aplication loses focus.
  203. type TouchCancel struct {
  204. // ID identifies the touch that caused the touch event.
  205. ID int
  206. }