17 #ifndef HEADER_SUPERTUX_VIDEO_COLOR_HPP 18 #define HEADER_SUPERTUX_VIDEO_COLOR_HPP 23 #include <SDL_image.h> 28 static const Color BLACK;
29 static const Color RED;
30 static const Color GREEN;
31 static const Color BLUE;
32 static const Color CYAN;
33 static const Color MAGENTA;
34 static const Color YELLOW;
35 static const Color WHITE;
38 static Color from_rgb888(uint8_t r, uint8_t g, uint8_t b)
40 return Color(static_cast<float>(r) / 255.0f,
41 static_cast<float>(g) / 255.0f,
42 static_cast<float>(b) / 255.0f);
45 static Color from_rgba8888(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255)
47 return Color(static_cast<float>(r) / 255.0f,
48 static_cast<float>(g) / 255.0f,
49 static_cast<float>(b) / 255.0f,
50 static_cast<float>(a) / 255.0f);
56 Color(
float red_,
float green_,
float blue_,
float alpha_ = 1.0);
58 Color(
const std::vector<float>& vals);
60 bool operator==(
const Color& other)
const;
61 bool operator!=(
const Color& other)
const;
63 float greyscale()
const;
65 bool operator < (
const Color& other)
const;
67 std::vector<float> toVector();
69 inline uint8_t r8()
const {
return static_cast<uint8_t
>(255.0f * red); }
70 inline uint8_t g8()
const {
return static_cast<uint8_t
>(255.0f * green); }
71 inline uint8_t b8()
const {
return static_cast<uint8_t
>(255.0f * blue); }
72 inline uint8_t a8()
const {
return static_cast<uint8_t
>(255.0f * alpha); }
74 inline uint32_t rgba()
const 76 return ((static_cast<uint32_t>(a8()) << 24u) |
77 (static_cast<uint32_t>(b8()) << 16u) |
78 (static_cast<uint32_t>(g8()) << 8u) |
79 (static_cast<uint32_t>(r8()) << 0u));
85 return std::to_string(red) +
" " + std::to_string(green) +
" " + std::to_string(blue);
88 SDL_Color to_sdl_color()
const 90 return { r8(), g8(), b8(), a8() };
94 float red, green, blue, alpha;
std::string to_string() const
Return a human-readable string representation for this color.
Definition: color.hpp:83