Posted 30 June 2013 - 01:41 PM
I know there is button threads and I always get lost trying to read the code. I just want to be able to make a box with a background color and it not going to be a button. I found this touch button code and can understand half of it but can anyone break it down a little farther with comments so I can understand what is happening. Tables are one thing I still don't fully understand. I inserted some of my comments to show what I get and don't get.
--button on/off color
bactive = colors.cyan
binactive=colors.gray
--text on/off color
tactive=colors.white
tinactive=colors.black
--Background color
bgcolor = colors.black
buttons = {}
--I understand this is where values are being put into the table
function newButton(id,xmin,xmax,ymin,ymax,text,func)
buttons[id] = {}
buttons[id]["xmin"] = xmin
buttons[id]["xmax"] = xmax
buttons[id]["ymin"] = ymin
buttons[id]["ymax"] = ymax
buttons[id]["active"] = false
buttons[id]["text"] = text
buttons[id]["func"] = func
end
---------------------------------------------------------------------------------
function printButton(id)
ymin = buttons[id]["ymin"]
ymax = buttons[id]["ymax"]
xmin = buttons[id]["xmin"]
xmax = buttons[id]["xmax"]
text = buttons[id]["text"]
ia = buttons[id]["active"]
width = xmax - xmin
height = ymax - ymin
if ia then m.setBackgroundColor(bactive) m.setTextColor(tactive)
else m.setBackgroundColor(binactive) m.setTextColor(tinactive) end
-- what is happening here? This is where I get lost.
for j = ymin,ymax do
m.setCursorPos(xmin,j)
for i = xmin,xmax do
m.write(" ")
end
end
m.setCursorPos(xmin + width / 2 - #text / 2 + 1,ymin + height / 2)
m.write(text)
m.setBackgroundColor(bgcolor)
end