diff options
author | 2024-05-02 13:15:17 +0200 | |
---|---|---|
committer | 2024-05-02 17:27:45 +0200 | |
commit | 09a6bcfffc24f5abdc8709403bab7ae1e01563f1 (patch) | |
tree | 8a09792cd01cb56a3a5d11184a60009f8a22a85f /tiny_skia/src/engine.rs | |
parent | aae8e4f5cfabfc3725ac938023fa29a6737a380c (diff) | |
download | iced-09a6bcfffc24f5abdc8709403bab7ae1e01563f1.tar.gz iced-09a6bcfffc24f5abdc8709403bab7ae1e01563f1.tar.bz2 iced-09a6bcfffc24f5abdc8709403bab7ae1e01563f1.zip |
Add `Image` rotation support
Co-authored-by: DKolter <68352124+DKolter@users.noreply.github.com>
Diffstat (limited to 'tiny_skia/src/engine.rs')
-rw-r--r-- | tiny_skia/src/engine.rs | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/tiny_skia/src/engine.rs b/tiny_skia/src/engine.rs index fbca1274..564d3752 100644 --- a/tiny_skia/src/engine.rs +++ b/tiny_skia/src/engine.rs @@ -539,10 +539,10 @@ impl Engine { pub fn draw_image( &mut self, image: &Image, - _transformation: Transformation, - _pixels: &mut tiny_skia::PixmapMut<'_>, - _clip_mask: &mut tiny_skia::Mask, - _clip_bounds: Rectangle, + transformation: Transformation, + pixels: &mut tiny_skia::PixmapMut<'_>, + clip_mask: &mut tiny_skia::Mask, + clip_bounds: Rectangle, ) { match image { #[cfg(feature = "image")] @@ -550,22 +550,31 @@ impl Engine { handle, filter_method, bounds, + rotation, + scale, } => { - let physical_bounds = *bounds * _transformation; + let physical_bounds = *bounds * transformation; - if !_clip_bounds.intersects(&physical_bounds) { + if !clip_bounds.intersects(&physical_bounds) { return; } - let clip_mask = (!physical_bounds.is_within(&_clip_bounds)) - .then_some(_clip_mask as &_); + let clip_mask = (!physical_bounds.is_within(&clip_bounds)) + .then_some(clip_mask as &_); + + let center = physical_bounds.center(); + let transform = into_transform(transformation) + .post_rotate_at(rotation.to_degrees(), center.x, center.y) + .post_translate(-center.x, -center.y) + .post_scale(scale.width, scale.height) + .post_translate(center.x, center.y); self.raster_pipeline.draw( handle, *filter_method, *bounds, - _pixels, - into_transform(_transformation), + pixels, + transform, clip_mask, ); } @@ -574,21 +583,31 @@ impl Engine { handle, color, bounds, + rotation, + scale, } => { - let physical_bounds = *bounds * _transformation; + let physical_bounds = *bounds * transformation; - if !_clip_bounds.intersects(&physical_bounds) { + if !clip_bounds.intersects(&physical_bounds) { return; } - let clip_mask = (!physical_bounds.is_within(&_clip_bounds)) - .then_some(_clip_mask as &_); + let clip_mask = (!physical_bounds.is_within(&clip_bounds)) + .then_some(clip_mask as &_); + + let center = physical_bounds.center(); + let transform = into_transform(transformation) + .post_rotate_at(rotation.to_degrees(), center.x, center.y) + .post_translate(-center.x, -center.y) + .post_scale(scale.width, scale.height) + .post_translate(center.x, center.y); self.vector_pipeline.draw( handle, *color, physical_bounds, - _pixels, + pixels, + transform, clip_mask, ); } |