@@ -287,13 +287,13 @@ impl App {
287
287
let bg_id = canvas
288
288
. create_image (
289
289
ImageSource :: try_from ( & bg_orig) . unwrap ( ) ,
290
- ImageFlags :: empty ( ) ,
290
+ ImageFlags :: NEAREST ,
291
291
)
292
292
. unwrap ( ) ;
293
293
let screen_id = canvas
294
294
. create_image (
295
295
ImageSource :: try_from ( & * SCREEN_FB . lock ( ) . unwrap ( ) ) . unwrap ( ) ,
296
- ImageFlags :: empty ( ) ,
296
+ ImageFlags :: NEAREST ,
297
297
)
298
298
. unwrap ( ) ;
299
299
@@ -337,12 +337,12 @@ impl ApplicationHandler<UserEvent> for App {
337
337
let window_size = window. inner_size ( ) ;
338
338
canvas. set_size ( window_size. width , window_size. height , dpi_factor) ;
339
339
340
+ let margin = ( MARGIN as f32 * dpi_factor) as u32 ;
341
+
340
342
let bitbox_x = MARGIN as f32 * dpi_factor;
341
343
let bitbox_y = MARGIN as f32 * dpi_factor;
342
- let bitbox_width =
343
- ( SCREEN_WIDTH + PADDING_LEFT + PADDING_RIGHT ) as f32 * dpi_factor;
344
- let bitbox_height =
345
- ( SCREEN_HEIGHT + 2 * PADDING_TOP_BOTTOM ) as f32 * dpi_factor;
344
+ let bitbox_width = ( window_size. width - 2 * margin) as f32 ;
345
+ let bitbox_height = ( window_size. height - 2 * margin) as f32 ;
346
346
347
347
let mut bitbox_path = Path :: new ( ) ;
348
348
bitbox_path. rect ( bitbox_x, bitbox_y, bitbox_width, bitbox_height) ;
@@ -359,11 +359,19 @@ impl ApplicationHandler<UserEvent> for App {
359
359
1f32 ,
360
360
) ,
361
361
) ;
362
-
363
- let screen_x = ( MARGIN + PADDING_LEFT ) as f32 * dpi_factor;
364
- let screen_y = ( MARGIN + PADDING_TOP_BOTTOM ) as f32 * dpi_factor;
365
- let screen_width = SCREEN_WIDTH as f32 * dpi_factor;
366
- let screen_height = SCREEN_HEIGHT as f32 * dpi_factor;
362
+ let bitbox_width_scale_factor = ( window_size. width - 2 * margin) as f32
363
+ / ( PADDING_LEFT + SCREEN_WIDTH + PADDING_RIGHT ) as f32 ;
364
+
365
+ let bitbox_height_scale_factor = ( window_size. height - 2 * margin) as f32
366
+ / ( 2 * PADDING_TOP_BOTTOM + SCREEN_HEIGHT ) as f32 ;
367
+
368
+ let screen_x =
369
+ ( margin as f32 + PADDING_LEFT as f32 * bitbox_width_scale_factor) as f32 ;
370
+ let screen_y = ( margin as f32
371
+ + PADDING_TOP_BOTTOM as f32 * bitbox_height_scale_factor)
372
+ as f32 ;
373
+ let screen_width = SCREEN_WIDTH as f32 * bitbox_width_scale_factor;
374
+ let screen_height = SCREEN_HEIGHT as f32 * bitbox_height_scale_factor;
367
375
let mut screen_path = Path :: new ( ) ;
368
376
screen_path. rect ( screen_x, screen_y, screen_width, screen_height) ;
369
377
canvas. fill_path (
@@ -395,11 +403,25 @@ impl ApplicationHandler<UserEvent> for App {
395
403
}
396
404
}
397
405
WindowEvent :: CursorMoved { position, .. } => {
398
- debug ! ( "{position:?}" ) ;
406
+ // debug!("{position:?}");
399
407
let Some ( window) = & mut self . window else {
400
408
return ;
401
409
} ;
402
- let ( x, y) : ( i32 , i32 ) = position. to_logical :: < f64 > ( window. scale_factor ( ) ) . into ( ) ;
410
+ //let (x, y): (i32, i32) = position.to_logical::<f64>(window.scale_factor()).into();
411
+ let ( x, y) = ( position. x , position. y ) ;
412
+ let window_size = window. inner_size ( ) ;
413
+ let dpi_factor = window. scale_factor ( ) as f32 ;
414
+ //let margin = (MARGIN as f32 * dpi_factor) as u32;
415
+ let width_scale_factor = ( window_size. width ) as f32
416
+ / ( 2 * MARGIN + PADDING_LEFT + SCREEN_WIDTH + PADDING_RIGHT ) as f32 ;
417
+
418
+ let height_scale_factor = ( window_size. height ) as f32
419
+ / ( 2 * MARGIN + 2 * PADDING_TOP_BOTTOM + SCREEN_HEIGHT ) as f32 ;
420
+
421
+ let ( x, y) = (
422
+ ( x as f32 / width_scale_factor) as i32 ,
423
+ ( y as f32 / height_scale_factor) as i32 ,
424
+ ) ;
403
425
let xrel = x - self . mouse_last_x ;
404
426
let yrel = y - self . mouse_last_y ;
405
427
// Ignore if mouse didn't move long enough
0 commit comments