-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIXES #52
- Loading branch information
Showing
7 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use winit::event::VirtualKeyCode; | ||
|
||
#[derive(Eq, PartialEq, Hash, Clone)] | ||
pub enum KeyCode { | ||
Escape, | ||
Left, | ||
Up, | ||
Right, | ||
Down, | ||
Any | ||
} | ||
|
||
impl From<VirtualKeyCode> for KeyCode { | ||
fn from(vkc: VirtualKeyCode) -> Self { | ||
match vkc{ | ||
VirtualKeyCode::Escape => KeyCode::Escape, | ||
VirtualKeyCode::Left => KeyCode::Left, | ||
VirtualKeyCode::Up => KeyCode::Up, | ||
VirtualKeyCode::Right => KeyCode::Right, | ||
VirtualKeyCode::Down => KeyCode::Down, | ||
_ => KeyCode::Any | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
|
||
pub mod keycode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::collections::HashSet; | ||
use crate::core::inputs::keycode::KeyCode; | ||
|
||
#[derive(Default)] | ||
pub struct Keyboard { | ||
pressed_keys: HashSet<KeyCode>, | ||
event_keys: HashSet<KeyCode> | ||
} | ||
|
||
impl Keyboard { | ||
pub fn key_pressed(&self, key: &KeyCode) -> bool{ | ||
self.pressed_keys.contains(key) | ||
} | ||
|
||
pub fn key_event(&self, key: &KeyCode) -> bool{ | ||
self.event_keys.contains(key) | ||
} | ||
|
||
pub(crate) fn clear_events(&mut self){ | ||
self.event_keys.clear() | ||
} | ||
|
||
pub(crate) fn press(&mut self, key: KeyCode){ | ||
self.pressed_keys.insert(key.clone()); | ||
self.event_keys.insert(key); | ||
} | ||
|
||
pub(crate) fn release(&mut self, key: KeyCode){ | ||
self.pressed_keys.remove(&key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ pub mod inputs; | |
pub mod mouse; | ||
pub mod time; | ||
pub mod window; | ||
pub mod keyboard; |