From 0ceee1cf3ae49f5bd0e3f2b346a4b34076e4523a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 4 Aug 2024 03:28:43 +0200 Subject: Implement image support for `canvas` widget --- tiny_skia/src/layer.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'tiny_skia/src/layer.rs') diff --git a/tiny_skia/src/layer.rs b/tiny_skia/src/layer.rs index 48fca1d8..9a169f46 100644 --- a/tiny_skia/src/layer.rs +++ b/tiny_skia/src/layer.rs @@ -116,6 +116,48 @@ impl Layer { } pub fn draw_image( + &mut self, + image: &Image, + transformation: Transformation, + ) { + match image { + Image::Raster { + handle, + filter_method, + bounds, + rotation, + opacity, + snap: _, + } => { + self.draw_raster( + handle.clone(), + *filter_method, + *bounds, + transformation, + *rotation, + *opacity, + ); + } + Image::Vector { + handle, + color, + bounds, + rotation, + opacity, + } => { + self.draw_svg( + handle.clone(), + *color, + *bounds, + transformation, + *rotation, + *opacity, + ); + } + } + } + + pub fn draw_raster( &mut self, handle: image::Handle, filter_method: image::FilterMethod, @@ -130,6 +172,7 @@ impl Layer { bounds: bounds * transformation, rotation, opacity, + snap: false, }; self.images.push(image); -- cgit From 92bd3ecd6b4a6618f0fc725dea3694c3b40e5314 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 4 Aug 2024 04:30:12 +0200 Subject: Introduce `Image` struct in `core::image` --- tiny_skia/src/layer.rs | 57 +++++++++++++++----------------------------------- 1 file changed, 17 insertions(+), 40 deletions(-) (limited to 'tiny_skia/src/layer.rs') diff --git a/tiny_skia/src/layer.rs b/tiny_skia/src/layer.rs index 9a169f46..33df0a86 100644 --- a/tiny_skia/src/layer.rs +++ b/tiny_skia/src/layer.rs @@ -1,11 +1,12 @@ +use crate::core::renderer::Quad; +use crate::core::svg; use crate::core::{ - image, renderer::Quad, svg, Background, Color, Point, Radians, Rectangle, - Transformation, + Background, Color, Image, Point, Radians, Rectangle, Transformation, }; +use crate::graphics; use crate::graphics::damage; use crate::graphics::layer; use crate::graphics::text::{Editor, Paragraph, Text}; -use crate::graphics::{self, Image}; use crate::Primitive; use std::rc::Rc; @@ -18,7 +19,7 @@ pub struct Layer { pub quads: Vec<(Quad, Background)>, pub primitives: Vec>, pub text: Vec>, - pub images: Vec, + pub images: Vec, } impl Layer { @@ -117,28 +118,14 @@ impl Layer { pub fn draw_image( &mut self, - image: &Image, + image: graphics::Image, transformation: Transformation, ) { match image { - Image::Raster { - handle, - filter_method, - bounds, - rotation, - opacity, - snap: _, - } => { - self.draw_raster( - handle.clone(), - *filter_method, - *bounds, - transformation, - *rotation, - *opacity, - ); + graphics::Image::Raster(raster, bounds) => { + self.draw_raster(raster.clone(), bounds, transformation); } - Image::Vector { + graphics::Image::Vector { handle, color, bounds, @@ -147,11 +134,11 @@ impl Layer { } => { self.draw_svg( handle.clone(), - *color, - *bounds, + color, + bounds, transformation, - *rotation, - *opacity, + rotation, + opacity, ); } } @@ -159,21 +146,11 @@ impl Layer { pub fn draw_raster( &mut self, - handle: image::Handle, - filter_method: image::FilterMethod, + image: Image, bounds: Rectangle, transformation: Transformation, - rotation: Radians, - opacity: f32, ) { - let image = Image::Raster { - handle, - filter_method, - bounds: bounds * transformation, - rotation, - opacity, - snap: false, - }; + let image = graphics::Image::Raster(image, bounds * transformation); self.images.push(image); } @@ -187,7 +164,7 @@ impl Layer { rotation: Radians, opacity: f32, ) { - let svg = Image::Vector { + let svg = graphics::Image::Vector { handle, color, bounds: bounds * transformation, @@ -304,7 +281,7 @@ impl Layer { &previous.images, ¤t.images, |image| vec![image.bounds().expand(1.0)], - Image::eq, + graphics::Image::eq, ); damage.extend(text); -- cgit From 8708101c892540ffc966cf7ee9d66ca5cd2e8ca6 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 4 Aug 2024 04:33:30 +0200 Subject: Simplify types in `tiny_skia::layer` --- tiny_skia/src/layer.rs | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'tiny_skia/src/layer.rs') diff --git a/tiny_skia/src/layer.rs b/tiny_skia/src/layer.rs index 33df0a86..5d3cb07b 100644 --- a/tiny_skia/src/layer.rs +++ b/tiny_skia/src/layer.rs @@ -1,12 +1,12 @@ use crate::core::renderer::Quad; use crate::core::svg; use crate::core::{ - Background, Color, Image, Point, Radians, Rectangle, Transformation, + self, Background, Color, Point, Radians, Rectangle, Transformation, }; -use crate::graphics; use crate::graphics::damage; use crate::graphics::layer; use crate::graphics::text::{Editor, Paragraph, Text}; +use crate::graphics::{self, Image}; use crate::Primitive; use std::rc::Rc; @@ -19,7 +19,7 @@ pub struct Layer { pub quads: Vec<(Quad, Background)>, pub primitives: Vec>, pub text: Vec>, - pub images: Vec, + pub images: Vec, } impl Layer { @@ -73,7 +73,7 @@ impl Layer { pub fn draw_text( &mut self, - text: crate::core::Text, + text: core::Text, position: Point, color: Color, clip_bounds: Rectangle, @@ -116,16 +116,12 @@ impl Layer { .push(Item::Cached(text, clip_bounds, transformation)); } - pub fn draw_image( - &mut self, - image: graphics::Image, - transformation: Transformation, - ) { + pub fn draw_image(&mut self, image: Image, transformation: Transformation) { match image { - graphics::Image::Raster(raster, bounds) => { + Image::Raster(raster, bounds) => { self.draw_raster(raster.clone(), bounds, transformation); } - graphics::Image::Vector { + Image::Vector { handle, color, bounds, @@ -146,11 +142,11 @@ impl Layer { pub fn draw_raster( &mut self, - image: Image, + image: core::Image, bounds: Rectangle, transformation: Transformation, ) { - let image = graphics::Image::Raster(image, bounds * transformation); + let image = Image::Raster(image, bounds * transformation); self.images.push(image); } @@ -164,7 +160,7 @@ impl Layer { rotation: Radians, opacity: f32, ) { - let svg = graphics::Image::Vector { + let svg = Image::Vector { handle, color, bounds: bounds * transformation, @@ -281,7 +277,7 @@ impl Layer { &previous.images, ¤t.images, |image| vec![image.bounds().expand(1.0)], - graphics::Image::eq, + Image::eq, ); damage.extend(text); @@ -313,7 +309,7 @@ impl graphics::Layer for Layer { fn flush(&mut self) {} - fn resize(&mut self, bounds: graphics::core::Rectangle) { + fn resize(&mut self, bounds: Rectangle) { self.bounds = bounds; } -- cgit From d4b08462e5a25929ec4df32f242898986902af56 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 4 Aug 2024 04:52:55 +0200 Subject: Introduce `Svg` struct in `core::svg` --- tiny_skia/src/layer.rs | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) (limited to 'tiny_skia/src/layer.rs') diff --git a/tiny_skia/src/layer.rs b/tiny_skia/src/layer.rs index 5d3cb07b..bdfd4d38 100644 --- a/tiny_skia/src/layer.rs +++ b/tiny_skia/src/layer.rs @@ -1,7 +1,6 @@ use crate::core::renderer::Quad; -use crate::core::svg; use crate::core::{ - self, Background, Color, Point, Radians, Rectangle, Transformation, + self, Background, Color, Point, Rectangle, Svg, Transformation, }; use crate::graphics::damage; use crate::graphics::layer; @@ -119,23 +118,10 @@ impl Layer { pub fn draw_image(&mut self, image: Image, transformation: Transformation) { match image { Image::Raster(raster, bounds) => { - self.draw_raster(raster.clone(), bounds, transformation); + self.draw_raster(raster, bounds, transformation); } - Image::Vector { - handle, - color, - bounds, - rotation, - opacity, - } => { - self.draw_svg( - handle.clone(), - color, - bounds, - transformation, - rotation, - opacity, - ); + Image::Vector(svg, bounds) => { + self.draw_svg(svg, bounds, transformation); } } } @@ -153,20 +139,11 @@ impl Layer { pub fn draw_svg( &mut self, - handle: svg::Handle, - color: Option, + svg: Svg, bounds: Rectangle, transformation: Transformation, - rotation: Radians, - opacity: f32, ) { - let svg = Image::Vector { - handle, - color, - bounds: bounds * transformation, - rotation, - opacity, - }; + let svg = Image::Vector(svg, bounds * transformation); self.images.push(svg); } -- cgit