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
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
use std::hash::Hash;

use palette::rgb::LinSrgb;

use crate::Pen;

pub trait InkJoyGelPenSize: Clone + Eq + PartialEq + Hash {
    fn nib_size() -> f64;
}

#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct PointSevenMM;
impl InkJoyGelPenSize for PointSevenMM {
    fn nib_size() -> f64 {
        0.7
    }
}

#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct PointFiveMM;
impl InkJoyGelPenSize for PointFiveMM {
    fn nib_size() -> f64 {
        0.5
    }
}

#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum InkJoyGelPenColor {
    Red,
    Berry,
    Pink,
    Orange,
    Yellow,
    Green,
    Lime,
    SlateBlue,
    Blue,
    BrightBlue,
    Teal,
    Purple,
    Cocoa,
    Black,
}

impl InkJoyGelPenColor {
    fn rgb_color(&self) -> LinSrgb {
        let (r, g, b) = match self {
            InkJoyGelPenColor::Red => (0xd1, 0x24, 0x31),
            InkJoyGelPenColor::Berry => (0xc1, 0x52, 0x9e),
            InkJoyGelPenColor::Pink => (0xd8, 0x40, 0x8c),
            InkJoyGelPenColor::Orange => (0xf3, 0x6c, 0x38),
            InkJoyGelPenColor::Yellow => (0xff, 0xda, 0x3a),
            InkJoyGelPenColor::Green => (0x00, 0xa8, 0x5d),
            InkJoyGelPenColor::Lime => (0xa6, 0xd0, 0x60),
            InkJoyGelPenColor::SlateBlue => (0x28, 0x62, 0x8f),
            InkJoyGelPenColor::Blue => (0x0a, 0x2e, 0x83),
            InkJoyGelPenColor::BrightBlue => (0x47, 0xb7, 0xe6),
            InkJoyGelPenColor::Teal => (0x00, 0x9b, 0xa8),
            InkJoyGelPenColor::Purple => (0x78, 0x5b, 0xa7),
            InkJoyGelPenColor::Cocoa => (0x8e, 0x61, 0x5e),
            InkJoyGelPenColor::Black => (0x37, 0x36, 0x3d),
        };
        LinSrgb::new(r as f32 / 255.0, g as f32 / 255.0, b as f32 / 255.0).into_linear()
    }
}

#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct InkJoyGelPen<T: InkJoyGelPenSize> {
    color: InkJoyGelPenColor,
    _size: std::marker::PhantomData<T>,
}

impl<T: InkJoyGelPenSize> InkJoyGelPen<T> {
    pub fn new(color: InkJoyGelPenColor) -> Self {
        let _size = std::marker::PhantomData;
        InkJoyGelPen { color, _size }
    }
}

impl<T: InkJoyGelPenSize> Pen for InkJoyGelPen<T> {
    fn available_colors() -> Vec<Self> {
        vec![
            InkJoyGelPen::new(InkJoyGelPenColor::Red),
            InkJoyGelPen::new(InkJoyGelPenColor::Berry),
            InkJoyGelPen::new(InkJoyGelPenColor::Pink),
            InkJoyGelPen::new(InkJoyGelPenColor::Orange),
            InkJoyGelPen::new(InkJoyGelPenColor::Yellow),
            InkJoyGelPen::new(InkJoyGelPenColor::Green),
            InkJoyGelPen::new(InkJoyGelPenColor::Lime),
            InkJoyGelPen::new(InkJoyGelPenColor::SlateBlue),
            InkJoyGelPen::new(InkJoyGelPenColor::Blue),
            InkJoyGelPen::new(InkJoyGelPenColor::BrightBlue),
            InkJoyGelPen::new(InkJoyGelPenColor::Teal),
            InkJoyGelPen::new(InkJoyGelPenColor::Purple),
            InkJoyGelPen::new(InkJoyGelPenColor::Cocoa),
            InkJoyGelPen::new(InkJoyGelPenColor::Black),
        ]
    }

    fn nib_size_mm() -> f64 {
        T::nib_size()
    }

    fn rgb_color(&self) -> LinSrgb {
        self.color.rgb_color()
    }
}