@@ -73,7 +73,7 @@ fn change_window(_: &mut World, resources: &mut Resources) {
73
73
}
74
74
bevy_window:: WindowCommand :: SetResolution { width, height } => {
75
75
let window = winit_windows. get_window ( id) . unwrap ( ) ;
76
- window. set_inner_size ( winit:: dpi:: PhysicalSize :: new ( width, height) ) ;
76
+ window. set_inner_size ( winit:: dpi:: LogicalSize :: new ( width, height) ) ;
77
77
}
78
78
bevy_window:: WindowCommand :: SetVsync { .. } => ( ) ,
79
79
bevy_window:: WindowCommand :: SetResizable { resizable } => {
@@ -97,7 +97,7 @@ fn change_window(_: &mut World, resources: &mut Resources) {
97
97
bevy_window:: WindowCommand :: SetCursorPosition { x, y } => {
98
98
let window = winit_windows. get_window ( id) . unwrap ( ) ;
99
99
window
100
- . set_cursor_position ( winit:: dpi:: PhysicalPosition :: new ( x, y) )
100
+ . set_cursor_position ( winit:: dpi:: LogicalPosition :: new ( x, y) )
101
101
. unwrap_or_else ( |e| error ! ( "Unable to set cursor position: {}" , e) ) ;
102
102
}
103
103
}
@@ -184,29 +184,28 @@ pub fn winit_runner(mut app: App) {
184
184
}
185
185
186
186
match event {
187
- event:: Event :: WindowEvent {
188
- event : WindowEvent :: Resized ( size) ,
189
- window_id : winit_window_id,
190
- ..
191
- } => {
192
- let winit_windows = app. resources . get_mut :: < WinitWindows > ( ) . unwrap ( ) ;
193
- let mut windows = app. resources . get_mut :: < Windows > ( ) . unwrap ( ) ;
194
- let window_id = winit_windows. get_window_id ( winit_window_id) . unwrap ( ) ;
195
- let window = windows. get_mut ( window_id) . unwrap ( ) ;
196
- window. update_resolution_from_backend ( size. width , size. height ) ;
197
-
198
- let mut resize_events = app. resources . get_mut :: < Events < WindowResized > > ( ) . unwrap ( ) ;
199
- resize_events. send ( WindowResized {
200
- id : window_id,
201
- height : window. height ( ) as usize ,
202
- width : window. width ( ) as usize ,
203
- } ) ;
204
- }
205
187
event:: Event :: WindowEvent {
206
188
event,
207
189
window_id : winit_window_id,
208
190
..
209
191
} => match event {
192
+ WindowEvent :: Resized ( size) => {
193
+ let winit_windows = app. resources . get_mut :: < WinitWindows > ( ) . unwrap ( ) ;
194
+ let mut windows = app. resources . get_mut :: < Windows > ( ) . unwrap ( ) ;
195
+ let window_id = winit_windows. get_window_id ( winit_window_id) . unwrap ( ) ;
196
+ let winit_window = winit_windows. get_window ( window_id) . unwrap ( ) ;
197
+ let window = windows. get_mut ( window_id) . unwrap ( ) ;
198
+ let size = size. to_logical ( winit_window. scale_factor ( ) ) ;
199
+ window. update_resolution_from_backend ( size. width , size. height ) ;
200
+
201
+ let mut resize_events =
202
+ app. resources . get_mut :: < Events < WindowResized > > ( ) . unwrap ( ) ;
203
+ resize_events. send ( WindowResized {
204
+ id : window_id,
205
+ height : window. height ( ) as usize ,
206
+ width : window. width ( ) as usize ,
207
+ } ) ;
208
+ }
210
209
WindowEvent :: CloseRequested => {
211
210
let mut window_close_requested_events = app
212
211
. resources
@@ -227,12 +226,13 @@ pub fn winit_runner(mut app: App) {
227
226
let winit_windows = app. resources . get_mut :: < WinitWindows > ( ) . unwrap ( ) ;
228
227
let window_id = winit_windows. get_window_id ( winit_window_id) . unwrap ( ) ;
229
228
let window = winit_windows. get_window ( window_id) . unwrap ( ) ;
230
- let inner_size = window. inner_size ( ) ;
229
+ let position = position. to_logical ( window. scale_factor ( ) ) ;
230
+ let inner_size = window. inner_size ( ) . to_logical :: < f32 > ( window. scale_factor ( ) ) ;
231
231
// move origin to bottom left
232
- let y_position = inner_size. height as f32 - position. y as f32 ;
232
+ let y_position = inner_size. height - position. y ;
233
233
cursor_moved_events. send ( CursorMoved {
234
234
id : window_id,
235
- position : Vec2 :: new ( position. x as f32 , y_position as f32 ) ,
235
+ position : Vec2 :: new ( position. x , y_position) ,
236
236
} ) ;
237
237
}
238
238
WindowEvent :: MouseInput { state, button, .. } => {
@@ -263,16 +263,22 @@ pub fn winit_runner(mut app: App) {
263
263
} ) ;
264
264
}
265
265
} ,
266
- WindowEvent :: Touch ( mut touch) => {
266
+ WindowEvent :: Touch ( touch) => {
267
267
let mut touch_input_events =
268
268
app. resources . get_mut :: < Events < TouchInput > > ( ) . unwrap ( ) ;
269
+
270
+ let winit_windows = app. resources . get_mut :: < WinitWindows > ( ) . unwrap ( ) ;
269
271
let windows = app. resources . get_mut :: < Windows > ( ) . unwrap ( ) ;
272
+ let window_id = winit_windows. get_window_id ( winit_window_id) . unwrap ( ) ;
273
+ let winit_window = winit_windows. get_window ( window_id) . unwrap ( ) ;
274
+ let mut location = touch. location . to_logical ( winit_window. scale_factor ( ) ) ;
275
+
270
276
// FIXME?: On Android window start is top while on PC/Linux/OSX on bottom
271
277
if cfg ! ( target_os = "android" ) {
272
278
let window_height = windows. get_primary ( ) . unwrap ( ) . height ( ) ;
273
- touch . location . y = window_height as f64 - touch . location . y ;
279
+ location. y = window_height as f32 - location. y ;
274
280
}
275
- touch_input_events. send ( converters:: convert_touch_input ( touch) ) ;
281
+ touch_input_events. send ( converters:: convert_touch_input ( touch, location ) ) ;
276
282
}
277
283
WindowEvent :: ReceivedCharacter ( c) => {
278
284
let mut char_input_events = app
@@ -288,6 +294,18 @@ pub fn winit_runner(mut app: App) {
288
294
char : c,
289
295
} )
290
296
}
297
+ WindowEvent :: ScaleFactorChanged {
298
+ scale_factor,
299
+ new_inner_size,
300
+ } => {
301
+ let winit_windows = app. resources . get_mut :: < WinitWindows > ( ) . unwrap ( ) ;
302
+ let mut windows = app. resources . get_mut :: < Windows > ( ) . unwrap ( ) ;
303
+ let window_id = winit_windows. get_window_id ( winit_window_id) . unwrap ( ) ;
304
+ let window = windows. get_mut ( window_id) . unwrap ( ) ;
305
+ let size = new_inner_size. to_logical ( scale_factor) ;
306
+ window. update_scale_factor_from_backend ( scale_factor) ;
307
+ window. update_resolution_from_backend ( size. width , size. height ) ;
308
+ }
291
309
_ => { }
292
310
} ,
293
311
event:: Event :: DeviceEvent { ref event, .. } => {
@@ -327,8 +345,8 @@ fn handle_create_window_events(
327
345
let create_window_events = resources. get :: < Events < CreateWindow > > ( ) . unwrap ( ) ;
328
346
let mut window_created_events = resources. get_mut :: < Events < WindowCreated > > ( ) . unwrap ( ) ;
329
347
for create_window_event in create_window_event_reader. iter ( & create_window_events) {
330
- let window = Window :: new ( create_window_event. id , & create_window_event. descriptor ) ;
331
- winit_windows. create_window ( event_loop, & window) ;
348
+ let mut window = Window :: new ( create_window_event. id , & create_window_event. descriptor ) ;
349
+ winit_windows. create_window ( event_loop, & mut window) ;
332
350
let window_id = window. id ( ) ;
333
351
windows. add ( window) ;
334
352
window_created_events. send ( WindowCreated { id : window_id } ) ;
0 commit comments