From 4ca9759dfd787e1f6ef11d05e1dfe541f887369b Mon Sep 17 00:00:00 2001 From: mahulst Date: Sun, 25 Sep 2022 13:00:57 +0200 Subject: [PATCH] Invert Y axis of all cursor interaction instead of only UI --- crates/bevy_ui/src/focus.rs | 4 +--- crates/bevy_winit/src/lib.rs | 11 +++-------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/crates/bevy_ui/src/focus.rs b/crates/bevy_ui/src/focus.rs index 8efd28c4fa51cc..f83054b2a8a14b 100644 --- a/crates/bevy_ui/src/focus.rs +++ b/crates/bevy_ui/src/focus.rs @@ -123,8 +123,6 @@ pub fn ui_focus_system( .find_map(|window| window.cursor_position()) .or_else(|| touches_input.first_pressed_position()); - let window_height = windows.get_primary().expect("No primary window").height(); - let mut moused_over_z_sorted_nodes = node_query .iter_mut() .filter_map( @@ -157,7 +155,7 @@ pub fn ui_focus_system( // clicking let contains_cursor = if let Some(cursor_position) = cursor_position { (min.x..max.x).contains(&cursor_position.x) - && (min.y..max.y).contains(&(window_height - cursor_position.y)) + && (min.y..max.y).contains(&cursor_position.y) } else { false }; diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index 66804c5a426b42..e1a6035c0d7820 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -149,11 +149,11 @@ fn change_window( } bevy_window::WindowCommand::SetCursorPosition { position } => { let window = winit_windows.get_window(id).unwrap(); - let inner_size = window.inner_size().to_logical::(window.scale_factor()); + window .set_cursor_position(LogicalPosition::new( position.x, - inner_size.height - position.y, + position.y, )) .unwrap_or_else(|e| error!("Unable to set cursor position: {}", e)); } @@ -431,13 +431,8 @@ pub fn winit_runner_with(mut app: App) { } WindowEvent::CursorMoved { position, .. } => { let mut cursor_moved_events = world.resource_mut::>(); - let winit_window = winit_windows.get_window(window_id).unwrap(); - let inner_size = winit_window.inner_size(); - - // move origin to bottom left - let y_position = inner_size.height as f64 - position.y; - let physical_position = DVec2::new(position.x, y_position); + let physical_position = DVec2::new(position.x, position.y); window .update_cursor_physical_position_from_backend(Some(physical_position));