-
Notifications
You must be signed in to change notification settings - Fork 4
/
wrappers.h
225 lines (179 loc) · 5.2 KB
/
wrappers.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#pragma once
#include "context.h"
#include "renderer.h"
namespace UI
{
struct UIcolor_t
{
uint8_t R = 255;
uint8_t G = 255;
uint8_t B = 255;
uint8_t A = 255;
constexpr UIcolor_t( ) : R( 0 ), G( 0 ), B( 0 ), A( 0 ) { }
constexpr UIcolor_t( uint8_t r, uint8_t g, uint8_t b, uint8_t a ) : R( r ), G( g ), B( b ), A( a ) { }
constexpr UIcolor_t( uint8_t r, uint8_t g, uint8_t b ) : R( r ), G( g ), B( b ), A( 255 ) { }
__forceinline color_t to_renderer_color( ) const
{
return color_t( R, G, B, A );
}
__forceinline static UIcolor_t get_rainbow( const float& alpha, const float& speed = 0.0005f )
{
static float hue_cycle{ };
UIcolor_t ret;
hue_cycle = std::fmod( hue_cycle + speed, 1.0f );
ret = hsb_to_rgb( hue_cycle, 0.7f, 1.0f );
return ret;
}
__forceinline static UIcolor_t get_rainbow( const float& alpha, float& hue_cycle )
{
UIcolor_t ret;
hue_cycle = std::fmod( hue_cycle + 0.003f, 1.0f );
ret = hsb_to_rgb( hue_cycle, 0.7f, 1.0f );
return ret;
}
__forceinline static UIcolor_t get_sinbow( )
{
static float cycle{ };
UIcolor_t ret;
cycle = std::fmod( cycle + 0.003f, 3.0f );
ret.R = cosf( cycle ) * .5f + .5f;
ret.G = cosf( cycle - 2.f * math::pi / 3.f ) * .5f + .5f;
ret.B = cosf( cycle - 4.f * math::pi / 3.f ) * .5f + .5f;
ret.R *= 255.f;
ret.G *= 255.f;
ret.B *= 255.f;
return ret;
}
__forceinline static UIcolor_t hsb_to_rgb( float hue, float saturation, float 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 UIcolor_t(
(uint8_t)( brightness * 255 ),
(uint8_t)( t * 255 ),
(uint8_t)( p * 255 )
);
}
if ( h < 2 )
{
return UIcolor_t(
(uint8_t)( q * 255 ),
(uint8_t)( brightness * 255 ),
(uint8_t)( p * 255 )
);
}
if ( h < 3 )
{
return UIcolor_t(
(uint8_t)( p * 255 ),
(uint8_t)( brightness * 255 ),
(uint8_t)( t * 255 )
);
}
if ( h < 4 )
{
return UIcolor_t(
(uint8_t)( p * 255 ),
(uint8_t)( q * 255 ),
(uint8_t)( brightness * 255 )
);
}
if ( h < 5 )
{
return UIcolor_t(
(uint8_t)( t * 255 ),
(uint8_t)( p * 255 ),
(uint8_t)( brightness * 255 )
);
}
return UIcolor_t(
(uint8_t)( brightness * 255 ),
(uint8_t)( p * 255 ),
(uint8_t)( q * 255 )
);
}
};
__forceinline void filled_rect( UIcolor_t color, float x, float y, float w, float h )
{
color_t renderer_color = color.to_renderer_color( );
g_ctx.m_render.filled_rect( renderer_color, x, y, w, h );
}
__forceinline void _filled_rect( UIcolor_t color, float x, float y, float w, float h )
{
color_t renderer_color = color.to_renderer_color( );
g_ctx.m_render.filled_rect( renderer_color, x, y, x + w, y + h );
}
__forceinline void rect_gradient( UIcolor_t top, UIcolor_t bottom, float x, float y, float w, float h )
{
color_t renderer_top = top.to_renderer_color( );
color_t renderer_bottom = bottom.to_renderer_color( );
g_ctx.m_render.rect_gradient( gradient_t::vertical, renderer_top, renderer_bottom, x, y, w, h );
}
__forceinline void skeet_rect( const float& alpha, const float& x0, const float& y0, const float& x1, const float& y1 )
{
}
__forceinline void line( UIcolor_t color, float x0, float y0, float x1, float y1 )
{
color_t renderer_color = color.to_renderer_color( );
g_ctx.m_render.line( renderer_color, x0, y0, x1, y1 );
}
static void string( UIcolor_t color, float x, float y, bool centered, const char* fmt, ... )
{
char buffer[256];
va_list args;
va_start( args, fmt );
vsprintf( buffer, fmt, args );
va_end( args );
const font_t font = font_t::font_menu; // Tahoma | NONANTIALIASED_QUALITY | FW_NORMAL | 12
color_t renderer_color = color.to_renderer_color( );
g_ctx.m_render.string( font, renderer_color, x, y, centered, buffer );
}
static void string( UIcolor_t color, float x, float y, bool centered, const wchar_t* fmt, ... )
{
wchar_t buffer[256];
va_list args;
va_start( args, fmt );
vswprintf( buffer, 256, fmt, args );
va_end( args );
const font_t font = font_t::font_menu; // Tahoma | NONANTIALIASED_QUALITY | FW_NORMAL | 12
color_t renderer_color = color.to_renderer_color( );
g_ctx.m_render._string( font, renderer_color, x, y, centered, buffer );
}
static float text_width( const char* fmt, ... )
{
char buffer[256];
va_list args;
va_start( args, fmt );
vsprintf( buffer, fmt, args );
va_end( args );
const font_t font = font_t::font_menu; // Tahoma | NONANTIALIASED_QUALITY | FW_NORMAL | 12
return g_ctx.m_render.text_width( font, buffer );
}
namespace util
{
static inline int screen_width( )
{
return g_ctx.m_screen_w;
}
static inline int screen_height( )
{
return g_ctx.m_screen_h;
}
enum mouse_state_t
{
MOUSE_INACTIVE,
MOUSE_ACTIVE
};
// not needed
static inline void set_mouse_state( const bool& state )
{
//static const auto cl_mouseenable = csgo.m_engine_cvars( )->FindVar( "cl_mouseenable" );
//cl_mouseenable->set_value( state );
}
}
}