use crate::core::{Bounds, HitboxId, Pixels, Point, Size};
use crate::gpu::Affine;
use crate::view::context::ElementContext;
impl ElementContext<'_> {
pub fn insert_hitbox(&mut self, bounds: Bounds, blocks: bool) -> HitboxId {
let Some(transform) = self.hit_transforms.last().filter(|transform| !transform.is_identity()) else {
let clipped = self.mask().intersect(&bounds);
return self.frame.hitboxes.insert(clipped, blocks);
};
let [x, y, width, height] =
transform.bounds_of([bounds.origin.x.0, bounds.origin.y.0, bounds.size.width.0, bounds.size.height.0]);
self.frame
.hitboxes
.insert(Bounds::new(Point::new(Pixels(x), Pixels(y)), Size::new(Pixels(width), Pixels(height))), blocks)
}
pub fn push_hit_transform(&mut self, transform: Affine) {
let current = self.hit_transforms.last().copied().unwrap_or_default();
self.hit_transforms.push(transform.then(current));
}
pub fn pop_hit_transform(&mut self) {
self.hit_transforms.pop();
}
}