Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Move the cursor's origin back to the bottom-left #6533

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Revert "Invert Y axis of all cursor interaction instead of only UI"
This reverts commit 8429b6d.
tim-blackbird committed Nov 10, 2022

Unverified

This user has not yet uploaded their public signing key.
commit daa225d22560c7cb24fc1d74c4825b5e12c8b938
4 changes: 3 additions & 1 deletion crates/bevy_ui/src/focus.rs
Original file line number Diff line number Diff line change
@@ -127,6 +127,8 @@ pub fn ui_focus_system(
.find_map(|window| window.cursor_position())
.or_else(|| touches_input.first_pressed_position());

let window_height = windows.primary().height();

// prepare an iterator that contains all the nodes that have the cursor in their rect,
// from the top node to the bottom one. this will also reset the interaction to `None`
// for all nodes encountered that are no longer hovered.
@@ -165,7 +167,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(&cursor_position.y)
&& (min.y..max.y).contains(&(window_height - cursor_position.y))
} else {
false
};
15 changes: 12 additions & 3 deletions crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
@@ -146,9 +146,12 @@ 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, position.y))
.set_cursor_position(LogicalPosition::new(
position.x,
inner_size.height - position.y,
))
.unwrap_or_else(|e| error!("Unable to set cursor position: {}", e));
}
bevy_window::WindowCommand::SetMaximized { maximized } => {
@@ -417,7 +420,13 @@ pub fn winit_runner_with(mut app: App) {
world.send_event(converters::convert_keyboard_input(input));
}
WindowEvent::CursorMoved { position, .. } => {
let physical_position = DVec2::new(position.x, position.y);
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);
window
.update_cursor_physical_position_from_backend(Some(physical_position));