From 61316d3c01b47864b018b9818bd67b6bece11204 Mon Sep 17 00:00:00 2001 From: setzer22 Date: Mon, 11 Dec 2023 19:48:03 +0100 Subject: [PATCH] Add way to hide cursor --- comfy-core/src/global_state.rs | 1 + comfy-core/src/input.rs | 8 ++++++++ comfy/src/game_loop.rs | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/comfy-core/src/global_state.rs b/comfy-core/src/global_state.rs index 849c1eb..796b7a3 100644 --- a/comfy-core/src/global_state.rs +++ b/comfy-core/src/global_state.rs @@ -103,6 +103,7 @@ pub struct GlobalState { pub mouse_world: Vec2, pub mouse_locked: bool, + pub cursor_hidden: bool, pub egui_scale_factor: f32, diff --git a/comfy-core/src/input.rs b/comfy-core/src/input.rs index 171b620..4062532 100644 --- a/comfy-core/src/input.rs +++ b/comfy-core/src/input.rs @@ -16,6 +16,14 @@ pub fn is_mouse_button_released(button: MouseButton) -> bool { GLOBAL_STATE.borrow().mouse_just_released.contains(&button) } +pub fn set_cursor_hidden(hidden: bool) { + GLOBAL_STATE.borrow_mut().cursor_hidden = hidden; +} + +pub fn set_mouse_locked(locked: bool) { + GLOBAL_STATE.borrow_mut().mouse_locked = locked; +} + pub fn is_key_pressed(keycode: KeyCode) -> bool { GLOBAL_STATE.borrow().just_pressed.contains(&keycode) } diff --git a/comfy/src/game_loop.rs b/comfy/src/game_loop.rs index 3890e73..e4b974e 100644 --- a/comfy/src/game_loop.rs +++ b/comfy/src/game_loop.rs @@ -172,8 +172,16 @@ pub async fn run_comfy_main_async( global_state.mouse_just_pressed.clear(); global_state.mouse_just_released.clear(); global_state.mouse_wheel = (0.0, 0.0); + + engine + .renderer + .as_ref() + .unwrap() + .window + .set_cursor_visible(!global_state.cursor_hidden); } + set_frame_time(frame_start.elapsed().as_secs_f32()); inc_frame_num();