SDLEvents.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace AtomicEngine
  4. {
  5. public static class SDLEvents
  6. {
  7. [DllImport(Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl)]
  8. static extern int SDL_SendWindowEvent(IntPtr window, byte windowevent, int data1, int data2);
  9. [DllImport(Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl)]
  10. static extern int SDL_SendAppEvent(byte eventType);
  11. [DllImport(Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl)]
  12. static extern void SDL_SetMainReady();
  13. public static void SetMainReady() => SDL_SetMainReady();
  14. public static void SendWindowEvent(SdlWindowEvent wndEvent, int data1 = 0, int data2 = 0)
  15. {
  16. var graphics = AtomicNET.GetSubsystem<Graphics>();
  17. SDL_SendWindowEvent(graphics.SDLWindow, (byte) wndEvent, data1, data2);
  18. }
  19. public static void SendAppEvent(SdlEventType eventType) => SDL_SendAppEvent((byte)eventType);
  20. }
  21. //see SDL_Video.h
  22. public enum SdlWindowEvent
  23. {
  24. SDL_WINDOWEVENT_NONE, /* Never used */
  25. SDL_WINDOWEVENT_SHOWN, /* Window has been shown */
  26. SDL_WINDOWEVENT_HIDDEN, /* Window has been hidden */
  27. SDL_WINDOWEVENT_EXPOSED, /* Window has been exposed and should be redrawn */
  28. SDL_WINDOWEVENT_MOVED, /* Window has been moved to data1, data2 */
  29. SDL_WINDOWEVENT_RESIZED, /* Window has been resized to data1xdata2 */
  30. SDL_WINDOWEVENT_SIZE_CHANGED, /* The window size has changed, either as a result of an API call or through the system or user changing the window size. */
  31. SDL_WINDOWEVENT_MINIMIZED, /* Window has been minimized */
  32. SDL_WINDOWEVENT_MAXIMIZED, /* Window has been maximized */
  33. SDL_WINDOWEVENT_RESTORED, /* Window has been restored to normal size and position */
  34. SDL_WINDOWEVENT_ENTER, /* Window has gained mouse focus */
  35. SDL_WINDOWEVENT_LEAVE, /* Window has lost mouse focus */
  36. SDL_WINDOWEVENT_FOCUS_GAINED, /* Window has gained keyboard focus */
  37. SDL_WINDOWEVENT_FOCUS_LOST, /* Window has lost keyboard focus */
  38. SDL_WINDOWEVENT_CLOSE /* The window manager requests that the window be closed */
  39. }
  40. //see SDL_Events.h
  41. public enum SdlEventType
  42. {
  43. SDL_FIRSTEVENT = 0, /**< Unused (do not remove) */
  44. /* Application events */
  45. SDL_QUIT = 0x100, /**< User-requested quit */
  46. /* These application events have special meaning on iOS, see README-ios.txt for details */
  47. SDL_APP_TERMINATING, /**< The application is being terminated by the OS
  48. Called on iOS in applicationWillTerminate()
  49. Called on Android in onDestroy()
  50. */
  51. SDL_APP_LOWMEMORY, /**< The application is low on memory, free memory if possible.
  52. Called on iOS in applicationDidReceiveMemoryWarning()
  53. Called on Android in onLowMemory()
  54. */
  55. SDL_APP_WILLENTERBACKGROUND, /**< The application is about to enter the background
  56. Called on iOS in applicationWillResignActive()
  57. Called on Android in onPause()
  58. */
  59. SDL_APP_DIDENTERBACKGROUND, /**< The application did enter the background and may not get CPU for some time
  60. Called on iOS in applicationDidEnterBackground()
  61. Called on Android in onPause()
  62. */
  63. SDL_APP_WILLENTERFOREGROUND, /**< The application is about to enter the foreground
  64. Called on iOS in applicationWillEnterForeground()
  65. Called on Android in onResume()
  66. */
  67. SDL_APP_DIDENTERFOREGROUND, /**< The application is now interactive
  68. Called on iOS in applicationDidBecomeActive()
  69. Called on Android in onResume()
  70. */
  71. /* Window events */
  72. SDL_WINDOWEVENT = 0x200, /**< Window state change */
  73. SDL_SYSWMEVENT, /**< System specific event */
  74. /* Keyboard events */
  75. SDL_KEYDOWN = 0x300, /**< Key pressed */
  76. SDL_KEYUP, /**< Key released */
  77. SDL_TEXTEDITING, /**< Keyboard text editing (composition) */
  78. SDL_TEXTINPUT, /**< Keyboard text input */
  79. /* Mouse events */
  80. SDL_MOUSEMOTION = 0x400, /**< Mouse moved */
  81. SDL_MOUSEBUTTONDOWN, /**< Mouse button pressed */
  82. SDL_MOUSEBUTTONUP, /**< Mouse button released */
  83. SDL_MOUSEWHEEL, /**< Mouse wheel motion */
  84. /* Joystick events */
  85. SDL_JOYAXISMOTION = 0x600, /**< Joystick axis motion */
  86. SDL_JOYBALLMOTION, /**< Joystick trackball motion */
  87. SDL_JOYHATMOTION, /**< Joystick hat position change */
  88. SDL_JOYBUTTONDOWN, /**< Joystick button pressed */
  89. SDL_JOYBUTTONUP, /**< Joystick button released */
  90. SDL_JOYDEVICEADDED, /**< A new joystick has been inserted into the system */
  91. SDL_JOYDEVICEREMOVED, /**< An opened joystick has been removed */
  92. /* Game controller events */
  93. SDL_CONTROLLERAXISMOTION = 0x650, /**< Game controller axis motion */
  94. SDL_CONTROLLERBUTTONDOWN, /**< Game controller button pressed */
  95. SDL_CONTROLLERBUTTONUP, /**< Game controller button released */
  96. SDL_CONTROLLERDEVICEADDED, /**< A new Game controller has been inserted into the system */
  97. SDL_CONTROLLERDEVICEREMOVED, /**< An opened Game controller has been removed */
  98. SDL_CONTROLLERDEVICEREMAPPED, /**< The controller mapping was updated */
  99. /* Touch events */
  100. SDL_FINGERDOWN = 0x700,
  101. SDL_FINGERUP,
  102. SDL_FINGERMOTION,
  103. /* Gesture events */
  104. SDL_DOLLARGESTURE = 0x800,
  105. SDL_DOLLARRECORD,
  106. SDL_MULTIGESTURE,
  107. /* Clipboard events */
  108. SDL_CLIPBOARDUPDATE = 0x900, /**< The clipboard changed */
  109. /* Drag and drop events */
  110. SDL_DROPFILE = 0x1000, /**< The system requests a file open */
  111. /* Render events */
  112. SDL_RENDER_TARGETS_RESET = 0x2000, /**< The render targets have been reset */
  113. /** Events ::SDL_USEREVENT through ::SDL_LASTEVENT are for your use,
  114. * and should be allocated with SDL_RegisterEvents()
  115. */
  116. SDL_USEREVENT = 0x8000,
  117. /**
  118. * This last event is only for bounding internal arrays
  119. */
  120. SDL_LASTEVENT = 0xFFFF
  121. }
  122. }