Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- second attempt at a net like frame work
- by Big SHiny Toys
- ]]--
- local net = {}
- function net.newWindow()
- return {}
- end
- function net.run(tWindo)
- local function inBouwndry(clickX,clickY,boxX,boxY,width,hight)
- return ( clickX >= boxX and clickX < boxX + width and clickY >= boxY and clickY < boxY + hight )
- end
- local function redraw()
- for k,v in pairs(tWindo) do
- v("redraw")
- end
- end
- redraw()
- while true do
- event = {os.pullEvent()}
- if event[1] == "redraw" then
- redraw()
- elseif event[1] == "mouse_click" then
- if event[2] == 1 then -- left click
- for k,v in pairs(tWindo) do
- if inBouwndry(event[3],event[4],v("box")) then
- v("call")()
- end
- end
- end
- end
- end
- end
- local button_meta = {
- __call = function(tButton,ins)
- if ins == "redraw" then
- term.setBackgroundColor(colors[tButton.bgColor] or tButton.bgColor)
- term.setTextColor(colors[tButton.textColor] or tButton.textColor)
- term.setCursorPos(tButton.posX,tButton.posY)
- term.write(tButton.sText)
- elseif ins == "box" then
- return tButton.posX,tButton.posY,#tButton.sText,1
- elseif ins == "call" then
- return tButton.buttonFunction
- end
- end
- }
- function net.button(window,label,func,posX,posY,tCol,bCol)
- local tempButton = {
- posY = posY,
- posX = posX,
- buttonFunction = func,
- sText = label,
- textColor = tCol,
- bgColor = bCol
- }
- setmetatable(tempButton,button_meta)
- table.insert(window,tempButton)
- end
- local function testA()
- print("test A")
- error()
- end
- local function testB()
- print("test B")
- error()
- end
- local win = net.newWindow()
- net.button(win,"[button1]",testA,2,2,"lime","green")
- net.button(win,"[button2]",testB,2,4,"lime","green")
- net.run(win)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement