1#![warn(clippy::missing_inline_in_public_items)]
2#![allow(clippy::result_unit_err)]
3
4extern crate alloc;
5
6use alloc::sync::Arc;
7use fermium::{mouse::SDL_SetRelativeMouseMode, prelude::SDL_SetHint};
8use init::{InitFlags, SdlInit};
9
10pub mod controller;
11pub mod error;
12pub mod events;
13pub mod init;
14pub mod surface;
15pub mod video;
16
17#[derive(Clone)]
18#[repr(transparent)]
19pub struct Sdl {
20 init: Arc<SdlInit>,
21}
22impl Sdl {
23 #[inline]
24 pub fn init(flags: InitFlags) -> Self {
25 Self { init: SdlInit::try_new_arc(flags).unwrap() }
26 }
27
28 #[inline]
29 pub fn set_controller_use_button_labels(&self, labels: bool) -> bool {
30 const SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS: &[u8] =
31 b"SDL_GAMECONTROLLER_USE_BUTTON_LABELS\0";
32 let value: &[u8] = if labels { b"1\0" } else { b"0\0" };
33 unsafe {
34 SDL_SetHint(SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS.as_ptr().cast(), value.as_ptr().cast())
35 }
36 .into()
37 }
38
39 #[inline]
48 pub fn set_relative_mouse_mode(&self, b: bool) -> Result<(), ()> {
49 if unsafe { SDL_SetRelativeMouseMode(b.into()) } == 0 {
50 Ok(())
51 } else {
52 Err(())
53 }
54 }
55}