Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ name = "sdl2"
path = "src/sdl2/lib.rs"

[dependencies]
bitflags = "1.2.1"
bitflags = "2.10.0"
libc = "0.2.92"
lazy_static = "1.4.0"
lazy_static = "1.5.0"

[dependencies.sdl2-sys]
path = "sdl2-sys"
Expand All @@ -31,9 +31,9 @@ version = ">= 1.0"
optional = true

[dev-dependencies]
rand = "0.7"
wgpu = { version = "0.20", features = ["spirv"] }
pollster = "0.2.4"
rand = "0.9.1"
wgpu = { version = "26.0.1", features = ["spirv"] }
pollster = "0.4.0"
env_logger = "0.11.0"

[dependencies.raw-window-handle]
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
In this file will be listed the changes, especially the breaking ones that one should be careful of
when upgrading from a version of rust-sdl2 to another.

### v0.39.0

[PR #1506](https://github.com/Rust-SDL2/rust-sdl2/pull/1506) **BREAKING CHANGE** Update crates.io dependencies, update bundled SDL2 to 2.32.10, add whitelist to bindgen to only emit SDL related items, and specifically no platform (or compiler, etc) specific items. Implement the same set of useful derived traits on bitflags types.

### v0.38.0

[PR #1493](https://github.com/Rust-SDL2/rust-sdl2/pull/1493) Add `Rect::origin` and specifies origin location in `Rect::new`.

[PR #1472](https://github.com/Rust-SDL2/rust-sdl2/pull/1472) Add `Canvas::render_geometry`, `Canvas::render_geometry_raw` and an example that uses them both. Both these bindings use `SDL_RenderGeometryRaw`.
Expand Down
6 changes: 3 additions & 3 deletions examples/audio-whitenoise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ impl AudioCallback for MyCallback {
type Channel = f32;

fn callback(&mut self, out: &mut [f32]) {
use self::rand::{thread_rng, Rng};
let mut rng = thread_rng();
use self::rand::{rng, Rng};
let mut rng = rng();

// Generate white noise
for x in out.iter_mut() {
*x = (rng.gen_range(0.0, 2.0) - 1.0) * self.volume;
*x = (rng.random_range(0.0..2.0) - 1.0) * self.volume;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion sdl2-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ path = "src/lib.rs"
libc = "^0.2"

[build-dependencies.bindgen]
version = "^0.69"
version = "0.72.1"
optional = true

[build-dependencies.pkg-config]
Expand Down
2 changes: 1 addition & 1 deletion sdl2-sys/SDL
Submodule SDL updated 1349 files
1 change: 1 addition & 0 deletions sdl2-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ fn generate_bindings(target: &str, host: &str, headers_paths: &[String]) {
let mut bindings = bindgen::Builder::default()
// enable no_std-friendly output by only using core definitions
.use_core()
.allowlist_item("(SDL|AUDIO|RW)_.*")
.bitfield_enum("SDL_RendererFlip")
.newtype_enum("SDL_Keymod")
.default_enum_style(bindgen::EnumVariation::Rust {
Expand Down
34,570 changes: 8,190 additions & 26,380 deletions sdl2-sys/sdl_bindings.rs

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions src/sdl2/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ pub enum EventType {
ControllerDeviceAdded = SDL_EventType::SDL_CONTROLLERDEVICEADDED as u32,
ControllerDeviceRemoved = SDL_EventType::SDL_CONTROLLERDEVICEREMOVED as u32,
ControllerDeviceRemapped = SDL_EventType::SDL_CONTROLLERDEVICEREMAPPED as u32,
ControllerSteamHandleUpdate = SDL_EventType::SDL_CONTROLLERSTEAMHANDLEUPDATED as u32,
ControllerTouchpadDown = SDL_EventType::SDL_CONTROLLERTOUCHPADDOWN as u32,
ControllerTouchpadMotion = SDL_EventType::SDL_CONTROLLERTOUCHPADMOTION as u32,
ControllerTouchpadUp = SDL_EventType::SDL_CONTROLLERTOUCHPADUP as u32,
Expand Down Expand Up @@ -411,6 +412,7 @@ pub enum DisplayEvent {
Orientation(Orientation),
Connected,
Disconnected,
Moved,
}

impl DisplayEvent {
Expand All @@ -433,6 +435,7 @@ impl DisplayEvent {
}
sys::SDL_DisplayEventID::SDL_DISPLAYEVENT_CONNECTED => DisplayEvent::Connected,
sys::SDL_DisplayEventID::SDL_DISPLAYEVENT_DISCONNECTED => DisplayEvent::Disconnected,
sys::SDL_DisplayEventID::SDL_DISPLAYEVENT_MOVED => DisplayEvent::Moved,
}
}

Expand All @@ -450,6 +453,7 @@ impl DisplayEvent {
sys::SDL_DisplayEventID::SDL_DISPLAYEVENT_DISCONNECTED as u8,
0,
),
DisplayEvent::Moved => (sys::SDL_DisplayEventID::SDL_DISPLAYEVENT_MOVED as u8, 0),
}
}

Expand Down Expand Up @@ -739,6 +743,11 @@ pub enum Event {
/// The controller's joystick `id`
which: u32,
},
ControllerSteamHandleUpdate {
timestamp: u32,
/// The controller's joystick `id`
which: u32,
},

ControllerTouchpadDown {
timestamp: u32,
Expand Down Expand Up @@ -1464,6 +1473,22 @@ impl Event {
}
}

Event::ControllerSteamHandleUpdate { timestamp, which } => {
let event = sys::SDL_ControllerDeviceEvent {
type_: SDL_EventType::SDL_CONTROLLERSTEAMHANDLEUPDATED as u32,
timestamp,
which: which as i32,
};
unsafe {
ptr::copy(
&event,
ret.as_mut_ptr() as *mut sys::SDL_ControllerDeviceEvent,
1,
);
Some(ret.assume_init())
}
}

Event::FingerDown { .. }
| Event::FingerUp { .. }
| Event::FingerMotion { .. }
Expand Down Expand Up @@ -1784,6 +1809,13 @@ impl Event {
which: event.which as u32,
}
}
EventType::ControllerSteamHandleUpdate => {
let event = raw.cdevice;
Event::ControllerSteamHandleUpdate {
timestamp: event.timestamp,
which: event.which as u32,
}
}
EventType::ControllerTouchpadDown => {
let event = raw.ctouchpad;
Event::ControllerTouchpadDown {
Expand Down Expand Up @@ -2101,6 +2133,10 @@ impl Event {
| (Self::ControllerDeviceAdded { .. }, Self::ControllerDeviceAdded { .. })
| (Self::ControllerDeviceRemoved { .. }, Self::ControllerDeviceRemoved { .. })
| (Self::ControllerDeviceRemapped { .. }, Self::ControllerDeviceRemapped { .. })
| (
Self::ControllerSteamHandleUpdate { .. },
Self::ControllerSteamHandleUpdate { .. },
)
| (Self::FingerDown { .. }, Self::FingerDown { .. })
| (Self::FingerUp { .. }, Self::FingerUp { .. })
| (Self::FingerMotion { .. }, Self::FingerMotion { .. })
Expand Down Expand Up @@ -2170,6 +2206,7 @@ impl Event {
Self::ControllerDeviceAdded { timestamp, .. } => timestamp,
Self::ControllerDeviceRemoved { timestamp, .. } => timestamp,
Self::ControllerDeviceRemapped { timestamp, .. } => timestamp,
Self::ControllerSteamHandleUpdate { timestamp, .. } => timestamp,
Self::ControllerTouchpadDown { timestamp, .. } => timestamp,
Self::ControllerTouchpadMotion { timestamp, .. } => timestamp,
Self::ControllerTouchpadUp { timestamp, .. } => timestamp,
Expand Down Expand Up @@ -2413,6 +2450,7 @@ impl Event {
| Self::ControllerDeviceAdded { .. }
| Self::ControllerDeviceRemoved { .. }
| Self::ControllerDeviceRemapped { .. }
| Self::ControllerSteamHandleUpdate { .. }
)
}

Expand Down
1 change: 1 addition & 0 deletions src/sdl2/image/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use version::Version;
bitflags! {
/// InitFlags are passed to init() to control which subsystem
/// functionality to load.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct InitFlag : u32 {
const JPG = image::IMG_InitFlags_IMG_INIT_JPG;
const PNG = image::IMG_InitFlags_IMG_INIT_PNG;
Expand Down
3 changes: 2 additions & 1 deletion src/sdl2/keyboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ pub use self::keycode::Keycode;
pub use self::scancode::Scancode;

bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct Mod: u16 {
const NOMOD = crate::sys::SDL_Keymod::KMOD_NONE.0 as u16;
const NOMOD = crate::sys::SDL_Keymod::KMOD_NONE.0 as u16;
const LSHIFTMOD = crate::sys::SDL_Keymod::KMOD_LSHIFT.0 as u16;
const RSHIFTMOD = crate::sys::SDL_Keymod::KMOD_RSHIFT.0 as u16;
const LCTRLMOD = crate::sys::SDL_Keymod::KMOD_LCTRL.0 as u16;
Expand Down
4 changes: 3 additions & 1 deletion src/sdl2/messagebox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::video::Window;
use crate::sys;

bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct MessageBoxFlag: u32 {
const ERROR =
sys::SDL_MessageBoxFlags::SDL_MESSAGEBOX_ERROR as u32;
Expand All @@ -24,6 +25,7 @@ bitflags! {
}

bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct MessageBoxButtonFlag: u32 {
const ESCAPEKEY_DEFAULT =
sys::SDL_MessageBoxButtonFlags::SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT as u32;
Expand All @@ -33,7 +35,7 @@ bitflags! {
}
}

#[derive(Debug)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct MessageBoxColorScheme {
pub background: (u8, u8, u8),
pub text: (u8, u8, u8),
Expand Down
4 changes: 3 additions & 1 deletion src/sdl2/mixer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ pub fn get_linked_version() -> Version {
}

bitflags!(
pub struct InitFlag : u32 {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct InitFlag: u32 {
const FLAC = mixer::MIX_InitFlags_MIX_INIT_FLAC;
const MOD = mixer::MIX_InitFlags_MIX_INIT_MOD;
const MP3 = mixer::MIX_InitFlags_MIX_INIT_MP3;
Expand All @@ -108,6 +109,7 @@ bitflags!(

bitflags!(
/// Which audio format changes are allowed when opening a device ([`open_audio_device`]).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct AllowChangeFlag: u32 {
const FREQUENCY = sys::SDL_AUDIO_ALLOW_FREQUENCY_CHANGE;
const FORMAT = sys::SDL_AUDIO_ALLOW_FORMAT_CHANGE;
Expand Down
8 changes: 7 additions & 1 deletion src/sdl2/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,12 +785,18 @@ impl CanvasBuilder {

/// Builds the renderer.
#[doc(alias = "SDL_CreateRenderer")]
pub fn build(self) -> Result<WindowCanvas, IntegerOrSdlError> {
pub fn build(mut self) -> Result<WindowCanvas, IntegerOrSdlError> {
use crate::common::IntegerOrSdlError::*;
let index = match self.index {
None => -1,
Some(index) => validate_int(index, "index")?,
};
if self.window.has_surface() {
// If the window has a surface, we need to destroy it before creating a renderer.
self.window
.destroy_surface()
.map_err(|e| IntegerOrSdlError::SdlError(e))?;
}
let raw = unsafe { sys::SDL_CreateRenderer(self.window.raw(), index, self.renderer_flags) };

if raw.is_null() {
Expand Down
1 change: 1 addition & 0 deletions src/sdl2/ttf/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use sys::SDL_Surface;

bitflags! {
/// The styling of a font.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct FontStyle: i32 {
const NORMAL = ttf::TTF_STYLE_NORMAL as i32;
const BOLD = ttf::TTF_STYLE_BOLD as i32;
Expand Down
17 changes: 17 additions & 0 deletions src/sdl2/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2204,6 +2204,23 @@ impl Window {
)
};
}

/// Returns whether the window has a surface.
#[doc(alias = "SDL_HasWindowSurface")]
pub fn has_surface(&self) -> bool {
unsafe { sys::SDL_HasWindowSurface(self.context.raw) == sys::SDL_bool::SDL_TRUE }
}

/// Destroys the window's surface.
#[doc(alias = "SDL_DestroyWindowSurface")]
pub fn destroy_surface(&mut self) -> Result<(), String> {
let result = unsafe { sys::SDL_DestroyWindowSurface(self.context.raw) };
if result < 0 {
Err(get_error())
} else {
Ok(())
}
}
}

#[derive(Copy, Clone)]
Expand Down
Loading