mirror of
https://github.com/penpot/penpot.git
synced 2025-01-23 06:58:58 -05:00
Merge pull request #5363 from penpot/superalex-wasm-shape-opacity
🎉 Shape opacity for wasm render
This commit is contained in:
commit
5018ff06ee
5 changed files with 19 additions and 1 deletions
|
@ -125,6 +125,10 @@
|
|||
;; https://rust-skia.github.io/doc/skia_safe/enum.BlendMode.html
|
||||
(h/call internal-module "_set_shape_blend_mode" (translate-blend-mode blend-mode)))
|
||||
|
||||
(defn set-shape-opacity
|
||||
[opacity]
|
||||
(h/call internal-module "_set_shape_opacity" (or opacity 1)))
|
||||
|
||||
(def debounce-render-without-cache (fns/debounce render-without-cache 100))
|
||||
|
||||
(defn set-view
|
||||
|
@ -146,7 +150,8 @@
|
|||
transform (dm/get-prop shape :transform)
|
||||
fills (dm/get-prop shape :fills)
|
||||
children (dm/get-prop shape :shapes)
|
||||
blend-mode (dm/get-prop shape :blend-mode)]
|
||||
blend-mode (dm/get-prop shape :blend-mode)
|
||||
opacity (dm/get-prop shape :opacity)]
|
||||
(use-shape id)
|
||||
(set-shape-selrect selrect)
|
||||
(set-shape-rotation rotation)
|
||||
|
@ -154,6 +159,7 @@
|
|||
(set-shape-fills fills)
|
||||
(set-shape-blend-mode blend-mode)
|
||||
(set-shape-children children)
|
||||
(set-shape-opacity opacity)
|
||||
(recur (inc index))))))
|
||||
(request-render))
|
||||
|
||||
|
|
|
@ -100,6 +100,7 @@
|
|||
: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)
|
||||
:shapes (api/set-shape-children v)
|
||||
nil)
|
||||
;; when something synced with wasm
|
||||
|
|
|
@ -166,6 +166,14 @@ pub extern "C" fn set_shape_blend_mode(mode: i32) {
|
|||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn set_shape_opacity(opacity: f32) {
|
||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
||||
if let Some(shape) = state.current_shape() {
|
||||
shape.opacity = opacity;
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
init_gl();
|
||||
}
|
||||
|
|
|
@ -164,6 +164,7 @@ impl RenderState {
|
|||
|
||||
let mut paint = skia::Paint::default();
|
||||
paint.set_blend_mode(shape.blend_mode.into());
|
||||
paint.set_alpha_f(shape.opacity);
|
||||
self.drawing_surface.draw(
|
||||
&mut self.final_surface.canvas(),
|
||||
(0.0, 0.0),
|
||||
|
|
|
@ -104,6 +104,7 @@ pub struct Shape {
|
|||
pub rotation: f32,
|
||||
fills: Vec<Fill>,
|
||||
pub blend_mode: BlendMode,
|
||||
pub opacity: f32,
|
||||
}
|
||||
|
||||
impl Shape {
|
||||
|
@ -117,6 +118,7 @@ impl Shape {
|
|||
rotation: 0.,
|
||||
fills: vec![],
|
||||
blend_mode: BlendMode::default(),
|
||||
opacity: 1.,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue