24 Color(uint8_t
r, uint8_t
g, uint8_t
b, uint8_t
a = 255)
42 return {
static_cast<uint8_t
>(
r * 255),
static_cast<uint8_t
>(
g * 255),
43 static_cast<uint8_t
>(
b * 255),
static_cast<uint8_t
>(
a * 255)};
50 return {sdlColor.r, sdlColor.g, sdlColor.b, sdlColor.a};
59 if (hex.empty() || hex[0] !=
'#' ||
60 (hex.length() != 7 && hex.length() != 9)) {
64 uint8_t
r = std::stoi(hex.substr(1, 2),
nullptr, 16);
65 uint8_t
g = std::stoi(hex.substr(3, 2),
nullptr, 16);
66 uint8_t
b = std::stoi(hex.substr(5, 2),
nullptr, 16);
69 if (hex.length() == 9) {
70 a = std::stoi(hex.substr(7, 2),
nullptr, 16);
const Color lightslategrey
const Color darkturquoise
const Color blanchedalmond
const Color lightseagreen
const Color mediumseagreen
const Color mediumslateblue
const Color cornflowerblue
const Color lightgoldenrodyellow
const Color palevioletred
const Color rebeccapurple
const Color paleturquoise
const Color mediumaquamarine
const Color darkslategrey
const Color darkslateblue
const Color darkolivegreen
const Color lavenderblush
const Color lightslategray
const Color mediumspringgreen
const Color mediumvioletred
const Color darkslategray
const Color mediumturquoise
const Color darkgoldenrod
const Color lightsteelblue
const Color palegoldenrod
RGBA color struct with 8-bit channels.
static Color fromHex(const std::string &hex)
From a hex string (e.g. "#RRGGBBAA") to a Color.
static Color fromSDLColor(const SDL_Color &sdlColor)
Convert from an SDL_Color to a Color.
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Construct a Color from RGBA values.
SDL_Color toSDLColor() const
Convert to an SDL_Color.
static Color fromFloat(float r, float g, float b, float a=1.0F)
From float RGBA values (0.0-1.0) to Color.
Color()
Construct a default Color (black, fully opaque).