View difference between Paste ID: x7E5Qbsx and 1iwuzsh8
SHOW: | | - or go back to the newest paste.
1
local mon = peripheral.wrap("top")
2
mon.setTextScale(1)
3
mon.setTextColor(colors.white)
4
local button={}
5
mon.setBackgroundColor(colors.black)
6
     
7
function setTable(name, func, xmin, xmax, ymin, ymax)
8
   button[name] = {}
9
   button[name]["func"] = func
10
   button[name]["active"] = false
11
   button[name]["xmin"] = xmin
12
   button[name]["ymin"] = ymin
13
   button[name]["xmax"] = xmax
14
   button[name]["ymax"] = ymax
15
end
16
17
function funcName()
18
   print("You clicked buttonText")
19
end
20
        
21
function fillTable()
22
   setTable("ButtonText", funcName, 5, 25, 4, 8)
23
end     
24
25
function fill(text, color, bData)
26
   mon.setBackgroundColor(color)
27-
   local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
27+
28-
   local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
28+
29-
   for j = bData["ymin"], bData["ymax"] do
29+
30-
      mon.setCursorPos(bData["xmin"], j)
30+
31-
      if j == yspot then
31+
32-
         for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
32+
33-
            if k == xspot then
33+
34-
               mon.write(text)
34+
35-
            else
35+
      if on == true then currColor = colors.lime else currColor = colors.gray end
36-
               mon.write(" ")
36+
37-
            end
37+
38
end
39-
      else
39+
40-
         for i = bData["xmin"], bData["xmax"] do
40+
41-
            mon.write(" ")
41+
42
   screen()
43
end     
44
45
function flash(name)
46
   toggleButton(name)
47
   screen()
48
   sleep(0.15)
49
   toggleButton(name)
50
   screen()
51
end
52-
      if on == true then currColor = colors.lime else currColor = colors.red end
52+
53
function checkxy(x, y)
54
   for name, data in pairs(button) do
55
      if y>=data["ymin"] and  y <= data["ymax"] then
56
         if x>=data["xmin"] and x<= data["xmax"] then
57
            data["func"]()
58
            return true
59
            --data["active"] = not data["active"]
60
            --print(name)
61
         end
62
      end
63
   end
64
   return false
65
end
66
     
67
function heading(text)
68
   w, h = mon.getSize()
69
   mon.setCursorPos((w-string.len(text))/2+1, 1)
70
   mon.write(text)
71
end
72
     
73
function label(w, h, text)
74
   mon.setCursorPos(w, h)
75
   mon.write(text)
76
end