]> git.nega.tv - josh/narcissus/commitdiff
narcissus-app: Switch to sdl3
authorJosh Simmons <josh@nega.tv>
Sat, 16 Nov 2024 15:21:11 +0000 (16:21 +0100)
committerJosh Simmons <josh@nega.tv>
Sat, 16 Nov 2024 19:49:09 +0000 (20:49 +0100)
Remove manual SDL2 bindings, and switch to sdl3-sys crate.
Improve handling of HiDPI monitors for shark.

Cargo.lock
Cargo.toml
engine/narcissus-app/Cargo.toml
engine/narcissus-app/src/button.rs [deleted file]
engine/narcissus-app/src/key.rs
engine/narcissus-app/src/lib.rs
engine/narcissus-app/src/sdl.rs
external/sdl2-sys/Cargo.toml [deleted file]
external/sdl2-sys/build.rs [deleted file]
external/sdl2-sys/src/lib.rs [deleted file]
title/shark/src/main.rs

index 510ffc8f22d1360d6897e879b36b5e5be6b6717f..d2bf7d2ff860072ffdec83e81a19311faaada9d2 100644 (file)
@@ -67,7 +67,7 @@ name = "narcissus-app"
 version = "0.1.0"
 dependencies = [
  "narcissus-core",
- "sdl2-sys",
+ "sdl3-sys",
 ]
 
 [[package]]
@@ -171,8 +171,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
 
 [[package]]
-name = "sdl2-sys"
-version = "0.1.0"
+name = "sdl3-sys"
+version = "0.1.2+SDL3-preview-3.1.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "48501d90bf219bf3126b26155c04834af300088432f98c6985aa8ad3a2441baa"
 
 [[package]]
 name = "shark"
