Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os = require("os")
- term = require("term")
- component = require("component")
- gpu = component.gpu
- function throwError(errorMessage)
- gpu.setResolution(gpu.maxResolution())
- gpu.setForeground(0xff0000)
- gpu.setBackground(0x000000)
- term.clear()
- print("The program ran into a serious error during execution.")
- print(errorMessage)
- gpu.setForeground(0xffffff)
- os.exit()
- end
- function addRect(x1,y1,x2,y2,color)
- temp = gpu.getBackground()
- gpu.setBackground(color)
- gpu.fill(x1,y1,x2-x1+1,y2-y1+1," ")
- gpu.setBackground(temp)
- end
- function addProgressBar(x1,y1,x2,y2,sideWidth,sideHeight,borderColor,filledBarColor,emptyBarColor,textColor,headerText,filledPercentage,isSideways,isInverted)
- isSideways = isSideways or false
- isInverted = isInverted or false
- if type(x1)~="number" then throwError("addProgressBar() argument 1 (x1) type int expected, "..type(x1).." found") end
- if type(x2)~="number" then throwError("addProgressBar() argument 3 (x2) type int expected, "..type(x2).." found") end
- if type(y1)~="number" then throwError("addProgressBar() argument 2 (y1) type int expected, "..type(y1).." found") end
- if type(y2)~="number" then throwError("addProgressBar() argument 4 (y2) type int expected, "..type(y2).." found") end
- if type(sideWidth)~="number" then throwError("addProgressBar() argument 5 (sideWidth) type int expected, "..type(sideWidth).." found") end
- if type(sideHeight)~="number" then throwError("addProgressBar() argument 6 (sideHeight) type int expected, "..type(sideHeight).." found") end
- if type(filledPercentage)~="number" then throwError("addProgressBar() argument 11 (filledPercentage) type float expected, "..type(filledPercentage).." found") end
- if isSideways == false then
- addRect(x1,y1,x2,y2,borderColor)
- addRect(x1+sideWidth,y1+sideHeight,x2-sideWidth,y2-sideHeight,emptyBarColor)
- barSize = (y2-y1-2*sideHeight)
- pixelsFilled = math.floor(filledPercentage*barSize+0.5)
- if isInverted == false then
- addRect(x1+sideWidth,y2-sideHeight-pixelsFilled,x2-sideWidth,y2-sideHeight,filledBarColor)
- elseif isInverted == true then
- addRect(x1+sideWidth,y1+sideHeight,x2-sideWidth,y1+sideHeight+pixelsFilled,filledBarColor)
- else
- throwError("addProgressBar() argument 13 (isInverted) type boolean expected, "..type(isInverted).." found")
- end
- elseif isSideways == true then
- addRect(x1,y1,x2,y2,borderColor)
- addRect(x1+sideWidth,y1+sideHeight,x2-sideWidth,y2-sideHeight,emptyBarColor)
- barSize = (x2-x1-2*sideWidth)
- pixelsFilled = math.floor(filledPercentage*barSize+0.5)
- if isInverted == false then
- addRect(x1+sideWidth,y1+sideHeight,x1+sideWidth+pixelsFilled,y2-sideHeight,filledBarColor)
- elseif isInverted == true then
- addRect(x2-sideWidth-pixelsFilled,y1+sideHeight,x2-sideWidth,y2-sideHeight,filledBarColor)
- else
- throwError("addProgressBar() argument 13 (isInverted) type boolean expected, "..type(isInverted).." found")
- end
- else
- throwError("addProgressBar() argument 12 (isSideways) type boolean expected, "..type(isSideways).." found")
- end
- if sideHeight>0 then
- col = {f = gpu.getForeground(),b = gpu.getBackground()}
- centerX = math.ceil((x1+x2)/2)
- centerY = math.floor(y1+sideHeight/2)
- gpu.setForeground(textColor)
- gpu.setBackground(borderColor)
- gpu.set(centerX-(string.len(tostring(headerText))/2),centerY,tostring(headerText))
- gpu.setForeground(col.f)
- gpu.setBackground(col.b)
- centerX = nil
- centerY = nil
- col = nil
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment