summaryrefslogtreecommitdiff
path: root/engine/src/lib.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-10-27 21:44:49 +0200
committerHampusM <hampus@hampusmat.com>2023-10-27 21:44:49 +0200
commit4c9fe4e4cf8b9b2358bdbb08766fef46dc9ba82b (patch)
tree6b2d43d5c94660386ab5066e8ce8dafc090f640a /engine/src/lib.rs
parentb8f437e48777e32eaf4f518b9d1a37c507eb0aac (diff)
feat(engine): add get cursor position
Diffstat (limited to 'engine/src/lib.rs')
-rw-r--r--engine/src/lib.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/engine/src/lib.rs b/engine/src/lib.rs
index d848112..ec969f8 100644
--- a/engine/src/lib.rs
+++ b/engine/src/lib.rs
@@ -154,6 +154,20 @@ impl Engine
.map_err(Error::GetKeyStateFailed)
}
+ /// Returns the cursor position.
+ ///
+ /// # Errors
+ /// Will return `Err` if unable to get the cursor position from GLFW.
+ pub fn get_cursor_pos(&self) -> Result<Vec2<f64>, Error>
+ {
+ let pos = self
+ .window
+ .get_cursor_position()
+ .map_err(Error::GetCursorPosFailed)?;
+
+ Ok(Vec2 { x: pos.x, y: pos.y })
+ }
+
fn update_delta_time(&mut self, prev_frame_start: &mut Option<Instant>)
{
let frame_start_time = Instant::now();
@@ -187,4 +201,7 @@ pub enum Error
#[error("Failed to get key state")]
GetKeyStateFailed(#[source] glfw::Error),
+
+ #[error("Failed to get cursor position")]
+ GetCursorPosFailed(#[source] glfw::Error),
}