File: color.cpp

package info (click to toggle)
higan 106-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 9,640 kB
  • sloc: cpp: 108,736; ansic: 809; makefile: 22; sh: 7
file content (79 lines) | stat: -rw-r--r-- 1,800 bytes parent folder | download | duplicates (2)
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
#if defined(Hiro_Color)

Color::Color() {
  setColor(0, 0, 0, 0);
}

Color::Color(signed red, signed green, signed blue, signed alpha) {
  setColor(red, green, blue, alpha);
}

Color::operator bool() const {
  return state.red || state.green || state.blue || state.alpha;
}

auto Color::operator==(const Color& source) const -> bool {
  return red() == source.red() && green() == source.green() && blue() == source.blue() && alpha() == source.alpha();
}

auto Color::operator!=(const Color& source) const -> bool {
  return !operator==(source);
}

auto Color::alpha() const -> uint8_t {
  return state.alpha;
}

auto Color::blue() const -> uint8_t {
  return state.blue;
}

auto Color::green() const -> uint8_t {
  return state.green;
}

auto Color::red() const -> uint8_t {
  return state.red;
}

auto Color::reset() -> type& {
  return setColor(0, 0, 0, 0);
}

auto Color::setAlpha(signed alpha) -> type& {
  state.alpha = max(0, min(255, alpha));
  return *this;
}

auto Color::setBlue(signed blue) -> type& {
  state.blue = max(0, min(255, blue));
  return *this;
}

auto Color::setColor(Color color) -> type& {
  return setColor(color.red(), color.green(), color.blue(), color.alpha());
}

auto Color::setColor(signed red, signed green, signed blue, signed alpha) -> type& {
  state.red   = max(0, min(255, red  ));
  state.green = max(0, min(255, green));
  state.blue  = max(0, min(255, blue ));
  state.alpha = max(0, min(255, alpha));
  return *this;
}

auto Color::setGreen(signed green) -> type& {
  state.green = max(0, min(255, green));
  return *this;
}

auto Color::setRed(signed red) -> type& {
  state.red = max(0, min(255, red));
  return *this;
}

auto Color::value() const -> uint32_t {
  return state.alpha << 24 | state.red << 16 | state.green << 8 | state.blue << 0;
}

#endif