133 lines
4.0 KiB
Lua
133 lines
4.0 KiB
Lua
local license = http.get("https://pastebin.com/raw/ZbDMa42Q").readAll()
|
|
local lWin = window.create(term.current(),1,1,term.getSize())
|
|
local oterm = term.current()
|
|
local scr = 0 -- scroll
|
|
local function renderWin()
|
|
local w,h = term.getSize()
|
|
lWin.reposition(1,1-scr,w-1,60)
|
|
term.redirect(lWin)
|
|
term.setBackgroundColor(colors.white)
|
|
term.setTextColor(colors.black)
|
|
term.clear()
|
|
term.setCursorPos(1,1)
|
|
print(license)
|
|
lWin.reposition(1,1-scr,w-1,({term.getCursorPos()})[2])
|
|
term.redirect(oterm)
|
|
end
|
|
|
|
local scrDrag
|
|
local calc
|
|
|
|
local function scrollbar(e)
|
|
local w,h = term.getSize()
|
|
term.setBackgroundColor(colors.lightGray)
|
|
term.setTextColor(colors.gray)
|
|
for y=1,h do
|
|
term.setCursorPos(w,y)
|
|
if y == 1 then
|
|
term.write("30")
|
|
elseif y == h then
|
|
term.write("31")
|
|
else
|
|
term.write(" ")
|
|
end
|
|
end
|
|
local w1,h1 = lWin.getSize()
|
|
if h1 > h then
|
|
local sH = h/h1 * (h-2) -- scrollbar height
|
|
local sY
|
|
local sYmax
|
|
if sH < 1 then
|
|
sY = 2 + (h-2.333)*(scr/(h1-h))
|
|
sYmax = 2+(h-2.333)*(h1-h)
|
|
else
|
|
sY = 2 + (h-1-sH)*(scr/(h1-h))
|
|
sYmax = 2+(h-1-sH)*(h1-h)
|
|
end
|
|
if e then
|
|
if e[1] == "mouse_click" and e[4] >= sY and e[4] <= sY+(sH-1) then
|
|
scrDrag = e[4]
|
|
elseif e[1] == "mouse_drag" and scrDrag then
|
|
local sYnew = sY+(e[4]-scrDrag)
|
|
calc = sY.."+("..e[4].."-"..scrDrag..")"
|
|
if sYnew <= sYmax then
|
|
sY = sYnew
|
|
scrDrag = e[4]
|
|
--calc = "("..sY.."/"..sYmax..") * ("..h1.."-"..h..")"
|
|
scr = (sY/sYmax) * (h1-h)
|
|
end
|
|
elseif e[1] == "mouse_up" then
|
|
scrDrag = nil
|
|
end
|
|
term.setCursorPos(1,1)
|
|
term.setTextColor(colors.red)
|
|
lUtils.transWrite("")
|
|
--os.sleep(0.5)
|
|
end
|
|
local bg = colors.gray
|
|
if scrDrag then
|
|
bg = colors.black
|
|
end
|
|
term.setBackgroundColor(bg)
|
|
for y=sY,sY+(sH-1) do
|
|
term.setCursorPos(w,y)
|
|
term.write(" ")
|
|
end
|
|
if sH < 1 then
|
|
term.setCursorPos(w,math.floor(sY))
|
|
if math.mod(sY,1) > 0.66 then
|
|
term.setBackgroundColor(bg)
|
|
term.setTextColor(colors.lightGray)
|
|
term.write("143")
|
|
elseif math.mod(sY,1) > 0.33 then
|
|
term.setBackgroundColor(bg)
|
|
term.setTextColor(colors.gray)
|
|
term.write("140")
|
|
else
|
|
term.setBackgroundColor(colors.lightGray)
|
|
term.setTextColor(bg)
|
|
term.write("131")
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
renderWin()
|
|
scrollbar()
|
|
while true do
|
|
local e = {os.pullEvent()}
|
|
local w,h = term.getSize()
|
|
if e[1] == "mouse_scroll" then
|
|
--local w,h = term.getSize()
|
|
local w1,h1 = lWin.getSize()
|
|
if h1 > h and e[3] >= 1 and e[4] >= 1 and e[3] <= self.x2-(self.x1-1) and e[4] <= self.y2-(self.y1-1) then
|
|
scr = scr+e[2]
|
|
--local w,h = term.getSize()
|
|
--local w1,h1 = lWin.getSize()
|
|
if scr < 0 then
|
|
scr = 0
|
|
elseif scr > h1-h then
|
|
scr = h1-h
|
|
end
|
|
renderWin()
|
|
scrollbar()
|
|
elseif h1 <= h and scr ~= 0 then
|
|
scr = 0
|
|
renderWin()
|
|
scrollbar()
|
|
end
|
|
elseif e[1] == "term_resize" then
|
|
renderWin()
|
|
scrollbar()
|
|
elseif string.find(e[1],"mouse") and e[3] == w and enabledcuznowitsdisabled then
|
|
scrollbar(e)
|
|
renderWin()
|
|
term.setCursorPos(1,1)
|
|
term.setTextColor(colors.red)
|
|
lUtils.transWrite(tostring(scrDrag)..", "..tostring(scr))
|
|
term.setCursorPos(1,2)
|
|
lUtils.transWrite(tostring(calc))
|
|
elseif e[1] == "mouse_up" then
|
|
scrDrag = nil
|
|
end
|
|
end |