mirror of
https://github.com/penpot/penpot.git
synced 2025-01-08 07:50:43 -05:00
Merge pull request #5295 from penpot/superalex-refactor-naming-anidated-shapes-wasm
🎉 Refactor naming anidated shapes with children for wasm render
This commit is contained in:
commit
58d744a342
5 changed files with 15 additions and 15 deletions
|
@ -20,7 +20,7 @@
|
||||||
(defonce wasm-set-shape-transform (constantly nil))
|
(defonce wasm-set-shape-transform (constantly nil))
|
||||||
(defonce wasm-set-shape-rotation (constantly nil))
|
(defonce wasm-set-shape-rotation (constantly nil))
|
||||||
(defonce wasm-set-shape-fills (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
|
(cr/defrecord Shape [id name type x y width height rotation selrect points
|
||||||
transform transform-inverse parent-id frame-id flip-x flip-y])
|
transform transform-inverse parent-id frame-id flip-x flip-y])
|
||||||
|
@ -118,8 +118,8 @@
|
||||||
:selrect (wasm-set-shape-selrect v)
|
:selrect (wasm-set-shape-selrect v)
|
||||||
:rotation (wasm-set-shape-rotation v)
|
:rotation (wasm-set-shape-rotation v)
|
||||||
:transform (wasm-set-shape-transform v)
|
:transform (wasm-set-shape-transform v)
|
||||||
:shapes (wasm-set-shapes v)
|
|
||||||
:fills (wasm-set-shape-fills v)
|
:fills (wasm-set-shape-fills v)
|
||||||
|
:shapes (wasm-set-shape-children v)
|
||||||
nil))
|
nil))
|
||||||
(let [delegate (.-delegate ^ShapeProxy coll)
|
(let [delegate (.-delegate ^ShapeProxy coll)
|
||||||
delegate' (assoc delegate k v)]
|
delegate' (assoc delegate k v)]
|
||||||
|
|
|
@ -59,12 +59,12 @@
|
||||||
[rotation]
|
[rotation]
|
||||||
(._set_shape_rotation ^js internal-module rotation))
|
(._set_shape_rotation ^js internal-module rotation))
|
||||||
|
|
||||||
(defn set-shapes
|
(defn set-shape-children
|
||||||
[shape_ids]
|
[shape_ids]
|
||||||
(._clear_child_shapes ^js internal-module)
|
(._clear_shape_children ^js internal-module)
|
||||||
(doseq [id shape_ids]
|
(doseq [id shape_ids]
|
||||||
(let [buffer (uuid/uuid->u32 id)]
|
(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
|
(defn set-shape-fills
|
||||||
[fills]
|
[fills]
|
||||||
|
@ -92,7 +92,7 @@
|
||||||
(set-shape-rotation rotation)
|
(set-shape-rotation rotation)
|
||||||
(set-shape-transform transform)
|
(set-shape-transform transform)
|
||||||
(set-shape-fills fills)
|
(set-shape-fills fills)
|
||||||
(set-shapes children)
|
(set-shape-children children)
|
||||||
(recur (inc index)))))))
|
(recur (inc index)))))))
|
||||||
|
|
||||||
(defn draw-objects
|
(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-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-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-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)
|
||||||
|
|
|
@ -130,19 +130,19 @@ pub unsafe extern "C" fn set_shape_transform(a: f32, b: f32, c: f32, d: f32, e:
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[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 state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
||||||
let id = uuid_from_u32_quartet(a, b, c, d);
|
let id = uuid_from_u32_quartet(a, b, c, d);
|
||||||
if let Some(shape) = state.current_shape.as_deref_mut() {
|
if let Some(shape) = state.current_shape.as_deref_mut() {
|
||||||
shape.shapes.push(id);
|
shape.children.push(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[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");
|
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
||||||
if let Some(shape) = state.current_shape.as_deref_mut() {
|
if let Some(shape) = state.current_shape.as_deref_mut() {
|
||||||
shape.shapes.clear();
|
shape.children.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ pub(crate) fn render_shape_tree(state: &mut State, id: Uuid) {
|
||||||
render_single_shape(&mut state.render_state.surface, shape);
|
render_single_shape(&mut state.render_state.surface, shape);
|
||||||
|
|
||||||
// draw all the children shapes
|
// draw all the children shapes
|
||||||
let shape_ids = shape.shapes.clone();
|
let shape_ids = shape.children.clone();
|
||||||
for shape_id in shape_ids {
|
for shape_id in shape_ids {
|
||||||
render_shape_tree(state, shape_id);
|
render_shape_tree(state, shape_id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ impl Fill {
|
||||||
p.set_style(skia::PaintStyle::Fill);
|
p.set_style(skia::PaintStyle::Fill);
|
||||||
p.set_anti_alias(true);
|
p.set_anti_alias(true);
|
||||||
// TODO: get proper blend mode. See https://tree.taiga.io/project/penpot/task/9275
|
// 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
|
p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ impl Fill {
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Shape {
|
pub struct Shape {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
pub shapes: Vec<Uuid>,
|
pub children: Vec::<Uuid>,
|
||||||
pub kind: Kind,
|
pub kind: Kind,
|
||||||
pub selrect: Rect,
|
pub selrect: Rect,
|
||||||
pub transform: Matrix,
|
pub transform: Matrix,
|
||||||
|
@ -95,7 +95,7 @@ impl Shape {
|
||||||
pub fn new(id: Uuid) -> Self {
|
pub fn new(id: Uuid) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
shapes: vec![],
|
children: Vec::<Uuid>::new(),
|
||||||
kind: Kind::Rect,
|
kind: Kind::Rect,
|
||||||
selrect: Rect::default(),
|
selrect: Rect::default(),
|
||||||
transform: Matrix::identity(),
|
transform: Matrix::identity(),
|
||||||
|
|
Loading…
Reference in a new issue