🎉 Render wasm fill images

This commit is contained in:
Alejandro Alonso 2024-11-25 17:30:24 +01:00
parent c688ae2e33
commit 0a3c6f38ef
7 changed files with 237 additions and 38 deletions

View file

@ -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
}
}
}
}