5#ifndef LODESTONE_COLOR_H
6#define LODESTONE_COLOR_H
16 constexpr Color(
const unsigned char r,
const unsigned char g,
17 const unsigned char b,
const unsigned char a = 0xFF)
20 constexpr operator unsigned char *() {
return &
r; }
21 constexpr operator const unsigned char *()
const {
return &
r; }
24 return std::format(
"Color[r={}, g={}, b={}, a={}]",
r,
g,
b,
a);
28 return r == rhs.
r &&
g == rhs.
g &&
b == rhs.
b &&
a == rhs.
a;
32 return {
static_cast<unsigned char>(
r + v),
33 static_cast<unsigned char>(
g + v),
34 static_cast<unsigned char>(
b + v),
35 static_cast<unsigned char>(
a + v)};
39 return {
static_cast<unsigned char>(
r - v),
40 static_cast<unsigned char>(
g - v),
41 static_cast<unsigned char>(
b - v),
42 static_cast<unsigned char>(
a - v)};
46 return {
static_cast<unsigned char>(
r * v),
47 static_cast<unsigned char>(
g * v),
48 static_cast<unsigned char>(
b * v),
49 static_cast<unsigned char>(
a * v)};
53 return {
static_cast<unsigned char>(
r / v),
54 static_cast<unsigned char>(
g / v),
55 static_cast<unsigned char>(
b / v),
56 static_cast<unsigned char>(
a / v)};
60 return {
static_cast<unsigned char>(
r + rhs.
r),
61 static_cast<unsigned char>(
g + rhs.
g),
62 static_cast<unsigned char>(
b + rhs.
b),
63 static_cast<unsigned char>(
a + rhs.
a)};
67 return {
static_cast<unsigned char>(
r - rhs.
r),
68 static_cast<unsigned char>(
g - rhs.
g),
69 static_cast<unsigned char>(
b - rhs.
b),
70 static_cast<unsigned char>(
a - rhs.
a)};
74 return {
static_cast<unsigned char>(
r * rhs.
r),
75 static_cast<unsigned char>(
g * rhs.
g),
76 static_cast<unsigned char>(
b * rhs.
b),
77 static_cast<unsigned char>(
a * rhs.
a)};
81 return {
static_cast<unsigned char>(
r / rhs.
r),
82 static_cast<unsigned char>(
g / rhs.
g),
83 static_cast<unsigned char>(
b / rhs.
b),
84 static_cast<unsigned char>(
a / rhs.
a)};
89template <>
struct std::hash<
lodestone::level::types::Color> {
92 return (v.r << 24) | (v.g << 16) | (v.b << 8) | (v.a);
constexpr Color operator-(const Color &rhs) const
Definition Color.h:66
unsigned char g
Definition Color.h:14
constexpr Color(const unsigned char r, const unsigned char g, const unsigned char b, const unsigned char a=0xFF)
Definition Color.h:16
constexpr Color operator+(const Color &rhs) const
Definition Color.h:59
constexpr Color operator*(const int v) const
Definition Color.h:45
unsigned char a
Definition Color.h:14
unsigned char b
Definition Color.h:14
constexpr Color operator+(const int v) const
Definition Color.h:31
unsigned char r
Definition Color.h:14
constexpr Color operator/(const Color &rhs) const
Definition Color.h:80
constexpr Color operator-(const int v) const
Definition Color.h:38
constexpr Color operator/(const int v) const
Definition Color.h:52
std::string toString() const override
Definition Color.h:23
constexpr Color operator*(const Color &rhs) const
Definition Color.h:73
constexpr bool operator==(const Color &rhs) const
Definition Color.h:27
size_t operator()(const lodestone::level::types::Color &v) const noexcept
Definition Color.h:90