Introduce Image struct in core::image
This commit is contained in:
parent
974ae6d1e7
commit
92bd3ecd6b
19 changed files with 184 additions and 334 deletions
|
|
@ -16,6 +16,7 @@ pub use stroke::{LineCap, LineDash, LineJoin, Stroke};
|
|||
pub use style::Style;
|
||||
pub use text::Text;
|
||||
|
||||
pub use crate::core::Image;
|
||||
pub use crate::gradient::{self, Gradient};
|
||||
|
||||
use crate::cache::Cached;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
//! Draw and generate geometry.
|
||||
use crate::core::image;
|
||||
use crate::core::svg;
|
||||
use crate::core::{Color, Point, Radians, Rectangle, Size, Vector};
|
||||
use crate::geometry::{self, Fill, Path, Stroke, Text};
|
||||
use crate::geometry::{self, Fill, Image, Path, Stroke, Text};
|
||||
|
||||
/// The region of a surface that can be used to draw geometry.
|
||||
#[allow(missing_debug_implementations)]
|
||||
|
|
@ -79,21 +78,8 @@ where
|
|||
|
||||
/// Draws the given image on the [`Frame`] inside the given bounds.
|
||||
#[cfg(feature = "image")]
|
||||
pub fn draw_image(
|
||||
&mut self,
|
||||
handle: &image::Handle,
|
||||
bounds: Rectangle,
|
||||
filter_method: image::FilterMethod,
|
||||
rotation: impl Into<Radians>,
|
||||
opacity: f32,
|
||||
) {
|
||||
self.raw.draw_image(
|
||||
handle,
|
||||
bounds,
|
||||
filter_method,
|
||||
rotation.into(),
|
||||
opacity,
|
||||
);
|
||||
pub fn draw_image(&mut self, bounds: Rectangle, image: impl Into<Image>) {
|
||||
self.raw.draw_image(bounds, image);
|
||||
}
|
||||
|
||||
/// Stores the current transform of the [`Frame`] and executes the given
|
||||
|
|
@ -219,14 +205,7 @@ pub trait Backend: Sized {
|
|||
fill: impl Into<Fill>,
|
||||
);
|
||||
|
||||
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>);
|
||||
|
||||
fn draw_svg(
|
||||
&mut self,
|
||||
|
|
@ -285,15 +264,7 @@ impl Backend for () {
|
|||
|
||||
fn into_geometry(self) -> Self::Geometry {}
|
||||
|
||||
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>) {}
|
||||
|
||||
fn draw_svg(
|
||||
&mut self,
|
||||
|
|
|
|||
|
|
@ -8,28 +8,8 @@ use crate::core::{image, svg, Color, Radians, Rectangle};
|
|||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Image {
|
||||
/// A raster image.
|
||||
Raster {
|
||||
/// The handle of a raster image.
|
||||
handle: image::Handle,
|
||||
Raster(image::Image, Rectangle),
|
||||
|
||||
/// The filter method of a raster image.
|
||||
filter_method: image::FilterMethod,
|
||||
|
||||
/// The bounds of the image.
|
||||
bounds: Rectangle,
|
||||
|
||||
/// The rotation of the image.
|
||||
rotation: Radians,
|
||||
|
||||
/// The opacity of the image.
|
||||
opacity: f32,
|
||||
|
||||
/// If set to `true`, the image will be snapped to the pixel grid.
|
||||
///
|
||||
/// This can avoid graphical glitches, specially when using a
|
||||
/// [`image::FilterMethod::Nearest`].
|
||||
snap: bool,
|
||||
},
|
||||
/// A vector image.
|
||||
Vector {
|
||||
/// The handle of a vector image.
|
||||
|
|
@ -53,10 +33,8 @@ impl Image {
|
|||
/// Returns the bounds of the [`Image`].
|
||||
pub fn bounds(&self) -> Rectangle {
|
||||
match self {
|
||||
Image::Raster {
|
||||
bounds, rotation, ..
|
||||
}
|
||||
| Image::Vector {
|
||||
Image::Raster(image, bounds) => bounds.rotate(image.rotation),
|
||||
Image::Vector {
|
||||
bounds, rotation, ..
|
||||
} => bounds.rotate(*rotation),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue