This commit is contained in:
Mikayla Maki 2023-01-23 10:45:31 -08:00
parent 426aeb7c5e
commit 27a80a1c94
4 changed files with 27 additions and 25 deletions

View file

@ -125,6 +125,7 @@ impl Event {
button,
position: vec2f(
native_event.locationInWindow().x as f32,
// MacOS screen coordinates are relative to bottom left
window_height - native_event.locationInWindow().y as f32,
),
modifiers: read_modifiers(native_event),
@ -150,6 +151,7 @@ impl Event {
button,
position: vec2f(
native_event.locationInWindow().x as f32,
// MacOS view coordinates are relative to bottom left
window_height - native_event.locationInWindow().y as f32,
),
modifiers: read_modifiers(native_event),

View file

@ -697,27 +697,20 @@ impl platform::Platform for MacPlatform {
}
fn set_cursor_style(&self, style: CursorStyle, window_id: usize, screen_position: &Vector2F) {
let top_most = Window::window_id_under(screen_position);
if top_most.is_none() {
return;
}
if top_most.unwrap() != window_id {
return;
}
dbg!(top_most.unwrap(), window_id);
dbg!(style);
unsafe {
let cursor: id = match style {
CursorStyle::Arrow => msg_send![class!(NSCursor), arrowCursor],
CursorStyle::ResizeLeftRight => msg_send![class!(NSCursor), resizeLeftRightCursor],
CursorStyle::ResizeUpDown => msg_send![class!(NSCursor), resizeUpDownCursor],
CursorStyle::PointingHand => msg_send![class!(NSCursor), pointingHandCursor],
CursorStyle::IBeam => msg_send![class!(NSCursor), IBeamCursor],
};
let _: () = msg_send![cursor, set];
if Some(window_id) == Window::window_id_under(screen_position) {
dbg!(screen_position, style);
unsafe {
let cursor: id = match style {
CursorStyle::Arrow => msg_send![class!(NSCursor), arrowCursor],
CursorStyle::ResizeLeftRight => {
msg_send![class!(NSCursor), resizeLeftRightCursor]
}
CursorStyle::ResizeUpDown => msg_send![class!(NSCursor), resizeUpDownCursor],
CursorStyle::PointingHand => msg_send![class!(NSCursor), pointingHandCursor],
CursorStyle::IBeam => msg_send![class!(NSCursor), IBeamCursor],
};
let _: () = msg_send![cursor, set];
}
}
}

View file

@ -52,6 +52,8 @@ use std::{
time::Duration,
};
use super::geometry::Vector2FExt;
const WINDOW_STATE_IVAR: &str = "windowState";
static mut WINDOW_CLASS: *const Class = ptr::null();
@ -564,11 +566,13 @@ impl Window {
unsafe {
let app = NSApplication::sharedApplication(nil);
let point = NSPoint::new(screen_position.x() as f64, screen_position.y() as f64);
let window_number: NSInteger = msg_send![class!(NSWindow), windowNumberAtPoint:point belowWindowWithWindowNumber:0 as NSInteger];
let point = screen_position.to_ns_point();
let window_number: NSInteger = msg_send![class!(NSWindow), windowNumberAtPoint:point belowWindowWithWindowNumber:0];
// For some reason this API doesn't work when our two windows are on top of each other
let top_most_window: id = msg_send![app, windowWithWindowNumber: window_number];
dbg!(top_most_window);
// dbg!(top_most_window);
let is_panel: BOOL = msg_send![top_most_window, isKindOfClass: PANEL_CLASS];
let is_window: BOOL = msg_send![top_most_window, isKindOfClass: WINDOW_CLASS];
if is_panel | is_window {
@ -779,7 +783,7 @@ impl platform::Window for Window {
fn screen_position(&self, view_position: &Vector2F) -> Vector2F {
let self_borrow = self.0.borrow_mut();
unsafe {
let point = NSPoint::new(view_position.x() as f64, view_position.y() as f64);
let point = view_position.to_ns_point();
let screen_point: NSPoint =
msg_send![self_borrow.native_window, convertPointToScreen: point];
vec2f(screen_point.x as f32, screen_point.y as f32)

View file

@ -317,6 +317,9 @@ impl Presenter {
}
}
dbg!("*******");
dbg!(position);
dbg!(event_reused);
if let Some(screen_position) = cx.screen_position(self.window_id, position) {
cx.platform().set_cursor_style(
style_to_assign,