Move core::Image::clip_bounds to graphics::Image

This commit is contained in:
Héctor Ramón Jiménez 2025-10-28 19:44:46 +01:00
parent 3cc5bd5dbc
commit 7c11ccb046
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
16 changed files with 189 additions and 88 deletions

View file

@ -550,7 +550,7 @@ impl Engine {
) {
match image {
#[cfg(feature = "image")]
Image::Raster(raster, bounds) => {
Image::Raster { image, bounds, .. } => {
let physical_bounds = *bounds * _transformation;
if !_clip_bounds.intersects(&physical_bounds) {
@ -561,7 +561,7 @@ impl Engine {
.then_some(_clip_mask as &_);
let center = physical_bounds.center();
let radians = f32::from(raster.rotation);
let radians = f32::from(image.rotation);
let transform = into_transform(_transformation).post_rotate_at(
radians.to_degrees(),
@ -570,17 +570,17 @@ impl Engine {
);
self.raster_pipeline.draw(
&raster.handle,
raster.filter_method,
&image.handle,
image.filter_method,
*bounds,
raster.opacity,
image.opacity,
_pixels,
transform,
clip_mask,
);
}
#[cfg(feature = "svg")]
Image::Vector(svg, bounds) => {
Image::Vector { svg, bounds, .. } => {
let physical_bounds = *bounds * _transformation;
if !_clip_bounds.intersects(&physical_bounds) {

View file

@ -307,7 +307,11 @@ impl geometry::frame::Backend for Frame {
image.rotation += external_rotation;
self.images.push(graphics::Image::Raster(image, bounds));
self.images.push(graphics::Image::Raster {
image,
bounds,
clip_bounds: self.clip_bounds,
});
}
fn draw_svg(&mut self, bounds: Rectangle, svg: impl Into<Svg>) {
@ -318,7 +322,11 @@ impl geometry::frame::Backend for Frame {
svg.rotation += external_rotation;
self.images.push(Image::Vector(svg, bounds));
self.images.push(Image::Vector {
svg,
bounds,
clip_bounds: self.clip_bounds,
});
}
}

View file

@ -117,11 +117,19 @@ impl Layer {
pub fn draw_image(&mut self, image: Image, transformation: Transformation) {
match image {
Image::Raster(raster, bounds) => {
self.draw_raster(raster, bounds, transformation);
Image::Raster {
image,
bounds,
clip_bounds,
} => {
self.draw_raster(image, bounds, clip_bounds, transformation);
}
Image::Vector(svg, bounds) => {
self.draw_svg(svg, bounds, transformation);
Image::Vector {
svg,
bounds,
clip_bounds,
} => {
self.draw_svg(svg, bounds, clip_bounds, transformation);
}
}
}
@ -130,17 +138,18 @@ impl Layer {
&mut self,
image: core::Image,
bounds: Rectangle,
clip_bounds: Rectangle,
transformation: Transformation,
) {
let image = Image::Raster(
core::Image {
clip_bounds: image.clip_bounds * transformation,
let image = Image::Raster {
image: core::Image {
border_radius: image.border_radius
* transformation.scale_factor(),
..image
},
bounds * transformation,
);
bounds: bounds * transformation,
clip_bounds: clip_bounds * transformation,
};
self.images.push(image);
}
@ -149,9 +158,14 @@ impl Layer {
&mut self,
svg: Svg,
bounds: Rectangle,
clip_bounds: Rectangle,
transformation: Transformation,
) {
let svg = Image::Vector(svg, bounds * transformation);
let svg = Image::Vector {
svg,
bounds: bounds * transformation,
clip_bounds: clip_bounds * transformation,
};
self.images.push(svg);
}

View file

@ -364,9 +364,14 @@ impl core::image::Renderer for Renderer {
self.engine.raster_pipeline.dimensions(handle)
}
fn draw_image(&mut self, image: core::Image, bounds: Rectangle) {
fn draw_image(
&mut self,
image: core::Image,
bounds: Rectangle,
clip_bounds: Rectangle,
) {
let (layer, transformation) = self.layers.current_mut();
layer.draw_raster(image, bounds, transformation);
layer.draw_raster(image, bounds, clip_bounds, transformation);
}
}
@ -379,9 +384,14 @@ impl core::svg::Renderer for Renderer {
self.engine.vector_pipeline.viewport_dimensions(handle)
}
fn draw_svg(&mut self, svg: core::Svg, bounds: Rectangle) {
fn draw_svg(
&mut self,
svg: core::Svg,
bounds: Rectangle,
clip_bounds: Rectangle,
) {
let (layer, transformation) = self.layers.current_mut();
layer.draw_svg(svg, bounds, transformation);
layer.draw_svg(svg, bounds, clip_bounds, transformation);
}
}