From 973d902a16b35258629d2a0b228ad9c3f49b6198 Mon Sep 17 00:00:00 2001 From: jussi Date: Thu, 8 Dec 2022 18:24:41 +0200 Subject: [PATCH] ReiLuaGui File explorer. --- API.md | 9 + changelog | 4 +- devnotes | 6 - .../calculator.lua} | 80 +---- examples/ReiLuaGui_examples/file_explorer.lua | 319 ++++++++++++++++++ examples/ReiLuaGui_examples/main.lua | 87 +++++ .../{ReiLuaGui => ReiLuaGui_test}/main.lua | 2 +- examples/resources/images/LICENCE | 5 +- examples/resources/images/files.png | Bin 0 -> 7500 bytes examples/resources/images/open-folder.png | Bin 0 -> 6243 bytes examples/resources/images/previous-button.png | Bin 0 -> 6820 bytes examples/resources/lib/gui.lua | 23 +- examples/resources/lib/utillib.lua | 4 + include/core.h | 1 + src/core.c | 18 + src/lua_core.c | 1 + 16 files changed, 473 insertions(+), 86 deletions(-) rename examples/{ReiLuaGui_calculator/main.lua => ReiLuaGui_examples/calculator.lua} (77%) create mode 100644 examples/ReiLuaGui_examples/file_explorer.lua create mode 100644 examples/ReiLuaGui_examples/main.lua rename examples/{ReiLuaGui => ReiLuaGui_test}/main.lua (99%) create mode 100644 examples/resources/images/files.png create mode 100644 examples/resources/images/open-folder.png create mode 100644 examples/resources/images/previous-button.png diff --git a/API.md b/API.md index 5b14782..e625af1 100644 --- a/API.md +++ b/API.md @@ -2083,6 +2083,15 @@ Change working directory, return true on success --- +> isFile = RL_IsPathFile( string path ) + +Check if a given path is a file or a directory + +- Failure return nil +- Success return bool + +--- + > fileDropped = RL_IsFileDropped() Check if a file has been dropped into window diff --git a/changelog b/changelog index d44b08d..e630e73 100644 --- a/changelog +++ b/changelog @@ -7,7 +7,9 @@ KEY CHANGES: - ADDED: Easings extra module. - ADDED: exit function. - FIXED: uluaGetNPatchInfo fix for RL_DrawTextureNPatch. Guess this was never tested and did not work at all >:E. + - ADDED: Flag option (-s) for doc_parser.lua for exporting module APIs to separate files. - ADDED: ReiLuaGui. + - ADDED: ReiLuaGui Examples. Detailed changes: ADDED: Help argument. @@ -15,7 +17,7 @@ CHANGED: Changed fuction name RL_rlSetLineWidth to RL_rlglSetLineWidth. CHANGED: Changed fuction name RL_rlGetLineWidth to RL_rlglGetLineWidth. FIXED: DrawRectangleGradient V and H expecting wrong arguments. ADDED: RL_LoadDirectoryFilesEx. -ADDED: Flag option (-s) for doc_parser.lua for exporting module APIs to separate files. FIXED: RL_DrawLineBezierQuad was called RL_DrawLineBezier in API. ADDED: Color lib. FIXED: RL_DrawEllipse and RL_DrawEllipseLines expecting wrong arguments. +ADDED: RL_IsPathFile. diff --git a/devnotes b/devnotes index a2811a1..eb6a635 100644 --- a/devnotes +++ b/devnotes @@ -1,10 +1,4 @@ Current { - * ReiLuaGui - * Examples: - * Movable window. - * Calculator. - * Grid icon window. - * File explorer. } Backlog { diff --git a/examples/ReiLuaGui_calculator/main.lua b/examples/ReiLuaGui_examples/calculator.lua similarity index 77% rename from examples/ReiLuaGui_calculator/main.lua rename to examples/ReiLuaGui_examples/calculator.lua index 57ba9a1..6f2023b 100644 --- a/examples/ReiLuaGui_calculator/main.lua +++ b/examples/ReiLuaGui_examples/calculator.lua @@ -1,28 +1,3 @@ -package.path = package.path..";"..RL_GetBasePath().."../resources/lib/?.lua" - -util = require( "utillib" ) -Vec2 = require( "vector2" ) -Rect = require( "rectangle" ) -Color = require( "color" ) -Gui = require( "gui" ) - --- Textures. - -local cancelTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/cancel.png" ) -local borderTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/ui_border.png" ) -local bgrTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/ui_bgr.png" ) - -RL_GenTextureMipmaps( cancelTexture ) -RL_GenTextureMipmaps( bgrTexture ) - -RL_SetTextureFilter( cancelTexture, TEXTURE_FILTER_TRILINEAR ) -RL_SetTextureFilter( bgrTexture, TEXTURE_FILTER_TRILINEAR ) - -RL_SetTextureWrap( borderTexture, TEXTURE_WRAP_REPEAT ) -RL_SetTextureWrap( bgrTexture, TEXTURE_WRAP_REPEAT ) - --- Calculator definition. - Calculator = {} Calculator.__index = Calculator @@ -38,7 +13,7 @@ function Calculator:new( pos ) object.windowRect = Rect:new( pos.x, pos.y, 196, 244 ) object.dragPos = Vec2:new( 0, 0 ) - -- Handle + -- Handle. object.handle = Gui.element:new( { bounds = Rect:new( 0, 0, object.windowRect.width, object.HANDLE_HIGHT ), @@ -133,8 +108,8 @@ function Calculator:new( pos ) table.insert( object.buttons, Gui.element:new( { bounds = Rect:new( 0, 0, 40, 32 ), drawBounds = true, - onMouseOver = function( self ) self.color = Color:new( LIGHTGRAY ) end, - notMouseOver = function( self ) self.color = Color:new( GRAY ) end, + onMouseOver = function( self ) self.color = Color:new( WHITE ) end, + notMouseOver = function( self ) self.color = Color:new( LIGHTGRAY ) end, } ) ) object.buttons[ #object.buttons ].pos = Vec2:new( 8 + x * 46, object.HANDLE_HIGHT + object.DISPLAY_HIGHT + 16 + y * 38 ) @@ -304,51 +279,4 @@ function Calculator:equals() self:updateDisplay() end --- End of calculator definition. - -local calculator = nil -local calculator2 = nil -local showButton = nil - -function initGui() - showButton = Gui.element:new( { - bounds = Rect:new( 0, 0, 96, 32 ), - drawBounds = true, - onClicked = function() - calculator:setVisible( true ) - calculator2:setVisible( true ) - end, - onMouseOver = function( self ) self.color = Color:new( LIGHTGRAY ) end, - notMouseOver = function( self ) self.color = Color:new( GRAY ) end, - } ) - - showButton:add( Gui.text:new( { text = "Show", VAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER } ) ) - - calculator = Calculator:new( Vec2:new( 128, 96 ) ) - calculator2 = Calculator:new( Vec2:new( 340, 96 ) ) -end - -function init() - local monitor = 0 - local mPos = RL_GetMonitorPosition( monitor ) - local mSize = RL_GetMonitorSize( monitor ) - winSize = RL_GetWindowSize() - - RL_SetWindowTitle( "Calculator" ) - RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) - RL_SetWindowState( FLAG_VSYNC_HINT ) - RL_SetWindowSize( winSize ) - RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) - - initGui() -end - -function process( delta ) - Gui.process( Vec2:new( RL_GetMousePosition() ) ) -end - -function draw() - RL_ClearBackground( RAYWHITE ) - - Gui.draw() -end +return Calculator diff --git a/examples/ReiLuaGui_examples/file_explorer.lua b/examples/ReiLuaGui_examples/file_explorer.lua new file mode 100644 index 0000000..692093e --- /dev/null +++ b/examples/ReiLuaGui_examples/file_explorer.lua @@ -0,0 +1,319 @@ +FileExplorer = {} +FileExplorer.__index = FileExplorer + +function FileExplorer:new( pos ) + pos = pos or Vec2:new( 0, 0 ) + + local object = setmetatable( {}, self ) + + object.HANDLE_HIGHT = 32 + object.DISPLAY_HIGHT = 40 + object.OPERATIONS = { ADD = 0, SUB = 1, MUL = 2, DIV = 3 } + + object.windowRect = Rect:new( pos.x, pos.y, 500, 330 ) + object.dragPos = Vec2:new( 0, 0 ) + + -- Handle. + + object.handle = Gui.element:new( { + bounds = Rect:new( 0, 0, object.windowRect.width, object.HANDLE_HIGHT ), + padding = 10, + onClicked = function() + object:set2Top() + object.dragPos = Vec2:new( RL_GetMousePosition() ) - Vec2:new( object.handle.bounds.x, object.handle.bounds.y ) + Gui.heldCallback = function() object:drag() end + end, + } ) + + object.handle:add( Gui.texture:new( { + bounds = object.handle.bounds:clone(), + texture = bgrTexture, + HAling = Gui.ALING.CENTER, + VAling = Gui.ALING.CENTER, + color = Color:new( LIGHTGRAY ), + } ) ) + + object.handle:add( Gui.texture:new( { + bounds = object.handle.bounds:clone(), + texture = borderTexture, + HAling = Gui.ALING.CENTER, + VAling = Gui.ALING.CENTER, + color = Color:new( LIGHTGRAY ), + nPatchInfo = { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = NPATCH_NINE_PATCH }, + } ) ) + + object.handle:add( Gui.text:new( { text = "File Explorer", fontSize = 20, VAling = Gui.ALING.CENTER } ) ) + + -- Close button. + + object.closeButton = Gui.element:new( { + bounds = Rect:new( 0, 0, object.HANDLE_HIGHT, object.HANDLE_HIGHT ), + onClicked = function() + object:setVisible( false ) + end, + onMouseOver = function( self ) self.items[1].color = Color:new( WHITE ) end, + notMouseOver = function( self ) self.items[1].color = Color:new( BLACK ) end, + } ) + + object.closeButton:add( Gui.texture:new( { + bounds = object.closeButton.bounds:clone(), + texture = cancelTexture, + HAling = Gui.ALING.CENTER, + VAling = Gui.ALING.CENTER, + } ) ) + + -- Panel. + + object.panel = Gui.element:new( { + bounds = Rect:new( 0, 0, object.windowRect.width, object.windowRect.height - object.HANDLE_HIGHT ), + } ) + + object.panel:add( Gui.texture:new( { + bounds = object.panel.bounds:clone(), + texture = bgrTexture, + HAling = Gui.ALING.CENTER, + VAling = Gui.ALING.CENTER, + color = Color:new( GRAY ), + } ) ) + + object.panel:add( Gui.texture:new( { + bounds = object.panel.bounds:clone(), + texture = borderTexture, + HAling = Gui.ALING.CENTER, + VAling = Gui.ALING.CENTER, + color = Color:new( LIGHTGRAY ), + nPatchInfo = { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = NPATCH_NINE_PATCH }, + } ) ) + + -- Path. + + object.pathBox = Gui.element:new( { + bounds = Rect:new( 0, 0, object.windowRect.width - 16 - 64, object.HANDLE_HIGHT ), + drawBounds = true, + color = Color:new( WHITE ), + -- onClicked = function() Gui.setInputFocus( object.pathBox ) end, + -- inputFocus = function() object.pathBox.color = Color:new( BLUE ) end, + -- inputUnfocus = function() object.pathBox.color = Color:new( WHITE ) end, + } ) + + object.pathBox:add( Gui.text:new( { text = "", maxTextLen = 30, allowLineBreak = false, VAling = Gui.ALING.CENTER } ) ) + + -- Back button. + + object.backButton = Gui.element:new( { + bounds = Rect:new( 0, 0, 56, object.HANDLE_HIGHT ), + drawBounds = true, + onMouseOver = function( self ) self.color = Color:new( WHITE ) end, + notMouseOver = function( self ) self.color = Color:new( LIGHTGRAY ) end, + onClicked = function() object:backDir() end, + } ) + + object.backButton:add( Gui.texture:new( { + bounds = Rect:new( 0, 0, object.HANDLE_HIGHT, object.HANDLE_HIGHT ), + texture = backTexture, + HAling = Gui.ALING.CENTER, + color = Color:new( BLACK ) + } ) ) + + -- Files. + + object.files = Gui.container:new( { + bounds = Rect:new( 0, 0, object.windowRect.width - 24, 200 ), + drawBounds = true, + scrollable = true, + showScrollbar = true, + -- drawScrollRect = true, + } ) + + -- File name. + + object.fileName = Gui.element:new( { + bounds = Rect:new( 0, 0, object.windowRect.width - 16 - 70, object.HANDLE_HIGHT ), + drawBounds = true, + color = Color:new( WHITE ), + } ) + + object.fileName:add( Gui.text:new( { text = "", maxTextLen = 32, allowLineBreak = false, VAling = Gui.ALING.CENTER } ) ) + + -- Open button. + + object.openButton = Gui.element:new( { + bounds = Rect:new( 0, 0, 64, object.HANDLE_HIGHT ), + drawBounds = true, + color = Color:new( WHITE ), + onClicked = function() object:openFile() end, + onMouseOver = function( self ) self.color = Color:new( WHITE ) end, + notMouseOver = function( self ) self.color = Color:new( LIGHTGRAY ) end, + } ) + + object.openButton:add( Gui.text:new( { text = "Open", VAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER } ) ) + + -- Variables. + + object.path = RL_GetBasePath() + + -- Take last '/' away. + if util.utf8Sub( object.path, utf8.len( object.path ), utf8.len( object.path ) ) == "/" then + object.path = util.utf8Sub( object.path, 1, utf8.len( object.path ) - 1 ) + end + object.file = "" + + -- Update. + + object:setPosition( Vec2:new( object.windowRect.x, object.windowRect.y ) ) + object:updatePath() + + return object +end + +function FileExplorer:updatePath() + local maxLen = self.pathBox.items[1].maxTextLen + local pathLen = utf8.len( self.path ) + local text = "" + + if maxLen < pathLen then + text = self.path:sub( pathLen - maxLen + 1, pathLen ) + else + text = self.path + end + + self.pathBox.items[1]:set( text ) + + self:updateFiles() +end + +function FileExplorer:changeDir( path ) + self.path = path + + self:updatePath() +end + +function FileExplorer:backDir() + self.path = RL_GetPrevDirectoryPath( self.path ) + + self:updatePath() +end + +function FileExplorer:fileSelect( file ) + self.file = file + + self.fileName.items[1]:set( RL_GetFileName( file ) ) +end + +function FileExplorer:openFile() + print( self.file ) +end + +function FileExplorer:updateFiles() + self.files:scroll( Vec2:new( 0, 0 ) ) + + for _, cell in ipairs( self.files.cells ) do + cell:delete() + end + + self.files.cells = {} + + local files = {} + local folders = {} + + for _, file in ipairs( RL_LoadDirectoryFiles( self.path ) ) do + if RL_IsPathFile( file ) then + table.insert( files, file ) + else + table.insert( folders, file ) + end + end + + table.sort( files, function( a, b ) return a < b end ) + table.sort( folders, function( a, b ) return a < b end ) + + for _, folder in ipairs( folders ) do + self:addFileToList( folder, folderTexture, { 150, 120, 80 }, function() self:changeDir( folder ) end ) + end + + for _, file in ipairs( files ) do + self:addFileToList( file, filesTexture, WHITE, function() self:fileSelect( file ) end ) + end +end + +function FileExplorer:addFileToList( file, texture, color, func ) + self.files:add( Gui.element:new( { + bounds = Rect:new( 0, 0, self.windowRect.width - 16 - 20, 20 ), + padding = 4, + onClicked = func, + } ) ) + + local element = self.files.cells[ #self.files.cells ] + + element:add( Gui.text:new( { + bounds = Rect:new( 28, 0, 20, 20 ), + text = RL_GetFileName( file ), + fontSize = 20, + HAling = Gui.ALING.NONE, + VAling = Gui.ALING.CENTER, + } ) ) + + element:add( Gui.texture:new( { + bounds = Rect:new( 0, 0, 20, 20 ), + texture = texture, + VAling = Gui.ALING.CENTER, + color = Color:new( color ), + } ) ) + + element.bounds.width = element.items[1].bounds.width + element.padding + element.items[2].bounds.width +end + +function FileExplorer:drag() + local mousePos = Vec2:new( RL_GetMousePosition() ) + local winPos = Vec2:new( self.handle.bounds.x, self.handle.bounds.y ) + + self:setPosition( mousePos - self.dragPos ) +end + +function FileExplorer:setPosition( pos ) + self.windowRect.x = pos.x + self.windowRect.y = pos.y + + self.handle:setPosition( pos ) + self.closeButton:setPosition( Vec2:new( pos.x + self.windowRect.width - self.HANDLE_HIGHT, pos.y ) ) + self.panel:setPosition( Vec2:new( pos.x, pos.y + self.HANDLE_HIGHT ) ) + self.pathBox:setPosition( Vec2:new( pos.x + 8, pos.y + self.HANDLE_HIGHT + 8 ) ) + self.backButton:setPosition( Vec2:new( pos.x + self.pathBox.bounds.width + 16, pos.y + self.HANDLE_HIGHT + 8 ) ) + self.files:setPosition( Vec2:new( pos.x + 8, pos.y + self.HANDLE_HIGHT * 2 + 16 ) ) + self.fileName:setPosition( Vec2:new( pos.x + 8, pos.y + self.HANDLE_HIGHT * 2 + 16 + 208 ) ) + self.openButton:setPosition( Vec2:new( pos.x + 8 + 420, pos.y + self.HANDLE_HIGHT * 2 + 16 + 208 ) ) +end + +function FileExplorer:setVisible( visible ) + self.handle.visible = visible + self.handle.disabled = not visible + self.panel.visible = visible + self.panel.disabled = not visible + self.closeButton.visible = visible + self.closeButton.disabled = not visible + self.pathBox.visible = visible + self.pathBox.disabled = not visible + self.backButton.visible = visible + self.backButton.disabled = not visible + self.files.visible = visible + self.files.disabled = not visible + self.fileName.visible = visible + self.fileName.disabled = not visible + self.openButton.visible = visible + self.openButton.disabled = not visible + + self.files:update() +end + +function FileExplorer:set2Top() + self.panel:set2Top() + self.handle:set2Top() + self.closeButton:set2Top() + self.pathBox:set2Top() + self.backButton:set2Top() + self.files:set2Top() + self.fileName:set2Top() + self.openButton:set2Top() +end + +return FileExplorer diff --git a/examples/ReiLuaGui_examples/main.lua b/examples/ReiLuaGui_examples/main.lua new file mode 100644 index 0000000..3a54c30 --- /dev/null +++ b/examples/ReiLuaGui_examples/main.lua @@ -0,0 +1,87 @@ +package.path = package.path..";"..RL_GetBasePath().."?.lua" +package.path = package.path..";"..RL_GetBasePath().."../resources/lib/?.lua" + +util = require( "utillib" ) +Vec2 = require( "vector2" ) +Rect = require( "rectangle" ) +Color = require( "color" ) +Gui = require( "gui" ) + +Calculator = require( "calculator" ) +FileExplorer = require( "file_explorer" ) + +-- Textures. + +-- Note that textures are global. +cancelTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/cancel.png" ) +backTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/previous-button.png" ) +folderTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/open-folder.png" ) +filesTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/files.png" ) +borderTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/ui_border.png" ) +bgrTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/ui_bgr.png" ) + +RL_GenTextureMipmaps( cancelTexture ) +RL_GenTextureMipmaps( backTexture ) +RL_GenTextureMipmaps( folderTexture ) +RL_GenTextureMipmaps( filesTexture ) +RL_GenTextureMipmaps( borderTexture ) +RL_GenTextureMipmaps( bgrTexture ) + +RL_SetTextureFilter( cancelTexture, TEXTURE_FILTER_TRILINEAR ) +RL_SetTextureFilter( backTexture, TEXTURE_FILTER_TRILINEAR ) +RL_SetTextureFilter( folderTexture, TEXTURE_FILTER_TRILINEAR ) +RL_SetTextureFilter( filesTexture, TEXTURE_FILTER_TRILINEAR ) +RL_SetTextureFilter( borderTexture, TEXTURE_FILTER_TRILINEAR ) +RL_SetTextureFilter( bgrTexture, TEXTURE_FILTER_TRILINEAR ) + +RL_SetTextureWrap( borderTexture, TEXTURE_WRAP_REPEAT ) +RL_SetTextureWrap( bgrTexture, TEXTURE_WRAP_REPEAT ) + +-- End of calculator definition. + +local calculator = nil +local fileExplorer = nil +local showButton = nil + +function initGui() + showButton = Gui.element:new( { + bounds = Rect:new( 0, 0, 96, 32 ), + drawBounds = true, + onClicked = function() + calculator:setVisible( true ) + fileExplorer:setVisible( true ) + end, + onMouseOver = function( self ) self.color = Color:new( LIGHTGRAY ) end, + notMouseOver = function( self ) self.color = Color:new( GRAY ) end, + } ) + + showButton:add( Gui.text:new( { text = "Show", VAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER } ) ) + + calculator = Calculator:new( Vec2:new( 32, 96 ) ) + fileExplorer = FileExplorer:new( Vec2:new( 280, 96 ) ) +end + +function init() + local monitor = 0 + local mPos = RL_GetMonitorPosition( monitor ) + local mSize = RL_GetMonitorSize( monitor ) + winSize = RL_GetWindowSize() + + RL_SetWindowTitle( "ReiLuaGui examples" ) + RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) + RL_SetWindowState( FLAG_VSYNC_HINT ) + RL_SetWindowSize( winSize ) + RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) + + initGui() +end + +function process( delta ) + Gui.process( Vec2:new( RL_GetMousePosition() ) ) +end + +function draw() + RL_ClearBackground( RAYWHITE ) + + Gui.draw() +end diff --git a/examples/ReiLuaGui/main.lua b/examples/ReiLuaGui_test/main.lua similarity index 99% rename from examples/ReiLuaGui/main.lua rename to examples/ReiLuaGui_test/main.lua index 9890646..ecf3084 100644 --- a/examples/ReiLuaGui/main.lua +++ b/examples/ReiLuaGui_test/main.lua @@ -140,7 +140,7 @@ function init() local mSize = RL_GetMonitorSize( monitor ) winSize = RL_GetWindowSize() - RL_SetWindowTitle( "ReiLua Gui" ) + RL_SetWindowTitle( "ReiLuaGui Test" ) RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) RL_SetWindowState( FLAG_VSYNC_HINT ) RL_SetWindowSize( winSize ) diff --git a/examples/resources/images/LICENCE b/examples/resources/images/LICENCE index bfe263f..3cf6909 100644 --- a/examples/resources/images/LICENCE +++ b/examples/resources/images/LICENCE @@ -9,4 +9,7 @@ ui_bgr.png Jussi Viitala CC0 check-mark.png Delapouite Creative Commons 3.0 https://game-icons.net Resized circle.png Delapouite Creative Commons 3.0 https://game-icons.net Resized plain-circle.png Delapouite Creative Commons 3.0 https://game-icons.net Resized -cancel.png Sbed Creative Commons 3.0 https://game-icons.net Resized \ No newline at end of file +previous-button.png Delapouite Creative Commons 3.0 https://game-icons.net Resized +open-folder.png Delapouite Creative Commons 3.0 https://game-icons.net Resized +files.png Delapouite Creative Commons 3.0 https://game-icons.net Resized +cancel.png Sbed Creative Commons 3.0 https://game-icons.net Resized diff --git a/examples/resources/images/files.png b/examples/resources/images/files.png new file mode 100644 index 0000000000000000000000000000000000000000..503e0d95753cb54e0ead3fa07ca6361656df69ba GIT binary patch literal 7500 zcmeHMc{J4B|DUmBok9u~&zMAF%)&6Hgp6g%Fxj`tET3Uw%$OPbQdyD~TWJubjY?9X zkStkyBBY3jB#}y4N=p4c)YH>*e&2I`=Q-#1`|H=|oI9V-z4!Hg-S_)--}jz-&m>ap ztYOltq#+OpjATP}0N-W{MN$;}&AGYnH3TB{Jlx4m;6M$5b9o#l%O8LX!ngn&2xT!L zkkH=q?(S(i+Ol7|wMQfymNrq3WUOv^ueI(%tLM#u;-{ad}?{s$;*_-t)Mb z8l*lqJilK^HXJ*AqO8^RxP7Vnr(?n$$?xV3?V3c7sK*v$?mD|`>SJJ#WQOqY#t?bM z@o>u9We+^end z${dTD#xNc(McN~^cfXcZtu`grb4z zH_I9a9VojGB^2cfyI%WWs7-xtZ)-t(=w=r*G&ny$J5;uc*nUk|PE=UqnRj65VWOCo z2piq;jNnI!zads*>DFtm!r1G4APZ|3Rw`Z?>%e6Y_hOy88(+mpu74?rP3t|wlUwbi zaJXuu-bWM)&!?z;A?buiOA2i6{m zB(mdY#^x;_K0KIp+~$2fmk2wn{u-fJm-swG-8<{@mU__yh*Y65)6=PIchZ_B|81+B zpBWqztSQdJ(+=dm*?Q~rhsUWWkIVJ~JDpGFN$j;yATnH2wA--ffu;Z2cYQDJoJOtGxW* zMGr*)cSfBB{kdwklNiI{^ZKxTJ~N}l8`stDSQ7}t#`t{IRdu*(@W*6W6}@!oaUybM~#g-b;dndCx(pBCD}}4Qj+=2W&5@;c0WHByZ`EvgRqiZ z74^}s6K!j!vOLwKWc*AArL(FenI(!#ca^}dON`f?DTlNJN1~;i7HPV z*dh+6I?#h9Q56X~&os|vwgon_bS@o^A<~Qvaxro}`*2=5rGallXQdmU8Oo=Xx)Y%l zEAQWd%D(3sC?*ysq022D^#}3?)wQ`xhCC&*l$~u?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kzicv~-S;+d^8)um)X&ZEhi0I^|Ci5?x%j^v0uKK@$iLF}w_LyF z`d144EAa2^`YqSLQs7^Ke`nYKnq1O*FS3lL4qN^culTMp7h4E_&G~n_CAH@>R@cq=*uN zc`SPE7sVLo^`fzBVo1unx_b7y)dUvah4kRo71y|#U6V{L50@Gg#)(vJzY4j~+K}xY zHz?Zom3d#rj=NW?PDKA%fOod6=e7%{hh6fgpwFO{N-5S5#EP2FP#w{m%LXN$E;+nR gG2W31o27X|M8?DuM29A%z;GZWOFQC~E#5Kz1;Sm$fB*mh literal 0 HcmV?d00001 diff --git a/examples/resources/images/open-folder.png b/examples/resources/images/open-folder.png new file mode 100644 index 0000000000000000000000000000000000000000..8a141191aeaccc582b8f011b2a670e088a66d9dd GIT binary patch literal 6243 zcmeHLX;4#H77oZ7L8F3zh{h<&mX(mLStV>jWC^kadtr^fW`%>Zv45oQ5&Ob=z2gD%75)qfj2a&Q^F^B}^ zJT43-?`{tcF0HeeHPLAir>%jyNrSHzeg$?RF)*~TfV7qVzf5< zeNt0NJEv$ihIXls&`QsKHa9Ic@45dTquY@gQChX$6EfpFk60IM6ErThi6;JR2qS5W zUR^ai9ECitIZ(N6R?OZpe$cYi@k+vO%cUJs$Fn+Zzjq9>t7 zr=q&>;e>2|TC1gYulc>6?o$)FBR#O*j@A`#wVxcd9}lk{GjGj)^~bsK1&S`~=!1Kc zPWMz69_<)Xml=89XiG$9uC;w{74$mN?RS-c&@gzExo1PDzyAVp6zIRkBdXnXt$*T9 zS904TY>2_Flh!4jz6Qr$_XmW=?^{QO)f2+VMWWJz^Za%2pW0Oeis88-i5W-gI?0=V z$cc$m&r1{E)gNjLIjoCUqsDI2*;!Cy(LPIEG(KT^nSi+PGZ=YLtA6-b)Y@`4)kTih zTIlY_NjE$Hq2iyMhfem@QQMlyI+GPr)v?~(i~u{K)@oy%ow&6$AW*ANw`>OK*)pr2 z%-8Gs32Z90C$zYZ*GrR9)RBi_Y54iC1{qs*O`AG`HfFyhbw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==Of`K}=badWc_PMC uO<`TQN9v1U5vrQcdKa%GZ#oZP-)OWpA%KP!gCJ-wn1{=1dhyDzZT|!!ehi-g literal 0 HcmV?d00001 diff --git a/examples/resources/images/previous-button.png b/examples/resources/images/previous-button.png new file mode 100644 index 0000000000000000000000000000000000000000..fa4ba7ece1422e7d9a6697274300bafdafccb57e GIT binary patch literal 6820 zcmeHMdo)zv+aE$9A%u`IDTy%`<1&*WcT(OK)9+56eg^V!ey+0TB?K5ODgHkM){ z>qQ_Ch#0}j%ntnB&bwEw0H2vRBPSt{mBR-eoH=&nAgCXUNu&D!P)>*+00n~SGzcWP z|CO^-=}X+2#kQ?9VJ;aPzq{;+%V*5?9iGJpWf^*H}(}_xSCF#k8^u>blLxpYgjX-Pmx{ng@K6Jtbw9^ieWX`?(vrdqq1tbDyN4ZR+%{z7hCTa^g3~J!^m-C zrG<46*~ykb?)3aB^Gu5 zEQO$3Icjf(DmY_*d-EPuVzy}l_Ibw6#x%jxqOY|cl6L6yIXdC{NED*ZgYNCwFVdO0 zEh(;yf`2i#%~*=#=X==*Q*jc#V%Sp7KR?MbEvNrF=EI>^@k(oyhEs zhqfq;#I2`M49vW2)Ur@3_8-jM<&JL;pLhA-R6GRrO<6=a<-1aj-rXP)9+opx#gYuw;aqaTioI= zjv!aW6gI%hWljf;>xlc+v9nJyE_nkEZ0mPkB|6 zR;CvbLW;7JdRX(Mo6L8cIo+t*_AvQc{iydleV^B!^i3^AiHu{Vz1|% zU!iaZ61y(SdavfBVjL`QbG{G6{eg?M^qTQU*5)@}O`Eg_(3L_3FX!z_;43xpvQ&-n z(pczi%d3+wAMxjCq~}pCNxt(%eUv;YI$SlqAcQ2hH96gVuJ|^3$~2JNiWD4-+^JSo z^U6d|^NI~eHdWAVG)ih;)}HBZqR(ab zhwfeMH{9u7SM?AoPpI(guv{snstoU8$O~UAvGezz>J(PV-x84YEJ?CBYX-AKtC93SOmEP;n(G97yD$Sp9 zpT{YIpPpMCzPupb5_#z2n!}EYL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5B=umXXa4Z_53&&vfJm4PMSY0>`!03{704xfF z#QX$BV6Zu41_j_jf#6zn5J#V^tw+HEXgCF_3&1hDXk9o~TbBZ-g0^Uy9!*ahL-`59 zmPH4%lI-)dS3D>x2t~z^sYq?A4xHuzc)&3q74Dg|f3 zWciZ8<)r(PJpqIt!*h9nM>x)yM8Lz)TF4&~k`I|f0}b#nYdRw!_{V?)-50Ruka=vP zboG!rNVE=C4}-<%=%arqIRY#;n29`06jDq3%Ls2-a9}VXv1DGJf&j}FU@SOO7C`1O zSq@C54<5#I3CgqlK1>9+6P3&%n~^yH2#Q3baVRtnsqcWo;Luo{j;;n0?Ea+Bq|#|2 z|C=^%^FR&0EV&h(4bC63Ec&ve>;eBTy)RuK`tnwSLYFrMj!gLy0-GENP?!A#vAzsZ zyvPhs0IVKg)AgI2{%=x2TOUKlAOSr%g+@Vx*#z+N3ebg904$(K(+5{j`@f;HnKVui znFSbof;@s;f$6!-6?Dt;LaG1iOOO}9TLq9XI0_B_L73iG!Vq5rM(}FJw}=f8|AP~Q zWrd%L3~2X71{N={79zeE!>^q2%FciA`nneX!5Kj4Ka>0xzklfZL)ULH@LS4%vg;3B zzs10BDgVi?|1-Koetb>=4Db{b1b!?jkoFouApGY@)(++*1lWWu{ki@y@c)$oOLML% zn4^3gI~#k*_7@Mqzh@wP9y=|~AhCitwgI}jS^v}0z04|Ozpgr)`-og?j5KQ$kw$YX{EUd&7c<$g1L>^Rg?Wu{{{9Y BONIad literal 0 HcmV?d00001 diff --git a/examples/resources/lib/gui.lua b/examples/resources/lib/gui.lua index c7609c1..4e4ee7e 100644 --- a/examples/resources/lib/gui.lua +++ b/examples/resources/lib/gui.lua @@ -226,7 +226,7 @@ Text.__index = Text function Text:new( set ) local object = setmetatable( {}, Text ) - object.bounds = Rect:new( 0, 0, 0, 0 ) + object.bounds = setProperty( set, "bounds", Rect:new( 0, 0, 0, 0 ) ) object.HAling = setProperty( set, "HAling", Gui.ALING.LEFT ) object.VAling = setProperty( set, "VAling", Gui.ALING.BOTTOM ) @@ -557,6 +557,8 @@ function Container:new( set ) object.showScrollbar = setProperty( set, "showScrollbar", false ) object.scrollbarWidth = setProperty( set, "scrollbarWidth", Gui.scrollbarWidth ) object.scrollAmount = setProperty( set, "scrollAmount", Gui.scrollAmount ) -- When using mouse scroll. + object.color = setProperty( set, "color", Color:new( WHITE ) ) + object.drawBounds = setProperty( set, "drawBounds", false ) object.drawScrollRect = setProperty( set, "drawScrollRect", false ) -- For grid container. Do not set both. object.columns = setProperty( set, "columns", nil ) @@ -661,6 +663,12 @@ function Container:updateScrollbar() self._VScrollbar.items[1].bounds.width = self.scrollbarWidth self._VScrollbar.items[1].bounds.height = self.bounds.height / self._scrollRect.height * self.bounds.height self._VScrollbar.items[1].bounds.y = self._scrollRect.y / self._scrollRect.height * self.bounds.height + + self._VScrollbar.visible = self.visible + self._VScrollbar.disabled = self.disabled + else + self._VScrollbar.visible = false + self._VScrollbar.disabled = true end if self.bounds.width < self._scrollRect.width then @@ -672,6 +680,12 @@ function Container:updateScrollbar() self._HScrollbar.items[1].bounds.width = self.bounds.width / self._scrollRect.width * self.bounds.width self._HScrollbar.items[1].bounds.height = self.scrollbarWidth self._HScrollbar.items[1].bounds.x = self._scrollRect.x / self._scrollRect.width * self.bounds.width + + self._HScrollbar.visible = self.visible + self._HScrollbar.disabled = self.disabled + else + self._HScrollbar.visible = false + self._HScrollbar.disabled = true end end @@ -727,6 +741,9 @@ function Container:update() cell._visibilityBounds = self._visibilityBounds end + cell.visible = self.visible + cell.disabled = self.disabled + if self.type == Gui.CONTAINER.VERTICAL then if self.HAling == Gui.ALING.CENTER then pos.x = self.bounds.x + self.bounds.width / 2 - cell.bounds.width / 2 @@ -838,6 +855,10 @@ function Container:set2Back() end function Container:draw() + if self.drawBounds then + RL_DrawRectangle( self.bounds, self.color ) + end + if self.drawScrollRect then RL_DrawRectangleLines( { self.bounds.x - self._scrollRect.x, diff --git a/examples/resources/lib/utillib.lua b/examples/resources/lib/utillib.lua index d6e5019..7fb7405 100644 --- a/examples/resources/lib/utillib.lua +++ b/examples/resources/lib/utillib.lua @@ -152,6 +152,10 @@ function utillib.toBoolean( v ) return false end +function utillib.boo2Number( bool ) + return bool and 1 or 0 +end + -- Print table content. function utillib.printt( t ) print( tostring(t).." = {" ) diff --git a/include/core.h b/include/core.h index cdd644f..af9e8bd 100644 --- a/include/core.h +++ b/include/core.h @@ -87,6 +87,7 @@ int lcoreGetWorkingDirectory( lua_State *L ); int lcoreLoadDirectoryFiles( lua_State *L ); int lcoreLoadDirectoryFilesEx( lua_State *L ); int lcoreChangeDirectory( lua_State *L ); +int lcoreIsPathFile( lua_State *L ); int lcoreIsFileDropped( lua_State *L ); int lcoreLoadDroppedFiles( lua_State *L ); int lcoreGetFileModTime( lua_State *L ); diff --git a/src/core.c b/src/core.c index eabfe52..dd2783a 100644 --- a/src/core.c +++ b/src/core.c @@ -2243,6 +2243,24 @@ int lcoreChangeDirectory( lua_State *L ) { return 1; } +/* +> isFile = RL_IsPathFile( string path ) + +Check if a given path is a file or a directory + +- Failure return nil +- Success return bool +*/ +int lcoreIsPathFile( lua_State *L ) { + if ( !lua_isstring( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_IsPathFile( string path )" ); + lua_pushnil( L ); + return 1; + } + lua_pushboolean( L, IsPathFile( lua_tostring( L, -1 ) ) ); + return 1; +} + /* > fileDropped = RL_IsFileDropped() diff --git a/src/lua_core.c b/src/lua_core.c index defd8f2..2a07a90 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -750,6 +750,7 @@ void luaRegister() { lua_register( L, "RL_LoadDirectoryFiles", lcoreLoadDirectoryFiles ); lua_register( L, "RL_LoadDirectoryFilesEx", lcoreLoadDirectoryFilesEx ); lua_register( L, "RL_ChangeDirectory", lcoreChangeDirectory ); + lua_register( L, "RL_IsPathFile", lcoreIsPathFile ); lua_register( L, "RL_IsFileDropped", lcoreIsFileDropped ); lua_register( L, "RL_LoadDroppedFiles", lcoreLoadDroppedFiles ); lua_register( L, "RL_GetFileModTime", lcoreGetFileModTime );