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
|
#ifndef D3D_HEADER //stackoverflow my niggas
#define D3D_HEADER
#include <d3d9.h>
#include <d3dx9.h>
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
#pragma warning(disable : 4838)
#include <xnamath.h>
#include <windows.h>
#include <dwmapi.h>
#pragma comment(lib, "dwmapi.lib")
#include "util.hpp"
#include "color.hpp"
enum FontAlign_t : size_t {
ALIGN_CENTER,
ALIGN_LEFT,
ALIGN_RIGHT
};
enum D3DFontFlags_t {
D3DFONTFLAG_OUTLINE = 0x10,
D3DFONTFLAG_DROPSHADOW = 0x100,
};
enum GradientType_t {
GRADIENT_HORIZONTAL,
GRADIENT_VERTICAL
};
//suck my dick
namespace d3d
{
struct d3d_vertex_t {
d3d_vertex_t( float x, float y, float z, clr_t color ) :
m_x( x ), m_y( y ), m_z( z ),
m_clr( D3DCOLOR_RGBA( color.r( ), color.g( ), color.b( ), color.a( ) ) ) { };
d3d_vertex_t( ) : m_x( 0.f ), m_y( 0.f ), m_z( 0.f ),
m_clr( 0 ) { };
float m_x;
float m_y;
float m_z;
float m_rhw = 1.f;
D3DCOLOR m_clr;
};
constexpr size_t VERTEX_SIZE = sizeof( d3d_vertex_t );
struct d3d_fonts_t {
void release( );
void create( IDirect3DDevice9* device );
ID3DXFont* f_12;
ID3DXFont* f_14;
ID3DXFont* f_16;
ID3DXFont* f_18;
ID3DXFont* f_menu;
ID3DXFont* f_con;
};
class c_renderer {
private:
IDirect3DDevice9* m_device;
IDirect3DStateBlock9* m_block;
public:
ulong_t m_width;
ulong_t m_height;
c_renderer( ) { };
c_renderer( IDirect3DDevice9* device );
~c_renderer( );
void on_device_lost( );
void on_device_reset( );
auto get_device( ) {
return m_device;
}
bool run_frame( IDirect3DDevice9* device );
void begin( );
void end( );
void draw_line( clr_t color, int x0, int y0, int x1, int y1 );
void draw_rect( clr_t color, int x, int y, int w, int h );
void draw_filled_rect( clr_t color, int x, int y, int w, int h );
void draw_circle( clr_t color, int x, int y, int r, int steps = 48 );
void draw_filled_circle( clr_t color, int x, int y, int r, int steps = 48 );
void draw_gradient( clr_t start, clr_t end, int x, int y, int w, int h, GradientType_t type );
void draw_text( ID3DXFont* font, clr_t color, int x, int y, FontAlign_t align, long font_flags, const char* msg );
template < FontAlign_t align = ALIGN_CENTER >
void draw_text( ID3DXFont* font, clr_t color, int x, int y, long font_flags, const char* msg, ... ) {
char* buffer = ( char* )_alloca( 2048 );
va_list list{ };
memset( buffer, 0, 2048 );
__crt_va_start( list, msg );
vsprintf_s( buffer, 2048, msg, list );
__crt_va_end( list );
draw_text( font, color, x, y, align, font_flags, buffer );
}
int get_text_width( ID3DXFont* font, long font_flags, const char* msg, ... );
int get_text_height( ID3DXFont* font, long font_flags, const char* msg, ... );
private:
void invalidate_objects( );
void create_objects( );
};
extern d3d::d3d_fonts_t fonts;
}
extern d3d::c_renderer g_d3d;
#endif
|