-
Notifications
You must be signed in to change notification settings - Fork 1
/
DrawUtils.cpp
140 lines (133 loc) · 3.74 KB
/
DrawUtils.cpp
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
#include "DrawUtils.h"
#include "SDK.h"
CFonts gFonts;
CTextures gTex;
//===================================================================================
void CFonts::Initialize()
{
arial = gInts.Surface->CreateFont();
verdana_bold = gInts.Surface->CreateFont();
verdana = gInts.Surface->CreateFont();
segoe = gInts.Surface->CreateFont();
calibri_light = gInts.Surface->CreateFont();
calibri_light_small = gInts.Surface->CreateFont();
cambria = gInts.Surface->CreateFont();
esp = gInts.Surface->CreateFont();
}
void CFonts::Reload()
{
gInts.Surface->SetFontGlyphSet(gFonts.arial, "Arial", ESP_HEIGHT, 500, 0, 0, FONTFLAG_OUTLINE);
gInts.Surface->SetFontGlyphSet(gFonts.verdana_bold, "Verdana", 14, 800, 0, 0, FONTFLAG_ANTIALIAS);
gInts.Surface->SetFontGlyphSet(gFonts.verdana, "Verdana", 14, 0, 0, 0, FONTFLAG_ANTIALIAS);
gInts.Surface->SetFontGlyphSet(gFonts.segoe, "Segoe UI", 24, 250, 0, 0, FONTFLAG_ANTIALIAS);
gInts.Surface->SetFontGlyphSet(gFonts.calibri_light, "Calibri Light", 24, 250, 0, 0, FONTFLAG_ANTIALIAS);
gInts.Surface->SetFontGlyphSet(gFonts.calibri_light_small, "Calibri Light", 18, 250, 0, 0, FONTFLAG_ANTIALIAS);
gInts.Surface->SetFontGlyphSet(gFonts.cambria, "Cambria", 48, 1000, 0, 0, FONTFLAG_ANTIALIAS);
gInts.Surface->SetFontGlyphSet(gFonts.esp, "Verdana", 14, 800, 0, 0, FONTFLAG_OUTLINE);
}
//===================================================================================
void CTextures::Initialize()
{
dark_gray = gInts.Surface->CreateNewTextureID();
}
void CTextures::Reload()
{
static const byte dark_gray_t[4] = { 50, 50, 50, 255 };
gInts.Surface->DrawSetTextureRGBA(dark_gray, dark_gray_t, 1, 1);
}
//===================================================================================
TextureHolder::TextureHolder(const byte* pRawRGBAData, int W, int H)
{
m_iTexture = gInts.Surface->CreateNewTextureID(true);
if (!m_iTexture)
return;
gInts.Surface->DrawSetTextureRGBA(m_iTexture, pRawRGBAData, W, H);
rawData = pRawRGBAData;
m_iW = W, m_iH = H;
m_bValid = true;
}
bool TextureHolder::Draw(int x, int y, Color clr, float scale)
{
if (!gInts.Surface->IsTextureIDValid(m_iTexture))
return false;
gInts.Surface->DrawSetColor(clr[0], clr[1], clr[2], clr[3]);
gInts.Surface->DrawSetTexture(m_iTexture);
gInts.Surface->DrawTexturedRect(x, y, x + (m_iW * scale), y + (m_iH * scale));
return true;
}
//===================================================================================
inline void ClampFl(float &fl)
{
if (fl > 1)
fl = 1;
else if (fl < 0)
fl = 0;
}
Color Color::FromHSB(float Hue, float Saturation, float Brightness, int Alpha)
{
while (Hue >= 1)
Hue -= 1;
while (Hue <= 0)
Hue += 1;
ClampFl(Saturation);
ClampFl(Brightness);
float h = Hue == 1.0f ? 0 : Hue * 6.0f;
float f = h - (int)h;
float p = Brightness * (1.0f - Saturation);
float q = Brightness * (1.0f - Saturation * f);
float t = Brightness * (1.0f - (Saturation * (1.0f - f)));
if (h < 1)
{
return Color(
(unsigned char)(Brightness * 255),
(unsigned char)(t * 255),
(unsigned char)(p * 255),
Alpha
);
}
else if (h < 2)
{
return Color(
(unsigned char)(q * 255),
(unsigned char)(Brightness * 255),
(unsigned char)(p * 255),
Alpha
);
}
else if (h < 3)
{
return Color(
(unsigned char)(p * 255),
(unsigned char)(Brightness * 255),
(unsigned char)(t * 255),
Alpha
);
}
else if (h < 4)
{
return Color(
(unsigned char)(p * 255),
(unsigned char)(q * 255),
(unsigned char)(Brightness * 255),
Alpha
);
}
else if (h < 5)
{
return Color(
(unsigned char)(t * 255),
(unsigned char)(p * 255),
(unsigned char)(Brightness * 255),
Alpha
);
}
else
{
return Color(
(unsigned char)(Brightness * 255),
(unsigned char)(p * 255),
(unsigned char)(q * 255),
Alpha
);
}
}