1pub struct DrawOptions {
2 fill_color: Option<(u8, u8, u8)>,
3 stroke_color: Option<(u8, u8, u8)>,
4 stroke_size: f64,
5}
6
7impl DrawOptions {
8 pub fn default() -> DrawOptions {
9 DrawOptions {
10 fill_color: None,
11 stroke_color: Some((0, 0, 0)),
12 stroke_size: 2.0,
13 }
14 }
15
16 pub fn stroked((r, g, b): (u8, u8, u8), size: f64) -> DrawOptions {
17 DrawOptions {
18 fill_color: None,
19 stroke_color: Some((r, g, b)),
20 stroke_size: size,
21 }
22 }
23
24 pub fn filled((r, g, b): (u8, u8, u8)) -> DrawOptions {
25 DrawOptions {
26 fill_color: Some((r, g, b)),
27 stroke_color: None,
28 stroke_size: 0.0,
29 }
30 }
31}
32
33pub enum Command {
34 StartShape(DrawOptions),
35 MoveTo {
36 x: f64,
37 y: f64
38 },
39 LineTo {
40 x: f64,
41 y: f64
42 },
43 CubicCurveTo {
44 cx1: f64,
46 cy1: f64,
47 cx2: f64,
49 cy2: f64,
50 x: f64,
52 y: f64,
53 },
54 QuadraticCurveTo {
55 cx: f64,
57 cy: f64,
58 x: f64,
60 y: f64,
61 },
62 ArcTo {
64 rx: f64,
66 ry: f64,
67 rotation: f64,
69 large_arc: bool,
71 sweep: bool,
72 x: f64,
74 y: f64,
75 },
76 CloseShape,
77 EndShape,
78}
79
80pub trait DrawBackend {
81 type Error;
82 fn apply(&mut self, command: Command) -> Result<(), Self::Error>;
83 fn close(self) -> Result<(), Self::Error>;
84}