mirror of
https://github.com/penpot/penpot.git
synced 2025-07-04 00:47:18 +02:00
🎉 Draw solid fills for shapes
This commit is contained in:
parent
669bca5fa5
commit
539d5dfc08
5 changed files with 79 additions and 24 deletions
|
@ -1,7 +1,6 @@
|
|||
use skia_safe as skia;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::state::State;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum Kind {
|
||||
None,
|
||||
|
@ -29,6 +28,8 @@ pub struct Rect {
|
|||
pub y2: f32,
|
||||
}
|
||||
|
||||
type Color = skia::Color;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Matrix {
|
||||
pub a: f32,
|
||||
|
@ -52,6 +53,33 @@ impl Matrix {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Fill {
|
||||
Solid(Color), // TODO: add more fills here
|
||||
}
|
||||
|
||||
impl From<Color> for Fill {
|
||||
fn from(value: Color) -> Self {
|
||||
Self::Solid(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl Fill {
|
||||
pub fn to_paint(&self) -> skia::Paint {
|
||||
match self {
|
||||
Self::Solid(color) => {
|
||||
let mut p = skia::Paint::default();
|
||||
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::DstOver);
|
||||
p
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Shape {
|
||||
pub id: Uuid,
|
||||
|
@ -60,17 +88,19 @@ pub struct Shape {
|
|||
pub selrect: Rect,
|
||||
pub transform: Matrix,
|
||||
pub rotation: f32,
|
||||
fills: Vec<Fill>,
|
||||
}
|
||||
|
||||
impl Shape {
|
||||
pub fn new(id: Uuid) -> Self {
|
||||
Self {
|
||||
id,
|
||||
shapes: Vec::<Uuid>::new(),
|
||||
shapes: vec![],
|
||||
kind: Kind::Rect,
|
||||
selrect: Rect::default(),
|
||||
transform: Matrix::identity(),
|
||||
rotation: 0.,
|
||||
fills: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,4 +115,16 @@ impl Shape {
|
|||
pub fn skew(&self) -> (f32, f32) {
|
||||
(self.transform.c, self.transform.b)
|
||||
}
|
||||
|
||||
pub fn fills(&self) -> std::slice::Iter<Fill> {
|
||||
self.fills.iter()
|
||||
}
|
||||
|
||||
pub fn add_fill(&mut self, f: Fill) {
|
||||
self.fills.push(f)
|
||||
}
|
||||
|
||||
pub fn clear_fills(&mut self) {
|
||||
self.fills.clear();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue