event.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package gg
  2. import (
  3. //"github.com/hajimehoshi/ebiten/v2"
  4. )
  5. import "surdeus.su/core/gg/mx"
  6. func diffEm[V comparable](s1, s2 []V) []V {
  7. combinedSlice := append(s1, s2...)
  8. dm := make(map[V]int)
  9. for _, v := range combinedSlice {
  10. if _, ok := dm[v]; ok {
  11. // remove element later as it exist in both slice.
  12. dm[v] += 1
  13. continue
  14. }
  15. // new entry, add in map!
  16. dm[v] = 1
  17. }
  18. var retSlice []V
  19. for k, v := range dm {
  20. if v == 1 {
  21. retSlice = append(retSlice, k)
  22. }
  23. }
  24. return retSlice
  25. }
  26. // The type represents event of a
  27. // key getting pressed down.
  28. type KeyDown struct {
  29. Key
  30. }
  31. // The type represents event of a
  32. // key getting pressed up.
  33. type KeyUp struct {
  34. Key
  35. }
  36. // The type represents event of a
  37. // mouse button being pressed down.
  38. type MouseButtonDown struct {
  39. MouseButton
  40. Position mx.Vector
  41. }
  42. // The type represents event of a
  43. // mouse button being pressed up.
  44. type MouseButtonUp struct {
  45. MouseButton
  46. Positon mx.Vector
  47. }
  48. // The type represents
  49. // event of moving the mouse.
  50. type MouseMove struct {
  51. // Real and absolute deltas
  52. // for the mouse movement.
  53. RealDelta, AbsDelta mx.Vector
  54. }
  55. // The type represents event
  56. // of a wheel change.
  57. type WheelChange struct {
  58. Offset mx.Vector
  59. }
  60. type KeyboardEvents struct {
  61. Downs []KeyDown
  62. Ups []KeyUp
  63. }
  64. type MouseEvents struct {
  65. Downs []MouseButtonDown
  66. Ups []MouseButtonUp
  67. Move *MouseMove
  68. Wheel *WheelChange
  69. }
  70. type Events struct {
  71. Keyboard KeyboardEvents
  72. Mouse MouseEvents
  73. }
  74. type EventChan chan any