lockbook_shared/
drawing.rs1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Clone, Serialize, Deserialize, Debug)]
6pub struct Drawing {
7 pub scale: f32,
8 pub translation_x: f32,
9 pub translation_y: f32,
10 pub strokes: Vec<Stroke>,
11 pub theme: Option<HashMap<ColorAlias, ColorRGB>>,
12}
13
14impl Default for Drawing {
15 fn default() -> Self {
16 Drawing { scale: 1.0, translation_x: 0.0, translation_y: 0.0, strokes: vec![], theme: None }
17 }
18}
19
20#[derive(Clone, Serialize, Deserialize, Debug)]
21pub struct Stroke {
22 pub points_x: Vec<f32>,
23 pub points_y: Vec<f32>,
24 pub points_girth: Vec<f32>,
25 pub color: ColorAlias,
26 pub alpha: f32,
27}
28
29impl Stroke {
30 pub fn new(color: ColorAlias) -> Self {
31 Self {
32 points_x: Vec::new(),
33 points_y: Vec::new(),
34 points_girth: Vec::new(),
35 color,
36 alpha: 1.0,
37 }
38 }
39
40 pub fn is_empty(&self) -> bool {
41 self.points_x.is_empty() && self.points_y.is_empty() && self.points_girth.is_empty()
42 }
43}
44
45#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, Copy)]
46pub enum ColorAlias {
47 Black,
48 Red,
49 Green,
50 Yellow,
51 Blue,
52 Magenta,
53 Cyan,
54 White,
55}
56
57#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Hash)]
58pub struct ColorRGB {
59 pub r: u8,
60 pub g: u8,
61 pub b: u8,
62}