summaryrefslogtreecommitdiffstats
path: root/tiny_skia
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-05-02 15:21:22 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-05-02 17:28:28 +0200
commita57313b23ecb9843856ca0ea08635b6121fcb2cb (patch)
tree42a88a4e42031ae99ae87aeb92fea85ab590b01e /tiny_skia
parent09a6bcfffc24f5abdc8709403bab7ae1e01563f1 (diff)
downloadiced-a57313b23ecb9843856ca0ea08635b6121fcb2cb.tar.gz
iced-a57313b23ecb9843856ca0ea08635b6121fcb2cb.tar.bz2
iced-a57313b23ecb9843856ca0ea08635b6121fcb2cb.zip
Simplify image rotation API and its internals
Diffstat (limited to 'tiny_skia')
-rw-r--r--tiny_skia/src/engine.rs26
-rw-r--r--tiny_skia/src/layer.rs10
-rw-r--r--tiny_skia/src/lib.rs11
3 files changed, 21 insertions, 26 deletions
diff --git a/tiny_skia/src/engine.rs b/tiny_skia/src/engine.rs
index 564d3752..e9935bdb 100644
--- a/tiny_skia/src/engine.rs
+++ b/tiny_skia/src/engine.rs
@@ -551,7 +551,6 @@ impl Engine {
filter_method,
bounds,
rotation,
- scale,
} => {
let physical_bounds = *bounds * transformation;
@@ -563,11 +562,13 @@ impl Engine {
.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);
+ let radians = f32::from(*rotation);
+
+ let transform = into_transform(transformation).post_rotate_at(
+ radians.to_degrees(),
+ center.x,
+ center.y,
+ );
self.raster_pipeline.draw(
handle,
@@ -584,7 +585,6 @@ impl Engine {
color,
bounds,
rotation,
- scale,
} => {
let physical_bounds = *bounds * transformation;
@@ -596,11 +596,13 @@ impl Engine {
.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);
+ let radians = f32::from(*rotation);
+
+ let transform = into_transform(transformation).post_rotate_at(
+ radians.to_degrees(),
+ center.x,
+ center.y,
+ );
self.vector_pipeline.draw(
handle,
diff --git a/tiny_skia/src/layer.rs b/tiny_skia/src/layer.rs
index e9651814..c8a31ba3 100644
--- a/tiny_skia/src/layer.rs
+++ b/tiny_skia/src/layer.rs
@@ -1,5 +1,5 @@
use crate::core::{
- image, renderer::Quad, svg, Background, Color, Point, Rectangle, Size,
+ image, renderer::Quad, svg, Background, Color, Point, Radians, Rectangle,
Transformation,
};
use crate::graphics::damage;
@@ -121,15 +121,13 @@ impl Layer {
filter_method: image::FilterMethod,
bounds: Rectangle,
transformation: Transformation,
- rotation: f32,
- scale: Size,
+ rotation: Radians,
) {
let image = Image::Raster {
handle,
filter_method,
bounds: bounds * transformation,
rotation,
- scale,
};
self.images.push(image);
@@ -141,15 +139,13 @@ impl Layer {
color: Option<Color>,
bounds: Rectangle,
transformation: Transformation,
- rotation: f32,
- scale: Size,
+ rotation: Radians,
) {
let svg = Image::Vector {
handle,
color,
bounds: bounds * transformation,
rotation,
- scale,
};
self.images.push(svg);
diff --git a/tiny_skia/src/lib.rs b/tiny_skia/src/lib.rs
index 4e3ebad3..75aaaf92 100644
--- a/tiny_skia/src/lib.rs
+++ b/tiny_skia/src/lib.rs
@@ -29,7 +29,7 @@ pub use geometry::Geometry;
use crate::core::renderer;
use crate::core::{
- Background, Color, Font, Pixels, Point, Rectangle, Size, Transformation,
+ Background, Color, Font, Pixels, Point, Radians, Rectangle, Transformation,
};
use crate::engine::Engine;
use crate::graphics::compositor;
@@ -377,8 +377,7 @@ impl core::image::Renderer for Renderer {
handle: Self::Handle,
filter_method: core::image::FilterMethod,
bounds: Rectangle,
- rotation: f32,
- scale: Size,
+ rotation: Radians,
) {
let (layer, transformation) = self.layers.current_mut();
layer.draw_image(
@@ -387,7 +386,6 @@ impl core::image::Renderer for Renderer {
bounds,
transformation,
rotation,
- scale,
);
}
}
@@ -406,11 +404,10 @@ impl core::svg::Renderer for Renderer {
handle: core::svg::Handle,
color: Option<Color>,
bounds: Rectangle,
- rotation: f32,
- scale: Size,
+ rotation: Radians,
) {
let (layer, transformation) = self.layers.current_mut();
- layer.draw_svg(handle, color, bounds, transformation, rotation, scale);
+ layer.draw_svg(handle, color, bounds, transformation, rotation);
}
}