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 function inBouwndry(clickX,clickY,boxX,boxY,width,hight)
- return ( clickX >= boxX and clickX < boxX + width and clickY >= boxY and clickY < boxY + hight )
- end
- local win_meta = {
- __call = function(tWin,ins)
- if ins == "kill" then
- tWin.run = false
- elseif ins == "redraw" then
- tWin.drawFlag = true
- end
- end
- }
- function newWindow()
- local tempWin = {
- components = {},
- drawFlag = true,
- run = true
- }
- setmetatable(tempWin,win_meta)
- return tempWin
- end
- function run(tWindo)
- local function redraw()
- for k,v in pairs(tWindo.components) do
- v("redraw")
- end
- end
- redraw()
- while tWindo.run 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.components) do
- if inBouwndry(event[3],event[4],v("box")) then
- v("call",event[3],event[4])
- end
- end
- end
- elseif event[1] == "mouse_scroll" then
- for k,v in pairs(tWindo.components) do
- if inBouwndry(event[3],event[4],v("box")) then
- v("scroll",event[2])
- end
- end
- end
- if tWindo.drawFlag then
- redraw()
- tWindo.drawFlag = false
- end
- end
- end
- local button_meta = {
- __call = function(tButton,ins,value)
- 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()
- elseif ins == "set" then
- tButton.sText = value
- tButton.drawFlag()
- end
- end
- }
- function button(window,label,func,posX,posY,tCol,bCol)
- local tempButton = {
- posY = posY,
- posX = posX,
- buttonFunction = func,
- sText = label,
- textColor = tCol,
- bgColor = bCol,
- drawFlag = function() window.drawFlag = true end
- }
- setmetatable(tempButton,button_meta)
- table.insert(window.components,tempButton)
- return tempButton
- end
- local list_meta = {
- __call = function(tButton,ins,clickX,clickY)
- if ins == "redraw" then
- term.setBackgroundColor(colors[tButton.bgColor] or tButton.bgColor)
- term.setTextColor(colors[tButton.textColor] or tButton.textColor)
- for i = 1,tButton.hight do
- term.setCursorPos(tButton.posX,tButton.posY+i-1)
- term.write(string.sub((tButton.tList[i + tButton.offset] or "")..string.rep(" ",tButton.width),1,tButton.width))
- end
- elseif ins == "box" then
- return tButton.posX,tButton.posY,tButton.width,tButton.hight
- elseif ins == "call" then
- local item = tButton.tList[(clickY - tButton.posY) + tButton.offset +1]
- if item then
- return tButton.buttonFunction(item)
- end
- elseif ins == "clear" then
- tButton.tList = {}
- tButton.offset = 0
- tButton.drawFlag()
- elseif ins == "add" then
- if clickX then
- table.insert(tButton.tList,clickX)
- end
- tButton.drawFlag()
- elseif ins == "scroll" then
- tButton.offset = tButton.offset + (clickX or 0)
- tButton.drawFlag()
- elseif ins == "set" then
- tButton.tList = clickX
- tButton.offset = 0
- tButton.drawFlag()
- end
- end
- }
- function listBox(window,list,func,posX,posY,width,hight,tCol,bCol)
- local tempList = {
- posY = posY,
- posX = posX,
- buttonFunction = func,
- sText = label,
- textColor = tCol,
- bgColor = bCol,
- width = width,
- hight = hight,
- offset = 0,
- tList = list,
- drawFlag = function() window.drawFlag = true end
- }
- setmetatable(tempList,list_meta)
- table.insert(window.components,tempList)
- return tempList
- end
- -- end api
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement