Skip to content

Commit 1cb06b3

Browse files
Implement window grabbing features
1 parent a3639a1 commit 1cb06b3

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

src/sdl2/video.rs

+75
Original file line numberDiff line numberDiff line change
@@ -1688,11 +1688,86 @@ impl Window {
16881688
}
16891689
}
16901690

1691+
#[doc(alias = "SDL_SetWindowKeyboardGrab")]
1692+
pub fn set_keyboard_grab(&mut self, grabbed: bool) {
1693+
unsafe {
1694+
sys::SDL_SetWindowKeyboardGrab(
1695+
self.context.raw,
1696+
if grabbed {
1697+
sys::SDL_bool::SDL_TRUE
1698+
} else {
1699+
sys::SDL_bool::SDL_FALSE
1700+
},
1701+
)
1702+
}
1703+
}
1704+
1705+
#[doc(alias = "SDL_SetWindowMouseGrab")]
1706+
pub fn set_mouse_grab(&mut self, grabbed: bool) {
1707+
unsafe {
1708+
sys::SDL_SetWindowMouseGrab(
1709+
self.context.raw,
1710+
if grabbed {
1711+
sys::SDL_bool::SDL_TRUE
1712+
} else {
1713+
sys::SDL_bool::SDL_FALSE
1714+
},
1715+
)
1716+
}
1717+
}
1718+
16911719
#[doc(alias = "SDL_GetWindowGrab")]
16921720
pub fn grab(&self) -> bool {
16931721
unsafe { sys::SDL_GetWindowGrab(self.context.raw) == sys::SDL_bool::SDL_TRUE }
16941722
}
16951723

1724+
#[doc(alias = "SDL_GetWindowKeyboardGrab")]
1725+
pub fn keyboard_grab(&self) -> bool {
1726+
unsafe { sys::SDL_GetWindowKeyboardGrab(self.context.raw) == sys::SDL_bool::SDL_TRUE }
1727+
}
1728+
1729+
#[doc(alias = "SDL_GetWindowMouseGrab")]
1730+
pub fn mouse_grab(&self) -> bool {
1731+
unsafe { sys::SDL_GetWindowMouseGrab(self.context.raw) == sys::SDL_bool::SDL_TRUE }
1732+
}
1733+
1734+
#[doc(alias = "SDL_SetWindowMouseRect")]
1735+
pub fn set_mouse_rect<R>(&self, rect: R) -> Result<(), String>
1736+
where
1737+
R: Into<Option<Rect>>,
1738+
{
1739+
let rect = rect.into();
1740+
let rect_raw_ptr = match rect {
1741+
Some(ref rect) => rect.raw(),
1742+
None => ptr::null(),
1743+
};
1744+
1745+
unsafe {
1746+
if sys::SDL_SetWindowMouseRect(self.context.raw, rect_raw_ptr) == 0 {
1747+
Ok(())
1748+
} else {
1749+
Err(get_error())
1750+
}
1751+
}
1752+
}
1753+
1754+
#[doc(alias = "SDL_GetWindowMouseRect")]
1755+
pub fn mouse_rect(&self) -> Option<Rect> {
1756+
unsafe {
1757+
let raw_rect = sys::SDL_GetWindowMouseRect(self.context.raw);
1758+
if raw_rect.is_null() {
1759+
None
1760+
} else {
1761+
Some(Rect::new(
1762+
(*raw_rect).x,
1763+
(*raw_rect).y,
1764+
(*raw_rect).w as u32,
1765+
(*raw_rect).h as u32,
1766+
))
1767+
}
1768+
}
1769+
}
1770+
16961771
#[doc(alias = "SDL_SetWindowBrightness")]
16971772
pub fn set_brightness(&mut self, brightness: f64) -> Result<(), String> {
16981773
unsafe {

0 commit comments

Comments
 (0)