You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

185 lines
3.5KB

  1. use crate::{
  2. ffi::{Bool, Nts},
  3. opaque_struct,
  4. };
  5. use std::os::raw;
  6. pub const WINDOW_POS_UNDEF: raw::c_int = 0x1FFF0000;
  7. bitflags::bitflags! {
  8. #[repr(transparent)]
  9. pub struct InitFlags: u32 {
  10. const TIMER = 0x01;
  11. const AUDIO = 0x10;
  12. const VIDEO = 0x20;
  13. const JOYSTICK = 0x200;
  14. const HAPTIC = 0x1000;
  15. const GAME_CONTROLLER = 0x2000;
  16. const EVENTS = 0x4000;
  17. const SENSOR = 0x8000;
  18. }
  19. }
  20. bitflags::bitflags! {
  21. #[repr(transparent)]
  22. pub struct WindowFlags: u32 {
  23. const FULLSCREEN = 0x00000001;
  24. const OPENGL = 0x00000002;
  25. const SHOWN = 0x00000004;
  26. const HIDDEN = 0x00000008;
  27. const BORDERLESS = 0x00000010;
  28. const RESIZABLE = 0x00000020;
  29. const MINIMIZED = 0x00000040;
  30. const MAXIMIZED = 0x00000080;
  31. const INPUT_GRABBED = 0x00000100;
  32. const INPUT_FOCUS = 0x00000200;
  33. const MOUSE_FOCUS = 0x00000400;
  34. const FULLSCREEN_DESKTOP = Self::FULLSCREEN.bits | 0x00001000;
  35. const FOREIGN = 0x00000800;
  36. const ALLOW_HIGH_DPI = 0x00002000;
  37. const MOUSE_CAPTURE = 0x00004000;
  38. const ALWAYS_ON_TOP = 0x00008000;
  39. const SKIP_TASKBAR = 0x00010000;
  40. const UTILITY = 0x00020000;
  41. const TOOLTIP = 0x00040000;
  42. const POPUP_MENU = 0x00080000;
  43. const VULKAN = 0x10000000;
  44. const METAL = 0x20000000;
  45. }
  46. }
  47. #[repr(u32)]
  48. #[derive(Clone, Copy)]
  49. pub enum EventType {
  50. Quit = 0x100,
  51. AppTerminating,
  52. AppLowMemory,
  53. AppWillEnterBackground,
  54. AppDidEnterBackground,
  55. AppWillEnterForeground,
  56. AppDidEnterForeground,
  57. LocaleChanged,
  58. DisplayEvent = 0x150,
  59. WindowEvent = 0x200,
  60. SysWmEvent,
  61. KeyDown = 0x300,
  62. KeyUp,
  63. TextEditing,
  64. TextInput,
  65. KeyMapChanged,
  66. MouseMotion = 0x400,
  67. MouseButtonDown,
  68. MouseButtonUp,
  69. MouseWheel,
  70. JoyAxisMotion = 0x600,
  71. JoyBallMotion,
  72. JoyHatMotion,
  73. JoyButtonDown,
  74. JoyButtonUp,
  75. JoyDeviceAdded,
  76. JoyDeviceRemoved,
  77. ControllerAxisMotion = 0x650,
  78. ControllerButtonDown,
  79. ControllerButtonUp,
  80. ControllerDeviceAdded,
  81. ControllerDeviceRemoved,
  82. ControllerDeviceRemapped,
  83. ControllerTouchPadDown,
  84. ControllerTouchPadMotion,
  85. ControllerTouchPadUp,
  86. ControllerSensorUpdate,
  87. FingerDown = 0x700,
  88. FingerUp,
  89. FingerMotion,
  90. DollarGesture = 0x800,
  91. DollarRecord,
  92. MultiGesture,
  93. ClipboardUpdate = 0x900,
  94. DropFile = 0x1000,
  95. DropText,
  96. DropBegin,
  97. DropComplete,
  98. AudioDeviceAdded = 0x1100,
  99. AudioDeviceRemoved,
  100. SensorUpdate = 0x1200,
  101. RenderTargetsReset = 0x2000,
  102. RenderDeviceReset,
  103. }
  104. #[repr(C)]
  105. #[derive(Copy, Clone)]
  106. pub struct CommonEvent {
  107. pub ty: EventType,
  108. pub time_stamp: u32,
  109. }
  110. #[repr(C)]
  111. pub union Event {
  112. pub ty: EventType,
  113. pub common: CommonEvent,
  114. _forced_size: [u8; 56],
  115. }
  116. opaque_struct!(pub Window);
  117. #[link(name = "SDL2")]
  118. extern "C" {
  119. // initialization
  120. #[link_name = "SDL_SetMainReady"]
  121. pub fn set_main_ready();
  122. #[link_name = "SDL_Init"]
  123. pub fn init(flags: InitFlags) -> raw::c_int;
  124. #[link_name = "SDL_Quit"]
  125. pub fn quit();
  126. // errors
  127. #[link_name = "SDL_GetError"]
  128. pub fn get_error() -> Nts;
  129. // events
  130. #[link_name = "SDL_PollEvent"]
  131. pub fn poll_event(event: *mut Event) -> raw::c_int;
  132. // windows
  133. #[link_name = "SDL_CreateWindow"]
  134. pub fn create_window(
  135. title: Nts, x: raw::c_int, y: raw::c_int, w: raw::c_int, h: raw::c_int,
  136. flags: WindowFlags,
  137. ) -> *mut Window;
  138. #[link_name = "SDL_DestroyWindow"]
  139. pub fn destroy_window(window: *mut Window);
  140. // vulkan
  141. #[link_name = "SDL_Vulkan_GetInstanceExtensions"]
  142. pub fn vulkan_get_instance_extensions(
  143. window: *mut Window, p_count: *mut raw::c_uint, p_names: *mut Nts,
  144. ) -> Bool;
  145. #[link_name = "SDL_Vulkan_CreateSurface"]
  146. pub fn vulkan_create_surface(
  147. window: *mut Window, instance: ash::vk::Instance,
  148. surface: *mut ash::vk::SurfaceKHR,
  149. ) -> Bool;
  150. }
  151. // EOF