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
use color::{*,Rgba,Rgb,ToRgb,ToRgba};
use color::consts::WHITE;
use super::Parameter;
use super::parameter::Changed;

pub struct OutlineMaterial{
    pub color: Rgba<f32>,
    pub offset: f32,
    changed: Changed,
}

pub struct Builder{
    color: Rgba<f32>,
    offset: f32,
}

impl Builder{
    pub fn new() -> Builder{
        Builder{
            color: WHITE.to_rgba(),
            offset: 0.01,
        }
    }

    pub fn offset(&mut self, offset: f32) -> &mut Builder{
        self.offset = offset;
        self
    }

    pub fn color<C: ToRgb>(&mut self, color: C) -> &mut Builder{
        let rgb: Rgb<f32> = color.to_rgb();
        self.color = rgba!(rgb, 1.);
        self
    }

    pub fn build(&self) -> OutlineMaterial{
        OutlineMaterial{
            color: self.color,
            offset: self.offset,
            changed: Changed::default(),
        }
    }
}

impl super::Material for OutlineMaterial{
    fn parameters(&mut self) -> Vec<Parameter>{
        vec![
            Parameter::new("base_color", &mut self.color, &self.changed),
            Parameter::new("offset", &mut self.offset, &self.changed),
        ]
    }

    fn parameter(&mut self, name: &str) -> Option<Parameter>{
        match name {
            "base_color" => Some(Parameter::new("base_color", &mut self.color, &self.changed)),
            "offset" => Some(Parameter::new("offset", &mut self.offset, &self.changed)),
            _ => None,
        }
    }

    fn changed(&self) -> bool{
        self.changed.changed()
    }

    fn reset_changed(&mut self){
        self.changed.reset();
    }
}