Merge pull request #1406 from Cobrand/master

Rollup of bindgen update to 2.26.0, event.is_touch(), FP render functions
This commit is contained in:
Cobrand
2024-06-13 16:37:18 +02:00
committed by GitHub
14 changed files with 5212 additions and 13177 deletions

View File

@@ -58,7 +58,7 @@ jobs:
build-linux:
name: build linux pkg-config
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v2
- name: Install dependencies

View File

@@ -31,9 +31,9 @@ optional = true
[dev-dependencies]
rand = "0.7"
wgpu = { version = "0.19", features = ["spirv"] }
wgpu = { version = "0.20", features = ["spirv"] }
pollster = "0.2.4"
env_logger = "0.9.0"
env_logger = "0.11.0"
[dependencies.raw-window-handle]
version = "0.6.0"

View File

@@ -30,7 +30,9 @@ fn main() -> Result<(), String> {
..Default::default()
});
let surface = unsafe {
match instance.create_surface_unsafe(wgpu::SurfaceTargetUnsafe::from_window(&window).unwrap()) {
match instance
.create_surface_unsafe(wgpu::SurfaceTargetUnsafe::from_window(&window).unwrap())
{
Ok(s) => s,
Err(e) => return Err(e.to_string()),
}

View File

@@ -20,7 +20,7 @@ path = "src/lib.rs"
libc = "^0.2"
[build-dependencies.bindgen]
version = "^0.53"
version = "^0.69"
optional = true
[build-dependencies.pkg-config]

View File

@@ -756,11 +756,11 @@ fn generate_bindings(target: &str, host: &str, headers_paths: &[String]) {
let bindings = bindings
.header("wrapper.h")
.blacklist_type("FP_NAN")
.blacklist_type("FP_INFINITE")
.blacklist_type("FP_ZERO")
.blacklist_type("FP_SUBNORMAL")
.blacklist_type("FP_NORMAL")
.blocklist_item("FP_NAN")
.blocklist_item("FP_INFINITE")
.blocklist_item("FP_ZERO")
.blocklist_item("FP_SUBNORMAL")
.blocklist_item("FP_NORMAL")
.derive_debug(false)
.generate()
.expect("Unable to generate bindings!");
@@ -774,16 +774,16 @@ fn generate_bindings(target: &str, host: &str, headers_paths: &[String]) {
if cfg!(feature = "image") {
let image_bindings = image_bindings
.header("wrapper_image.h")
.blacklist_type("FP_NAN")
.blacklist_type("FP_INFINITE")
.blacklist_type("FP_ZERO")
.blacklist_type("FP_SUBNORMAL")
.blacklist_type("FP_NORMAL")
.whitelist_type("IMG.*")
.whitelist_function("IMG.*")
.whitelist_var("IMG.*")
.blacklist_type("SDL_.*")
.blacklist_type("_IO.*|FILE")
.blocklist_item("FP_NAN")
.blocklist_item("FP_INFINITE")
.blocklist_item("FP_ZERO")
.blocklist_item("FP_SUBNORMAL")
.blocklist_item("FP_NORMAL")
.allowlist_type("IMG.*")
.allowlist_function("IMG.*")
.allowlist_var("IMG.*")
.blocklist_type("SDL_.*")
.blocklist_type("_IO.*|FILE")
.generate()
.expect("Unable to generate image_bindings!");
@@ -797,16 +797,16 @@ fn generate_bindings(target: &str, host: &str, headers_paths: &[String]) {
if cfg!(feature = "ttf") {
let ttf_bindings = ttf_bindings
.header("wrapper_ttf.h")
.blacklist_type("FP_NAN")
.blacklist_type("FP_INFINITE")
.blacklist_type("FP_ZERO")
.blacklist_type("FP_SUBNORMAL")
.blacklist_type("FP_NORMAL")
.whitelist_type("TTF.*")
.whitelist_function("TTF.*")
.whitelist_var("TTF.*")
.blacklist_type("SDL_.*")
.blacklist_type("_IO.*|FILE")
.blocklist_item("FP_NAN")
.blocklist_item("FP_INFINITE")
.blocklist_item("FP_ZERO")
.blocklist_item("FP_SUBNORMAL")
.blocklist_item("FP_NORMAL")
.allowlist_type("TTF.*")
.allowlist_function("TTF.*")
.allowlist_var("TTF.*")
.blocklist_type("SDL_.*")
.blocklist_type("_IO.*|FILE")
.generate()
.expect("Unable to generate ttf_bindings!");
@@ -820,19 +820,19 @@ fn generate_bindings(target: &str, host: &str, headers_paths: &[String]) {
if cfg!(feature = "mixer") {
let mixer_bindings = mixer_bindings
.header("wrapper_mixer.h")
.blacklist_type("FP_NAN")
.blacklist_type("FP_INFINITE")
.blacklist_type("FP_ZERO")
.blacklist_type("FP_SUBNORMAL")
.blacklist_type("FP_NORMAL")
.whitelist_type("MIX.*")
.whitelist_type("Mix.*")
.whitelist_type("MUS.*")
.whitelist_function("Mix.*")
.whitelist_var("MIX.*")
.whitelist_var("MUS.*")
.blacklist_type("SDL_.*")
.blacklist_type("_IO.*|FILE")
.blocklist_item("FP_NAN")
.blocklist_item("FP_INFINITE")
.blocklist_item("FP_ZERO")
.blocklist_item("FP_SUBNORMAL")
.blocklist_item("FP_NORMAL")
.allowlist_type("MIX.*")
.allowlist_type("Mix.*")
.allowlist_type("MUS.*")
.allowlist_function("Mix.*")
.allowlist_var("MIX.*")
.allowlist_var("MUS.*")
.blocklist_type("SDL_.*")
.blocklist_type("_IO.*|FILE")
.generate()
.expect("Unable to generate mixer_bindings!");
@@ -846,15 +846,15 @@ fn generate_bindings(target: &str, host: &str, headers_paths: &[String]) {
if cfg!(feature = "gfx") {
let gfx_framerate_bindings = gfx_framerate_bindings
.header("wrapper_gfx_framerate.h")
.blacklist_type("FP_NAN")
.blacklist_type("FP_INFINITE")
.blacklist_type("FP_ZERO")
.blacklist_type("FP_SUBNORMAL")
.blacklist_type("FP_NORMAL")
.whitelist_type("FPS.*")
.whitelist_function("SDL_.*rame.*")
.whitelist_var("FPS.*")
.blacklist_type("_IO.*|FILE")
.blocklist_item("FP_NAN")
.blocklist_item("FP_INFINITE")
.blocklist_item("FP_ZERO")
.blocklist_item("FP_SUBNORMAL")
.blocklist_item("FP_NORMAL")
.allowlist_type("FPS.*")
.allowlist_function("SDL_.*rame.*")
.allowlist_var("FPS.*")
.blocklist_type("_IO.*|FILE")
.generate()
.expect("Unable to generate gfx_framerate_bindings!");
@@ -866,31 +866,31 @@ fn generate_bindings(target: &str, host: &str, headers_paths: &[String]) {
let gfx_primitives_bindings = gfx_primitives_bindings
.header("wrapper_gfx_primitives.h")
.blacklist_type("FP_NAN")
.blacklist_type("FP_INFINITE")
.blacklist_type("FP_ZERO")
.blacklist_type("FP_SUBNORMAL")
.blacklist_type("FP_NORMAL")
.blacklist_type("SDL_.*")
.whitelist_function("pixel.*")
.whitelist_function("rectangle.*")
.whitelist_function("rounded.*")
.whitelist_function("box.*")
.whitelist_function(".*line(Color|RGBA).*")
.whitelist_function("thick.*")
.whitelist_function(".*circle.*")
.whitelist_function("arc.*")
.whitelist_function("filled.*")
.whitelist_function(".*ellipse.*")
.whitelist_function("pie.*")
.whitelist_function(".*trigon.*")
.whitelist_function(".*polygon.*")
.whitelist_function("textured.*")
.whitelist_function("bezier.*")
.whitelist_function("character.*")
.whitelist_function("string.*")
.whitelist_function("gfx.*")
.blacklist_type("_IO.*|FILE")
.blocklist_item("FP_NAN")
.blocklist_item("FP_INFINITE")
.blocklist_item("FP_ZERO")
.blocklist_item("FP_SUBNORMAL")
.blocklist_item("FP_NORMAL")
.blocklist_type("SDL_.*")
.allowlist_function("pixel.*")
.allowlist_function("rectangle.*")
.allowlist_function("rounded.*")
.allowlist_function("box.*")
.allowlist_function(".*line(Color|RGBA).*")
.allowlist_function("thick.*")
.allowlist_function(".*circle.*")
.allowlist_function("arc.*")
.allowlist_function("filled.*")
.allowlist_function(".*ellipse.*")
.allowlist_function("pie.*")
.allowlist_function(".*trigon.*")
.allowlist_function(".*polygon.*")
.allowlist_function("textured.*")
.allowlist_function("bezier.*")
.allowlist_function("character.*")
.allowlist_function("string.*")
.allowlist_function("gfx.*")
.blocklist_type("_IO.*|FILE")
.generate()
.expect("Unable to generate gfx_primitives_bindings!");
@@ -902,13 +902,13 @@ fn generate_bindings(target: &str, host: &str, headers_paths: &[String]) {
let gfx_imagefilter_bindings = gfx_imagefilter_bindings
.header("wrapper_gfx_imagefilter.h")
.whitelist_function("SDL_image.*")
.blacklist_type("FP_NAN")
.blacklist_type("FP_INFINITE")
.blacklist_type("FP_ZERO")
.blacklist_type("FP_SUBNORMAL")
.blacklist_type("FP_NORMAL")
.blacklist_type("_IO.*|FILE")
.allowlist_function("SDL_image.*")
.blocklist_item("FP_NAN")
.blocklist_item("FP_INFINITE")
.blocklist_item("FP_ZERO")
.blocklist_item("FP_SUBNORMAL")
.blocklist_item("FP_NORMAL")
.blocklist_type("_IO.*|FILE")
.generate()
.expect("Unable to generate gfx_imagefilter_bindings!");
@@ -920,17 +920,17 @@ fn generate_bindings(target: &str, host: &str, headers_paths: &[String]) {
let gfx_rotozoom_bindings = gfx_rotozoom_bindings
.header("wrapper_gfx_rotozoom.h")
.blacklist_type("SDL_.*")
.whitelist_function("rotozoom.*")
.whitelist_function("zoom.*")
.whitelist_function("shrink.*")
.whitelist_function("rotate.*")
.blacklist_type("FP_NAN")
.blacklist_type("FP_INFINITE")
.blacklist_type("FP_ZERO")
.blacklist_type("FP_SUBNORMAL")
.blacklist_type("FP_NORMAL")
.blacklist_type("_IO.*|FILE")
.blocklist_type("SDL_.*")
.allowlist_function("rotozoom.*")
.allowlist_function("zoom.*")
.allowlist_function("shrink.*")
.allowlist_function("rotate.*")
.blocklist_item("FP_NAN")
.blocklist_item("FP_INFINITE")
.blocklist_item("FP_ZERO")
.blocklist_item("FP_SUBNORMAL")
.blocklist_item("FP_NORMAL")
.blocklist_type("_IO.*|FILE")
.generate()
.expect("Unable to generate gfx_rotozoom_bindings!");

File diff suppressed because one or more lines are too long

View File

@@ -669,11 +669,19 @@ pub enum Event {
timestamp: u32,
window_id: u32,
which: u32,
/// How much did we scroll in X, with integer precision
x: i32,
/// How much did we scroll in Y, with integer precision
y: i32,
direction: MouseWheelDirection,
/// How much did we scroll in X, with floating precision (added in 2.0.18)
precise_x: f32,
/// How much did we scroll in Y, with floating precision (added in 2.0.18)
precise_y: f32,
/// The X position of the mouse from the window's origin
mouse_x: i32,
/// The X position of the mouse from the window's origin
mouse_y: i32,
},
JoyAxisMotion {
@@ -1205,6 +1213,8 @@ impl Event {
direction,
precise_x,
precise_y,
mouse_x,
mouse_y,
} => {
let event = sys::SDL_MouseWheelEvent {
type_: SDL_EventType::SDL_MOUSEWHEEL as u32,
@@ -1216,6 +1226,8 @@ impl Event {
direction: direction.to_ll(),
preciseX: precise_x,
preciseY: precise_y,
mouseX: mouse_x,
mouseY: mouse_y,
};
unsafe {
ptr::copy(&event, ret.as_mut_ptr() as *mut sys::SDL_MouseWheelEvent, 1);
@@ -1680,6 +1692,8 @@ impl Event {
direction: mouse::MouseWheelDirection::from_ll(event.direction),
precise_x: event.preciseX,
precise_y: event.preciseY,
mouse_x: event.mouseX,
mouse_y: event.mouseY,
}
}
@@ -2356,6 +2370,8 @@ impl Event {
/// precise_y: 0.0,
/// x: 0,
/// y: 0,
/// mouse_x: 0,
/// mouse_y: 0,
/// direction: MouseWheelDirection::Normal,
/// };
/// assert!(ev.is_mouse());
@@ -2375,6 +2391,34 @@ impl Event {
}
}
/// Returns `true` if this mouse event is coming from touch.
///
/// If used on any other kind of event, non-mouse related, this returns `false`.
pub fn is_touch(&self) -> bool {
// FIXME: Use a constant from sdl2-sys when bindgen will be fixed (see https://github.com/Rust-SDL2/rust-sdl2/issues/1265)
const SDL_TOUCH_MOUSEID: u32 = 0xFFFFFFFF;
match self {
Self::MouseMotion {
which: SDL_TOUCH_MOUSEID,
..
}
| Self::MouseButtonDown {
which: SDL_TOUCH_MOUSEID,
..
}
| Self::MouseButtonUp {
which: SDL_TOUCH_MOUSEID,
..
}
| Self::MouseWheel {
which: SDL_TOUCH_MOUSEID,
..
} => true,
_ => false,
}
}
/// Returns `true` if this is a controller event.
///
/// # Example
@@ -2925,6 +2969,8 @@ mod test {
direction: MouseWheelDirection::Flipped,
precise_x: 1.6,
precise_y: 2.7,
mouse_x: 0,
mouse_y: 5,
};
let e2 = Event::from_ll(e.clone().to_ll().unwrap());
assert_eq!(e, e2);

View File

@@ -118,7 +118,7 @@ impl PowerLevel {
SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_MEDIUM => PowerLevel::Medium,
SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_FULL => PowerLevel::Full,
SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_WIRED => PowerLevel::Wired,
_ => panic!("Unexpected power level: {:?}", raw),
_ => panic!("Unexpected power level: {}", raw as i32),
}
}

View File

@@ -1,8 +1,8 @@
extern crate raw_window_handle;
use self::raw_window_handle::{
RawDisplayHandle, RawWindowHandle,
HasWindowHandle, HasDisplayHandle, DisplayHandle, WindowHandle, HandleError
DisplayHandle, HandleError, HasDisplayHandle, HasWindowHandle, RawDisplayHandle,
RawWindowHandle, WindowHandle,
};
use crate::{sys::SDL_Window, video::Window};
@@ -16,7 +16,7 @@ impl HasWindowHandle for Window {
use self::raw_window_handle::WebWindowHandle;
let handle = WebWindowHandle::new(1);
let handle = RawWindowHandle::Web(handle);
let handle = unsafe{WindowHandle::borrow_raw(handle)};
let handle = unsafe { WindowHandle::borrow_raw(handle) };
return Ok(handle);
}
@@ -50,7 +50,7 @@ impl HasWindowHandle for Window {
handle.hinstance = hinstance;
let handle = RawWindowHandle::Win32(handle);
let handle = unsafe {WindowHandle::borrow_raw(handle)};
let handle = unsafe { WindowHandle::borrow_raw(handle) };
Ok(handle)
}
#[cfg(target_os = "windows")]
@@ -67,7 +67,7 @@ impl HasWindowHandle for Window {
};
let handle = WinRtWindowHandle::new(core_window);
let handle = RawWindowHandle::WinRt(handle);
let handle = unsafe {WindowHandle::borrow_raw(handle)};
let handle = unsafe { WindowHandle::borrow_raw(handle) };
Ok(handle)
}
@@ -81,21 +81,18 @@ impl HasWindowHandle for Window {
SDL_SYSWM_WAYLAND => {
use self::raw_window_handle::WaylandWindowHandle;
let surf = unsafe {wm_info.info.wl}.surface as *mut libc::c_void;
let surf = unsafe { wm_info.info.wl }.surface as *mut libc::c_void;
let surf = core::ptr::NonNull::<libc::c_void>::new(surf);
match surf {
Some(surf) => {
let handle = WaylandWindowHandle::new(surf);
let handle = RawWindowHandle::Wayland(handle);
let handle = unsafe {WindowHandle::borrow_raw(handle)};
let handle = unsafe { WindowHandle::borrow_raw(handle) };
Ok(handle)
}
None => {
Err(HandleError::Unavailable)
}
None => Err(HandleError::Unavailable),
}
}
#[cfg(any(
target_os = "linux",
@@ -110,7 +107,7 @@ impl HasWindowHandle for Window {
let window = unsafe { wm_info.info.x11 }.window;
let xlib_handle = XlibWindowHandle::new(window);
let raw_handle = RawWindowHandle::Xlib(xlib_handle);
let handle = unsafe{WindowHandle::borrow_raw(raw_handle)};
let handle = unsafe { WindowHandle::borrow_raw(raw_handle) };
Ok(handle)
}
@@ -125,10 +122,10 @@ impl HasWindowHandle for Window {
panic!("metal_view not initialized, please call WindowBuilder::metal_view() when building the window");
}
};
let handle = AppKitWindowHandle::new(ns_view);
let handle = RawWindowHandle::AppKit(handle);
let handle = unsafe {WindowHandle::borrow_raw(handle)};
let handle = unsafe { WindowHandle::borrow_raw(handle) };
Ok(handle)
}
@@ -150,15 +147,14 @@ impl HasWindowHandle for Window {
// Someone with an IOS device please test
let handle = UiKitWindowHandle::new(ui_window);
let handle = RawWindowHandle::UiKit(handle);
let handle = unsafe {WindowHandle::borrow_raw(handle)};
let handle = unsafe { WindowHandle::borrow_raw(handle) };
Ok(handle)
}
#[cfg(any(target_os = "android"))]
SDL_SYSWM_ANDROID => {
use self::raw_window_handle::AndroidNdkWindowHandle;
let a_native_window =
unsafe { wm_info.info.android }.window as *mut libc::c_void;
let a_native_window = unsafe { wm_info.info.android }.window as *mut libc::c_void;
let a_native_window = core::ptr::NonNull::<libc::c_void>::new(a_native_window);
let a_native_window = match a_native_window {
Some(anw) => anw,
@@ -168,7 +164,7 @@ impl HasWindowHandle for Window {
};
let handle = AndroidNdkWindowHandle::new(a_native_window);
let handle = RawWindowHandle::AndroidNdk(handle);
let handle = unsafe{WindowHandle::borrow_raw(handle)};
let handle = unsafe { WindowHandle::borrow_raw(handle) };
Ok(handle)
}
x => {
@@ -195,7 +191,7 @@ impl HasDisplayHandle for Window {
use self::raw_window_handle::WebDisplayHandle;
let handle = WebDisplayHandle::new();
let handle = RawDisplayHandle::Web(handle);
let handle = unsafe{DisplayHandle::borrow_raw(handle)};
let handle = unsafe { DisplayHandle::borrow_raw(handle) };
return Ok(handle);
}
@@ -217,7 +213,7 @@ impl HasDisplayHandle for Window {
let handle = WindowsDisplayHandle::new();
let handle = RawDisplayHandle::Windows(handle);
let handle = unsafe {DisplayHandle::borrow_raw(handle)};
let handle = unsafe { DisplayHandle::borrow_raw(handle) };
Ok(handle)
}
@@ -237,12 +233,10 @@ impl HasDisplayHandle for Window {
Some(display) => {
let mut handle = WaylandDisplayHandle::new(display);
let handle = RawDisplayHandle::Wayland(handle);
let handle = unsafe{DisplayHandle::borrow_raw(handle)};
let handle = unsafe { DisplayHandle::borrow_raw(handle) };
Ok(handle)
}
None => {
Err(HandleError::Unavailable)
}
None => Err(HandleError::Unavailable),
}
}
#[cfg(any(
@@ -260,7 +254,7 @@ impl HasDisplayHandle for Window {
let window = unsafe { wm_info.info.x11 }.window as i32;
let handle = XlibDisplayHandle::new(display, window);
let handle = RawDisplayHandle::Xlib(handle);
let handle = unsafe {DisplayHandle::borrow_raw(handle)};
let handle = unsafe { DisplayHandle::borrow_raw(handle) };
Ok(handle)
}
@@ -269,7 +263,7 @@ impl HasDisplayHandle for Window {
use self::raw_window_handle::AppKitDisplayHandle;
let handle = AppKitDisplayHandle::new();
let handle = RawDisplayHandle::AppKit(handle);
let handle = unsafe {DisplayHandle::borrow_raw(handle)};
let handle = unsafe { DisplayHandle::borrow_raw(handle) };
Ok(handle)
}
#[cfg(any(target_os = "ios"))]
@@ -278,7 +272,7 @@ impl HasDisplayHandle for Window {
let handle = UiKitDisplayHandle::new();
let handle = RawDisplayHandle::UiKit(handle);
let handle = unsafe {DisplayHandle::borrow_raw(handle)};
let handle = unsafe { DisplayHandle::borrow_raw(handle) };
Ok(handle)
}
@@ -288,7 +282,7 @@ impl HasDisplayHandle for Window {
let handle = AndroidDisplayHandle::new();
let handle = RawDisplayHandle::Android(handle);
let handle = unsafe {DisplayHandle::borrow_raw(handle)};
let handle = unsafe { DisplayHandle::borrow_raw(handle) };
Ok(handle)
}

File diff suppressed because it is too large Load Diff

View File

@@ -32,6 +32,8 @@ use crate::common::{validate_int, IntegerOrSdlError};
use crate::get_error;
use crate::pixels;
use crate::pixels::PixelFormatEnum;
use crate::rect::FPoint;
use crate::rect::FRect;
use crate::rect::Point;
use crate::rect::Rect;
use crate::surface;
@@ -1331,6 +1333,251 @@ impl<T: RenderTarget> Canvas<T> {
}
}
/// Draws a point on the current rendering target.
/// Errors if drawing fails for any reason (e.g. driver failure)
#[doc(alias = "SDL_RenderDrawPointF")]
pub fn draw_fpoint<P: Into<FPoint>>(&mut self, point: P) -> Result<(), String> {
let point = point.into();
let result = unsafe { sys::SDL_RenderDrawPointF(self.context.raw, point.x(), point.y()) };
if result != 0 {
Err(get_error())
} else {
Ok(())
}
}
/// Draws multiple points on the current rendering target.
/// Errors if drawing fails for any reason (e.g. driver failure)
#[doc(alias = "SDL_RenderDrawPointsF")]
pub fn draw_fpoints<'a, P: Into<&'a [FPoint]>>(&mut self, points: P) -> Result<(), String> {
let points = points.into();
let result = unsafe {
sys::SDL_RenderDrawPointsF(
self.context.raw,
FPoint::raw_slice(points),
points.len() as c_int,
)
};
if result != 0 {
Err(get_error())
} else {
Ok(())
}
}
/// Draws a line on the current rendering target.
/// Errors if drawing fails for any reason (e.g. driver failure)
#[doc(alias = "SDL_RenderDrawLineF")]
pub fn draw_fline<P1: Into<FPoint>, P2: Into<FPoint>>(
&mut self,
start: P1,
end: P2,
) -> Result<(), String> {
let start = start.into();
let end = end.into();
let result = unsafe {
sys::SDL_RenderDrawLineF(self.context.raw, start.x(), start.y(), end.x(), end.y())
};
if result != 0 {
Err(get_error())
} else {
Ok(())
}
}
/// Draws a series of connected lines on the current rendering target.
/// Errors if drawing fails for any reason (e.g. driver failure)
#[doc(alias = "SDL_RenderDrawLinesF")]
pub fn draw_flines<'a, P: Into<&'a [FPoint]>>(&mut self, points: P) -> Result<(), String> {
let points = points.into();
let result = unsafe {
sys::SDL_RenderDrawLinesF(
self.context.raw,
FPoint::raw_slice(points),
points.len() as c_int,
)
};
if result != 0 {
Err(get_error())
} else {
Ok(())
}
}
/// Draws a rectangle on the current rendering target.
/// Errors if drawing fails for any reason (e.g. driver failure)
#[doc(alias = "SDL_RenderDrawRectF")]
pub fn draw_frect(&mut self, rect: FRect) -> Result<(), String> {
let result = unsafe { sys::SDL_RenderDrawRectF(self.context.raw, rect.raw()) };
if result != 0 {
Err(get_error())
} else {
Ok(())
}
}
/// Draws some number of rectangles on the current rendering target.
/// Errors if drawing fails for any reason (e.g. driver failure)
#[doc(alias = "SDL_RenderDrawRectsF")]
pub fn draw_frects(&mut self, rects: &[FRect]) -> Result<(), String> {
let result = unsafe {
sys::SDL_RenderDrawRectsF(
self.context.raw,
FRect::raw_slice(rects),
rects.len() as c_int,
)
};
if result != 0 {
Err(get_error())
} else {
Ok(())
}
}
/// Fills a rectangle on the current rendering target with the drawing
/// color.
/// Passing None will fill the entire rendering target.
/// Errors if drawing fails for any reason (e.g. driver failure)
#[doc(alias = "SDL_RenderFillRectF")]
pub fn fill_frect<R: Into<Option<FRect>>>(&mut self, rect: R) -> Result<(), String> {
let result = unsafe {
sys::SDL_RenderFillRectF(
self.context.raw,
rect.into().as_ref().map(|r| r.raw()).unwrap_or(ptr::null()),
)
};
if result != 0 {
Err(get_error())
} else {
Ok(())
}
}
/// Fills some number of rectangles on the current rendering target with
/// the drawing color.
/// Errors if drawing fails for any reason (e.g. driver failure)
#[doc(alias = "SDL_RenderFillRectsF")]
pub fn fill_frects(&mut self, rects: &[FRect]) -> Result<(), String> {
let result = unsafe {
sys::SDL_RenderFillRectsF(
self.context.raw,
FRect::raw_slice(rects),
rects.len() as c_int,
)
};
if result != 0 {
Err(get_error())
} else {
Ok(())
}
}
/// Copies a portion of the texture to the current rendering target.
///
/// * If `src` is `None`, the entire texture is copied.
/// * If `dst` is `None`, the texture will be stretched to fill the given
/// rectangle.
///
/// Errors if drawing fails for any reason (e.g. driver failure),
/// or if the provided texture does not belong to the renderer.
#[doc(alias = "SDL_RenderCopyF")]
pub fn copy_f<R1, R2>(&mut self, texture: &Texture, src: R1, dst: R2) -> Result<(), String>
where
R1: Into<Option<Rect>>,
R2: Into<Option<FRect>>,
{
let ret = unsafe {
sys::SDL_RenderCopyF(
self.context.raw,
texture.raw,
match src.into() {
Some(ref rect) => rect.raw(),
None => ptr::null(),
},
match dst.into() {
Some(ref rect) => rect.raw(),
None => ptr::null(),
},
)
};
if ret != 0 {
Err(get_error())
} else {
Ok(())
}
}
/// Copies a portion of the texture to the current rendering target,
/// optionally rotating it by angle around the given center and also
/// flipping it top-bottom and/or left-right.
///
/// * If `src` is `None`, the entire texture is copied.
/// * If `dst` is `None`, the texture will be stretched to fill the given
/// rectangle.
/// * If `center` is `None`, rotation will be done around the center point
/// of `dst`, or `src` if `dst` is None.
///
/// Errors if drawing fails for any reason (e.g. driver failure),
/// if the provided texture does not belong to the renderer,
/// or if the driver does not support RenderCopyEx.
#[doc(alias = "SDL_RenderCopyExF")]
pub fn copy_ex_f<R1, R2, P>(
&mut self,
texture: &Texture,
src: R1,
dst: R2,
angle: f64,
center: P,
flip_horizontal: bool,
flip_vertical: bool,
) -> Result<(), String>
where
R1: Into<Option<Rect>>,
R2: Into<Option<FRect>>,
P: Into<Option<FPoint>>,
{
use crate::sys::SDL_RendererFlip::*;
let flip = unsafe {
match (flip_horizontal, flip_vertical) {
(false, false) => SDL_FLIP_NONE,
(true, false) => SDL_FLIP_HORIZONTAL,
(false, true) => SDL_FLIP_VERTICAL,
(true, true) => transmute::<u32, sys::SDL_RendererFlip>(
transmute::<sys::SDL_RendererFlip, u32>(SDL_FLIP_HORIZONTAL)
| transmute::<sys::SDL_RendererFlip, u32>(SDL_FLIP_VERTICAL),
),
}
};
let ret = unsafe {
sys::SDL_RenderCopyExF(
self.context.raw,
texture.raw,
match src.into() {
Some(ref rect) => rect.raw(),
None => ptr::null(),
},
match dst.into() {
Some(ref rect) => rect.raw(),
None => ptr::null(),
},
angle as c_double,
match center.into() {
Some(ref point) => point.raw(),
None => ptr::null(),
},
flip,
)
};
if ret != 0 {
Err(get_error())
} else {
Ok(())
}
}
/// Copies a portion of the texture to the current rendering target.
///
/// * If `src` is `None`, the entire texture is copied.

View File

@@ -145,7 +145,7 @@ impl<'a> io::Read for RWops<'a> {
self.raw,
buf.as_ptr() as *mut c_void,
1,
out_len as sys::size_t,
out_len as libc::size_t,
)
};
Ok(ret as usize)
@@ -160,7 +160,7 @@ impl<'a> io::Write for RWops<'a> {
self.raw,
buf.as_ptr() as *const c_void,
1,
in_len as sys::size_t,
in_len as libc::size_t,
)
};
Ok(ret as usize)

View File

@@ -1489,7 +1489,7 @@ impl Window {
#[doc(alias = "SDL_GetWindowICCProfile")]
pub fn icc_profile(&self) -> Result<Vec<u8>, String> {
unsafe {
let mut size: sys::size_t = 0;
let mut size: libc::size_t = 0;
let data = sys::SDL_GetWindowICCProfile(self.context.raw, &mut size as *mut _);
if data.is_null() {
return Err(get_error());
@@ -1556,9 +1556,9 @@ impl Window {
#[doc(alias = "SDL_SetWindowResizable")]
pub fn set_resizable(&mut self, resizable: bool) {
let resizable = if resizable {
SDL_bool::SDL_TRUE
sys::SDL_bool::SDL_TRUE
} else {
SDL_bool::SDL_FALSE
sys::SDL_bool::SDL_FALSE
};
unsafe {
sys::SDL_SetWindowResizable(self.context.raw, resizable);

View File

@@ -13,17 +13,19 @@ mod raw_window_handle_test {
fn get_windows_handle() {
let window = new_hidden_window();
match window.window_handle() {
Ok(window_handle) => {
match window_handle.as_raw() {
RawWindowHandle::Win32(_) => {
println!("Successfully received Win32 window handle")
},
RawWindowHandle::WinRt(_) => {
println!("Successfully received WinRt window handle")
}
raw_handle => {
assert!(false, "Wrong window handle type for Windows: {:?}", raw_handle)
}
Ok(window_handle) => match window_handle.as_raw() {
RawWindowHandle::Win32(_) => {
println!("Successfully received Win32 window handle")
}
RawWindowHandle::WinRt(_) => {
println!("Successfully received WinRt window handle")
}
raw_handle => {
assert!(
false,
"Wrong window handle type for Windows: {:?}",
raw_handle
)
}
},
Err(e) => {
@@ -31,18 +33,24 @@ mod raw_window_handle_test {
}
}
match window.display_handle() {
Ok(display_handle) => {
match display_handle.as_raw() {
RawDisplayHandle::Windows(_) => {
println!("Successfully received Windows display handle")
},
raw_handle => {
assert!(false, "Wrong display handle type for Windows: {:?}", raw_handle)
}
Ok(display_handle) => match display_handle.as_raw() {
RawDisplayHandle::Windows(_) => {
println!("Successfully received Windows display handle")
}
raw_handle => {
assert!(
false,
"Wrong display handle type for Windows: {:?}",
raw_handle
)
}
},
Err(e) => {
assert!(false, "Failed to recieve display handle on Windows: {:?}", e)
assert!(
false,
"Failed to recieve display handle on Windows: {:?}",
e
)
}
}
}
@@ -58,17 +66,19 @@ mod raw_window_handle_test {
fn get_linux_handle() {
let window = new_hidden_window();
match window.window_handle() {
Ok(handle) => {
match handle.as_raw() {
RawWindowHandle::Xlib(_) => {
println!("Successfully received X11 window handle")
}
RawWindowHandle::Wayland(_) => {
println!("Successfully received Wayland window handle")
}
raw_handle => {
assert!(false, "Wrong window handle type for Linux: {:?}", raw_handle)
}
Ok(handle) => match handle.as_raw() {
RawWindowHandle::Xlib(_) => {
println!("Successfully received X11 window handle")
}
RawWindowHandle::Wayland(_) => {
println!("Successfully received Wayland window handle")
}
raw_handle => {
assert!(
false,
"Wrong window handle type for Linux: {:?}",
raw_handle
)
}
},
Err(e) => {
@@ -76,22 +86,24 @@ mod raw_window_handle_test {
}
}
match window.display_handle() {
Ok(handle) => {
match handle.as_raw() {
RawDisplayHandle::Xlib(_) => {
println!("Successfully recieved X11 display handle")
}
RawDisplayHandle::Wayland(_) => {
println!("Successfully recieved Wayland display handle")
}
raw_handle => {
assert!(false, "Wrong display handle type for Linux: {:?}", raw_handle)
}
Ok(handle) => match handle.as_raw() {
RawDisplayHandle::Xlib(_) => {
println!("Successfully recieved X11 display handle")
}
}
RawDisplayHandle::Wayland(_) => {
println!("Successfully recieved Wayland display handle")
}
raw_handle => {
assert!(
false,
"Wrong display handle type for Linux: {:?}",
raw_handle
)
}
},
Err(e) => {
assert!(false, "Failed to recieve display handle on Linux: {:?}", e)
},
}
}
}
@@ -100,29 +112,33 @@ mod raw_window_handle_test {
fn get_macos_handle() {
let window = new_hidden_window();
match window.window_handle() {
Ok(handle) => {
match handle.as_raw() {
RawWindowHandle::AppKit(_) => {
println!("Successfully recieved AppKit window handle")
}
raw_handle => {
assert!(false, "Wrong window handle type for macOS: {:?}", raw_handle)
}
Ok(handle) => match handle.as_raw() {
RawWindowHandle::AppKit(_) => {
println!("Successfully recieved AppKit window handle")
}
}
raw_handle => {
assert!(
false,
"Wrong window handle type for macOS: {:?}",
raw_handle
)
}
},
Err(e) => {
assert!(false, "Failed to recieve window handle on macOS: {:?}", e)
}
};
match window.display_handle() {
Ok(handle) => {
match handle.as_raw(){
RawDisplayHandle::AppKit(_) => {
println!("Successfully recieved AppKit display handle")
}
raw_handle => {
assert!(false, "Wrong display handle type for macOS: {:?}", raw_handle)
}
Ok(handle) => match handle.as_raw() {
RawDisplayHandle::AppKit(_) => {
println!("Successfully recieved AppKit display handle")
}
raw_handle => {
assert!(
false,
"Wrong display handle type for macOS: {:?}",
raw_handle
)
}
},
Err(e) => {