diff options
Diffstat (limited to 'engine/src/windowing')
| -rw-r--r-- | engine/src/windowing/keyboard.rs | 28 | ||||
| -rw-r--r-- | engine/src/windowing/window.rs | 16 |
2 files changed, 42 insertions, 2 deletions
diff --git a/engine/src/windowing/keyboard.rs b/engine/src/windowing/keyboard.rs index e4fffe5..a1c3e22 100644 --- a/engine/src/windowing/keyboard.rs +++ b/engine/src/windowing/keyboard.rs @@ -10,6 +10,34 @@ pub struct Keyboard impl Keyboard { + /// Returns whether the given key was just pressed this frame. This function will + /// return `false` if the key was also pressed the previous frame. + pub fn just_pressed(&self, key: Key) -> bool + { + self.get_key_state(key) == KeyState::Pressed + && self.get_prev_key_state(key) == KeyState::Released + } + + /// Returns whether the given key was just released this frame. This function will + /// return `false` if the key was also released the previous frame. + pub fn just_released(&self, key: Key) -> bool + { + self.get_key_state(key) == KeyState::Released + && self.get_prev_key_state(key) == KeyState::Pressed + } + + /// Returns whether the given key is currently pressed. + pub fn pressed(&self, key: Key) -> bool + { + self.get_key_state(key) == KeyState::Pressed + } + + /// Returns whether the given key is currently released. + pub fn released(&self, key: Key) -> bool + { + self.get_key_state(key) == KeyState::Released + } + #[must_use] pub fn get_key_state(&self, key: Key) -> KeyState { diff --git a/engine/src/windowing/window.rs b/engine/src/windowing/window.rs index 79b2102..627bdec 100644 --- a/engine/src/windowing/window.rs +++ b/engine/src/windowing/window.rs @@ -87,11 +87,12 @@ pub struct CreationReady; #[non_exhaustive] pub struct Window { - wid: Id, pub title: Cow<'static, str>, pub cursor_visible: bool, pub cursor_grab_mode: CursorGrabMode, + wid: Id, inner_size: Dimens<u32>, + scale_factor: f64, } impl Window @@ -106,17 +107,23 @@ impl Window &self.inner_size } + pub fn scale_factor(&self) -> f64 + { + self.scale_factor + } + pub(crate) fn new( winit_window: &winit::window::Window, creation_attrs: &CreationAttributes, ) -> Self { Self { - wid: Id::from_inner(winit_window.id()), title: creation_attrs.title().to_string().into(), cursor_visible: true, cursor_grab_mode: CursorGrabMode::None, + wid: Id::from_inner(winit_window.id()), inner_size: winit_window.inner_size().into(), + scale_factor: winit_window.scale_factor(), } } @@ -130,6 +137,11 @@ impl Window { self.inner_size = inner_size; } + + pub(crate) fn set_scale_factor(&mut self, scale_factor: f64) + { + self.scale_factor = scale_factor; + } } #[derive(Debug, Component)] |