index 3cc5ecadd26099c5abc29bb3e3b54e22259144ee..fabaec9968538ee999e78208b1356365f6c6ed27 100644 (file)
@@ -5,7 +5,6 @@ members = [
     "title/shark-shaders",
     "external/blake3-smol",
     "external/renderdoc-sys",
-    "external/sdl2-sys",
     "external/sqlite-sys",
     "external/stb_image-sys",
     "external/stb_truetype-sys",
index 73f7559948f77391a087baff2618d1a0b50de37b..edfc212649878d4cfa50bb3b0e7890d04096f5c1 100644 (file)
@@ -7,4 +7,4 @@ edition = "2021"
 
 [dependencies]
 narcissus-core = { path = "../narcissus-core" }
-sdl2-sys = { path = "../../external/sdl2-sys" }
\ No newline at end of file
+sdl3-sys = "0.1.2"
\ No newline at end of file
diff --git a/engine/narcissus-app/src/button.rs b/engine/narcissus-app/src/button.rs
deleted file mode 100644 (file)
index 73da975..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
-pub enum Button {
-    Left,
-    Middle,
-    Right,
-    X1,
-    X2,
-}
index 265f447c7cf14308a43ad49701c5c119e8454ca2..fd6d3860872e85b842585d99adfae76706c1634b 100644 (file)
@@ -119,7 +119,7 @@ pub enum Key {
     NumpadPlusMinus,
     NumpadComma,
 
-    Eject,
+    MediaEject,
     Stop,
     Mute,
     VolumeUp,
@@ -150,25 +150,9 @@ pub enum Key {
     Find,
     Cut,
     Help,
-    Calculator,
     AltErase,
     Cancel,
 
-    BrightnessUp,
-    BrightnessDown,
-
-    SwitchVideoMode,
-
-    KeyboardIlluminationToggle,
-    KeyboardIlluminationDown,
-    KeyboardIlluminationUp,
-
-    App1,
-    App2,
-    WWW,
-    Mail,
-    Computer,
-
     ACBookmarks,
     ACBack,
     ACForward,
@@ -176,12 +160,12 @@ pub enum Key {
     ACRefresh,
     ACSearch,
 
-    AudioNext,
-    AudioPlay,
-    AudioPrev,
-    AudioStop,
-    AudioRewind,
-    AudioFastForward,
+    MediaNextTrack,
+    MediaPlay,
+    MediaPreviousTrack,
+    MediaStop,
+    MediaRewind,
+    MediaFastForward,
 
     Language1,
     Language2,
index dc6205dd5f2e00b2d747cd7041b12b8bb612627c..f4f2d3b79ef50e448ad71d79a4fd9ff269e8c8a9 100644 (file)
@@ -1,4 +1,3 @@
-mod button;
 mod key;
 mod sdl;
 
@@ -6,13 +5,15 @@ use std::rc::Rc;
 
 use narcissus_core::{flags_def, raw_window::AsRawWindow, Upcast};
 
-pub use button::Button;
 pub use key::Key;
 
-#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
-pub enum PressedState {
-    Released,
-    Pressed,
+flags_def!(ButtonFlags);
+impl ButtonFlags {
+    pub const LEFT: Self = Self(1 << 0);
+    pub const MIDDLE: Self = Self(1 << 1);
+    pub const RIGHT: Self = Self(1 << 2);
+    pub const X1: Self = Self(1 << 3);
+    pub const X2: Self = Self(1 << 4);
 }
 
 flags_def!(ModifierFlags);
@@ -35,11 +36,13 @@ pub struct WindowId(u64);
 pub trait Window: AsRawWindow + Upcast<dyn AsRawWindow> {
     fn id(&self) -> WindowId;
 
-    fn extent(&self) -> (u32, u32);
-    fn drawable_extent(&self) -> (u32, u32);
+    fn size(&self) -> (u32, u32);
+    fn size_in_pixels(&self) -> (u32, u32);
+
+    fn display_scale(&self) -> f32;
 }
 
-#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
+#[derive(Clone, Copy, PartialEq, Debug)]
 #[non_exhaustive]
 pub enum Event {
     Unknown,
@@ -49,20 +52,20 @@ pub enum Event {
         window_id: WindowId,
         key: Key,
         repeat: bool,
-        pressed: PressedState,
+        down: bool,
         modifiers: ModifierFlags,
     },
 
     ButtonPress {
         window_id: WindowId,
-        button: Button,
-        pressed: PressedState,
+        buttons: ButtonFlags,
+        down: bool,
     },
 
     MouseMotion {
         window_id: WindowId,
-        x: i32,
-        y: i32,
+        x: f32,
+        y: f32,
     },
 
     /// A window has gained mouse focus.
@@ -80,28 +83,46 @@ pub enum Event {
     },
 
     /// A window has gained keyboard focus.
-    FocusIn {
+    FocusGained {
         window_id: WindowId,
     },
 
     /// A window has lost keyboard focus.
-    FocusOut {
+    FocusLost {
         window_id: WindowId,
     },
 
-    /// The window has been resized.
+    /// A window has been resized.
+    ///
+    /// `width` contains the new window size in logical pixel units.
+    /// `height` contains the new window size in logical pixel units.
     Resize {
         window_id: WindowId,
         width: u32,
         height: u32,
     },
 
-    // The close button has been pressed on the window.
-    Close {
+    /// A window has been resized.
+    ///
+    /// `width` contains the new window size in native pixel units.
+    /// `height` contains the new window size in native pixel units.
+    ResizePixels {
+        window_id: WindowId,
+        width: u32,
+        height: u32,
+    },
+
+    /// A window has changed display scale.
+    ScaleChanged {
+        window_id: WindowId,
+    },
+
+    /// The close button has been pressed on the window.
+    CloseRequested {
         window_id: WindowId,
     },
 
-    // The window has been destroyed.
+    /// The window has been destroyed.
     Destroy {
         window_id: WindowId,
     },
index 4e39553f6fad7310b222f805ba091c7b9eeff880..167680111a4b4ea7db4cf7255bca4687ff785909 100644 (file)
-use std::{collections::HashMap, ffi::CString, mem::MaybeUninit, rc::Rc};
+use std::{
+    collections::HashMap,
+    ffi::{CStr, CString},
+    mem::MaybeUninit,
+    rc::Rc,
+};
 
-use crate::{App, Button, Event, Key, ModifierFlags, PressedState, Window, WindowId};
+use crate::{App, ButtonFlags, Event, Key, ModifierFlags, Window, WindowId};
 
 use narcissus_core::{
     raw_window::{AsRawWindow, RawWindow, WaylandWindow, XlibWindow},
     Mutex, Upcast,
 };
-use sdl2_sys as sdl;
+use sdl3_sys::{
+    events::{
+        SDL_EventType, SDL_PollEvent, SDL_EVENT_KEY_DOWN, SDL_EVENT_KEY_UP,
+        SDL_EVENT_MOUSE_BUTTON_DOWN, SDL_EVENT_MOUSE_BUTTON_UP, SDL_EVENT_MOUSE_MOTION,
+        SDL_EVENT_QUIT, SDL_EVENT_WINDOW_CLOSE_REQUESTED, SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED,
+        SDL_EVENT_WINDOW_FOCUS_GAINED, SDL_EVENT_WINDOW_FOCUS_LOST, SDL_EVENT_WINDOW_MOUSE_ENTER,
+        SDL_EVENT_WINDOW_MOUSE_LEAVE, SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED,
+        SDL_EVENT_WINDOW_RESIZED,
+    },
+    init::{SDL_InitSubSystem, SDL_Quit, SDL_INIT_VIDEO},
+    keycode::*,
+    mouse::{
+        SDL_BUTTON_LMASK, SDL_BUTTON_MMASK, SDL_BUTTON_RMASK, SDL_BUTTON_X1MASK, SDL_BUTTON_X2MASK,
+    },
+    properties::{SDL_GetNumberProperty, SDL_GetPointerProperty},
+    scancode::*,
+    video::{
+        SDL_CreateWindow, SDL_DestroyWindow, SDL_GetCurrentVideoDriver, SDL_GetWindowDisplayScale,
+        SDL_GetWindowID, SDL_GetWindowProperties, SDL_GetWindowSize, SDL_GetWindowSizeInPixels,
+        SDL_Window, SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER,
+        SDL_PROP_WINDOW_WAYLAND_SURFACE_POINTER, SDL_PROP_WINDOW_X11_DISPLAY_POINTER,
+        SDL_PROP_WINDOW_X11_WINDOW_NUMBER, SDL_WINDOW_HIGH_PIXEL_DENSITY, SDL_WINDOW_RESIZABLE,
+        SDL_WINDOW_VULKAN,
+    },
+};
 
 fn sdl_window_id(window_id: u32) -> WindowId {
     WindowId(window_id as u64)
 }
 
 struct SdlWindow {
-    window: *mut sdl::Window,
+    window: *mut SDL_Window,
 }
 
 impl Window for SdlWindow {
     fn id(&self) -> WindowId {
-        sdl_window_id(unsafe { sdl::SDL_GetWindowID(self.window) })
+        sdl_window_id(unsafe { SDL_GetWindowID(self.window) })
     }
 
-    fn extent(&self) -> (u32, u32) {
+    fn size(&self) -> (u32, u32) {
         let mut width = 0;
         let mut height = 0;
-        unsafe {
-            sdl::SDL_GetWindowSize(self.window, &mut width, &mut height);
+        if !unsafe { SDL_GetWindowSize(self.window, &mut width, &mut height) } {
+            #[cfg(debug_assertions)]
+            panic!("failed to retreive window size");
         }
         (width as u32, height as u32)
     }
 
-    fn drawable_extent(&self) -> (u32, u32) {
+    fn size_in_pixels(&self) -> (u32, u32) {
         let mut width = 0;
         let mut height = 0;
-        unsafe {
-            sdl::SDL_Vulkan_GetDrawableSize(self.window, &mut width, &mut height);
+        if !unsafe { SDL_GetWindowSizeInPixels(self.window, &mut width, &mut height) } {
+            #[cfg(debug_assertions)]
+            panic!("failed to retreive window size in pixels");
         }
         (width as u32, height as u32)
     }
+
+    fn display_scale(&self) -> f32 {
+        unsafe { SDL_GetWindowDisplayScale(self.window) }
+    }
 }
 
 impl AsRawWindow for SdlWindow {
     fn as_raw_window(&self) -> RawWindow {
-        let wm_info = unsafe {
-            let mut wm_info = MaybeUninit::<sdl::SysWMinfo>::zeroed();
-            std::ptr::write(
-                std::ptr::addr_of_mut!((*wm_info.as_mut_ptr()).version),
-                sdl::Version::current(),
+        let properties = unsafe { SDL_GetWindowProperties(self.window) };
+
+        #[cfg(target_os = "linux")]
+        {
+            let current_video_driver = unsafe { SDL_GetCurrentVideoDriver() };
+            assert_ne!(
+                current_video_driver,
+                core::ptr::null(),
+                "no video driver initialized"
             );
-            let res = sdl::SDL_GetWindowWMInfo(self.window, wm_info.as_mut_ptr());
-            assert_eq!(res, sdl::Bool::True);
-            wm_info.assume_init()
-        };
 
-        match wm_info.subsystem {
-            sdl::SysWMType::X11 => RawWindow::Xlib(XlibWindow {
-                display: unsafe { wm_info.info.x11.display },
-                window: unsafe { wm_info.info.x11.window },
-            }),
-            sdl::SysWMType::WAYLAND => RawWindow::Wayland(WaylandWindow {
-                display: unsafe { wm_info.info.wayland.display },
-                surface: unsafe { wm_info.info.wayland.surface },
-            }),
-            _ => panic!("unspported wm system"),
+            // Safety: null-checked above, SDL ensures return value is a null-terminated ascii string.
+            let current_video_driver = unsafe {
+                CStr::from_ptr(current_video_driver)
+                    .to_str()
+                    .expect("invalid video driver")
+            };
+
+            match current_video_driver {
+                "wayland" => {
+                    let display = unsafe {
+                        SDL_GetPointerProperty(
+                            properties,
+                            SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER,
+                            core::ptr::null_mut(),
+                        )
+                    };
+                    let surface = unsafe {
+                        SDL_GetPointerProperty(
+                            properties,
+                            SDL_PROP_WINDOW_WAYLAND_SURFACE_POINTER,
+                            core::ptr::null_mut(),
+                        )
+                    };
+                    RawWindow::Wayland(WaylandWindow { display, surface })
+                }
+                "x11" => {
+                    let display = unsafe {
+                        SDL_GetPointerProperty(
+                            properties,
+                            SDL_PROP_WINDOW_X11_DISPLAY_POINTER,
+                            core::ptr::null_mut(),
+                        )
+                    };
+                    let window = unsafe {
+                        SDL_GetNumberProperty(properties, SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0)
+                    } as i32;
+                    RawWindow::Xlib(XlibWindow { display, window })
+                }
+                _ => {
+                    panic!("unknown sdl video driver")
+                }
+            }
         }
+
+        #[cfg(not(target_os = "linux"))]
+        panic!("unsupported os")
     }
 }
 
@@ -79,7 +149,10 @@ pub struct SdlApp {
 
 impl SdlApp {
     pub fn new() -> Result<Self, ()> {
-        unsafe { sdl::SDL_Init(sdl::INIT_VIDEO) };
+        if !unsafe { SDL_InitSubSystem(SDL_INIT_VIDEO) } {
+            panic!("failed to initalize sdl");
+        }
+
         Ok(Self {
             windows: Mutex::new(HashMap::new()),
         })
@@ -89,9 +162,9 @@ impl SdlApp {
 impl Drop for SdlApp {
     fn drop(&mut self) {
         for window in self.windows.get_mut().values() {
-            unsafe { sdl::SDL_DestroyWindow(window.window) };
+            unsafe { SDL_DestroyWindow(window.window) };
         }
-        unsafe { sdl::SDL_Quit() };
+        unsafe { SDL_Quit() };
     }
 }
 
@@ -99,20 +172,15 @@ impl App for SdlApp {
     fn create_window(&self, desc: &crate::WindowDesc) -> Rc<dyn Window> {
         let title = CString::new(desc.title).unwrap();
         let window = unsafe {
-            sdl::SDL_CreateWindow(
+            SDL_CreateWindow(
                 title.as_ptr(),
-                0,
-                0,
                 desc.width as i32,
                 desc.height as i32,
-                sdl::WINDOW_VULKAN
-                    | sdl::WINDOW_SHOWN
-                    | sdl::WINDOW_RESIZABLE
-                    | sdl::WINDOW_ALLOW_HIGHDPI,
+                SDL_WINDOW_VULKAN | SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_RESIZABLE,
             )
         };
         assert!(!window.is_null());
-        let window_id = WindowId(unsafe { sdl::SDL_GetWindowID(window) } as u64);
+        let window_id = WindowId(unsafe { SDL_GetWindowID(window) } as u64);
         let window = Rc::new(SdlWindow { window });
         self.windows.lock().insert(window_id, window.clone());
         window
@@ -124,89 +192,82 @@ impl App for SdlApp {
         if let Some(mut window) = self.windows.lock().remove(&window_id) {
             let window = Rc::get_mut(&mut window)
                 .expect("tried to destroy a window while there are outstanding references");
-            unsafe { sdl::SDL_DestroyWindow(window.window) };
+            unsafe { SDL_DestroyWindow(window.window) };
         }
     }
 
     fn poll_event(&self) -> Option<Event> {
-        let mut event = MaybeUninit::uninit();
-        if unsafe { sdl::SDL_PollEvent(event.as_mut_ptr()) } == 0 {
-            return None;
-        }
+        let event = unsafe {
+            let mut event = MaybeUninit::uninit();
+            if !SDL_PollEvent(event.as_mut_ptr()) {
+                return None;
+            }
+            event.assume_init()
+        };
 
-        let event = unsafe { event.assume_init() };
-        let e = match unsafe { event.r#type } {
-            sdl::EventType::QUIT => Event::Quit,
-            sdl::EventType::WINDOWEVENT => match unsafe { event.window.event } {
-                sdl::WindowEventId::None => Event::Unknown,
-                sdl::WindowEventId::Shown => Event::Unknown,
-                sdl::WindowEventId::Hidden => Event::Unknown,
-                sdl::WindowEventId::Exposed => Event::Unknown,
-                sdl::WindowEventId::Moved => Event::Unknown,
-                sdl::WindowEventId::Resized => Event::Resize {
-                    window_id: sdl_window_id(unsafe { event.window.window_id }),
-                    width: unsafe { event.window.data1 } as u32,
-                    height: unsafe { event.window.data2 } as u32,
-                },
-                sdl::WindowEventId::SizeChanged => Event::Unknown,
-                sdl::WindowEventId::Minimized => Event::Unknown,
-                sdl::WindowEventId::Maximized => Event::Unknown,
-                sdl::WindowEventId::Restored => Event::Unknown,
-                sdl::WindowEventId::Enter => Event::MouseEnter {
-                    window_id: sdl_window_id(unsafe { event.window.window_id }),
-                    x: unsafe { event.window.data1 },
-                    y: unsafe { event.window.data2 },
-                },
-                sdl::WindowEventId::Leave => Event::MouseLeave {
-                    window_id: sdl_window_id(unsafe { event.window.window_id }),
-                    x: unsafe { event.window.data1 },
-                    y: unsafe { event.window.data2 },
-                },
-                sdl::WindowEventId::FocusGained => Event::FocusIn {
-                    window_id: sdl_window_id(unsafe { event.window.window_id }),
-                },
-                sdl::WindowEventId::FocusLost => Event::FocusOut {
-                    window_id: sdl_window_id(unsafe { event.window.window_id }),
-                },
-                sdl::WindowEventId::Close => Event::Close {
-                    window_id: sdl_window_id(unsafe { event.window.window_id }),
-                },
-                sdl::WindowEventId::TakeFocus => Event::Unknown,
-                sdl::WindowEventId::HitTest => Event::Unknown,
-                sdl::WindowEventId::IccprofChanged => Event::Unknown,
-                sdl::WindowEventId::DisplayChanged => Event::Unknown,
+        let e = match SDL_EventType(unsafe { event.r#type }) {
+            SDL_EVENT_QUIT => Event::Quit,
+            SDL_EVENT_WINDOW_RESIZED => Event::Resize {
+                window_id: sdl_window_id(unsafe { event.window.windowID }),
+                width: unsafe { event.window.data1 } as u32,
+                height: unsafe { event.window.data2 } as u32,
+            },
+            SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED => Event::ResizePixels {
+                window_id: sdl_window_id(unsafe { event.window.windowID }),
+                width: unsafe { event.window.data1 } as u32,
+                height: unsafe { event.window.data2 } as u32,
+            },
+            SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED => Event::ScaleChanged {
+                window_id: sdl_window_id(unsafe { event.window.windowID }),
             },
-            sdl::EventType::KEYUP | sdl::EventType::KEYDOWN => {
-                let scancode = unsafe { event.key.keysym.scancode };
-                let modifiers = unsafe { event.key.keysym.modifiers };
-                let repeat = unsafe { event.key.repeat } != 0;
-                let state = unsafe { event.key.state };
+            SDL_EVENT_WINDOW_MOUSE_ENTER => Event::MouseEnter {
+                window_id: sdl_window_id(unsafe { event.window.windowID }),
+                x: unsafe { event.window.data1 },
+                y: unsafe { event.window.data2 },
+            },
+            SDL_EVENT_WINDOW_MOUSE_LEAVE => Event::MouseLeave {
+                window_id: sdl_window_id(unsafe { event.window.windowID }),
+                x: unsafe { event.window.data1 },
+                y: unsafe { event.window.data2 },
+            },
+            SDL_EVENT_WINDOW_FOCUS_GAINED => Event::FocusGained {
+                window_id: sdl_window_id(unsafe { event.window.windowID }),
+            },
+            SDL_EVENT_WINDOW_FOCUS_LOST => Event::FocusLost {
+                window_id: sdl_window_id(unsafe { event.window.windowID }),
+            },
+            SDL_EVENT_WINDOW_CLOSE_REQUESTED => Event::CloseRequested {
+                window_id: sdl_window_id(unsafe { event.window.windowID }),
+            },
+            SDL_EVENT_KEY_UP | SDL_EVENT_KEY_DOWN => {
+                let scancode = unsafe { event.key.scancode };
+                let modifiers = unsafe { event.key.r#mod };
+                let repeat = unsafe { event.key.repeat };
+                let down = unsafe { event.key.down };
                 let key = map_sdl_scancode(scancode);
                 let modifiers = map_sdl_modifiers(modifiers);
-                let pressed = map_sdl_pressed_state(state);
                 Event::KeyPress {
-                    window_id: sdl_window_id(unsafe { event.window.window_id }),
+                    window_id: sdl_window_id(unsafe { event.window.windowID }),
                     key,
                     repeat,
-                    pressed,
+                    down,
                     modifiers,
                 }
             }
-            sdl::EventType::MOUSEBUTTONUP | sdl::EventType::MOUSEBUTTONDOWN => {
+            SDL_EVENT_MOUSE_BUTTON_UP | SDL_EVENT_MOUSE_BUTTON_DOWN => {
                 let button = unsafe { event.button.button };
-                let state = unsafe { event.button.state };
-                let button = map_sdl_button(button);
-                let pressed = map_sdl_pressed_state(state);
+                let down = unsafe { event.button.down };
+                let buttons = map_sdl_buttons(button as u32);
                 Event::ButtonPress {
-                    window_id: sdl_window_id(unsafe { event.window.window_id }),
-                    button,
-                    pressed,
+                    window_id: sdl_window_id(unsafe { event.window.windowID }),
+                    buttons,
+                    down,
                 }
             }
-            sdl::EventType::MOUSEMOTION => Event::MouseMotion {
-                window_id: sdl_window_id(unsafe { event.window.window_id }),
-                x: unsafe { event.window.data1 },
-                y: unsafe { event.window.data2 },
+            SDL_EVENT_MOUSE_MOTION => Event::MouseMotion {
+                window_id: sdl_window_id(unsafe { event.motion.windowID }),
+                x: unsafe { event.motion.x },
+                y: unsafe { event.motion.y },
             },
             _ => Event::Unknown,
         };
@@ -219,234 +280,221 @@ impl App for SdlApp {
     }
 }
 
-fn map_sdl_button(button: sdl::MouseButton) -> Button {
-    match button {
-        sdl::MouseButton::Left => Button::Left,
-        sdl::MouseButton::Middle => Button::Middle,
-        sdl::MouseButton::Right => Button::Right,
-        sdl::MouseButton::X1 => Button::X1,
-        sdl::MouseButton::X2 => Button::X2,
+fn map_sdl_buttons(buttons: u32) -> ButtonFlags {
+    let mut flags = ButtonFlags::default();
+    if buttons & SDL_BUTTON_LMASK != 0 {
+        flags |= ButtonFlags::LEFT
     }
-}
-
-fn map_sdl_pressed_state(pressed_state: sdl::PressedState) -> PressedState {
-    match pressed_state {
-        sdl::PressedState::Released => PressedState::Released,
-        sdl::PressedState::Pressed => PressedState::Pressed,
+    if buttons & SDL_BUTTON_MMASK != 0 {
+        flags |= ButtonFlags::MIDDLE
     }
+    if buttons & SDL_BUTTON_RMASK != 0 {
+        flags |= ButtonFlags::RIGHT
+    }
+    if buttons & SDL_BUTTON_X1MASK != 0 {
+        flags |= ButtonFlags::X1
+    }
+    if buttons & SDL_BUTTON_X2MASK != 0 {
+        flags |= ButtonFlags::X2
+    }
+    flags
 }
 
-fn map_sdl_modifiers(modifiers: sdl::Keymod) -> ModifierFlags {
+fn map_sdl_modifiers(modifiers: SDL_Keymod) -> ModifierFlags {
     let mut flags = ModifierFlags::default();
-    if modifiers.0 & sdl::Keymod::ALT.0 != 0 {
-        flags &= ModifierFlags::ALT
+    if modifiers & SDL_KMOD_ALT != 0 {
+        flags |= ModifierFlags::ALT
     }
-    if modifiers.0 & sdl::Keymod::SHIFT.0 != 0 {
-        flags &= ModifierFlags::SHIFT
+    if modifiers & SDL_KMOD_SHIFT != 0 {
+        flags |= ModifierFlags::SHIFT
     }
-    if modifiers.0 & sdl::Keymod::CTRL.0 != 0 {
-        flags &= ModifierFlags::CTRL
+    if modifiers & SDL_KMOD_CTRL != 0 {
+        flags |= ModifierFlags::CTRL
     }
-    if modifiers.0 & sdl::Keymod::GUI.0 != 0 {
-        flags &= ModifierFlags::META
+    if modifiers & SDL_KMOD_GUI != 0 {
+        flags |= ModifierFlags::META
     }
     flags
 }
 
-fn map_sdl_scancode(scancode: sdl::Scancode) -> Key {
+fn map_sdl_scancode(scancode: SDL_Scancode) -> Key {
     match scancode {
-        sdl::Scancode::A => Key::A,
-        sdl::Scancode::B => Key::B,
-        sdl::Scancode::C => Key::C,
-        sdl::Scancode::D => Key::D,
-        sdl::Scancode::E => Key::E,
-        sdl::Scancode::F => Key::F,
-        sdl::Scancode::G => Key::G,
-        sdl::Scancode::H => Key::H,
-        sdl::Scancode::I => Key::I,
-        sdl::Scancode::J => Key::J,
-        sdl::Scancode::K => Key::K,
-        sdl::Scancode::L => Key::L,
-        sdl::Scancode::M => Key::M,
-        sdl::Scancode::N => Key::N,
-        sdl::Scancode::O => Key::O,
-        sdl::Scancode::P => Key::P,
-        sdl::Scancode::Q => Key::Q,
-        sdl::Scancode::R => Key::R,
-        sdl::Scancode::S => Key::S,
-        sdl::Scancode::T => Key::T,
-        sdl::Scancode::U => Key::U,
-        sdl::Scancode::V => Key::V,
-        sdl::Scancode::W => Key::W,
-        sdl::Scancode::X => Key::X,
-        sdl::Scancode::Y => Key::Y,
-        sdl::Scancode::Z => Key::Z,
-
-        sdl::Scancode::SCANCODE_1 => Key::Key1,
-        sdl::Scancode::SCANCODE_2 => Key::Key2,
-        sdl::Scancode::SCANCODE_3 => Key::Key3,
-        sdl::Scancode::SCANCODE_4 => Key::Key4,
-        sdl::Scancode::SCANCODE_5 => Key::Key5,
-        sdl::Scancode::SCANCODE_6 => Key::Key6,
-        sdl::Scancode::SCANCODE_7 => Key::Key7,
-        sdl::Scancode::SCANCODE_8 => Key::Key8,
-        sdl::Scancode::SCANCODE_9 => Key::Key9,
-        sdl::Scancode::SCANCODE_0 => Key::Key0,
-
-        sdl::Scancode::RETURN => Key::Return,
-        sdl::Scancode::ESCAPE => Key::Escape,
-        sdl::Scancode::BACKSPACE => Key::Backspace,
-        sdl::Scancode::DELETE => Key::Delete,
-        sdl::Scancode::TAB => Key::Tab,
-        sdl::Scancode::SPACE => Key::Space,
-        sdl::Scancode::MINUS => Key::Minus,
-        sdl::Scancode::EQUALS => Key::Equal,
-        sdl::Scancode::LEFTBRACKET => Key::LeftBrace,
-        sdl::Scancode::RIGHTBRACKET => Key::RightBrace,
-        sdl::Scancode::BACKSLASH => Key::Backslash,
-        sdl::Scancode::SEMICOLON => Key::Semicolon,
-        sdl::Scancode::APOSTROPHE => Key::Apostrophe,
-        sdl::Scancode::GRAVE => Key::Grave,
-        sdl::Scancode::COMMA => Key::Comma,
-        sdl::Scancode::PERIOD => Key::Period,
-        sdl::Scancode::SLASH => Key::Slash,
-        sdl::Scancode::CAPSLOCK => Key::CapsLock,
-
-        sdl::Scancode::F1 => Key::F1,
-        sdl::Scancode::F2 => Key::F2,
-        sdl::Scancode::F3 => Key::F3,
-        sdl::Scancode::F4 => Key::F4,
-        sdl::Scancode::F5 => Key::F5,
-        sdl::Scancode::F6 => Key::F6,
-        sdl::Scancode::F7 => Key::F7,
-        sdl::Scancode::F8 => Key::F8,
-        sdl::Scancode::F9 => Key::F9,
-        sdl::Scancode::F10 => Key::F10,
-        sdl::Scancode::F11 => Key::F11,
-        sdl::Scancode::F12 => Key::F12,
-        sdl::Scancode::F13 => Key::F13,
-        sdl::Scancode::F14 => Key::F14,
-        sdl::Scancode::F15 => Key::F15,
-        sdl::Scancode::F16 => Key::F16,
-        sdl::Scancode::F17 => Key::F17,
-        sdl::Scancode::F18 => Key::F18,
-        sdl::Scancode::F19 => Key::F19,
-        sdl::Scancode::F20 => Key::F20,
-        sdl::Scancode::F21 => Key::F21,
-        sdl::Scancode::F22 => Key::F22,
-        sdl::Scancode::F23 => Key::F23,
-        sdl::Scancode::F24 => Key::F24,
-
-        sdl::Scancode::SCROLLLOCK => Key::ScrollLock,
-        sdl::Scancode::INSERT => Key::Insert,
-        sdl::Scancode::HOME => Key::Home,
-        sdl::Scancode::END => Key::End,
-        sdl::Scancode::PAGEUP => Key::PageUp,
-        sdl::Scancode::PAGEDOWN => Key::PageDown,
-
-        sdl::Scancode::LEFT => Key::Left,
-        sdl::Scancode::RIGHT => Key::Right,
-        sdl::Scancode::UP => Key::Up,
-        sdl::Scancode::DOWN => Key::Down,
-
-        sdl::Scancode::NUMLOCKCLEAR => Key::NumLock,
-        sdl::Scancode::KP_DIVIDE => Key::NumpadDivide,
-        sdl::Scancode::KP_MULTIPLY => Key::NumpadMultiply,
-        sdl::Scancode::KP_MINUS => Key::NumpadSubtract,
-        sdl::Scancode::KP_PLUS => Key::NumpadAdd,
-        sdl::Scancode::KP_ENTER => Key::NumpadEnter,
-        sdl::Scancode::KP_1 => Key::Numpad1,
-        sdl::Scancode::KP_2 => Key::Numpad2,
-        sdl::Scancode::KP_3 => Key::Numpad3,
-        sdl::Scancode::KP_4 => Key::Numpad4,
-        sdl::Scancode::KP_5 => Key::Numpad5,
-        sdl::Scancode::KP_6 => Key::Numpad6,
-        sdl::Scancode::KP_7 => Key::Numpad7,
-        sdl::Scancode::KP_8 => Key::Numpad8,
-        sdl::Scancode::KP_9 => Key::Numpad9,
-        sdl::Scancode::KP_0 => Key::Numpad0,
-        sdl::Scancode::KP_PERIOD => Key::NumpadPeriod,
-        sdl::Scancode::KP_EQUALS => Key::NumpadEquals,
-        sdl::Scancode::KP_LEFTPAREN => Key::NumpadLeftParen,
-        sdl::Scancode::KP_RIGHTPAREN => Key::NumpadRightParen,
-        sdl::Scancode::KP_PLUSMINUS => Key::NumpadPlusMinus,
-        sdl::Scancode::KP_COMMA => Key::NumpadComma,
-
-        sdl::Scancode::EJECT => Key::Eject,
-        sdl::Scancode::STOP => Key::Stop,
-        sdl::Scancode::MUTE => Key::Mute,
-        sdl::Scancode::VOLUMEUP => Key::VolumeUp,
-        sdl::Scancode::VOLUMEDOWN => Key::VolumeDown,
-        sdl::Scancode::POWER => Key::Power,
-
-        sdl::Scancode::APPLICATION => Key::Compose,
-        sdl::Scancode::SLEEP => Key::Sleep,
-
-        sdl::Scancode::LSHIFT => Key::LeftShift,
-        sdl::Scancode::RSHIFT => Key::RightShift,
-        sdl::Scancode::LCTRL => Key::LeftControl,
-        sdl::Scancode::RCTRL => Key::RightControl,
-        sdl::Scancode::LALT => Key::LeftAlt,
-        sdl::Scancode::RALT => Key::RightAlt,
-        sdl::Scancode::LGUI => Key::LeftMeta,
-        sdl::Scancode::RGUI => Key::RightMeta,
-
-        sdl::Scancode::MENU => Key::Menu,
-        sdl::Scancode::PAUSE => Key::Pause,
-
-        sdl::Scancode::NONUSBACKSLASH => Key::NonUSBackslash,
-        sdl::Scancode::SYSREQ => Key::SysReq,
-        sdl::Scancode::AGAIN => Key::Again,
-        sdl::Scancode::UNDO => Key::Undo,
-        sdl::Scancode::COPY => Key::Copy,
-        sdl::Scancode::PASTE => Key::Paste,
-        sdl::Scancode::FIND => Key::Find,
-        sdl::Scancode::CUT => Key::Cut,
-        sdl::Scancode::HELP => Key::Help,
-        sdl::Scancode::CALCULATOR => Key::Calculator,
-        sdl::Scancode::ALTERASE => Key::AltErase,
-        sdl::Scancode::CANCEL => Key::Cancel,
-
-        sdl::Scancode::BRIGHTNESSUP => Key::BrightnessUp,
-        sdl::Scancode::BRIGHTNESSDOWN => Key::BrightnessDown,
-
-        sdl::Scancode::DISPLAYSWITCH => Key::SwitchVideoMode,
-
-        sdl::Scancode::KBDILLUMTOGGLE => Key::KeyboardIlluminationToggle,
-        sdl::Scancode::KBDILLUMDOWN => Key::KeyboardIlluminationDown,
-        sdl::Scancode::KBDILLUMUP => Key::KeyboardIlluminationUp,
-
-        sdl::Scancode::APP1 => Key::App1,
-        sdl::Scancode::APP2 => Key::App2,
-        sdl::Scancode::WWW => Key::WWW,
-        sdl::Scancode::MAIL => Key::Mail,
-        sdl::Scancode::COMPUTER => Key::Computer,
-
-        sdl::Scancode::AC_BOOKMARKS => Key::ACBookmarks,
-        sdl::Scancode::AC_BACK => Key::ACBack,
-        sdl::Scancode::AC_FORWARD => Key::ACForward,
-        sdl::Scancode::AC_HOME => Key::ACHome,
-        sdl::Scancode::AC_REFRESH => Key::ACRefresh,
-        sdl::Scancode::AC_SEARCH => Key::ACSearch,
-
-        sdl::Scancode::AUDIONEXT => Key::AudioNext,
-        sdl::Scancode::AUDIOPLAY => Key::AudioPlay,
-        sdl::Scancode::AUDIOPREV => Key::AudioPrev,
-        sdl::Scancode::AUDIOSTOP => Key::AudioStop,
-        sdl::Scancode::AUDIOREWIND => Key::AudioRewind,
-        sdl::Scancode::AUDIOFASTFORWARD => Key::AudioFastForward,
-
-        sdl::Scancode::LANG1 => Key::Language1,
-        sdl::Scancode::LANG2 => Key::Language2,
-        sdl::Scancode::LANG3 => Key::Language3,
-        sdl::Scancode::LANG4 => Key::Language4,
-        sdl::Scancode::LANG5 => Key::Language5,
-
-        sdl::Scancode::INTERNATIONAL1 => Key::International1,
-        sdl::Scancode::INTERNATIONAL2 => Key::International2,
-        sdl::Scancode::INTERNATIONAL3 => Key::International3,
-        sdl::Scancode::INTERNATIONAL4 => Key::International4,
-        sdl::Scancode::INTERNATIONAL5 => Key::International5,
+        SDL_SCANCODE_A => Key::A,
+        SDL_SCANCODE_B => Key::B,
+        SDL_SCANCODE_C => Key::C,
+        SDL_SCANCODE_D => Key::D,
+        SDL_SCANCODE_E => Key::E,
+        SDL_SCANCODE_F => Key::F,
+        SDL_SCANCODE_G => Key::G,
+        SDL_SCANCODE_H => Key::H,
+        SDL_SCANCODE_I => Key::I,
+        SDL_SCANCODE_J => Key::J,
+        SDL_SCANCODE_K => Key::K,
+        SDL_SCANCODE_L => Key::L,
+        SDL_SCANCODE_M => Key::M,
+        SDL_SCANCODE_N => Key::N,
+        SDL_SCANCODE_O => Key::O,
+        SDL_SCANCODE_P => Key::P,
+        SDL_SCANCODE_Q => Key::Q,
+        SDL_SCANCODE_R => Key::R,
+        SDL_SCANCODE_S => Key::S,
+        SDL_SCANCODE_T => Key::T,
+        SDL_SCANCODE_U => Key::U,
+        SDL_SCANCODE_V => Key::V,
+        SDL_SCANCODE_W => Key::W,
+        SDL_SCANCODE_X => Key::X,
+        SDL_SCANCODE_Y => Key::Y,
+        SDL_SCANCODE_Z => Key::Z,
+
+        SDL_SCANCODE_1 => Key::Key1,
+        SDL_SCANCODE_2 => Key::Key2,
+        SDL_SCANCODE_3 => Key::Key3,
+        SDL_SCANCODE_4 => Key::Key4,
+        SDL_SCANCODE_5 => Key::Key5,
+        SDL_SCANCODE_6 => Key::Key6,
+        SDL_SCANCODE_7 => Key::Key7,
+        SDL_SCANCODE_8 => Key::Key8,
+        SDL_SCANCODE_9 => Key::Key9,
+        SDL_SCANCODE_0 => Key::Key0,
+
+        SDL_SCANCODE_RETURN => Key::Return,
+        SDL_SCANCODE_ESCAPE => Key::Escape,
+        SDL_SCANCODE_BACKSPACE => Key::Backspace,
+        SDL_SCANCODE_DELETE => Key::Delete,
+        SDL_SCANCODE_TAB => Key::Tab,
+        SDL_SCANCODE_SPACE => Key::Space,
+        SDL_SCANCODE_MINUS => Key::Minus,
+        SDL_SCANCODE_EQUALS => Key::Equal,
+        SDL_SCANCODE_LEFTBRACKET => Key::LeftBrace,
+        SDL_SCANCODE_RIGHTBRACKET => Key::RightBrace,
+        SDL_SCANCODE_BACKSLASH => Key::Backslash,
+        SDL_SCANCODE_SEMICOLON => Key::Semicolon,
+        SDL_SCANCODE_APOSTROPHE => Key::Apostrophe,
+        SDL_SCANCODE_GRAVE => Key::Grave,
+        SDL_SCANCODE_COMMA => Key::Comma,
+        SDL_SCANCODE_PERIOD => Key::Period,
+        SDL_SCANCODE_SLASH => Key::Slash,
+        SDL_SCANCODE_CAPSLOCK => Key::CapsLock,
+
+        SDL_SCANCODE_F1 => Key::F1,
+        SDL_SCANCODE_F2 => Key::F2,
+        SDL_SCANCODE_F3 => Key::F3,
+        SDL_SCANCODE_F4 => Key::F4,
+        SDL_SCANCODE_F5 => Key::F5,
+        SDL_SCANCODE_F6 => Key::F6,
+        SDL_SCANCODE_F7 => Key::F7,
+        SDL_SCANCODE_F8 => Key::F8,
+        SDL_SCANCODE_F9 => Key::F9,
+        SDL_SCANCODE_F10 => Key::F10,
+        SDL_SCANCODE_F11 => Key::F11,
+        SDL_SCANCODE_F12 => Key::F12,
+        SDL_SCANCODE_F13 => Key::F13,
+        SDL_SCANCODE_F14 => Key::F14,
+        SDL_SCANCODE_F15 => Key::F15,
+        SDL_SCANCODE_F16 => Key::F16,
+        SDL_SCANCODE_F17 => Key::F17,
+        SDL_SCANCODE_F18 => Key::F18,
+        SDL_SCANCODE_F19 => Key::F19,
+        SDL_SCANCODE_F20 => Key::F20,
+        SDL_SCANCODE_F21 => Key::F21,
+        SDL_SCANCODE_F22 => Key::F22,
+        SDL_SCANCODE_F23 => Key::F23,
+        SDL_SCANCODE_F24 => Key::F24,
+
+        SDL_SCANCODE_SCROLLLOCK => Key::ScrollLock,
+        SDL_SCANCODE_INSERT => Key::Insert,
+        SDL_SCANCODE_HOME => Key::Home,
+        SDL_SCANCODE_END => Key::End,
+        SDL_SCANCODE_PAGEUP => Key::PageUp,
+        SDL_SCANCODE_PAGEDOWN => Key::PageDown,
+
+        SDL_SCANCODE_LEFT => Key::Left,
+        SDL_SCANCODE_RIGHT => Key::Right,
+        SDL_SCANCODE_UP => Key::Up,
+        SDL_SCANCODE_DOWN => Key::Down,
+
+        SDL_SCANCODE_NUMLOCKCLEAR => Key::NumLock,
+        SDL_SCANCODE_KP_DIVIDE => Key::NumpadDivide,
+        SDL_SCANCODE_KP_MULTIPLY => Key::NumpadMultiply,
+        SDL_SCANCODE_KP_MINUS => Key::NumpadSubtract,
+        SDL_SCANCODE_KP_PLUS => Key::NumpadAdd,
+        SDL_SCANCODE_KP_ENTER => Key::NumpadEnter,
+        SDL_SCANCODE_KP_1 => Key::Numpad1,
+        SDL_SCANCODE_KP_2 => Key::Numpad2,
+        SDL_SCANCODE_KP_3 => Key::Numpad3,
+        SDL_SCANCODE_KP_4 => Key::Numpad4,
+        SDL_SCANCODE_KP_5 => Key::Numpad5,
+        SDL_SCANCODE_KP_6 => Key::Numpad6,
+        SDL_SCANCODE_KP_7 => Key::Numpad7,
+        SDL_SCANCODE_KP_8 => Key::Numpad8,
+        SDL_SCANCODE_KP_9 => Key::Numpad9,
+        SDL_SCANCODE_KP_0 => Key::Numpad0,
+        SDL_SCANCODE_KP_PERIOD => Key::NumpadPeriod,
+        SDL_SCANCODE_KP_EQUALS => Key::NumpadEquals,
+        SDL_SCANCODE_KP_LEFTPAREN => Key::NumpadLeftParen,
+        SDL_SCANCODE_KP_RIGHTPAREN => Key::NumpadRightParen,
+        SDL_SCANCODE_KP_PLUSMINUS => Key::NumpadPlusMinus,
+        SDL_SCANCODE_KP_COMMA => Key::NumpadComma,
+
+        SDL_SCANCODE_MEDIA_EJECT => Key::MediaEject,
+        SDL_SCANCODE_STOP => Key::Stop,
+        SDL_SCANCODE_MUTE => Key::Mute,
+        SDL_SCANCODE_VOLUMEUP => Key::VolumeUp,
+        SDL_SCANCODE_VOLUMEDOWN => Key::VolumeDown,
+        SDL_SCANCODE_POWER => Key::Power,
+
+        SDL_SCANCODE_APPLICATION => Key::Compose,
+        SDL_SCANCODE_SLEEP => Key::Sleep,
+
+        SDL_SCANCODE_LSHIFT => Key::LeftShift,
+        SDL_SCANCODE_RSHIFT => Key::RightShift,
+        SDL_SCANCODE_LCTRL => Key::LeftControl,
+        SDL_SCANCODE_RCTRL => Key::RightControl,
+        SDL_SCANCODE_LALT => Key::LeftAlt,
+        SDL_SCANCODE_RALT => Key::RightAlt,
+        SDL_SCANCODE_LGUI => Key::LeftMeta,
+        SDL_SCANCODE_RGUI => Key::RightMeta,
+
+        SDL_SCANCODE_MENU => Key::Menu,
+        SDL_SCANCODE_PAUSE => Key::Pause,
+
+        SDL_SCANCODE_NONUSBACKSLASH => Key::NonUSBackslash,
+        SDL_SCANCODE_SYSREQ => Key::SysReq,
+        SDL_SCANCODE_AGAIN => Key::Again,
+        SDL_SCANCODE_UNDO => Key::Undo,
+        SDL_SCANCODE_COPY => Key::Copy,
+        SDL_SCANCODE_PASTE => Key::Paste,
+        SDL_SCANCODE_FIND => Key::Find,
+        SDL_SCANCODE_CUT => Key::Cut,
+        SDL_SCANCODE_HELP => Key::Help,
+        SDL_SCANCODE_ALTERASE => Key::AltErase,
+        SDL_SCANCODE_CANCEL => Key::Cancel,
+
+        SDL_SCANCODE_AC_BOOKMARKS => Key::ACBookmarks,
+        SDL_SCANCODE_AC_BACK => Key::ACBack,
+        SDL_SCANCODE_AC_FORWARD => Key::ACForward,
+        SDL_SCANCODE_AC_HOME => Key::ACHome,
+        SDL_SCANCODE_AC_REFRESH => Key::ACRefresh,
+        SDL_SCANCODE_AC_SEARCH => Key::ACSearch,
+
+        SDL_SCANCODE_MEDIA_NEXT_TRACK => Key::MediaNextTrack,
+        SDL_SCANCODE_MEDIA_PLAY => Key::MediaPlay,
+        SDL_SCANCODE_MEDIA_PREVIOUS_TRACK => Key::MediaPreviousTrack,
+        SDL_SCANCODE_MEDIA_STOP => Key::MediaStop,
+        SDL_SCANCODE_MEDIA_REWIND => Key::MediaRewind,
+        SDL_SCANCODE_MEDIA_FAST_FORWARD => Key::MediaFastForward,
+
+        SDL_SCANCODE_LANG1 => Key::Language1,
+        SDL_SCANCODE_LANG2 => Key::Language2,
+        SDL_SCANCODE_LANG3 => Key::Language3,
+        SDL_SCANCODE_LANG4 => Key::Language4,
+        SDL_SCANCODE_LANG5 => Key::Language5,
+
+        SDL_SCANCODE_INTERNATIONAL1 => Key::International1,
+        SDL_SCANCODE_INTERNATIONAL2 => Key::International2,
+        SDL_SCANCODE_INTERNATIONAL3 => Key::International3,
+        SDL_SCANCODE_INTERNATIONAL4 => Key::International4,
+        SDL_SCANCODE_INTERNATIONAL5 => Key::International5,
 
         _ => Key::Unknown,
     }
diff --git a/external/sdl2-sys/Cargo.toml b/external/sdl2-sys/Cargo.toml
deleted file mode 100644 (file)
index 44e60d1..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-[package]
-name = "sdl2-sys"
-version = "0.1.0"
-edition = "2021"
-links = "SDL2"
-
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-
-[dependencies]
\ No newline at end of file
diff --git a/external/sdl2-sys/build.rs b/external/sdl2-sys/build.rs
deleted file mode 100644 (file)
index a5d2729..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-fn main() {
-    println!("cargo:rerun-if-changed=build.rs");
-    println!("cargo:rustc-link-lib=SDL2");
-}
diff --git a/external/sdl2-sys/src/lib.rs b/external/sdl2-sys/src/lib.rs
deleted file mode 100644 (file)
index c8bf451..0000000
+++ /dev/null
@@ -1,1330 +0,0 @@
-#![allow(non_camel_case_types)]
-use std::{ffi::c_void, os::raw::c_char};
-
-pub const MAJOR_VERSION: u8 = 2;
-pub const MINOR_VERSION: u8 = 24;
-pub const PATCH_VERSION: u8 = 2;
-
-#[repr(C)]
-pub struct Window {
-    _unused: [u8; 0],
-}
-
-#[repr(C)]
-#[derive(Clone, Copy, PartialEq, Eq, Debug)]
-pub enum Bool {
-    False = 0,
-    True = 1,
-}
-
-pub type JoystickID = i32;
-pub type TouchID = i64;
-pub type FingerID = i64;
-pub type GestureID = i64;
-
-#[repr(u8)]
-#[derive(Clone, Copy, PartialEq, Eq)]
-pub enum PressedState {
-    Released = 0,
-    Pressed = 1,
-}
-
-#[repr(u8)]
-#[derive(Clone, Copy, PartialEq, Eq)]
-pub enum MouseButton {
-    Left = 1,
-    Middle = 2,
-    Right = 3,
-    X1 = 4,
-    X2 = 5,
-}
-
-#[repr(i32)]
-#[derive(Clone, Copy, PartialEq, Eq)]
-pub enum Scancode {
-    UNKNOWN = 0,
-
-    /**
-     *  \name Usage page 0x07
-     *
-     *  These values are from usage page 0x07 (USB keyboard page).
-     */
-    /* @{ */
-    A = 4,
-    B = 5,
-    C = 6,
-    D = 7,
-    E = 8,
-    F = 9,
-    G = 10,
-    H = 11,
-    I = 12,
-    J = 13,
-    K = 14,
-    L = 15,
-    M = 16,
-    N = 17,
-    O = 18,
-    P = 19,
-    Q = 20,
-    R = 21,
-    S = 22,
-    T = 23,
-    U = 24,
-    V = 25,
-    W = 26,
-    X = 27,
-    Y = 28,
-    Z = 29,
-
-    SCANCODE_1 = 30,
-    SCANCODE_2 = 31,
-    SCANCODE_3 = 32,
-    SCANCODE_4 = 33,
-    SCANCODE_5 = 34,
-    SCANCODE_6 = 35,
-    SCANCODE_7 = 36,
-    SCANCODE_8 = 37,
-    SCANCODE_9 = 38,
-    SCANCODE_0 = 39,
-
-    RETURN = 40,
-    ESCAPE = 41,
-    BACKSPACE = 42,
-    TAB = 43,
-    SPACE = 44,
-
-    MINUS = 45,
-    EQUALS = 46,
-    LEFTBRACKET = 47,
-    RIGHTBRACKET = 48,
-    BACKSLASH = 49,
-    /**< Located at the lower left of the return
-     *   key on ISO keyboards and at the right end
-     *   of the QWERTY row on ANSI keyboards.
-     *   Produces REVERSE SOLIDUS (backslash) and
-     *   VERTICAL LINE in a US layout, REVERSE
-     *   SOLIDUS and VERTICAL LINE in a UK Mac
-     *   layout, NUMBER SIGN and TILDE in a UK
-     *   Windows layout, DOLLAR SIGN and POUND SIGN
-     *   in a Swiss German layout, NUMBER SIGN and
-     *   APOSTROPHE in a German layout, GRAVE
-     *   ACCENT and POUND SIGN in a French Mac
-     *   layout, and ASTERISK and MICRO SIGN in a
-     *   French Windows layout.
-     */
-    NONUSHASH = 50,
-    /**< ISO USB keyboards actually use this code
-     *   instead of 49 for the same key, but all
-     *   OSes I've seen treat the two codes
-     *   identically. So, as an implementor, unless
-     *   your keyboard generates both of those
-     *   codes and your OS treats them differently,
-     *   you should generate BACKSLASH
-     *   instead of this code. As a user, you
-     *   should not rely on this code because SDL
-     *   will never generate it with most (all?)
-     *   keyboards.
-     */
-    SEMICOLON = 51,
-    APOSTROPHE = 52,
-    GRAVE = 53,
-    /**< Located in the top left corner (on both ANSI
-     *   and ISO keyboards). Produces GRAVE ACCENT and
-     *   TILDE in a US Windows layout and in US and UK
-     *   Mac layouts on ANSI keyboards, GRAVE ACCENT
-     *   and NOT SIGN in a UK Windows layout, SECTION
-     *   SIGN and PLUS-MINUS SIGN in US and UK Mac
-     *   layouts on ISO keyboards, SECTION SIGN and
-     *   DEGREE SIGN in a Swiss German layout (Mac:
-     *   only on ISO keyboards), CIRCUMFLEX ACCENT and
-     *   DEGREE SIGN in a German layout (Mac: only on
-     *   ISO keyboards), SUPERSCRIPT TWO and TILDE in a
-     *   French Windows layout, COMMERCIAL AT and
-     *   NUMBER SIGN in a French Mac layout on ISO
-     *   keyboards, and LESS-THAN SIGN and GREATER-THAN
-     *   SIGN in a Swiss German, German, or French Mac
-     *   layout on ANSI keyboards.
-     */
-    COMMA = 54,
-    PERIOD = 55,
-    SLASH = 56,
-
-    CAPSLOCK = 57,
-
-    F1 = 58,
-    F2 = 59,
-    F3 = 60,
-    F4 = 61,
-    F5 = 62,
-    F6 = 63,
-    F7 = 64,
-    F8 = 65,
-    F9 = 66,
-    F10 = 67,
-    F11 = 68,
-    F12 = 69,
-
-    PRINTSCREEN = 70,
-    SCROLLLOCK = 71,
-    PAUSE = 72,
-    INSERT = 73,
-    /**< insert on PC, help on some Mac keyboards (but
-    does send code 73, not 117) */
-    HOME = 74,
-    PAGEUP = 75,
-    DELETE = 76,
-    END = 77,
-    PAGEDOWN = 78,
-    RIGHT = 79,
-    LEFT = 80,
-    DOWN = 81,
-    UP = 82,
-
-    NUMLOCKCLEAR = 83,
-    /**< num lock on PC, clear on Mac keyboards
-     */
-    KP_DIVIDE = 84,
-    KP_MULTIPLY = 85,
-    KP_MINUS = 86,
-    KP_PLUS = 87,
-    KP_ENTER = 88,
-    KP_1 = 89,
-    KP_2 = 90,
-    KP_3 = 91,
-    KP_4 = 92,
-    KP_5 = 93,
-    KP_6 = 94,
-    KP_7 = 95,
-    KP_8 = 96,
-    KP_9 = 97,
-    KP_0 = 98,
-    KP_PERIOD = 99,
-
-    NONUSBACKSLASH = 100,
-    /**< This is the additional key that ISO
-     *   keyboards have over ANSI ones,
-     *   located between left shift and Y.
-     *   Produces GRAVE ACCENT and TILDE in a
-     *   US or UK Mac layout, REVERSE SOLIDUS
-     *   (backslash) and VERTICAL LINE in a
-     *   US or UK Windows layout, and
-     *   LESS-THAN SIGN and GREATER-THAN SIGN
-     *   in a Swiss German, German, or French
-     *   layout. */
-    APPLICATION = 101,
-    /**< windows contextual menu, compose */
-    POWER = 102,
-    /**< The USB document says this is a status flag,
-     *   not a physical key - but some Mac keyboards
-     *   do have a power key. */
-    KP_EQUALS = 103,
-    F13 = 104,
-    F14 = 105,
-    F15 = 106,
-    F16 = 107,
-    F17 = 108,
-    F18 = 109,
-    F19 = 110,
-    F20 = 111,
-    F21 = 112,
-    F22 = 113,
-    F23 = 114,
-    F24 = 115,
-    EXECUTE = 116,
-    HELP = 117,
-    MENU = 118,
-    SELECT = 119,
-    STOP = 120,
-    AGAIN = 121,
-    /**< redo */
-    UNDO = 122,
-    CUT = 123,
-    COPY = 124,
-    PASTE = 125,
-    FIND = 126,
-    MUTE = 127,
-    VOLUMEUP = 128,
-    VOLUMEDOWN = 129,
-    /* not sure whether there's a reason to enable these */
-    /*     LOCKINGCAPSLOCK = 130,  */
-    /*     LOCKINGNUMLOCK = 131, */
-    /*     LOCKINGSCROLLLOCK = 132, */
-    KP_COMMA = 133,
-    KP_EQUALSAS400 = 134,
-
-    INTERNATIONAL1 = 135,
-    /**< used on Asian keyboards, see
-    footnotes in USB doc */
-    INTERNATIONAL2 = 136,
-    INTERNATIONAL3 = 137,
-    /**< Yen */
-    INTERNATIONAL4 = 138,
-    INTERNATIONAL5 = 139,
-    INTERNATIONAL6 = 140,
-    INTERNATIONAL7 = 141,
-    INTERNATIONAL8 = 142,
-    INTERNATIONAL9 = 143,
-    LANG1 = 144,
-    /**< Hangul/English toggle */
-    LANG2 = 145,
-    /**< Hanja conversion */
-    LANG3 = 146,
-    /**< Katakana */
-    LANG4 = 147,
-    /**< Hiragana */
-    LANG5 = 148,
-    /**< Zenkaku/Hankaku */
-    LANG6 = 149,
-    /**< reserved */
-    LANG7 = 150,
-    /**< reserved */
-    LANG8 = 151,
-    /**< reserved */
-    LANG9 = 152,
-    /**< reserved */
-    ALTERASE = 153,
-    /**< Erase-Eaze */
-    SYSREQ = 154,
-    CANCEL = 155,
-    CLEAR = 156,
-    PRIOR = 157,
-    RETURN2 = 158,
-    SEPARATOR = 159,
-    OUT = 160,
-    OPER = 161,
-    CLEARAGAIN = 162,
-    CRSEL = 163,
-    EXSEL = 164,
-
-    KP_00 = 176,
-    KP_000 = 177,
-    THOUSANDSSEPARATOR = 178,
-    DECIMALSEPARATOR = 179,
-    CURRENCYUNIT = 180,
-    CURRENCYSUBUNIT = 181,
-    KP_LEFTPAREN = 182,
-    KP_RIGHTPAREN = 183,
-    KP_LEFTBRACE = 184,
-    KP_RIGHTBRACE = 185,
-    KP_TAB = 186,
-    KP_BACKSPACE = 187,
-    KP_A = 188,
-    KP_B = 189,
-    KP_C = 190,
-    KP_D = 191,
-    KP_E = 192,
-    KP_F = 193,
-    KP_XOR = 194,
-    KP_POWER = 195,
-    KP_PERCENT = 196,
-    KP_LESS = 197,
-    KP_GREATER = 198,
-    KP_AMPERSAND = 199,
-    KP_DBLAMPERSAND = 200,
-    KP_VERTICALBAR = 201,
-    KP_DBLVERTICALBAR = 202,
-    KP_COLON = 203,
-    KP_HASH = 204,
-    KP_SPACE = 205,
-    KP_AT = 206,
-    KP_EXCLAM = 207,
-    KP_MEMSTORE = 208,
-    KP_MEMRECALL = 209,
-    KP_MEMCLEAR = 210,
-    KP_MEMADD = 211,
-    KP_MEMSUBTRACT = 212,
-    KP_MEMMULTIPLY = 213,
-    KP_MEMDIVIDE = 214,
-    KP_PLUSMINUS = 215,
-    KP_CLEAR = 216,
-    KP_CLEARENTRY = 217,
-    KP_BINARY = 218,
-    KP_OCTAL = 219,
-    KP_DECIMAL = 220,
-    KP_HEXADECIMAL = 221,
-
-    LCTRL = 224,
-    LSHIFT = 225,
-    LALT = 226,
-    /**< alt, option */
-    LGUI = 227,
-    /**< windows, command (apple), meta */
-    RCTRL = 228,
-    RSHIFT = 229,
-    RALT = 230,
-    /**< alt gr, option */
-    RGUI = 231,
-    /**< windows, command (apple), meta */
-    MODE = 257,
-    /**< I'm not sure if this is really not covered
-     *   by any of the above, but since there's a
-     *   special KMOD_MODE for it I'm adding it here
-     */
-
-    /* @} *//* Usage page 0x07 */
-
-    /**
-     *  \name Usage page 0x0C
-     *
-     *  These values are mapped from usage page 0x0C (USB consumer page).
-     */
-    /* @{ */
-    AUDIONEXT = 258,
-    AUDIOPREV = 259,
-    AUDIOSTOP = 260,
-    AUDIOPLAY = 261,
-    AUDIOMUTE = 262,
-    MEDIASELECT = 263,
-    WWW = 264,
-    MAIL = 265,
-    CALCULATOR = 266,
-    COMPUTER = 267,
-    AC_SEARCH = 268,
-    AC_HOME = 269,
-    AC_BACK = 270,
-    AC_FORWARD = 271,
-    AC_STOP = 272,
-    AC_REFRESH = 273,
-    AC_BOOKMARKS = 274,
-
-    /* @} *//* Usage page 0x0C */
-    /**
-     *  \name Walther keys
-     *
-     *  These are values that Christian Walther added (for mac keyboard?).
-     */
-    /* @{ */
-    BRIGHTNESSDOWN = 275,
-    BRIGHTNESSUP = 276,
-    DISPLAYSWITCH = 277,
-    /**< display mirroring/dual display
-    switch, video mode switch */
-    KBDILLUMTOGGLE = 278,
-    KBDILLUMDOWN = 279,
-    KBDILLUMUP = 280,
-    EJECT = 281,
-    SLEEP = 282,
-
-    APP1 = 283,
-    APP2 = 284,
-
-    /* @} *//* Walther keys */
-    /**
-     *  \name Usage page 0x0C (additional media keys)
-     *
-     *  These values are mapped from usage page 0x0C (USB consumer page).
-     */
-    /* @{ */
-    AUDIOREWIND = 285,
-    AUDIOFASTFORWARD = 286,
-
-    /* @} *//* Usage page 0x0C (additional media keys) */
-
-    /* Add any other keys here. */
-    NUM_SCANCODES = 512,
-}
-
-const fn keycode_from_scancode(scancode: Scancode) -> i32 {
-    scancode as i32 | 1 << 30
-}
-
-#[repr(i32)]
-#[derive(Clone, Copy)]
-pub enum Keycode {
-    UNKNOWN = 0,
-
-    RETURN = '\r' as i32,
-    ESCAPE = '\x1B' as i32,
-    BACKSPACE = '\x08' as i32,
-    TAB = '\t' as i32,
-    SPACE = ' ' as i32,
-    EXCLAIM = '!' as i32,
-    QUOTEDBL = '"' as i32,
-    HASH = '#' as i32,
-    PERCENT = '%' as i32,
-    DOLLAR = '$' as i32,
-    AMPERSAND = '&' as i32,
-    QUOTE = '\'' as i32,
-    LEFTPAREN = '(' as i32,
-    RIGHTPAREN = ')' as i32,
-    ASTERISK = '*' as i32,
-    PLUS = '+' as i32,
-    COMMA = ',' as i32,
-    MINUS = '-' as i32,
-    PERIOD = '.' as i32,
-    SLASH = '/' as i32,
-    KEY_0 = '0' as i32,
-    KEY_1 = '1' as i32,
-    KEY_2 = '2' as i32,
-    KEY_3 = '3' as i32,
-    KEY_4 = '4' as i32,
-    KEY_5 = '5' as i32,
-    KEY_6 = '6' as i32,
-    KEY_7 = '7' as i32,
-    KEY_8 = '8' as i32,
-    KEY_9 = '9' as i32,
-    COLON = ':' as i32,
-    SEMICOLON = ';' as i32,
-    LESS = '<' as i32,
-    EQUALS = '=' as i32,
-    GREATER = '>' as i32,
-    QUESTION = '?' as i32,
-    AT = '@' as i32,
-
-    /*
-      Skip uppercase letters
-    */
-    LEFTBRACKET = '[' as i32,
-    BACKSLASH = '\\' as i32,
-    RIGHTBRACKET = ']' as i32,
-    CARET = '^' as i32,
-    UNDERSCORE = '_' as i32,
-    BACKQUOTE = '`' as i32,
-    a = 'a' as i32,
-    b = 'b' as i32,
-    c = 'c' as i32,
-    d = 'd' as i32,
-    e = 'e' as i32,
-    f = 'f' as i32,
-    g = 'g' as i32,
-    h = 'h' as i32,
-    i = 'i' as i32,
-    j = 'j' as i32,
-    k = 'k' as i32,
-    l = 'l' as i32,
-    m = 'm' as i32,
-    n = 'n' as i32,
-    o = 'o' as i32,
-    p = 'p' as i32,
-    q = 'q' as i32,
-    r = 'r' as i32,
-    s = 's' as i32,
-    t = 't' as i32,
-    u = 'u' as i32,
-    v = 'v' as i32,
-    w = 'w' as i32,
-    x = 'x' as i32,
-    y = 'y' as i32,
-    z = 'z' as i32,
-
-    CAPSLOCK = keycode_from_scancode(Scancode::CAPSLOCK),
-
-    F1 = keycode_from_scancode(Scancode::F1),
-    F2 = keycode_from_scancode(Scancode::F2),
-    F3 = keycode_from_scancode(Scancode::F3),
-    F4 = keycode_from_scancode(Scancode::F4),
-    F5 = keycode_from_scancode(Scancode::F5),
-    F6 = keycode_from_scancode(Scancode::F6),
-    F7 = keycode_from_scancode(Scancode::F7),
-    F8 = keycode_from_scancode(Scancode::F8),
-    F9 = keycode_from_scancode(Scancode::F9),
-    F10 = keycode_from_scancode(Scancode::F10),
-    F11 = keycode_from_scancode(Scancode::F11),
-    F12 = keycode_from_scancode(Scancode::F12),
-
-    PRINTSCREEN = keycode_from_scancode(Scancode::PRINTSCREEN),
-    SCROLLLOCK = keycode_from_scancode(Scancode::SCROLLLOCK),
-    PAUSE = keycode_from_scancode(Scancode::PAUSE),
-    INSERT = keycode_from_scancode(Scancode::INSERT),
-    HOME = keycode_from_scancode(Scancode::HOME),
-    PAGEUP = keycode_from_scancode(Scancode::PAGEUP),
-    DELETE = '\x7F' as i32,
-    END = keycode_from_scancode(Scancode::END),
-    PAGEDOWN = keycode_from_scancode(Scancode::PAGEDOWN),
-    RIGHT = keycode_from_scancode(Scancode::RIGHT),
-    LEFT = keycode_from_scancode(Scancode::LEFT),
-    DOWN = keycode_from_scancode(Scancode::DOWN),
-    UP = keycode_from_scancode(Scancode::UP),
-
-    NUMLOCKCLEAR = keycode_from_scancode(Scancode::NUMLOCKCLEAR),
-    KP_DIVIDE = keycode_from_scancode(Scancode::KP_DIVIDE),
-    KP_MULTIPLY = keycode_from_scancode(Scancode::KP_MULTIPLY),
-    KP_MINUS = keycode_from_scancode(Scancode::KP_MINUS),
-    KP_PLUS = keycode_from_scancode(Scancode::KP_PLUS),
-    KP_ENTER = keycode_from_scancode(Scancode::KP_ENTER),
-    KP_1 = keycode_from_scancode(Scancode::KP_1),
-    KP_2 = keycode_from_scancode(Scancode::KP_2),
-    KP_3 = keycode_from_scancode(Scancode::KP_3),
-    KP_4 = keycode_from_scancode(Scancode::KP_4),
-    KP_5 = keycode_from_scancode(Scancode::KP_5),
-    KP_6 = keycode_from_scancode(Scancode::KP_6),
-    KP_7 = keycode_from_scancode(Scancode::KP_7),
-    KP_8 = keycode_from_scancode(Scancode::KP_8),
-    KP_9 = keycode_from_scancode(Scancode::KP_9),
-    KP_0 = keycode_from_scancode(Scancode::KP_0),
-    KP_PERIOD = keycode_from_scancode(Scancode::KP_PERIOD),
-
-    APPLICATION = keycode_from_scancode(Scancode::APPLICATION),
-    POWER = keycode_from_scancode(Scancode::POWER),
-    KP_EQUALS = keycode_from_scancode(Scancode::KP_EQUALS),
-    F13 = keycode_from_scancode(Scancode::F13),
-    F14 = keycode_from_scancode(Scancode::F14),
-    F15 = keycode_from_scancode(Scancode::F15),
-    F16 = keycode_from_scancode(Scancode::F16),
-    F17 = keycode_from_scancode(Scancode::F17),
-    F18 = keycode_from_scancode(Scancode::F18),
-    F19 = keycode_from_scancode(Scancode::F19),
-    F20 = keycode_from_scancode(Scancode::F20),
-    F21 = keycode_from_scancode(Scancode::F21),
-    F22 = keycode_from_scancode(Scancode::F22),
-    F23 = keycode_from_scancode(Scancode::F23),
-    F24 = keycode_from_scancode(Scancode::F24),
-    EXECUTE = keycode_from_scancode(Scancode::EXECUTE),
-    HELP = keycode_from_scancode(Scancode::HELP),
-    MENU = keycode_from_scancode(Scancode::MENU),
-    SELECT = keycode_from_scancode(Scancode::SELECT),
-    STOP = keycode_from_scancode(Scancode::STOP),
-    AGAIN = keycode_from_scancode(Scancode::AGAIN),
-    UNDO = keycode_from_scancode(Scancode::UNDO),
-    CUT = keycode_from_scancode(Scancode::CUT),
-    COPY = keycode_from_scancode(Scancode::COPY),
-    PASTE = keycode_from_scancode(Scancode::PASTE),
-    FIND = keycode_from_scancode(Scancode::FIND),
-    MUTE = keycode_from_scancode(Scancode::MUTE),
-    VOLUMEUP = keycode_from_scancode(Scancode::VOLUMEUP),
-    VOLUMEDOWN = keycode_from_scancode(Scancode::VOLUMEDOWN),
-    KP_COMMA = keycode_from_scancode(Scancode::KP_COMMA),
-    KP_EQUALSAS400 = keycode_from_scancode(Scancode::KP_EQUALSAS400),
-
-    ALTERASE = keycode_from_scancode(Scancode::ALTERASE),
-    SYSREQ = keycode_from_scancode(Scancode::SYSREQ),
-    CANCEL = keycode_from_scancode(Scancode::CANCEL),
-    CLEAR = keycode_from_scancode(Scancode::CLEAR),
-    PRIOR = keycode_from_scancode(Scancode::PRIOR),
-    RETURN2 = keycode_from_scancode(Scancode::RETURN2),
-    SEPARATOR = keycode_from_scancode(Scancode::SEPARATOR),
-    OUT = keycode_from_scancode(Scancode::OUT),
-    OPER = keycode_from_scancode(Scancode::OPER),
-    CLEARAGAIN = keycode_from_scancode(Scancode::CLEARAGAIN),
-    CRSEL = keycode_from_scancode(Scancode::CRSEL),
-    EXSEL = keycode_from_scancode(Scancode::EXSEL),
-
-    KP_00 = keycode_from_scancode(Scancode::KP_00),
-    KP_000 = keycode_from_scancode(Scancode::KP_000),
-    THOUSANDSSEPARATOR = keycode_from_scancode(Scancode::THOUSANDSSEPARATOR),
-    DECIMALSEPARATOR = keycode_from_scancode(Scancode::DECIMALSEPARATOR),
-    CURRENCYUNIT = keycode_from_scancode(Scancode::CURRENCYUNIT),
-    CURRENCYSUBUNIT = keycode_from_scancode(Scancode::CURRENCYSUBUNIT),
-    KP_LEFTPAREN = keycode_from_scancode(Scancode::KP_LEFTPAREN),
-    KP_RIGHTPAREN = keycode_from_scancode(Scancode::KP_RIGHTPAREN),
-    KP_LEFTBRACE = keycode_from_scancode(Scancode::KP_LEFTBRACE),
-    KP_RIGHTBRACE = keycode_from_scancode(Scancode::KP_RIGHTBRACE),
-    KP_TAB = keycode_from_scancode(Scancode::KP_TAB),
-    KP_BACKSPACE = keycode_from_scancode(Scancode::KP_BACKSPACE),
-    KP_A = keycode_from_scancode(Scancode::KP_A),
-    KP_B = keycode_from_scancode(Scancode::KP_B),
-    KP_C = keycode_from_scancode(Scancode::KP_C),
-    KP_D = keycode_from_scancode(Scancode::KP_D),
-    KP_E = keycode_from_scancode(Scancode::KP_E),
-    KP_F = keycode_from_scancode(Scancode::KP_F),
-    KP_XOR = keycode_from_scancode(Scancode::KP_XOR),
-    KP_POWER = keycode_from_scancode(Scancode::KP_POWER),
-    KP_PERCENT = keycode_from_scancode(Scancode::KP_PERCENT),
-    KP_LESS = keycode_from_scancode(Scancode::KP_LESS),
-    KP_GREATER = keycode_from_scancode(Scancode::KP_GREATER),
-    KP_AMPERSAND = keycode_from_scancode(Scancode::KP_AMPERSAND),
-    KP_DBLAMPERSAND = keycode_from_scancode(Scancode::KP_DBLAMPERSAND),
-    KP_VERTICALBAR = keycode_from_scancode(Scancode::KP_VERTICALBAR),
-    KP_DBLVERTICALBAR = keycode_from_scancode(Scancode::KP_DBLVERTICALBAR),
-    KP_COLON = keycode_from_scancode(Scancode::KP_COLON),
-    KP_HASH = keycode_from_scancode(Scancode::KP_HASH),
-    KP_SPACE = keycode_from_scancode(Scancode::KP_SPACE),
-    KP_AT = keycode_from_scancode(Scancode::KP_AT),
-    KP_EXCLAM = keycode_from_scancode(Scancode::KP_EXCLAM),
-    KP_MEMSTORE = keycode_from_scancode(Scancode::KP_MEMSTORE),
-    KP_MEMRECALL = keycode_from_scancode(Scancode::KP_MEMRECALL),
-    KP_MEMCLEAR = keycode_from_scancode(Scancode::KP_MEMCLEAR),
-    KP_MEMADD = keycode_from_scancode(Scancode::KP_MEMADD),
-    KP_MEMSUBTRACT = keycode_from_scancode(Scancode::KP_MEMSUBTRACT),
-    KP_MEMMULTIPLY = keycode_from_scancode(Scancode::KP_MEMMULTIPLY),
-    KP_MEMDIVIDE = keycode_from_scancode(Scancode::KP_MEMDIVIDE),
-    KP_PLUSMINUS = keycode_from_scancode(Scancode::KP_PLUSMINUS),
-    KP_CLEAR = keycode_from_scancode(Scancode::KP_CLEAR),
-    KP_CLEARENTRY = keycode_from_scancode(Scancode::KP_CLEARENTRY),
-    KP_BINARY = keycode_from_scancode(Scancode::KP_BINARY),
-    KP_OCTAL = keycode_from_scancode(Scancode::KP_OCTAL),
-    KP_DECIMAL = keycode_from_scancode(Scancode::KP_DECIMAL),
-    KP_HEXADECIMAL = keycode_from_scancode(Scancode::KP_HEXADECIMAL),
-
-    LCTRL = keycode_from_scancode(Scancode::LCTRL),
-    LSHIFT = keycode_from_scancode(Scancode::LSHIFT),
-    LALT = keycode_from_scancode(Scancode::LALT),
-    LGUI = keycode_from_scancode(Scancode::LGUI),
-    RCTRL = keycode_from_scancode(Scancode::RCTRL),
-    RSHIFT = keycode_from_scancode(Scancode::RSHIFT),
-    RALT = keycode_from_scancode(Scancode::RALT),
-    RGUI = keycode_from_scancode(Scancode::RGUI),
-
-    MODE = keycode_from_scancode(Scancode::MODE),
-
-    AUDIONEXT = keycode_from_scancode(Scancode::AUDIONEXT),
-    AUDIOPREV = keycode_from_scancode(Scancode::AUDIOPREV),
-    AUDIOSTOP = keycode_from_scancode(Scancode::AUDIOSTOP),
-    AUDIOPLAY = keycode_from_scancode(Scancode::AUDIOPLAY),
-    AUDIOMUTE = keycode_from_scancode(Scancode::AUDIOMUTE),
-    MEDIASELECT = keycode_from_scancode(Scancode::MEDIASELECT),
-    WWW = keycode_from_scancode(Scancode::WWW),
-    MAIL = keycode_from_scancode(Scancode::MAIL),
-    CALCULATOR = keycode_from_scancode(Scancode::CALCULATOR),
-    COMPUTER = keycode_from_scancode(Scancode::COMPUTER),
-    AC_SEARCH = keycode_from_scancode(Scancode::AC_SEARCH),
-    AC_HOME = keycode_from_scancode(Scancode::AC_HOME),
-    AC_BACK = keycode_from_scancode(Scancode::AC_BACK),
-    AC_FORWARD = keycode_from_scancode(Scancode::AC_FORWARD),
-    AC_STOP = keycode_from_scancode(Scancode::AC_STOP),
-    AC_REFRESH = keycode_from_scancode(Scancode::AC_REFRESH),
-    AC_BOOKMARKS = keycode_from_scancode(Scancode::AC_BOOKMARKS),
-
-    BRIGHTNESSDOWN = keycode_from_scancode(Scancode::BRIGHTNESSDOWN),
-    BRIGHTNESSUP = keycode_from_scancode(Scancode::BRIGHTNESSUP),
-    DISPLAYSWITCH = keycode_from_scancode(Scancode::DISPLAYSWITCH),
-    KBDILLUMTOGGLE = keycode_from_scancode(Scancode::KBDILLUMTOGGLE),
-    KBDILLUMDOWN = keycode_from_scancode(Scancode::KBDILLUMDOWN),
-    KBDILLUMUP = keycode_from_scancode(Scancode::KBDILLUMUP),
-    EJECT = keycode_from_scancode(Scancode::EJECT),
-    SLEEP = keycode_from_scancode(Scancode::SLEEP),
-    APP1 = keycode_from_scancode(Scancode::APP1),
-    APP2 = keycode_from_scancode(Scancode::APP2),
-
-    AUDIOREWIND = keycode_from_scancode(Scancode::AUDIOREWIND),
-    AUDIOFASTFORWARD = keycode_from_scancode(Scancode::AUDIOFASTFORWARD),
-}
-
-#[repr(C)]
-#[derive(Clone, Copy, PartialEq, Eq)]
-pub struct Keymod(pub u16);
-
-impl Keymod {
-    pub const NONE: Self = Self(0x0000);
-    pub const LSHIFT: Self = Self(0x0001);
-    pub const RSHIFT: Self = Self(0x0002);
-    pub const LCTRL: Self = Self(0x0040);
-    pub const RCTRL: Self = Self(0x0080);
-    pub const LALT: Self = Self(0x0100);
-    pub const RALT: Self = Self(0x0200);
-    pub const LGUI: Self = Self(0x0400);
-    pub const RGUI: Self = Self(0x0800);
-    pub const NUM: Self = Self(0x1000);
-    pub const CAPS: Self = Self(0x2000);
-    pub const MODE: Self = Self(0x4000);
-    pub const SCROLL: Self = Self(0x8000);
-
-    pub const CTRL: Self = Self(Self::LCTRL.0 | Self::RCTRL.0);
-    pub const SHIFT: Self = Self(Self::LSHIFT.0 | Self::RSHIFT.0);
-    pub const ALT: Self = Self(Self::LALT.0 | Self::RALT.0);
-    pub const GUI: Self = Self(Self::LGUI.0 | Self::RGUI.0);
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct Keysym {
-    pub scancode: Scancode,
-    pub sym: Keycode,
-    pub modifiers: Keymod,
-    pub _unused: u32,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy, PartialEq, Eq)]
-pub enum EventType {
-    FIRSTEVENT = 0,
-    QUIT = 0x100,
-
-    APP_TERMINATING,
-    APP_LOWMEMORY,
-    APP_WILLENTERBACKGROUND,
-    APP_DIDENTERBACKGROUND,
-    APP_WILLENTERFOREGROUND,
-    APP_DIDENTERFOREGROUND,
-
-    LOCALECHANGED,
-
-    DISPLAYEVENT = 0x150,
-
-    WINDOWEVENT = 0x200,
-    SYSWMEVENT,
-
-    KEYDOWN = 0x300,
-    KEYUP,
-    TEXTEDITING,
-    TEXTINPUT,
-    KEYMAPCHANGED,
-
-    MOUSEMOTION = 0x400,
-    MOUSEBUTTONDOWN,
-    MOUSEBUTTONUP,
-    MOUSEWHEEL,
-
-    JOYAXISMOTION = 0x600,
-    JOYBALLMOTION,
-    JOYHATMOTION,
-    JOYBUTTONDOWN,
-    JOYBUTTONUP,
-    JOYDEVICEADDED,
-    JOYDEVICEREMOVED,
-
-    CONTROLLERAXISMOTION = 0x650,
-    CONTROLLERBUTTONDOWN,
-    CONTROLLERBUTTONUP,
-    CONTROLLERDEVICEADDED,
-    CONTROLLERDEVICEREMOVED,
-    CONTROLLERDEVICEREMAPPED,
-    CONTROLLERTOUCHPADDOWN,
-    CONTROLLERTOUCHPADMOTION,
-    CONTROLLERTOUCHPADUP,
-    CONTROLLERSENSORUPDATE,
-
-    FINGERDOWN = 0x700,
-    FINGERUP,
-    FINGERMOTION,
-
-    DOLLARGESTURE = 0x800,
-    DOLLARRECORD,
-    MULTIGESTURE,
-
-    CLIPBOARDUPDATE = 0x900,
-
-    DROPFILE = 0x1000,
-    DROPTEXT,
-    DROPBEGIN,
-    DROPCOMPLETE,
-
-    AUDIODEVICEADDED = 0x1100,
-    AUDIODEVICEREMOVED,
-
-    SENSORUPDATE = 0x1200,
-    RENDER_TARGETS_RESET = 0x2000,
-    RENDER_DEVICE_RESET,
-
-    POLLSENTINEL = 0x7F00,
-
-    USEREVENT = 0x8000,
-    LASTEVENT = 0xFFFF,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct CommonEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct DisplayEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub display: u32,
-    pub event: u8,
-    pub _padding1: u8,
-    pub _padding2: u8,
-    pub _padding3: u8,
-    pub data1: i32,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct WindowEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub window_id: u32,
-    pub event: WindowEventId,
-    pub padding1: u8,
-    pub padding2: u8,
-    pub padding3: u8,
-    pub data1: i32,
-    pub data2: i32,
-}
-
-#[repr(u8)]
-#[derive(Clone, Copy, PartialEq, Eq)]
-pub enum WindowEventId {
-    /// Never used *
-    None,
-    /// Window has been shown *
-    Shown,
-    /// Window has been hidden *
-    Hidden,
-    /// Window has been exposed and should be redrawn *
-    Exposed,
-    /// Window has been moved to data1, data2 *
-    Moved,
-    /// Window has been resized to data1xdata2 *
-    Resized,
-    /// The window size has changed, either as a result of an API call or through the system or user changing the window size. *
-    SizeChanged,
-    /// Window has been minimized *
-    Minimized,
-    /// Window has been maximized *
-    Maximized,
-    /// Window has been restored to normal size and position *
-    Restored,
-    /// Window has gained mouse focus *
-    Enter,
-    /// Window has lost mouse focus *
-    Leave,
-    /// Window has gained keyboard focus *
-    FocusGained,
-    /// Window has lost keyboard focus *
-    FocusLost,
-    /// The window manager requests that the window be closed *
-    Close,
-    /// Window is being offered a focus (should SetWindowInputFocus() on itself or a subwindow, or ignore) *
-    TakeFocus,
-    /// Window had a hit test that wasn't SDL_HITTEST_NORMAL. *
-    HitTest,
-    /// The ICC profile of the window's display has changed. *
-    IccprofChanged,
-    /// Window has been moved to display data1. *
-    DisplayChanged,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct KeyboardEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub window_id: u32,
-    pub state: PressedState,
-    pub repeat: u8,
-    pub _padding2: u8,
-    pub _padding3: u8,
-    pub keysym: Keysym,
-}
-
-const TEXTEDITINGEVENT_TEXT_SIZE: usize = 32;
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct TextEditingEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub window_id: u32,
-    pub text: [u8; TEXTEDITINGEVENT_TEXT_SIZE],
-    pub start: i32,
-    pub length: i32,
-}
-
-const TEXTINPUTEVENT_TEXT_SIZE: usize = 32;
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct TextInputEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub window_id: u32,
-    pub text: [u8; TEXTINPUTEVENT_TEXT_SIZE],
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct MouseMotionEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub window_id: u32,
-    pub which: u32,
-    pub state: u32,
-    pub x: i32,
-    pub y: i32,
-    pub xrel: i32,
-    pub yrel: i32,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct MouseButtonEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub window_id: u32,
-    pub which: u32,
-    pub button: MouseButton,
-    pub state: PressedState,
-    pub clicks: u8,
-    pub padding1: u8,
-    pub x: i32,
-    pub y: i32,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct MouseWheelEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub window_id: u32,
-    pub which: u32,
-    pub x: i32,
-    pub y: i32,
-    pub direction: u32,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct JoyAxisEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub which: JoystickID,
-    pub axis: u8,
-    pub padding1: u8,
-    pub padding2: u8,
-    pub padding3: u8,
-    pub value: i16,
-    pub padding4: u16,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct JoyBallEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub which: JoystickID,
-    pub ball: u8,
-    pub padding1: u8,
-    pub padding2: u8,
-    pub padding3: u8,
-    pub xrel: i16,
-    pub yrel: i16,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct JoyHatEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub which: JoystickID,
-    pub hat: u8,
-    pub value: u8,
-    pub padding1: u8,
-    pub padding2: u8,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct JoyButtonEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub which: JoystickID,
-    pub button: u8,
-    pub state: u8,
-    pub padding1: u8,
-    pub padding2: u8,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct JoyDeviceEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub which: i32,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct ControllerAxisEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub which: JoystickID,
-    pub axis: u8,
-    pub padding1: u8,
-    pub padding2: u8,
-    pub padding3: u8,
-    pub value: i16,
-    pub padding4: u16,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct ControllerButtonEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub which: JoystickID,
-    pub button: u8,
-    pub state: u8,
-    pub padding1: u8,
-    pub padding2: u8,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct ControllerDeviceEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub which: i32,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct ControllerTouchpadEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub which: JoystickID,
-    pub touchpad: i32,
-    pub finger: i32,
-    pub x: f32,
-    pub y: f32,
-    pub pressure: f32,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct ControllerSensorEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub which: JoystickID,
-    pub sensor: i32,
-    pub data: [f32; 3],
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct AudioDeviceEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub which: u32,
-    pub iscapture: u8,
-    pub padding1: u8,
-    pub padding2: u8,
-    pub padding3: u8,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct TouchFingerEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub touch_id: TouchID,
-    pub finger_id: FingerID,
-    pub x: f32,
-    pub y: f32,
-    pub dx: f32,
-    pub dy: f32,
-    pub pressure: f32,
-    pub window_id: u32,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct MultiGestureEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub touch_id: TouchID,
-    pub d_theta: f32,
-    pub d_dist: f32,
-    pub x: f32,
-    pub y: f32,
-    pub num_fingers: u16,
-    pub padding: u16,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct DollarGestureEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub touch_id: TouchID,
-    pub gesture_id: GestureID,
-    pub num_fingers: u32,
-    pub error: f32,
-    pub x: f32,
-    pub y: f32,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct DropEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub file: *const c_char,
-    pub window_id: u32,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct SensorEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub which: i32,
-    pub data: [f32; 6],
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct QuitEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct OSEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct UserEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub window_id: u32,
-    pub code: i32,
-    pub data1: *mut c_void,
-    pub data2: *mut c_void,
-}
-
-#[repr(C)]
-pub struct SysWMmsg {
-    _unused: [u8; 0],
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct SysWMEvent {
-    pub r#type: EventType,
-    pub timestamp: u32,
-    pub msg: *mut SysWMmsg,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub union Event {
-    pub r#type: EventType,
-    pub common: CommonEvent,
-    pub display: DisplayEvent,
-    pub window: WindowEvent,
-    pub key: KeyboardEvent,
-    pub edit: TextEditingEvent,
-    pub text: TextInputEvent,
-    pub motion: MouseMotionEvent,
-    pub button: MouseButtonEvent,
-    pub wheel: MouseWheelEvent,
-    pub jaxis: JoyAxisEvent,
-    pub jball: JoyBallEvent,
-    pub jhat: JoyHatEvent,
-    pub jbutton: JoyButtonEvent,
-    pub jdevice: JoyDeviceEvent,
-    pub caxis: ControllerAxisEvent,
-    pub cbutton: ControllerButtonEvent,
-    pub cdevice: ControllerDeviceEvent,
-    pub ctouchpad: ControllerTouchpadEvent,
-    pub csensor: ControllerSensorEvent,
-    pub adevice: AudioDeviceEvent,
-    pub sensor: SensorEvent,
-    pub quit: QuitEvent,
-    pub user: UserEvent,
-    pub syswm: SysWMEvent,
-    pub tfinger: TouchFingerEvent,
-    pub mgesture: MultiGestureEvent,
-    pub dgesture: DollarGestureEvent,
-    pub r#drop: DropEvent,
-}
-
-#[repr(C)]
-pub struct Version {
-    pub major: u8,
-    pub minor: u8,
-    pub patch: u8,
-}
-
-impl Version {
-    pub const fn current() -> Self {
-        Self {
-            major: MAJOR_VERSION,
-            minor: MINOR_VERSION,
-            patch: PATCH_VERSION,
-        }
-    }
-}
-
-#[repr(C)]
-pub enum SysWMType {
-    UNKNOWN,
-    WINDOWS,
-    X11,
-    DIRECTFB,
-    COCOA,
-    UIKIT,
-    WAYLAND,
-    MIR, /* no longer available, left for API/ABI compatibility. Remove in 2.1! */
-    WINRT,
-    ANDROID,
-    VIVANTE,
-    OS2,
-    HAIKU,
-    KMSDRM,
-    RISCOS,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct SysWMTypeX11 {
-    pub display: *mut c_void,
-    pub window: i32,
-}
-
-#[repr(C)]
-#[derive(Clone, Copy)]
-pub struct SysWMTypeWayland {
-    pub display: *mut c_void,
-    pub surface: *mut c_void,
-    pub shell_surface: *mut c_void,
-    pub egl_window: *mut c_void,
-    pub xdg_surface: *mut c_void,
-    pub xdg_toplevel: *mut c_void,
-    pub xdg_popup: *mut c_void,
-    pub xdg_positioner: *mut c_void,
-}
-
-#[repr(C)]
-pub union SysWMTypeUnion {
-    pub x11: SysWMTypeX11,
-    pub wayland: SysWMTypeWayland,
-    dummy: [u8; 64],
-}
-
-#[repr(C)]
-pub struct SysWMinfo {
-    pub version: Version,
-    pub subsystem: SysWMType,
-    pub info: SysWMTypeUnion,
-}
-
-extern "C" {
-    pub fn SDL_Init(flags: u32) -> i32;
-    pub fn SDL_Quit();
-
-    pub fn SDL_CreateWindow(
-        title: *const c_char,
-        x: i32,
-        y: i32,
-        w: i32,
-        h: i32,
-        flags: u32,
-    ) -> *mut Window;
-    pub fn SDL_DestroyWindow(window: *mut Window);
-
-    pub fn SDL_GetWindowID(window: *mut Window) -> u32;
-    pub fn SDL_GetWindowFromID(id: u32) -> *mut Window;
-    pub fn SDL_GetWindowSize(window: *mut Window, w: *mut i32, h: *mut i32);
-    pub fn SDL_GetKeyFromScancode(scancode: Scancode) -> Keycode;
-
-    pub fn SDL_PollEvent(event: *mut Event) -> i32;
-
-    pub fn SDL_GetWindowWMInfo(window: *mut Window, info: *mut SysWMinfo) -> Bool;
-
-    pub fn SDL_Vulkan_LoadLibrary(path: *const c_char) -> i32;
-    pub fn SDL_Vulkan_GetInstanceExtensions(
-        window: *mut Window,
-        count: &mut u32,
-        names: *mut *const c_char,
-    ) -> i32;
-    pub fn SDL_Vulkan_GetVkGetInstanceProcAddr() -> *mut c_void;
-    pub fn SDL_Vulkan_CreateSurface(window: *mut Window, instance: u64, surface: *mut u64) -> Bool;
-    pub fn SDL_Vulkan_GetDrawableSize(window: *mut Window, w: *mut i32, h: *mut i32);
-}
-
-pub const INIT_VIDEO: u32 = 0x0000_0020;
-pub const WINDOW_SHOWN: u32 = 0x0000_0004;
-pub const WINDOW_RESIZABLE: u32 = 0x0000_0020;
-pub const WINDOW_ALLOW_HIGHDPI: u32 = 0x0000_2000;
-pub const WINDOW_VULKAN: u32 = 0x1000_0000;
index 6f53544fc789d5ee625606359efaefe7dae0b3fe..71bda09b490cccb73fdb6e83ee2f95a3faa25419 100644 (file)
@@ -16,7 +16,7 @@ use renderdoc_sys as rdoc;
 
 use fonts::{FontFamily, Fonts};
 use helpers::load_obj;
-use narcissus_app::{create_app, Event, Key, PressedState, WindowDesc};
+use narcissus_app::{create_app, Event, Key, WindowDesc};
 use narcissus_core::{box_assume_init, default, rand::Pcg64, zeroed_box, BitIter};
 use narcissus_font::{FontCollection, GlyphCache, HorizontalMetrics};
 use narcissus_gpu::{
@@ -447,23 +447,24 @@ impl GameState {
 }
 
 struct UiState<'a> {
-    scale: f32,
     fonts: &'a Fonts<'a>,
     glyph_cache: GlyphCache<'a, Fonts<'a>>,
 
+    scale: f32,
+
     tmp_string: String,
 
     draw_cmds: Vec<Draw2dCmd>,
 }
 
 impl<'a> UiState<'a> {
-    fn new(fonts: &'a Fonts<'a>, scale: f32) -> Self {
+    fn new(fonts: &'a Fonts<'a>) -> Self {
         let glyph_cache = GlyphCache::new(fonts, GLYPH_CACHE_SIZE, GLYPH_CACHE_SIZE, 1);
 
         Self {
-            scale,
             fonts,
             glyph_cache,
+            scale: 1.0,
             tmp_string: default(),
             draw_cmds: vec![],
         }
@@ -478,11 +479,14 @@ impl<'a> UiState<'a> {
         border_color: u32,
         background_color: u32,
     ) {
+        let bounds = bounds * self.scale;
+
         let bounds_min = position;
         let bounds_max = position + bounds;
 
-        let border_width = border_width.clamp(0.0, 255.0).floor() as u8;
-        let border_radii = border_radii.map(|radius| radius.clamp(0.0, 255.0).floor() as u8);
+        let border_width = (border_width * self.scale).clamp(0.0, 255.0).floor() as u8;
+        let border_radii =
+            border_radii.map(|radius| (radius * self.scale).clamp(0.0, 255.0).floor() as u8);
 
         self.draw_cmds.push(Draw2dCmd::rect(
             bounds_min,
@@ -501,7 +505,7 @@ impl<'a> UiState<'a> {
         font_family: FontFamily,
         font_size_px: f32,
         args: std::fmt::Arguments,
-    ) {
+    ) -> f32 {
         let font = self.fonts.font(font_family);
         let font_size_px = font_size_px * self.scale;
         let scale = font.scale_for_size_px(font_size_px);
@@ -542,6 +546,8 @@ impl<'a> UiState<'a> {
 
             x += advance_width * scale;
         }
+
+        (font.ascent() - font.descent() + font.line_gap()) * scale
     }
 }
 
@@ -1657,6 +1663,9 @@ pub fn main() {
         std::env::set_var("SDL_VIDEODRIVER", "wayland")
     }
 
+    let ui_scale_override =
+        std::env::var("NARCISSUS_UI_SCALE").map_or(None, |scale| scale.parse::<f32>().ok());
+
     let app = create_app();
     let gpu = create_device(narcissus_gpu::DeviceBackend::Vulkan);
 
@@ -1666,15 +1675,13 @@ pub fn main() {
         height: 600,
     });
 
-    let scale = 1.0;
-
     let thread_token = ThreadToken::new();
     let thread_token = &thread_token;
 
     let mut action_queue = Vec::new();
 
     let fonts = Fonts::new();
-    let mut ui_state = UiState::new(&fonts, scale);
+    let mut ui_state = UiState::new(&fonts);
     let mut game_state = GameState::new();
     let mut draw_state = DrawState::new(gpu.as_ref(), thread_token);
 
@@ -1735,22 +1742,20 @@ pub fn main() {
                 height,
                 image: swapchain_image,
             } = loop {
-                let (_width, height) = window.extent();
-                let (drawable_width, drawable_height) = window.drawable_extent();
-
-                ui_state.scale = drawable_height as f32 / height as f32;
-
+                let (width, height) = window.size_in_pixels();
                 if let Ok(result) = gpu.acquire_swapchain(
                     frame,
                     window.upcast(),
-                    drawable_width,
-                    drawable_height,
+                    width,
+                    height,
                     &mut swapchain_configurator,
                 ) {
                     break result;
                 }
             };
 
+            let mut window_display_scale = window.display_scale();
+
             let tick_start = Instant::now();
             'tick: loop {
                 'poll_events: while let Some(event) = app.poll_event() {
@@ -1760,7 +1765,7 @@ pub fn main() {
                             window_id: _,
                             key,
                             repeat,
-                            pressed,
+                            down,
                             modifiers: _,
                         } => {
                             if repeat {
@@ -1777,19 +1782,19 @@ pub fn main() {
                                 _ => None,
                             };
 
-                            let value = match pressed {
-                                PressedState::Released => 0.0,
-                                PressedState::Pressed => 1.0,
-                            };
+                            let value = if down { 1.0 } else { 0.0 };
 
                             if let Some(action) = action {
                                 action_queue.push(ActionEvent { action, value })
                             }
                         }
+                        ScaleChanged { window_id: _ } => {
+                            window_display_scale = window.display_scale()
+                        }
                         Quit => {
                             break 'main;
                         }
-                        Close { window_id } => {
+                        CloseRequested { window_id } => {
                             let window = app.window(window_id);
                             gpu.destroy_swapchain(window.upcast());
                         }
@@ -1808,11 +1813,13 @@ pub fn main() {
                 tick_accumulator -= target_dt;
             }
 
+            ui_state.scale = ui_scale_override.unwrap_or(window_display_scale);
+
             let draw_start = Instant::now();
             let tick_duration = draw_start - tick_start;
             let (base_x, base_y) = sin_cos_pi_f32(game_state.time);
-            let base_x = (base_x + 1.0) * 0.5;
-            let base_y = (base_y + 1.0) * 0.5;
+            let base_x = (base_x + 1.0) * 0.5 * ui_state.scale;
+            let base_y = (base_y + 1.0) * 0.5 * ui_state.scale;
 
             for _ in 0..100 {
                 ui_state.rect(
@@ -1827,16 +1834,18 @@ pub fn main() {
 
             let (s, _) = sin_cos_pi_f32(game_state.time * 0.1);
 
-            for i in 0..224 {
-                ui_state.text_fmt(
+            let mut y = 8.0 * ui_state.scale;
+            for _ in 0..224 {
+                let vertical_advance = ui_state.text_fmt(
                         5.0,
-                        10.0 + (i as f32) * (22.0 + s * 8.0),
+                        y,
                         FontFamily::NotoSansJapanese,
                         16.0 + s * 8.0,
                         format_args!(
                             "お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog.  ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog.  ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog.  ████████"
                         ),
                     );
+                y += vertical_advance;
             }
 
             for i in 0..500 {
@@ -1845,7 +1854,7 @@ pub fn main() {
                     (vec2(width as f32, height as f32) / 2.0)
                         - 250.0
                         - vec2(rect_x, rect_y) * 1000.0,
-                    vec2(500.0, 500.0),
+                    vec2(400.0, 400.0),
                     10.0,
                     [rect_x * 50.0, rect_y * 50.0, 25.0, 25.0],
                     0xffffffff,
@@ -1862,21 +1871,20 @@ pub fn main() {
                 microshades::ORANGE_RGBA8[2].rotate_right(8),
             );
 
+            y = base_y * 150.0;
             for i in 0..10 {
                 if i & 1 != 0 {
-                    let i = i as f32;
-                    ui_state.text_fmt(
-                        base_x * 100.0 * scale - 5.0,
-                        base_y * 150.0 * scale + i * 50.0 * scale,
+                    y += ui_state.text_fmt(
+                        base_x * 100.0 - 5.0,
+                        y,
                         FontFamily::RobotoRegular,
                         20.0,
                         format_args!("tick: {:?}", tick_duration),
                     );
                 } else {
-                    let i = i as f32;
-                    ui_state.text_fmt(
-                        base_x * 100.0 * scale - 5.0,
-                        base_y * 150.0 * scale + i * 50.0 * scale,
+                    y += ui_state.text_fmt(
+                        base_x * 100.0 - 5.0,
+                        y,
                         FontFamily::RobotoRegular,
                         20.0,
                         format_args!("draw: {:?}", draw_duration),