1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/*
* Copyright (C) 2002-2025 by the Widelands Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <https://www.gnu.org/licenses/>.
*
*/
#ifndef WL_GRAPHIC_COLOR_H
#define WL_GRAPHIC_COLOR_H
#include <string>
#include <SDL_pixels.h>
struct RGBColor {
RGBColor(uint8_t R, uint8_t G, uint8_t B);
RGBColor(const RGBColor& other) = default;
explicit RGBColor(uint32_t);
// Initializes the color to black.
RGBColor();
// Returns this color in hex format.
[[nodiscard]] std::string hex_value() const;
// Map this color to the given 'fmt'
[[nodiscard]] uint32_t map(const SDL_PixelFormat& fmt) const;
// Set it to the given 'clr' which is interpretes through 'fmt'.
void set(SDL_PixelFormat* fmt, uint32_t clr);
RGBColor& operator=(const RGBColor& other) = default;
bool operator!=(const RGBColor& other) const;
bool operator==(const RGBColor& other) const;
uint8_t r, g, b;
};
struct RGBAColor {
RGBAColor(uint8_t R, uint8_t G, uint8_t B, uint8_t A);
explicit RGBAColor(uint32_t);
RGBAColor(const RGBAColor& other) = default;
// Initializes the color to black.
RGBAColor();
// Initializes to opaque color.
RGBAColor(const RGBColor& c); // NOLINT allow implicit conversion
// Returns this color in hex format.
[[nodiscard]] std::string hex_value() const;
// Map this color to the given 'fmt'
[[nodiscard]] uint32_t map(const SDL_PixelFormat& fmt) const;
// Set it to the given 'clr' which is interpretes through 'fmt'.
void set(const SDL_PixelFormat& fmt, uint32_t clr);
RGBAColor& operator=(const RGBAColor& other) = default;
bool operator!=(const RGBAColor& other) const;
bool operator==(const RGBAColor& other) const;
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
};
#endif // end of include guard: WL_GRAPHIC_COLOR_H
|