From 8182c486e64f21c6f95b9108b0e506e603c2a65c Mon Sep 17 00:00:00 2001 From: jussi Date: Mon, 17 Apr 2023 17:55:27 +0300 Subject: Raygui wrapper examples. --- devnotes | 12 +- examples/ReiLuaGui_examples/main.lua | 2 +- examples/raygui_examples/calculator.lua | 160 ++++++++++++++++++++++ examples/raygui_examples/main.lua | 44 ++++++ examples/raygui_lib/main.lua | 153 +++++++++++---------- examples/resources/lib/raygui.lua | 230 ++++++++++++++++++++++++++------ 6 files changed, 485 insertions(+), 116 deletions(-) create mode 100644 examples/raygui_examples/calculator.lua create mode 100644 examples/raygui_examples/main.lua diff --git a/devnotes b/devnotes index b0392b3..c323107 100644 --- a/devnotes +++ b/devnotes @@ -1,18 +1,18 @@ Current { - * Check new functions from https://github.com/raysan5/raylib/blob/master/CHANGELOG - * Tilemap clib. + * Check raylib changes from https://github.com/raysan5/raylib/blob/master/CHANGELOG } Backlog { - * IsWaveReady and other Is* ready functions. + * Platformer example physics process for true framerate independence. * Extend color lib functionality. + * Tilemap clib. Fast tilemap draw and clib example. - * Platformer example physics process for true framerate independence. - * rlgl - * More low level functions. Could be usefull now when for example draw polygon is removed. + * IsWaveReady and other Is* ready functions. * Text * Ability to set font texture filtering. * Codepoints? + * rlgl + * More low level functions. Could be usefull now when for example DrawTexturePoly is removed. * Audio * AudioStream. * Core. diff --git a/examples/ReiLuaGui_examples/main.lua b/examples/ReiLuaGui_examples/main.lua index 3c120b5..29dace8 100644 --- a/examples/ReiLuaGui_examples/main.lua +++ b/examples/ReiLuaGui_examples/main.lua @@ -1,7 +1,7 @@ package.path = package.path..";"..RL.GetBasePath().."?.lua" package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" -Util = require( "utillib" ) +util = require( "utillib" ) Vec2 = require( "vector2" ) Rect = require( "rectangle" ) Color = require( "color" ) diff --git a/examples/raygui_examples/calculator.lua b/examples/raygui_examples/calculator.lua new file mode 100644 index 0000000..0bbad98 --- /dev/null +++ b/examples/raygui_examples/calculator.lua @@ -0,0 +1,160 @@ +Calculator = {} +Calculator.__index = Calculator + +Calculator.OPERATIONS = { + ADD = 0, + SUB = 1, + DIV = 2, + MUL = 3, + EQUAL = 4, + CLEAR = 5, +} + +function Calculator:new( pos ) + local object = setmetatable( {}, Calculator ) + + object.window = Raygui.WindowBox:new( + Rect:new( pos.x, pos.y, 188, 216 ), + "Calculator", + -- Close callback. + function() object:setVisible( false ) end, + -- Grab callback. + function() object:set2Top() end, + -- Drag callback. + function( self ) object:setPosition( Vec2:new( self.bounds.x, self.bounds.y ) ) end + ) + object.display = Raygui.Label:new( + Rect:new( 0, 0, 180, 20 ), + "" + ) + object.display.position = Vec2:new( 10, 32 ) + object.buttons = {} + + local buttons = { + { "7", function() object:addNumber( 7 ) end }, + { "8", function() object:addNumber( 8 ) end }, + { "9", function() object:addNumber( 9 ) end }, + { "/", function() object:addOperation( self.OPERATIONS.DIV ) end }, + { "4", function() object:addNumber( 4 ) end }, + { "5", function() object:addNumber( 5 ) end }, + { "6", function() object:addNumber( 6 ) end }, + { "*", function() object:addOperation( self.OPERATIONS.MUL ) end }, + { "1", function() object:addNumber( 1 ) end }, + { "2", function() object:addNumber( 2 ) end }, + { "3", function() object:addNumber( 3 ) end }, + { "-", function() object:addOperation( self.OPERATIONS.SUB ) end }, + { "0", function() object:addNumber( 0 ) end }, + { "C", function() object:addOperation( self.OPERATIONS.CLEAR ) end }, + { "=", function() object:addOperation( self.OPERATIONS.EQUAL ) end }, + { "+", function() object:addOperation( self.OPERATIONS.ADD ) end }, + } + local rowCount = 4 + local buttonRect = Rect:new( 5, 64, 40, 32 ) + local startPos = Vec2:new( buttonRect.x, buttonRect.y ) + local buttonSpacing = 6 + + for i, button in ipairs( buttons ) do + table.insert( object.buttons, Raygui.Button:new( + buttonRect:clone(), + button[1], + button[2] + ) ) + -- Set position in window. + object.buttons[i].position = Vec2:new( buttonRect.x, buttonRect.y ) + + if i % rowCount == 0 then + buttonRect.x = startPos.x + buttonRect.y = buttonRect.y + buttonRect.height + buttonSpacing + else + buttonRect.x = buttonRect.x + buttonRect.width + buttonSpacing + end + end + + object.visible = true + object.numbers = { "", "" } + object.op = nil + + object:setPosition( pos ) + + return object +end + +function Calculator:addNumber( num ) + if self.op == nil then + self.numbers[1] = self.numbers[1]..tostring( num ) + else + self.numbers[2] = self.numbers[2]..tostring( num ) + end + + self:updateDisplay() +end + +function Calculator:addOperation( op ) + if op == self.OPERATIONS.EQUAL then + if self.op == self.OPERATIONS.ADD then + self.numbers[1] = tonumber( self.numbers[1] ) + tonumber( self.numbers[2] ) + elseif self.op == self.OPERATIONS.SUB then + self.numbers[1] = tonumber( self.numbers[1] ) - tonumber( self.numbers[2] ) + elseif self.op == self.OPERATIONS.MUL then + self.numbers[1] = tonumber( self.numbers[1] ) * tonumber( self.numbers[2] ) + elseif self.op == self.OPERATIONS.DIV then + self.numbers[1] = tonumber( self.numbers[1] ) / tonumber( self.numbers[2] ) + end + + self.numbers[2] = "" + self.op = nil + elseif op == self.OPERATIONS.CLEAR then + self.numbers[1] = "" + self.numbers[2] = "" + self.op = nil + else + self.op = op + end + + self:updateDisplay() +end + +function Calculator:updateDisplay() + self.display.text = self.numbers[1] + + if self.op == self.OPERATIONS.ADD then + self.display.text = self.display.text.."+" + elseif self.op == self.OPERATIONS.SUB then + self.display.text = self.display.text.."-" + elseif self.op == self.OPERATIONS.MUL then + self.display.text = self.display.text.."*" + elseif self.op == self.OPERATIONS.DIV then + self.display.text = self.display.text.."/" + end + + self.display.text = self.display.text..self.numbers[2] +end + +function Calculator:setPosition( pos ) + self.display:setPosition( pos + self.display.position ) + + for _, button in ipairs( self.buttons ) do + button:setPosition( pos + button.position ) + end +end + +function Calculator:set2Top() + Raygui.set2Top( self.window ) + Raygui.set2Top( self.display ) + + for _, button in ipairs( self.buttons ) do + Raygui.set2Top( button ) + end +end + +function Calculator:setVisible( visible ) + self.visible = visible + self.window.visible = visible + self.display.visible = visible + + for _, button in ipairs( self.buttons ) do + button.visible = visible + end +end + +return Calculator \ No newline at end of file diff --git a/examples/raygui_examples/main.lua b/examples/raygui_examples/main.lua new file mode 100644 index 0000000..844ad39 --- /dev/null +++ b/examples/raygui_examples/main.lua @@ -0,0 +1,44 @@ +package.path = package.path..";"..RL.GetBasePath().."?.lua" +package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" + + +Util = require( "utillib" ) +Rect = require( "rectangle" ) +Vec2 = require( "vector2" ) +Color = require( "color" ) +Raygui = require( "raygui" ) +Calculator = require( "calculator" ) + +local calculator = nil +local calculator2 = nil + +function RL.init() + local monitor = 0 + local mPos = Vec2:new( RL.GetMonitorPosition( monitor ) ) + local mSize = Vec2:new( RL.GetMonitorSize( monitor ) ) + local winSize = Vec2:new( 1024, 800 ) + + RL.SetWindowTitle( "Raygui examples" ) + RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + RL.SetWindowSize( winSize ) + RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } ) + + RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 20 ) + RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SPACING, 4 ) + + calculator = Calculator:new( Vec2:new( 32, 32 ) ) + calculator2 = Calculator:new( Vec2:new( 64, 65 ) ) +end + +function RL.process( delta ) + -- Gui:process() + Raygui:process() +end + +function RL.draw() + RL.ClearBackground( RL.DARKBLUE ) + + -- Gui:draw() + Raygui:draw() +end diff --git a/examples/raygui_lib/main.lua b/examples/raygui_lib/main.lua index f2594fe..39f25cd 100644 --- a/examples/raygui_lib/main.lua +++ b/examples/raygui_lib/main.lua @@ -6,8 +6,6 @@ Vec2 = require( "vector2" ) Color = require( "color" ) Raygui = require( "raygui" ) -local raygui = Raygui:new() - local grid = {} local windowbox = {} local winOpen = true @@ -27,39 +25,39 @@ function RL.init() 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( + local label = Raygui.Label:new( Rect:new( 16, 16, 64, 32 ), "Cat" - ) ) - local toggleGroup = raygui:add( raygui.ToggleGroup:new( + ) + local toggleGroup = 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( + ) + local button = Raygui.Button:new( Rect:new( 245, 188, 64, 32 ), "Dog", function() toggleGroup:setText( "Dog;Cat\nEagle" ) end - ) ) - local checkbox = raygui:add( raygui.CheckBox:new( + ) + local checkbox = Raygui.CheckBox:new( Rect:new( 64, 128, 20, 20 ), "Dog", false - ) ) - local combobox = raygui:add( raygui.ComboBox:new( + ) + local combobox = Raygui.ComboBox:new( Rect:new( 64, 256, 128, 32 ), "Dog\nCow\nDonkey", 0 - ) ) - local dropdownbox = raygui:add( raygui.DropdownBox:new( + ) + local dropdownbox = 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( + ) + local spinner = Raygui.Spinner:new( Rect:new( 464, 256, 128, 32 ), "Health", 0, @@ -67,8 +65,8 @@ function RL.init() 10, false, function( self ) print( "Spinner value changed to "..self.value ) end - ) ) - local valuebox = raygui:add( raygui.ValueBox:new( + ) + local valuebox = Raygui.ValueBox:new( Rect:new( 464, 316, 128, 32 ), "Health", 0, @@ -76,22 +74,22 @@ function RL.init() 100, false, function( self ) print( "ValueBox value changed to "..self.value ) end - ) ) - local textbox = raygui:add( raygui.TextBox:new( + ) + local textbox = 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( + ) + local textboxmulti = 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( + ) + local slider = Raygui.Slider:new( Rect:new( 50, 500, 256, 32 ), "min", "max", @@ -99,8 +97,8 @@ function RL.init() 0, 100, function( self ) print( "Changed value "..self.value ) end - ) ) - local sliderbar = raygui:add( raygui.SliderBar:new( + ) + local sliderbar = Raygui.SliderBar:new( Rect:new( 50, 550, 256, 32 ), "min", "max", @@ -108,8 +106,8 @@ function RL.init() 0, 100, function( self ) print( "Changed value "..self.value ) end - ) ) - local progressbar = raygui:add( raygui.ProgressBar:new( + ) + local progressbar = Raygui.ProgressBar:new( Rect:new( 50, 600, 256, 32 ), "min", "max", @@ -117,60 +115,69 @@ function RL.init() 0, 100, function( self ) print( "Changed value "..self.value ) end - ) ) - local statusbar = raygui:add( raygui.StatusBar:new( + ) + local statusbar = Raygui.StatusBar:new( Rect:new( 50, 650, 256, 32 ), "StatusBar" - ) ) - local dummyrec = raygui:add( raygui.DummyRec:new( + ) + local dummyrec = Raygui.DummyRec:new( Rect:new( 50, 700, 256, 32 ), "DummyRec" - ) ) - grid = raygui:add( raygui.Grid:new( + ) + grid = Raygui.Grid:new( Rect:new( 400, 400, 256, 256 ), "Grid", 32, 2 - ) ) - windowbox = raygui:add( raygui.WindowBox:new( + ) + windowbox = Raygui.WindowBox:new( Rect:new( 720, 250, 256, 256 ), "WindowBox", - function( self ) self.visible = false end - ) ) - local groupbox = raygui:add( raygui.GroupBox:new( + -- Close callback. + function( self ) self.visible = false end, + -- Grab callback. + function( self ) Raygui.set2Top( self ) end + ) + local groupbox = Raygui.GroupBox:new( Rect:new( 400, 700, 256, 256 ), "GroupBox" - ) ) - local line = raygui:add( raygui.Line:new( + ) + local line = Raygui.Line:new( Rect:new( 400, 32, 256, 16 ), "Line" - ) ) - local panel = raygui:add( raygui.Panel:new( + ) + local panel = Raygui.Panel:new( Rect:new( 400, 64, 256, 128 ), - "Panel" - ) ) - local scrollpanel = raygui:add( raygui.ScrollPanel:new( + "Panel", + -- Grab callback. + function( self ) Raygui.set2Top( self ) end + ) + local scrollpanel = Raygui.ScrollPanel:new( Rect:new( 800, 64, 256, 256 ), "ScrollPanel", Rect:new( 0, 0, 256, 600 ), - Vec2:new( 0, 0 ) - ) ) - local listview = raygui:add( raygui.ListView:new( + Vec2:new( 0, 0 ), + -- Callback. + nil, + -- Grab callback. + function( self ) Raygui.set2Top( self ) end + ) + local listview = Raygui.ListView:new( Rect:new( 1100, 64, 128, 80 ), "Cat\nDog\nHorse\nCow\nPig\nEagle\nLion", 0, 0, function( self ) print( self:getItem( self.active ) ) end - ) ) - local listviewex = raygui:add( raygui.ListViewEx:new( + ) + local listviewex = Raygui.ListViewEx:new( Rect:new( 1300, 64, 128, 80 ), "Cat\nDog\nHorse\nCow\nPig\nEagle\nLion", 0, 0, 0, function( self ) print( self:getItem( self.active ) ) end - ) ) - local messagebox = raygui:add( raygui.MessageBox:new( + ) + local messagebox = Raygui.MessageBox:new( Rect:new( 1100, 150, 300, 128 ), "Title", "Message", @@ -180,14 +187,16 @@ function RL.init() print( "You pressed "..self:getItem( self.buttonIndex ) ) if self.buttonIndex == 1 then - raygui:set2Back( windowbox ) + Raygui.set2Back( windowbox ) elseif self.buttonIndex == 2 then - raygui:set2Top( windowbox ) + Raygui.set2Top( windowbox ) end end - end - ) ) - local textinputbox = raygui:add( raygui.TextInputBox:new( + end, + -- Grab callback. + function( self ) Raygui.set2Top( self ) end + ) + local textinputbox = Raygui.TextInputBox:new( Rect:new( 1100, 300, 300, 128 ), "Title", "Message", @@ -199,40 +208,42 @@ function RL.init() if 0 < self.buttonIndex then print( "You pressed "..self:getItem( self.buttonIndex ) ) end - end - ) ) - local colorpicker = raygui:add( raygui.ColorPicker:new( + end, + -- Grab callback. + function( self ) Raygui.set2Top( self ) end + ) + local colorpicker = Raygui.ColorPicker:new( Rect:new( 1500, 32, 128, 128 ), "Color Picker", Color:new() - ) ) - local colorpanel = raygui:add( raygui.ColorPanel:new( + ) + local colorpanel = Raygui.ColorPanel:new( Rect:new( 1700, 32, 128, 128 ), "Color Panel", Color:new() - ) ) - local colorbaralpha = raygui:add( raygui.ColorBarAlpha:new( + ) + local colorbaralpha = Raygui.ColorBarAlpha:new( Rect:new( 1700, 180, 128, 20 ), "Color Panel", 1.0 - ) ) - local colorbarhue = raygui:add( raygui.ColorBarHue:new( + ) + local colorbarhue = Raygui.ColorBarHue:new( Rect:new( 1840, 32, 20, 128 ), "Color Panel", 1.0 - ) ) + ) end function RL.process( delta ) if RL.IsKeyPressed( RL.KEY_R ) then - raygui:set2Top( windowbox ) + Raygui.set2Top( windowbox ) end if RL.IsKeyPressed( RL.KEY_F ) then - raygui:set2Back( windowbox ) + Raygui.set2Back( windowbox ) end - raygui:process() + Raygui.process() end function RL.draw() @@ -250,5 +261,5 @@ function RL.draw() ) end - raygui:draw() + Raygui.draw() end diff --git a/examples/resources/lib/raygui.lua b/examples/resources/lib/raygui.lua index 694a311..1ebb3f0 100644 --- a/examples/resources/lib/raygui.lua +++ b/examples/resources/lib/raygui.lua @@ -47,31 +47,29 @@ end -- Raygui. -Raygui = {} -Raygui.__index = Raygui +Raygui = { + RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT = 24, -function Raygui:new() - local object = setmetatable( {}, Raygui ) + elements = {}, + focused = 0, + dragging = nil, + grabPos = Vec2:new(), +} - object.elements = {} - object.focused = 0 +function Raygui.process() + -- If dragging, don't process element masking. + if Raygui.dragging ~= nil then + Raygui.drag( Raygui.dragging ) - return object -end - -function Raygui:add( element ) - table.insert( self.elements, element ) - - return element -end + return + end -function Raygui:process() - for i = #self.elements, 1, -1 do - local element = self.elements[i] + for i = #Raygui.elements, 1, -1 do + local element = Raygui.elements[i] if element.visible and element.process ~= nil then if element:process() then - self.focused = i + Raygui.focused = i return end @@ -79,11 +77,40 @@ function Raygui:process() end end -function Raygui:draw() - RL.GuiLock() +function Raygui.drag( element ) + local mousePos = Vec2:new( RL.GetMousePosition() ) + local mouseOver = RL.CheckCollisionPointRec( mousePos, element.bounds ) + + if element.draggable and element ~= Raygui.dragging and RL.IsMouseButtonPressed( RL.MOUSE_BUTTON_LEFT ) + and mouseOver and mousePos.y - element.bounds.y <= Raygui.RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT then + Raygui.grabPos = mousePos - Vec2:new( element.bounds.x, element.bounds.y ) - for i, element in ipairs( self.elements ) do - if i == self.focused then + if element.grabCallback ~= nil then + element.grabCallback( element ) + end + Raygui.dragging = element + end + + if element == Raygui.dragging then + if not RL.IsMouseButtonDown( RL.MOUSE_BUTTON_LEFT ) then + Raygui.dragging = nil + end + + element:setPosition( mousePos - Raygui.grabPos ) + + if element.dragCallback ~= nil then + element.dragCallback( element ) + end + end + + return mouseOver +end + +function Raygui.draw() + RL.GuiLock() + + for i, element in ipairs( Raygui.elements ) do + if i == Raygui.focused then RL.GuiUnlock() end @@ -93,20 +120,20 @@ function Raygui:draw() end end -function Raygui:set2Top( element ) - for i, curElement in ipairs( self.elements ) do +function Raygui.set2Top( element ) + for i, curElement in ipairs( Raygui.elements ) do if element == curElement then - Util.tableMove( self.elements, i, 1, #self.elements ) + Util.tableMove( Raygui.elements, i, 1, #Raygui.elements ) return end end end -function Raygui:set2Back( element ) - for i, curElement in ipairs( self.elements ) do +function Raygui.set2Back( element ) + for i, curElement in ipairs( Raygui.elements ) do if element == curElement then - Util.tableMove( self.elements, i, 1, 1 ) + Util.tableMove( Raygui.elements, i, 1, 1 ) return end @@ -119,23 +146,43 @@ end -- WindowBox. +--- Window Box control, shows a window that can be closed +---@class WindowBox +---@field bounds table Rect +---@field text string +---@field callback function|nil +---@field grabCallback function|nil +---@field dragCallback function|nil +---@field visible boolean +---@field draggable boolean WindowBox = {} WindowBox.__index = WindowBox -function WindowBox:new( bounds, text, callback ) +---@param bounds table Rect +---@param text string +---@param callback function|nil +---@param grabCallback function|nil +---@param dragCallback function|nil +---@return table object +function WindowBox:new( bounds, text, callback, grabCallback, dragCallback ) local object = setmetatable( {}, WindowBox ) object.bounds = bounds:clone() object.text = text object.callback = callback + object.grabCallback = grabCallback + object.dragCallback = dragCallback object.visible = true + object.draggable = true + + table.insert( Raygui.elements, object ) return object end function WindowBox:process() - return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds ) + return Raygui.drag( self ) end function WindowBox:draw() @@ -151,9 +198,16 @@ end -- GroupBox. +--- Group Box control with text name +---@class GroupBox +---@field bounds table Rect +---@field text string +---@field visible boolean GroupBox = {} GroupBox.__index = GroupBox +---@param bounds table Rect +---@param text string function GroupBox:new( bounds, text ) local object = setmetatable( {}, GroupBox ) @@ -162,6 +216,8 @@ function GroupBox:new( bounds, text ) object.visible = true + table.insert( Raygui.elements, object ) + return object end @@ -180,6 +236,7 @@ end -- Line. +--- Line separator control, could contain text Line = {} Line.__index = Line @@ -191,6 +248,8 @@ function Line:new( bounds, text ) object.visible = true + table.insert( Raygui.elements, object ) + return object end @@ -209,22 +268,28 @@ end -- Panel. +--- Panel control, useful to group controls Panel = {} Panel.__index = Panel -function Panel:new( bounds, text ) +function Panel:new( bounds, text, grabCallback, dragCallback ) local object = setmetatable( {}, Panel ) object.bounds = bounds:clone() object.text = text object.visible = true + object.draggable = true + object.grabCallback = grabCallback + object.dragCallback = dragCallback + + table.insert( Raygui.elements, object ) return object end function Panel:process() - return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds ) + return Raygui.drag( self ) end function Panel:draw() @@ -238,10 +303,11 @@ end -- ScrollPanel. +--- Scroll Panel control ScrollPanel = {} ScrollPanel.__index = ScrollPanel -function ScrollPanel:new( bounds, text, content, scroll, callback ) +function ScrollPanel:new( bounds, text, content, scroll, callback, grabCallback, dragCallback ) local object = setmetatable( {}, ScrollPanel ) object.bounds = bounds:clone() @@ -250,14 +316,19 @@ function ScrollPanel:new( bounds, text, content, scroll, callback ) object.scroll = scroll:clone() object.view = Rect:new() object.callback = callback + object.grabCallback = grabCallback + object.dragCallback = dragCallback object.visible = true + object.draggable = true + + table.insert( Raygui.elements, object ) return object end function ScrollPanel:process() - return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds ) + return Raygui.drag( self ) end function ScrollPanel:draw() @@ -284,6 +355,7 @@ end -- Label. +--- Label control, shows text Label = {} Label.__index = Label @@ -295,6 +367,8 @@ function Label:new( bounds, text ) object.visible = true + table.insert( Raygui.elements, object ) + return object end @@ -313,6 +387,7 @@ end -- Button. +--- Button control Button = {} Button.__index = Button @@ -326,6 +401,8 @@ function Button:new( bounds, text, callback ) object.clicked = false object.visible = true + table.insert( Raygui.elements, object ) + return object end @@ -348,6 +425,7 @@ end -- LabelButton. +--- Label button control LabelButton = {} LabelButton.__index = LabelButton @@ -361,6 +439,8 @@ function LabelButton:new( bounds, text, callback ) object.clicked = false object.visible = true + table.insert( Raygui.elements, object ) + return object end @@ -383,6 +463,7 @@ end -- Toggle. +--- Toggle Button control Toggle = {} Toggle.__index = Toggle @@ -396,6 +477,8 @@ function Toggle:new( bounds, text, active, callback ) object.visible = true + table.insert( Raygui.elements, object ) + return object end @@ -420,6 +503,7 @@ end -- ToggleGroup. +--- Toggle Group control ToggleGroup = {} ToggleGroup.__index = ToggleGroup @@ -435,6 +519,8 @@ function ToggleGroup:new( bounds, text, active, callback ) object.focusBounds = {} object:updateFocusBounds() + table.insert( Raygui.elements, object ) + return object end @@ -520,6 +606,8 @@ function CheckBox:new( bounds, text, checked, callback ) object.focusBounds = bounds:clone() object:updateFocusBounds() + table.insert( Raygui.elements, object ) + return object end @@ -585,6 +673,7 @@ end -- ComboBox. +--- Combo Box control ComboBox = {} ComboBox.__index = ComboBox @@ -598,6 +687,8 @@ function ComboBox:new( bounds, text, active, callback ) object.visible = true + table.insert( Raygui.elements, object ) + return object end @@ -622,6 +713,7 @@ end -- DropdownBox. +--- Dropdown Box control DropdownBox = {} DropdownBox.__index = DropdownBox @@ -638,6 +730,8 @@ function DropdownBox:new( bounds, text, active, editMode, callback ) object.editModeBounds = bounds:clone() object:updateFocusBounds() + table.insert( Raygui.elements, object ) + return object end @@ -691,6 +785,7 @@ end -- Spinner. +--- Spinner control Spinner = {} Spinner.__index = Spinner @@ -707,6 +802,8 @@ function Spinner:new( bounds, text, value, minValue, maxValue, editMode, callbac object.visible = true + table.insert( Raygui.elements, object ) + return object end @@ -736,6 +833,7 @@ end -- ValueBox. +--- Value Box control ValueBox = {} ValueBox.__index = ValueBox @@ -752,6 +850,8 @@ function ValueBox:new( bounds, text, value, minValue, maxValue, editMode, callba object.visible = true + table.insert( Raygui.elements, object ) + return object end @@ -781,6 +881,7 @@ end -- TextBox. +--- Text Box control TextBox = {} TextBox.__index = TextBox @@ -796,6 +897,8 @@ function TextBox:new( bounds, text, textSize, editMode, callback ) object.scissorMode = false object.visible = true + table.insert( Raygui.elements, object ) + return object end @@ -832,6 +935,7 @@ end -- TextBoxMulti. +-- Text Box control with multiple lines TextBoxMulti = {} TextBoxMulti.__index = TextBoxMulti @@ -846,6 +950,8 @@ function TextBoxMulti:new( bounds, text, textSize, editMode, callback ) object.visible = true + table.insert( Raygui.elements, object ) + return object end @@ -874,6 +980,7 @@ end -- Slider. +--- Slider control Slider = {} Slider.__index = Slider @@ -890,6 +997,8 @@ function Slider:new( bounds, textLeft, textRight, value, minValue, maxValue, cal object.visible = true + table.insert( Raygui.elements, object ) + return object end @@ -914,6 +1023,7 @@ end -- SliderBar. +--- Slider Bar control SliderBar = {} SliderBar.__index = SliderBar @@ -930,6 +1040,8 @@ function SliderBar:new( bounds, textLeft, textRight, value, minValue, maxValue, object.visible = true + table.insert( Raygui.elements, object ) + return object end @@ -954,6 +1066,7 @@ end -- ProgressBar. +--- Progress Bar control, shows current progress value ProgressBar = {} ProgressBar.__index = ProgressBar @@ -970,6 +1083,8 @@ function ProgressBar:new( bounds, textLeft, textRight, value, minValue, maxValue object.visible = true + table.insert( Raygui.elements, object ) + return object end @@ -994,6 +1109,7 @@ end -- StatusBar. +--- Status Bar control, shows info text StatusBar = {} StatusBar.__index = StatusBar @@ -1005,6 +1121,8 @@ function StatusBar:new( bounds, text ) object.visible = true + table.insert( Raygui.elements, object ) + return object end @@ -1023,6 +1141,7 @@ end -- DummyRec. +--- Dummy control for placeholders DummyRec = {} DummyRec.__index = DummyRec @@ -1034,6 +1153,8 @@ function DummyRec:new( bounds, text ) object.visible = true + table.insert( Raygui.elements, object ) + return object end @@ -1052,6 +1173,7 @@ end -- Grid. +--- Grid control Grid = {} Grid.__index = Grid @@ -1067,6 +1189,8 @@ function Grid:new( bounds, text, spacing, subdivs, callback ) object.cell = Vec2:new() object.visible = true + table.insert( Raygui.elements, object ) + return object end @@ -1095,6 +1219,7 @@ end -- ListView. +--- List View control ListView = {} ListView.__index = ListView @@ -1108,6 +1233,8 @@ function ListView:new( bounds, text, scrollIndex, active, callback ) object.callback = callback object.visible = true + table.insert( Raygui.elements, object ) + return object end @@ -1136,6 +1263,7 @@ end -- ListViewEx. +--- List View with extended parameters ListViewEx = {} ListViewEx.__index = ListViewEx @@ -1150,6 +1278,8 @@ function ListViewEx:new( bounds, text, focus, scrollIndex, active, callback ) object.callback = callback object.visible = true + table.insert( Raygui.elements, object ) + return object end @@ -1178,10 +1308,11 @@ end -- MessageBox. +--- Message Box control, displays a message MessageBox = {} MessageBox.__index = MessageBox -function MessageBox:new( bounds, title, message, buttons, callback ) +function MessageBox:new( bounds, title, message, buttons, callback, grabCallback, dragCallback ) local object = setmetatable( {}, MessageBox ) object.bounds = bounds:clone() @@ -1189,9 +1320,14 @@ function MessageBox:new( bounds, title, message, buttons, callback ) object.message = message object.buttons = buttons object.callback = callback + object.grabCallback = grabCallback + object.dragCallback = dragCallback object.buttonIndex = -1 object.visible = true + object.draggable = true + + table.insert( Raygui.elements, object ) return object end @@ -1201,7 +1337,7 @@ function MessageBox:getItem( id ) end function MessageBox:process() - return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds ) + return Raygui.drag( self ) end function MessageBox:draw() @@ -1219,10 +1355,11 @@ end -- TextInputBox. +--- Text Input Box control, ask for text, supports secret TextInputBox = {} TextInputBox.__index = TextInputBox -function TextInputBox:new( bounds, title, message, buttons, text, textMaxSize, secretViewActive, callback ) +function TextInputBox:new( bounds, title, message, buttons, text, textMaxSize, secretViewActive, callback, grabCallback, dragCallback ) local object = setmetatable( {}, TextInputBox ) object.bounds = bounds:clone() @@ -1233,9 +1370,14 @@ function TextInputBox:new( bounds, title, message, buttons, text, textMaxSize, s object.textMaxSize = textMaxSize object.secretViewActive = secretViewActive object.callback = callback + object.grabCallback = grabCallback + object.dragCallback = dragCallback object.buttonIndex = -1 object.visible = true + object.draggable = true + + table.insert( Raygui.elements, object ) return object end @@ -1245,7 +1387,7 @@ function TextInputBox:getItem( id ) end function TextInputBox:process() - return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds ) + return Raygui.drag( self ) end function TextInputBox:draw() @@ -1263,6 +1405,7 @@ end -- ColorPicker. +--- Color Picker control ( multiple color controls ) ColorPicker = {} ColorPicker.__index = ColorPicker @@ -1276,6 +1419,8 @@ function ColorPicker:new( bounds, text, color, callback ) object.visible = true + table.insert( Raygui.elements, object ) + return object end @@ -1301,6 +1446,7 @@ end -- ColorPanel. +--- Color Panel control ColorPanel = {} ColorPanel.__index = ColorPanel @@ -1314,6 +1460,8 @@ function ColorPanel:new( bounds, text, color, callback ) object.visible = true + table.insert( Raygui.elements, object ) + return object end @@ -1339,6 +1487,7 @@ end -- ColorBarAlpha. +--- Color Bar Alpha control ColorBarAlpha = {} ColorBarAlpha.__index = ColorBarAlpha @@ -1352,6 +1501,8 @@ function ColorBarAlpha:new( bounds, text, alpha, callback ) object.visible = true + table.insert( Raygui.elements, object ) + return object end @@ -1375,6 +1526,7 @@ end -- ColorBarHue. +--- Color Bar Hue control ColorBarHue = {} ColorBarHue.__index = ColorBarHue @@ -1388,6 +1540,8 @@ function ColorBarHue:new( bounds, text, value, callback ) object.visible = true + table.insert( Raygui.elements, object ) + return object end -- cgit v1.2.3