Skip to content

Commit

Permalink
Invert Y axis of all cursor interaction instead of only UI
Browse files Browse the repository at this point in the history
  • Loading branch information
mahulst committed Sep 25, 2022
1 parent c0c8011 commit 4ca9759
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
4 changes: 1 addition & 3 deletions crates/bevy_ui/src/focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
};
Expand Down
11 changes: 3 additions & 8 deletions crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<f32>(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));
}
Expand Down Expand Up @@ -431,13 +431,8 @@ pub fn winit_runner_with(mut app: App) {
}
WindowEvent::CursorMoved { position, .. } => {
let mut cursor_moved_events = world.resource_mut::<Events<CursorMoved>>();
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));

Expand Down

0 comments on commit 4ca9759

Please sign in to comment.