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 ba1318e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 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
2 changes: 1 addition & 1 deletion crates/bevy_ui/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ pub fn extract_default_ui_camera_view<T: Component>(
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,
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 ba1318e

Please sign in to comment.