Introduce Image struct in core::image
This commit is contained in:
parent
974ae6d1e7
commit
92bd3ecd6b
19 changed files with 184 additions and 334 deletions
|
|
@ -550,14 +550,7 @@ impl Engine {
|
|||
) {
|
||||
match image {
|
||||
#[cfg(feature = "image")]
|
||||
Image::Raster {
|
||||
handle,
|
||||
filter_method,
|
||||
bounds,
|
||||
rotation,
|
||||
opacity,
|
||||
snap: _,
|
||||
} => {
|
||||
Image::Raster(raster, bounds) => {
|
||||
let physical_bounds = *bounds * _transformation;
|
||||
|
||||
if !_clip_bounds.intersects(&physical_bounds) {
|
||||
|
|
@ -568,7 +561,7 @@ impl Engine {
|
|||
.then_some(_clip_mask as &_);
|
||||
|
||||
let center = physical_bounds.center();
|
||||
let radians = f32::from(*rotation);
|
||||
let radians = f32::from(raster.rotation);
|
||||
|
||||
let transform = into_transform(_transformation).post_rotate_at(
|
||||
radians.to_degrees(),
|
||||
|
|
@ -577,10 +570,10 @@ impl Engine {
|
|||
);
|
||||
|
||||
self.raster_pipeline.draw(
|
||||
handle,
|
||||
*filter_method,
|
||||
&raster.handle,
|
||||
raster.filter_method,
|
||||
*bounds,
|
||||
*opacity,
|
||||
raster.opacity,
|
||||
_pixels,
|
||||
transform,
|
||||
clip_mask,
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
use crate::core::image;
|
||||
use crate::core::svg;
|
||||
use crate::core::text::LineHeight;
|
||||
use crate::core::{Color, Pixels, Point, Radians, Rectangle, Size, Vector};
|
||||
use crate::graphics::cache::{self, Cached};
|
||||
use crate::graphics::geometry::fill::{self, Fill};
|
||||
use crate::graphics::geometry::stroke::{self, Stroke};
|
||||
use crate::graphics::geometry::{self, Path, Style};
|
||||
use crate::graphics::{Gradient, Image, Text};
|
||||
use crate::graphics::geometry::{self, Image, Path, Style};
|
||||
use crate::graphics::{self, Gradient, Text};
|
||||
use crate::Primitive;
|
||||
|
||||
use std::rc::Rc;
|
||||
|
|
@ -15,7 +14,7 @@ use std::rc::Rc;
|
|||
pub enum Geometry {
|
||||
Live {
|
||||
text: Vec<Text>,
|
||||
images: Vec<Image>,
|
||||
images: Vec<graphics::Image>,
|
||||
primitives: Vec<Primitive>,
|
||||
clip_bounds: Rectangle,
|
||||
},
|
||||
|
|
@ -25,7 +24,7 @@ pub enum Geometry {
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct Cache {
|
||||
pub text: Rc<[Text]>,
|
||||
pub images: Rc<[Image]>,
|
||||
pub images: Rc<[graphics::Image]>,
|
||||
pub primitives: Rc<[Primitive]>,
|
||||
pub clip_bounds: Rectangle,
|
||||
}
|
||||
|
|
@ -61,7 +60,7 @@ pub struct Frame {
|
|||
transform: tiny_skia::Transform,
|
||||
stack: Vec<tiny_skia::Transform>,
|
||||
primitives: Vec<Primitive>,
|
||||
images: Vec<Image>,
|
||||
images: Vec<graphics::Image>,
|
||||
text: Vec<Text>,
|
||||
}
|
||||
|
||||
|
|
@ -283,25 +282,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<Image>) {
|
||||
let mut image = image.into();
|
||||
|
||||
let (bounds, external_rotation) =
|
||||
transform_rectangle(bounds, self.transform);
|
||||
|
||||
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(
|
||||
|
|
@ -315,7 +304,7 @@ impl geometry::frame::Backend for Frame {
|
|||
let (bounds, external_rotation) =
|
||||
transform_rectangle(bounds, self.transform);
|
||||
|
||||
self.images.push(Image::Vector {
|
||||
self.images.push(graphics::Image::Vector {
|
||||
handle: handle.clone(),
|
||||
bounds,
|
||||
color,
|
||||
|
|
|
|||
|
|
@ -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<Item<Primitive>>,
|
||||
pub text: Vec<Item<Text>>,
|
||||
pub images: Vec<Image>,
|
||||
pub images: Vec<graphics::Image>,
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -341,7 +341,7 @@ impl graphics::geometry::Renderer for Renderer {
|
|||
);
|
||||
|
||||
for image in images {
|
||||
layer.draw_image(&image, transformation);
|
||||
layer.draw_image(image, transformation);
|
||||
}
|
||||
|
||||
layer.draw_text_group(text, clip_bounds, transformation);
|
||||
|
|
@ -354,7 +354,7 @@ impl graphics::geometry::Renderer for Renderer {
|
|||
);
|
||||
|
||||
for image in cache.images.iter() {
|
||||
layer.draw_image(image, transformation);
|
||||
layer.draw_image(image.clone(), transformation);
|
||||
}
|
||||
|
||||
layer.draw_text_cache(
|
||||
|
|
@ -381,23 +381,9 @@ impl core::image::Renderer for Renderer {
|
|||
self.engine.raster_pipeline.dimensions(handle)
|
||||
}
|
||||
|
||||
fn draw_image(
|
||||
&mut self,
|
||||
handle: Self::Handle,
|
||||
filter_method: core::image::FilterMethod,
|
||||
bounds: Rectangle,
|
||||
rotation: core::Radians,
|
||||
opacity: f32,
|
||||
) {
|
||||
fn draw_image(&mut self, image: core::Image, bounds: Rectangle) {
|
||||
let (layer, transformation) = self.layers.current_mut();
|
||||
layer.draw_raster(
|
||||
handle,
|
||||
filter_method,
|
||||
bounds,
|
||||
transformation,
|
||||
rotation,
|
||||
opacity,
|
||||
);
|
||||
layer.draw_raster(image, bounds, transformation);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue