mirror of
https://github.com/penpot/penpot.git
synced 2025-05-29 15:56:12 +02:00
🎉 Render wasm fill images
This commit is contained in:
parent
c688ae2e33
commit
0a3c6f38ef
7 changed files with 237 additions and 38 deletions
|
@ -2,6 +2,7 @@ use skia_safe as skia;
|
|||
|
||||
use super::Color;
|
||||
use crate::math;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Gradient {
|
||||
|
@ -40,10 +41,19 @@ impl Gradient {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ImageFill {
|
||||
pub id: Uuid,
|
||||
pub alpha: u8,
|
||||
pub height: f32,
|
||||
pub width: f32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Fill {
|
||||
Solid(Color),
|
||||
LinearGradient(Gradient),
|
||||
Image(ImageFill),
|
||||
}
|
||||
|
||||
impl Fill {
|
||||
|
@ -57,6 +67,15 @@ impl Fill {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn new_image_fill(id: Uuid, alpha: u8, height: f32, width: f32) -> Self {
|
||||
Self::Image(ImageFill {
|
||||
id,
|
||||
alpha,
|
||||
height,
|
||||
width,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn to_paint(&self, rect: &math::Rect) -> skia::Paint {
|
||||
match self {
|
||||
Self::Solid(color) => {
|
||||
|
@ -75,6 +94,14 @@ impl Fill {
|
|||
p.set_blend_mode(skia::BlendMode::SrcOver);
|
||||
p
|
||||
}
|
||||
Self::Image(image_fill) => {
|
||||
let mut p = skia::Paint::default();
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue