-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathColor.h
More file actions
89 lines (66 loc) · 2.5 KB
/
Color.h
File metadata and controls
89 lines (66 loc) · 2.5 KB
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
81
82
83
84
85
86
87
88
89
/* Color
*
* From: https://github.com/PokemonAutomation/
*
* A very lightweight color class to avoid pulling in <QColor>.
*
*/
#ifndef PokemonAutomation_Color_H
#define PokemonAutomation_Color_H
#include <stdint.h>
#include <string>
namespace PokemonAutomation{
constexpr inline uint32_t combine_argb(uint8_t a, uint8_t r, uint8_t g, uint8_t b){
return (((uint32_t)a << 8 | r) << 8 | g) << 8 | b;
}
constexpr inline uint32_t combine_rgb(uint8_t r, uint8_t g, uint8_t b){
return (((uint32_t)255 << 8 | r) << 8 | g) << 8 | b;
}
class Color{
public:
constexpr Color() : m_argb(0) {}
constexpr explicit Color(uint32_t argb) : m_argb(argb) {}
constexpr Color(uint8_t red, uint8_t green, uint8_t blue) : m_argb(combine_rgb(red, green, blue)) {}
constexpr Color(uint8_t alpha, uint8_t red, uint8_t green, uint8_t blue) : m_argb(combine_argb(alpha, red, green, blue)) {}
constexpr explicit operator bool() const{
return m_argb != 0;
}
constexpr explicit operator uint32_t() const{
return m_argb;
}
bool operator<(Color color) const{
return m_argb < color.m_argb;
}
bool operator==(Color color) const{
return m_argb == color.m_argb;
}
bool operator!=(Color color) const{
return m_argb != color.m_argb;
}
uint8_t alpha () const { return (uint8_t)(m_argb >> 24); }
uint8_t red () const { return (uint8_t)(m_argb >> 16); }
uint8_t green () const { return (uint8_t)(m_argb >> 8); }
uint8_t blue () const { return (uint8_t)(m_argb >> 0); }
// Example: "[0xFFFDBD00 A=255 R=253 G=189 B=00]"
std::string to_string() const;
private:
uint32_t m_argb;
};
constexpr Color COLOR_WHITE(0xffffffff);
constexpr Color COLOR_BLACK(0xff000000);
constexpr Color COLOR_GRAY(0xff808080);
constexpr Color COLOR_RED(0xffff0000);
constexpr Color COLOR_GREEN(0xff00ff00);
constexpr Color COLOR_BLUE(0xff0080ff);
constexpr Color COLOR_DARK_BLUE(0xff0000ff); // Hard to see on dark theme.
constexpr Color COLOR_MAGENTA(0xffff00ff);
constexpr Color COLOR_YELLOW(0xffffff00);
constexpr Color COLOR_CYAN(0xff00ffff);
constexpr Color COLOR_ORANGE(0xffffa500);
//constexpr Color COLOR_PURPLE(0xff800080); // Hard to see on dark theme.
constexpr Color COLOR_PURPLE(0xff8a2be2);
constexpr Color COLOR_DARKGREEN(0xff008000);
constexpr Color COLOR_DARKCYAN(0xff008080);
constexpr Color COLOR_GREEN2(0xff00aa00);
}
#endif