-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdrawing.cpp
More file actions
166 lines (132 loc) · 6.63 KB
/
Copy pathdrawing.cpp
File metadata and controls
166 lines (132 loc) · 6.63 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
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
#include "drawing.h"
namespace Overlay::Drawing {
static constexpr DWORD c_black = 0x000000;
static constexpr DWORD c_bg_dark = 0x1C1C1C;
static constexpr DWORD c_bg_shield = 0x0A0A0A;
static constexpr DWORD c_health_hi = 0x00FF00;
static constexpr DWORD c_health_md = 0xFF6300;
static constexpr DWORD c_health_lo = 0xFF0000;
static constexpr DWORD c_shield_white = 0xF7F7F7;
static constexpr DWORD c_shield_blue = 0x27B2FF;
static constexpr DWORD c_shield_purple = 0xCE3BFF;
static constexpr DWORD c_shield_gold = 0xFFFF4F;
static constexpr DWORD c_shield_red = 0xDB0202;
static constexpr DWORD c_shield_crack = 0x616161;
static auto ShieldColor(int armor_type) noexcept -> DWORD {
switch (armor_type) {
case 1: return c_shield_white;
case 2: return c_shield_blue;
case 3: return c_shield_purple;
case 4: return c_shield_gold;
case 5: return c_shield_red;
default: return c_shield_white;
}
}
auto Line(Sdk::OSD& draw, int x1, int y1, int x2, int y2, DWORD color, int thickness) noexcept -> void {
if (thickness < 1) thickness = 1;
if (y1 == y2) {
int x = x1 < x2 ? x1 : x2;
int w = x1 < x2 ? x2 - x1 : x1 - x2;
if (w < 1) w = 1;
draw.FilledRect(x, y1, w, thickness, color);
return;
}
if (x1 == x2) {
int y = y1 < y2 ? y1 : y2;
int h = y1 < y2 ? y2 - y1 : y1 - y2;
if (h < 1) h = 1;
draw.FilledRect(x1, y, thickness, h, color);
}
}
auto Rect(Sdk::OSD& draw, int x, int y, int w, int h, DWORD color, int thickness) noexcept -> void {
if (thickness < 1) thickness = 1;
draw.FilledRect(x, y, w, thickness, color);
draw.FilledRect(x, y + h - thickness, w, thickness, color);
draw.FilledRect(x, y, thickness, h, color);
draw.FilledRect(x + w - thickness, y, thickness, h, color);
}
auto FilledBox(Sdk::OSD& draw, int x, int y, int w, int h, DWORD color) noexcept -> void {
draw.FilledRect(x, y, w, h, color);
}
auto CorneredBox(Sdk::OSD& draw, int x, int y, int w, int h, DWORD color, int thickness) noexcept -> void {
if (thickness < 1) thickness = 1;
int line_w = w / 3;
int line_h = h / 3;
draw.FilledRect(x, y, line_w, thickness, color);
draw.FilledRect(x, y, thickness, line_h, color);
draw.FilledRect(x + w - line_w, y, line_w, thickness, color);
draw.FilledRect(x + w - thickness, y, thickness, line_h, color);
draw.FilledRect(x, y + h - thickness, line_w, thickness, color);
draw.FilledRect(x, y + h - line_h, thickness, line_h, color);
draw.FilledRect(x + w - line_w, y + h - thickness, line_w, thickness, color);
draw.FilledRect(x + w - thickness, y + h - line_h, thickness, line_h, color);
}
auto QuadFilled(Sdk::OSD& draw, int x, int y, int w, int h, DWORD color) noexcept -> void {
draw.FilledRect(x, y, w, h, color);
}
auto TextOutline(Sdk::OSD& draw, int x, int y, DWORD color, const char* str) noexcept -> void {
if (!str) return;
draw.Text(x - 1, y, c_black, str);
draw.Text(x + 1, y, c_black, str);
draw.Text(x, y - 1, c_black, str);
draw.Text(x, y + 1, c_black, str);
draw.Text(x, y, color, str);
}
auto HealthBar(Sdk::OSD& draw, int x, int y, int width, int height, float health) noexcept -> void {
DWORD color;
if (health > 75.0f) color = c_health_hi;
else if (health > 45.0f) color = c_health_md;
else color = c_health_lo;
float pct = health / 100.0f;
if (pct < 0.0f) pct = 0.0f;
if (pct > 1.0f) pct = 1.0f;
int fill_w = static_cast<int>(static_cast<float>(width) * pct);
draw.FilledRect(x - 1, y - 1, width + 2, height + 2, c_black);
draw.FilledRect(x, y, width, height, c_bg_dark);
if (fill_w > 0)
draw.FilledRect(x, y, fill_w, height, color);
}
auto ShieldBar(Sdk::OSD& draw, int x, int y, int width, int height, int shield, int armor_type, bool stacked) noexcept -> void {
if (armor_type < 1 || armor_type > 5) return;
DWORD color = ShieldColor(armor_type);
constexpr int k_max_shield = 125;
float pct = static_cast<float>(shield) / static_cast<float>(k_max_shield);
if (pct < 0.0f) pct = 0.0f;
if (pct > 1.0f) pct = 1.0f;
int fill_w = static_cast<int>(static_cast<float>(width) * pct);
DWORD bg = stacked ? c_bg_shield : c_bg_dark;
draw.FilledRect(x - 1, y - 1, width + 2, height + 2, c_black);
draw.FilledRect(x, y, width, height, bg);
if (fill_w > 0)
draw.FilledRect(x, y, fill_w, height, color);
}
auto SeerHealth(Sdk::OSD& draw, int x, int y, int shield, int armor_type, int health) noexcept -> void {
constexpr int k_bar_w = 80;
constexpr int k_bar_h = 4;
constexpr int k_seg_h = 3;
constexpr int k_steps = 5;
constexpr int k_step_v = 25;
int bar_x = x - k_bar_w / 2;
draw.FilledRect(bar_x - 4, y - 10, k_bar_w + 8, k_bar_h + k_seg_h + 8, c_black);
float hp = static_cast<float>(health) / 100.0f;
if (hp < 0.0f) hp = 0.0f;
if (hp > 1.0f) hp = 1.0f;
int health_w = static_cast<int>(static_cast<float>(k_bar_w) * hp);
draw.FilledRect(bar_x, y - 6, k_bar_w, k_bar_h, c_bg_dark);
if (health_w > 0)
draw.FilledRect(bar_x, y - 6, health_w, k_bar_h, c_health_hi);
DWORD col = ShieldColor(armor_type);
int seg_w = (k_bar_w - (k_steps - 1)) / k_steps;
int remaining = shield;
for (int i = 0; i < k_steps; i++) {
int sx = bar_x + i * (seg_w + 1);
int sy = y - 1;
int seg_val = remaining > k_step_v ? k_step_v : (remaining < 0 ? 0 : remaining);
int seg_fill = static_cast<int>(static_cast<float>(seg_w) * static_cast<float>(seg_val) / static_cast<float>(k_step_v));
draw.FilledRect(sx, sy, seg_w, k_seg_h, c_shield_crack);
if (seg_fill > 0)
draw.FilledRect(sx, sy, seg_fill, k_seg_h, col);
remaining -= k_step_v;
}
}
}