mirror of
https://github.com/lisk77/comet.git
synced 2025-10-25 06:18:49 +00:00
initial commit
This commit is contained in:
commit
6154c72b0e
55 changed files with 9481 additions and 0 deletions
89
crates/comet_input/src/mouse.rs
Normal file
89
crates/comet_input/src/mouse.rs
Normal 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,
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue