Verified Commit 70415b0a authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Add mouse functions - cursor, grab, and relative mode

parent ed7204c4
[package]
name = "orbclient"
version = "0.3.24"
version = "0.3.25"
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
description = "The Orbital Client Library"
documentation = "https://docs.rs/orbclient"
......
......@@ -221,13 +221,28 @@ impl Window {
self.t.clone()
}
// Set position
/// Set cursor visibility
pub fn set_mouse_cursor(&mut self, visible: bool) {
let _ = self.file.write(if visible { b"M,C,1" } else { b"M,C,0" });
}
/// Set mouse grabbing
pub fn set_mouse_grab(&mut self, grab: bool) {
let _ = self.file.write(if grab { b"M,G,1" } else { b"M,G,0" });
}
/// Set mouse relative mode
pub fn set_mouse_relative(&mut self, relative: bool) {
let _ = self.file.write(if relative { b"M,R,1" } else { b"M,R,0" });
}
/// Set position
pub fn set_pos(&mut self, x: i32, y: i32) {
let _ = self.file.write(&format!("P,{},{}", x, y).as_bytes());
self.sync_path();
}
// Set size
/// Set size
pub fn set_size(&mut self, width: u32, height: u32) {
//TODO: Improve safety and reliability
unsafe {
......
......@@ -212,7 +212,22 @@ impl Window {
self.t.clone()
}
// Set position
/// Set cursor visibility
pub fn set_mouse_cursor(&mut self, visible: bool) {
unsafe { &mut *SDL_CTX }.mouse().show_cursor(visible);
}
/// Set mouse grabbing
pub fn set_mouse_grab(&mut self, grab: bool) {
unsafe { &mut *SDL_CTX }.mouse().capture(grab);
}
/// Set mouse relative mode
pub fn set_mouse_relative(&mut self, relative: bool) {
unsafe { &mut *SDL_CTX }.mouse().set_relative_mouse_mode(relative);
}
/// Set position
pub fn set_pos(&mut self, x: i32, y: i32) {
self.inner.window_mut().set_position(
sdl2::video::WindowPos::Positioned(x),
......@@ -221,7 +236,7 @@ impl Window {
self.sync_path();
}
// Set size
/// Set size
pub fn set_size(&mut self, width: u32, height: u32) {
let _ = self.inner.window_mut().set_size(width, height);
self.sync_path();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment