mirror of
https://github.com/penpot/penpot.git
synced 2025-05-13 22:56:37 +02:00
🎉 Implement boolean operations (wasm)
This commit is contained in:
parent
1514faca55
commit
4e5f67676c
8 changed files with 126 additions and 16 deletions
25
render-wasm/src/shapes/bools.rs
Normal file
25
render-wasm/src/shapes/bools.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum BoolType {
|
||||
Union,
|
||||
Difference,
|
||||
Intersection,
|
||||
Exclusion,
|
||||
}
|
||||
|
||||
impl From<u8> for BoolType {
|
||||
fn from(value: u8) -> Self {
|
||||
match value {
|
||||
0 => Self::Union,
|
||||
1 => Self::Difference,
|
||||
2 => Self::Intersection,
|
||||
3 => Self::Exclusion,
|
||||
_ => Self::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for BoolType {
|
||||
fn default() -> Self {
|
||||
Self::Union
|
||||
}
|
||||
}
|
|
@ -88,6 +88,12 @@ fn starts_and_ends_at_same_point(path: &skia::Path) -> bool {
|
|||
start_point == end_point
|
||||
}
|
||||
|
||||
impl Default for Path {
|
||||
fn default() -> Self {
|
||||
Path::try_from(Vec::new()).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Vec<RawPathData>> for Path {
|
||||
type Error = String;
|
||||
|
||||
|
|
|
@ -64,7 +64,11 @@ impl Renderable for Shape {
|
|||
}
|
||||
|
||||
fn children_ids(&self) -> Vec<Uuid> {
|
||||
self.children.clone()
|
||||
if let Kind::Bool(_, _) = self.kind {
|
||||
vec![]
|
||||
} else {
|
||||
self.children.clone()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,7 +101,7 @@ fn render_fill(
|
|||
(_, Kind::Circle(rect)) => {
|
||||
surface.canvas().draw_oval(rect, &fill.to_paint(&selrect));
|
||||
}
|
||||
(_, Kind::Path(path)) => {
|
||||
(_, Kind::Path(path)) | (_, Kind::Bool(_, path)) => {
|
||||
surface.canvas().draw_path(
|
||||
&path.to_skia_path().transform(path_transform.unwrap()),
|
||||
&fill.to_paint(&selrect),
|
||||
|
@ -130,7 +134,7 @@ fn render_stroke(
|
|||
match kind {
|
||||
Kind::Rect(rect) => draw_stroke_on_rect(surface.canvas(), stroke, rect, &selrect),
|
||||
Kind::Circle(rect) => draw_stroke_on_circle(surface.canvas(), stroke, rect, &selrect),
|
||||
Kind::Path(path) => {
|
||||
Kind::Path(path) | Kind::Bool(_, path) => {
|
||||
draw_stroke_on_path(surface.canvas(), stroke, path, &selrect, path_transform);
|
||||
}
|
||||
}
|
||||
|
@ -439,7 +443,7 @@ pub fn draw_image_fill_in_container(
|
|||
oval_path.add_oval(container, None);
|
||||
canvas.clip_path(&oval_path, skia::ClipOp::Intersect, true);
|
||||
}
|
||||
Kind::Path(p) => {
|
||||
Kind::Path(p) | Kind::Bool(_, p) => {
|
||||
canvas.clip_path(
|
||||
&p.to_skia_path().transform(path_transform.unwrap()),
|
||||
skia::ClipOp::Intersect,
|
||||
|
@ -476,7 +480,7 @@ pub fn draw_image_stroke_in_container(
|
|||
match kind {
|
||||
Kind::Rect(rect) => draw_stroke_on_rect(canvas, stroke, rect, &outer_rect),
|
||||
Kind::Circle(rect) => draw_stroke_on_circle(canvas, stroke, rect, &outer_rect),
|
||||
Kind::Path(p) => {
|
||||
Kind::Path(p) | Kind::Bool(_, p) => {
|
||||
let mut path = p.to_skia_path();
|
||||
path.transform(path_transform.unwrap());
|
||||
let stroke_kind = stroke.render_kind(p.is_open());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue