Skip to content

Commit 4d61d9a

Browse files
committed
use different bind
1 parent d862759 commit 4d61d9a

File tree

4 files changed

+124
-52
lines changed

4 files changed

+124
-52
lines changed

sdl2-sys/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,8 @@ fn generate_bindings(target: &str, host: &str, headers_paths: &[String]) {
657657
let mut bindings = bindgen::Builder::default()
658658
// enable no_std-friendly output by only using core definitions
659659
.use_core()
660-
.constified_enum("SDL_RendererFlip")
661-
.constified_enum("SDL_Keymod")
660+
.bitfield_enum("SDL_RendererFlip")
661+
.newtype_enum("SDL_Keymod")
662662
.default_enum_style(bindgen::EnumVariation::Rust {
663663
non_exhaustive: false,
664664
})

sdl2-sys/sdl_bindings.rs

Lines changed: 98 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7929,26 +7929,64 @@ pub enum SDL_KeyCode {
79297929
SDLK_CALL = 1073742113,
79307930
SDLK_ENDCALL = 1073742114,
79317931
}
7932-
pub const SDL_Keymod_KMOD_NONE: SDL_Keymod = 0;
7933-
pub const SDL_Keymod_KMOD_LSHIFT: SDL_Keymod = 1;
7934-
pub const SDL_Keymod_KMOD_RSHIFT: SDL_Keymod = 2;
7935-
pub const SDL_Keymod_KMOD_LCTRL: SDL_Keymod = 64;
7936-
pub const SDL_Keymod_KMOD_RCTRL: SDL_Keymod = 128;
7937-
pub const SDL_Keymod_KMOD_LALT: SDL_Keymod = 256;
7938-
pub const SDL_Keymod_KMOD_RALT: SDL_Keymod = 512;
7939-
pub const SDL_Keymod_KMOD_LGUI: SDL_Keymod = 1024;
7940-
pub const SDL_Keymod_KMOD_RGUI: SDL_Keymod = 2048;
7941-
pub const SDL_Keymod_KMOD_NUM: SDL_Keymod = 4096;
7942-
pub const SDL_Keymod_KMOD_CAPS: SDL_Keymod = 8192;
7943-
pub const SDL_Keymod_KMOD_MODE: SDL_Keymod = 16384;
7944-
pub const SDL_Keymod_KMOD_SCROLL: SDL_Keymod = 32768;
7945-
pub const SDL_Keymod_KMOD_CTRL: SDL_Keymod = 192;
7946-
pub const SDL_Keymod_KMOD_SHIFT: SDL_Keymod = 3;
7947-
pub const SDL_Keymod_KMOD_ALT: SDL_Keymod = 768;
7948-
pub const SDL_Keymod_KMOD_GUI: SDL_Keymod = 3072;
7949-
pub const SDL_Keymod_KMOD_RESERVED: SDL_Keymod = 32768;
7932+
impl SDL_Keymod {
7933+
pub const KMOD_NONE: SDL_Keymod = SDL_Keymod(0);
7934+
}
7935+
impl SDL_Keymod {
7936+
pub const KMOD_LSHIFT: SDL_Keymod = SDL_Keymod(1);
7937+
}
7938+
impl SDL_Keymod {
7939+
pub const KMOD_RSHIFT: SDL_Keymod = SDL_Keymod(2);
7940+
}
7941+
impl SDL_Keymod {
7942+
pub const KMOD_LCTRL: SDL_Keymod = SDL_Keymod(64);
7943+
}
7944+
impl SDL_Keymod {
7945+
pub const KMOD_RCTRL: SDL_Keymod = SDL_Keymod(128);
7946+
}
7947+
impl SDL_Keymod {
7948+
pub const KMOD_LALT: SDL_Keymod = SDL_Keymod(256);
7949+
}
7950+
impl SDL_Keymod {
7951+
pub const KMOD_RALT: SDL_Keymod = SDL_Keymod(512);
7952+
}
7953+
impl SDL_Keymod {
7954+
pub const KMOD_LGUI: SDL_Keymod = SDL_Keymod(1024);
7955+
}
7956+
impl SDL_Keymod {
7957+
pub const KMOD_RGUI: SDL_Keymod = SDL_Keymod(2048);
7958+
}
7959+
impl SDL_Keymod {
7960+
pub const KMOD_NUM: SDL_Keymod = SDL_Keymod(4096);
7961+
}
7962+
impl SDL_Keymod {
7963+
pub const KMOD_CAPS: SDL_Keymod = SDL_Keymod(8192);
7964+
}
7965+
impl SDL_Keymod {
7966+
pub const KMOD_MODE: SDL_Keymod = SDL_Keymod(16384);
7967+
}
7968+
impl SDL_Keymod {
7969+
pub const KMOD_SCROLL: SDL_Keymod = SDL_Keymod(32768);
7970+
}
7971+
impl SDL_Keymod {
7972+
pub const KMOD_CTRL: SDL_Keymod = SDL_Keymod(192);
7973+
}
7974+
impl SDL_Keymod {
7975+
pub const KMOD_SHIFT: SDL_Keymod = SDL_Keymod(3);
7976+
}
7977+
impl SDL_Keymod {
7978+
pub const KMOD_ALT: SDL_Keymod = SDL_Keymod(768);
7979+
}
7980+
impl SDL_Keymod {
7981+
pub const KMOD_GUI: SDL_Keymod = SDL_Keymod(3072);
7982+
}
7983+
impl SDL_Keymod {
7984+
pub const KMOD_RESERVED: SDL_Keymod = SDL_Keymod(32768);
7985+
}
7986+
#[repr(transparent)]
79507987
#[doc = " \\brief Enumeration of valid key mods (possibly OR'd together)."]
7951-
pub type SDL_Keymod = libc::c_uint;
7988+
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
7989+
pub struct SDL_Keymod(pub libc::c_uint);
79527990
#[doc = " \\brief The SDL keysym structure, used in key events.\n\n \\note If you are looking for translated character input, see the ::SDL_TEXTINPUT event."]
79537991
#[repr(C)]
79547992
#[derive(Copy, Clone)]
@@ -15506,14 +15544,48 @@ pub enum SDL_TextureModulate {
1550615544
#[doc = "< srcA = srcA * alpha"]
1550715545
SDL_TEXTUREMODULATE_ALPHA = 2,
1550815546
}
15509-
#[doc = "< Do not flip"]
15510-
pub const SDL_RendererFlip_SDL_FLIP_NONE: SDL_RendererFlip = 0;
15511-
#[doc = "< flip horizontally"]
15512-
pub const SDL_RendererFlip_SDL_FLIP_HORIZONTAL: SDL_RendererFlip = 1;
15513-
#[doc = "< flip vertically"]
15514-
pub const SDL_RendererFlip_SDL_FLIP_VERTICAL: SDL_RendererFlip = 2;
15547+
impl SDL_RendererFlip {
15548+
#[doc = "< Do not flip"]
15549+
pub const SDL_FLIP_NONE: SDL_RendererFlip = SDL_RendererFlip(0);
15550+
}
15551+
impl SDL_RendererFlip {
15552+
#[doc = "< flip horizontally"]
15553+
pub const SDL_FLIP_HORIZONTAL: SDL_RendererFlip = SDL_RendererFlip(1);
15554+
}
15555+
impl SDL_RendererFlip {
15556+
#[doc = "< flip vertically"]
15557+
pub const SDL_FLIP_VERTICAL: SDL_RendererFlip = SDL_RendererFlip(2);
15558+
}
15559+
impl ::core::ops::BitOr<SDL_RendererFlip> for SDL_RendererFlip {
15560+
type Output = Self;
15561+
#[inline]
15562+
fn bitor(self, other: Self) -> Self {
15563+
SDL_RendererFlip(self.0 | other.0)
15564+
}
15565+
}
15566+
impl ::core::ops::BitOrAssign for SDL_RendererFlip {
15567+
#[inline]
15568+
fn bitor_assign(&mut self, rhs: SDL_RendererFlip) {
15569+
self.0 |= rhs.0;
15570+
}
15571+
}
15572+
impl ::core::ops::BitAnd<SDL_RendererFlip> for SDL_RendererFlip {
15573+
type Output = Self;
15574+
#[inline]
15575+
fn bitand(self, other: Self) -> Self {
15576+
SDL_RendererFlip(self.0 & other.0)
15577+
}
15578+
}
15579+
impl ::core::ops::BitAndAssign for SDL_RendererFlip {
15580+
#[inline]
15581+
fn bitand_assign(&mut self, rhs: SDL_RendererFlip) {
15582+
self.0 &= rhs.0;
15583+
}
15584+
}
15585+
#[repr(transparent)]
1551515586
#[doc = " Flip constants for SDL_RenderCopyEx"]
15516-
pub type SDL_RendererFlip = libc::c_uint;
15587+
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
15588+
pub struct SDL_RendererFlip(pub libc::c_uint);
1551715589
#[doc = " A structure representing rendering state"]
1551815590
#[repr(C)]
1551915591
#[derive(Copy, Clone)]

src/sdl2/keyboard/mod.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ pub use self::scancode::Scancode;
1818

1919
bitflags! {
2020
pub struct Mod: u16 {
21-
const NOMOD = crate::sys::SDL_Keymod_KMOD_NONE as u16;
22-
const LSHIFTMOD = crate::sys::SDL_Keymod_KMOD_LSHIFT as u16;
23-
const RSHIFTMOD = crate::sys::SDL_Keymod_KMOD_RSHIFT as u16;
24-
const LCTRLMOD = crate::sys::SDL_Keymod_KMOD_LCTRL as u16;
25-
const RCTRLMOD = crate::sys::SDL_Keymod_KMOD_RCTRL as u16;
26-
const LALTMOD = crate::sys::SDL_Keymod_KMOD_LALT as u16;
27-
const RALTMOD = crate::sys::SDL_Keymod_KMOD_RALT as u16;
28-
const LGUIMOD = crate::sys::SDL_Keymod_KMOD_LGUI as u16;
29-
const RGUIMOD = crate::sys::SDL_Keymod_KMOD_RGUI as u16;
30-
const NUMMOD = crate::sys::SDL_Keymod_KMOD_NUM as u16;
31-
const CAPSMOD = crate::sys::SDL_Keymod_KMOD_CAPS as u16;
32-
const MODEMOD = crate::sys::SDL_Keymod_KMOD_MODE as u16;
33-
const RESERVEDMOD = crate::sys::SDL_Keymod_KMOD_RESERVED as u16;
21+
const NOMOD = crate::sys::SDL_Keymod::KMOD_NONE.0 as u16;
22+
const LSHIFTMOD = crate::sys::SDL_Keymod::KMOD_LSHIFT.0 as u16;
23+
const RSHIFTMOD = crate::sys::SDL_Keymod::KMOD_RSHIFT.0 as u16;
24+
const LCTRLMOD = crate::sys::SDL_Keymod::KMOD_LCTRL.0 as u16;
25+
const RCTRLMOD = crate::sys::SDL_Keymod::KMOD_RCTRL.0 as u16;
26+
const LALTMOD = crate::sys::SDL_Keymod::KMOD_LALT.0 as u16;
27+
const RALTMOD = crate::sys::SDL_Keymod::KMOD_RALT.0 as u16;
28+
const LGUIMOD = crate::sys::SDL_Keymod::KMOD_LGUI.0 as u16;
29+
const RGUIMOD = crate::sys::SDL_Keymod::KMOD_RGUI.0 as u16;
30+
const NUMMOD = crate::sys::SDL_Keymod::KMOD_NUM.0 as u16;
31+
const CAPSMOD = crate::sys::SDL_Keymod::KMOD_CAPS.0 as u16;
32+
const MODEMOD = crate::sys::SDL_Keymod::KMOD_MODE.0 as u16;
33+
const RESERVEDMOD = crate::sys::SDL_Keymod::KMOD_RESERVED.0 as u16;
3434
}
3535
}
3636

@@ -186,7 +186,7 @@ impl KeyboardUtil {
186186

187187
#[doc(alias = "SDL_GetModState")]
188188
pub fn mod_state(&self) -> Mod {
189-
unsafe { Mod::from_bits(sys::SDL_GetModState() as u16).unwrap() }
189+
unsafe { Mod::from_bits(sys::SDL_GetModState().0 as u16).unwrap() }
190190
}
191191

192192
#[doc(alias = "SDL_SetModState")]

src/sdl2/render.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,12 +1638,12 @@ impl<T: RenderTarget> Canvas<T> {
16381638
P: Into<Option<FPoint>>,
16391639
{
16401640
let flip = match (flip_horizontal, flip_vertical) {
1641-
(false, false) => crate::sys::SDL_RendererFlip_SDL_FLIP_NONE,
1642-
(true, false) => crate::sys::SDL_RendererFlip_SDL_FLIP_HORIZONTAL,
1643-
(false, true) => crate::sys::SDL_RendererFlip_SDL_FLIP_VERTICAL,
1641+
(false, false) => crate::sys::SDL_RendererFlip::SDL_FLIP_NONE,
1642+
(true, false) => crate::sys::SDL_RendererFlip::SDL_FLIP_HORIZONTAL,
1643+
(false, true) => crate::sys::SDL_RendererFlip::SDL_FLIP_VERTICAL,
16441644
(true, true) => {
1645-
crate::sys::SDL_RendererFlip_SDL_FLIP_HORIZONTAL
1646-
| crate::sys::SDL_RendererFlip_SDL_FLIP_VERTICAL
1645+
crate::sys::SDL_RendererFlip::SDL_FLIP_HORIZONTAL
1646+
| crate::sys::SDL_RendererFlip::SDL_FLIP_VERTICAL
16471647
}
16481648
};
16491649

@@ -1741,12 +1741,12 @@ impl<T: RenderTarget> Canvas<T> {
17411741
P: Into<Option<Point>>,
17421742
{
17431743
let flip = match (flip_horizontal, flip_vertical) {
1744-
(false, false) => crate::sys::SDL_RendererFlip_SDL_FLIP_NONE,
1745-
(true, false) => crate::sys::SDL_RendererFlip_SDL_FLIP_HORIZONTAL,
1746-
(false, true) => crate::sys::SDL_RendererFlip_SDL_FLIP_VERTICAL,
1744+
(false, false) => crate::sys::SDL_RendererFlip::SDL_FLIP_NONE,
1745+
(true, false) => crate::sys::SDL_RendererFlip::SDL_FLIP_HORIZONTAL,
1746+
(false, true) => crate::sys::SDL_RendererFlip::SDL_FLIP_VERTICAL,
17471747
(true, true) => {
1748-
crate::sys::SDL_RendererFlip_SDL_FLIP_HORIZONTAL
1749-
| crate::sys::SDL_RendererFlip_SDL_FLIP_VERTICAL
1748+
crate::sys::SDL_RendererFlip::SDL_FLIP_HORIZONTAL
1749+
| crate::sys::SDL_RendererFlip::SDL_FLIP_VERTICAL
17501750
}
17511751
};
17521752

0 commit comments

Comments
 (0)