forked from Ares-Developers/YRpp
-
Notifications
You must be signed in to change notification settings - Fork 30
/
BasicStructures.h
166 lines (129 loc) · 3.09 KB
/
BasicStructures.h
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#pragma once
#include <Matrix3D.h>
struct Color16Struct;
//used for most colors
struct ColorStruct
{
ColorStruct() = default;
ColorStruct(BYTE const r, BYTE const g, BYTE const b)
: R(r), G(g), B(b)
{ }
ColorStruct(const ColorStruct& c)
: R(c.R), G(c.G), B(c.B)
{ }
inline explicit ColorStruct(Color16Struct const color);
explicit ColorStruct(DWORD const color) {
memcpy(this, &color, sizeof(ColorStruct));
}
inline explicit ColorStruct(WORD const color);
bool operator == (ColorStruct const rhs) const {
return R == rhs.R && G == rhs.G && B == rhs.B;
}
bool operator != (ColorStruct const rhs) const {
return !(*this == rhs);
}
explicit operator DWORD() const {
DWORD ret = 0;
memcpy(&ret, this, sizeof(ColorStruct));
return ret;
}
inline explicit operator WORD() const;
BYTE R, G, B;
};
struct BytePalette {
ColorStruct Entries[256];
ColorStruct& operator [](int const idx) {
return this->Entries[idx];
}
ColorStruct const& operator [](int const idx) const {
return this->Entries[idx];
}
};
//used for light colors
struct TintStruct
{
TintStruct() = default;
TintStruct(int r, int g, int b) :Red { r }, Green { g }, Blue { b }{}
int Red, Green, Blue;
bool operator == (TintStruct const rhs) const
{
return Red == rhs.Red && Green == rhs.Green && Blue == rhs.Blue;
}
bool operator != (TintStruct const rhs) const
{
return !(*this == rhs);
}
bool operator < (TintStruct const rhs) const
{
if (Red < rhs.Red)
return true;
if (Green < rhs.Green)
return true;
if (Blue < rhs.Blue)
return true;
return false;
}
};
//16bit colors
#pragma pack(push, 1)
struct Color16Struct
{
Color16Struct() = default;
explicit Color16Struct(ColorStruct const color) :
B(static_cast<unsigned short>(color.B >> 3u)),
G(static_cast<unsigned short>(color.G >> 2u)),
R(static_cast<unsigned short>(color.R >> 3u))
{ }
explicit Color16Struct(WORD const color) {
memcpy(this, &color, sizeof(Color16Struct));
}
explicit Color16Struct(DWORD const color)
: Color16Struct(ColorStruct(color))
{ }
bool operator == (Color16Struct const rhs) const {
return R == rhs.R && G == rhs.G && B == rhs.B;
}
bool operator != (Color16Struct const rhs) const {
return !(*this == rhs);
}
explicit operator WORD() const {
WORD ret;
memcpy(&ret, this, sizeof(Color16Struct));
return ret;
}
explicit operator DWORD() const {
return static_cast<DWORD>(ColorStruct(*this));
}
unsigned short B : 5;
unsigned short G : 6;
unsigned short R : 5;
};
#pragma pack(pop)
inline ColorStruct::ColorStruct(Color16Struct const color) :
B(static_cast<BYTE>(color.B << 3u | color.B >> 2u)),
G(static_cast<BYTE>(color.G << 2u | color.G >> 4u)),
R(static_cast<BYTE>(color.R << 3u | color.R >> 2u))
{ }
inline ColorStruct::ColorStruct(WORD const color) :
ColorStruct(Color16Struct(color))
{ }
ColorStruct::operator WORD() const {
return static_cast<WORD>(Color16Struct(*this));
}
//Random number range
struct RandomStruct
{
int Min, Max;
};
//obvious
struct RectangleStruct
{
int X, Y, Width, Height;
};
struct LTRBStruct
{
int Left;
int Top;
int Right;
int Bottom;
};