-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuttonAPI.lua
72 lines (67 loc) · 1.43 KB
/
buttonAPI.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
local buttonTable = {}
function createButtons()
return buttonTable
end
function addButton(bt,name,x,y,w,h,state,v,ca,cia)
if state == nil then
state = false
end
local tbt = {
["state"] = state,
["name"] = name,
["visi"] = v,
["bx"] = x,
["bw"] = w,
["by"] = y,
["bh"] = h,
["coloractive"] = ca,
["colorinactive"] = cia,
}
table.insert(bt, tbt)
return bt
end
function buttonEvent(bt)
if term.isColor() then
for i in ipairs(bt) do
if bt[i]["visi"] then
if bt[i]["state"] == true then
if bt[i]["coloractive"] then
color = bt[i]["coloractive"]
else
color = colors.lime
end
else
if bt[i]["coloractive"] then
color = bt[i]["colorinactive"]
else
color = colors.red
end
end
local x,y = bt[i]["bx"],bt[i]["by"]
local w,h = bt[i]["bw"]-1,bt[i]["bh"]-1
for xpos = x,(x+w) do
for ypos = y,(y+h) do
paintutils.drawPixel(xpos,ypos,color)
end
term.setCursorPos((x+(w/2+1))-#bt[i]["name"]/2,(y+(h/2)))
print(bt[i]["name"])
end
term.setBackgroundColor(colors.black)
end
end
else
error("screen is not color",0)
end
while true do
event,mbutton,x,y = os.pullEvent("mouse_click")
for i = 1, #bt do
if bt[i]["visi"] then
if x >= bt[i]["bx"] and x <= bt[i]["bx"] + bt[i]["bw"]-1 then
if y >= bt[i]["by"] and y <= bt[i]["by"] + bt[i]["bh"]-1 then
return bt[i]["name"], bt[i]["state"]
end
end
end
end
end
end