mirror of
https://github.com/penpot/penpot.git
synced 2025-01-06 14:50:20 -05:00
Merge pull request #5435 from penpot/superalex-render-wasm-show-content-support
🎉 Suport for show-content in render wasm
This commit is contained in:
commit
8599c52fc0
5 changed files with 47 additions and 23 deletions
|
@ -80,6 +80,10 @@
|
|||
(aget buffer 2)
|
||||
(aget buffer 3))))
|
||||
|
||||
(defn set-shape-clip-content
|
||||
[clip-content]
|
||||
(h/call internal-module "_set_shape_clip_content" clip-content))
|
||||
|
||||
(defn set-shape-selrect
|
||||
[selrect]
|
||||
(h/call internal-module "_set_shape_selrect"
|
||||
|
@ -247,21 +251,23 @@
|
|||
pending
|
||||
(loop [index 0 pending []]
|
||||
(if (< index total-shapes)
|
||||
(let [shape (nth shapes index)
|
||||
type (dm/get-prop shape :type)
|
||||
id (dm/get-prop shape :id)
|
||||
selrect (dm/get-prop shape :selrect)
|
||||
rotation (dm/get-prop shape :rotation)
|
||||
transform (dm/get-prop shape :transform)
|
||||
fills (if (= type :group)
|
||||
[] (dm/get-prop shape :fills))
|
||||
children (dm/get-prop shape :shapes)
|
||||
blend-mode (dm/get-prop shape :blend-mode)
|
||||
opacity (dm/get-prop shape :opacity)
|
||||
hidden (dm/get-prop shape :hidden)
|
||||
content (dm/get-prop shape :content)]
|
||||
(let [shape (nth shapes index)
|
||||
type (dm/get-prop shape :type)
|
||||
id (dm/get-prop shape :id)
|
||||
clip-content (not (dm/get-prop shape :show-content))
|
||||
selrect (dm/get-prop shape :selrect)
|
||||
rotation (dm/get-prop shape :rotation)
|
||||
transform (dm/get-prop shape :transform)
|
||||
fills (if (= type :group)
|
||||
[] (dm/get-prop shape :fills))
|
||||
children (dm/get-prop shape :shapes)
|
||||
blend-mode (dm/get-prop shape :blend-mode)
|
||||
opacity (dm/get-prop shape :opacity)
|
||||
hidden (dm/get-prop shape :hidden)
|
||||
content (dm/get-prop shape :content)]
|
||||
|
||||
(use-shape id)
|
||||
(set-shape-clip-content clip-content)
|
||||
(set-shape-selrect selrect)
|
||||
(set-shape-rotation rotation)
|
||||
(set-shape-transform transform)
|
||||
|
|
|
@ -111,15 +111,16 @@
|
|||
(when ^boolean shape/*wasm-sync*
|
||||
(api/use-shape (:id self))
|
||||
(case k
|
||||
:selrect (api/set-shape-selrect v)
|
||||
:rotation (api/set-shape-rotation v)
|
||||
:transform (api/set-shape-transform v)
|
||||
:fills (api/set-shape-fills v)
|
||||
:blend-mode (api/set-shape-blend-mode v)
|
||||
:opacity (api/set-shape-opacity v)
|
||||
:hidden (api/set-shape-hidden v)
|
||||
:shapes (api/set-shape-children v)
|
||||
:content (api/set-shape-path-content v)
|
||||
:selrect (api/set-shape-selrect v)
|
||||
:show-content (api/set-shape-clip-content (not v))
|
||||
:rotation (api/set-shape-rotation v)
|
||||
:transform (api/set-shape-transform v)
|
||||
:fills (api/set-shape-fills v)
|
||||
:blend-mode (api/set-shape-blend-mode v)
|
||||
:opacity (api/set-shape-opacity v)
|
||||
:hidden (api/set-shape-hidden v)
|
||||
:shapes (api/set-shape-children v)
|
||||
:content (api/set-shape-path-content v)
|
||||
nil)
|
||||
;; when something synced with wasm
|
||||
;; is modified, we need to request
|
||||
|
|
|
@ -111,7 +111,15 @@ pub extern "C" fn set_shape_selrect(left: f32, top: f32, right: f32, bottom: f32
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn set_shape_rotation(rotation: f32) {
|
||||
pub unsafe extern "C" fn set_shape_clip_content(clip_content: bool) {
|
||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
||||
if let Some(shape) = state.current_shape() {
|
||||
shape.clip_content = clip_content;
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn set_shape_rotation(rotation: f32) {
|
||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
||||
if let Some(shape) = state.current_shape() {
|
||||
shape.rotation = rotation;
|
||||
|
|
|
@ -413,6 +413,13 @@ impl RenderState {
|
|||
|
||||
if !id.is_nil() {
|
||||
self.render_single_shape(shape);
|
||||
if shape.clip_content {
|
||||
self.drawing_surface.canvas().clip_rect(
|
||||
shape.selrect,
|
||||
skia::ClipOp::Intersect,
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// draw all the children shapes
|
||||
|
|
|
@ -51,6 +51,7 @@ pub struct Shape {
|
|||
pub selrect: math::Rect,
|
||||
pub transform: Matrix,
|
||||
pub rotation: f32,
|
||||
pub clip_content: bool,
|
||||
fills: Vec<Fill>,
|
||||
pub blend_mode: BlendMode,
|
||||
pub opacity: f32,
|
||||
|
@ -66,6 +67,7 @@ impl Shape {
|
|||
selrect: math::Rect::new_empty(),
|
||||
transform: Matrix::identity(),
|
||||
rotation: 0.,
|
||||
clip_content: true,
|
||||
fills: vec![],
|
||||
blend_mode: BlendMode::default(),
|
||||
opacity: 1.,
|
||||
|
|
Loading…
Reference in a new issue