-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhisperer.rs
64 lines (60 loc) · 1.61 KB
/
whisperer.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#![allow(unused)]
use kurbo::{Affine, Point, Rect, Shape, Stroke};
use peniko::{BlendMode, Brush, BrushRef, Fill};
use serde::{Deserialize, Serialize};
use std::borrow::Borrow;
pub enum PaintOpRef<'a, 'b> {
Fill {
style: Fill,
brush: BrushRef<'b>,
},
Stroke {
style: &'a Stroke,
brush: BrushRef<'b>,
},
PushLayer {
blend: BlendMode,
alpha: f32,
},
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum PaintOp {
Fill { style: Fill, brush: Brush },
Stroke { style: Stroke, brush: Brush },
PushLayer { blend: BlendMode, alpha: f32 },
}
impl<'a> From<&'a PaintOp> for PaintOpRef<'a, 'a> {
fn from(x: &'a PaintOp) -> PaintOpRef<'a, 'a> {
match x {
PaintOp::Fill { style, brush } => PaintOpRef::Fill {
style: *style,
brush: brush.into(),
},
PaintOp::Stroke { style, brush } => PaintOpRef::Stroke {
style,
brush: brush.into(),
},
PaintOp::PushLayer { blend, alpha } => PaintOpRef::PushLayer {
blend: *blend,
alpha: *alpha,
},
}
}
}
pub trait SceneWhisperer {
fn apply_paint_op(
&mut self,
op: PaintOpRef<'_, '_>,
transform: Affine,
brush_transform: Option<Affine>,
shape: &impl Shape,
);
fn apply_paint_ops<'a, 'b, I>(
&mut self,
ops: I,
transform: Affine,
brush_transform: Option<Affine>,
shape: &impl Shape,
) where
I: IntoIterator<Item = PaintOpRef<'a, 'b>>;
}