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` --- wgpu/src/geometry.rs | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) (limited to 'wgpu/src/geometry.rs') diff --git a/wgpu/src/geometry.rs b/wgpu/src/geometry.rs index cb629b3e..6b1bb074 100644 --- a/wgpu/src/geometry.rs +++ b/wgpu/src/geometry.rs @@ -1,5 +1,4 @@ //! Build and draw geometry. -use crate::core::image; use crate::core::svg; use crate::core::text::LineHeight; use crate::core::{ @@ -9,11 +8,11 @@ use crate::graphics::cache::{self, Cached}; use crate::graphics::color; use crate::graphics::geometry::fill::{self, Fill}; use crate::graphics::geometry::{ - self, LineCap, LineDash, LineJoin, Path, Stroke, Style, + self, Image, LineCap, LineDash, LineJoin, Path, Stroke, Style, }; use crate::graphics::gradient::{self, Gradient}; use crate::graphics::mesh::{self, Mesh}; -use crate::graphics::{self, Image, Text}; +use crate::graphics::{self, Text}; use crate::text; use crate::triangle; @@ -27,7 +26,7 @@ use std::sync::Arc; pub enum Geometry { Live { meshes: Vec, - images: Vec, + images: Vec, text: Vec, }, Cached(Cache), @@ -36,7 +35,7 @@ pub enum Geometry { #[derive(Debug, Clone)] pub struct Cache { pub meshes: Option, - pub images: Option>, + pub images: Option>, pub text: Option, } @@ -99,7 +98,7 @@ pub struct Frame { clip_bounds: Rectangle, buffers: BufferStack, meshes: Vec, - images: Vec, + images: Vec, text: Vec, transforms: Transforms, fill_tessellator: tessellation::FillTessellator, @@ -377,25 +376,15 @@ impl geometry::frame::Backend for Frame { } } - fn draw_image( - &mut self, - handle: &image::Handle, - bounds: Rectangle, - filter_method: image::FilterMethod, - rotation: Radians, - opacity: f32, - ) { + fn draw_image(&mut self, bounds: Rectangle, image: impl Into) { + let mut image = image.into(); + let (bounds, external_rotation) = self.transforms.current.transform_rectangle(bounds); - self.images.push(Image::Raster { - handle: handle.clone(), - filter_method, - bounds, - rotation: rotation + external_rotation, - opacity, - snap: false, - }); + image.rotation += external_rotation; + + self.images.push(graphics::Image::Raster(image, bounds)); } fn draw_svg( @@ -409,7 +398,7 @@ impl geometry::frame::Backend for Frame { let (bounds, external_rotation) = self.transforms.current.transform_rectangle(bounds); - self.images.push(Image::Vector { + self.images.push(graphics::Image::Vector { handle: handle.clone(), color, bounds, -- cgit