Skip to content

Commit

Permalink
Move the cursor's origin back to the bottom-left (bevyengine#6533)
Browse files Browse the repository at this point in the history
This reverts commit 8429b6d as discussed in bevyengine#6522.

I tested that the game_menu example works as it should.

Co-authored-by: devil-ira <justthecooldude@gmail.com>
  • Loading branch information
2 people authored and ItsDoot committed Feb 1, 2023
1 parent 08d112d commit ecc7c22
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion crates/bevy_ui/src/focus.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -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
};
Expand Down
15 changes: 12 additions & 3 deletions crates/bevy_winit/src/lib.rs
Expand Up @@ -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 } => {
Expand Down Expand Up @@ -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));

Expand Down

0 comments on commit ecc7c22

Please sign in to comment.