mirror of
https://github.com/penpot/penpot.git
synced 2025-06-04 01:41:39 +02:00
🎉 Serialize radial fills in one go
This commit is contained in:
parent
5765d1c56c
commit
dc3d802d3d
4 changed files with 65 additions and 33 deletions
|
@ -282,20 +282,26 @@ pub extern "C" fn add_shape_linear_fill() {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn add_shape_radial_fill(
|
||||
start_x: f32,
|
||||
start_y: f32,
|
||||
end_x: f32,
|
||||
end_y: f32,
|
||||
opacity: f32,
|
||||
width: f32,
|
||||
) {
|
||||
pub extern "C" fn add_shape_radial_fill() {
|
||||
with_current_shape!(state, |shape: &mut Shape| {
|
||||
shape.add_fill(shapes::Fill::new_radial_gradient(
|
||||
(start_x, start_y),
|
||||
(end_x, end_y),
|
||||
opacity,
|
||||
width,
|
||||
let bytes = mem::bytes();
|
||||
let raw_gradient_bytes: [u8; RAW_FILL_DATA_SIZE] =
|
||||
bytes[0..RAW_FILL_DATA_SIZE].try_into().unwrap();
|
||||
let raw_gradient = shapes::RawGradientData::from(raw_gradient_bytes);
|
||||
let stops: Vec<shapes::RawStopData> = bytes[RAW_FILL_DATA_SIZE..]
|
||||
.chunks(RAW_STOP_DATA_SIZE)
|
||||
.map(|chunk| {
|
||||
let data: [u8; RAW_STOP_DATA_SIZE] = chunk.try_into().unwrap();
|
||||
shapes::RawStopData::from(data)
|
||||
})
|
||||
.collect();
|
||||
|
||||
shape.add_fill(shapes::Fill::new_radial_gradient_with_stops(
|
||||
raw_gradient.start(),
|
||||
raw_gradient.end(),
|
||||
raw_gradient.opacity(),
|
||||
raw_gradient.width(),
|
||||
stops,
|
||||
));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -41,6 +41,10 @@ impl RawGradientData {
|
|||
pub fn opacity(&self) -> f32 {
|
||||
self.opacity
|
||||
}
|
||||
|
||||
pub fn width(&self) -> f32 {
|
||||
self.width
|
||||
}
|
||||
}
|
||||
|
||||
pub const RAW_STOP_DATA_SIZE: usize = 8;
|
||||
|
@ -199,14 +203,30 @@ impl Fill {
|
|||
opacity: f32,
|
||||
width: f32,
|
||||
) -> Self {
|
||||
Self::RadialGradient(Gradient {
|
||||
Self::new_radial_gradient_with_stops(start, end, opacity, width, vec![])
|
||||
}
|
||||
|
||||
pub fn new_radial_gradient_with_stops(
|
||||
start: (f32, f32),
|
||||
end: (f32, f32),
|
||||
opacity: f32,
|
||||
width: f32,
|
||||
stops: Vec<RawStopData>,
|
||||
) -> Self {
|
||||
let mut gradient = Gradient {
|
||||
start,
|
||||
end,
|
||||
opacity,
|
||||
colors: vec![],
|
||||
offsets: vec![],
|
||||
width,
|
||||
})
|
||||
};
|
||||
|
||||
for stop in stops {
|
||||
gradient.add_stop(stop.color(), stop.offset());
|
||||
}
|
||||
|
||||
Self::RadialGradient(gradient)
|
||||
}
|
||||
|
||||
pub fn new_image_fill(id: Uuid, opacity: u8, (width, height): (i32, i32)) -> Self {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue