Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local MONITOR = nil
- function setMonitor(mon)
- MONITOR = mon
- end
- function getMonitor()
- return MONITOR
- end
- function string.jsub(str, startIndex, endIndex)
- if (endIndex == nil) then
- endIndex = string.len(str) + 1
- end
- return string.sub(str, startIndex, endIndex - 1)
- end
- function drawText(x, y, text, foreground, background)
- MONITOR.setCursorPos(x, y)
- if (foreground ~= nil) then
- MONITOR.setTextColor(foreground)
- end
- if (background ~= nil) then
- MONITOR.setBackgroundColor(background)
- end
- MONITOR.write(text)
- end
- function drawBox(x, y, w, h, background, character)
- if (background ~= nil) then
- MONITOR.setBackgroundColor(background)
- MONITOR.setTextColor(background)
- end
- if (character == nil) then
- character = " "
- end
- local y2 = y + h - 1
- for i = y, y2 do
- MONITOR.setCursorPos(x, i)
- MONITOR.write(string.rep(character, w))
- end
- end
- function drawRect2d(x1, y1, x2, y2, background, character)
- if (background ~= nil) then
- MONITOR.setBackgroundColor(background)
- MONITOR.setTextColor(background)
- end
- if (character == nil) then
- character = " "
- end
- local w = x2 - x1 + 1
- for y = y1, y2 do
- MONITOR.setCursorPos(x1, y)
- MONITOR.write(string.rep(character, w))
- end
- end
- -- Draws a vertical line at the given x and y coords, with the given height, in the given colour
- function drawLineV(x, y, h, background, character)
- if (background ~= nil) then
- MONITOR.setBackgroundColor(background)
- MONITOR.setTextColor(background)
- end
- if (character == nil) then
- character = " "
- end
- for i = y, h do
- MONITOR.setCursorPos(x, i)
- MONITOR.write(character)
- end
- end
- function drawLineH(x, y, w, background, character)
- if (character == nil) then
- character = " "
- end
- drawText(x, y, string.rep(character, w), background, background)
- end
- function drawProgressBar(x, y, w, h, min, max, val, foreground, background)
- drawBox(x, y, w, h, background)
- drawBox(x, y, math.floor((val / (max - min)) * w), h, foreground)
- end
- function clearMonitor()
- MONITOR.setBackgroundColor(colours.black)
- MONITOR.setTextColor(colours.white)
- MONITOR.clear()
- end
- function drawButton(btn, text, textColour, background)
- local x = btn.x1
- local y = btn.y1
- drawRect2d(x, y, btn.x2, btn.y2, background)
- local len = string.len(text)
- if (len < 1) then
- return
- end
- local w = btn.x2 - btn.x1 + 1
- local h = btn.y2 - btn.y1 + 1
- local cX = math.floor(w / 2) - math.floor(len / 2)
- local cY = math.ceil(h / 2)
- drawText(cX, cY, text, textColour, background)
- end
Add Comment
Please, Sign In to add comment