Skip to content

Commit 8429b6d

Browse files
committed
Invert Y axis of all cursor interaction instead of only UI
1 parent c0c8011 commit 8429b6d

File tree

3 files changed

+5
-15
lines changed

3 files changed

+5
-15
lines changed

crates/bevy_ui/src/focus.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ pub fn ui_focus_system(
123123
.find_map(|window| window.cursor_position())
124124
.or_else(|| touches_input.first_pressed_position());
125125

126-
let window_height = windows.get_primary().expect("No primary window").height();
127-
128126
let mut moused_over_z_sorted_nodes = node_query
129127
.iter_mut()
130128
.filter_map(
@@ -157,7 +155,7 @@ pub fn ui_focus_system(
157155
// clicking
158156
let contains_cursor = if let Some(cursor_position) = cursor_position {
159157
(min.x..max.x).contains(&cursor_position.x)
160-
&& (min.y..max.y).contains(&(window_height - cursor_position.y))
158+
&& (min.y..max.y).contains(&cursor_position.y)
161159
} else {
162160
false
163161
};

crates/bevy_ui/src/render/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ pub fn extract_default_ui_camera_view<T: Component>(
247247
Mat4::orthographic_rh(0.0, logical_size.x, logical_size.y, 0.0, 0.0, UI_CAMERA_FAR);
248248
let default_camera_view = commands
249249
.spawn(ExtractedView {
250-
projection: projection.get_projection_matrix(),
250+
projection: projection_matrix,
251251
transform: GlobalTransform::from_xyz(
252252
0.0,
253253
0.0,

crates/bevy_winit/src/lib.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,9 @@ fn change_window(
149149
}
150150
bevy_window::WindowCommand::SetCursorPosition { position } => {
151151
let window = winit_windows.get_window(id).unwrap();
152-
let inner_size = window.inner_size().to_logical::<f32>(window.scale_factor());
152+
153153
window
154-
.set_cursor_position(LogicalPosition::new(
155-
position.x,
156-
inner_size.height - position.y,
157-
))
154+
.set_cursor_position(LogicalPosition::new(position.x, position.y))
158155
.unwrap_or_else(|e| error!("Unable to set cursor position: {}", e));
159156
}
160157
bevy_window::WindowCommand::SetMaximized { maximized } => {
@@ -431,13 +428,8 @@ pub fn winit_runner_with(mut app: App) {
431428
}
432429
WindowEvent::CursorMoved { position, .. } => {
433430
let mut cursor_moved_events = world.resource_mut::<Events<CursorMoved>>();
434-
let winit_window = winit_windows.get_window(window_id).unwrap();
435-
let inner_size = winit_window.inner_size();
436-
437-
// move origin to bottom left
438-
let y_position = inner_size.height as f64 - position.y;
439431

440-
let physical_position = DVec2::new(position.x, y_position);
432+
let physical_position = DVec2::new(position.x, position.y);
441433
window
442434
.update_cursor_physical_position_from_backend(Some(physical_position));
443435

0 commit comments

Comments
 (0)