From dc2edd69440fcc2470a45562149166695d4edbcc Mon Sep 17 00:00:00 2001 From: jussi Date: Fri, 14 Apr 2023 00:11:58 +0300 Subject: [PATCH] Raygui wrapper lib. --- API.md | 10 +- ReiLua_API.lua | 7 +- changelog | 1 + devnotes | 1 + examples/ReiLuaGui_examples/calculator.lua | 2 +- examples/gui/main.lua | 3 - examples/platformer/main.lua | 6 - examples/raygui_lib/main.lua | 155 +++++++++++++++++++++ examples/resources/clib/rllib.so | Bin 0 -> 15576 bytes examples/resources/clib/sampleclib.so | Bin 0 -> 15336 bytes examples/resources/lib/gui.lua | 12 +- examples/resources/lib/rectangle.lua | 2 + examples/resources/lib/utillib.lua | 3 + include/raygui.h | 6 +- include/rgui.h | 1 + include/state.h | 1 + src/gl.c | 5 +- src/lua_core.c | 1 + src/rgui.c | 16 ++- src/state.c | 1 + 20 files changed, 210 insertions(+), 23 deletions(-) create mode 100644 examples/raygui_lib/main.lua create mode 100755 examples/resources/clib/rllib.so create mode 100755 examples/resources/clib/sampleclib.so diff --git a/API.md b/API.md index fc21aa2..8548011 100644 --- a/API.md +++ b/API.md @@ -5955,13 +5955,21 @@ Get gui state ( global state ) > success = RL.GuiSetFont( Font font ) -Set gui custom font ( Global state ) +Set gui custom font ( global state ) - Failure return false - Success return true --- +> font = RL.GuiGetFont() + +Get gui custom font ( global state ) + +- Success return int + +--- + ## Gui - Style --- diff --git a/ReiLua_API.lua b/ReiLua_API.lua index a7e194a..c37d760 100644 --- a/ReiLua_API.lua +++ b/ReiLua_API.lua @@ -4759,13 +4759,18 @@ function RL.GuiGetState() end -- Gui - Font ----Set gui custom font ( Global state ) +---Set gui custom font ( global state ) ---- Failure return false ---- Success return true ---@param font any ---@return any success function RL.GuiSetFont( font ) end +---Get gui custom font ( global state ) +---- Success return int +---@return any font +function RL.GuiGetFont() end + -- Gui - Style ---Set one style property diff --git a/changelog b/changelog index 1aff534..cc7188a 100644 --- a/changelog +++ b/changelog @@ -50,6 +50,7 @@ Detailed changes: - ADDED: GetCamera3DViewMatrix - ADDED: GetCamera3DProjectionMatrix - ADDED: glBlitFramebuffer + - ADDED: GuiGetFont ------------------------------------------------------------------------ Release: ReiLua version 0.4.0 Using Raylib 4.2 diff --git a/devnotes b/devnotes index da84006..e48a8d7 100644 --- a/devnotes +++ b/devnotes @@ -1,5 +1,6 @@ Current { * Check new functions from https://github.com/raysan5/raylib/blob/master/CHANGELOG + * Tilemap clib. } Backlog { diff --git a/examples/ReiLuaGui_examples/calculator.lua b/examples/ReiLuaGui_examples/calculator.lua index 964763e..8ebf0b6 100644 --- a/examples/ReiLuaGui_examples/calculator.lua +++ b/examples/ReiLuaGui_examples/calculator.lua @@ -32,7 +32,7 @@ function Calculator:new( pos ) VAling = Gui.ALING.CENTER, color = Color:new( RL.LIGHTGRAY ), } ) ) - + object.handle:add( Gui.texture:new( { bounds = object.handle.bounds:clone(), texture = borderTexture, diff --git a/examples/gui/main.lua b/examples/gui/main.lua index 7ae8237..25c4ed6 100644 --- a/examples/gui/main.lua +++ b/examples/gui/main.lua @@ -33,9 +33,6 @@ function RL.init() RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) end -function RL.process( delta ) -end - function RL.draw() RL.ClearBackground( { 50, 20, 75 } ) diff --git a/examples/platformer/main.lua b/examples/platformer/main.lua index 98c5936..f419423 100644 --- a/examples/platformer/main.lua +++ b/examples/platformer/main.lua @@ -3,12 +3,6 @@ package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" Util = require( "utillib" ) Vec2 = require( "vector2" ) --- print( "RL", RL, #RL ) - --- for i, v in pairs( RL ) do --- print( i, v ) --- end - local TILE_SIZE = 16 local PLAYER_MAXSPEED = 1.5 local PLAYER_ACCELL = 5 diff --git a/examples/raygui_lib/main.lua b/examples/raygui_lib/main.lua new file mode 100644 index 0000000..6facd42 --- /dev/null +++ b/examples/raygui_lib/main.lua @@ -0,0 +1,155 @@ +package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" + +Util = require( "utillib" ) +Rect = require( "rectangle" ) +Vec2 = require( "vector2" ) +Color = require( "color" ) +Raygui = require( "raygui" ) + +local raygui = Raygui:new() + +local grid = {} + +function RL.init() + local monitor = 0 + local mPos = RL.GetMonitorPosition( monitor ) + local mSize = RL.GetMonitorSize( monitor ) + local winSize = { 1920, 1080 } + + RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + RL.SetWindowSize( winSize ) + RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) + + RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 20 ) + RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SPACING, 4 ) + RL.GuiSetStyle( RL.SPINNER, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_RIGHT ) + + local label = raygui:add( raygui.Label:new( + Rect:new( 16, 16, 64, 32 ), + "Cat" + ) ) + local toggleGroup = raygui:add( raygui.ToggleGroup:new( + Rect:new( 68, 16, 64, 32 ), + "Cat\nDog", + 0, + function( self ) print( self:getItem( self.active ) ) end + ) ) + local button = raygui:add( raygui.Button:new( + Rect:new( 245, 188, 64, 32 ), + "Dog", + function() toggleGroup:setText( "Dog;Cat\nEagle" ) end + ) ) + local checkbox = raygui:add( raygui.CheckBox:new( + Rect:new( 64, 128, 20, 20 ), + "Dog", + false + ) ) + local combobox = raygui:add( raygui.ComboBox:new( + Rect:new( 64, 256, 128, 32 ), + "Dog\nCow\nDonkey", + 0 + ) ) + local dropdownbox = raygui:add( raygui.DropdownBox:new( + Rect:new( 256, 128, 128, 32 ), + "Dog\nGiraffe\nLion\nHorse", + 0, + false, + function( self ) print( self:getItem( self.active ) ) end + ) ) + local spinner = raygui:add( raygui.Spinner:new( + Rect:new( 464, 256, 128, 32 ), + "Health", + 0, + 0, + 10, + false, + function( self ) print( "Spinner value changed to "..self.value ) end + ) ) + local valuebox = raygui:add( raygui.ValueBox:new( + Rect:new( 464, 316, 128, 32 ), + "Health", + 0, + 0, + 100, + false, + function( self ) print( "ValueBox value changed to "..self.value ) end + ) ) + local textbox = raygui:add( raygui.TextBox:new( + Rect:new( 32, 316, 256, 32 ), + "Name", + 32, + false, + function( self ) print( "Set text "..self.text ) end + ) ) + local textboxmulti = raygui:add( raygui.TextBoxMulti:new( + Rect:new( 32, 400, 256, 64 ), + "Buggy?", + 32, + false, + function( self ) print( "Set text "..self.text ) end + ) ) + local slider = raygui:add( raygui.Slider:new( + Rect:new( 50, 500, 256, 32 ), + "min", + "max", + 0, + 0, + 100, + function( self ) print( "Changed value "..self.value ) end + ) ) + local sliderbar = raygui:add( raygui.SliderBar:new( + Rect:new( 50, 550, 256, 32 ), + "min", + "max", + 0, + 0, + 100, + function( self ) print( "Changed value "..self.value ) end + ) ) + local progressbar = raygui:add( raygui.ProgressBar:new( + Rect:new( 50, 600, 256, 32 ), + "min", + "max", + 20, + 0, + 100, + function( self ) print( "Changed value "..self.value ) end + ) ) + local statusbar = raygui:add( raygui.StatusBar:new( + Rect:new( 50, 650, 256, 32 ), + "StatusBar" + ) ) + local dummyrec = raygui:add( raygui.DummyRec:new( + Rect:new( 50, 700, 256, 32 ), + "DummyRec" + ) ) + grid = raygui:add( raygui.Grid:new( + Rect:new( 400, 400, 256, 256 ), + "Grid", + 32, + 2 + ) ) +end + +function RL.process( delta ) + raygui:process() +end + +function RL.draw() + RL.ClearBackground( { 50, 20, 75 } ) + + if 0 <= grid.cell.x then + RL.DrawRectangleLines( + { + grid.bounds.x + grid.cell.x * 32, + grid.bounds.y + grid.cell.y * 32, + 32, + 32 + }, + RL.GREEN + ) + end + + raygui:draw() +end diff --git a/examples/resources/clib/rllib.so b/examples/resources/clib/rllib.so new file mode 100755 index 0000000000000000000000000000000000000000..6368e17fdb380075fd421e4ca9767c48fb8fa1a4 GIT binary patch literal 15576 zcmeHOY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CyiVL(#2#b$+cE$UBXv*2_WJe9_I}E9*E5FB5ILM8 rA^O32#^dMv&vL+c?9laERfFof9Ecfg;TB>Xsq}Tjv1^7 literal 0 HcmV?d00001 diff --git a/examples/resources/clib/sampleclib.so b/examples/resources/clib/sampleclib.so new file mode 100755 index 0000000000000000000000000000000000000000..b232cc97c6e281f1b92d433da06cef9b36d0cdf8 GIT binary patch literal 15336 zcmeHOeTZCF6~8k{+NsU%tTkUI(L5xDt=iYkrdz9J&1^Qi`=XmPCL3)~d6}Jgn;D#s zW#&z@Y0<8vmV~fWQK(o7QW2{Dvna?Kv~04aX;mZv3-J$ODMYg>cH5$)f*H@b_xxsN zZ+BD*B9wQR_s%`Pdw%EMcizXnZ|A(nhDL|uv6wKZSbRQa2}UKn_VUdSk3>LHuy&gcWATAFaaO3LDFlq z-J#a2C*Nxt)3EXV6UB1LuZHPL==;jwKX$;+29@AMz8VIVu>*sJaw!-~j~4>dwt9=7 znM(T;`BJ)&eG*Mhd#T< z;C$_xks5uj1=r761FQKK9KN{er4}6bl%}NgUfoJUZcPm&T5!I{P`Xm4#`bttFtR1Z zd!_xD`^@N0%1E~7Eh6ocz)Z)hA7T7A+`&k*gU0!8oMASPN)&-80#O8_ z2t*NxA`nF&ia->BC<0Lgq6oa(BQRO0Rp|#iIm~7AE70^~so1tP59}nAU)&SR^?Hir zuGi~ze)B&`l3z%<@NcYKVvihFv8k@uw)M9rzE1C@%-v4g{A>04agwUDYq)dEr;@jy zOiZgiTOauF?w$H)N4BBYb9I6G;NK$EKxfwz@xhK;;sfN#_{b9cM`};6X#aw4XDBLB z1fmE;5r`rXMIeem6oDuLQ3Rq0L=kv5MgVz*$RkvaIZEUS+Q-a45pwyN5se(dOQNqA ziNwYZ(U&Ff@cp7Azj2%B^lGNdR*}ea9throzni6=r~Ss`+pb6SGNappX8$si~Ov}36T$rM84_B;NT~mZpx^>%h|v=CSG!`EG0 zbtqi7Fz0_V#MEYm@dLj{;~SJ6m;1FrvXKW5`%i28&8jB_#K_NSd{g6kL~D^Man3B4 z_yMm{WwpHOCkS_7)FPjy`f7RJvu*JCHux379op=&NWg0TUu%QM=|nozW|!@R>woCj z4V41rTDuw5%-#0!KPOHA&nw^0R?B`aUCMIG_`YKY2M+8XB$Tc(f5`KP4-Xs|^1XeB z38L(Bf9T*oPCFkNeQ@u6^c)7m7tJjg48App>lOl-7uJjrz@2-4UHM7GmE<*2YNW^Vm?DdD3fE_xw<#wdAwRx zZl+u;2BpxxqTZ3t^Ac1ZO@U zi_Jer7{^4G5zXhiJm0Y{A`@LO4(R-RZ{<6}gFFsHk(f3hzhUvGr2%r%I$_|!?Nb&X z^CTqJeXzI3|BUbvf8~g!NL*)vHsS~U`&8i}g5T~tGuYex|HR^_9AgRjIEW%~{s8}i zDwIrz+pY1v4!%RP?V&@yOx$D(AM4#Y`7RK4WTFdn$X5vEzaAtJDSzp+4`&0 z#Md79ShwK2M0|gUbtn48b?|56w)T(jhGuyoM8(nj<_>(wWol~WWBq+y_^BpU*T92( z%i?1_*4<->u!9?0=Y=C 0) { - if (IsKeyPressed(KEY_BACKSPACE)) + // if (IsKeyPressed(KEY_BACKSPACE)) + if ( GetKeyPressed() == KEY_BACKSPACE ) { while ((keyCount > 0) && ((text[--keyCount] & 0xc0) == 0x80)); text[keyCount] = '\0'; @@ -2343,7 +2344,8 @@ bool GuiTextBoxMulti(Rectangle bounds, char *text, int textSize, bool editMode) // Delete characters if (textLength > 0) { - if (IsKeyPressed(KEY_BACKSPACE)) + // if (IsKeyPressed(KEY_BACKSPACE)) + if ( GetKeyPressed() == KEY_BACKSPACE ) { if ((unsigned char)text[textLength - 1] < 127) { diff --git a/include/rgui.h b/include/rgui.h index b23b472..576c0c6 100644 --- a/include/rgui.h +++ b/include/rgui.h @@ -11,6 +11,7 @@ int lguiGuiSetState( lua_State *L ); int lguiGuiGetState( lua_State *L ); /* Font. */ int lguiGuiSetFont( lua_State *L ); +int lguiGuiGetFont( lua_State *L ); /* Style */ int lguiGuiSetStyle( lua_State *L ); int lguiGuiGetStyle( lua_State *L ); diff --git a/include/state.h b/include/state.h index b82cfd9..305be56 100644 --- a/include/state.h +++ b/include/state.h @@ -14,6 +14,7 @@ typedef struct { lua_State *luaState; Vector2 resolution; int textureSource; + size_t guiFont; /* Resources. */ /* Images. */ Image **images; diff --git a/src/gl.c b/src/gl.c index 18947d5..a6777a9 100644 --- a/src/gl.c +++ b/src/gl.c @@ -55,10 +55,11 @@ int lglBlitFramebuffer( lua_State *L ) { dstRect.x, dstRect.y, dstRect.width, dstRect.height, mask, filter - // GL_COLOR_BUFFER_BIT, // mask - // GL_NEAREST // filter ); + glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 ); + glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 ); + lua_pushboolean( L, true ); return 1; diff --git a/src/lua_core.c b/src/lua_core.c index 3c839c6..6bb6237 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -1290,6 +1290,7 @@ void luaRegister() { assingGlobalFunction( "GuiGetState", lguiGuiGetState ); /* Font. */ assingGlobalFunction( "GuiSetFont", lguiGuiSetFont ); + assingGlobalFunction( "GuiGetFont", lguiGuiGetFont ); /* Style. */ assingGlobalFunction( "GuiSetStyle", lguiGuiSetStyle ); assingGlobalFunction( "GuiGetStyle", lguiGuiGetStyle ); diff --git a/src/rgui.c b/src/rgui.c index 57f4a4d..e2c1fa0 100644 --- a/src/rgui.c +++ b/src/rgui.c @@ -131,7 +131,7 @@ int lguiGuiGetState( lua_State *L ) { /* > success = RL.GuiSetFont( Font font ) -Set gui custom font ( Global state ) +Set gui custom font ( global state ) - Failure return false - Success return true @@ -143,6 +143,7 @@ int lguiGuiSetFont( lua_State *L ) { return 1; } size_t fontId = lua_tointeger( L, 1 ); + state->guiFont = fontId; GuiSetFont( *state->fonts[ fontId ] ); lua_pushboolean( L, true ); @@ -150,6 +151,19 @@ int lguiGuiSetFont( lua_State *L ) { return 1; } +/* +> font = RL.GuiGetFont() + +Get gui custom font ( global state ) + +- Success return int +*/ +int lguiGuiGetFont( lua_State *L ) { + lua_pushinteger( L, state->guiFont ); + + return 1; +} + /* ## Gui - Style */ diff --git a/src/state.c b/src/state.c index e9e12f4..877464e 100644 --- a/src/state.c +++ b/src/state.c @@ -17,6 +17,7 @@ bool stateInit( const char *exePath ) { state->resolution = (Vector2){ 800, 600 }; state->luaState = NULL; state->textureSource = TEXTURE_SOURCE_TEXTURE; + state->guiFont = 0; /* Images. */ state->imageAlloc = ALLOC_PAGE_SIZE; state->imageCount = 0;