0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 15:09:10 -05:00

Merge pull request #5363 from penpot/superalex-wasm-shape-opacity

🎉 Shape opacity for wasm render
This commit is contained in:
Belén Albeza 2024-11-25 11:30:50 +01:00 committed by GitHub
commit 5018ff06ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 19 additions and 1 deletions

View file

@ -125,6 +125,10 @@
;; https://rust-skia.github.io/doc/skia_safe/enum.BlendMode.html ;; https://rust-skia.github.io/doc/skia_safe/enum.BlendMode.html
(h/call internal-module "_set_shape_blend_mode" (translate-blend-mode blend-mode))) (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)) (def debounce-render-without-cache (fns/debounce render-without-cache 100))
(defn set-view (defn set-view
@ -146,7 +150,8 @@
transform (dm/get-prop shape :transform) transform (dm/get-prop shape :transform)
fills (dm/get-prop shape :fills) fills (dm/get-prop shape :fills)
children (dm/get-prop shape :shapes) 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) (use-shape id)
(set-shape-selrect selrect) (set-shape-selrect selrect)
(set-shape-rotation rotation) (set-shape-rotation rotation)
@ -154,6 +159,7 @@
(set-shape-fills fills) (set-shape-fills fills)
(set-shape-blend-mode blend-mode) (set-shape-blend-mode blend-mode)
(set-shape-children children) (set-shape-children children)
(set-shape-opacity opacity)
(recur (inc index)))))) (recur (inc index))))))
(request-render)) (request-render))

View file

@ -100,6 +100,7 @@
:transform (api/set-shape-transform v) :transform (api/set-shape-transform v)
:fills (api/set-shape-fills v) :fills (api/set-shape-fills v)
:blend-mode (api/set-shape-blend-mode v) :blend-mode (api/set-shape-blend-mode v)
:opacity (api/set-shape-opacity v)
:shapes (api/set-shape-children v) :shapes (api/set-shape-children v)
nil) nil)
;; when something synced with wasm ;; when something synced with wasm

View file

@ -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() { fn main() {
init_gl(); init_gl();
} }

View file

@ -164,6 +164,7 @@ impl RenderState {
let mut paint = skia::Paint::default(); let mut paint = skia::Paint::default();
paint.set_blend_mode(shape.blend_mode.into()); paint.set_blend_mode(shape.blend_mode.into());
paint.set_alpha_f(shape.opacity);
self.drawing_surface.draw( self.drawing_surface.draw(
&mut self.final_surface.canvas(), &mut self.final_surface.canvas(),
(0.0, 0.0), (0.0, 0.0),

View file

@ -104,6 +104,7 @@ pub struct Shape {
pub rotation: f32, pub rotation: f32,
fills: Vec<Fill>, fills: Vec<Fill>,
pub blend_mode: BlendMode, pub blend_mode: BlendMode,
pub opacity: f32,
} }
impl Shape { impl Shape {
@ -117,6 +118,7 @@ impl Shape {
rotation: 0., rotation: 0.,
fills: vec![], fills: vec![],
blend_mode: BlendMode::default(), blend_mode: BlendMode::default(),
opacity: 1.,
} }
} }