Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Button API with pixels instead of squares
- --because my version of computercraft doesn't have them
- --table with all the buttons
- buttons={}
- --makes a table with all the button information
- --and insert it into main buttons table
- function makeNewButton(name,text,IX,IY,FX,FY)
- --(Initial x,y and final x,y as button coordinates)
- local z={IX=IX,IY=IY,FX=FX,FY=FY,text=text,state=false}
- buttons[name]=z
- end
- --actually draws the button
- function renderButton(button,color,monitor_name)
- --sets color (i'm going to add the other colors lateer)
- if color=="white" then
- color=1
- elseif color=="green" then
- color=32
- elseif color=="gray" then
- color=128
- elseif color=="blue" then
- color=2048
- elseif color=="red" then
- color=16384
- end
- --checks if there any monitors are called
- if monitor_name~=nil then
- term.redirect(monitor_name)
- end
- --draws button based on its coordinates
- local b = buttons[button]
- for x=b["IX"],b["FX"] do
- for y=b["IY"],b["FY"] do
- paintutils.drawPixel(x,y,color)
- end
- end
- --draws the text in the middle of the button with black to add contrast
- term.setCursorPos(((b["FX"]+b["IX"])/2)-(#b["text"]/2),(b["FY"]+b["IY"])/2)
- term.setTextColor(colors.black)
- term.write(b["text"])
- --restore the cursor position and set cursor in the computer again
- term.setCursorPos(1,1)
- term.restore()
- end
- --checks if the button is colliding with set coordinates
- function isButtonColliding(button,target_x,target_y)
- local b = buttons[button]
- --collision states x and y
- colx = (target_x>=b["IX"] and target_x<=b["FX"])
- coly = (target_y>=b["IY"] and target_y<=b["FY"])
- return (colx and coly)
- end
Add Comment
Please, Sign In to add comment