From c1d213a0cd1a04c8b462361d6b967d27091b1954 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Wed, 13 Nov 2024 11:48:29 +0100 Subject: [PATCH] :tada: Refactor naming anidated shapes with children for wasm render --- common/src/app/common/types/shape/impl.cljc | 4 ++-- frontend/src/app/render_wasm.cljs | 10 +++++----- render-wasm/src/main.rs | 8 ++++---- render-wasm/src/render.rs | 2 +- render-wasm/src/shapes.rs | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/common/src/app/common/types/shape/impl.cljc b/common/src/app/common/types/shape/impl.cljc index ed798d1d5..a6ac5555f 100644 --- a/common/src/app/common/types/shape/impl.cljc +++ b/common/src/app/common/types/shape/impl.cljc @@ -20,7 +20,7 @@ (defonce wasm-set-shape-transform (constantly nil)) (defonce wasm-set-shape-rotation (constantly nil)) (defonce wasm-set-shape-fills (constantly nil)) -(defonce wasm-set-shapes (constantly nil)) +(defonce wasm-set-shape-children (constantly nil)) (cr/defrecord Shape [id name type x y width height rotation selrect points transform transform-inverse parent-id frame-id flip-x flip-y]) @@ -118,8 +118,8 @@ :selrect (wasm-set-shape-selrect v) :rotation (wasm-set-shape-rotation v) :transform (wasm-set-shape-transform v) - :shapes (wasm-set-shapes v) :fills (wasm-set-shape-fills v) + :shapes (wasm-set-shape-children v) nil)) (let [delegate (.-delegate ^ShapeProxy coll) delegate' (assoc delegate k v)] diff --git a/frontend/src/app/render_wasm.cljs b/frontend/src/app/render_wasm.cljs index 27231af09..3c662b50c 100644 --- a/frontend/src/app/render_wasm.cljs +++ b/frontend/src/app/render_wasm.cljs @@ -59,12 +59,12 @@ [rotation] (._set_shape_rotation ^js internal-module rotation)) -(defn set-shapes +(defn set-shape-children [shape_ids] - (._clear_child_shapes ^js internal-module) + (._clear_shape_children ^js internal-module) (doseq [id shape_ids] (let [buffer (uuid/uuid->u32 id)] - (._add_child_shape ^js internal-module (aget buffer 0) (aget buffer 1) (aget buffer 2) (aget buffer 3))))) + (._add_shape_child ^js internal-module (aget buffer 0) (aget buffer 1) (aget buffer 2) (aget buffer 3))))) (defn set-shape-fills [fills] @@ -92,7 +92,7 @@ (set-shape-rotation rotation) (set-shape-transform transform) (set-shape-fills fills) - (set-shapes children) + (set-shape-children children) (recur (inc index))))))) (defn draw-objects @@ -155,4 +155,4 @@ (set! app.common.types.shape.impl/wasm-set-shape-transform set-shape-transform) (set! app.common.types.shape.impl/wasm-set-shape-rotation set-shape-rotation) (set! app.common.types.shape.impl/wasm-set-shape-fills set-shape-fills) -(set! app.common.types.shape.impl/wasm-set-shapes set-shapes) +(set! app.common.types.shape.impl/wasm-set-shape-children set-shape-children) diff --git a/render-wasm/src/main.rs b/render-wasm/src/main.rs index 2d6271aa4..cf4907a00 100644 --- a/render-wasm/src/main.rs +++ b/render-wasm/src/main.rs @@ -130,19 +130,19 @@ pub unsafe extern "C" fn set_shape_transform(a: f32, b: f32, c: f32, d: f32, e: } #[no_mangle] -pub extern "C" fn add_child_shape(a: u32, b: u32, c: u32, d: u32) { +pub extern "C" fn add_shape_child(a: u32, b: u32, c: u32, d: u32) { let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer"); let id = uuid_from_u32_quartet(a, b, c, d); if let Some(shape) = state.current_shape.as_deref_mut() { - shape.shapes.push(id); + shape.children.push(id); } } #[no_mangle] -pub extern "C" fn clear_child_shapes() { +pub extern "C" fn clear_shape_children() { let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer"); if let Some(shape) = state.current_shape.as_deref_mut() { - shape.shapes.clear(); + shape.children.clear(); } } diff --git a/render-wasm/src/render.rs b/render-wasm/src/render.rs index db98861c2..473272bca 100644 --- a/render-wasm/src/render.rs +++ b/render-wasm/src/render.rs @@ -84,7 +84,7 @@ pub(crate) fn render_shape_tree(state: &mut State, id: Uuid) { render_single_shape(&mut state.render_state.surface, shape); // draw all the children shapes - let shape_ids = shape.shapes.clone(); + let shape_ids = shape.children.clone(); for shape_id in shape_ids { render_shape_tree(state, shape_id); } diff --git a/render-wasm/src/shapes.rs b/render-wasm/src/shapes.rs index 0e6f49e19..eb44322ce 100644 --- a/render-wasm/src/shapes.rs +++ b/render-wasm/src/shapes.rs @@ -73,7 +73,7 @@ impl Fill { p.set_style(skia::PaintStyle::Fill); p.set_anti_alias(true); // TODO: get proper blend mode. See https://tree.taiga.io/project/penpot/task/9275 - p.set_blend_mode(skia::BlendMode::DstOver); + p.set_blend_mode(skia::BlendMode::SrcOver); p } } @@ -83,7 +83,7 @@ impl Fill { #[derive(Debug, Clone)] pub struct Shape { pub id: Uuid, - pub shapes: Vec, + pub children: Vec::, pub kind: Kind, pub selrect: Rect, pub transform: Matrix, @@ -95,7 +95,7 @@ impl Shape { pub fn new(id: Uuid) -> Self { Self { id, - shapes: vec![], + children: Vec::::new(), kind: Kind::Rect, selrect: Rect::default(), transform: Matrix::identity(),