initial commit

This commit is contained in:
lisk77 2024-10-26 02:15:26 +02:00
commit 6154c72b0e
55 changed files with 9481 additions and 0 deletions

View file

@ -0,0 +1,7 @@
[package]
name = "comet_input"
version = "0.1.0"
edition = "2021"
[dependencies]
winit = { version = "0.29", features = ["rwh_05"] }

View file

@ -0,0 +1,32 @@
use winit::event::{ElementState, KeyEvent, WindowEvent};
use winit::keyboard::{ KeyCode, PhysicalKey};
pub type Key = KeyCode;
pub fn key_pressed(event: &WindowEvent, key_code: Key) -> bool {
match event {
WindowEvent::KeyboardInput {
event: KeyEvent {
state: ElementState::Pressed,
physical_key: PhysicalKey::Code(code),
..
},
..
} => *code == key_code,
_ => false,
}
}
pub fn key_released(event: &WindowEvent, key_code: Key) -> bool {
match event {
WindowEvent::KeyboardInput {
event: KeyEvent {
state: ElementState::Released,
physical_key: PhysicalKey::Code(code),
..
},
..
} => *code == key_code,
_ => false,
}
}

View file

@ -0,0 +1,2 @@
pub mod keyboard;
pub mod mouse;

View file

@ -0,0 +1,89 @@
use winit::event::{
ElementState,
WindowEvent,
MouseButton,
MouseScrollDelta
};
pub type Button = MouseButton;
pub fn mouse_pressed(event: &WindowEvent, button: Button) -> bool {
match event {
WindowEvent::MouseInput {
button: button_pressed,
state: ElementState::Pressed,
..
} => *button_pressed == button,
_ => false,
}
}
pub fn mouse_released(event: &WindowEvent, button: Button) -> bool {
match event {
WindowEvent::MouseInput {
button: button_released,
state: ElementState::Released,
..
} => *button_released == button,
_ => false,
}
}
pub fn mouse_wheel_vertical(event: &WindowEvent) -> f32 {
match event {
WindowEvent::MouseWheel {
delta: MouseScrollDelta::LineDelta(_, y),
..
} => *y,
WindowEvent::MouseWheel {
delta: MouseScrollDelta::PixelDelta(p),
..
} => p.y as f32,
_ => 0.0,
}
}
pub fn mouse_wheel_horizontal(event: &WindowEvent) -> f32 {
match event {
WindowEvent::MouseWheel {
delta: MouseScrollDelta::LineDelta(x, _),
..
} => *x,
WindowEvent::MouseWheel {
delta: MouseScrollDelta::PixelDelta(p),
..
} => p.x as f32,
_ => 0.0,
}
}
pub fn mouse_moved(event: &WindowEvent) -> (f64, f64) {
match event {
WindowEvent::CursorMoved {
position,
..
} => (position.x, position.y),
_ => (0.0, 0.0),
}
}
pub fn mouse_entered(event: &WindowEvent) -> bool {
match event {
WindowEvent::CursorEntered { .. } => true,
_ => false,
}
}
pub fn mouse_exited(event: &WindowEvent) -> bool {
match event {
WindowEvent::CursorLeft { .. } => true,
_ => false,
}
}
pub fn mouse_dragged(event: &WindowEvent) -> bool {
match event {
WindowEvent::CursorMoved { .. } => true,
_ => false,
}
}