Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
Add way to hide cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
setzer22 committed Dec 11, 2023
1 parent 4b443f9 commit 61316d3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions comfy-core/src/global_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub struct GlobalState {
pub mouse_world: Vec2,

pub mouse_locked: bool,
pub cursor_hidden: bool,

pub egui_scale_factor: f32,

Expand Down
8 changes: 8 additions & 0 deletions comfy-core/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 8 additions & 0 deletions comfy/src/game_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 61316d3

Please sign in to comment.