Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local gpu = component.gpu
- local unicode = require("unicode")
- local event = require("event")
- local term = require("term")
- local os = require("os")
- local mk = require("multikey")
- local null = "n"
- local WIDTH, HEIGHT = gpu.maxResolution()
- local lines = {
- lightDouble = {
- hor = unicode.char(0x2550),
- vert = unicode.char(0x2551),
- topLeft = unicode.char(0x2554),
- topRight = unicode.char(0x2557),
- bottomRight = unicode.char(0x255D),
- bottomLeft = unicode.char(0x255A)
- },
- light = {
- hor = unicode.char(0x2500),
- vert = unicode.char(0x2502),
- topLeft = unicode.char(0x250C),
- topRight = unicode.char(0x2510),
- bottomRight = unicode.char(0x2518),
- bottomLeft = unicode.char(0x2514)
- },
- lightDotted = {
- hor = unicode.char(0x2504),
- vert = unicode.char(0x2506),
- topLeft = unicode.char(0x250C),
- topRight = unicode.char(0x2510),
- bottomRight = unicode.char(0x2518),
- bottomLeft = unicode.char(0x2514)
- },
- thin = {
- hor = unicode.char(0x2501),
- vert = unicode.char(0x2503),
- topLeft = unicode.char(0x250F),
- topRight = unicode.char(0x2513),
- bottomRight = unicode.char(0x251B),
- bottomLeft = unicode.char(0x2517)
- },
- thinDotted = {
- hor = unicode.char(0x2505),
- vert = unicode.char(0x2507),
- topLeft = unicode.char(0x250F),
- topRight = unicode.char(0x2510),
- bottomRight = unicode.char(0x251B),
- bottomLeft = unicode.char(0x2517)
- },
- thinAlternate = {
- top = unicode.char(0x2594),
- right = unicode.char(0x2595),
- bottom = unicode.char(0x2581),
- left = unicode.char(0x258F)
- },
- medium = {
- top = unicode.char(0x2580),
- right = unicode.char(0x2590),
- bottom = unicode.char(0x2584),
- left = unicode.char(0x258C),
- topLeft = unicode.char(0x2597),
- topRight = unicode.char(0x2596),
- bottomRight = unicode.char(0x2598),
- bottomLeft = unicode.char(0x259D)
- }
- }
- local intersections = {}
- -- Clockwise: Top, Right, Bottom, Left
- -- LIGHT / THIN 2 LINES
- mk.put(intersections, null, "light", null, "light", unicode.char(0x2500))
- mk.put(intersections, null, "thin", null, "thin", unicode.char(0x2501))
- mk.put(intersections, "light", null, "light", null, unicode.char(0x2502))
- mk.put(intersections, "thin", null, "thin", null, unicode.char(0x2503))
- mk.put(intersections, null, "light", "light", null, unicode.char(0x250C))
- mk.put(intersections, null, "thin", "light", null, unicode.char(0x250D))
- mk.put(intersections, null, "light", "thin", null, unicode.char(0x250E))
- mk.put(intersections, null, "thin", "thin", null, unicode.char(0x250F))
- mk.put(intersections, null, null, "light", "light", unicode.char(0x2510))
- mk.put(intersections, null, null, "light", "thin", unicode.char(0x2511))
- mk.put(intersections, null, null, "thin", "light", unicode.char(0x2512))
- mk.put(intersections, null, null, "thin", "thin", unicode.char(0x2513))
- mk.put(intersections, "light", "light", null, null, unicode.char(0x2514))
- mk.put(intersections, "light", "thin", null, null, unicode.char(0x2515))
- mk.put(intersections, "thin", "light", null, null, unicode.char(0x2516))
- mk.put(intersections, "thin", "thin", null, null, unicode.char(0x2517))
- mk.put(intersections, "light", null, null, "light", unicode.char(0x2518))
- mk.put(intersections, "light", null, null, "thin", unicode.char(0x2519))
- mk.put(intersections, "thin", null, null, "light", unicode.char(0x251A))
- mk.put(intersections, "thin", null, null, "thin", unicode.char(0x251B))
- -- LIGHT/DOUBLE 2 LINES
- mk.put(intersections, null, "double", null, "double", unicode.char(0x2550))
- mk.put(intersections, "double", null, "double", null, unicode.char(0x2551))
- mk.put(intersections, null, "double", "light", "null", unicode.char(0x2552))
- mk.put(intersections, null, "light", "double", null, unicode.char(0x2553))
- mk.put(intersections, null, "double", "double", null, unicode.char(0x2554))
- mk.put(intersections, null, null, "light", "double", unicode.char(0x2555))
- mk.put(intersections, null, null, "double", "light", unicode.char(0x2556))
- mk.put(intersections, null, null, "double", "double", unicode.char(0x2557))
- mk.put(intersections, "light", "double", null, null, unicode.char(0x2558))
- mk.put(intersections, "double", "light", null, null, unicode.char(0x2559))
- mk.put(intersections, "double", "double", null, null, unicode.char(0x255A))
- mk.put(intersections, "light", null, null, "double", unicode.char(0x255B))
- mk.put(intersections, "double", null, null, "light", unicode.char(0x255C))
- mk.put(intersections, "double", null, null, "double", unicode.char(0x255D))
- -- LIGHT / THIN 3 LINES
- mk.put(intersections, "light", "light", "light", null, unicode.char(0x251C))
- mk.put(intersections, "light", "thin", "light", null, unicode.char(0x251D))
- mk.put(intersections, "thin", "light", "light", null, unicode.char(0x251E))
- mk.put(intersections, "light", "light", "thin", null, unicode.char(0x251F))
- mk.put(intersections, "thin", "light", "thin", null, unicode.char(0x2520))
- mk.put(intersections, "thin", "thin", "light", null, unicode.char(0x2521))
- mk.put(intersections, "light", "thin", "thin", null, unicode.char(0x2522))
- mk.put(intersections, "thin", "thin", "thin", null, unicode.char(0x2523))
- mk.put(intersections, "light", null, "light", "light", unicode.char(0x2524))
- mk.put(intersections, "light", null, "light", "thin", unicode.char(0x2525))
- mk.put(intersections, "thin", null, "light", "light", unicode.char(0x2526))
- mk.put(intersections, "light", null, "thin", "light", unicode.char(0x2527))
- mk.put(intersections, "thin", null, "thin", "light", unicode.char(0x2528))
- mk.put(intersections, "thin", null, "light", "thin", unicode.char(0x2529))
- mk.put(intersections, "light", null, "thin", "thin", unicode.char(0x252A))
- mk.put(intersections, "thin", null, "thin", "thin", unicode.char(0x252B))
- mk.put(intersections, null, "light", "light", "light", unicode.char(0x252C))
- mk.put(intersections, null, "light", "light", "thin", unicode.char(0x252D))
- mk.put(intersections, null, "thin", "light", "light", unicode.char(0x252E))
- mk.put(intersections, null, "thin", "light", "thin", unicode.char(0x252F))
- mk.put(intersections, null, "light", "thin", "light", unicode.char(0x2530))
- mk.put(intersections, null, "light", "thin", "thin", unicode.char(0x2531))
- mk.put(intersections, null, "thin", "thin", "light", unicode.char(0x2532))
- mk.put(intersections, null, "thin", "thin", "thin", unicode.char(0x2533))
- mk.put(intersections, "light", "light", null, "light", unicode.char(0x2534))
- mk.put(intersections, "light", "light", null, "thin", unicode.char(0x2535))
- mk.put(intersections, "light", "thin", null, "light", unicode.char(0x2356))
- mk.put(intersections, "light", "thin", null, "thin", unicode.char(0x2357))
- mk.put(intersections, "thin", "light", null, "light", unicode.char(0x2358))
- mk.put(intersections, "thin", "light", null, "thin", unicode.char(0x2359))
- mk.put(intersections, "thin", "thin", null, "light", unicode.char(0x235A))
- mk.put(intersections, "thin", "thin", null, "thin", unicode.char(0x235B))
- -- LIGHT / DOUBLE 3 LINES
- mk.put(intersections, "light", "double", "light", null, unicode.char(0x255E))
- mk.put(intersections, "double", "light", "double", null, unicode.char(0x255F))
- mk.put(intersections, "double", "double", "double", null, unicode.char(0x2560))
- mk.put(intersections, "light", null, "light", "double", unicode.char(0x2561))
- mk.put(intersections, "double", null, "double", "light", unicode.char(0x2562))
- mk.put(intersections, "double", null, "double", "double", unicode.char(0x2563))
- mk.put(intersections, null, "double", "light", "double", unicode.char(0x2564))
- mk.put(intersections, null, "light", "double", "light", unicode.char(0x2565))
- mk.put(intersections, null, "double", "double", "double", unicode.char(0x2566))
- mk.put(intersections, "light", "double", null, "double", unicode.char(0x2567))
- mk.put(intersections, "double", "light", null, "light", unicode.char(0x2568))
- mk.put(intersections, "double", "double", null, "double", unicode.char(0x2569))
- -- LIGHT / THIN 4 LINES
- mk.put(intersections, "light", "light", "light", "light", unicode.char(0x253C))
- mk.put(intersections, "light", "light", "light", "thin", unicode.char(0x253D))
- mk.put(intersections, "light", "thin", "light", "light", unicode.char(0x253E))
- mk.put(intersections, "light", "thin", "light", "thin", unicode.char(0x253F))
- mk.put(intersections, "thin", "light", "light", "light", unicode.char(0x2540))
- mk.put(intersections, "thin", "thin", "light", "thin", unicode.char(0x2541))
- mk.put(intersections, "thin", "light", "thin", "light", unicode.char(0x2542))
- mk.put(intersections, "thin", "light", "light", "thin", unicode.char(0x2543))
- mk.put(intersections, "thin", "thin", "light", "light", unicode.char(0x2544))
- mk.put(intersections, "light", "light", "thin", "thin", unicode.char(0x2545))
- mk.put(intersections, "light", "thin", "thin", "light", unicode.char(0x2546))
- mk.put(intersections, "thin", "thin", "light", "thin", unicode.char(0x2547))
- mk.put(intersections, "light", "thin", "thin", "thin", unicode.char(0x2548))
- mk.put(intersections, "thin", "light", "thin", "thin", unicode.char(0x2549))
- mk.put(intersections, "thin", "thin", "thin", "light", unicode.char(0x254A))
- mk.put(intersections, "thin", "thin", "thin", "thin", unicode.char(0x254B))
- -- LIGHT / DOUBLE 4 LINES
- mk.put(intersections, "light", "double", "light", "double", unicode.char(0x256A))
- mk.put(intersections, "double", "light", "double", "light", unicode.char(0x256B))
- mk.put(intersections, "double", "double", "double", "double", unicode.char(0x256C))
- points = {}
- function generateBoxPoints(boxes, boxDebug)
- boxDebug = boxDebug or false
- --points= {}
- for i,box in ipairs(boxes) do
- for i = box.startX, box.endX do
- mk.put(points, i, box.startY, {lineType = box.lineType})
- mk.put(points, i, box.endY, {lineType = box.lineType})
- end
- for i = box.startY, box.endY do
- mk.put(points, box.startX, i, {lineType = box.lineType})
- mk.put(points, box.endX, i, {lineType = box.lineType})
- end
- end
- if boxDebug == true then
- for _,x,y,point in mk.tuples(points) do
- print(x,y,point)
- end
- end
- for _,x,y,point in mk.tuples(points) do
- local top = mk.get(points, x, y - 1) or null
- local right = mk.get(points, x + 1, y) or null
- local bottom = mk.get(points, x, y + 1) or null
- local left = mk.get(points, x - 1, y) or null
- top = top.lineType or null
- right = right.lineType or null
- bottom = bottom.lineType or null
- left = left.lineType or null
- local expChar = mk.get(intersections, top, right, bottom, left)
- if expChar == nil then
- if top ~= null or bottom ~= null then
- expChar = mk.get(intersections, point.lineType, null, point.lineType, null)
- else
- expChar = mk.get(intersections, null, point.lineType, null, point.lineType)
- end
- end
- mk.put(points, x, y, {lineType = point.lineType, char = expChar})
- end
- --return points
- end
- function drawBoxes(points)
- for _,x,y,point in mk.tuples(points) do
- gpu.set(x, y, point.char or "n")
- end
- end
- local tabs = {}
- function drawWindow(w, h, numTabs, tabWidth, fill)
- local ranges = {
- {2, 1, w - (tabWidth + 1), 1},
- {w - tabWidth, 2, w - (tabWidth + 1), h-1},
- {2, h, w - (tabWidth + 1), h},
- {1, 2, 1, h - 1}
- }
- for k,v in ipairs(ranges) do
- if k == 1 then
- for i = v[1], v[3] do
- gpu.set(i, v[2], lines.thinAlternate.bottom)
- end
- elseif k == 2 then
- for i = v[2], v[4] do
- gpu.set(v[1], i, lines.thinAlternate.left)
- end
- elseif k == 3 then
- for i = v[1], v[3] do
- gpu.set(i, v[2], lines.thinAlternate.top)
- end
- elseif k == 4 then
- for i = v[2], v[4] do
- gpu.set(v[1], i, lines.thinAlternate.right)
- end
- end
- end
- local tabHeight = math.floor(h / numTabs)
- for tab = 1, numTabs do
- tabs[tab] = {
- --active = false,
- w = tabWidth,
- h = tabHeight,
- coords = {w - tabWidth + 1, ((tab * tabHeight) - tabHeight) + 1, w - 1, tab * tabHeight},
- borderRanges = {
- {w - tabWidth + 1, ((tab * tabHeight) - tabHeight) + 1, w - 1, ((tab * tabHeight) - tabHeight) + 1},
- {w, ((tab * tabHeight) - tabHeight) + 2, w, tab * tabHeight - 1},
- {w - tabWidth + 1, tab * tabHeight, w - 1, tab * tabHeight},
- {w - tabWidth, ((tab * tabHeight) - tabHeight) + 2, w - tabWidth, tab * tabHeight - 1}
- }
- }
- for k,v in ipairs(tabs[tab].borderRanges) do
- if k == 1 then
- for i = v[1], v[3] do
- gpu.set(i, v[2], lines.thinAlternate.bottom)
- end
- elseif k == 2 then
- for i = v[2], v[4] do
- gpu.set(v[1], i, lines.thinAlternate.left)
- end
- elseif k == 3 then
- for i = v[1], v[3] do
- gpu.set(i, v[2], lines.thinAlternate.top)
- end
- elseif k == 4 then
- --[[for i = v[2], v[4] do
- gpu.set(v[1], i, lines.thinAlternate.right)
- end]]--
- end
- end
- end
- gpu.setBackground(fill)
- gpu.fill(2, 2, w - 20, h - 2, " ")
- end
- local activeTab = 0
- local wasActiveTab = 0
- function tabClick(x, y)
- for k,v in ipairs(tabs) do
- if x > v.coords[1] and x < v.coords[3] and y > v.coords[2] and y < v.coords[4] then
- if activeTab ~= 0 then
- wasActiveTab = activeTab
- end
- activeTab = k
- end
- end
- end
- function paint(fill)
- if activeTab ~= 0 then
- gpu.setBackground(fill)
- gpu.fill(tabs[activeTab].coords[1], tabs[activeTab].coords[2] + 1, tabs[activeTab].w - 1, tabs[activeTab].h - 2, " ")
- gpu.setForeground(fill)
- gpu.fill(tabs[activeTab].coords[1] - 1, tabs[activeTab].coords[2] + 1, 1, tabs[activeTab].h - 2, lines.thinAlternate.left)
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0x000000)
- end
- if wasActiveTab ~= 0 then
- gpu.fill(tabs[wasActiveTab].coords[1], tabs[wasActiveTab].coords[2] + 1, tabs[wasActiveTab].w - 1, tabs[wasActiveTab].h - 2, " ")
- wasActiveTab = 0
- end
- end
- -- In boxes with different styles that share sides, the boxes that are added later will take priority over boxes added earlier.
- generateBoxPoints({
- {startX = 1, startY = 1, endX = 80, endY = 50, lineType = "light"},
- {startX = 80, startY = 1, endX = 160, endY = 45, lineType = "thin"}
- })
- --mergedPoints = mergeBoxes(returnedBoxPoints)
- term.clear()
- while true do
- gpu.setBackground(0x000000)
- ev, e1, e2, e3 = event.pull(1)
- if ev == "touch" then
- tabClick(e2, e3)
- --[[term.clear()
- os.exit()]]--
- end
- --drawBoxes(points)
- paint(0x00B6FF)
- drawWindow(WIDTH, HEIGHT, 4, 18, 0x00B6FF)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement