mirror of
https://github.com/penpot/penpot.git
synced 2026-05-16 13:33:45 +00:00
* ♻️ Move shape type serialization to wasm module * ♻️ Refactor serialization of constraints and vertical alignment into wasm module * ♻️ Refactor serialization and model of shape blur * ♻️ Refactor bool serialization to the wasm module * ♻️ Split wasm::layout into submodules * ♻️ Refactor serialization of AlignItems, AlignContent, JustifyItems and JustifyContent * ♻️ Refactor serialization of WrapType and FlexDirection * ♻️ Refactor serialization of JustifySelf * ♻️ Refactor serialization of GridCell * ♻️ Refactor serialization of AlignSelf * 🐛 Fix AlignSelf not being serialized * ♻️ Refactor handling of None variants in Raw* enums * ♻️ Refactor serialization of grid direction * ♻️ Refactor serialization of GridTrack and GridTrackType * ♻️ Refactor serialization of Sizing * ♻️ Refactor serialization of ShadowStyle * ♻️ Refactor serialization of StrokeCap and StrokeStyle * ♻️ Refactor serialization of BlendMode * ♻️ Refactor serialization of FontStyle * ♻️ Refactor serialization of GrowType
66 lines
2.1 KiB
Rust
66 lines
2.1 KiB
Rust
use macros::ToJs;
|
|
use skia_safe as skia;
|
|
|
|
use crate::shapes::BlendMode;
|
|
use crate::{with_current_shape_mut, STATE};
|
|
|
|
#[derive(Debug, PartialEq, Clone, Copy, ToJs)]
|
|
#[repr(u8)]
|
|
#[allow(dead_code)]
|
|
pub enum RawBlendMode {
|
|
Normal = 3,
|
|
Screen = 14,
|
|
Overlay = 15,
|
|
Darken = 16,
|
|
Lighten = 17,
|
|
ColorDodge = 18,
|
|
ColorBurn = 19,
|
|
HardLight = 20,
|
|
SoftLight = 21,
|
|
Difference = 22,
|
|
Exclusion = 23,
|
|
Multiply = 24,
|
|
Hue = 25,
|
|
Saturation = 26,
|
|
Color = 27,
|
|
Luminosity = 28,
|
|
}
|
|
|
|
impl From<u8> for RawBlendMode {
|
|
fn from(value: u8) -> Self {
|
|
unsafe { std::mem::transmute(value) }
|
|
}
|
|
}
|
|
|
|
impl From<RawBlendMode> for BlendMode {
|
|
fn from(value: RawBlendMode) -> Self {
|
|
match value {
|
|
RawBlendMode::Normal => BlendMode(skia::BlendMode::SrcOver),
|
|
RawBlendMode::Screen => BlendMode(skia::BlendMode::Screen),
|
|
RawBlendMode::Overlay => BlendMode(skia::BlendMode::Overlay),
|
|
RawBlendMode::Darken => BlendMode(skia::BlendMode::Darken),
|
|
RawBlendMode::Lighten => BlendMode(skia::BlendMode::Lighten),
|
|
RawBlendMode::ColorDodge => BlendMode(skia::BlendMode::ColorDodge),
|
|
RawBlendMode::ColorBurn => BlendMode(skia::BlendMode::ColorBurn),
|
|
RawBlendMode::HardLight => BlendMode(skia::BlendMode::HardLight),
|
|
RawBlendMode::SoftLight => BlendMode(skia::BlendMode::SoftLight),
|
|
RawBlendMode::Difference => BlendMode(skia::BlendMode::Difference),
|
|
RawBlendMode::Exclusion => BlendMode(skia::BlendMode::Exclusion),
|
|
RawBlendMode::Multiply => BlendMode(skia::BlendMode::Multiply),
|
|
RawBlendMode::Hue => BlendMode(skia::BlendMode::Hue),
|
|
RawBlendMode::Saturation => BlendMode(skia::BlendMode::Saturation),
|
|
RawBlendMode::Color => BlendMode(skia::BlendMode::Color),
|
|
RawBlendMode::Luminosity => BlendMode(skia::BlendMode::Luminosity),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[no_mangle]
|
|
pub extern "C" fn set_shape_blend_mode(mode: u8) {
|
|
let mode = RawBlendMode::from(mode);
|
|
|
|
with_current_shape_mut!(state, |shape: &mut Shape| {
|
|
shape.set_blend_mode(mode.into());
|
|
});
|
|
}
|