22#ifndef SDL2PP_COLOR_HH
23#define SDL2PP_COLOR_HH
27#include <SDL_pixels.h>
29#include <SDL2pp/Export.hh>
48class SDL2PP_EXPORT
Color :
public SDL_Color {
56 constexpr Color() : SDL_Color{0, 0, 0, 0} {
65 constexpr Color(
const SDL_Color& color) : SDL_Color{color.r, color.g, color.b, color.a} {
76 constexpr Color(Uint8 r, Uint8 g, Uint8 b) : SDL_Color{r, g, b, SDL_ALPHA_OPAQUE} {
88 constexpr Color(Uint8 r, Uint8 g, Uint8 b, Uint8 a) : SDL_Color{r, g, b, a} {
125 constexpr Uint8 GetRed()
const {
224 return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a;
249SDL2PP_EXPORT std::ostream& operator<<(std::ostream& stream,
const SDL2pp::Color& color);
258struct hash<SDL2pp::Color> {
268 size_t seed = std::hash<int>()(c.r);
269 seed ^= std::hash<int>()(c.g) + 0x9e3779b9 + (seed<<6) + (seed>>2);
270 seed ^= std::hash<int>()(c.b) + 0x9e3779b9 + (seed<<6) + (seed>>2);
271 seed ^= std::hash<int>()(c.a) + 0x9e3779b9 + (seed<<6) + (seed>>2);
RGB color with Alpha.
Definition: Color.hh:48
Color & SetGreen(int ng)
Set the green component from the color.
Definition: Color.hh:160
constexpr Color()
Default constructor.
Definition: Color.hh:56
Color(const Color &) noexcept=default
Copy constructor.
constexpr Uint8 GetAlpha() const
Get the alpha component from the color.
Definition: Color.hh:194
Color & SetAlpha(int na)
Set the alpha component from the color.
Definition: Color.hh:206
Color & SetRed(int nr)
Set the red component from the color.
Definition: Color.hh:137
Color & SetBlue(int nb)
Set the blue component from the color.
Definition: Color.hh:183
constexpr Color(const SDL_Color &color)
Construct a color from existing SDL_Color.
Definition: Color.hh:65
constexpr Uint8 GetBlue() const
Get the blue component from the color.
Definition: Color.hh:171
constexpr Uint8 GetGreen() const
Get the green component from the color.
Definition: Color.hh:148
constexpr Color(Uint8 r, Uint8 g, Uint8 b)
Construct the color from given RGB, alpha is opaque.
Definition: Color.hh:76
constexpr Color(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Construct the color from given RGB and alpha values.
Definition: Color.hh:88
Color(Color &&) noexcept=default
Move constructor.
size_t operator()(const SDL2pp::Color &c) const
Hash function for SDL2pp::Color.
Definition: Color.hh:267