summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjussi2024-07-02 14:59:38 +0300
committerjussi2024-07-02 14:59:38 +0300
commitfd18b5526e0c2b058f175ba140258549fec09098 (patch)
treeea357ac9cbe9c24a3e009092da99896f38561a3c /src
parente45564ea3f0f27c32264f98da80c6d3556256de0 (diff)
downloadreilua-enhanced-fd18b5526e0c2b058f175ba140258549fec09098.tar.gz
reilua-enhanced-fd18b5526e0c2b058f175ba140258549fec09098.tar.bz2
reilua-enhanced-fd18b5526e0c2b058f175ba140258549fec09098.zip
GuiGetIcons fix and added GuiSetIcons.
Diffstat (limited to 'src')
-rw-r--r--src/lua_core.c1
-rw-r--r--src/rgui.c43
-rw-r--r--src/rmath.c4
3 files changed, 42 insertions, 6 deletions
diff --git a/src/lua_core.c b/src/lua_core.c
index 4cfbed5..e7356e9 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -2082,6 +2082,7 @@ void luaRegister() {
assingGlobalFunction( "GuiIconText", lguiGuiIconText );
assingGlobalFunction( "GuiSetIconScale", lguiGuiSetIconScale );
assingGlobalFunction( "GuiGetIcons", lguiGuiGetIcons );
+ assingGlobalFunction( "GuiSetIcons", lguiGuiSetIcons );
assingGlobalFunction( "GuiLoadIcons", lguiGuiLoadIcons );
assingGlobalFunction( "GuiDrawIcon", lguiGuiDrawIcon );
/* Container/separator controls, useful for controls organization. */
diff --git a/src/rgui.c b/src/rgui.c
index fb5a7ad..30f3535 100644
--- a/src/rgui.c
+++ b/src/rgui.c
@@ -2,6 +2,7 @@
#include "state.h"
#include "rgui.h"
#include "lua_core.h"
+#include "rmath.h"
#define RAYGUI_IMPLEMENTATION
#include "raygui.h"
@@ -286,14 +287,48 @@ int lguiGuiSetIconScale( lua_State* L ) {
}
/*
-> icons = RL.GuiGetIcons()
+> iconsBuffer = RL.GuiGetIcons()
-Get raygui icons data pointer
+Get raygui icons data in buffer. guiIcons size is by default: 256*(16*16/32) = 2048*4 = 8192 bytes = 8 KB
-- Success return int
+- Success return Buffer
*/
int lguiGuiGetIcons( lua_State* L ) {
- lua_pushinteger( L, *GuiGetIcons() );
+ const unsigned int dataSize = RAYGUI_ICON_MAX_ICONS * RAYGUI_ICON_DATA_ELEMENTS * sizeof( unsigned int );
+
+ Buffer buffer = {
+ .type = BUFFER_UNSIGNED_INT,
+ .size = dataSize * sizeof( unsigned int ),
+ .data = malloc( dataSize * sizeof( unsigned int ) )
+ };
+ memcpy( buffer.data, GuiGetIcons(), dataSize );
+
+ uluaPushBuffer( L, buffer );
+
+ return 1;
+}
+
+/*
+> success = RL.GuiSetIcons( Buffer iconBuffer )
+
+Set raygui icons data in buffer. guiIcons size is by default: 256*(16*16/32) = 2048*4 = 8192 bytes = 8 KB
+
+- Failure return false
+- Success return true
+*/
+int lguiGuiSetIcons( lua_State* L ) {
+ Buffer* buffer = uluaGetBuffer( L, 1 );
+
+ if ( buffer->type != BUFFER_UNSIGNED_INT ) {
+ TraceLog( state->logLevelInvalid, "Buffer type must be BUFFER_UNSIGNED_INT" );
+ lua_pushboolean( L, false );
+
+ return 1;
+ }
+ const unsigned int dataSize = RAYGUI_ICON_MAX_ICONS * RAYGUI_ICON_DATA_ELEMENTS * sizeof( unsigned int );
+ memcpy( GuiGetIcons(), buffer->data, imin( dataSize, buffer->size ) );
+
+ lua_pushboolean( L, true );
return 1;
}
diff --git a/src/rmath.c b/src/rmath.c
index 9048b49..1fa9690 100644
--- a/src/rmath.c
+++ b/src/rmath.c
@@ -3,11 +3,11 @@
#include "rmath.h"
#include "lua_core.h"
-inline int imin( int a, int b ) {
+int imin( int a, int b ) {
return a < b ? a : b;
}
-inline int imax( int a, int b ) {
+int imax( int a, int b ) {
return a > b ? a : b;
}