16#include <glm/gtx/norm.hpp>
18#include "AUI/Traits/values.h"
26class AColor :
public glm::vec4 {
28 constexpr AColor() : glm::vec4(0, 0, 0, 1.f) {}
29 constexpr AColor(
const glm::vec4& v) : glm::vec4(v) {}
31 API_AUI_CORE AColor(
const AString& s);
32 constexpr AColor(
float scalar) : glm::vec4(scalar) {}
33 constexpr AColor(
float r,
float g,
float b) : glm::vec4(r, g, b, 1.f) {}
34 constexpr AColor(
float r,
float g,
float b,
float a) : glm::vec4(r, g, b, a) {}
43 : glm::vec4(((color >> 24) & 0xff) / 255.f, ((color >> 16) & 0xff) / 255.f, ((color >> 8) & 0xff) / 255.f,
44 ((color) & 0xff) / 255.f) {}
54 ((color >> 16) & 0xff) / 255.f,
55 ((color >> 8) & 0xff) / 255.f,
56 ((color) & 0xff) / 255.f,
57 ((color >> 24) & 0xff) / 255.f,
69 ((color >> 16) & 0xff) / 255.f,
70 ((color >> 8) & 0xff) / 255.f,
71 ((color) & 0xff) / 255.f,
76 constexpr AColor operator*(
float other)
const {
return AColor(x * other, y * other, z * other, w * other); }
78 API_AUI_CORE AString toString()
const;
80 API_AUI_CORE
float readabilityOfForegroundColor(
const AColor& foreground);
86 AColor
opacify(
float alpha)
const noexcept {
107 inline constexpr AColor
mul(
float d)
const {
108 return glm::clamp(glm::vec4(r * d, g * d, b * d, a), glm::vec4(0.f), glm::vec4(1.f));
110 inline constexpr AColor darker(
float d)
const {
return mul(1.f - d); }
111 inline constexpr AColor lighter(
float d)
const {
return mul(1.f + d); }
113 bool isFullyTransparent()
const {
return a < 0.001f; }
114 bool isFullyOpaque()
const {
return a > 0.999f; }
116 AColor readableBlackOrWhite()
const {
120 AColor
opacify(
float d) {
return { x, y, z, a * d }; }
122 static const AColor BLACK;
123 static const AColor WHITE;
124 static const AColor RED;
125 static const AColor GREEN;
126 static const AColor BLUE;
127 static const AColor GRAY;
130inline const AColor AColor::BLACK = { 0.f, 0.f, 0.f, 1.f };
131inline const AColor AColor::WHITE = { 1.f, 1.f, 1.f, 1.f };
132inline const AColor AColor::RED = { 1.f, 0.f, 0.f, 1.f };
133inline const AColor AColor::GREEN = { 0.f, 1.f, 0.f, 1.f };
134inline const AColor AColor::BLUE = { 0.f, 0.f, 1.f, 1.f };
135inline const AColor AColor::GRAY = { 0.5f, 0.5f, 0.5f, 1.f };
137inline std::ostream& operator<<(std::ostream& o,
const AColor& color) {
140 if (!color.isFullyOpaque()) {
141 std::snprintf(buf,
sizeof(buf),
"%02x", uint8_t(color.a * 255.f));
145 buf,
sizeof(buf),
"%02x%02x%02x", uint8_t(color.r * 255.f), uint8_t(color.g * 255.f), uint8_t(color.b * 255.f));
164inline constexpr AColor operator""_rgb(
unsigned long long v) {
165 assert((
"_rgb literal should be in 0xrrggbb format, not 0xaarrggbb" && !(v & 0xff000000u)));
174 aui::float_within_0_1 hue = 0.f;
175 aui::float_within_0_1 saturation = 0.f;
176 aui::float_within_0_1 value = 0.f;
180 [[nodiscard]]
AColor toRGB()
const noexcept;
Represents a 4-component floating point color (RGBA).
Definition AColor.h:26
constexpr AColor(unsigned int color)
Construct with hex integer.
Definition AColor.h:42
constexpr AColor mul(float d) const
Multiply all color components except alpha channel (rgb * d, a)
Definition AColor.h:107
AColor transparentize(float alpha) const noexcept
Decreases the alpha channel by the given value.
Definition AColor.h:96
AColor opacify(float alpha) const noexcept
Increases the alpha channel by the given value.
Definition AColor.h:86
static constexpr AColor fromRRGGBB(unsigned int color)
Construct with hex integer.
Definition AColor.h:67
static constexpr AColor fromAARRGGBB(unsigned int color)
Construct with hex integer.
Definition AColor.h:52
Represents a Unicode character string.
Definition AString.h:37
Represents a 3-component floating point color (HSV).
Definition AColor.h:173