mirror of
https://github.com/penpot/penpot.git
synced 2025-05-18 01:56:11 +02:00
🎉 Implement drawing with blend mode (single fill)
This commit is contained in:
parent
7458165e51
commit
966e942a7f
5 changed files with 87 additions and 15 deletions
|
@ -72,7 +72,6 @@ impl Fill {
|
|||
p.set_color(*color);
|
||||
p.set_style(skia::PaintStyle::Fill);
|
||||
p.set_anti_alias(true);
|
||||
// TODO: get proper blend mode. See https://tree.taiga.io/project/penpot/task/9275
|
||||
p.set_blend_mode(skia::BlendMode::SrcOver);
|
||||
p
|
||||
}
|
||||
|
@ -80,15 +79,43 @@ impl Fill {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
pub struct BlendMode(skia::BlendMode);
|
||||
|
||||
impl Default for BlendMode {
|
||||
fn default() -> Self {
|
||||
BlendMode(skia::BlendMode::SrcOver)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<i32> for BlendMode {
|
||||
fn from(value: i32) -> Self {
|
||||
if value <= skia::BlendMode::Luminosity as i32 {
|
||||
unsafe { Self(std::mem::transmute(value)) }
|
||||
} else {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<skia::BlendMode> for BlendMode {
|
||||
fn into(self) -> skia::BlendMode {
|
||||
match self {
|
||||
Self(skia_blend) => skia_blend,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Shape {
|
||||
pub id: Uuid,
|
||||
pub children: Vec::<Uuid>,
|
||||
pub children: Vec<Uuid>,
|
||||
pub kind: Kind,
|
||||
pub selrect: Rect,
|
||||
pub transform: Matrix,
|
||||
pub rotation: f32,
|
||||
fills: Vec<Fill>,
|
||||
pub blend_mode: BlendMode,
|
||||
}
|
||||
|
||||
impl Shape {
|
||||
|
@ -101,6 +128,7 @@ impl Shape {
|
|||
transform: Matrix::identity(),
|
||||
rotation: 0.,
|
||||
fills: vec![],
|
||||
blend_mode: BlendMode::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,4 +155,8 @@ impl Shape {
|
|||
pub fn clear_fills(&mut self) {
|
||||
self.fills.clear();
|
||||
}
|
||||
|
||||
pub fn set_blend_mode(&mut self, mode: BlendMode) {
|
||||
self.blend_mode = mode;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue