summaryrefslogtreecommitdiff
path: root/src/text.c
diff options
context:
space:
mode:
authorjussi2022-03-10 17:53:43 +0200
committerjussi2022-03-10 17:53:43 +0200
commit26a11a4b7f32a6fc2d131e4c78fe1ca40cc6ac8a (patch)
treeb6fc68889bf5df58ba3455e6d64da6b2f78d38de /src/text.c
parentdebe4baa8c208458f847dd4c89c17f7cc39be559 (diff)
downloadreilua-enhanced-26a11a4b7f32a6fc2d131e4c78fe1ca40cc6ac8a.tar.gz
reilua-enhanced-26a11a4b7f32a6fc2d131e4c78fe1ca40cc6ac8a.tar.bz2
reilua-enhanced-26a11a4b7f32a6fc2d131e4c78fe1ca40cc6ac8a.zip
Measure text.
Diffstat (limited to 'src/text.c')
-rw-r--r--src/text.c78
1 files changed, 76 insertions, 2 deletions
diff --git a/src/text.c b/src/text.c
index 1089c1b..ace5e20 100644
--- a/src/text.c
+++ b/src/text.c
@@ -1,6 +1,7 @@
#include "main.h"
#include "state.h"
#include "text.h"
+#include "textures.h"
#include "lua_core.h"
static void checkFontRealloc( int i ) {
@@ -62,6 +63,46 @@ int ltextLoadFont( lua_State *L ) {
}
/*
+> font = RL_LoadFontFromImage( Image image, Color key, int firstChar )
+
+Load font from Image ( XNA style )
+
+- Failure return -1
+- Success return int
+*/
+int ltextLoadFontFromImage( lua_State *L ) {
+ if ( !lua_isnumber( L, -3 ) || !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadFontFromImage( Image image, Color key, int firstChar )" );
+ lua_pushinteger( L, -1 );
+ return 1;
+ }
+ int i = 0;
+
+ for ( i = 0; i < state->fontCount; i++ ) {
+ if ( state->fonts[i] == NULL ) {
+ break;
+ }
+ }
+ int firstChar = lua_tointeger( L, -1 );
+ lua_pop( L, 1 );
+ Color key = uluaGetColor( L );
+ lua_pop( L, 1 );
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+
+ state->fonts[i] = malloc( sizeof( Font ) );
+ *state->fonts[i] = LoadFontFromImage( *state->images[ imageId ], key, firstChar );
+ lua_pushinteger( L, i );
+ checkFontRealloc( i );
+
+ return 1;
+}
+
+/*
> success = RL_UnloadFont( Font font )
Unload Font from GPU memory ( VRAM )
@@ -150,7 +191,7 @@ int ltextDrawText( lua_State *L ) {
}
/*
-> success = RL_DrawTextPro( Font font, const char text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint )
+> success = 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 )
@@ -160,7 +201,7 @@ Draw text using Font and pro parameters ( rotation )
int ltextDrawTextPro( lua_State *L ) {
if ( !lua_isnumber( L, -8 ) || !lua_isstring( L, -7 ) || !lua_istable( L, -6 ) || !lua_istable( L, -5 )
|| !lua_isnumber( L, -4 ) || !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
- TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawTextPro( Font font, const char text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint )" );
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawTextPro( Font font, string text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint )" );
lua_pushboolean( L, false );
return 1;
}
@@ -187,3 +228,36 @@ int ltextDrawTextPro( lua_State *L ) {
return 1;
}
+
+/*
+## Text - Misc
+*/
+
+/*
+> size = RL_MeasureText( Font font, string text, float fontSize, float spacing )
+
+Measure string size for Font
+
+- Failure return false
+- Success return Vector2
+*/
+int ltextMeasureText( lua_State *L ) {
+ if ( !lua_isnumber( L, -4 ) || !lua_isstring( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
+ TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_MeasureText( Font font, string text, float fontSize, float spacing )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ float spacing = lua_tonumber( L, -1 );
+ lua_pop( L, 1 );
+ float fontSize = lua_tonumber( L, -1 );
+ lua_pop( L, 1 );
+ size_t fontId = lua_tointeger( L, -2 );
+
+ if ( !validFont( fontId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ uluaPushVector2( L, MeasureTextEx( *state->fonts[ fontId ], lua_tostring( L, -1 ), fontSize, spacing ) );
+
+ return 1;
+}