CommonLibSSE (Parapets fork)
Loading...
Searching...
No Matches
Color.h
Go to the documentation of this file.
1#pragma once
2
3namespace RE
4{
5 struct Color
6 {
7 public:
8 enum : std::size_t
9 {
14
15 kTotal
16 };
17
18 constexpr Color() noexcept :
19 red(0),
20 green(0),
21 blue(0),
22 alpha(0)
23 {}
24
25 constexpr Color(const Color& a_rhs) noexcept :
26 red(a_rhs.red),
27 green(a_rhs.green),
28 blue(a_rhs.blue),
29 alpha(a_rhs.alpha)
30 {}
31
32 constexpr Color(Color&& a_rhs) noexcept :
33 red(std::move(a_rhs.red)),
34 green(std::move(a_rhs.green)),
35 blue(std::move(a_rhs.blue)),
36 alpha(std::move(a_rhs.alpha))
37 {}
38
39 constexpr Color(std::uint8_t a_red, std::uint8_t a_green, std::uint8_t a_blue, std::uint8_t a_alpha) noexcept :
40 red(a_red),
41 green(a_green),
42 blue(a_blue),
43 alpha(a_alpha)
44 {}
45
46 ~Color() noexcept = default;
47
48 constexpr Color& operator=(const Color& a_rhs) noexcept
49 {
50 if (this != std::addressof(a_rhs)) {
51 red = a_rhs.red;
52 green = a_rhs.green;
53 blue = a_rhs.blue;
54 alpha = a_rhs.alpha;
55 }
56 return *this;
57 }
58
59 constexpr Color& operator=(Color&& a_rhs) noexcept
60 {
61 if (this != std::addressof(a_rhs)) {
62 red = std::move(a_rhs.red);
63 green = std::move(a_rhs.green);
64 blue = std::move(a_rhs.blue);
65 alpha = std::move(a_rhs.alpha);
66 }
67 return *this;
68 }
69
70 [[nodiscard]] friend constexpr bool operator==(const Color& a_lhs, const Color& a_rhs) noexcept
71 {
72 for (std::size_t i = 0; i < kTotal; ++i) {
73 if (a_lhs[i] != a_rhs[i]) {
74 return false;
75 }
76 }
77 return true;
78 }
79
80 [[nodiscard]] friend constexpr bool operator!=(const Color& a_lhs, const Color& a_rhs) noexcept
81 {
82 return !(a_lhs == a_rhs);
83 }
84
85 [[nodiscard]] constexpr std::uint8_t& operator[](std::size_t a_idx) noexcept
86 {
87 assert(a_idx < kTotal);
88 return std::addressof(red)[a_idx];
89 }
90
91 [[nodiscard]] constexpr const std::uint8_t& operator[](std::size_t a_idx) const noexcept
92 {
93 assert(a_idx < kTotal);
94 return std::addressof(red)[a_idx];
95 }
96
97 // members
98 std::uint8_t red; // 0
99 std::uint8_t green; // 1
100 std::uint8_t blue; // 2
101 std::uint8_t alpha; // 3
102 };
103 static_assert(sizeof(Color) == 0x4);
104}
Definition: AbsorbEffect.h:6
Definition: Color.h:6
std::uint8_t blue
Definition: Color.h:100
std::uint8_t red
Definition: Color.h:98
constexpr Color(std::uint8_t a_red, std::uint8_t a_green, std::uint8_t a_blue, std::uint8_t a_alpha) noexcept
Definition: Color.h:39
constexpr Color(Color &&a_rhs) noexcept
Definition: Color.h:32
constexpr std::uint8_t & operator[](std::size_t a_idx) noexcept
Definition: Color.h:85
constexpr Color & operator=(Color &&a_rhs) noexcept
Definition: Color.h:59
std::uint8_t green
Definition: Color.h:99
constexpr const std::uint8_t & operator[](std::size_t a_idx) const noexcept
Definition: Color.h:91
constexpr Color(const Color &a_rhs) noexcept
Definition: Color.h:25
~Color() noexcept=default
constexpr Color() noexcept
Definition: Color.h:18
friend constexpr bool operator!=(const Color &a_lhs, const Color &a_rhs) noexcept
Definition: Color.h:80
std::uint8_t alpha
Definition: Color.h:101
@ kBlue
Definition: Color.h:12
@ kTotal
Definition: Color.h:15
@ kRed
Definition: Color.h:10
@ kGreen
Definition: Color.h:11
@ kAlpha
Definition: Color.h:13
friend constexpr bool operator==(const Color &a_lhs, const Color &a_rhs) noexcept
Definition: Color.h:70