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
226
227
228
229
230
231
|
#include "main.h"
#include "state.h"
#include "text.h"
#include "textures.h"
#include "lua_core.h"
/*
## Text - Loading
*/
/*
> RL.GetFontDefault()
Get the default Font
*/
int ltextGetFontDefault( lua_State *L ) {
uluaPushFont( L, GetFontDefault() );
return 1;
}
/*
> font = RL.LoadFont( string fileName )
Load font from file into GPU memory (VRAM)
- Failure return nil
- Success return Font
*/
int ltextLoadFont( lua_State *L ) {
if ( FileExists( luaL_checkstring( L, 1 ) ) ) {
uluaPushFont( L, LoadFont( lua_tostring( L, 1 ) ) );
return 1;
}
TraceLog( state->logLevelInvalid, "Invalid file path '%s'", lua_tostring( L, 1 ) );
lua_pushnil( L );
return 1;
}
/*
> font = RL.LoadFontEx( string fileName, int fontSize, int fontChars{} )
Load font from file with extended parameters. Loading the default character set
- Failure return nil
- Success return Font
*/
int ltextLoadFontEx( lua_State *L ) {
int fontSize = luaL_checkinteger( L, 2 );
if ( FileExists( luaL_checkstring( L, 1 ) ) ) {
if ( lua_istable( L, 3 ) ) {
int glyphCount = uluaGetTableLenIndex( L, 3 );
int fontChars[ glyphCount ];
int t = lua_gettop( L );
int i = 0;
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
fontChars[i] = lua_tointeger( L, -1 );
i++;
lua_pop( L, 1 );
}
uluaPushFont( L, LoadFontEx( lua_tostring( L, 1 ), fontSize, fontChars, glyphCount ) );
return 0;
}
uluaPushFont( L, LoadFontEx( lua_tostring( L, 1 ), fontSize, NULL, 0 ) );
return 1;
}
TraceLog( state->logLevelInvalid, "Invalid file path '%s'", lua_tostring( L, 1 ) );
lua_pushnil( L );
return 1;
}
/*
> font = RL.LoadFontFromImage( Image image, Color key, int firstChar )
Load font from Image ( XNA style )
- Success return Font
*/
int ltextLoadFontFromImage( lua_State *L ) {
Image *image = luaL_checkudata( L, 1, "Image" );
Color key = uluaGetColorIndex( L, 2 );
int firstChar = luaL_checkinteger( L, 3 );
uluaPushFont( L, LoadFontFromImage( *image, key, firstChar ) );
return 1;
}
/*
## Text - Draw
*/
/*
> RL.DrawFPS( Vector2 pos )
Draw current FPS
*/
int ltextDrawFPS( lua_State *L ) {
Vector2 pos = uluaGetVector2Index( L, 1 );
DrawFPS( pos.x, pos.y );
return 0;
}
/*
> RL.DrawText( Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )
Draw text using font and additional parameters
*/
int ltextDrawText( lua_State *L ) {
Font *font = luaL_checkudata( L, 1, "Font" );
Vector2 position = uluaGetVector2Index( L, 3 );
float fontSize = luaL_checknumber( L, 4 );
float spacing = luaL_checknumber( L, 5 );
Color tint = uluaGetColorIndex( L, 6 );
DrawTextEx( *font, luaL_checkstring( L, 2 ), position, fontSize, spacing, tint );
return 0;
}
/*
> RL.DrawTextPro( Font font, string text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint )
Draw text using Font and pro parameters (rotation)
*/
int ltextDrawTextPro( lua_State *L ) {
Font *font = luaL_checkudata( L, 1, "Font" );
Vector2 position = uluaGetVector2Index( L, 3 );
Vector2 origin = uluaGetVector2Index( L, 4 );
float rotation = luaL_checknumber( L, 5 );
float fontSize = luaL_checknumber( L, 6 );
float spacing = luaL_checknumber( L, 7 );
Color tint = uluaGetColorIndex( L, 8 );
DrawTextPro( *font, luaL_checkstring( L, 2 ), position, origin, rotation, fontSize, spacing, tint );
return 0;
}
/*
## Text - Misc
*/
/*
> size = RL.MeasureText( Font font, string text, float fontSize, float spacing )
Measure string size for Font
- Success return Vector2
*/
int ltextMeasureText( lua_State *L ) {
Font *font = luaL_checkudata( L, 1, "Font" );
float fontSize = luaL_checknumber( L, 3 );
float spacing = luaL_checknumber( L, 4 );
uluaPushVector2( L, MeasureTextEx( *font, luaL_checkstring( L, 2 ), fontSize, spacing ) );
return 1;
}
/*
> baseSize = RL.GetFontBaseSize( Font font )
Get font base size (default chars height)
- Success return int
*/
int ltextGetFontBaseSize( lua_State *L ) {
Font *font = luaL_checkudata( L, 1, "Font" );
lua_pushinteger( L, font->baseSize );
return 1;
}
/*
> glyphCount = RL.GetFontGlyphCount( Font font )
Get font number of glyph characters
- Success return int
*/
int ltextGetFontGlyphCount( lua_State *L ) {
Font *font = luaL_checkudata( L, 1, "Font" );
lua_pushinteger( L, font->glyphCount );
return 1;
}
/*
> glyphPadding = RL.GetFontGlyphPadding( Font font )
Get font padding around the glyph characters
- Success return int
*/
int ltextGetFontGlyphPadding( lua_State *L ) {
Font *font = luaL_checkudata( L, 1, "Font" );
lua_pushinteger( L, font->glyphPadding );
return 1;
}
/*
> texture = RL.GetFontTexture( Font font )
Get font texture atlas containing the glyphs.
- Success return Texture
*/
int ltextGetFontTexture( lua_State *L ) {
Font *font = luaL_checkudata( L, 1, "Font" );
uluaPushTexture( L, font->texture );
return 1;
}
|