@@ -12,7 +12,7 @@ pub use winit_windows::*;
12
12
13
13
use bevy_app:: { App , AppExit , CoreStage , Events , ManualEventReader , Plugin } ;
14
14
use bevy_ecs:: { system:: IntoExclusiveSystem , world:: World } ;
15
- use bevy_math:: { ivec2, Vec2 } ;
15
+ use bevy_math:: { ivec2, DVec2 , Vec2 } ;
16
16
use bevy_utils:: tracing:: { error, trace, warn} ;
17
17
use bevy_window:: {
18
18
CreateWindow , CursorEntered , CursorLeft , CursorMoved , FileDragAndDrop , ReceivedCharacter ,
@@ -303,20 +303,18 @@ pub fn winit_runner_with(mut app: App, mut event_loop: EventLoop<()>) {
303
303
let mut cursor_moved_events =
304
304
world. get_resource_mut :: < Events < CursorMoved > > ( ) . unwrap ( ) ;
305
305
let winit_window = winit_windows. get_window ( window_id) . unwrap ( ) ;
306
- let position = position. to_logical ( winit_window. scale_factor ( ) ) ;
307
- let inner_size = winit_window
308
- . inner_size ( )
309
- . to_logical :: < f32 > ( winit_window. scale_factor ( ) ) ;
306
+ let inner_size = winit_window. inner_size ( ) ;
310
307
311
308
// move origin to bottom left
312
- let y_position = inner_size. height - position. y ;
309
+ let y_position = inner_size. height as f64 - position. y ;
313
310
314
- let position = Vec2 :: new ( position. x , y_position) ;
315
- window. update_cursor_position_from_backend ( Some ( position) ) ;
311
+ let physical_position = DVec2 :: new ( position. x , y_position) ;
312
+ window
313
+ . update_cursor_physical_position_from_backend ( Some ( physical_position) ) ;
316
314
317
315
cursor_moved_events. send ( CursorMoved {
318
316
id : window_id,
319
- position,
317
+ position : ( physical_position / window . scale_factor ( ) ) . as_vec2 ( ) ,
320
318
} ) ;
321
319
}
322
320
WindowEvent :: CursorEntered { .. } => {
@@ -327,7 +325,7 @@ pub fn winit_runner_with(mut app: App, mut event_loop: EventLoop<()>) {
327
325
WindowEvent :: CursorLeft { .. } => {
328
326
let mut cursor_left_events =
329
327
world. get_resource_mut :: < Events < CursorLeft > > ( ) . unwrap ( ) ;
330
- window. update_cursor_position_from_backend ( None ) ;
328
+ window. update_cursor_physical_position_from_backend ( None ) ;
331
329
cursor_left_events. send ( CursorLeft { id : window_id } ) ;
332
330
}
333
331
WindowEvent :: MouseInput { state, button, .. } => {
@@ -363,8 +361,7 @@ pub fn winit_runner_with(mut app: App, mut event_loop: EventLoop<()>) {
363
361
let mut touch_input_events =
364
362
world. get_resource_mut :: < Events < TouchInput > > ( ) . unwrap ( ) ;
365
363
366
- let winit_window = winit_windows. get_window ( window_id) . unwrap ( ) ;
367
- let mut location = touch. location . to_logical ( winit_window. scale_factor ( ) ) ;
364
+ let mut location = touch. location . to_logical ( window. scale_factor ( ) ) ;
368
365
369
366
// On a mobile window, the start is from the top while on PC/Linux/OSX from
370
367
// bottom
0 commit comments