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

Add way to hide cursor (& fix missing wgsl string) #77

Merged
merged 5 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions comfy-core/src/shaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ pub enum UniformDef {
}

impl UniformDef {
pub fn to_wgsl(&self) -> &'static str {
pub fn to_wgsl(&self) -> &str {
match self {
UniformDef::F32(_) => "f32",
UniformDef::Custom { .. } => "X",
UniformDef::Custom { wgsl_decl, .. } => &wgsl_decl,
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion comfy-core/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ pub fn gen_font_handle() -> FontHandle {
)
}

/// Opaque handle to a font. The ID is exposed for debugging purposes.
/// If you set it manually, you're on your own!
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct FontHandle(u64);
pub struct FontHandle(pub u64);

fn draw_text_internal(
text: TextData,
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