Move the cursor's origin back to the bottom-left (#6533)
This reverts commit 8429b6d6ca as discussed in #6522.
I tested that the game_menu example works as it should.
Co-authored-by: devil-ira <justthecooldude@gmail.com>
			
			
This commit is contained in:
		
							parent
							
								
									9b56b549ad
								
							
						
					
					
						commit
						99c815fd00
					
				| @ -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 | ||||
|                 }; | ||||
|  | ||||
| @ -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)); | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 ira
						ira