From dc2edd69440fcc2470a45562149166695d4edbcc Mon Sep 17 00:00:00 2001 From: jussi Date: Fri, 14 Apr 2023 00:11:58 +0300 Subject: Raygui wrapper lib. --- 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 + 9 files changed, 167 insertions(+), 16 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 (limited to 'examples') 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 0000000..6368e17 Binary files /dev/null and b/examples/resources/clib/rllib.so differ diff --git a/examples/resources/clib/sampleclib.so b/examples/resources/clib/sampleclib.so new file mode 100755 index 0000000..b232cc9 Binary files /dev/null and b/examples/resources/clib/sampleclib.so differ diff --git a/examples/resources/lib/gui.lua b/examples/resources/lib/gui.lua index 8335247..8bec529 100644 --- a/examples/resources/lib/gui.lua +++ b/examples/resources/lib/gui.lua @@ -1,4 +1,4 @@ -util = require( "utillib" ) +Util = require( "utillib" ) Rect = require( "rectangle" ) Vec2 = require( "vector2" ) Color = require( "color" ) @@ -106,11 +106,11 @@ function Gui.delete( cell ) end function Gui.set2Top( cell ) - util.tableMove( Gui._cells, Gui.getId( cell ), 1, #Gui._cells ) + Util.tableMove( Gui._cells, Gui.getId( cell ), 1, #Gui._cells ) end function Gui.set2Back( cell ) - util.tableMove( Gui._cells, Gui.getId( cell ), 1, 1 ) + Util.tableMove( Gui._cells, Gui.getId( cell ), 1, 1 ) end function Gui.process( mousePosition ) @@ -187,7 +187,7 @@ function Gui.process( mousePosition ) if 0 < key then if key == RL.KEY_BACKSPACE then - Gui._inputItem.text = util.utf8Sub( Gui._inputItem.text, 0, utf8.len( Gui._inputItem.text ) - 1 ) + Gui._inputItem.text = Util.utf8Sub( Gui._inputItem.text, 0, utf8.len( Gui._inputItem.text ) - 1 ) elseif key == RL.KEY_ENTER or key == RL.KEY_KP_ENTER then if Gui._inputItem.allowLineBreak then Gui._inputItem.text = Gui._inputItem.text.."\n" @@ -615,8 +615,8 @@ function Container:scroll( pos ) return end - self._scrollRect.x = util.clamp( pos.x, 0, self._scrollRect.width - self.bounds.width ) - self._scrollRect.y = util.clamp( pos.y, 0, self._scrollRect.height - self.bounds.height ) + self._scrollRect.x = Util.clamp( pos.x, 0, self._scrollRect.width - self.bounds.width ) + self._scrollRect.y = Util.clamp( pos.y, 0, self._scrollRect.height - self.bounds.height ) self:update() end diff --git a/examples/resources/lib/rectangle.lua b/examples/resources/lib/rectangle.lua index 2f9ad6c..3c0adf5 100644 --- a/examples/resources/lib/rectangle.lua +++ b/examples/resources/lib/rectangle.lua @@ -1,4 +1,6 @@ Rectangle = {} +-- Rectangle.TYPE = "Rectangle" + Rectangle.meta = { __index = Rectangle, __tostring = function( r ) diff --git a/examples/resources/lib/utillib.lua b/examples/resources/lib/utillib.lua index 3021465..920ebd7 100644 --- a/examples/resources/lib/utillib.lua +++ b/examples/resources/lib/utillib.lua @@ -114,6 +114,9 @@ function utillib.split( str, sep ) for str in string.gmatch( str, "([^"..sep.."]+)" ) do table.insert( t, str ) end + -- for s in string.gmatch( str, "([^"..sep.."]+)" ) do + -- table.insert( t, s ) + -- end return t end -- cgit v1.2.3