From ba1318e8501adccd1e3dff65ae6ff398c0a2dc90 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_ui/src/render/mod.rs | 2 +- crates/bevy_winit/src/lib.rs | 11 +++-------- 3 files changed, 5 insertions(+), 12 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_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index a611be84c38fa6..6b6a973c3e742a 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -247,7 +247,7 @@ pub fn extract_default_ui_camera_view( Mat4::orthographic_rh(0.0, logical_size.x, logical_size.y, 0.0, 0.0, UI_CAMERA_FAR); let default_camera_view = commands .spawn(ExtractedView { - projection: projection.get_projection_matrix(), + projection: projection_matrix, transform: GlobalTransform::from_xyz( 0.0, 0.0, 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));