mirror of
https://github.com/penpot/penpot.git
synced 2025-07-01 15:57:18 +02:00
♻️ Refactor image fills
This commit is contained in:
parent
7105e49ac2
commit
58c4e53ee4
4 changed files with 44 additions and 28 deletions
|
@ -60,10 +60,20 @@ impl Gradient {
|
|||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ImageFill {
|
||||
pub id: Uuid,
|
||||
pub alpha: u8,
|
||||
pub height: f32,
|
||||
pub width: f32,
|
||||
id: Uuid,
|
||||
opacity: u8,
|
||||
height: i32,
|
||||
width: i32,
|
||||
}
|
||||
|
||||
impl ImageFill {
|
||||
pub fn size(&self) -> (i32, i32) {
|
||||
(self.width, self.height)
|
||||
}
|
||||
|
||||
pub fn id(&self) -> Uuid {
|
||||
self.id
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
@ -84,10 +94,10 @@ impl Fill {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn new_image_fill(id: Uuid, alpha: u8, height: f32, width: f32) -> Self {
|
||||
pub fn new_image_fill(id: Uuid, opacity: u8, (width, height): (i32, i32)) -> Self {
|
||||
Self::Image(ImageFill {
|
||||
id,
|
||||
alpha,
|
||||
opacity,
|
||||
height,
|
||||
width,
|
||||
})
|
||||
|
@ -116,7 +126,7 @@ impl Fill {
|
|||
p.set_style(skia::PaintStyle::Fill);
|
||||
p.set_anti_alias(true);
|
||||
p.set_blend_mode(skia::BlendMode::SrcOver);
|
||||
p.set_alpha(image_fill.alpha);
|
||||
p.set_alpha(image_fill.opacity);
|
||||
p
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,12 +6,12 @@ pub type Image = skia::Image;
|
|||
pub fn draw_image_in_container(
|
||||
canvas: &skia::Canvas,
|
||||
image: &Image,
|
||||
size: (f32, f32),
|
||||
size: (i32, i32),
|
||||
container: skia::Rect,
|
||||
paint: &skia::Paint,
|
||||
) {
|
||||
let width = size.0;
|
||||
let height = size.1;
|
||||
let width = size.0 as f32;
|
||||
let height = size.1 as f32;
|
||||
let image_aspect_ratio = width / height;
|
||||
|
||||
// Container size
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue