Posted 10 December 2014 - 09:36 PM
Hello I'm working on a touch API for terminals and when reading the x and y of the mouseclick I want to be able to see if a button is located at those coordinates.
my code for setting up the table is:
The ID is what the button is reffered to and everything else is self explanatory, Ignore the Index part its a test.
Then to create the button:
This with all my other code give's this: http://imgur.com/rZgvquO
So when the mouse is pressed I want to be able to find out if a button is drawn at those coordinates, I already know how to look for these events and such and have created a simple Menu API which uses arrow keys and Index but this has quite stumped me.
Any help is appreciated.
my code for setting up the table is:
function setButton(ID, text, xMin, xMax, y, Index, Function)
button[ID] = {}
button[ID] ["text"] = text
button[ID] ["xMin"] = xMin
button[ID] ["xMax"] = xMax
button[ID] ["y"] = y
button[ID] ["Function"] = Function
button[Index] = {}
button[Index] ["ID"] = ID
ButtonAmount = ButtonAmount + 1
end
The ID is what the button is reffered to and everything else is self explanatory, Ignore the Index part its a test.
Then to create the button:
function createButton(ID)
local data = button[ID]
term.setBackgroundColor(ButtonOffC)
term.setCursorPos(data["xMin"], data["y"])
local side = math.ceil((data["xMax"] - data["xMin"]) - data["text"]:len())
local todraw = side
while todraw > 0 do
term.write(" ")
todraw = todraw - 1
end
todraw = side
term.write(data["text"])
while todraw > 0 do
term.write(" ")
todraw = todraw - 1
end
end
This with all my other code give's this: http://imgur.com/rZgvquO
So when the mouse is pressed I want to be able to find out if a button is drawn at those coordinates, I already know how to look for these events and such and have created a simple Menu API which uses arrow keys and Index but this has quite stumped me.
Any help is appreciated.