16#include <glm/gtx/norm.hpp>
18#include "AUI/Traits/values.h"
29 constexpr AColor(): glm::vec4(0, 0, 0, 1.f)
32 constexpr AColor(
const glm::vec4& v): glm::vec4(v){}
35 constexpr AColor(
float scalar) : glm::vec4(scalar) {}
36 constexpr AColor(
float r,
float g,
float b) : glm::vec4(r, g, b, 1.f) {}
37 constexpr AColor(
float r,
float g,
float b,
float a) : glm::vec4(r, g, b, a) {}
44 constexpr AColor(
unsigned int color) : glm::vec4(
45 ((color >> 24) & 0xff) / 255.f,
46 ((color >> 16) & 0xff) / 255.f,
47 ((color >> 8) & 0xff) / 255.f,
48 ((color) & 0xff) / 255.f) {}
55 static constexpr AColor fromAARRGGBB(
unsigned int color)
58 ((color >> 16) & 0xff) / 255.f,
59 ((color >> 8) & 0xff) / 255.f,
60 ((color) & 0xff) / 255.f,
61 ((color >> 24) & 0xff) / 255.f,
70 static constexpr AColor fromRRGGBB(
unsigned int color)
73 ((color >> 16) & 0xff) / 255.f,
74 ((color >> 8) & 0xff) / 255.f,
75 ((color) & 0xff) / 255.f,
80 constexpr AColor operator*(
float other)
const
82 return AColor(x * other, y * other, z * other, w * other);
85 API_AUI_CORE
AString toString()
const;
87 API_AUI_CORE
float readabilityOfForegroundColor(
const AColor &foreground);
116 return glm::clamp(glm::vec4(r * d, g * d, b * d, a), glm::vec4(0.f), glm::vec4(1.f));
118 inline constexpr AColor darker(
float d)
const {
121 inline constexpr AColor lighter(
float d)
const {
125 bool isFullyTransparent()
const {
128 bool isFullyOpaque()
const {
132 AColor readableBlackOrWhite()
const {
133 return glm::length2(glm::vec3{*
this}) > 1.5f ? fromRRGGBB(0) : fromRRGGBB(0xffffff);
137 return {x, y, z, a * d};
140 static const AColor BLACK;
141 static const AColor WHITE;
143 static const AColor GREEN;
148inline const AColor AColor::BLACK = {0.f, 0.f, 0.f, 1.f};
149inline const AColor AColor::WHITE = {1.f, 1.f, 1.f, 1.f};
150inline const AColor AColor::RED = {1.f, 0.f, 0.f, 1.f};
151inline const AColor AColor::GREEN = {0.f, 1.f, 0.f, 1.f};
152inline const AColor AColor::BLUE = {0.f, 0.f, 1.f, 1.f};
153inline const AColor AColor::GRAY = {0.5f, 0.5f, 0.5f, 1.f};
156inline std::ostream& operator<<(std::ostream& o,
const AColor& color) {
159 if (!color.isFullyOpaque()) {
160 std::snprintf(buf,
sizeof(buf),
"%02x", uint8_t(color.a * 255.f));
163 std::snprintf(buf,
sizeof(buf),
"%02x%02x%02x", uint8_t(color.r * 255.f), uint8_t(color.g * 255.f), uint8_t(color.b * 255.f));
173inline constexpr AColor operator""_argb(
unsigned long long v)
175 return AColor::fromAARRGGBB(
unsigned(v));
184inline constexpr AColor operator""_rgb(
unsigned long long v)
186 assert((
"_rgb literal should be in 0xrrggbb format, not 0xaarrggbb" && !(v & 0xff000000u)));
187 return AColor::fromRRGGBB(
unsigned(v));
198 [[nodiscard]]
AColor toRGB()
const noexcept;
Represents a 4-component floating point color.
Definition: AColor.h:27
constexpr AColor mul(float d) const
Multiply all color components except alpha channel (rgb * d, a)
Definition: AColor.h:115
AColor transparentize(float alpha) const noexcept
Decreases the alpha channel by the given value.
Definition: AColor.h:104
AColor opacify(float alpha) const noexcept
Increases the alpha channel by the given value.
Definition: AColor.h:94
Represents a Unicode character string.
Definition: AString.h:37
Clamps the possible values for a number to the specified range: [min;max].
Definition: values.h:452