Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- pastebin get tpj7K41D scrollBars
- local component = require("component")
- local gpu = component.gpu
- local event = require("event")
- local unicode = require("unicode")
- local term = require("term")
- local shift = 1
- fPix = unicode.char(9608)
- uPix = unicode.char(9600)
- dPix = unicode.char(9604)
- progressBarsTitles = {[5]="124", [10]="New title", [15]="New Title again", [20]="20 %", [25]="One more Title", [30]="30-percents title", [35]="VeryLongString", [40]="'Path Of File On Computer'", [45]="And it is fourty-five percents", [50]="Half of Line", [55]="55 percents", [60]="Going a way", [65]="Faster and faster", [70]="Almost done", [75]="3/4", [80]="20 percents more", [85]="Just idle", [90]="Keep going", [95]="It's posible", [100]="Job done"}
- progressBars = {progressBar = {x=8, y=8, length=32, title="Тестовый прогрессбар", width=2, barSize = 4, active = true, showPercents = true, fill = false, percents = 0, cFore = 0x00FF00, cForePrepare = 0x009900, cForeProgress = 0x0000FF, cForeTitle = 0xFFFFFF, cBackTitle = 0x000000, cForePercents = 0xFFFFFF},
- progressBar1 = {x=8, y=16, length=32, title="Test progressbar", width=1, active = true, showPercents = false, fill = true, percents = 0, cFore = 0x00FF00, cForePrepare = 0x009900, cForeProgress = 0x0000FF, cForeTitle = 0xFFFFFF, cBackTitle = 0x000000, cForePercents = 0xFFFFFF},
- progressBar2 = {x=56, y=8, length=32, title="Новый прогрессбар", width=4, active = true, showPercents = true, fill = true, percents = 0, cFore = 0x00FF00, cForePrepare = 0x009900, cForeProgress = 0x0000FF, cForeTitle = 0xFFFFFF, cBackTitle = 0x000000, cForePercents = 0xFFFFFF}}
- gpu.setForeground(progressBars.progressBar.cFore)
- gpu.fill(4, 4, 88, 16, fPix)
- function drawProgressBar(tbl1)
- if tbl1.active then
- if not tbl1.fill then
- tbl1.position = tbl1.x - tbl1.barSize
- end
- gpu.setForeground(tbl1.cForePrepare)
- if tbl1.width%2 == 1 then
- gpu.fill(tbl1.x, tbl1.y, tbl1.length, tbl1.width, fPix)
- elseif tbl1.width%2 == 0 then
- gpu.setBackground(tbl1.cFore)
- gpu.fill(tbl1.x, tbl1.y, tbl1.length, 1, dPix)
- gpu.fill(tbl1.x, tbl1.y + 1, tbl1.length, tbl1.width - 1, fPix)
- gpu.fill(tbl1.x, tbl1.y + tbl1.width, tbl1.length, 1, uPix)
- end
- if tbl1.showPercents then
- gpu.setForeground(tbl1.cForePercents)
- if tbl1.percents <= 9 then
- percents = tostring(tbl1.percents) .. "%"
- for i = tbl1.x + tbl1.length/2 - 1, tbl1.x + tbl1.length/2 do
- local _, color = gpu.get(i, tbl1.y)
- gpu.setBackground(color)
- gpu.set(i, tbl1.y + math.floor(tbl1.width/2), string.sub(percents, i - tbl1.x - (tbl1.length/2 - 2)))
- end
- elseif tbl1.percents > 9 and tbl1.percents < 100 then
- percents = tostring(tbl1.percents) .. "%"
- for i = tbl1.x + tbl1.length/2 - 1, tbl1.x + tbl1.length/2 + 1 do
- local _, color = gpu.get(i, tbl1.y)
- gpu.setBackground(color)
- gpu.set(i, tbl1.y + math.floor(tbl1.width/2), string.sub(percents, i - tbl1.x - (tbl1.length/2 - 2)))
- end
- else
- percents = tostring(tbl1.percents) .. "%"
- for i = tbl1.x + tbl1.length/2 - 2, tbl1.x + tbl1.length/2 + 1 do
- local _, color = gpu.get(i, tbl1.y)
- gpu.setBackground(color)
- gpu.set(i, tbl1.y + math.floor(tbl1.width/2), string.sub(percents, i - tbl1.x - (tbl1.width/2 - 3)))
- end
- end
- end
- if unicode.len(tbl1.title) > tbl1.length - 4 then
- title = unicode.wtrunc(tbl1.title, (tbl1.length - 3) - 2) .. ".."
- else
- title = tbl1.title
- end
- gpu.setForeground(tbl1.cForeTitle)
- gpu.setBackground(tbl1.cBackTitle)
- gpu.set(tbl1.x + 2, tbl1.y - 1, title)
- end
- oldTitle = tbl1.title
- end
- function drawProgressBars()
- for k,v in pairs(progressBars) do
- drawProgressBar(v)
- end
- end
- function processingProgressBar(tbl)
- if tbl.percents < 100 then
- tbl.percents = tbl.percents + 1
- percents = tostring(tbl.percents) .. "%"
- if tbl.fill == false then
- tbl.position = tbl.position + shift
- end
- end
- if not tbl.fill then
- if tbl.position + tbl.barSize > tbl.x and tbl.position + tbl.barSize <= tbl.x + tbl.length then
- if tbl.position + tbl.barSize - tbl.x < tbl.barSize then
- barSize = tbl.position + tbl.barSize - tbl.x
- barPosition = tbl.x
- else
- barSize = tbl.barSize
- barPosition = tbl.position
- end
- elseif tbl.position + tbl.barSize > tbl.x + tbl.length and tbl.position + tbl.barSize < tbl.x + tbl.length + tbl.barSize then
- barSize = tbl.x + tbl.length - tbl.position
- barPosition = tbl.position
- elseif tbl.position >= tbl.x + tbl.length then
- tbl.position = tbl.x - tbl.barSize
- barSize = 0
- barPosition = tbl.position
- elseif tbl.position + tbl.barSize <= tbl.x then
- barSize = 0
- barPosition = tbl.position
- end
- if tbl.width%2 == 0 then
- gpu.setForeground(tbl.cForePrepare)
- gpu.setBackground(tbl.cFore)
- gpu.fill(tbl.x, tbl.y, tbl.length, 1, dPix)
- gpu.fill(tbl.x, tbl.y + 1, tbl.length, tbl.width - 1, fPix)
- gpu.fill(tbl.x, tbl.y + tbl.width, tbl.length, 1, uPix)
- gpu.setForeground(tbl.cForeProgress)
- gpu.fill(barPosition, tbl.y, barSize, 1, dPix)
- gpu.fill(barPosition, tbl.y + 1, barSize, tbl.width - 1, fPix)
- gpu.fill(barPosition, tbl.y + tbl.width, barSize, 1, uPix)
- elseif tbl.width%2 == 1 then
- gpu.setForeground(tbl.cForePrepare)
- gpu.fill(tbl.x, tbl.y, tbl.length, tbl.width, fPix)
- gpu.setForeground(tbl.cForeProgress)
- gpu.fill(barPosition, tbl.y, barSize, tbl.width, fPix)
- end
- else
- if tbl.width%2 == 1 then
- gpu.setForeground(tbl.cForeProgress)
- gpu.fill(tbl.x, tbl.y, math.floor(tbl.percents/(100/tbl.length)), tbl.width, fPix)
- elseif tbl.width%2 == 0 then
- gpu.setForeground(tbl.cForeProgress)
- gpu.setBackground(tbl.cFore)
- gpu.fill(tbl.x, tbl.y, math.floor(tbl.percents/(100/tbl.length)), 1, dPix)
- gpu.fill(tbl.x, tbl.y + 1, math.floor(tbl.percents/(100/tbl.length)), tbl.width - 1, fPix)
- gpu.fill(tbl.x, tbl.y + tbl.width, math.floor(tbl.percents/(100/tbl.length)), 1, uPix)
- end
- end
- if tbl.showPercents == true then
- gpu.setForeground(tbl.cForePercents)
- if tbl.percents >= 0 and tbl.percents <= 9 then
- for i = tbl.x + tbl.length/2 - 1, tbl.x + tbl.length/2 do
- local _, color = gpu.get(i, tbl.y)
- gpu.setBackground(color)
- gpu.set(i, tbl.y + math.floor(tbl.width/2), string.sub(percents, i - tbl.x - (tbl.length/2 - 2)))
- end
- elseif tbl.percents > 9 and tbl.percents < 100 then
- for i = tbl.x + tbl.length/2 - 1, tbl.x + tbl.length/2 + 1 do
- local _, color = gpu.get(i, tbl.y)
- gpu.setBackground(color)
- gpu.set(i, tbl.y + math.floor(tbl.width/2), string.sub(percents, i - tbl.x - (tbl.length/2 - 2)))
- end
- elseif tbl.percents == 100 then
- for i = tbl.x + tbl.length/2 - 2, tbl.x + tbl.length/2 + 1 do
- local _, color = gpu.get(i, tbl.y)
- gpu.setBackground(color)
- gpu.set(i, tbl.y + math.floor(tbl.width/2), string.sub(percents, i - tbl.x - (tbl.length/2 - 3)))
- end
- end
- end
- if progressBarsTitles[tbl.percents] ~= nil then
- tbl.title = progressBarsTitles[tbl.percents]
- end
- if tbl.title ~= oldTitle then
- gpu.setForeground(tbl.cFore)
- gpu.fill(tbl.x, tbl.y - 1, tbl.length, 1, fPix)
- if unicode.len(tbl.title) > tbl.length - 4 then
- title = unicode.wtrunc(tbl.title, (tbl.length - 3) - 2) .. ".."
- else
- title = tbl.title
- end
- gpu.setForeground(tbl.cForeTitle)
- gpu.setBackground(tbl.cBackTitle)
- gpu.set(tbl.x + 2, tbl.y - 1, title)
- end
- oldTitle = tbl.title
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0x000000)
- end
- drawProgressBars()
- while true do
- local event, _, key, key1, _ = event.pull()
- if event == "key_down" and key == 113 then
- processingProgressBar(progressBars.progressBar)
- elseif event == "key_down" and key == 101 then
- processingProgressBar(progressBars.progressBar1)
- elseif event == "key_down" and key == 114 then
- processingProgressBar(progressBars.progressBar2)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement