Skip to content

Commit

Permalink
Merge pull request #198 from gufoe/master
Browse files Browse the repository at this point in the history
Added set_cursor_position and hide_cursor functions
  • Loading branch information
sebcrozet authored Oct 26, 2020
2 parents 05d3c91 + b1684f6 commit 2afa354
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/window/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ impl Canvas {
self.canvas.set_cursor_grab(grab);
}

pub fn set_cursor_position(&self, x: f64, y: f64) {
self.canvas.set_cursor_position(x, y);
}

pub fn hide_cursor(&self, hide: bool) {
self.canvas.hide_cursor(hide);
}

/// Hide the window.
pub fn hide(&mut self) {
self.canvas.hide()
Expand Down Expand Up @@ -157,6 +165,8 @@ pub(crate) trait AbstractCanvas {
fn set_title(&mut self, title: &str);
fn set_icon(&mut self, icon: impl GenericImage<Pixel = impl Pixel<Subpixel = u8>>);
fn set_cursor_grab(&self, grab: bool);
fn set_cursor_position(&self, x: f64, y: f64);
fn hide_cursor(&self, hide: bool);
fn hide(&mut self);
fn show(&mut self);

Expand Down
10 changes: 10 additions & 0 deletions src/window/gl_canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ impl AbstractCanvas for GLCanvas {
let _ = self.window.window().grab_cursor(grab);
}

fn set_cursor_position(&self, x: f64, y: f64) {
let dpi = self.window.get_hidpi_factor();
self.window.set_cursor_position(glutin::dpi::LogicalPosition::new(x / dpi, y / dpi)).unwrap();
}


fn hide_cursor(&self, hide: bool) {
self.window.hide_cursor(hide);
}

fn hide(&mut self) {
self.window.hide()
}
Expand Down
11 changes: 11 additions & 0 deletions src/window/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ impl Window {
Vector2::new(w, h)
}


/// Sets the maximum number of frames per second. Cannot be 0. `None` means there is no limit.
#[inline]
pub fn set_framerate_limit(&mut self, fps: Option<u64>) {
Expand Down Expand Up @@ -151,6 +152,16 @@ impl Window {
self.canvas.set_cursor_grab(grab);
}

#[inline]
pub fn set_cursor_position(&self, x: f64, y: f64) {
self.canvas.set_cursor_position(x, y);
}

#[inline]
pub fn hide_cursor(&self, hide: bool) {
self.canvas.hide_cursor(hide);
}

/// Closes the window.
#[inline]
pub fn close(&mut self) {
Expand Down

0 comments on commit 2afa354

Please sign in to comment.