Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --
- --GUI API by neonerZ v1.0
- --http://youtube.com/neonerz
- --
- -- use os.loadAPI("guiAPI") (or whatever you named it) to include this
- -- API in your script. To call a function, you'd use guiAPI.function(vairables)
- -- If you named this script somthing other than guiAPI, adjust the above command accordingly
- -- example usage: register a button
- -- guiAPI.setTable("button1", "Button Name", 3, 4, 10, 3, 4000, 4001, colors.blue, colors.white)
- -- This script must be in the same directory as the script calling it
- -- you can also add this to your turtles rom/api folder to use it like a standard computercraft API
- local button={}
- --Function to create button table
- function setTable(name, text, xmin, ymin, width, height, onFreq, offFreq, bcolor, tcolor)
- button[name] = {}
- button[name]["text"] = text
- button[name]["active"] = false
- button[name]["xmin"] = xmin
- button[name]["ymin"] = ymin
- button[name]["width"] = width
- button[name]["height"] = height
- button[name]["onFreq"] = onFreq
- button[name]["offFreq"] = offFreq
- button[name]["bcolor"] = bcolor
- button[name]["tcolor"] = tcolor
- end
- --Toggle button on and off
- function toggleButton(name, state)
- if state=="on" then
- button[name]["active"] = true
- else
- button[name]["active"] = false
- end
- end
- --Draw button on screen
- function drawButton(x, y, width, height, bcolor, tcolor, text)
- m.setBackgroundColor(bcolor)
- --Draw the background
- for i=1,height do
- m.setCursorPos(x,y+i-1)
- m.write(string.rep(" ", width))
- end
- -- m.setBackgroundColor(colors.black)
- --Write the text
- m.setTextColor(tcolor)
- local textX = x + math.floor(width/2 - string.len(text)/2)
- local textY = y + math.floor(height/2)
- m.setCursorPos(textX, textY)
- m.write(text)
- end
- --Draw a box on the monitor
- function drawBox(xpos, ypos, height, width, title, bcolor, tcolor, tbcolor)
- -- if xpos == 1 then xpos=2 end
- -- if ypos == 1 then ypos=2 end
- if ypos > height then height = height+ypos end
- if xpos > width then rwidth = xpos+width -2 else rwidth = width end
- for h = ypos,height+1 do
- for i = xpos,rwidth+1 do
- m.setCursorPos(i,h)
- m.setBackgroundColor(bcolor)
- m.write(" ")
- end
- end
- titleCount = #title
- titlePos = math.floor((width-titleCount)/2)+xpos
- m.setBackgroundColor(tbcolor)
- m.setTextColor(tcolor)
- m.setCursorPos(titlePos,ypos)
- m.write(title)
- m.setBackgroundColor(defaultMonColor)
- h=nil
- i=nil
- end
- --Draw text on the monitor
- function drawText(xpos,ypos,tcolor,bcolor,text)
- m.setCursorPos(xpos,ypos)
- m.setTextColor(tcolor)
- m.setBackgroundColor(bcolor)
- m.write(text)
- m.setBackgroundColor(defaultMonColor)
- end
- --Check if a button within the table has been clicked
- --(returns button name if matches, or false if not)
- function checkxy(x, y)
- returnCheckxy=false
- for name, data in pairs(button) do
- if data["height"] == 1 then
- ymax = data["ymin"]
- else
- ymax = data["height"] + data["ymin"]
- end
- if data["width"] == 1 then
- xmax = data["xmin"]
- else
- xmax = data["width"] + data["xmin"]
- end
- if y>=data["ymin"] and y <= ymax then
- if x>=data["xmin"] and x<= xmax then
- returnCheckxy = {name = name,
- text = data["text"],
- onFreq = data["onFreq"],
- offFreq = data["offFreq"],
- bcolor = data["bcolor"],
- tcolor = data["tcolor"],
- active = data["active"]}
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement