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
				
			
		
							
								
								
									
										32
									
								
								crates/comet_input/src/keyboard.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								crates/comet_input/src/keyboard.rs
									
										
									
									
									
										Normal 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, | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										2
									
								
								crates/comet_input/src/lib.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								crates/comet_input/src/lib.rs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,2 @@ | |||
| pub mod keyboard; | ||||
| pub mod mouse; | ||||
							
								
								
									
										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