Use platform API to request mouse position
Co-Authored-By: Conrad Irwin <conrad@zed.dev>
This commit is contained in:
parent
5996b6b46b
commit
684db11afd
8 changed files with 35 additions and 24 deletions
|
@ -221,6 +221,14 @@ unsafe fn build_classes() {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn convert_mouse_position(position: NSPoint, window_height: f32) -> Vector2F {
|
||||
vec2f(
|
||||
position.x as f32,
|
||||
// MacOS screen coordinates are relative to bottom left
|
||||
window_height - position.y as f32,
|
||||
)
|
||||
}
|
||||
|
||||
unsafe fn build_window_class(name: &'static str, superclass: &Class) -> *const Class {
|
||||
let mut decl = ClassDecl::new(name, superclass).unwrap();
|
||||
decl.add_ivar::<*mut c_void>(WINDOW_STATE_IVAR);
|
||||
|
@ -661,6 +669,16 @@ impl platform::Window for MacWindow {
|
|||
}
|
||||
}
|
||||
|
||||
fn mouse_position(&self) -> Vector2F {
|
||||
let position = unsafe {
|
||||
self.0
|
||||
.borrow()
|
||||
.native_window
|
||||
.mouseLocationOutsideOfEventStream()
|
||||
};
|
||||
convert_mouse_position(position, self.content_size().y())
|
||||
}
|
||||
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||
self
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue