4 #include <SDL_pixels.h> 14 constexpr
Color() : SDL_Color{0, 0, 0, 255} {}
21 constexpr
Color(Uint8 r, Uint8 g, Uint8 b, Uint8
a = 255)
22 : SDL_Color{r, g, b,
a}
33 Color(Uint32 raw, SDL_PixelFormat
const& format)
35 SDL_GetRGBA(raw, &format, &r, &g, &b, &
a);
39 Color(Uint32 raw, Uint32 format)
41 auto f = SDL_AllocFormat(format);
42 if (!f)
throw Exception{
"SDL_AllocFormat"};
43 SDL_GetRGBA(raw, f, &r, &g, &b, &
a);
55 Uint32
as_uint(SDL_PixelFormat
const& format)
const 57 if (SDL_ISPIXELFORMAT_ALPHA(format.format))
59 return SDL_MapRGBA(&format, r, g, b,
a);
63 return SDL_MapRGB(&format, r, g, b);
70 auto f = SDL_AllocFormat(format);
71 if (!f)
throw Exception{
"SDL_AllocFormat"};
80 return r == c.r && g == c.g && b == c.b &&
a == c.a;
86 return stream <<
"(r:" << c.r <<
",g:" << c.g <<
",b:" << c.b
87 <<
",a:" << c.a <<
")";
90 static constexpr
Color White() {
return {255, 255, 255, 255}; }
91 static constexpr
Color Black() {
return {0, 0, 0, 255}; }
92 static constexpr
Color Red() {
return {255, 0, 0, 255}; }
93 static constexpr
Color Green() {
return {0, 255, 0, 255}; }
94 static constexpr
Color Blue() {
return {0, 0, 255, 255}; }
constexpr Color()
Construct an sdl::Color object. Color will be black by default.
Color(Uint32 raw, Uint32 format)
Converting constructor that will initialize the color with a given 32 bit value, according to the pro...
static constexpr Color Black()
static constexpr Color Transparent()
Color(Uint32 raw, SDL_PixelFormat const &format)
Converting constructor that will initialize the color with a given 32 bit value, according to the pro...
static constexpr Color White()
Color & operator=(Color const &)=default
Default copy assing operator.
friend std::ostream & operator<<(std::ostream &stream, Color const &c)
Output stream overload that will print the value of the current color as a 4D vector of 8bit numbers...
C++ wrapping around the SDL_Color structure.
Define to deactivate exception support.
constexpr Color(Uint8 r, Uint8 g, Uint8 b, Uint8 a=255)
Construct an sdl Color::object with the given 8 bit color values.
Uint32 as_uint(Uint32 format) const
Return the color of the current object as a 32bit number (4 bytes)
static constexpr Color Blue()
Define to deactivate exception support.
static constexpr Color Red()
bool operator==(Color const &c) const
Return true if both colors are identical.
Uint32 as_uint(SDL_PixelFormat const &format) const
Return the color of the current object as a 32bit number (4 bytes)
static constexpr Color Green()