1
1
//! The touch input functionality.
2
2
3
+ use bevy_ecs:: entity:: Entity ;
3
4
use bevy_ecs:: event:: { Event , EventReader } ;
4
5
use bevy_ecs:: system:: { ResMut , Resource } ;
5
6
use bevy_math:: Vec2 ;
@@ -44,6 +45,8 @@ pub struct TouchInput {
44
45
pub phase : TouchPhase ,
45
46
/// The position of the finger on the touchscreen.
46
47
pub position : Vec2 ,
48
+ /// The window entity registering the touch.
49
+ pub window : Entity ,
47
50
/// Describes how hard the screen was pressed.
48
51
///
49
52
/// May be [`None`] if the platform does not support pressure sensitivity.
@@ -408,6 +411,7 @@ mod test {
408
411
#[ test]
409
412
fn touch_process ( ) {
410
413
use crate :: { touch:: TouchPhase , TouchInput , Touches } ;
414
+ use bevy_ecs:: entity:: Entity ;
411
415
use bevy_math:: Vec2 ;
412
416
413
417
let mut touches = Touches :: default ( ) ;
@@ -417,6 +421,7 @@ mod test {
417
421
let touch_event = TouchInput {
418
422
phase : TouchPhase :: Started ,
419
423
position : Vec2 :: splat ( 4.0 ) ,
424
+ window : Entity :: PLACEHOLDER ,
420
425
force : None ,
421
426
id : 4 ,
422
427
} ;
@@ -432,6 +437,7 @@ mod test {
432
437
let moved_touch_event = TouchInput {
433
438
phase : TouchPhase :: Moved ,
434
439
position : Vec2 :: splat ( 5.0 ) ,
440
+ window : Entity :: PLACEHOLDER ,
435
441
force : None ,
436
442
id : touch_event. id ,
437
443
} ;
@@ -453,6 +459,7 @@ mod test {
453
459
let cancel_touch_event = TouchInput {
454
460
phase : TouchPhase :: Canceled ,
455
461
position : Vec2 :: ONE ,
462
+ window : Entity :: PLACEHOLDER ,
456
463
force : None ,
457
464
id : touch_event. id ,
458
465
} ;
@@ -468,6 +475,7 @@ mod test {
468
475
let end_touch_event = TouchInput {
469
476
phase : TouchPhase :: Ended ,
470
477
position : Vec2 :: splat ( 4.0 ) ,
478
+ window : Entity :: PLACEHOLDER ,
471
479
force : None ,
472
480
id : touch_event. id ,
473
481
} ;
@@ -487,13 +495,15 @@ mod test {
487
495
#[ test]
488
496
fn touch_pressed ( ) {
489
497
use crate :: { touch:: TouchPhase , TouchInput , Touches } ;
498
+ use bevy_ecs:: entity:: Entity ;
490
499
use bevy_math:: Vec2 ;
491
500
492
501
let mut touches = Touches :: default ( ) ;
493
502
494
503
let touch_event = TouchInput {
495
504
phase : TouchPhase :: Started ,
496
505
position : Vec2 :: splat ( 4.0 ) ,
506
+ window : Entity :: PLACEHOLDER ,
497
507
force : None ,
498
508
id : 4 ,
499
509
} ;
@@ -509,13 +519,15 @@ mod test {
509
519
#[ test]
510
520
fn touch_released ( ) {
511
521
use crate :: { touch:: TouchPhase , TouchInput , Touches } ;
522
+ use bevy_ecs:: entity:: Entity ;
512
523
use bevy_math:: Vec2 ;
513
524
514
525
let mut touches = Touches :: default ( ) ;
515
526
516
527
let touch_event = TouchInput {
517
528
phase : TouchPhase :: Ended ,
518
529
position : Vec2 :: splat ( 4.0 ) ,
530
+ window : Entity :: PLACEHOLDER ,
519
531
force : None ,
520
532
id : 4 ,
521
533
} ;
@@ -531,13 +543,15 @@ mod test {
531
543
#[ test]
532
544
fn touch_canceled ( ) {
533
545
use crate :: { touch:: TouchPhase , TouchInput , Touches } ;
546
+ use bevy_ecs:: entity:: Entity ;
534
547
use bevy_math:: Vec2 ;
535
548
536
549
let mut touches = Touches :: default ( ) ;
537
550
538
551
let touch_event = TouchInput {
539
552
phase : TouchPhase :: Canceled ,
540
553
position : Vec2 :: splat ( 4.0 ) ,
554
+ window : Entity :: PLACEHOLDER ,
541
555
force : None ,
542
556
id : 4 ,
543
557
} ;
0 commit comments