galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
Colour.cpp
Go to the documentation of this file.
1
7
9
10#include "Colour.hpp"
11
12const constexpr auto COLOUR_OFFSET = static_cast<float>(0xFF);
13
14#ifdef GALAXY_WIN_PLATFORM
18#endif
19
20namespace galaxy
21{
22 namespace graphics
23 {
25 : m_array {255, 255, 255, 255}
26 , m_vec4 {1.0f, 1.0f, 1.0f, 1.0f}
27 {
28 }
29
31 {
32 this->m_array = std::move(c.m_array);
33 this->m_vec4 = std::move(c.m_vec4);
34 }
35
37 {
38 this->m_array = c.m_array;
39 this->m_vec4 = c.m_vec4;
40 }
41
43 {
44 if (this != &c)
45 {
46 this->m_array = std::move(c.m_array);
47 this->m_vec4 = std::move(c.m_vec4);
48 }
49
50 return *this;
51 }
52
54 {
55 if (this != &c)
56 {
57 this->m_array = c.m_array;
58 this->m_vec4 = c.m_vec4;
59 }
60
61 return *this;
62 }
63
65 {
66 }
67
68 void Colour::set_r(const std::uint8_t r)
69 {
70 m_array[0] = r;
71
72 if (r == 255)
73 {
74 m_vec4.x = 1.0f;
75 }
76 else if (r == 0)
77 {
78 m_vec4.x = 0.0f;
79 }
80 else
81 {
82 m_vec4.x = static_cast<float>(r) / COLOUR_OFFSET;
83 }
84 }
85
86 void Colour::set_g(const std::uint8_t g)
87 {
88 m_array[1] = g;
89
90 if (g == 255)
91 {
92 m_vec4.y = 1.0f;
93 }
94 else if (g == 0)
95 {
96 m_vec4.y = 0.0f;
97 }
98 else
99 {
100 m_vec4.y = static_cast<float>(g) / COLOUR_OFFSET;
101 }
102 }
103
104 void Colour::set_b(const std::uint8_t b)
105 {
106 m_array[2] = b;
107
108 if (b == 255)
109 {
110 m_vec4.z = 1.0f;
111 }
112 else if (b == 0)
113 {
114 m_vec4.z = 0.0f;
115 }
116 else
117 {
118 m_vec4.z = static_cast<float>(b) / COLOUR_OFFSET;
119 }
120 }
121
122 void Colour::set_a(const std::uint8_t a)
123 {
124 m_array[3] = a;
125
126 if (a == 255)
127 {
128 m_vec4.w = 1.0f;
129 }
130 else if (a == 0)
131 {
132 m_vec4.w = 0.0f;
133 }
134 else
135 {
136 m_vec4.w = static_cast<float>(a) / COLOUR_OFFSET;
137 }
138 }
139
140 void Colour::set_rgba(const glm::vec4& rgba)
141 {
142 m_vec4 = rgba;
143
144 m_vec4.x = std::clamp(m_vec4.x, 0.0f, 1.0f);
145 m_vec4.y = std::clamp(m_vec4.y, 0.0f, 1.0f);
146 m_vec4.z = std::clamp(m_vec4.z, 0.0f, 1.0f);
147 m_vec4.w = std::clamp(m_vec4.w, 0.0f, 1.0f);
148
153 }
154
155 std::array<std::uint8_t, 4>& Colour::array()
156 {
157 return m_array;
158 }
159
160 glm::vec4& Colour::vec4()
161 {
162 return m_vec4;
163 }
164
165 const std::array<std::uint8_t, 4>& Colour::array() const
166 {
167 return m_array;
168 }
169
170 const glm::vec4& Colour::vec4() const
171 {
172 return m_vec4;
173 }
174 } // namespace graphics
175} // namespace galaxy
176
177#ifdef GALAXY_WIN_PLATFORM
179#endif
const constexpr auto COLOUR_OFFSET
Colour.cpp galaxy.
Definition Colour.cpp:12
#define GALAXY_DISABLE_WARNING_POP
Definition Pragma.hpp:57
#define GALAXY_DISABLE_WARNING(x)
Definition Pragma.hpp:58
#define GALAXY_DISABLE_WARNING_PUSH
Macro for windows platform detection.
Definition Pragma.hpp:56
Represents an RGBA colour.
Definition Colour.hpp:27
void set_g(const std::uint8_t g)
Green.
Definition Colour.cpp:86
glm::vec4 m_vec4
r,g,b,a = x,y,z,w.
Definition Colour.hpp:196
~Colour()
Destructor.
Definition Colour.cpp:64
std::array< std::uint8_t, 4 > & array()
Get integer array.
Definition Colour.cpp:155
R r() const
Get red.
B b() const
Get blue.
Colour & operator=(Colour &&)
Move assignment operator.
Definition Colour.cpp:42
glm::vec4 & vec4()
Get vec4.
Definition Colour.cpp:160
std::array< std::uint8_t, 4 > m_array
r,g,b,a = 0,1,2,3.
Definition Colour.hpp:191
void set_r(const std::uint8_t r)
Red.
Definition Colour.cpp:68
Colour()
Constructor.
Definition Colour.cpp:24
void set_rgba(const glm::vec4 &rgba)
Set RGBA.
Definition Colour.cpp:140
G g() const
Get green.
void set_b(const std::uint8_t b)
Blue.
Definition Colour.cpp:104
void set_a(const std::uint8_t a)
Alpha.
Definition Colour.cpp:122
A a() const
Get alpha.
Animated.cpp galaxy.
Definition Animated.cpp:16