Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local gpu = component.gpu
- local event = require("event")
- local term = require("term")
- local screenWidth, screenHeight = gpu.getResolution()
- local gui = {}
- local white = 0xFFFFFF
- local black = 0x000000
- local red = 0xFF0000
- local green = 0x00FF00
- local blue = 0x0000FF
- function gui.NewProgressbar(layout, bgcolour, fgcolour, x, y, width, height, value, maxvalue, direction)
- local tmpTable = {}
- tmpTable["Type"] = "Progressbar"
- tmpTable["BGColour"] = bgcolour
- tmpTable["FGColour"] = fgcolour
- tmpTable["X"] = x
- tmpTable["Y"] = y
- tmpTable["Width"] = width
- tmpTable["Height"] = height
- tmpTable["Value"] = value
- tmpTable["MaxValue"] = maxvalue
- tmpTable["Direction"] = direction or 0
- table.insert(layout, tmpTable)
- return #layout
- end
- function gui.NewLabel(layout, bgcolour, fgcolour, x, y, txt, length)
- local tmpTable = {}
- tmpTable["Type"] = "Label"
- tmpTable["BGColour"] = bgcolour
- tmpTable["FGColour"] = fgcolour
- tmpTable["X"] = x
- tmpTable["Y"] = y
- tmpTable["Text"] = txt
- tmpTable["Length"] = length
- table.insert(layout, tmpTable)
- return #layout
- end
- function gui.SetValue(layout, widgetID, newvalue)
- layout[widgetID].Value = newvalue
- end
- function gui.SetText(layout, widgetID, newtxt)
- layout[widgetID].Text = newtxt
- end
- function gui.NewUI(x, y, w, h, bg, fg)
- local tmpTable = {}
- tmpTable["Type"] = "UI"
- tmpTable["X"] = x
- tmpTable["Y"] = y
- tmpTable["Width"] = w
- tmpTable["Height"] = h
- tmpTable["Background"] = bg
- tmpTable["Foreground"] = fg
- return tmpTable
- end
- function gui.ClearScreen()
- gpu.setBackground(black)
- gpu.setForeground(white)
- gpu.fill(1, 1, screenWidth, screenHeight, " ")
- term.clear()
- end
- local function _displayProgressbar(progressbar)
- gpu.setBackground(progressbar.BGColour)
- gpu.setForeground(progressbar.FGColour)
- gpu.fill(progressbar.X, progressbar.Y, progressbar.Width, progressbar.Height, " ")
- term.setCursor(1, 1)
- if progressbar.Direction == 0 then
- local percent = math.floor(progressbar.Value / progressbar.MaxValue * progressbar.Height)
- gpu.setBackground(progressbar.FGColour)
- gpu.setForeground(progressbar.BGColour)
- gpu.fill(progressbar.X, progressbar.Y+progressbar.Height-percent, progressbar.Width, percent, " ")
- end
- end
- local function _displayLabel(label)
- gpu.setBackground(label.BGColour)
- gpu.setForeground(label.FGColour)
- gpu.fill(label.X, label.Y, label.Length, 1, " ")
- gpu.set(label.X, label.Y, label.Text)
- end
- function gui.RunUI(layout)
- if layout.Type == "UI" then
- for k, v in ipairs(layout) do
- if v.Type == "Progressbar" then
- _displayProgressbar(v)
- elseif v.Type == "Label" then
- _displayLabel(v)
- end
- end
- end
- end
- return gui
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement