use super::super::*;
use super::make_global_arrangement;
use bevy_ecs::world::World;
use windows::Win32::Graphics::Direct2D::Common::D2D1_COLOR_F;
#[test]
fn test_hit_test_entity_bounds_alpha_boundary_above() {
use crate::ecs::graphics::Visual;
use crate::ecs::widget::brushes::Brushes;
let mut world = World::new();
let entity = world
.spawn((
HitTest::bounds(),
Visual {
opacity: 0.502,
..Default::default()
},
Brushes::with_foreground(D2D1_COLOR_F {
r: 1.0,
g: 0.0,
b: 0.0,
a: 1.0,
}),
))
.id();
world.flush();
world
.entity_mut(entity)
.insert(make_global_arrangement(0.0, 0.0, 100.0, 100.0));
assert!(hit_test_entity(
&world,
entity,
PhysicalPoint::new(50.0, 50.0)
));
}
#[test]
fn test_hit_test_entity_bounds_alpha_boundary_below() {
use crate::ecs::graphics::Visual;
use crate::ecs::widget::brushes::Brushes;
let mut world = World::new();
let entity = world
.spawn((
HitTest::bounds(),
Visual {
opacity: 0.501,
..Default::default()
},
Brushes::with_foreground(D2D1_COLOR_F {
r: 1.0,
g: 0.0,
b: 0.0,
a: 1.0,
}),
))
.id();
world.flush();
world
.entity_mut(entity)
.insert(make_global_arrangement(0.0, 0.0, 100.0, 100.0));
assert!(!hit_test_entity(
&world,
entity,
PhysicalPoint::new(50.0, 50.0)
));
}
#[test]
fn test_hit_test_entity_bounds_low_opacity() {
use crate::ecs::graphics::Visual;
use crate::ecs::widget::brushes::Brushes;
let mut world = World::new();
let entity = world
.spawn((
HitTest::bounds(),
Visual {
opacity: 0.4,
..Default::default()
},
Brushes::with_foreground(D2D1_COLOR_F {
r: 0.0,
g: 1.0,
b: 0.0,
a: 1.0,
}),
))
.id();
world.flush();
world
.entity_mut(entity)
.insert(make_global_arrangement(0.0, 0.0, 100.0, 100.0));
assert!(!hit_test_entity(
&world,
entity,
PhysicalPoint::new(50.0, 50.0)
));
}
#[test]
fn test_hit_test_entity_bounds_low_foreground_alpha() {
use crate::ecs::graphics::Visual;
use crate::ecs::widget::brushes::Brushes;
let mut world = World::new();
let entity = world
.spawn((
HitTest::bounds(),
Visual {
opacity: 1.0,
..Default::default()
},
Brushes::with_foreground(D2D1_COLOR_F {
r: 0.0,
g: 0.0,
b: 1.0,
a: 0.4,
}),
))
.id();
world.flush();
world
.entity_mut(entity)
.insert(make_global_arrangement(0.0, 0.0, 100.0, 100.0));
assert!(!hit_test_entity(
&world,
entity,
PhysicalPoint::new(50.0, 50.0)
));
}
#[test]
fn test_hit_test_entity_bounds_no_opacity_no_brushes() {
let mut world = World::new();
let entity = world
.spawn((
make_global_arrangement(0.0, 0.0, 100.0, 100.0),
HitTest::bounds(),
))
.id();
assert!(hit_test_entity(
&world,
entity,
PhysicalPoint::new(50.0, 50.0)
));
}
#[test]
fn test_hit_test_entity_bounds_inherit_foreground() {
use crate::ecs::graphics::Visual;
use crate::ecs::widget::brushes::Brushes;
let mut world = World::new();
let entity = world
.spawn((
HitTest::bounds(),
Visual {
opacity: 0.502,
..Default::default()
},
Brushes::default(), ))
.id();
world.flush();
world
.entity_mut(entity)
.insert(make_global_arrangement(0.0, 0.0, 100.0, 100.0));
assert!(hit_test_entity(
&world,
entity,
PhysicalPoint::new(50.0, 50.0)
));
}