♻️ Extract wasm-functions for fills and strokes out of main.rs

This commit is contained in:
Belén Albeza 2025-04-15 12:43:25 +02:00
parent 64a2a08d24
commit f500a00d04
4 changed files with 159 additions and 143 deletions

View file

@ -0,0 +1,60 @@
use skia_safe as skia;
use crate::mem;
use crate::shapes;
use crate::utils::uuid_from_u32_quartet;
use crate::with_current_shape;
use crate::STATE;
#[no_mangle]
pub extern "C" fn add_shape_solid_fill(raw_color: u32) {
with_current_shape!(state, |shape: &mut Shape| {
let color = skia::Color::new(raw_color);
shape.add_fill(shapes::Fill::Solid(color));
});
}
#[no_mangle]
pub extern "C" fn add_shape_linear_fill() {
with_current_shape!(state, |shape: &mut Shape| {
let bytes = mem::bytes();
let gradient = shapes::Gradient::try_from(&bytes[..]).expect("Invalid gradient data");
shape.add_fill(shapes::Fill::LinearGradient(gradient));
});
}
#[no_mangle]
pub extern "C" fn add_shape_radial_fill() {
with_current_shape!(state, |shape: &mut Shape| {
let bytes = mem::bytes();
let gradient = shapes::Gradient::try_from(&bytes[..]).expect("Invalid gradient data");
shape.add_fill(shapes::Fill::RadialGradient(gradient));
});
}
#[no_mangle]
pub extern "C" fn add_shape_image_fill(
a: u32,
b: u32,
c: u32,
d: u32,
alpha: f32,
width: i32,
height: i32,
) {
with_current_shape!(state, |shape: &mut Shape| {
let id = uuid_from_u32_quartet(a, b, c, d);
shape.add_fill(shapes::Fill::new_image_fill(
id,
(alpha * 0xff as f32).floor() as u8,
(width, height),
));
});
}
#[no_mangle]
pub extern "C" fn clear_shape_fills() {
with_current_shape!(state, |shape: &mut Shape| {
shape.clear_fills();
});
}