-
Notifications
You must be signed in to change notification settings - Fork 0
/
DrawTools.h
147 lines (115 loc) · 5.45 KB
/
DrawTools.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
//
// Created by emiel on 8/05/21.
//
#ifndef RESPECTRAL_DRAWTOOLS_H
#define RESPECTRAL_DRAWTOOLS_H
#include "Injector.h"
#include <stdarg.h>
#include <stdio.h>
#include <mathlib/vmatrix.h>
#define RED(COLORCODE) ((int) ( COLORCODE >> 24) )
#define BLUE(COLORCODE) ((int) ( COLORCODE >> 8 ) & 0xFF )
#define GREEN(COLORCODE) ((int) ( COLORCODE >> 16 ) & 0xFF )
#define ALPHA(COLORCODE) ((int) COLORCODE & 0xFF )
#define COLORCODE(r,g,b,a)((unsigned int)((((r)&0xff)<<24)|(((g)&0xff)<<16)|(((b)&0xff)<<8)|((a)&0xff)))
namespace draw
{
static unsigned long defaultFont = -2000;
static unsigned long titleFont = -2000;
static unsigned long currentFont = -2000;
extern bool enabled;
extern int screenWidth;
extern int screenHeight;
inline void init()
{
defaultFont = g_surface->CreateFont( );
g_engineClient->GetScreenSize(screenWidth, screenHeight);
g_surface->SetFontGlyphSet(defaultFont, "Verdana", 16, 500, 0, 0, 0x200 );
titleFont = g_surface->CreateFont( );
g_surface->SetFontGlyphSet(titleFont, "Verdana", 18, 500, 0, 0, 0x200 );
}
inline void DefaultFont()
{
currentFont = defaultFont;
}
inline void TitleFont()
{
currentFont = titleFont;
}
inline void drawString( int x, int y, unsigned int dwColor, const wchar_t *pszText)
{
if( !pszText )
return;
g_surface->DrawSetTextPos( x, y );
g_surface->DrawSetTextFont(currentFont );
g_surface->DrawSetTextColor( RED(dwColor), GREEN(dwColor), BLUE(dwColor), ALPHA(dwColor) );
g_surface->DrawPrintText( pszText, wcslen( pszText ) );
}
inline void drawString( int x, int y, unsigned int dwColor, const char *pszText, ... )
{
if( pszText == NULL )
return;
va_list va_alist;
char szBuffer[1024] = { '\0' };
wchar_t szString[1024] = { '\0' };
va_start( va_alist, pszText );
vsprintf( szBuffer, pszText, va_alist );
va_end( va_alist );
swprintf( szString, 1024, L"%s", szBuffer );
g_surface->DrawSetTextPos( x, y );
g_surface->DrawSetTextFont(currentFont );
g_surface->DrawSetTextColor( RED(dwColor), GREEN(dwColor), BLUE(dwColor), ALPHA(dwColor) );
g_surface->DrawPrintText( szString, wcslen( szString ) );
}
inline void OutlineRect( int x, int y, int w, int h, unsigned int dwColor )
{
g_surface->DrawSetColor( RED(dwColor), GREEN(dwColor), BLUE(dwColor), ALPHA(dwColor) );
g_surface->DrawOutlinedRect( x, y, x + w, y + h );
}
inline void DrawRect( int x, int y, int w, int h, unsigned int dwColor )
{
g_surface->DrawSetColor( RED(dwColor), GREEN(dwColor), BLUE(dwColor), ALPHA(dwColor) );
g_surface->DrawFilledRect( x, y, x + w, y + h );
}
inline bool WorldToScreen( Vector &vOrigin, Vector &vScreen )
{
auto & worldToScreen = g_engineClient->WorldToScreenMatrix(); //Grab the world to screen matrix from CEngineClient::WorldToScreenMatrix
float w = worldToScreen[3][0] * vOrigin[0] + worldToScreen[3][1] * vOrigin[1] + worldToScreen[3][2] * vOrigin[2] + worldToScreen[3][3]; //Calculate the angle in compareson to the player's camera.
vScreen.z = 0; //Screen doesn't have a 3rd dimension.
if( w > 0.001 ) //If the object is within view.
{
float fl1DBw = 1 / w; //Divide 1 by the angle.
vScreen.x = (screenWidth / 2) + ( 0.5 * ((worldToScreen[0][0] * vOrigin[0] + worldToScreen[0][1] * vOrigin[1] + worldToScreen[0][2] * vOrigin[2] + worldToScreen[0][3]) * fl1DBw) * screenWidth + 0.5); //Get the X dimension and push it in to the Vector.
vScreen.y = (screenHeight / 2) - ( 0.5 * ((worldToScreen[1][0] * vOrigin[0] + worldToScreen[1][1] * vOrigin[1] + worldToScreen[1][2] * vOrigin[2] + worldToScreen[1][3]) * fl1DBw) * screenHeight + 0.5); //Get the Y dimension and push it in to the Vector.
return true;
}
return false;
}
inline void GetTextSize(int &wide, int &tall, const char *pszText, ...)
{
if( pszText == NULL )
return;
va_list va_alist;
char szBuffer[1024] = { '\0' };
wchar_t szString[1024] = { '\0' };
va_start( va_alist, pszText );
vsprintf( szBuffer, pszText, va_alist );
va_end( va_alist );
swprintf( szString, 1024, L"%s", szBuffer );
g_surface->GetTextSize(currentFont, szString, wide, tall);
}
inline void DrawBox( Vector vOrigin, int r, int g, int b, int alpha, int box_width, int radius )
{
Vector vScreen;
if( !WorldToScreen( vOrigin, vScreen ) )
return;
int radius2 = radius<<1;
OutlineRect( vScreen.x - radius + box_width, vScreen.y - radius + box_width, radius2 - box_width, radius2 - box_width, 0x000000FF );
OutlineRect( vScreen.x - radius - 1, vScreen.y - radius - 1, radius2 + ( box_width + 2 ), radius2 + ( box_width + 2 ), 0x000000FF );
DrawRect( vScreen.x - radius + box_width, vScreen.y - radius, radius2 - box_width, box_width,COLORCODE( r, g, b, alpha ));
DrawRect( vScreen.x - radius, vScreen.y + radius, radius2, box_width,COLORCODE( r, g, b, alpha ));
DrawRect( vScreen.x - radius, vScreen.y - radius, box_width, radius2,COLORCODE( r, g, b, alpha ));
DrawRect( vScreen.x + radius, vScreen.y - radius, box_width, radius2 + box_width, COLORCODE( r, g, b, alpha ) );
}
}
#endif //RESPECTRAL_DRAWTOOLS_H