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
use crate::quicksilver_compat::graphics::Color;
use crate::{graphics::Image, Transform};
#[derive(Copy, Clone)]
pub enum Background<'a> {
Col(Color),
Img(&'a Image),
ImgView(&'a Image, Transform),
Blended(&'a Image, Color),
}
impl<'a> Background<'a> {
pub fn image(&self) -> Option<&Image> {
match self {
Background::Col(_) => None,
Background::Img(img) | Background::Blended(img, _) | Background::ImgView(img, _) => {
Some(img)
}
}
}
pub fn color(&self) -> Color {
match self {
Background::Col(color) | Background::Blended(_, color) => *color,
Background::Img(_) | Background::ImgView(_, _) => Color::WHITE,
}
}
pub fn texture_transform(&self) -> Option<Transform> {
match self {
Background::Col(_) | Background::Blended(_, _) => None,
Background::Img(img) => Some(img.texture_transform()),
Background::ImgView(img, transform) => Some(img.texture_transform() * *transform),
}
}
}
impl<'a> From<Color> for Background<'a> {
fn from(col: Color) -> Self {
Background::Col(col)
}
}
impl<'a> From<&'a Image> for Background<'a> {
fn from(img: &'a Image) -> Self {
Background::Img(img)
}
}
impl<'a> From<(&'a Image, Color)> for Background<'a> {
fn from((img, col): (&'a Image, Color)) -> Self {
Background::Blended(img, col)
}
}