Hide the cursor when focused

This commit is contained in:
Thinkofname 2016-03-21 18:59:15 +00:00
parent 7364dc41c3
commit 43c4c35d7a
3 changed files with 14 additions and 12 deletions

19
Cargo.lock generated
View File

@ -5,7 +5,7 @@ dependencies = [
"byteorder 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cgmath 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"flate2 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
"glutin 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"glutin 0.4.9 (git+https://github.com/Thinkofname/glutin?branch=hide-cursor-state-x11)",
"hyper 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
@ -85,13 +85,13 @@ dependencies = [
[[package]]
name = "cocoa"
version = "0.2.5"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"objc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"objc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -261,11 +261,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "glutin"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "git+https://github.com/Thinkofname/glutin?branch=hide-cursor-state-x11#267221af3e239c79a2617c46ba3f1259663c29f7"
dependencies = [
"android_glue 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"cgl 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"cocoa 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"cocoa 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"dwmapi-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -275,7 +275,7 @@ dependencies = [
"khronos_api 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"objc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"objc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"osmesa-sys 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"shared_library 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"shell32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -284,7 +284,7 @@ dependencies = [
"wayland-kbd 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"wayland-window 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"x11-dl 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"x11-dl 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -481,10 +481,9 @@ dependencies = [
[[package]]
name = "objc"
version = "0.1.8"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -813,7 +812,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "x11-dl"
version = "2.3.1"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"dylib 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -4,7 +4,7 @@ version = "0.0.1"
authors = [ "Thinkofdeath <thinkofdeath@spigotmc.org>" ]
[dependencies]
glutin = "0.4.9"
glutin = {git = "https://github.com/Thinkofname/glutin", branch = "hide-cursor-state-x11"}
byteorder = "0.5.0"
hyper = "0.8.0"
serde = "0.7.0"

View File

@ -244,6 +244,7 @@ fn handle_window_event(window: &glutin::Window,
game.mouse_pos = (x, y);
let (width, height) = window.get_inner_size_pixels().unwrap();
if game.focused {
window.set_cursor_state(glutin::CursorState::Hide).unwrap();
window.set_cursor_position((width/2) as i32, (height/2) as i32).unwrap();
let s = 2000.0 + 0.01;
let (rx, ry) = ((x-(width/2) as i32) as f64 / s, (y-(height/2) as i32) as f64 / s);
@ -265,6 +266,7 @@ fn handle_window_event(window: &glutin::Window,
if game.server.is_connected() && !game.focused {
game.focused = true;
window.set_cursor_state(glutin::CursorState::Hide).unwrap();
window.set_cursor_position((width/2) as i32, (height/2) as i32).unwrap();
return;
}
@ -272,7 +274,7 @@ fn handle_window_event(window: &glutin::Window,
ui_container.click_at(game, x as f64, y as f64, width as f64, height as f64);
}
}
Event::MouseWheel(delta) => {
Event::MouseWheel(delta, _) => {
let (x, y) = match delta {
glutin::MouseScrollDelta::LineDelta(x, y) => (x, y),
glutin::MouseScrollDelta::PixelDelta(x, y) => (x, y),
@ -282,6 +284,7 @@ fn handle_window_event(window: &glutin::Window,
}
Event::KeyboardInput(glutin::ElementState::Released, _, Some(VirtualKeyCode::Escape)) => {
if game.focused {
window.set_cursor_state(glutin::CursorState::Normal).unwrap();
game.focused = false;
}
}