This repository has been archived by the owner on Sep 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
d3dDraw.h
176 lines (148 loc) · 4.41 KB
/
d3dDraw.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
167
168
169
170
171
172
173
174
175
176
#ifndef D3DDRAW_H
#define D3DDRAW_H
#include "pch.h"
namespace d3dHook
{
class Color4 {
public:
int r, g, b, a;
Color4(int cr = 255, int cg = 255, int cb = 255, int ca = 255) {
r = cr; g = cg; b = cb; a = ca;
}
inline Color4 Color4::operator* (const float lhs) { return Color4(r * lhs, g * lhs, b * lhs, a * lhs); }
inline Color4 Color4::operator+ (const Color4 lhs) {
r += lhs.r;
g += lhs.g;
b += lhs.b;
a += lhs.a;
if (r > 255) r = 255;
if (g > 255) g = 255;
if (b > 255) b = 255;
if (a > 255) a = 255;
return *this;
}
};
class Vector2 {
public:
int x, y;
Vector2(int px = 0, int py = 0) {
x = px; y = py;
}
inline Vector2 Vector2::operator+ (const Vector2&lhs) { return Vector2(x + lhs.x, y + lhs.y); }
inline Vector2 Vector2::operator- (const Vector2&lhs) { return Vector2(x - lhs.x, y - lhs.y); }
inline Vector2 Vector2::operator* (const int lhs) { return Vector2(x*lhs, y*lhs); }
inline Vector2 Vector2::operator/ (const int lhs) { return Vector2(x / lhs, y / lhs); }
};
class Box2D {
public:
Vector2 Pos;
Vector2 Size;
Box2D() {
Pos = Vector2();
Size = Vector2();
}
Box2D(Vector2&p, Vector2&s) {
Pos = p;
Size = s;
}
Box2D(int xx, int xy, int xsx, int xsy) {
Pos = Vector2(xx, xy);
Size = Vector2(xsx, xsy);
}
};
void DrawLine(Vector2&p, Vector2&p0, Color4&c);
void DrawCursorLine(Vector2&p, Vector2&p0, Color4&c);
void FillRGB(Box2D&b, Color4&c);
void DrawBox(Box2D&b, float px, Color4&c);
void DrawAndFillBox(Box2D&b, Color4&c, Color4&ac, float px);
void DrawProgressBar(Box2D&b, Color4&c, Color4&ac, Color4&pc, float t, float px0, float px1);
void DrawTabBox(Box2D&b, Color4&c, Color4&ac, Color4&t, char* title);
int DrawString(char* String, Vector2&p, Color4&c, ID3DXFont* ifont);
int DrawString(char* String, Vector2&p, Color4&c, ID3DXFont* ifont)
{
RECT ShadowPos;
ShadowPos.left = p.x + 1;
ShadowPos.top = p.y + 1;
RECT FontPos;
FontPos.left = p.x;
FontPos.top = p.y;
ifont->DrawTextA(0, String, strlen(String), &ShadowPos, DT_NOCLIP, D3DCOLOR_ARGB(c.a, c.r / 3, c.g / 3, c.b / 3));
ifont->DrawTextA(0, String, strlen(String), &FontPos, DT_NOCLIP, D3DCOLOR_ARGB(c.a, c.r, c.g, c.b));
return 0;
}
void FillRGB(Box2D&b, Color4&c)
{
D3DXVECTOR2 vLine[2];
p_Line->SetWidth(b.Size.x);
vLine[0].x = b.Pos.x + b.Size.x / 2;
vLine[0].y = b.Pos.y;
vLine[1].x = b.Pos.x + b.Size.x / 2;
vLine[1].y = b.Pos.y + b.Size.y;
p_Line->Begin();
p_Line->Draw(vLine, 2, D3DCOLOR_RGBA(c.r, c.g, c.b, c.a));
p_Line->End();
}
void DrawLine(Vector2&p, Vector2&p0, Color4&c)
{
D3DXVECTOR2 dLine[2];
p_Line->SetWidth(1);
dLine[0].x = p.x;
dLine[0].y = p.y;
dLine[1].x = p0.x;
dLine[1].y = p0.y;
p_Line->Draw(dLine, 2, D3DCOLOR_ARGB(c.a, c.r, c.g, c.b));
}
void DrawCursorLine(Vector2&p, Vector2&p0, Color4&c)
{
D3DXVECTOR2 dLine[2];
p_Line->SetWidth(2);
dLine[0].x = p.x;
dLine[0].y = p.y;
dLine[1].x = p0.x;
dLine[1].y = p0.y;
p_Line->Draw(dLine, 2, D3DCOLOR_ARGB(c.a, c.r, c.g, c.b));
}
void DrawBox(Box2D&b, float px, Color4&c)
{
D3DXVECTOR2 points[5];
points[0] = D3DXVECTOR2(b.Pos.x, b.Pos.y);
points[1] = D3DXVECTOR2(b.Pos.x + b.Size.x, b.Pos.y);
points[2] = D3DXVECTOR2(b.Pos.x + b.Size.x, b.Pos.y + b.Size.y);
points[3] = D3DXVECTOR2(b.Pos.x, b.Pos.y + b.Size.y);
points[4] = D3DXVECTOR2(b.Pos.x, b.Pos.y);
p_Line->SetWidth(px);
p_Line->Draw(points, 5, D3DCOLOR_RGBA(c.r, c.g, c.b, c.a));
}
void DrawAndFillBox(Box2D&b, Color4&c, Color4&ac, float px = 1)
{
Box2D fill = b;
fill.Pos.x += 1;
fill.Pos.y += 1;
fill.Size.x -= 1;
fill.Size.y -= 1;
DrawBox(b, px, c);
FillRGB(fill, ac);
}
void DrawProgressBar(Box2D&b, Color4&c, Color4&ac, Color4&pc, float t, float px0 = 1, float px1 = 1)
{
Box2D prog = b;
prog.Size.x = floor(prog.Size.x * t);
FillRGB(b, ac);
if (prog.Size.x > 0)
{
FillRGB(prog, pc);
DrawBox(prog, px1, c);
}
DrawBox(b, px0, c);
}
void DrawTabBox(Box2D&b, Color4&c, Color4&ac, Color4&t, char* title)
{
Vector2 sOff = Vector2(b.Pos.x + 3, b.Pos.y);
Vector2 lOff = Vector2(b.Pos.x, b.Pos.y + 16);
Vector2 lEnd = Vector2(b.Pos.x + b.Size.x, b.Pos.y + 16);
FillRGB(b, ac);
DrawLine(lOff, lEnd, c);
DrawString(title, sOff, t, pFontSmall);
}
}
#endif