Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Gooey is a LimeFyre API.--
- local width, height = term.getSize( )
- gooey = { }
- UI = { }
- UIButton = { }
- UICheckbox = { }
- UIRadio = { }
- UIText = { }
- ActiveUI = { }
- local protos = { }
- protos.frame = {
- x = 1,
- y = 1,
- w = width,
- h = height,
- c = colours.white,
- children = { },
- isVisible = true,
- }
- protos.button = {
- x = 1,
- y = 1,
- w = 10,
- h = 3,
- text = "A Button",
- textColour = colours.white,
- bgColour = colours.grey,
- onClick = function( ) end,
- isVisible = true,
- }
- --UI FRAMES--
- function gooey.UI:new( x, y, w, h, c )
- local a = { x = x, y = y, w = w, h = h, c = c }
- local o = setmetatable( a, protos.frame )
- setmetatable( o, self )
- self.__index = self
- table.insert( ActiveUI, self )
- return o
- end
- function gooey.UI:move( x, y )
- self.x, self.y = x, y
- end
- function gooey.UI:setColour( colour )
- self.colour = colour
- end
- function gooey.UI:toggle( )
- self.isVisible = not self.isVisible
- end
- function gooey.UI:show( )
- self.isVisible = true
- end
- function gooey.UI:hide( )
- self.isVisible = false
- end
- function gooey.UIButton:new( frame, x, y, text, textColour, bgColour )
- if frame == nil then
- error( "expected frame object, got nil" )
- else
- local w = #text + 2
- local h = 3
- local a = { frame = frame, x = x, y = y, w = w, h = h, text = text, bgColour = bgColour, textColour = textColour }
- local o = setmetatable( a, protos.button )
- setmetatable( o, self )
- self.__index = self
- table.insert( frame.children, self )
- return o
- end
- end
- function gooey.UIButton:checkClick( x, y )
- if x >= self.x and x <= self.w and y >= self.y and y <= self.h then
- self:onClick( )
- end
- end
- function gooey.UIButton:draw( )
- if self.isVisible then
- paintutils.drawFilledBox( self.x, self.y, self.w, self.h, self.bgColour )
- term.setCursorPos( self.x + 1, self.y + 1 )
- print( self.text )
- end
- end
- function gooey.UIButton:setTextColour( colour )
- self.textColour = colour
- end
- function gooey.UIButton:setBackgroundColour( colour )
- self.bgColour = colour
- end
- function gooey.UIButton:toggle( )
- self.isVisible = not self.isVisible
- end
- function gooey.UIButton:show( )
- self.isVisible = true
- end
- function gooey.UIButton:hide( )
- self.isVisible = false
- end
- function gooey.checkClick( x, y )
- for k, v in pairs( ActiveUI ) do
- for a, b in pairs( v.children ) do
- if b.isVisible and b.checkClick ~= nil then
- b:checkClick( x, y )
- end
- end
- end
- end
- function gooey.draw( )
- for k, v in pairs( ActiveUI ) do
- if v.isVisible then
- paintutils.drawFilledBox( v.x, v.y, v.w, v.h, v.colour )
- for a, b in pairs( v.children ) do
- b:draw( )
- end
- end
- end
- end
- return gooey
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement