This repository has been archived by the owner on Mar 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Drawings.cpp
executable file
·75 lines (62 loc) · 2.34 KB
/
Drawings.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
#include "main.hpp"
HFONT testfont;
void CDrawings::DrawBox(int x, int y, int w, int h, Color color) {
pSurface->DrawSetColor(color);
pSurface->DrawOutlinedRect(x, y, x + w, y + h);
}
void CDrawings::FillRGBA(int x, int y, int w, int h, Color color) {
pSurface->DrawSetColor(color);
pSurface->DrawFilledRect(x, y, x + w, y + h);
}
void CDrawings::DrawLine(int x, int y, int xx, int yy, Color color) {
pSurface->DrawSetColor(color);
pSurface->DrawLine(x, y, xx, yy);
}
std::wstring StringToWstring(std::string str) {
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
try
{
return converter.from_bytes(str);
}
catch (std::range_error)
{
std::wostringstream s;
s << str.c_str();
return s.str();
}
}
void CDrawings::DrawString(int x, int y, Color color, HFONT font, const wchar_t* szString) {
pSurface->DrawSetTextPos(x, y);
pSurface->DrawSetTextFont(font);
pSurface->DrawSetTextColor(color);
pSurface->DrawPrintText(szString, wcslen(szString));
}
void CDrawings::DrawString(int x, int y, Color color, HFONT font, const char* szString) {
std::wstring wString = StringToWstring(szString);
pSurface->DrawSetTextPos(x, y);
pSurface->DrawSetTextFont(font);
pSurface->DrawSetTextColor(color);
pSurface->DrawPrintText(wString.c_str(), wcslen(wString.c_str()));
}
void CDrawings::DrawString(int x, int y, Color color, HFONT font, bool bCenter, const char* szString) {
std::wstring wString = StringToWstring(szString);
if(bCenter) {
int wide, tall;
pSurface->GetTextSize(font, wString.c_str(), wide, tall);
x -= wide / 2;
y -= tall / 2;
}
pSurface->DrawSetTextPos(x, y);
pSurface->DrawSetTextFont(font);
pSurface->DrawSetTextColor(color);
pSurface->DrawPrintText(wString.c_str(), wcslen(wString.c_str()));
}
void CDrawings::DrawHealthbar(int x, int y, int w, int h, int health, Color color) {
if(health > 100)
health = 100; // Just a fix, tried without this on Zombie servers.. you don't wanna know what happend.
int hw = h - ((h) * health) / 100;
this->FillRGBA(x, y - 1, w, h + 2, Color(0, 0, 0, 120));
this->FillRGBA(x, y + hw - 1, w, h - hw + 2, color);
this->DrawBox(x, y - 1, w, h + 2, Color(0, 0, 0, 200));
}
CDrawings* Drawings = new CDrawings();