summaryrefslogtreecommitdiffstats
path: root/tiny_skia
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-05-03 13:25:58 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-05-03 13:25:58 +0200
commitfa9e1d96ea1924b51749b775ea0e67e69bc8a305 (patch)
tree20cb13d6e3074569a15a16c8b0d261b1875a2045 /tiny_skia
parent38cf87cb45484c7e52ddf775fb3abd7edbecc652 (diff)
downloadiced-fa9e1d96ea1924b51749b775ea0e67e69bc8a305.tar.gz
iced-fa9e1d96ea1924b51749b775ea0e67e69bc8a305.tar.bz2
iced-fa9e1d96ea1924b51749b775ea0e67e69bc8a305.zip
Introduce dynamic `opacity` support for `Image` and `Svg`
Diffstat (limited to 'tiny_skia')
-rw-r--r--tiny_skia/src/engine.rs4
-rw-r--r--tiny_skia/src/layer.rs4
-rw-r--r--tiny_skia/src/lib.rs12
-rw-r--r--tiny_skia/src/raster.rs2
-rw-r--r--tiny_skia/src/vector.rs6
5 files changed, 26 insertions, 2 deletions
diff --git a/tiny_skia/src/engine.rs b/tiny_skia/src/engine.rs
index 544ff614..028b304f 100644
--- a/tiny_skia/src/engine.rs
+++ b/tiny_skia/src/engine.rs
@@ -551,6 +551,7 @@ impl Engine {
filter_method,
bounds,
rotation,
+ opacity,
} => {
let physical_bounds = *bounds * _transformation;
@@ -574,6 +575,7 @@ impl Engine {
handle,
*filter_method,
*bounds,
+ *opacity,
_pixels,
transform,
clip_mask,
@@ -585,6 +587,7 @@ impl Engine {
color,
bounds,
rotation,
+ opacity,
} => {
let physical_bounds = *bounds * _transformation;
@@ -608,6 +611,7 @@ impl Engine {
handle,
*color,
physical_bounds,
+ *opacity,
_pixels,
transform,
clip_mask,
diff --git a/tiny_skia/src/layer.rs b/tiny_skia/src/layer.rs
index c907c93c..48fca1d8 100644
--- a/tiny_skia/src/layer.rs
+++ b/tiny_skia/src/layer.rs
@@ -122,12 +122,14 @@ impl Layer {
bounds: Rectangle,
transformation: Transformation,
rotation: Radians,
+ opacity: f32,
) {
let image = Image::Raster {
handle,
filter_method,
bounds: bounds * transformation,
rotation,
+ opacity,
};
self.images.push(image);
@@ -140,12 +142,14 @@ impl Layer {
bounds: Rectangle,
transformation: Transformation,
rotation: Radians,
+ opacity: f32,
) {
let svg = Image::Vector {
handle,
color,
bounds: bounds * transformation,
rotation,
+ opacity,
};
self.images.push(svg);
diff --git a/tiny_skia/src/lib.rs b/tiny_skia/src/lib.rs
index e0cbfa0d..1aabff00 100644
--- a/tiny_skia/src/lib.rs
+++ b/tiny_skia/src/lib.rs
@@ -378,6 +378,7 @@ impl core::image::Renderer for Renderer {
filter_method: core::image::FilterMethod,
bounds: Rectangle,
rotation: core::Radians,
+ opacity: f32,
) {
let (layer, transformation) = self.layers.current_mut();
layer.draw_image(
@@ -386,6 +387,7 @@ impl core::image::Renderer for Renderer {
bounds,
transformation,
rotation,
+ opacity,
);
}
}
@@ -405,9 +407,17 @@ impl core::svg::Renderer for Renderer {
color: Option<Color>,
bounds: Rectangle,
rotation: core::Radians,
+ opacity: f32,
) {
let (layer, transformation) = self.layers.current_mut();
- layer.draw_svg(handle, color, bounds, transformation, rotation);
+ layer.draw_svg(
+ handle,
+ color,
+ bounds,
+ transformation,
+ rotation,
+ opacity,
+ );
}
}
diff --git a/tiny_skia/src/raster.rs b/tiny_skia/src/raster.rs
index 907fce7c..c40f55b2 100644
--- a/tiny_skia/src/raster.rs
+++ b/tiny_skia/src/raster.rs
@@ -31,6 +31,7 @@ impl Pipeline {
handle: &raster::Handle,
filter_method: raster::FilterMethod,
bounds: Rectangle,
+ opacity: f32,
pixels: &mut tiny_skia::PixmapMut<'_>,
transform: tiny_skia::Transform,
clip_mask: Option<&tiny_skia::Mask>,
@@ -56,6 +57,7 @@ impl Pipeline {
image,
&tiny_skia::PixmapPaint {
quality,
+ opacity,
..Default::default()
},
transform,
diff --git a/tiny_skia/src/vector.rs b/tiny_skia/src/vector.rs
index 8e3463f2..bbe08cb8 100644
--- a/tiny_skia/src/vector.rs
+++ b/tiny_skia/src/vector.rs
@@ -34,6 +34,7 @@ impl Pipeline {
handle: &Handle,
color: Option<Color>,
bounds: Rectangle,
+ opacity: f32,
pixels: &mut tiny_skia::PixmapMut<'_>,
transform: Transform,
clip_mask: Option<&tiny_skia::Mask>,
@@ -47,7 +48,10 @@ impl Pipeline {
bounds.x as i32,
bounds.y as i32,
image,
- &tiny_skia::PixmapPaint::default(),
+ &tiny_skia::PixmapPaint {
+ opacity,
+ ..tiny_skia::PixmapPaint::default()
+ },
transform,
clip_mask,
);